From 034020d5f97862edb276b164df866dfe019a3439 Mon Sep 17 00:00:00 2001 From: jiangjunjie Date: Fri, 18 Sep 2026 17:03:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4set=5F=E6=94=B9=E6=88=90set+?= =?UTF-8?q?=E5=A4=A7=E5=86=99=E5=AD=97=E6=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/index.js | 639 +++++++++++++++++++--------------- src/tests/store-smoke.test.js | 29 ++ src/utils/utils.js | 4 +- src/views/chat.vue | 133 +++---- 4 files changed, 467 insertions(+), 338 deletions(-) create mode 100644 src/tests/store-smoke.test.js diff --git a/src/store/index.js b/src/store/index.js index c27590b..272a678 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,5 +1,5 @@ import { defineStore } from 'pinia' -import { computed, ref } from 'vue' +import { ref } from 'vue' import { Toast, Dialog } from 'vant' import { fetchPost, upLoadImgHttp } from '@/utils/https' @@ -8,16 +8,19 @@ import FormatDate from '@/utils/filters' import utils from '@/utils/utils' import { Decryption, DecryptionECB, Encrypt } from '@/utils' import _ from 'lodash' + // 幂等键统一采用用户消息前缀,便于和后端日志对齐排查。 const createIdempotentKey = () => `user_msg_${Date.now()}` export const UPDATE_DIRECTION = 'UPDATE_DIRECTION' -let token = sessionStorage.token ? sessionStorage.token : '' -let userId = localStorage.userId ? localStorage.userId : '' -let source = localStorage.source ? localStorage.source : '' -let planCode = localStorage.planCode ? localStorage.planCode : '' -let entrance = localStorage.entrance ? localStorage.entrance : '' + +// —— 模块级初始值(加 initial 前缀,避免与 setup 内同名 ref 产生 TDZ/遮蔽问题)—— +const initialToken = sessionStorage.token ? sessionStorage.token : '' +const initialUserId = localStorage.userId ? localStorage.userId : '' +const initialSource = localStorage.source ? localStorage.source : '' +const initialPlanCode = localStorage.planCode ? localStorage.planCode : '' +const initialEntrance = localStorage.entrance ? localStorage.entrance : '' // 取到身份证后解密 -let userInfo = localStorage.userInfo ? JSON.parse(localStorage.userInfo) : {} +const initialUserInfo = localStorage.userInfo ? JSON.parse(localStorage.userInfo) : {} // try { // if(!!userInfo.versionNo1){ // const year = new Date().getFullYear() @@ -33,61 +36,62 @@ let userInfo = localStorage.userInfo ? JSON.parse(localStorage.userInfo) : {} // } // } // } catch (error) { } -let configId = localStorage.configId ? localStorage.configId : '' -let sessionId = localStorage.sessionId ? localStorage.sessionId : '' - -let auStatus = localStorage.auStatus ? localStorage.auStatus : '' -let bStatus = localStorage.bStatus ? localStorage.bStatus : '' -let bthdate = localStorage.bthdate ? localStorage.bthdate : '' -let workNum = localStorage.workNum ? localStorage.workNum : '' -let htmlExtParams = localStorage.htmlExtParams ? localStorage.htmlExtParams : '' -let complaint = localStorage.complaint ? localStorage.complaint : '' -let navigationCorpus = localStorage.navigationCorpus ? localStorage.navigationCorpus : '' - -// let manualService = sessionStorage.manualService ? sessionStorage.manualService : ''; //1机器人 2人工 -let headerAvatar = localStorage.headerAvatar ? JSON.parse(localStorage.headerAvatar) : {} -let sysConfig = localStorage.sysConfig ? localStorage.sysConfig : '' -let isLeaveMessageSuccess = sessionStorage.isLeaveMessageSuccess +const initialConfigId = localStorage.configId ? localStorage.configId : '' +const initialSessionId = localStorage.sessionId ? localStorage.sessionId : '' + +const initialHtmlExtParams = localStorage.htmlExtParams ? localStorage.htmlExtParams : '' +const initialComplaint = localStorage.complaint ? localStorage.complaint : '' +const initialNavigationCorpus = localStorage.navigationCorpus ? localStorage.navigationCorpus : '' + +const initialHeaderAvatar = localStorage.headerAvatar ? JSON.parse(localStorage.headerAvatar) : {} +const initialSysConfig = localStorage.sysConfig ? localStorage.sysConfig : '' +const initialIsLeaveMessageSuccess = sessionStorage.isLeaveMessageSuccess ? sessionStorage.isLeaveMessageSuccess : false //留言是否成功 // 聊天消息 数据 -let chatList = localStorage.chatList ? JSON.parse(localStorage.chatList) : [] +const initialChatList = localStorage.chatList ? JSON.parse(localStorage.chatList) : [] + +const initialSendMessageList = localStorage.sendMessageList + ? JSON.parse(localStorage.sendMessageList) + : [] -let sendMessageList = localStorage.sendMessageList ? JSON.parse(localStorage.sendMessageList) : [] -let receiveMessageList = localStorage.receiveMessageList +const initialReceiveMessageList = localStorage.receiveMessageList ? JSON.parse(localStorage.receiveMessageList) : [] export const useAppStore = defineStore('app', () => { // Session 相关状态(原 apiState) - const token = ref(token) - const userId = ref(userId) - const configId = ref(configId) - const sessionId = ref(sessionId) - const source = ref(source) - const planCode = ref(planCode) - const entrance = ref(entrance) + const token = ref(initialToken) + const userId = ref(initialUserId) + const configId = ref(initialConfigId) + const sessionId = ref(initialSessionId) + const source = ref(initialSource) + const planCode = ref(initialPlanCode) + const entrance = ref(initialEntrance) const elder = ref(true) - const headerAvatar = ref(headerAvatar) - const htmlExtParams = ref(htmlExtParams) - const complaint = ref(complaint) - const navigationCorpus = ref(navigationCorpus) + const notitle = ref('') + const userInfo = ref(initialUserInfo) + const sysConfig = ref(initialSysConfig) + const headerAvatar = ref(initialHeaderAvatar) + const htmlExtParams = ref(initialHtmlExtParams) + const complaint = ref(initialComplaint) + const navigationCorpus = ref(initialNavigationCorpus) const routeAction = ref('push') const direction = ref('forward') const mescrollContent = ref('') const isLeaveMessage = ref(false) - const isLeaveMessageSuccess = ref(isLeaveMessageSuccess) + const isLeaveMessageSuccess = ref(initialIsLeaveMessageSuccess) const manualService = ref(1) const queuedTimeout = ref(false) const sendLoading = ref(false) const isSendSuccess = ref(false) const timestamp = ref(0) const sendParmas = ref({}) - const chatList = ref(chatList) - const sendMessageList = ref(sendMessageList) - const receiveMessageList = ref(receiveMessageList) - const chatId = ref(chatId) + const chatList = ref(initialChatList) + const sendMessageList = ref(initialSendMessageList) + const receiveMessageList = ref(initialReceiveMessageList) + const chatId = ref('') const currentItemId = ref('') const issubmit = ref(true) const otherTips = ref('') @@ -120,397 +124,435 @@ export const useAppStore = defineStore('app', () => { const isBqCalcClaim = ref(false) const msgReply = ref(true) const hotUserData = ref(null) + const branchCompany = ref('') - function setIsBqCalcClaim(isBqCalcClaim) { - isBqCalcClaim.value = isBqCalcClaim + // —— Session —— + function setIsBqCalcClaim(payload) { + isBqCalcClaim.value = payload } - function set_token(token) { - token.value = token + + function setToken(payload) { + token.value = payload try { - sessionStorage.token = token + sessionStorage.token = payload } catch (e) { console.log(e) } } - function set_sessionId(sessionId) { - sessionId.value = sessionId + + function setSessionId(payload) { + sessionId.value = payload try { - localStorage.sessionId = sessionId + localStorage.sessionId = payload } catch (e) { console.log(e) } } - function set_configId(configId) { - configId.value = configId + + function setConfigId(payload) { + configId.value = payload try { - localStorage.configId = configId + localStorage.configId = payload } catch (e) { console.log(e) } } - function set_appentry(appentry) { - appentry.value = appentry + + function setAppentry(payload) { + appentry.value = payload } - function set_bpErrorInfo(bpErrorInfo) { - bpErrorInfo.value = bpErrorInfo + + function setBpErrorInfo(payload) { + bpErrorInfo.value = payload } - function del_token() { + + function delToken() { token.value = '' } - function set_userid(userId) { - userId.value = userId - try { - localStorage.userId = userId - } catch (e) { - console.log(e) - } - } - function set_sessionId(sessionId) { - sessionId.value = sessionId - try { - localStorage.sessionId = sessionId - } catch (e) { - console.log(e) - } - } - function set_configId(configId) { - configId.value = configId + + function setUserId(payload) { + userId.value = payload try { - localStorage.configId = configId + localStorage.userId = payload } catch (e) { console.log(e) } } - function set_source(source) { - source.value = source + + function setSource(payload) { + source.value = payload try { - localStorage.source = source + localStorage.source = payload } catch (e) { console.log(e) } } - function set_notitle(notitle) { - notitle.value = notitle + + function setNotitle(payload) { + notitle.value = payload try { - localStorage.notitle = notitle + localStorage.notitle = payload } catch (e) { console.log(e) } } - function set_elder(elder) { - elder.value = elder + + function setElder(payload) { + elder.value = payload try { - localStorage.elder = elder + localStorage.elder = payload } catch (e) { console.log(e) } } - function set_plan_code(planCode) { - planCode.value = planCode + + function setPlanCode(payload) { + planCode.value = payload try { - localStorage.planCode = planCode + localStorage.planCode = payload } catch (e) { console.log(e) } } - function set_entrance(entrance) { - entrance.value = entrance + + function setEntrance(payload) { + entrance.value = payload try { - localStorage.entrance = entrance + localStorage.entrance = payload } catch (e) { console.log(e) } } - function set_userInfo(userInfo) { - userInfo.value = userInfo + + function setUserInfo(payload) { + userInfo.value = payload try { - localStorage.userInfo = JSON.stringify(userInfo) + localStorage.userInfo = JSON.stringify(payload) } catch (e) { console.log(e) } } - function set_htmlExtParams(htmlExtParams) { - htmlExtParams.value = htmlExtParams + + function setHtmlExtParams(payload) { + htmlExtParams.value = payload try { - localStorage.htmlExtParams = htmlExtParams + localStorage.htmlExtParams = payload } catch (e) { console.log(e) } } - function set_complaint(complaint) { - complaint.value = complaint + + function setComplaint(payload) { + complaint.value = payload try { - localStorage.complaint = complaint + localStorage.complaint = payload } catch (e) { console.log(e) } } - function set_navigationCorpus(navigationCorpus) { - navigationCorpus.value = navigationCorpus + + function setNavigationCorpus(payload) { + navigationCorpus.value = payload try { - localStorage.navigationCorpus = navigationCorpus + localStorage.navigationCorpus = payload } catch (e) { console.log(e) } } - function set_manualService(manualService) { - manualService.value = manualService + + function setManualService(payload) { + manualService.value = payload try { - localStorage.manualService = JSON.stringify(manualService) + localStorage.manualService = JSON.stringify(payload) } catch (e) { console.log(e) } } - function set_sysConfig(sysConfig) { - sysConfig.value = sysConfig + + function setSysConfig(payload) { + sysConfig.value = payload try { - localStorage.sysConfig = JSON.stringify(sysConfig) + localStorage.sysConfig = payload } catch (e) { console.log(e) } } - function set_headerAvatar(headerAvatar) { - headerAvatar.value = headerAvatar + + function setHeaderAvatar(payload) { + headerAvatar.value = payload try { - localStorage.headerAvatar = JSON.stringify(headerAvatar) + localStorage.headerAvatar = JSON.stringify(payload) } catch (e) { console.log(e) } } - function set_sendLoading(sendLoading) { - sendLoading.value = sendLoading + + // —— 消息发送状态 —— + function setSendLoading(payload) { + sendLoading.value = payload } - function set_isSendSuccess(isSendSuccess) { - isSendSuccess.value = isSendSuccess + + function setIsSendSuccess(payload) { + isSendSuccess.value = payload } - function set_qaId(qaId) { - qaId.value = qaId + + function setQaId(payload) { + qaId.value = payload } - function set_problemFeedback(problemFeedback) { - problemFeedback.value = problemFeedback + + function setProblemFeedback(payload) { + problemFeedback.value = payload } - function set_otherTips(otherTips) { - otherTips.value = otherTips + + function setOtherTips(payload) { + otherTips.value = payload } - function set_lastMessage(lastMessage) { - lastMessage.value = lastMessage + + function setLastMessage(payload) { + lastMessage.value = payload } - function set_sendFailList(sendFailList) { - sendFailList.value.push(sendFailList) + + function setSendFailList(payload) { + sendFailList.value.push(payload) } - function set_isLostMessage(isLostMessage) { - isLostMessage.value = isLostMessage + + function setIsLostMessage(payload) { + isLostMessage.value = payload } - function del_sendFailList(delSendFailList) { - sendFailList.value = delSendFailList + + function delSendFailList(payload) { + sendFailList.value = payload } - function set_leaveMessage(leaveMessage) { - leaveMessage.value = leaveMessage + + function setLeaveMessage(payload) { + isLeaveMessage.value = payload } - function set_isLeaveMessageSuccess(leaveMessage) { - isLeaveMessageSuccess.value = isLeaveMessageSuccess + + function setIsLeaveMessageSuccess(payload) { + isLeaveMessageSuccess.value = payload try { - sessionStorage.isLeaveMessageSuccess = isLeaveMessageSuccess + sessionStorage.isLeaveMessageSuccess = payload } catch (e) { console.log(e) } } - function set_mescrollContent(mescrollContent) { - mescrollContent.value = mescrollContent + function setMescrollContent(payload) { + mescrollContent.value = payload + } + + function setSendMessageList(payload) { + sendMessageList.value = payload } - function set_sendMessageList(sendMessageList) { - sendMessageList.value = sendMessageList + + function setReceiveMessageList(payload) { + receiveMessageList.value = payload } - function set_receiveMessageList(receiveMessageList) { - receiveMessageList.value = receiveMessageList + + function setTts(payload) { + tts.value = payload } - function set_tts(tts) { - tts.value = tts + + function setHxOpenSuccesed(payload) { + hxOpenSucceseds.value = payload } - function set_hxOpenSuccesed(sendMessageList) { - sendMessageList.value = sendMessageList + + function setTimestamp(payload) { + timestamp.value = payload } - function addSendMessageList(sendMessageList) { - sendMessageList.value = sendMessageList + + function setSendParmas(payload) { + sendParmas.value = payload } - function set_sendMessageList(sendMessageList) { - sendMessageList.value = sendMessageList + + function setQueuedTimeout(payload) { + queuedTimeout.value = payload } - function addSendMessageList(sendMessageList) { - sendMessage = sendMessage || {} - console.log("接收发送的消息===", sendMessage); + + // 存储发送的消息到 chatList + function addSendMessageList(payload = {}) { + console.log('接收发送的消息===', payload) sendParmas.value = { token: token.value, - fromFlag: sendMessage.fromFlag || 1, // 1为自己 2为其他 other提示消息 + fromFlag: payload.fromFlag || 1, // 1为自己 2为其他 other提示消息 userId: userId.value, sessionId: sessionId.value, - reqAndResType: sendMessage.reqAndResType, // 1文本 2图片 3问提评价 - msgType: sendMessage.msgType || '', // - msgText: sendMessage.msgText, - file: sendMessage.file || '', - filename: sendMessage.filename || '', - formData: sendMessage.formData || '', + reqAndResType: payload.reqAndResType, // 1文本 2图片 3问提评价 + msgType: payload.msgType || '', + msgText: payload.msgText, + file: payload.file || '', + filename: payload.filename || '', + formData: payload.formData || '', source: source.value, - timestamp: sendMessage.timestamp || (new Date()).valueOf(), + timestamp: payload.timestamp || new Date().valueOf(), msgSource: manualService.value, // 1机器人 2人工 - cmd: sendMessage.cmd || '', - sendLoading: sendMessage.sendLoading, - isSendSuccess: sendMessage.isSendSuccess, - voiceNo: sendMessage.voiceNo, - quoteData: sendMessage.quoteData || null + cmd: payload.cmd || '', + sendLoading: payload.sendLoading, + isSendSuccess: payload.isSendSuccess, + voiceNo: payload.voiceNo, + quoteData: payload.quoteData || null, + bpErrorContent: payload.bpErrorContent || '', // 电子回访断点服务 } - console.log("发送消息==", sendParmas.value); + console.log('发送消息==', sendParmas.value) - timestamp.value = sendParmas.value.timestamp; + timestamp.value = sendParmas.value.timestamp // 存储正在发送的那条数据 - set_currentItemId(endParmas.timestamp) - sendParmas.value.bpErrorContent = sendMessage.bpErrorContent || '', // 电子回访断点服务 - - chatList.value.push(sendParmas.value); - // console.log("消息列表数据1==", chatList); - try { - // localStorage.chatList = JSON.stringify(chatList) + setCurrentItemId(sendParmas.value.timestamp) - // console.log("addSendMessageList==", chatList); - } catch (e) { - console.log(e) - } + chatList.value.push(sendParmas.value) } - function set_chatList(chatList) {// 消息列表 - let normalizedItem = utils.normalizeMessage(chatList); - chatList.value.push(normalizedItem); - try { - // localStorage.chatList = JSON.stringify(chatList) - // console.log("set_chatList==", chatList); - } catch (e) { - console.log(e) - } + + // 消息列表 + function setChatList(payload) { + const normalizedItem = utils.normalizeMessage(payload) + chatList.value.push(normalizedItem) } - function del_chatList(index) { + + function delChatList(index) { chatList.value.splice(index, 1) } - function delall_chatList() { - chatList.value.splice(0, chatList.value.length); + + function delAllChatList() { + chatList.value.splice(0, chatList.value.length) } - function del_set_sendFailList(del_Id) { + + function delSendFailListById(delId) { if (sendFailList.value && sendFailList.value.length > 0) { - console.log('未删除前sendFailList===', sendFailList.value.length); sendFailList.value.forEach((item, index) => { - - if (del_Id === item.timestamp) { + if (delId === item.timestamp) { sendFailList.value.splice(index, 1) } - }); - console.log('删除后的数据sendFailList==', sendFailList.value.length); + }) } } + // 存储到消息队列中 - function set_chatId(chatId) { - chatId.value.push(chatId); - // console.log("存储的消息chatId:", chatId) + function setChatId(payload) { + chatId.value.push(payload) } - function set_currentItemId(currentItemId) { - currentItemId.value = currentItemId; - // console.log("存储的消息chatId:", chatId) + + function setCurrentItemId(payload) { + currentItemId.value = payload } - function set_findActiveItem(findActiveItem) { + + function setFindActiveItem(findActiveItem) { if (chatList.value && chatList.value.length > 0) { - chatList.value.forEach(item => { + chatList.value.forEach((item) => { if (currentItemId.value == item.timestamp) { - item.isSendSuccess = findActiveItem; - item.sendLoading = false; + item.isSendSuccess = findActiveItem + item.sendLoading = false } - }); + }) } } - function set_activeItemExtra(state, data) { + + function setActiveItemExtra(data) { if (chatList.value && chatList.value.length > 0) { - chatList.value.forEach(item => { + chatList.value.forEach((item) => { if (currentItemId.value == item.timestamp) { if (data && data.imgKey) { - Vue.set(item, 'imgKey', data.imgKey); + item.imgKey = data.imgKey } if (data && data.imgUrl) { - Vue.set(item, 'imgUrl', data.imgUrl); + item.imgUrl = data.imgUrl } } - }); + }) } } - function set_reSendMessage(state, reSendMessageId) { - if (chatList.value && chatList.value.length > 0) { + function setReSendMessage(reSendMessageId) { + if (chatList.value && chatList.value.length > 0) { chatList.value.forEach((item, index) => { if (reSendMessageId === item.timestamp) { chatList.value.splice(index, 1) } - }); + }) } - del_set_sendFailList(reSendMessageId) + delSendFailListById(reSendMessageId) } + function scrollBottom() { setTimeout(() => { try { - mescrollContent.value.scrollTop = mescrollContent.value.scrollHeight || 0; + mescrollContent.value.scrollTop = mescrollContent.value.scrollHeight || 0 } catch (error) { console.log(error.message) } - }, 500); + }, 500) } - // 页面是否后台了 - function set_isBackstage(isBackstage) { - isBackstage.value = isBackstage; + + // —— 其他状态 —— + function setIsBackstage(payload) { + isBackstage.value = payload } + // 存储语音 - function set_VoiceData(payload) { - voiceDataList.value.push(payload); + function setVoiceData(payload) { + voiceDataList.value.push(payload) } + // sdk是否已加载好 - function set_sdkLoaded(sdkLoaded) { - sdkLoaded.value = sdkLoaded; + function setSdkLoaded(payload) { + sdkLoaded.value = payload } - function set_isBackstage(isBackstage) { - isBackstage.value = isBackstage; + + function setPcaData(payload) { + pcaData.value = payload } - function set_pcaData(payload) { - pcaData.value = payload; + function setChannelReform(payload) { + channelReform.value = payload } - function set_channelReform(payload) { - channelReform.value = payload; + + function setMsgStatus(payload) { + msgStatus.value = payload } - function set_msgStatus(payload) { - msgStatus.value = payload; + + function setMsgReply(payload) { + msgReply.value = payload } - function set_msgReply(payload) { - msgReply.value = payload; + + function setIsHumanChat(payload) { + isHumanChat.value = payload } - function set_isHumanChat(payload) { - isHumanChat.value = payload; + + function setGaokeUser(payload) { + gaokeUser.value = payload } - function set_gaokeUser(payload) { - gaokeUser.value = payload; + + function setBranchCompany(payload) { + branchCompany.value = payload } - function set_branchCompany(payload) { - branchCompany.value = payload; + + function setHotUser(payload) { + hotUser.value = payload } - function set_hotUser(payload) { - hotUser.value = payload; + + function setHotUserData(payload) { + hotUserData.value = payload } - function set_hotUserData(payload) { - hotUserData.value = payload; + + function setReviewRestricted(payload) { + reviewRestricted.value = payload } - function set_reviewRestricted(payload) { - hotUserData.value = payload; + + function setIntegratedUser(payload) { + integratedUser.value = payload } - function set_integratedUser(payload) { - integratedUser.value = payload; + + function setHxSessionId(payload) { + hxSessionId.value = payload + } + + function setShowHumanAppraise(payload) { + showHumanAppraise.value = payload } return { + // State token, userId, configId, @@ -519,11 +561,13 @@ export const useAppStore = defineStore('app', () => { planCode, entrance, elder, + notitle, + userInfo, + sysConfig, headerAvatar, htmlExtParams, complaint, navigationCorpus, - headerAvatar, routeAction, direction, mescrollContent, @@ -551,7 +595,7 @@ export const useAppStore = defineStore('app', () => { problemFeedback, isBackstage, sdkLoaded, - chatAr, + chatArr, bpErrorInfo, voiceDataList, hxOpenSucceseds, @@ -568,33 +612,78 @@ export const useAppStore = defineStore('app', () => { integratedUser, showHumanAppraise, mydFlag, + isBqCalcClaim, msgReply, hotUserData, + branchCompany, + + // Actions setIsBqCalcClaim, - set_token, + setToken, setSessionId, - set_configId, - set_appentry, - set_bpErrorInfo, - del_token, - set_userid, - set_source, - set_notitle, - set_planCode, - set_entrance, - set_elder, - set_headerAvatar, - set_htmlExtParams, - set_compl, - set_navigationCorpus, - set_manualService, - set_queuedTimeout, - set_sendLoading, - set_isSendSuccess, - set_timestamp, - set_sendParmas, - set_chatList, - set_chatId, + setConfigId, + setAppentry, + setBpErrorInfo, + delToken, + setUserId, + setSource, + setNotitle, + setElder, + setPlanCode, + setEntrance, + setUserInfo, + setHtmlExtParams, + setComplaint, + setNavigationCorpus, + setManualService, + setSysConfig, + setHeaderAvatar, + setSendLoading, + setIsSendSuccess, + setQaId, + setProblemFeedback, + setOtherTips, + setLastMessage, + setSendFailList, + setIsLostMessage, + delSendFailList, + delSendFailListById, + setLeaveMessage, + setIsLeaveMessageSuccess, + setMescrollContent, + setSendMessageList, + setReceiveMessageList, + setTts, + setHxOpenSuccesed, + setTimestamp, + setSendParmas, + setQueuedTimeout, + addSendMessageList, + setChatList, + delChatList, + delAllChatList, + setChatId, + setCurrentItemId, + setFindActiveItem, + setActiveItemExtra, + setReSendMessage, + scrollBottom, + setIsBackstage, + setVoiceData, + setSdkLoaded, + setPcaData, + setChannelReform, + setMsgStatus, + setMsgReply, + setIsHumanChat, + setGaokeUser, + setBranchCompany, + setHotUser, + setHotUserData, + setReviewRestricted, + setIntegratedUser, + setHxSessionId, + setShowHumanAppraise, } }) -export default useAppStore \ No newline at end of file +export default useAppStore diff --git a/src/tests/store-smoke.test.js b/src/tests/store-smoke.test.js new file mode 100644 index 0000000..1d93964 --- /dev/null +++ b/src/tests/store-smoke.test.js @@ -0,0 +1,29 @@ +import { describe, it, expect } from 'vitest' +import { createPinia, setActivePinia } from 'pinia' +import { useAppStore } from '@/store/index.js' + +describe('store/index.js smoke', () => { + it('初始化并调用 camelCase setter', () => { + setActivePinia(createPinia()) + const store = useAppStore() + + expect(typeof store.setSource).toBe('function') + expect(typeof store.setUserInfo).toBe('function') + expect(typeof store.setSessionId).toBe('function') + + store.setSource('95810000') + store.setNotitle('1') + store.setUserInfo({ name: '测试' }) + store.setSessionId('sid-1') + store.setChatId('cid-1') + store.setChatList({ msgText: 'hi', timestamp: 1 }) + store.addSendMessageList({ reqAndResType: '1', msgText: 'hello' }) + + expect(store.source).toBe('95810000') + expect(store.notitle).toBe('1') + expect(store.userInfo.name).toBe('测试') + expect(store.sessionId).toBe('sid-1') + expect(store.chatList.length).toBeGreaterThan(0) + expect(store.sendParmas.msgText).toBe('hello') + }) +}) diff --git a/src/utils/utils.js b/src/utils/utils.js index 579ec55..1d6728b 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -816,8 +816,8 @@ export default { // 触发自定义人工满意度评价弹窗 console.log('触发自定义人工满意度评价弹窗'); const hxSessionId = item.hxSessionId - appStore().set_hxSessionId(hxSessionId); - appStore().set_showHumanAppraise(true); + appStore().setHxSessionId(hxSessionId); + appStore().setShowHumanAppraise(true); } else { if (!appStore().sdkLoaded) { console.log('sdk未加载'); diff --git a/src/views/chat.vue b/src/views/chat.vue index b47ba4d..542e7a4 100644 --- a/src/views/chat.vue +++ b/src/views/chat.vue @@ -25,8 +25,19 @@ import Utils from '@/utils/utils' // 状态管理 const store = useAppStore() const router = useRouter() -console.log(store, 'store'); -const { set_source , set_userInfo, set_notitle , set_configId,set_entrance,set_appentry,set_htmlExtParams,set_complaint, set_navigationCorpus, setSessionId }= store +console.log(store, 'store') +const { + setSource, + setUserInfo, + setNotitle, + setConfigId, + setEntrance, + setAppentry, + setHtmlExtParams, + setComplaint, + setNavigationCorpus, + setSessionId, +} = store // 响应式数据 const isToken = ref(false) const isWX = ref(false) @@ -39,84 +50,84 @@ const source = computed(() => store.source) // 生命周期 onMounted(async () => { - var liccsAds = localStorage.getItem("liccsAds"); // 记录用户弹窗提示 - localStorage.clear(); - localStorage.liccsAds = liccsAds || ""; + var liccsAds = localStorage.getItem('liccsAds') // 记录用户弹窗提示 + localStorage.clear() + localStorage.liccsAds = liccsAds || '' //清除session 清除上次的记录 - sessionStorage.clear(); + sessionStorage.clear() - urlParams.value = Utils.getUrlParams(); - console.log("txfModules参数", urlParams.value.txfModules); + urlParams.value = Utils.getUrlParams() + console.log('txfModules参数', urlParams.value.txfModules) console.log('this.urlParams--', urlParams.value) let userInfo = { - phone: urlParams.value.phone || "", - name: urlParams.value.name || "", - sex: urlParams.value.sex || "", - openid: urlParams.value.openid || "", - idtype: urlParams.value.idtype || "", - pid: urlParams.value.pid || "", - - auStatus: urlParams.value.auStatus || "", //实名认证状态 枚举:1、0、其他(1为已认证状态,其他为非认证认证状态) - bdStatus: urlParams.value.bStatus || urlParams.value.bdStatus || "", //老客户绑定状态 1为已绑定状态,其他为非绑定状态 - bthdate: urlParams.value.bthdate || "", //出生日期 - workNum: urlParams.value.workNum || "", //营销员工号 - unit: urlParams.value.unit || "", //单位 - orgname: urlParams.value.orgname || "", //机构名称 - - txfModules: urlParams.value.txfModules || "", //太享福渠道活动与功能显示 - - sceneId: urlParams.value.sceneId || "", //场景标识(微信跟随) - entrance: urlParams.value.entrance || "", // 入口标识 - planCode: urlParams.value.planCode || urlParams.value.modelCode || "", //星云渠道产品代码 + phone: urlParams.value.phone || '', + name: urlParams.value.name || '', + sex: urlParams.value.sex || '', + openid: urlParams.value.openid || '', + idtype: urlParams.value.idtype || '', + pid: urlParams.value.pid || '', + + auStatus: urlParams.value.auStatus || '', //实名认证状态 枚举:1、0、其他(1为已认证状态,其他为非认证认证状态) + bdStatus: urlParams.value.bStatus || urlParams.value.bdStatus || '', //老客户绑定状态 1为已绑定状态,其他为非绑定状态 + bthdate: urlParams.value.bthdate || '', //出生日期 + workNum: urlParams.value.workNum || '', //营销员工号 + unit: urlParams.value.unit || '', //单位 + orgname: urlParams.value.orgname || '', //机构名称 + + txfModules: urlParams.value.txfModules || '', //太享福渠道活动与功能显示 + + sceneId: urlParams.value.sceneId || '', //场景标识(微信跟随) + entrance: urlParams.value.entrance || '', // 入口标识 + planCode: urlParams.value.planCode || urlParams.value.modelCode || '', //星云渠道产品代码 // 断点服务 - bpErrorCode: urlParams.value.bErrorCode || urlParams.value.brErrorCode || "", - bpErrorContent: urlParams.value.bErrorContent || urlParams.value.errorMsg || "", - bpErrorModule: urlParams.value.bErrorModule || "", // 电子回访断点服务 - bpErrorPicture: urlParams.value.bErrorPicture || "", // 微信给付断点服务 + bpErrorCode: urlParams.value.bErrorCode || urlParams.value.brErrorCode || '', + bpErrorContent: urlParams.value.bErrorContent || urlParams.value.errorMsg || '', + bpErrorModule: urlParams.value.bErrorModule || '', // 电子回访断点服务 + bpErrorPicture: urlParams.value.bErrorPicture || '', // 微信给付断点服务 entryIdnum: '', // 查门店证件号加密传参 entryOpenid: '', // 查门店openid加密传参 - userType: urlParams.value.usertype || "", // 95980000渠道(b2bi),说明一下是游客 - }; + userType: urlParams.value.usertype || '', // 95980000渠道(b2bi),说明一下是游客 + } - isWX.value = Utils.isWeiXin(); - // set_userInfo(userInfo);//用户信息 - // set_source(urlParams.value.ht || ""); //来源 - // set_notitle(urlParams.value.notitle || ""); //是否展示头部 - // set_configId(urlParams.value.configId || ""); //环信参数 - // set_entrance(urlParams.value.entrance || ""); //入口标识 - // set_appentry(urlParams.value.appentry || ""); // 是否为老版本app + isWX.value = Utils.isWeiXin() + // setUserInfo(userInfo);//用户信息 + // setSource(urlParams.value.ht || ""); //来源 + // setNotitle(urlParams.value.notitle || ""); //是否展示头部 + // setConfigId(urlParams.value.configId || ""); //环信参数 + // setEntrance(urlParams.value.entrance || ""); //入口标识 + // setAppentry(urlParams.value.appentry || ""); // 是否为老版本app - // set_htmlExtParams(urlParams.value.htmlExtParams || ""); //扩展参数 - // set_complaint(urlParams.value.complaint || ""); //扩展参数 - // set_navigationCorpus(urlParams.value.navigationCorpus || ""); //扩展参数 + // setHtmlExtParams(urlParams.value.htmlExtParams || ""); //扩展参数 + // setComplaint(urlParams.value.complaint || ""); //扩展参数 + // setNavigationCorpus(urlParams.value.navigationCorpus || ""); //扩展参数 // 渠道校验 - let checkToast = null; + let checkToast = null try { checkToast = showLoadingToast({ - message: "加载中...", + message: '加载中...', duration: 0, - loadingType: "spinner", + loadingType: 'spinner', forbidClick: true, - }); - const checkRes = await Post("config/downSource", { - source: urlParams.value.ht || "95810000" - }); - checkToast.clear(); + }) + const checkRes = await Post('config/downSource', { + source: urlParams.value.ht || '95810000', + }) + checkToast.clear() if (checkRes.code === 0 && checkRes.data !== null) { Dialog.alert({ - title: "提示", + title: '提示', message: checkRes.data.toast, - confirmButtonText: "确定" - }).then(res => { - Utils.closeWindow(); - }); - return; + confirmButtonText: '确定', + }).then((res) => { + Utils.closeWindow() + }) + return } } catch (error) { - console.log("渠道校验异常:", error); + console.log('渠道校验异常:', error) // if (checkToast) { // checkToast.clear(); // } @@ -185,15 +196,15 @@ const getToken = async () => { params.userId = decodeURIComponent(urlParams.value.appTicket).replace(/ /g, '+') } showLoadingToast({ message: '加载中...', duration: 0, loadingType: 'spinner', forbidClick: true }) - console.log('Post', Post); + console.log('Post', Post) try { const res = await Post('user/info', params) - console.log('res', res); + console.log('res', res) // await Post('user/info', params) // closeToast() return res } catch (error) { - console.log('error', error); + console.log('error', error) // closeToast() throw error }