diff --git a/package.json b/package.json index 4f3daa1..c36fa11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ruoyi", - "version": "3.8.7", + "version": "1.0.202405241500", "description": "金鸡湖现代服务业品牌管理系统", "author": "若依", "license": "MIT", diff --git a/src/main.js b/src/main.js index 4cc4dd7..329caac 100644 --- a/src/main.js +++ b/src/main.js @@ -5,6 +5,9 @@ import Cookies from "js-cookie"; import Element from "element-ui"; import "./assets/styles/element-variables.scss"; +// 引入package.json +import packageJson from '../package.json' + import "@/assets/styles/index.scss"; // global css import "@/assets/styles/ruoyi.scss"; // ruoyi css import App from "./App"; @@ -71,6 +74,14 @@ Vue.use(plugins); Vue.use(VueMeta); DictData.install(); +const version = packageJson.version +const localVersion = localStorage.getItem('projectVersion') +// 判断版本号是否一致 +if (!localVersion || version !== localVersion) { + localStorage.clear() // 清除缓存 + localStorage.setItem('projectVersion', version) +} + /** * If you don't want to use mock-server * you want to use MockJs for mock api diff --git a/src/versionPlugin.js b/src/versionPlugin.js new file mode 100644 index 0000000..6cb13e6 --- /dev/null +++ b/src/versionPlugin.js @@ -0,0 +1,28 @@ +const fs = require('fs') +const path = require('path') +const sep = path.sep + +function VersionPlugin (options) { + this.options = options || {} +} + +VersionPlugin.prototype.apply = function (compiler) { + var self = this + compiler.plugin('afterPlugins', function (params) { // 在 webpack 完成插件加载后执行 + const packageJsonPath = path.join(params.context, sep + 'package.json') // 获取 package.json 文件路径 + const dateStr = getDateStr() // 获取日期字符串 + let packageJsonStr = fs.readFileSync(packageJsonPath, 'utf8') // 读取 package.json 文件内容 + const r = new RegExp('(?<=version\\":\\s*\\")(.*)(?=")') // 构造正则表达式匹配 version 字段 + packageJsonStr = packageJsonStr.replace(r, "1.0." + dateStr) // 更新 version 字段 dateStr是当天的日期没有秒,获取到秒可能更好 ⌈ 自行判断是否需要 now.getSeconds() ⌋ + fs.writeFileSync(packageJsonPath, packageJsonStr, 'utf8') // 将更新后的内容写回 package.json 文件 + }) +} +function getDateStr () { + const now = new Date() + return now.getFullYear() + format(now.getMonth() + 1) + format(now.getDate()) + format(now.getHours()) + format(now.getMinutes()) + function format (num) { + return num < 10 ? '0' + num : '' + num + } +} + +module.exports = VersionPlugin \ No newline at end of file diff --git a/vue.config.js b/vue.config.js index ce8aab7..5f1e4c4 100644 --- a/vue.config.js +++ b/vue.config.js @@ -70,6 +70,10 @@ module.exports = { ], }, chainWebpack(config) { + const VersionPlugin = require('./src/versionPlugin') + config.plugin('version').use(VersionPlugin).tap(args => { + return args + }) config.plugins.delete("preload"); // TODO: need test config.plugins.delete("prefetch"); // TODO: need test