Преглед на файлове

Merge branch 'master' of https://git.steerinfo.com/XTEMS/xt-ems-front

lirl преди 3 години
родител
ревизия
748a972ff6
променени са 3 файла, в които са добавени 263 реда и са изтрити 24 реда
  1. 132 1
      src/components/main.vue
  2. 131 23
      src/views/energyOperationSupport/components/securitys/SecurityFile.vue
  3. BIN
      static/img/14430.wav

+ 132 - 1
src/components/main.vue

@@ -588,6 +588,14 @@ export default {
             }
         };
         return {
+            websocket: '',
+            userInfo: {}, // 用户信息
+            qrRole: [], //角色信息
+            roleList: {
+                obj: {},
+                arr: []
+            }, // 角色信息
+            userRoles: [],
             leaveFlag: true,
             PEButShow: false,
             PEhandleDownloadExcelForElTable,
@@ -749,6 +757,7 @@ export default {
             window.top.removeEventListener('unload', e => this.unloadHandler(e))
             window.top.removeEventListener('onunload', e => this.onunloadHandler(e))
         }
+        this.websocketclose();
     },
     mounted () {
         //  取字典
@@ -760,6 +769,7 @@ export default {
             this.minHeight = 'width: 100%;height: calc(100% - 10px);border: 0px;min-height: ' + ($('#menuTabId').height() - 113) + 'px'
             this.leaveFlag = false;
         });
