Browse Source

版本自动更新功能

dev_web_online
陈薪名 2 years ago
parent
commit
9854499f5a
  1. 1
      fe/PC/public/config.js
  2. 3
      fe/PC/public/version.json
  3. 8
      fe/PC/src/api/wms-api.js
  4. 5
      fe/PC/src/components/News/index.vue
  5. 1
      fe/PC/src/main.js
  6. 2
      fe/PC/src/permission.js
  7. 3
      fe/PC/src/utils/request.js
  8. 29
      fe/PC/src/utils/upDateVersion.js
  9. 6
      fe/PC/vue.config.js

1
fe/PC/public/config.js

@ -19,6 +19,7 @@ window.SITE_CONFIG['warehouseCode'] = 'T8'
window.SITE_CONFIG['company'] = 'DongYang'
window.SITE_CONFIG['client_secret'] = '1q2w3E*'
window.SITE_CONFIG['reportsUrl'] = 'http://dev.ccwin-in.com:60074/#/reports/'
window.SITE_CONFIG['versionUrl'] = 'http://dev.ccwin-in.com:60070'
// mock
// window.SITE_CONFIG['apifoxToken'] = 'NXHNi5mp0dnUHGt0wkCrjvfcidsFKV33'

3
fe/PC/public/version.json

@ -0,0 +1,3 @@
{
"version": "1.0.6"
}

8
fe/PC/src/api/wms-api.js

@ -557,6 +557,14 @@ export function getOneCustomerInfoByCode(code) {
method: 'get'
})
}
// 获取版本编号
export function getVsersion() {
return request({
url: window.SITE_CONFIG['versionUrl'] + `/version.json?t=${new Date().getTime()}`,
method: 'get'
})
}
// 根据编号获取字典信息
// export function getDictByCode(code) {
// return request({

5
fe/PC/src/components/News/index.vue

@ -12,6 +12,7 @@
<script>
import { userNotifyNotReadList, userNotifyHasRead, userNotifyMessageNotReadList, userNotifyMessageUpdate, notifyMessage, getPageList } from "@/api/wms-api"
import dialogIndex from "@/components/News/dialogIndex"
import { updateVersion } from '@/utils/upDateVersion'
export default {
name: 'News',
data() {
@ -27,12 +28,16 @@ export default {
this.userId = this.$store.getters.name.id
this.getNoReadCount(this.userId)
this.getSetInterval()
//
updateVersion()
},
methods: {
getSetInterval() {
let that = this
setInterval(function () {
that.getNoReadCount(that.userId)
//
updateVersion()
},120000)
},
getNoReadCount(userId) {

1
fe/PC/src/main.js

@ -45,7 +45,6 @@ Vue.prototype.defaultExportBtn = defaultExportBtn;
import * as filters from './filters' // global filters
console.log("V421.20.52.win");
/**
* If you don't want to use mock-server
* you want to use MockJs for mock api

2
fe/PC/src/permission.js

@ -21,7 +21,7 @@ const whiteList = ['/login', '/auth-redirect', '/testForm'] // no redirect white
router.beforeEach(async (to, from, next) => {
// 添加路由信息,方便代码修改定位
console.log('----------------' + to.meta.title + '-----------------------'+ to.fullPath.substring(to.fullPath.lastIndexOf('-')+1,to.fullPath.length) + '.vue' );
// console.log('----------------' + to.meta.title + '-----------------------'+ to.fullPath.substring(to.fullPath.lastIndexOf('-')+1,to.fullPath.length) + '.vue' );
// start progress bar
NProgress.start()

3
fe/PC/src/utils/request.js

@ -7,7 +7,6 @@ import store from '@/store'
import {
getToken
} from '@/utils/auth'
import { updateVersion } from '@/utils/upDateVersion'
// create an axios instance
const service = axios.create({
@ -22,8 +21,6 @@ service.interceptors.request.use(
// do something before request is sent
if (store.getters.token) {
// 检测版本是否有更新
updateVersion()
// let each request carry token
// ['X-Token'] is a custom headers key
// please modify it according to the actual situation

29
fe/PC/src/utils/upDateVersion.js

@ -1,20 +1,31 @@
/**
* 检测版本更新
* 检测版本更新 触发机制在 news/index 跟随消息定时器一并触发
*/
import Vue from 'vue'
import { getVsersion } from '@/api/wms-api'
export function updateVersion () {
const versionConfig = process.env.VUE_APP_INFO
let version = localStorage.getItem('upDateVersion')
if (version != versionConfig) {
localStorage.setItem('upDateVersion', versionConfig)
setTimeout(() => {
save()
}, 1000 * 3)
let versionConfig = ''
// dev模式不开启更新功能
if (window.SITE_CONFIG['versionUrl'] && process.env.NODE_ENV != 'development') {
getVsersion().then(res => {
versionConfig = res.version
if (versionConfig) {
let version = localStorage.getItem('upDateVersion')
if (version != versionConfig) {
localStorage.setItem('upDateVersion', versionConfig)
setTimeout(() => {
save()
}, 1000 * 3)
}
}
}).catch(err => {
console.log(err)
})
}
}
function save () {
var vm = new Vue()
vm.$message.success('正在更新, 预计5秒后更新完成')
vm.$message.warning('有新版本发布,自动更新升级中')
setTimeout(() => {
vm.$message.success('更新完成')
}, 1000 * 3)

6
fe/PC/vue.config.js

@ -8,12 +8,6 @@ function resolve(dir) {
const name = defaultSettings.title || '基础数据管理网站' // page title
const pkg = require('./package.json')
const info = {
...pkg
}
process.env.VUE_APP_INFO = info.version
// If your port is set to 80,
// use administrator privileges to execute the command line.
// For example, Mac: sudo npm run

Loading…
Cancel
Save