From 2a0cbf1356509707da46e60ac13e52d2cd0543b9 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期二, 04 三月 2025 10:11:12 +0800
Subject: [PATCH] 公共数据组件引用

---
 src/main.js             |  131 ++++++++++++++++----------
 package.json            |    1 
 src/plugins/download.js |  131 +++++++++++++++++--------
 3 files changed, 170 insertions(+), 93 deletions(-)

diff --git a/package.json b/package.json
index 4208e1b..f77ab56 100644
--- a/package.json
+++ b/package.json
@@ -49,6 +49,7 @@
     "js-cookie": "3.0.1",
     "jsencrypt": "3.0.0-rc.1",
     "mammoth": "^1.9.0",
+    "moment": "^2.30.1",
     "nprogress": "0.2.0",
     "print-js": "^1.6.0",
     "quill": "2.0.2",
diff --git a/src/main.js b/src/main.js
index 2be086c..7f0fd18 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,70 +1,99 @@
-import Vue from 'vue'
+import Vue from "vue";
 
-import Cookies from 'js-cookie'
+import Cookies from "js-cookie";
 
-import Element from 'element-ui'
-import './assets/styles/element-variables.scss'
+import Element from "element-ui";
+import "./assets/styles/element-variables.scss";
 
-import '@/assets/styles/index.scss' // global css
-import '@/assets/styles/ruoyi.scss' // ruoyi css
-import App from './App'
-import store from './store'
-import router from './router'
-import directive from './directive' // directive
-import plugins from './plugins' // plugins
-import { download } from '@/utils/request'
+import "@/assets/styles/index.scss"; // global css
+import "@/assets/styles/ruoyi.scss"; // ruoyi css
+import App from "./App";
+import store from "./store";
+import router from "./router";
+import directive from "./directive"; // directive
+import plugins from "./plugins"; // plugins
+import { download } from "@/utils/request";
 
-import './assets/icons' // icon
-import './permission' // permission control
+import "./assets/icons"; // icon
+import "./permission"; // permission control
 import { getDicts } from "@/api/system/dict/data";
 import { getConfigKey } from "@/api/system/config";
-import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/ruoyi";
+import {
+  parseTime,
+  resetForm,
+  addDateRange,
+  selectDictLabel,
+  selectDictLabels,
+  handleTree,
+} from "@/utils/ruoyi";
 // 鍒嗛〉缁勪欢
 import Pagination from "@/components/Pagination";
 // 鑷畾涔夎〃鏍煎伐鍏风粍浠�
-import RightToolbar from "@/components/RightToolbar"
+import RightToolbar from "@/components/RightToolbar";
 // 瀵屾枃鏈粍浠�
-import Editor from "@/components/Editor"
+import Editor from "@/components/Editor";
 // 鏂囦欢涓婁紶缁勪欢
-import FileUpload from "@/components/FileUpload"
+import FileUpload from "@/components/FileUpload";
 // 鍥剧墖涓婁紶缁勪欢
-import ImageUpload from "@/components/ImageUpload"
+import ImageUpload from "@/components/ImageUpload";
 // 鍥剧墖棰勮缁勪欢
-import ImagePreview from "@/components/ImagePreview"
+import ImagePreview from "@/components/ImagePreview";
 // 瀛楀吀鏍囩缁勪欢
-import DictTag from '@/components/DictTag'
+import DictTag from "@/components/DictTag";
 // 澶撮儴鏍囩缁勪欢
-import VueMeta from 'vue-meta'
+import VueMeta from "vue-meta";
 // 瀛楀吀鏁版嵁缁勪欢
-import DictData from '@/components/DictData'
+import DictData from "@/components/DictData";
+import { checkPermi } from "@/utils/permission"; // 鏉冮檺鍒ゆ柇鍑芥暟
+import { getToken } from "@/utils/auth";
+// 鏃堕棿杞崲
+import Moment from "moment";
 
 // 鍏ㄥ眬鏂规硶鎸傝浇
