From 4381520f3c438f33cc82f835baabfd2fa8e70501 Mon Sep 17 00:00:00 2001 From: wangyifeng <812766448@qq.com> Date: Thu, 10 Apr 2025 11:30:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B8=85=E9=99=A4=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=97=B6=E5=90=8C=E6=97=B6=E6=B8=85=E7=90=86=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E8=AE=B0=E5=BD=95=E7=BC=93=E5=AD=98=EF=BC=9B=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=89=93=E5=8C=85=E7=BC=96=E8=AF=91=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=94=A8=E6=97=B6=E9=97=B4=E6=88=B3=E7=BB=B4=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 6 +++- vite.config.js | 82 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 63 insertions(+), 25 deletions(-) diff --git a/src/main.js b/src/main.js index fae97a9..c434bc6 100644 --- a/src/main.js +++ b/src/main.js @@ -16,7 +16,8 @@ import { vLoading } from '@/components/x-loading/index.js' import messagePopup from '@/components/x-message/useMessagePopup' import pageAnimation from '@/components/page-animation/index.vue' import * as plugins from './plugins' -import { useDialogueStore, useTalkStore, useUserStore } from '@/store' +import { useDialogueStore, useTalkStore, useUserStore, useDialogueListStore } from '@/store' +import {uniStorage} from "@/utils/uniStorage.js" const { showMessage } = messagePopup() dayjs.locale('zh-cn') @@ -92,6 +93,9 @@ export function createApp() { //处理OA、墨册强制刷新时,聊天同步强制刷新 window.doLocationRefresh = () => { + //同时先清除聊天记录缓存 + useDialogueListStore().dialogueList.value = [] + uniStorage.removeItem('dialogueList') location.reload(true) } diff --git a/vite.config.js b/vite.config.js index ae2c9d7..34b27e9 100644 --- a/vite.config.js +++ b/vite.config.js @@ -15,10 +15,14 @@ export default defineConfig({ resolve: { alias: [ { - find: "@", - replacement: resolve(process.cwd(), 'src') - } - ] + find: '@', + replacement: resolve(process.cwd(), 'src'), + }, + { + find: '@/static', + replacement: resolve(__dirname, 'src/static'), + }, + ], }, server: { host: '0.0.0.0', // 监听所有网络接口 @@ -28,9 +32,9 @@ export default defineConfig({ '/pag': { target: 'https://cdn.tmui.design', changeOrigin: true, - rewrite: (path) => path.replace(/^\/api/, '/api') + rewrite: (path) => path.replace(/^\/api/, '/api'), }, - } + }, }, plugins: [ Uni(), @@ -44,39 +48,69 @@ export default defineConfig({ 'useDialog', 'useMessage', 'useNotification', - 'useLoadingBar' - ] - } - ] + 'useLoadingBar', + ], + }, + ], }), Components({ - resolvers: [NaiveUiResolver()] - }) + resolvers: [NaiveUiResolver()], + }), ], build: { rollupOptions: { output: { - // 输出重构 打包编译后的js文件名称,添加时间戳 - entryFileNames: `js/[name].${timestamp}.js`, - chunkFileNames: `js/[name].${timestamp}.js`, - assetFileNames: `[ext]/[name].${timestamp}.[ext]`, - // 确保 Vue 文件编译后的 JS 文件也添加时间戳 - manualChunks: { - 'vue': ['vue'] - } - } - } + entryFileNames(chunkInfo) { + return `static/js/${chunkInfo.name}.${timestamp}.js` + }, + //需要注释掉 @dcloudio/uni-h5-vite/dist/plugin/config.js 中的同名方法,不然不会生效 + chunkFileNames: (chunkInfo) => { + const facadeModuleId = chunkInfo.facadeModuleId + ? chunkInfo.facadeModuleId.split('/') + : [] + //console.log(facadeModuleId); + if (chunkInfo.facadeModuleId?.length) { + const fileName = `pages-${ + facadeModuleId[facadeModuleId.length - 2] + }-${facadeModuleId[facadeModuleId.length - 1]}` + console.log('正在打包' + fileName) + return `static/js/${fileName}.${timestamp}.js` + } else { + console.log('正在打包', `static/js/[name].${timestamp}.js`) + return `static/js/[name].${timestamp}.js` + } + }, + // 资源文件像 字体,图片等 + assetFileNames: (assetInfo) => { + if ( + assetInfo.name && + assetInfo.type === 'asset' && + /\.(jpe?g|png|gif|svg)$/i.test(assetInfo.name) + ) { + return 'static/images/[name].[hash].[ext]' + } + if ( + assetInfo.name && + assetInfo.type === 'asset' && + /\.(ttf|woff|woff2|eot)$/i.test(assetInfo.name) + ) { + return 'static/fonts/[name].[hash].[ext]' + } + return 'static/[ext]/[name]-[hash].[ext]' + }, + }, + }, }, css: { extract: { // css重构 打包编译后的css文件名称,添加时间戳 filename: `css/[name].${timestamp}.css`, - chunkFilename: `css/[name].${timestamp}.css` + chunkFilename: `css/[name].${timestamp}.css`, }, preprocessorOptions: { scss: { additionalData: `@import "@/static/css/color.scss";`, }, }, - } + }, })