修改清空缓存白屏现象
This commit is contained in:
parent
86503555ee
commit
52cfb19000
|
|
@ -9,7 +9,7 @@
|
||||||
import ThemePicker from '@/components/ThemePicker'
|
import ThemePicker from '@/components/ThemePicker'
|
||||||
import { mapActions } from 'vuex'
|
import { mapActions } from 'vuex'
|
||||||
import { get } from '@/utils/config'
|
import { get } from '@/utils/config'
|
||||||
import { setToken } from '@/utils/auth'
|
import { getToken, setToken } from '@/utils/auth'
|
||||||
|
|
||||||
// import AlertNotification from "@/views/warning/AlertNotification.vue";
|
// import AlertNotification from "@/views/warning/AlertNotification.vue";
|
||||||
|
|
||||||
|
|
@ -32,6 +32,12 @@ export default {
|
||||||
setToken(token)
|
setToken(token)
|
||||||
this.$router.push({ path: '/' })
|
this.$router.push({ path: '/' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 确保 Vuex store 中的 token 状态与 Cookie 同步
|
||||||
|
const cookieToken = getToken()
|
||||||
|
if (cookieToken && !this.$store.state.user.token) {
|
||||||
|
this.$store.commit('user/SET_TOKEN', cookieToken)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
metaInfo() {
|
metaInfo() {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ export default {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
socket: null,
|
socket: null,
|
||||||
wsUrl: JSON.parse(localStorage.getItem('systemConfig')).webSocketurl,//'ws://localhost:18082/ws', // WebSocket 端点
|
wsUrl: this.getWebSocketUrl(),//'ws://localhost:18082/ws', // WebSocket 端点
|
||||||
isConnected: false, // 连接状态
|
isConnected: false, // 连接状态
|
||||||
reconnectInterval: 5000 // 自动重连时间间隔(毫秒
|
reconnectInterval: 5000 // 自动重连时间间隔(毫秒
|
||||||
|
|
||||||
|
|
@ -117,12 +117,26 @@ export default {
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
// this.checkPasswordStatus()
|
// this.checkPasswordStatus()
|
||||||
|
// 确保 wsUrl 被正确初始化
|
||||||
|
this.wsUrl = this.getWebSocketUrl()
|
||||||
|
|
||||||
if (this.roles.includes("audit") || this.roles.includes("systemAdmin")) {
|
if (this.roles.includes("audit") || this.roles.includes("systemAdmin")) {
|
||||||
this.connectWebSocket();
|
this.connectWebSocket();
|
||||||
}
|
}
|
||||||
this.handleNoWarningLog()
|
this.handleNoWarningLog()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// 获取 WebSocket URL,处理 localStorage 可能为 null 的情况
|
||||||
|
getWebSocketUrl() {
|
||||||
|
try {
|
||||||
|
const systemConfig = JSON.parse(localStorage.getItem('systemConfig'))
|
||||||
|
return systemConfig && systemConfig.webSocketurl ? systemConfig.webSocketurl : 'ws://localhost:18082/ws'
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to get WebSocket URL:', error)
|
||||||
|
return 'ws://localhost:18082/ws'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
checkPasswordStatus() {
|
checkPasswordStatus() {
|
||||||
checkPasswordStatus().then(response => {
|
checkPasswordStatus().then(response => {
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,14 @@ const whiteList = ["/login", "/register", "/qrCode/qrCodePage","/screen/cityScre
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
NProgress.start();
|
NProgress.start();
|
||||||
if (getToken()) {
|
const token = getToken();
|
||||||
|
|
||||||
|
if (token) {
|
||||||
|
// 确保 Vuex store 中的 token 状态与 Cookie 同步
|
||||||
|
if (!store.state.user.token) {
|
||||||
|
store.commit('user/SET_TOKEN', token);
|
||||||
|
}
|
||||||
|
|
||||||
to.meta.title && store.dispatch("settings/setTitle", to.meta.title);
|
to.meta.title && store.dispatch("settings/setTitle", to.meta.title);
|
||||||
/* has token*/
|
/* has token*/
|
||||||
if (to.path === "/login") {
|
if (to.path === "/login") {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,14 @@
|
||||||
const systemConfig = JSON.parse(localStorage.getItem('systemConfig'));
|
// 获取系统配置,处理 localStorage 可能为 null 的情况
|
||||||
|
function getSystemConfig() {
|
||||||
|
try {
|
||||||
|
const config = JSON.parse(localStorage.getItem('systemConfig'))
|
||||||
|
return config || {}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to parse systemConfig:', error)
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} path
|
* @param {string} path
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
|
|
@ -92,10 +102,14 @@ export function validPwd(value) {
|
||||||
|
|
||||||
export function validateNewPassword(rule, value, callback) {
|
export function validateNewPassword(rule, value, callback) {
|
||||||
// 使用配置文件中的策略进行验证
|
// 使用配置文件中的策略进行验证
|
||||||
|
const systemConfig = getSystemConfig()
|
||||||
|
const passwordConfig = systemConfig.passwordConfig || {}
|
||||||
|
|
||||||
// 1. 检查密码长度
|
// 1. 检查密码长度
|
||||||
if (value.length < systemConfig.passwordConfig.minLength || value.length > systemConfig.passwordConfig.maxLength) {
|
const minLength = passwordConfig.minLength || 8
|
||||||
callback(new Error('密码长度应为' + systemConfig.passwordConfig.minLength + '至' + systemConfig.passwordConfig.maxLength + '位!'))
|
const maxLength = passwordConfig.maxLength || 20
|
||||||
|
if (value.length < minLength || value.length > maxLength) {
|
||||||
|
callback(new Error('密码长度应为' + minLength + '至' + maxLength + '位!'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,24 +119,25 @@ export function validateNewPassword(rule, value, callback) {
|
||||||
const hasDigit = /\d/.test(value)
|
const hasDigit = /\d/.test(value)
|
||||||
const hasSpecialChar = /[!@#$%^&*(),.?":{}|<>]/.test(value)
|
const hasSpecialChar = /[!@#$%^&*(),.?":{}|<>]/.test(value)
|
||||||
|
|
||||||
if (systemConfig.passwordConfig.requireUpperCase && !hasUpperCase) {
|
if (passwordConfig.requireUpperCase && !hasUpperCase) {
|
||||||
callback(new Error('密码必须包含大写字母!'))
|
callback(new Error('密码必须包含大写字母!'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (systemConfig.passwordConfig.requireLowerCase && !hasLowerCase) {
|
if (passwordConfig.requireLowerCase && !hasLowerCase) {
|
||||||
callback(new Error('密码必须包含小写字母!'))
|
callback(new Error('密码必须包含小写字母!'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (systemConfig.passwordConfig.requireDigit && !hasDigit) {
|
if (passwordConfig.requireDigit && !hasDigit) {
|
||||||
callback(new Error('密码必须包含数字!'))
|
callback(new Error('密码必须包含数字!'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (systemConfig.passwordConfig.requireSpecialChar && !hasSpecialChar) {
|
if (passwordConfig.requireSpecialChar && !hasSpecialChar) {
|
||||||
callback(new Error('密码必须包含特殊字符!'))
|
callback(new Error('密码必须包含特殊字符!'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 3. 检查是否包含弱密码
|
// 3. 检查是否包含弱密码
|
||||||
for (const weakPwd of systemConfig.passwordConfig.weakPasswords) {
|
const weakPasswords = passwordConfig.weakPasswords || []
|
||||||
|
for (const weakPwd of weakPasswords) {
|
||||||
// 将密码和弱密码都转换为小写进行比较
|
// 将密码和弱密码都转换为小写进行比较
|
||||||
if (value.toLowerCase().includes(weakPwd.toLowerCase())) {
|
if (value.toLowerCase().includes(weakPwd.toLowerCase())) {
|
||||||
callback(new Error(`密码包含常见的弱密码片段: ${weakPwd}`))
|
callback(new Error(`密码包含常见的弱密码片段: ${weakPwd}`))
|
||||||
|
|
@ -130,8 +145,10 @@ export function validateNewPassword(rule, value, callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 4. 检查是否包含超过规定数量的连续字符
|
// 4. 检查是否包含超过规定数量的连续字符
|
||||||
if (systemConfig.passwordConfig.restrictConsecutiveChars && containsConsecutiveCharacters(value, systemConfig.passwordConfig.maxConsecutiveChars)) {
|
const restrictConsecutiveChars = passwordConfig.restrictConsecutiveChars || false
|
||||||
callback(new Error(`密码不能包含超过${systemConfig.passwordConfig.maxConsecutiveChars}位连续字符!`))
|
const maxConsecutiveChars = passwordConfig.maxConsecutiveChars || 3
|
||||||
|
if (restrictConsecutiveChars && containsConsecutiveCharacters(value, maxConsecutiveChars)) {
|
||||||
|
callback(new Error(`密码不能包含超过${maxConsecutiveChars}位连续字符!`))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
callback() // 验证成功
|
callback() // 验证成功
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue