From 0000e935d6c7f74cb6682aea1bbf24d8deade390 Mon Sep 17 00:00:00 2001 From: wwl <xchao828@163.com> Date: 星期四, 03 七月 2025 17:49:18 +0800 Subject: [PATCH] 1 --- src/main copy.js | 142 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 142 insertions(+), 0 deletions(-) diff --git a/src/main copy.js b/src/main copy.js new file mode 100644 index 0000000..30d4cab --- /dev/null +++ b/src/main copy.js @@ -0,0 +1,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 瑙f瀽鍚庢秷鎭�:', 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('娑堟伅瑙f瀽澶辫触:', 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; \ No newline at end of file -- Gitblit v1.8.0