-Vue.prototype.getDicts = getDicts
-Vue.prototype.getConfigKey = getConfigKey
-Vue.prototype.parseTime = parseTime
-Vue.prototype.resetForm = resetForm
-Vue.prototype.addDateRange = addDateRange
-Vue.prototype.selectDictLabel = selectDictLabel
-Vue.prototype.selectDictLabels = selectDictLabels
-Vue.prototype.download = download
-Vue.prototype.handleTree = handleTree
+Vue.prototype.getDicts = getDicts;
+Vue.prototype.getConfigKey = getConfigKey;
+Vue.prototype.parseTime = parseTime;
+Vue.prototype.resetForm = resetForm;
+Vue.prototype.addDateRange = addDateRange;
+Vue.prototype.selectDictLabel = selectDictLabel;
+Vue.prototype.selectDictLabels = selectDictLabels;
+Vue.prototype.download = download;
+Vue.prototype.handleTree = handleTree;
 Vue.prototype.HaveJson = (val) => {
-  return JSON.parse(JSON.stringify(val))
-}
+  return JSON.parse(JSON.stringify(val));
+};
+Vue.prototype.javaApi = process.env.VUE_APP_BASE_API
+  ? process.env.VUE_APP_BASE_API
+  : "http://192.168.0.104:8002";
+Vue.prototype.checkPermi = checkPermi;
+Vue.prototype.uploadHeader = {
+  Authorization: "Bearer " + getToken(),
+};
+// 瑙e喅el-radio-group鍗曢�夋鑷韩鐨刡ug
+Vue.directive("removeAriaHidden", {
+  bind(el, binding) {
+    let ariaEls = el.querySelectorAll(".el-radio__original");
+    ariaEls.forEach((item) => {
+      item.removeAttribute("aria-hidden");
+    });
+  },
+});
+Vue.use(Moment);
+Vue.prototype.$moment = Moment;
 
 // 鍏ㄥ眬缁勪欢鎸傝浇
-Vue.component('DictTag', DictTag)
-Vue.component('Pagination', Pagination)
-Vue.component('RightToolbar', RightToolbar)
-Vue.component('Editor', Editor)
-Vue.component('FileUpload', FileUpload)
-Vue.component('ImageUpload', ImageUpload)
-Vue.component('ImagePreview', ImagePreview)
+Vue.component("DictTag", DictTag);
+Vue.component("Pagination", Pagination);
+Vue.component("RightToolbar", RightToolbar);
+Vue.component("Editor", Editor);
+Vue.component("FileUpload", FileUpload);
+Vue.component("ImageUpload", ImageUpload);
+Vue.component("ImagePreview", ImagePreview);
 
-Vue.use(directive)
-Vue.use(plugins)
-Vue.use(VueMeta)
-DictData.install()
+Vue.use(directive);
+Vue.use(plugins);
+Vue.use(VueMeta);
+DictData.install();
 
 /**
  * If you don't want to use mock-server
@@ -76,14 +105,14 @@
  */
 
 Vue.use(Element, {
-  size: Cookies.get('size') || 'medium' // set element-ui default size
-})
+  size: Cookies.get("size") || "medium", // set element-ui default size
+});
 
-Vue.config.productionTip = false
+Vue.config.productionTip = false;
 
 new Vue({
-  el: '#app',
+  el: "#app",
   router,
   store,
-  render: h => h(App)
-})
+  render: (h) => h(App),
+});
diff --git a/src/plugins/download.js b/src/plugins/download.js
index 42acd00..c0c1878 100644
--- a/src/plugins/download.js
+++ b/src/plugins/download.js
@@ -1,79 +1,126 @@
-import axios from 'axios'
-import {Loading, Message} from 'element-ui'
-import { saveAs } from 'file-saver'
-import { getToken } from '@/utils/auth'
-import errorCode from '@/utils/errorCode'
+import axios from "axios";
+import { Loading, Message } from "element-ui";
+import { saveAs } from "file-saver";
+import { getToken } from "@/utils/auth";
+import errorCode from "@/utils/errorCode";
 import { blobValidate } from "@/utils/ruoyi";
 
