微信小程序适配+登录失效直接跳转到首页
parent
2b69bf0d33
commit
d59312b159
|
|
@ -15,9 +15,12 @@ const MQTT_CONFIG = {
|
||||||
username: 'admin', // 替换为通用账号
|
username: 'admin', // 替换为通用账号
|
||||||
password: 'Admin#12345678', // 替换为通用密码
|
password: 'Admin#12345678', // 替换为通用密码
|
||||||
clean: true,
|
clean: true,
|
||||||
|
host: '122.51.109.52',
|
||||||
|
port: 9001,
|
||||||
reconnectPeriod: 5000, // 重连间隔
|
reconnectPeriod: 5000, // 重连间隔
|
||||||
connectTimeout: 10000, // 连接超时
|
connectTimeout: 10000, // 连接超时
|
||||||
keepalive: 60 // 心跳时间
|
keepalive: 60, // 心跳时间
|
||||||
|
protocol: 'ws'
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===================== MQTT全局状态管理 =====================
|
// ===================== MQTT全局状态管理 =====================
|
||||||
|
|
@ -71,8 +74,19 @@ export function connectMqtt() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 创建客户端实例(同步操作)
|
// 创建客户端实例(同步操作)
|
||||||
mqttState.client = mqtt.connect(MQTT_CONFIG.server, mqttState.options)
|
// mqttState.client = mqtt.connect(MQTT_CONFIG.server, mqttState.options)
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
MQTT_CONFIG.protocol = 'wxs';
|
||||||
|
// #endif
|
||||||
|
mqttState.client = mqtt.connect({
|
||||||
|
host: MQTT_CONFIG.host,
|
||||||
|
port: MQTT_CONFIG.port,
|
||||||
|
clientId: mqttState.options.clientId,
|
||||||
|
username: MQTT_CONFIG.username,
|
||||||
|
password: MQTT_CONFIG.password,
|
||||||
|
// 关键:指定用小程序的Socket
|
||||||
|
protocol: MQTT_CONFIG.protocol // 或'ws',根据你的MQTT服务协议
|
||||||
|
})
|
||||||
// 监听核心事件(异步,同步更新状态)
|
// 监听核心事件(异步,同步更新状态)
|
||||||
mqttState.client.on('connect', () => {
|
mqttState.client.on('connect', () => {
|
||||||
console.log('MQTT连接成功')
|
console.log('MQTT连接成功')
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -38,13 +38,17 @@ const request = config => {
|
||||||
const code = res.data.code || 200
|
const code = res.data.code || 200
|
||||||
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
||||||
if (code === 401) {
|
if (code === 401) {
|
||||||
showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
|
|
||||||
if (res.confirm) {
|
|
||||||
store.dispatch('LogOut').then(res => {
|
store.dispatch('LogOut').then(res => {
|
||||||
uni.reLaunch({ url: '/pages/login' })
|
uni.reLaunch({ url: '/pages/login' })
|
||||||
})
|
})
|
||||||
}
|
// todo
|
||||||
})
|
// showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
|
||||||
|
// if (res.confirm) {
|
||||||
|
// store.dispatch('LogOut').then(res => {
|
||||||
|
// uni.reLaunch({ url: '/pages/login' })
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// })
|
||||||
reject('无效的会话,或者会话已过期,请重新登录。')
|
reject('无效的会话,或者会话已过期,请重新登录。')
|
||||||
} else if (code === 500) {
|
} else if (code === 500) {
|
||||||
toast(msg)
|
toast(msg)
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,16 @@ const upload = config => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
resolve(result)
|
resolve(result)
|
||||||
} else if (code == 401) {
|
} else if (code == 401) {
|
||||||
showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => {
|
// todo
|
||||||
if (res.confirm) {
|
// showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => {
|
||||||
|
// if (res.confirm) {
|
||||||
|
// store.dispatch('LogOut').then(res => {
|
||||||
|
// uni.reLaunch({ url: '/pages/login/login' })
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// })
|
||||||
store.dispatch('LogOut').then(res => {
|
store.dispatch('LogOut').then(res => {
|
||||||
uni.reLaunch({ url: '/pages/login/login' })
|
uni.reLaunch({ url: '/pages/login' })
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
reject('无效的会话,或者会话已过期,请重新登录。')
|
reject('无效的会话,或者会话已过期,请重新登录。')
|
||||||
} else if (code === 500) {
|
} else if (code === 500) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue