ezhizao_zx 5 bulan lalu
induk
melakukan
0039427c5d
5 mengubah file dengan 28 tambahan dan 2 penghapusan
  1. 1 0
      package.json
  2. 3 0
      src/eventBus.js
  3. 7 0
      src/main.js
  4. 6 2
      src/utils/request.js
  5. 11 0
      src/views/dialog/notification.vue

+ 1 - 0
package.json

@@ -29,6 +29,7 @@
     "jsencrypt": "3.3.1",
     "jszip": "^3.10.1",
     "lodash-es": "^4.17.21",
+    "mitt": "^3.0.1",
     "moment": "^2.29.4",
     "nprogress": "0.2.0",
     "pinia": "2.0.22",

+ 3 - 0
src/eventBus.js

@@ -0,0 +1,3 @@
+import mitt from 'mitt';
+const emitter = mitt();
+export default emitter;

+ 7 - 0
src/main.js

@@ -11,6 +11,7 @@ import VxeUI from 'vxe-pc-ui'
 import 'vxe-pc-ui/lib/style.css'
 
 import moment from 'moment'
+import emitter from './eventBus';
 moment.locale('zh-cn')
 
 import './assets/font-awesome-4.7.0/css/font-awesome.min.css'
@@ -91,6 +92,12 @@ app.component('Editor', Editor)
 app.component('CountTo', CountTo)
 app.component('Notification', Notification)
 
+app.config.globalProperties.$emitter = emitter;
+
+app.config.globalProperties.$showDialog = function (message) {
+  emitter.emit('show-dialog', message);
+};
+
 // const globalDialogInstance = app._context.components.Notification;
 
 // app.config.globalProperties.$showDialog = function (data) {

+ 6 - 2
src/utils/request.js

@@ -6,7 +6,8 @@ import { tansParams, blobValidate } from '@/utils/ruoyi'
 import cache from '@/plugins/cache'
 import { saveAs } from 'file-saver'
 import useUserStore from '@/store/modules/user'
-import notification from '../views/dialog/notification.vue'
+// import notification from '../views/dialog/notification.vue'
+import emitter from '../eventBus'
 // import { getCurrentInstance } from 'vue';
 // import { reject } from 'lodash-es'
 
@@ -49,7 +50,7 @@ service.interceptors.request.use(
     let requestable = true
     let notifications = []
     // 当登录状态为已登录时才可以获取公告
-    console.log(config)
+    // console.log(config)
     if (getToken() && !isToken && tenantInfo && config.url != '/ezhizao-dms-sys/getInfo' && config.url != '/ezhizao-dms-sys/getRouters') {
       // 所有条件都具备的情况下需先请求公告
       let url = import.meta.env.VITE_APP_BASE_API + '/business/notification/getUnshowedNotification'
@@ -236,6 +237,9 @@ export function downloadPdf(url, params, filename, config) {
 }
 
 function showDialog(message) {
+  // console.log(message, emitter)
+  emitter.emit('show-dialog', message)
+  console.log(emitter)
   // const instance = getCurrentInstance();
   // console.log(instance)
   // if (instance && instance.proxy && instance.proxy.showNotification) {

+ 11 - 0
src/views/dialog/notification.vue

@@ -10,13 +10,24 @@
   </el-dialog>
 </template>
 <script setup>
+import emitter from '../../eventBus';
 const title = ref('测试公告')
 const content = ref('测试公告内容')
 const visible = ref(false)
 const open = () => {
+  console.log('notification show')
   visible.value = true
 }
 const close = () => {
   visible.value = false
 }
+onMounted(() => {
+  console.log('mounted notification')
+  console.log(emitter)
+  emitter.on('show-dialog', open);
+});
+
+onUnmounted(() => {
+  emitter.off('show-dialog');
+});
 </script>