diff --git a/src/api/common.js b/src/api/common.js index 9897be59..6ae46633 100644 --- a/src/api/common.js +++ b/src/api/common.js @@ -4,6 +4,7 @@ import { import { getToken } from '@/common/common.js' +import common from '@/common/common'; export const uploadFile = (file, data) => { @@ -145,9 +146,11 @@ export function downloadVoiceFile(url) { url: `${baseUrl}${url}`, header, success(result) { + console.log(result) resolve(result) }, fail(error) { + console.log(error) reject(new Error(error)); } }); diff --git a/src/api/socket.js b/src/api/socket.js index 5abf5514..ca9c0b7d 100644 --- a/src/api/socket.js +++ b/src/api/socket.js @@ -26,13 +26,14 @@ export default class WebSocketUtil { close: [], // 连接关闭回调 error: [] // 错误处理回调 }; - this.init(); // 初始化WebSocket连接 + this.init(true); // 初始化WebSocket连接 } /** * 初始化WebSocket连接 */ - init() { + init(flag = false) { + if(flag) this.reconnectCount = 0 // 创建WebSocket连接 this.socketTask = uni.connectSocket({ url: this.url, @@ -59,7 +60,17 @@ export default class WebSocketUtil { // 监听WebSocket消息接收事件 this.socketTask.onMessage((res) => { - console.log('收到WebSocket消息', res); + if(res.data){ + const { rtnCode } = JSON.parse(res.data) + console.log('收到WebSocket消息', JSON.parse(res.data) ); + if(['0005', 'QQ0005'].includes(res.rtnCode)) { + goto_login_fun(); + return + } + }else{ + goto_login_fun(); + return + } this.triggerEvent('message', res); // 触发消息接收事件 }); @@ -198,6 +209,8 @@ export default class WebSocketUtil { } else { console.error('达到最大重连次数,停止尝试'); this.triggerEvent('error', new Error('达到最大重连次数')); + this.reconnectTimer = null + this.close() goto_login_fun() } } diff --git a/src/components/image-preview/image-preview.vue b/src/components/image-preview/image-preview.vue index a90318a2..23341f1b 100644 --- a/src/components/image-preview/image-preview.vue +++ b/src/components/image-preview/image-preview.vue @@ -4,7 +4,10 @@ diff --git a/src/store/storage.js b/src/store/storage.js new file mode 100644 index 00000000..c0ae35ff --- /dev/null +++ b/src/store/storage.js @@ -0,0 +1,52 @@ +import { defineStore } from 'pinia'; +import { ref } from 'vue'; + +export const useStorageStore = defineStore('storageStore',{ + state:()=>({ + imgObjStr: '{}', + videoObjStr: '{}', + audioObjStr: '{}' + }), + getters:{ + imgObj(state){ + return JSON.parse(state.imgObjStr) + }, + videoObj(state){ + return JSON.parse(state.videoObjStr) + }, + audioObj(state){ + return JSON.parse(state.audioObjStr) + } + }, + actions:{ + setStorage(type, id, url) { + if(type === 'image'){ + let _obj = JSON.parse(this.imgObjStr) + _obj[id] = url + this.imgObjStr = JSON.stringify(_obj) + }else if(type === 'video'){ + let _obj = JSON.parse(this.videoObjStr) + _obj[id] = url + this.videoObjStr = JSON.stringify(_obj) + }else if(type === 'audio'){ + let _obj = JSON.parse(this.audioObjStr) + _obj[id] = url + this.audioObjStr = JSON.stringify(_obj) + } + }, + getStorageById(type, id, cb = (()=>{})){ + // 两种方式 ,传递回调函数 或 直接取return值 + let _obj + if(type === 'image'){ + _obj = JSON.parse(this.imgObjStr) + }else if(type === 'video'){ + _obj = JSON.parse(this.videoObjStr) + }else if(type === 'audio'){ + _obj = JSON.parse(this.audioObjStr) + } + let _cache = _obj[id]||'' + cb && cb(_cache) + return _cache + } + } +}) \ No newline at end of file