1
wwl
12 小时以前 0000e935d6c7f74cb6682aea1bbf24d8deade390
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// src/main.js
import Vue from "vue";
import Cookies from "js-cookie";
import "babel-polyfill";
import Element from "element-ui";
import "./assets/styles/element-variables.scss";
import "@/assets/styles/index.scss";
import "@/assets/styles/ruoyi.scss";
import App from "./App";
import store from "./store";
import router from "./router";
import directive from "./directive";
import plugins from "./plugins";
import { download } from "@/utils/request";
import Print from "vue-print-nb";
import JsonExcel from "vue-json-excel";
import "./assets/icons";
import "./permission";
import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import {
  parseTime,
  resetForm,
  addDateRange,
  selectDictLabel,
  selectDictLabels,
  handleTree,
} from "@/utils/ruoyi";
import Pagination from "@/components/Pagination";
import Editor from "@/components/Editor";
import FileUpload from "@/components/FileUpload";
import ImageUpload from "@/components/ImageUpload";
import ImagePreview from "@/components/ImagePreview";
import DictTag from "@/components/DictTag";
import VueMeta from "vue-meta";
import DictData from "@/components/DictData";
import * as echarts from "echarts";
import VueBarcode from "vue-barcode";
import { initWebSocket, closeWebSocket } from "@/utils/websocket";
 
Vue.component("downloadExcel", JsonExcel);
Vue.component("barcode", VueBarcode);
Vue.component("DictTag", DictTag);
Vue.component("Pagination", Pagination);
Vue.component("Editor", Editor);
Vue.component("FileUpload", FileUpload);
Vue.component("ImageUpload", ImageUpload);
Vue.component("ImagePreview", ImagePreview);
 
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.$echarts = echarts;
 
Vue.prototype.$showNotification = function (type, title, message, onClick) {
  console.log('触发通知:', { type, title, message });
  Vue.prototype.$notify({
    title,
    message,
    type,
    duration: 5000,
    position: 'top-right',
    offset: 50,
    onClick,
    customClass: 'global-notification',
    appendTo: document.body
  });
};
 
// 监听路由变化
router.afterEach(() => {
  console.log('路由切换完成,当前路径:', router.currentRoute.path);
});
 
const app = new Vue({
  el: "#app",
  router,
  store,
  render: (h) => h(App),
  mounted() {
    const token = store.state.user.token || Cookies.get('token') || '';
    if (token) {
      console.log('Token:', token);
      initWebSocket(token, (type, data) => {
        if (type === 'error') {
          Vue.prototype.$showNotification('error', '错误', data);
          return;
        }
        try {
          const message = JSON.parse(data);
          console.log('WebSocket 解析后消息:', message);
          if (message.noticeId && message.noticeTitle) {
            const noticeTypeLabel = message.noticeType === '1' ? '通知' : '公告';
            const contentPreview = message.noticeContent
              ? message.noticeContent.replace(/<[^>]+>/g, '').substring(0, 20) + '...'
              : '无内容';
            Vue.prototype.$showNotification(
              'success',
              `新${noticeTypeLabel}`,
              `${message.noticeTitle} - ${contentPreview}`,
              () => {
          
                router.push({
                  path: '/redirect/notice',
                  query: { noticeId: message.noticeId }
                });
              }
            );
          } else {
            console.log('未知消息类型:', message);
            Vue.prototype.$showNotification('info', '消息', '收到未知格式的消息');
          }
        } catch (error) {
          console.error('消息解析失败:', error, '原始数据:', data);
          Vue.prototype.$showNotification('info', '消息', `服务器回应字符串: ${data}`);
        }
      });
    } else {
      console.error('未找到 token,无法初始化 WebSocket');
    }
  },
  beforeDestroy() {
    closeWebSocket(); // 清理 WebSocket
  }
});
 
Vue.use(directive);
Vue.use(plugins);
Vue.use(VueMeta);
Vue.use(Print);
Vue.use(Element, {
  size: Cookies.get("size") || "medium",
});
DictData.install();
 
Vue.config.productionTip = false;