lxh 1 روز پیش
والد
کامیت
239c016fd4
2فایلهای تغییر یافته به همراه36 افزوده شده و 63 حذف شده
  1. 34 63
      src/hooks/system/useMethods.ts
  2. 2 0
      src/layouts/default/header/components/VoiceBroadcast.vue

+ 34 - 63
src/hooks/system/useMethods.ts

@@ -57,69 +57,40 @@ export function useMethods() {
    * @param url
    */
   async function exportXlsPost(name, url, params, isXlsx = false) {
-
-    const data = await defHttp.post({ url: url, params: params, responseType: 'blob', timeout: 1000 * 1000 }, { isTransformResponse: false });
-    if (!data) {
-      createMessage.warning('文件下载失败');
-      return;
-    }
-    if (!name || typeof name != 'string') {
-      name = '导出文件';
-    }
-    const blobOptions = { type: 'application/vnd.ms-excel' };
-    let fileSuffix = '.xls';
-    if (isXlsx === true) {
-      blobOptions['type'] = XLSX_MIME_TYPE;
-      fileSuffix = XLSX_FILE_SUFFIX;
-    }
-    if (typeof window.navigator.msSaveBlob !== 'undefined') {
-      window.navigator.msSaveBlob(new Blob([data], blobOptions), name + fileSuffix);
-    } else {
-      const url = window.URL.createObjectURL(new Blob([data], blobOptions));
-      const link = document.createElement('a');
-      link.style.display = 'none';
-      link.href = url;
-      link.setAttribute('download', name + fileSuffix);
-      document.body.appendChild(link);
-      link.click();
-      document.body.removeChild(link); //下载完成移除元素
-      window.URL.revokeObjectURL(url); //释放掉blob对象
-    }
-   
-    // const key = 'updatable';
-    // message.loading({ content: '正在导出,请稍等...', key });
-    // defHttp
-    //   .post({ url: url, params: params, timeout: 1000 * 1000 }, { isTransformResponse: false })
-    //   .then((data) => {
-    //     debugger;
-    //     if (data.code == 200 && data.result) {
-    //       const messageArr = data.result.split('/');
-    //       const fileUrl = messageArr[messageArr.length - 1];
-    //       if (fileUrl) {
-    //         const baseApiUrl = glob.domainUrl;
-    //         // 下载文件
-    //         const a = document.createElement('a');
-    //         // 定义下载名称
-    //         a.download = name;
-    //         // 隐藏标签
-    //         a.style.display = 'none';
-    //         // 设置文件路径
-    //         a.href = `${baseApiUrl}/sys/common/static/${fileUrl}`;
-    //         // 将创建的标签插入dom
-    //         document.body.appendChild(a);
-    //         // 点击标签,执行下载
-    //         a.click();
-    //         // 将标签从dom移除
-    //         document.body.removeChild(a);
-    //         message.success({ content: '导出成功!', key, duration: 1 });
-    //       }
-    //     } else {
-    //       message.error({ content: '下载失败!', key, duration: 1 });
-    //     }
-    //   })
-    //   .catch(() => {
-    //     message.error({ content: '下载失败!', key, duration: 1 });
-    //   });
+     const key = 'updatable';
+     message.loading({ content: '正在导出,请稍等...', key });
+     defHttp
+       .post({ url: url, params: params, timeout: 1000 * 1000 }, { isTransformResponse: false })
+       .then((data) => {
+         debugger;
+         if (data.code == 200 && data.result) {
+           const messageArr = data.result.split('/');
+           const fileUrl = messageArr[messageArr.length - 1];
+           if (fileUrl) {
+             const baseApiUrl = glob.domainUrl;
+             // 下载文件
+             const a = document.createElement('a');
+             // 定义下载名称
+             a.download = name;
+             // 隐藏标签
+             a.style.display = 'none';
+             // 设置文件路径
+             a.href = `${baseApiUrl}/sys/common/static/${fileUrl}`;
+             // 将创建的标签插入dom
+             document.body.appendChild(a);
+             // 点击标签,执行下载
+             a.click();
+             // 将标签从dom移除
+             document.body.removeChild(a);
+             message.success({ content: '导出成功!', key, duration: 1 });
+           }
+         } else {
+           message.error({ content: '下载失败!', key, duration: 1 });
+        }
+       })
+       .catch(() => {
+         message.error({ content: '下载失败!', key, duration: 1 });
+       });
   }
 
   async function exportXlsPost1(name, url, params, isXlsx = false) {

+ 2 - 0
src/layouts/default/header/components/VoiceBroadcast.vue

@@ -123,9 +123,11 @@
         // let wsClientId = md5(token);
         // let userId = unref(userStore.getUserInfo).id + '_' + wsClientId;
         let userId = unref(userStore.getUserInfo).id + '?token=' + token;
+        console.log(userStore.getUserInfo,'userId---')
         // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
         // let url = glob.wsUrl?.replace('https://', 'wss://').replace('http://', 'ws://') + '/websocket/' + userId;
         let url = 'http://' + window.location.hostname + ':9999'?.replace('https://', 'wss://').replace('http://', 'ws://') + '/websocket/' + userId;
+        console.log(url,'url------')
         connectWebSocket(url);
         onWebSocket(onWebSocketMessage);
       }