+        this.getRoles();
     },
     methods: {
         logoutAwait: async function(){
@@ -940,6 +950,16 @@ export default {
                 window.top.addEventListener('beforeunload', e => that.beforeunloadHandler(e))
                 window.top.addEventListener('unload', e => that.unloadHandler(e))
                 window.top.addEventListener('onunload', e => that.onunloadHandler(e))
+                // websocket初始化
+                let token = getCookie('accessToken');
+                // WebSocket
+                      if ('WebSocket' in window) {
+                        // this.websocket = new WebSocket('ws://localhost:8086/websocket/123?token=' + token,[token])
+                        this.websocket = new WebSocket('ws://localhost:8086/websocket/' + token);
+                        this.initWebSocket()
+                      } else {
+                        alert('当前浏览器 Not support websocket')
+                      }
             }
 
             if (routerFlag > 0 || routerFlagP > 0) {
@@ -1232,7 +1252,118 @@ export default {
         updataUserInfo (data) {
             this.getUserInfo();
             this.$store.commit('userInfo', data)
-        }
+        },
+        initWebSocket () {
+                // 连接错误
+                this.websocket.onerror = this.setErrorMessage
+        
+                // 连接成功
+                this.websocket.onopen = this.setOnopenMessage
+        
+                // 收到消息的回调
+                this.websocket.onmessage = this.setOnmessageMessage
+        
+                // 连接关闭的回调
+                this.websocket.onclose = this.setOncloseMessage
+        
+                // 监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
+                window.onbeforeunload = this.onbeforeunload
+              },
+              setErrorMessage () {
+                console.log('WebSocket连接发生错误   状态码:' + this.websocket.readyState)
+              },
+              setOnopenMessage () {
+                console.log('WebSocket连接成功    状态码:' + this.websocket.readyState)
+              },
+              setOnmessageMessage (event) {
+                // 根据服务器推送的消息做自己的业务处理
+                let data = JSON.parse(event.data);
+                let show = false;
+                for(let item of data.role) {
+                  let roleId = this.roleList.obj[item].id;
+                  if(this.qrRole.includes(roleId)) {
+                    show = true;
+                    break;
+                  }
+                }
+                if(show) {
+                this.$notify({
+                          title: data.title,
+                          message: data.message,
+                          position: 'bottom-right',
+                          duration: 0
+                        });
+                // let audio = new Audio()
+                // audio.src = '/static/img/14430.wav';
+                // // 开启自动播放
+                //     // this.audio.autoplay = true;
+                // audio.play();
+                this.handleSpeak(data.tips);
+                console.log('服务端返回:' + event.data);
+                console.log( document.visibilityState );
+                console.log( document.hidden);
+                if (document.visibilityState != 'visible' || document.hidden) {
+                  let myWindow = window.open('','','width=200,height=100,left=800,top=500');
+                  // let myWindow = window.open(location.href,'_parent','');
+                   myWindow.document.write('<p>'+data.message+'</p>');
+                   myWindow.focus();
+                }
+                }
+              },
+              setOncloseMessage () {
+                console.log('WebSocket连接关闭    状态码:' + this.websocket.readyState)
+              },
+              onbeforeunload () {
+                this.closeWebSocket()
+              },
+              closeWebSocket () {
+                this.websocket.close()
+              },
+              // 语音播报的函数
+               handleSpeak(text='你好啊!'){
+                   if(window.speechSynthesis){
+                       const synth = window.speechSynthesis;
+                       const msg = new SpeechSynthesisUtterance();
+                       msg.text = text;     // 文字内容
+                       msg.lang = "zh-CN";  // 使用的语言:中文
+                       msg.volume = 20;      // 声音音量:1
+                       msg.rate = 1;        // 语速:1
+                       msg.pitch = 1;       // 音高:1
+                       msg.voice = this.getWindowVoice()  // 使用本地服务合成语音(若是获取不到 请异步获取, 加一个setTimeout)
+                       synth.speak(msg);    // 播放
+                   }
+               },
+              getWindowVoice(){  // 获取浏览器中语音 (中文 + 本地服务)
+                 return window.speechSynthesis.getVoices().find(item => item.localService && item.lang === 'zh-CN')
+              },
+              getRoles () {
+                  let that = this;
+                  // 获取用户信息
+                  this.store.dispatch('getUserInfo').then((res) => {
+                      that.axios.get('pass/v1/sysuserroles/?userId=' + res.data.userId + '&pageNum=1&pageSize=100').then(rest => {
+                        if (rest) {
+                          for (let i = 0; i < rest.data.list.length; i++) {
+                            that.qrRole.push(rest.data.list[i].roleId)
+                          }
+                          that.userRoles = rest.data.list; // 获取用户角色关联信息
+                        }
+                      })
+                  });
+                  // 获取角色信息
+                  this.store.dispatch('system/rolesManage/list').then(res => {
+                    if (res.code === '0') {
+                      this.roleList.arr = res.data;
+                      for (let obj of res.data) {
+                          this.roleList.obj[obj.roleName] = {
+                              name: obj.roleName,
+                              id: obj.id
+                          };
+                      }
+                      } else {
+                    this.$message.error(res.message);
+                  }
+                  });
+              }
     }
 }
 </script>

+ 131 - 23
src/views/energyOperationSupport/components/securitys/SecurityFile.vue

@@ -123,6 +123,7 @@
                         ref="upload"
                         :http-request="beforeUpload"
                         :auto-upload="false"
+                        :loading="loading"
                         >
                         <i class="el-icon-upload"></i>
                         <!-- <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div> -->
@@ -133,21 +134,35 @@
                         ref="upload1"
                         action=""
                         :http-request="beforeUpload"
+                        :loading="loading"
                         :auto-upload="false">
                         <el-button
                         slot="trigger"
                         size="small"
                         type="primary"
+                        :loading="loading"
+                        icon="el-icon-plus"
                         >选取文件
                         </el-button>
                         </el-upload>
                         <el-button
-                        style="margin-left: 10px;"
-                        size="small" type="success"
+                        style="margin-left: 20px;"
+                        size="small"
+                        type="primary"
                         v-privilege="activeMenu + 'UPLOAD'"
                         @click="submitUpload"
+                        :loading="loading"
                         >上传到服务器
                         </el-button>
+                        <el-button
+                            class="button"
+                            type="primary"
+                            size="mini"
+                            icon="el-icon-edit-outline"
+                            v-privilege="activeMenu + 'UPDATA'"
+                            @click="but_edit_plural()"
+                            :loading="loading"
+                        >修改</el-button>
                         <el-button
                             class="button"
                             type="danger"
@@ -165,6 +180,7 @@
                                 icon="el-icon-search"
                                 v-privilege="activeMenu + 'QUERY'"
                                 @click="getTableData(1)"
+                                :loading="loading"
                             >查询</el-button>
                             <el-button
                                 size="mini"
@@ -237,15 +253,47 @@
                                 width="320px"
                                 :show-overflow-tooltip="true"
                             > <template slot-scope="scope">
-                                      <el-tag
-                                        effect="dark"
-                                        :disable-transitions="true"
-                                        v-for="(tag,key) in scope.row.fileType"
-                                        :key="key"
-                                        size="small">
-                                        {{ tag }}
-                                      </el-tag>
-                                </template>
+                                      <el-form-item
+                                          v-if="scope.row.isSelection"
+                                          :prop="scope.row.ID + '.fileType'"
+                                      >
+                                          <el-tag
+                                            effect="dark"
+                                            v-for="(tag,key) in tableFormDataObj[scope.row.ID].fileType"
+                                            :key="key"
+                                            closable
+                                            size="small"
+                                            :disable-transitions="true"
+                                            @close="rowhandleClose(tag, scope.row)">
+                                            {{tag}}
+                                          </el-tag>
+                                          <el-input
+                                            class="input-new-tag"
+                                            v-if="tableFormDataObj[scope.row.ID].showInput"
+                                            v-model="tableFormDataObj[scope.row.ID].inputValue"
+                                            ref="saveTagInput"
+                                            size="small"
+                                            @keyup.enter.native="rowhandleInputConfirm(scope.row)"
+                                            @blur="rowhandleInputConfirm(scope.row)"
+                                          >
+                                          </el-input>
+                                          <el-button
+                                          v-else
+                                          class="button-new-tag"
+                                          size="small"
+                                          @click="rowshowInput(scope.row)"
+                                          >+标签</el-button>
+                                      </el-form-item>
+                                      <template v-else>
+                                        <el-tag
+                                          effect="dark"
+                                          :disable-transitions="true"
+                                          v-for="(tag,key) in scope.row.fileType"
+                                          :key="key"
+                                          size="small">
+                                          {{ tag }}
+                                        </el-tag></template>
+                                  </template>
                             </el-table-column>
                             <el-table-column
                                 sortable
@@ -286,6 +334,7 @@
                             icon="el-icon-download"
                             v-privilege="activeMenu + 'DOWNLOAD'"
                             @click="downloadFile(scope.row)"
+                            :loading="loading"
                             >点击下载
                             </el-button>
                             <el-button
@@ -294,6 +343,7 @@
                             icon="el-icon-view"
                             v-privilege="activeMenu + 'PREVIEW'"
                             @click="preview(scope.row)"
+                            :loading="loading"
                             >预览
                             </el-button>
                             </template>
@@ -556,7 +606,7 @@ export default {
             dialog: {
                 editorBox: {
                     show: false,
-                    type: '',
+                    fileType: '',
                     form: {
                         default: {
                             workprocid: ''
@@ -568,7 +618,8 @@ export default {
                             isprimary: '0',
                             unitid: '',
                             seqno: '',
-                            code: ''
+                            code: '',
+                            fileType: ''
                         },
                         rules: {
                             productid: [
@@ -777,7 +828,9 @@ export default {
                                 createMan: item.createMan,
                                 createTime: item.createTime,
                                 updateMan: item.updateMan,
-                                updateTime: item.updateTime
+                                updateTime: item.updateTime,
+                                showInput: false,
+                                inputValue: ''
                             })
                             }
                         }
@@ -818,7 +871,7 @@ export default {
             }
             for (let item of val) {
                 let obj = {};
-                let xId = item.itemid;
+                let xId = item.ID;
                 if (that.tableFormDataObj[xId]) {
                     tableFormDataObj[xId] = that.tableFormDataObj[xId];
                 } else {
@@ -829,7 +882,7 @@ export default {
                 }
                 item.isSelection = true;
             }
-            that.tableFormDataObj = tableFormDataObj;
+            that.tableFormDataObj = JSON.parse(JSON.stringify(tableFormDataObj));
             that.multipleSelection = val;
         },
         but_add () {
@@ -852,7 +905,9 @@ export default {
             }, 100);
         },
         beforeUpload (file) {
-          let that = this
+          let that = this;
+          that.tableLoading = true;
+          that.loading = true;
           let foorData = new FormData();
           foorData.append('file', file.file);
           foorData.append('type', this.filterForm.data.securityTypeid);
@@ -873,16 +928,50 @@ export default {
                 } else {
                 that.$message.error(res.message);
                 }
+                that.tableLoading = false;
+                that.loading = false;
           }).catch(function () {
+            that.$message({
+                 message: '上传失败,FTP服务器可能已断开连接',
+                 type: 'success'
+             });
+             that.tableLoading = false;
+             that.loading = false;
           });
         },
         submitUpload () {
+        let that = this;
         this.$refs.upload.submit();
         this.$refs.upload1.submit();
       },
       handleRemove (file, fileList) {
         console.log(file, fileList);
       },
+      // 行内标签删除
+      rowhandleClose (tag, row) {
+        let that = this;
+        that.tableFormDataObj[row.ID].fileType.splice(that.tableFormDataObj[row.ID].fileType.indexOf(tag), 1);
+      },
+      // 行内标签新增
+      rowhandleInputConfirm (row) {
+        let that = this;
+        let inputValue = that.tableFormDataObj[row.ID].inputValue;
+        if (inputValue) {
+          that.tableFormDataObj[row.ID].fileType.push(inputValue);
+        }
+        that.tableFormDataObj[row.ID].showInput = false;
+        that.tableFormDataObj[row.ID].inputValue = '';
+      },
+      // 行内input获取焦点
+      rowshowInput (row) {
+        let that = this;
+        that.tableFormDataObj[row.ID].showInput = true;
+        // setTimeout(function(){
+        //    that.$nextTick(_ => {
+        //      this.$refs.saveTagInput.$refs.input.focus();
+        //    });
+        // },500)
+      },
       handlePreview (file) {
         console.log(file);
       },
@@ -894,16 +983,22 @@ export default {
                     if (valid) {
                         let SubmitData = [];
                         for (let key in that.tableFormDataObj) {
+                          let fileTypes = '';
+                          for (let item in that.tableFormDataObj[key].fileType) {
+                              if (Number(item) === that.tableFormDataObj[key].fileType.length - 1) {
+                                  fileTypes += that.tableFormDataObj[key].fileType[item];
+                              } else {
+                                  fileTypes += that.tableFormDataObj[key].fileType[item] + ';';
+                              }
+                          }
                             SubmitData.push({
-                                itemid: that.tableFormDataObj[key].itemid,
-                                isprimary: that.tableFormDataObj[key].isprimary,
-                                unitid: that.tableFormDataObj[key].unitid,
-                                seqno: that.tableFormDataObj[key].seqno,
-                                code: that.tableFormDataObj[key].code
+                                Id: that.tableFormDataObj[key].ID,
+                                fileType: fileTypes,
+                                seqno: that.tableFormDataObj[key].seqno
                             });
                         }
                         that.loading = true;
-                        that.axios.put('pass/ems/v1/trmworkprocproducts/', SubmitData)
+                        that.axios.put('pass/ems/v1/uploadfiles/batchupdate', SubmitData)
                             .then(function (res) {
                                 if (res.code === '0') {
                                     that.$message({
@@ -928,6 +1023,7 @@ export default {
         // 批量删除
         but_del_plural () {
             let that = this;
+            that.loading = true;
             if (that.multipleSelection.length > 0) {
                 let ids = [];
                 let paths = [];
@@ -948,6 +1044,7 @@ export default {
                                     type: 'success'
                                 });
                                 that.getTableData();
+                                that.loading = false;
                             } else {
                                 if (res.code === '51') {
 
@@ -955,11 +1052,13 @@ export default {
                                 that.$message.error(res.message);
                             }
                         }).catch(function () {
+                          that.loading = false;
                         });
                 }).catch(() => {
                 });
             } else {
                 this.$message.error('至少要选择一条数据');
+                that.loading = false;
             }
         },
         dataSave () {
@@ -1079,6 +1178,7 @@ export default {
             //     }
             // };
             // xhr.send();
+            that.loading = true;
                 let urla = 'pass/ems/v1/uploadfiles/downloadFile/';
                 that.axios.get(urla, {
                 params: SubmitData,
@@ -1089,18 +1189,22 @@ export default {
                        message: '下载成功',
                        type: 'success'
                    });
+                   that.loading = false;
                 }).catch(function () {
                     that.$message.error('下载失败');
+                    that.loading = false;
                 })
         },
         // js实现文件下载而不直接打开
         saveAs (data, fileName) {
+            this.loading = true;
             let urlObject = window.URL || window.webkitURL || window;
             // 将二进制流转为blob
             let exportBlob = new Blob([data]);
             if (typeof window.navigator.msSaveBlob !== 'undefined') {
               // 兼容IE,window.navigator.msSaveBlob:以本地方式保存文件
               window.navigator.msSaveBlob(exportBlob, decodeURI(fileName));
+              this.loading = false;
             } else {
                 // 创建新的URL并指向File对象或者Blob对象的地址
                 let blobURL = urlObject.createObjectURL(exportBlob);
@@ -1116,6 +1220,7 @@ export default {
                 saveLink.click();
                 // 释放blob URL地址
                 urlObject.revokeObjectURL(exportBlob);
+                this.loading = false;
                 // let blob = new Blob([data])
                 // let fileURL = urlObject.createObjectURL(blob);
                 // 下载代码
@@ -1130,6 +1235,7 @@ export default {
         },
         preview (data) {
             let that = this;
+            that.loading = true;
             let SubmitData = {
                 fileName: data.fileName,
                 fileUrl: data.fileUrl
@@ -1163,6 +1269,7 @@ export default {
                 that.dialogVisible = true;
                 that.previewUrl = blobURL;
                 that.tableLoading = false;
+                that.loading = false;
                 // 'https://file.keking.cn/onlinePreview?url=' + encodeURIComponent(blobURL)
                 // http://view.officeapps.live.com/op/view.aspx?src' + blobURL;
                 // 创建a标签,用于跳转至下载链接
@@ -1187,6 +1294,7 @@ export default {
             }).catch(function () {
                 that.tableLoading = false;
                 that.$message.error('预览失败');
+                that.loading = false;
             })
         }
     }

BIN
static/img/14430.wav