-const baseURL = process.env.VUE_APP_BASE_API
+const baseURL = process.env.VUE_APP_BASE_API;
 let downloadLoadingInstance;
 
 export default {
   name(name, isDelete = true) {
-    var url = baseURL + "/common/download?fileName=" + encodeURIComponent(name) + "&delete=" + isDelete
+    var url =
+      baseURL +
+      "/common/download?fileName=" +
+      encodeURIComponent(name) +
+      "&delete=" +
+      isDelete;
     axios({
-      method: 'get',
+      method: "get",
       url: url,
-      responseType: 'blob',
-      headers: { 'Authorization': 'Bearer ' + getToken() }
+      responseType: "blob",
+      headers: { Authorization: "Bearer " + getToken() },
     }).then((res) => {
       const isBlob = blobValidate(res.data);
       if (isBlob) {
-        const blob = new Blob([res.data])
-        this.saveAs(blob, decodeURIComponent(res.headers['download-filename']))
+        const blob = new Blob([res.data]);
+        this.saveAs(blob, decodeURIComponent(res.headers["download-filename"]));
       } else {
         this.printErrMsg(res.data);
       }
-    })
+    });
   },
   resource(resource) {
-    var url = baseURL + "/common/download/resource?resource=" + encodeURIComponent(resource);
+    var url =
+      baseURL +
+      "/common/download/resource?resource=" +
+      encodeURIComponent(resource);
     axios({
-      method: 'get',
+      method: "get",
       url: url,
-      responseType: 'blob',
-      headers: { 'Authorization': 'Bearer ' + getToken() }
+      responseType: "blob",
+      headers: { Authorization: "Bearer " + getToken() },
     }).then((res) => {
       const isBlob = blobValidate(res.data);
       if (isBlob) {
-        const blob = new Blob([res.data])
-        this.saveAs(blob, decodeURIComponent(res.headers['download-filename']))
+        const blob = new Blob([res.data]);
+        this.saveAs(blob, decodeURIComponent(res.headers["download-filename"]));
       } else {
         this.printErrMsg(res.data);
       }
-    })
+    });
   },
   zip(url, name) {
-    var url = baseURL + url
-    downloadLoadingInstance = Loading.service({ text: "姝e湪涓嬭浇鏁版嵁锛岃绋嶅��", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", })
+    var url = baseURL + url;
+    downloadLoadingInstance = Loading.service({
+      text: "姝e湪涓嬭浇鏁版嵁锛岃绋嶅��",
+      spinner: "el-icon-loading",
+      background: "rgba(0, 0, 0, 0.7)",
+    });
     axios({
-      method: 'get',
+      method: "get",
       url: url,
-      responseType: 'blob',
-      headers: { 'Authorization': 'Bearer ' + getToken() }
-    }).then((res) => {
-      const isBlob = blobValidate(res.data);
-      if (isBlob) {
-        const blob = new Blob([res.data], { type: 'application/zip' })
-        this.saveAs(blob, name)
-      } else {
-        this.printErrMsg(res.data);
-      }
-      downloadLoadingInstance.close();
-    }).catch((r) => {
-      console.error(r)
-      Message.error('涓嬭浇鏂囦欢鍑虹幇閿欒锛岃鑱旂郴绠$悊鍛橈紒')
-      downloadLoadingInstance.close();
+      responseType: "blob",
+      headers: { Authorization: "Bearer " + getToken() },
     })
+      .then((res) => {
+        const isBlob = blobValidate(res.data);
+        if (isBlob) {
+          const blob = new Blob([res.data], { type: "application/zip" });
+          this.saveAs(blob, name);
+        } else {
+          this.printErrMsg(res.data);
+        }
+        downloadLoadingInstance.close();
+      })
+      .catch((r) => {
+        console.error(r);
+        Message.error("涓嬭浇鏂囦欢鍑虹幇閿欒锛岃鑱旂郴绠$悊鍛橈紒");
+        downloadLoadingInstance.close();
+      });
   },
   saveAs(text, name, opts) {
-    saveAs(text, name, opts);
+    if (typeof text === "string") {
+      // 璺緞涓嬭浇
+      saveAs(text, name, opts);
+      Message.success("鏁版嵁瀵煎嚭鎴愬姛");
+    } else {
+      // 娴佷笅杞�
+      blobToText(text)
+        .then((result) => {
+          Message.error(result.msg);
+        })
+        .catch(() => {
+          saveAs(text, name, opts);
+          Message.success("鏁版嵁瀵煎嚭鎴愬姛");
+        });
+    }
   },
   async printErrMsg(data) {
     const resText = await data.text();
     const rspObj = JSON.parse(resText);
-    const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
+    const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode["default"];
     Message.error(errMsg);
-  }
-}
+  },
+};
 
+// 灏哹lob杞垚鏂囨湰
+function blobToText(blob) {
+  return new Promise((resolve, reject) => {
+    const fileReader = new FileReader();
+    fileReader.readAsText(blob);
+    fileReader.onload = function () {
+      try {
+        const result = JSON.parse(this.result);
+        if (result && result["code"] !== 200) {
+          resolve(result);
+        } else {
+          reject();
+        }
+      } catch (e) {
+        reject();
+      }
+    };
+  });
+}

--
Gitblit v1.9.3