diff --git a/src/common/store/index.js b/src/common/store/index.js index b9c56be..303705c 100644 --- a/src/common/store/index.js +++ b/src/common/store/index.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-03-22 18:28:52 * @LastEditors: ch - * @LastEditTime: 2022-05-21 11:38:51 + * @LastEditTime: 2022-06-10 16:51:08 * @Description: file content */ import Vue from 'vue' @@ -17,16 +17,19 @@ const // 地址列表 ADDRESS = 'ads', // oppenId - OPPED_ID = 'oi'; + OPPED_ID = 'oi', + // 每个浏览器创建一个UUID作为同一个用户的标识 + UUID = 'uid';; export default new Vuex.Store({ state : { token : uni.getStorageSync(TOKEN) || '', userInfo : JSON.parse(uni.getStorageSync(USER_INFO) || '{}'), address : JSON.parse(uni.getStorageSync(ADDRESS) || '[]'), + openId : uni.getStorageSync(OPPED_ID) || '', + uuid : uni.getStorageSync(UUID) || '', imData : [], - imMsgCount : 0, - openId : uni.getStorageSync(OPPED_ID) || '' + imMsgCount : 0 }, mutations:{ SET_TOKEN (state, token = ''){ @@ -41,15 +44,19 @@ export default new Vuex.Store({ state.address = address; uni.setStorageSync(ADDRESS, JSON.stringify(address)); }, + SET_UUID (state, uid){ + state.uuid = uid; + uni.setStorageSync(UUID, uid); + }, + SET_OPEN_ID (state, data){ + state.openId = data; + uni.setStorageSync(OPPED_ID, data); + }, SET_IM_DATA (state, data){ state.imData = data ; }, SET_IM_MSG_COUNT (state, data){ state.imMsgCount = data; - }, - SET_OPEN_ID (state, data){ - state.openId = data; - uni.setStorageSync(OPPED_ID, data); } }, actions : { diff --git a/src/common/utils/requset.js b/src/common/utils/requset.js index aa673f8..473afb6 100644 --- a/src/common/utils/requset.js +++ b/src/common/utils/requset.js @@ -2,14 +2,21 @@ * @Author: ch * @Date: 2022-03-17 17:42:32 * @LastEditors: ch - * @LastEditTime: 2022-05-23 15:19:36 + * @LastEditTime: 2022-06-10 16:52:26 * @Description: 项目接口请求统一处理器,返回一个需要token和不需要token的请求封装方法 */ import MsbUniRequest from '@/common/plugins/msbUniRequest'; import $store from '@/common/store'; import ENV from '@/common/config/env'; +import { CreateUUID } from '@/common/utils'; +// 获取已有的UUID没则创建一个并保存到locaStorage中下次使用 +let uuid = $store.state.uuid +if (!uuid) { + uuid = CreateUUID(16, 2); + $store.commit('SET_UUID', uuid); +} /** * 接口返回成功结果统一处理 * @param {*} response @@ -85,6 +92,7 @@ MsbRequest.use('request', (option) => { return isRepeatVerify; } } + option.header.uid = uuid; return option; }) MsbRequest.use('success', successIntercept); @@ -98,6 +106,7 @@ MsbRequestTk.baseUrl = ENV.baseUrl; MsbRequestTk.use('request', (option) => { const token = $store.state.token; + option.header.uid = uuid; if(!token){ // 登录状态处理,没有token直接跳转至登录 uni.redirectTo({