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