store和接口调用代码提交

master
wujingling0908 2 weeks ago
parent 034020d5f9
commit b9ff01e056
  1. 3
      src/main.js
  2. 847
      src/store/app.js
  3. 690
      src/store/index.js
  4. 37
      src/views/chat.vue
  5. 2
      vite.config.js

@ -3,7 +3,6 @@
import { createApp } from 'vue' import { createApp } from 'vue'
import App from './App.vue' import App from './App.vue'
import router from './router' import router from './router'
import { createPinia } from 'pinia'
import pinia from './store' import pinia from './store'
import Vant from 'vant' import Vant from 'vant'
import 'vant/lib/index.css' import 'vant/lib/index.css'
@ -62,7 +61,7 @@ app.use(Vue3Lazyload, {
attempt: 3, // 失败重试次数 attempt: 3, // 失败重试次数
}) })
app.use(router) app.use(router)
app.use(createPinia()) app.use(pinia)
app.use(Vant) app.use(Vant)
// Vue2 全局挂载的 this.$post / this.$xss,迁移后在 globalProperties 上注册 // Vue2 全局挂载的 this.$post / this.$xss,迁移后在 globalProperties 上注册

@ -1,304 +1,689 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { computed, ref } from 'vue' import { ref } from 'vue'
import { Toast, Dialog } from 'vant'
import { fetchPost, upLoadImgHttp } from '@/utils/https'
import wsConnection from '@/utils/socket'
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()}` const createIdempotentKey = () => `user_msg_${Date.now()}`
export const UPDATE_DIRECTION = 'UPDATE_DIRECTION'
// —— 模块级初始值(加 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 : ''
// 取到身份证后解密
const initialUserInfo = localStorage.userInfo ? JSON.parse(localStorage.userInfo) : {}
// try {
// if(!!userInfo.versionNo1){
// const year = new Date().getFullYear()
// const versionNo1 = DecryptionECB(`${year}${year}${year}${year}`,userInfo.versionNo1)
// const key = versionNo1.substring(0, 16)
// const iv = versionNo1.substring(16, 32)
// if (!!userInfo.encryptPhone) {
// userInfo.decryptPhone = Decryption(key,iv,userInfo.encryptPhone)
// }
// if (!!userInfo.idnum) {
// userInfo.idnum = Decryption(key,iv,userInfo.idnum)
// console.log("取到后解密====", userInfo.idnum)
// }
// }
// } catch (error) { }
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 //留言是否成功
// 聊天消息 数据
const initialChatList = localStorage.chatList ? JSON.parse(localStorage.chatList) : []
const initialSendMessageList = localStorage.sendMessageList
? JSON.parse(localStorage.sendMessageList)
: []
const initialReceiveMessageList = localStorage.receiveMessageList
? JSON.parse(localStorage.receiveMessageList)
: []
export const useAppStore = defineStore('app', () => { export const useAppStore = defineStore('app', () => {
// Session 相关状态(原 apiState) // Session 相关状态(原 apiState)
const sessionId = ref('') const token = ref(initialToken)
const messageId = ref('') const userId = ref(initialUserId)
const serverLastMessageId = ref('') const configId = ref(initialConfigId)
const currentNode = ref('') const sessionId = ref(initialSessionId)
const currentStage = ref('') const source = ref(initialSource)
const channel = ref('') const planCode = ref(initialPlanCode)
const code = ref('') const entrance = ref(initialEntrance)
const cardType = ref('') const elder = ref(true)
const idempotentKey = ref(createIdempotentKey()) const notitle = ref('')
const userId = ref('debug-user') 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(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(initialChatList)
const sendMessageList = ref(initialSendMessageList)
const receiveMessageList = ref(initialReceiveMessageList)
const chatId = ref('')
const currentItemId = ref('')
const issubmit = ref(true)
const otherTips = ref('')
const lastMessage = ref({})
const asrConfig = ref({})
const sendFailList = ref([])
const isLostMessage = ref('')
const hxSessionId = ref('')
const qaId = ref('')
const problemFeedback = ref(false)
const isBackstage = ref(false)
const sdkLoaded = ref(false)
const chatArr = ref([]) const chatArr = ref([])
const isChatLoading = ref(false) const bpErrorInfo = ref([])
const voiceDataList = ref([])
// 应用相关状态 const hxOpenSucceseds = ref([])
const appName = ref('xiaolan-chat') const pcaData = ref([])
const loading = ref(false) const appentry = ref('')
// 保单是否基金类型,默认为非基金 N const tts = ref('')
const jjxFlag = ref('N') const flagType = ref('')
// 保单是否保障类型,默认为非基金 N const msgStatus = ref('')
const bzxFlag = ref('N') const channelReform = ref(false)
// const isHumanChat = ref(false)
const sfFlag = ref('N') const gaokeUser = ref(false)
const isUserSelctLoading = ref(false) const hotUser = ref(false)
const buttonLoading = ref(false) const reviewRestricted = ref(false)
const integratedUser = ref(false)
// Getters const showHumanAppraise = ref(false)
const hasSession = computed(() => !!sessionId.value) const mydFlag = ref(false)
const isLoading = computed(() => loading.value) const isBqCalcClaim = ref(false)
const userInfo = computed(() => ({ const msgReply = ref(true)
userId: userId.value, const hotUserData = ref(null)
code: code.value, const branchCompany = ref('')
channel: channel.value,
})) // —— Session ——
function setIsBqCalcClaim(payload) {
isBqCalcClaim.value = payload
}
function setToken(payload) {
token.value = payload
try {
sessionStorage.token = payload
} catch (e) {
console.log(e)
}
}
function setSessionId(payload) {
sessionId.value = payload
try {
localStorage.sessionId = payload
} catch (e) {
console.log(e)
}
}
function setConfigId(payload) {
configId.value = payload
try {
localStorage.configId = payload
} catch (e) {
console.log(e)
}
}
function setAppentry(payload) {
appentry.value = payload
}
function setBpErrorInfo(payload) {
bpErrorInfo.value = payload
}
function delToken() {
token.value = ''
}
function setUserId(payload) {
userId.value = payload
try {
localStorage.userId = payload
} catch (e) {
console.log(e)
}
}
function setSource(payload) {
source.value = payload
try {
localStorage.source = payload
} catch (e) {
console.log(e)
}
}
function setNotitle(payload) {
notitle.value = payload
try {
localStorage.notitle = payload
} catch (e) {
console.log(e)
}
}
function setElder(payload) {
elder.value = payload
try {
localStorage.elder = payload
} catch (e) {
console.log(e)
}
}
function setPlanCode(payload) {
planCode.value = payload
try {
localStorage.planCode = payload
} catch (e) {
console.log(e)
}
}
function setEntrance(payload) {
entrance.value = payload
try {
localStorage.entrance = payload
} catch (e) {
console.log(e)
}
}
function setUserInfo(payload) {
userInfo.value = payload
try {
localStorage.userInfo = JSON.stringify(payload)
} catch (e) {
console.log(e)
}
}
function setHtmlExtParams(payload) {
htmlExtParams.value = payload
try {
localStorage.htmlExtParams = payload
} catch (e) {
console.log(e)
}
}
function setComplaint(payload) {
complaint.value = payload
try {
localStorage.complaint = payload
} catch (e) {
console.log(e)
}
}
function setNavigationCorpus(payload) {
navigationCorpus.value = payload
try {
localStorage.navigationCorpus = payload
} catch (e) {
console.log(e)
}
}
function setManualService(payload) {
manualService.value = payload
try {
localStorage.manualService = JSON.stringify(payload)
} catch (e) {
console.log(e)
}
}
function setSysConfig(payload) {
sysConfig.value = payload
try {
localStorage.sysConfig = payload
} catch (e) {
console.log(e)
}
}
function setHeaderAvatar(payload) {
headerAvatar.value = payload
try {
localStorage.headerAvatar = JSON.stringify(payload)
} catch (e) {
console.log(e)
}
}
// —— 消息发送状态 ——
function setSendLoading(payload) {
sendLoading.value = payload
}
function setIsSendSuccess(payload) {
isSendSuccess.value = payload
}
function setQaId(payload) {
qaId.value = payload
}
function setProblemFeedback(payload) {
problemFeedback.value = payload
}
function setOtherTips(payload) {
otherTips.value = payload
}
function setLastMessage(payload) {
lastMessage.value = payload
}
function setSendFailList(payload) {
sendFailList.value.push(payload)
}
function setIsLostMessage(payload) {
isLostMessage.value = payload
}
function delSendFailList(payload) {
sendFailList.value = payload
}
function setLeaveMessage(payload) {
isLeaveMessage.value = payload
}
function setIsLeaveMessageSuccess(payload) {
isLeaveMessageSuccess.value = payload
try {
sessionStorage.isLeaveMessageSuccess = payload
} catch (e) {
console.log(e)
}
}
function setMescrollContent(payload) {
mescrollContent.value = payload
}
function setSendMessageList(payload) {
sendMessageList.value = payload
}
function setReceiveMessageList(payload) {
receiveMessageList.value = payload
}
function setTts(payload) {
tts.value = payload
}
// Actions - Session 管理 function setHxOpenSuccesed(payload) {
function setSessionId(id) { hxOpenSucceseds.value = payload
sessionId.value = id
} }
function setMessageId(id) { function setTimestamp(payload) {
messageId.value = id || '' timestamp.value = payload
console.log('MessageId-------->', messageId.value)
console.log('SessionId-------->', sessionId.value)
} }
function setServerLastMessageId(id) {
serverLastMessageId.value = id || '' function setSendParmas(payload) {
sendParmas.value = payload
} }
function clearMessageId() { function setQueuedTimeout(payload) {
messageId.value = '' queuedTimeout.value = payload
} }
function setUserInfo(info) { // 存储发送的消息到 chatList
if (info.userId !== undefined) userId.value = info.userId function addSendMessageList(payload = {}) {
if (info.channel !== undefined) channel.value = info.channel console.log('接收发送的消息===', payload)
if (info.code !== undefined) code.value = info.code
sendParmas.value = {
token: token.value,
fromFlag: payload.fromFlag || 1, // 1为自己 2为其他 other提示消息
userId: userId.value,
sessionId: sessionId.value,
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: payload.timestamp || new Date().valueOf(),
msgSource: manualService.value, // 1机器人 2人工
cmd: payload.cmd || '',
sendLoading: payload.sendLoading,
isSendSuccess: payload.isSendSuccess,
voiceNo: payload.voiceNo,
quoteData: payload.quoteData || null,
bpErrorContent: payload.bpErrorContent || '', // 电子回访断点服务
} }
console.log('发送消息==', sendParmas.value)
function setFlowPosition({ node, stage }) { timestamp.value = sendParmas.value.timestamp
if (node !== undefined) currentNode.value = node
if (stage !== undefined) currentStage.value = stage // 存储正在发送的那条数据
setCurrentItemId(sendParmas.value.timestamp)
chatList.value.push(sendParmas.value)
} }
function setCardType(type) { // 消息列表
cardType.value = type function setChatList(payload) {
const normalizedItem = utils.normalizeMessage(payload)
chatList.value.push(normalizedItem)
} }
// 允许外部在特殊场景下直接覆盖幂等键。 function delChatList(index) {
function setIdempotentKey(key) { chatList.value.splice(index, 1)
idempotentKey.value = key || ''
} }
// 请求成功后刷新出下一次交互要使用的幂等键。 function delAllChatList() {
function refreshIdempotentKey() { chatList.value.splice(0, chatList.value.length)
const nextKey = createIdempotentKey()
idempotentKey.value = nextKey
return nextKey
} }
// 兼容现有调用方按方法读取幂等键。 function delSendFailListById(delId) {
function getIdempotentKey() { if (sendFailList.value && sendFailList.value.length > 0) {
return idempotentKey.value sendFailList.value.forEach((item, index) => {
if (delId === item.timestamp) {
sendFailList.value.splice(index, 1)
}
})
}
} }
// 清理时不置空,直接生成新键,避免后续请求误拿空值。 // 存储到消息队列中
function clearIdempotentKey() { function setChatId(payload) {
idempotentKey.value = createIdempotentKey() chatId.value.push(payload)
} }
// 统一替换整段聊天记录,适合会话恢复或回放场景。 function setCurrentItemId(payload) {
function setChatArr(list) { currentItemId.value = payload
chatArr.value = Array.isArray(list) ? list : []
} }
// 新消息统一从 store 入口追加,便于后续集中扩展。 function setFindActiveItem(findActiveItem) {
function pushChatMessage(message) { if (chatList.value && chatList.value.length > 0) {
if (message) { chatList.value.forEach((item) => {
chatArr.value.push(message) if (currentItemId.value == item.timestamp) {
item.isSendSuccess = findActiveItem
item.sendLoading = false
}
})
} }
} }
/** function setActiveItemExtra(data) {
* 创建并推送用户消息到聊天列表 if (chatList.value && chatList.value.length > 0) {
* @param {String} content - 消息内容 chatList.value.forEach((item) => {
* @param {String} messageType - 消息类型,默认为 'user' if (currentItemId.value == item.timestamp) {
* @param {String} systemType - 系统类型,默认为 'CARD' if (data && data.imgKey) {
* @returns {Object|null} 创建的消息对象,失败返回 null item.imgKey = data.imgKey
*/ }
function pushUserMessage(content, messageType = 'user', systemType = 'CARD') { if (data && data.imgUrl) {
if (!content) { item.imgUrl = data.imgUrl
console.warn('pushUserMessage: 消息内容不能为空') }
return null }
})
}
} }
const model = JSON.parse( function setReSendMessage(reSendMessageId) {
JSON.stringify([ if (chatList.value && chatList.value.length > 0) {
{ chatList.value.forEach((item, index) => {
value: '', if (reSendMessageId === item.timestamp) {
param: '', chatList.value.splice(index, 1)
type: 'text', }
options: { })
label: '', }
readOnly: false, delSendFailListById(reSendMessageId)
placeholder: '', }
},
},
]),
)
model[0].options.label = content function scrollBottom() {
setTimeout(() => {
try {
mescrollContent.value.scrollTop = mescrollContent.value.scrollHeight || 0
} catch (error) {
console.log(error.message)
}
}, 500)
}
const messageObj = { // —— 其他状态 ——
type: messageType, function setIsBackstage(payload) {
system: systemType, isBackstage.value = payload
isSendSuccess: true,
message: model,
} }
if (messageType === 'user') { // 存储语音
messageObj.idempotentKey = idempotentKey.value function setVoiceData(payload) {
isChatLoading.value = true voiceDataList.value.push(payload)
} }
chatArr.value.push(messageObj) // sdk是否已加载好
function setSdkLoaded(payload) {
sdkLoaded.value = payload
}
return messageObj function setPcaData(payload) {
pcaData.value = payload
} }
// 根据幂等键回写指定消息的发送状态,必要时同步记录失败请求参数。 function setChannelReform(payload) {
function updateChatMessageSendStatus(idempotentKeyValue, isSendSuccess, requestParams = null) { channelReform.value = payload
if (!idempotentKeyValue) {
return false
} }
for (let index = chatArr.value.length - 1; index >= 0; index -= 1) { function setMsgStatus(payload) {
const item = chatArr.value[index] msgStatus.value = payload
if (item?.idempotentKey === idempotentKeyValue) {
item.isSendSuccess = isSendSuccess
if (requestParams) {
item.requestParams = requestParams
} }
return true
function setMsgReply(payload) {
msgReply.value = payload
} }
function setIsHumanChat(payload) {
isHumanChat.value = payload
} }
return false function setGaokeUser(payload) {
gaokeUser.value = payload
} }
function clearChatArr() { function setBranchCompany(payload) {
chatArr.value = [] branchCompany.value = payload
} }
// 会话级状态统一回收,并重置一份新的幂等键给下一轮会话使用。 function setHotUser(payload) {
function clearSession() { hotUser.value = payload
sessionId.value = ''
messageId.value = ''
currentNode.value = ''
currentStage.value = ''
channel.value = ''
cardType.value = ''
idempotentKey.value = createIdempotentKey()
userId.value = 'debug-user'
chatArr.value = []
} }
// Actions - 应用管理 function setHotUserData(payload) {
function setLoading(value) { hotUserData.value = payload
loading.value = Boolean(value)
} }
function setAppName(name) { function setReviewRestricted(payload) {
appName.value = name || appName.value reviewRestricted.value = payload
} }
//
function setJjxFlag(name) { function setIntegratedUser(payload) {
jjxFlag.value = name || appName.value integratedUser.value = payload
} }
function setBzxFLag(name) {
bzxFlag.value = name || appName.value function setHxSessionId(payload) {
hxSessionId.value = payload
} }
function setSfFlag(name) { function setShowHumanAppraise(payload) {
sfFlag.value = name || appName.value showHumanAppraise.value = payload
} }
return { return {
// Session State - 会话ID,用于标识当前用户会话 // State
sessionId, token,
// Session State - 当前消息ID
messageId,
serverLastMessageId,
// Session State - 当前工作流节点编码
currentNode,
// Session State - 当前工作流阶段编码
currentStage,
// Session State - 渠道标识(如微信、APP等)
channel,
code,
// Session State - 卡片类型,用于标识当前交互的卡片模版类型
cardType,
// Session State - 幂等键
idempotentKey,
// Session State - 用户ID,默认为 debug-user
userId, userId,
// Session State - 聊天渲染数组 configId,
chatArr, sessionId,
source,
// App State - 应用名称 planCode,
appName, entrance,
// App State - 全局加载状态标识 elder,
loading, notitle,
// App State - 保单是否基金类型,默认为非基金
jjxFlag,
// App State - 保单是否保障类型,默认为非保障
bzxFlag,
// App State -
sfFlag,
// Getters - 判断是否存在有效会话
hasSession,
// Getters - 获取当前加载状态
isLoading,
// Getters - 获取用户信息对象(包含 userId 和 channel)
userInfo, userInfo,
sysConfig,
// Actions - Session - 设置会话ID headerAvatar,
htmlExtParams,
complaint,
navigationCorpus,
routeAction,
direction,
mescrollContent,
isLeaveMessage,
isLeaveMessageSuccess,
manualService,
queuedTimeout,
sendLoading,
isSendSuccess,
timestamp,
sendParmas,
chatList,
sendMessageList,
receiveMessageList,
chatId,
currentItemId,
issubmit,
otherTips,
lastMessage,
asrConfig,
sendFailList,
isLostMessage,
hxSessionId,
qaId,
problemFeedback,
isBackstage,
sdkLoaded,
chatArr,
bpErrorInfo,
voiceDataList,
hxOpenSucceseds,
pcaData,
appentry,
tts,
flagType,
msgStatus,
channelReform,
isHumanChat,
gaokeUser,
hotUser,
reviewRestricted,
integratedUser,
showHumanAppraise,
mydFlag,
isBqCalcClaim,
msgReply,
hotUserData,
branchCompany,
// Actions
setIsBqCalcClaim,
setToken,
setSessionId, setSessionId,
// Actions - Session - 设置消息ID setConfigId,
setMessageId, setAppentry,
// Actions - setServerLastMessageId - 设置消息ID setBpErrorInfo,
setServerLastMessageId, delToken,
// Actions - Session - 清空消息ID setUserId,
clearMessageId, setSource,
// Actions - Session - 设置用户信息(userId 和 channel) setNotitle,
setElder,
setPlanCode,
setEntrance,
setUserInfo, setUserInfo,
// Actions - Session - 设置工作流位置(节点和阶段) setHtmlExtParams,
setFlowPosition, setComplaint,
// Actions - Session - 设置卡片类型 setNavigationCorpus,
setCardType, setManualService,
// Actions - Session - 设置幂等键 setSysConfig,
setIdempotentKey, setHeaderAvatar,
// Actions - Session - 刷新幂等键 setSendLoading,
refreshIdempotentKey, setIsSendSuccess,
// Actions - Session - 获取幂等键 setQaId,
getIdempotentKey, setProblemFeedback,
// Actions - Session - 清空幂等键 setOtherTips,
clearIdempotentKey, setLastMessage,
// Actions - Session - 覆盖聊天数组 setSendFailList,
setChatArr, setIsLostMessage,
// Actions - Session - 追加聊天消息 delSendFailList,
pushChatMessage, delSendFailListById,
// Actions - Session - 创建并推送用户消息到聊天列表 setLeaveMessage,
pushUserMessage, setIsLeaveMessageSuccess,
// Actions - Session - 根据幂等键更新消息发送状态 setMescrollContent,
updateChatMessageSendStatus, setSendMessageList,
// Actions - Session - 清空聊天数组 setReceiveMessageList,
clearChatArr, setTts,
// Actions - Session - 清空会话状态,重置为初始值 setHxOpenSuccesed,
clearSession, setTimestamp,
setSendParmas,
// Actions - App - 设置全局加载状态 setQueuedTimeout,
setLoading, addSendMessageList,
// Actions - App - 设置应用名称 setChatList,
setAppName, delChatList,
// Actions - App - 设置保单是否基金类型 delAllChatList,
setJjxFlag, setChatId,
// Actions - App - 设置保单是否保障类型 setCurrentItemId,
setBzxFLag, setFindActiveItem,
setActiveItemExtra,
// Actions - App - 设置获取医院需要类型 setReSendMessage,
setSfFlag, scrollBottom,
isUserSelctLoading, setIsBackstage,
isChatLoading, setVoiceData,
buttonLoading, setSdkLoaded,
setPcaData,
setChannelReform,
setMsgStatus,
setMsgReply,
setIsHumanChat,
setGaokeUser,
setBranchCompany,
setHotUser,
setHotUserData,
setReviewRestricted,
setIntegratedUser,
setHxSessionId,
setShowHumanAppraise,
} }
}) })
export default useAppStore

@ -1,689 +1,5 @@
import { defineStore } from 'pinia' import { createPinia } from 'pinia'
import { ref } from 'vue'
import { Toast, Dialog } from 'vant' const pinia = createPinia()
import { fetchPost, upLoadImgHttp } from '@/utils/https'
import wsConnection from '@/utils/socket'
import FormatDate from '@/utils/filters'
import utils from '@/utils/utils'
import { Decryption, DecryptionECB, Encrypt } from '@/utils'
import _ from 'lodash'
// 幂等键统一采用用户消息前缀,便于和后端日志对齐排查。 export default pinia
const createIdempotentKey = () => `user_msg_${Date.now()}`
export const UPDATE_DIRECTION = 'UPDATE_DIRECTION'
// —— 模块级初始值(加 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 : ''
// 取到身份证后解密
const initialUserInfo = localStorage.userInfo ? JSON.parse(localStorage.userInfo) : {}
// try {
// if(!!userInfo.versionNo1){
// const year = new Date().getFullYear()
// const versionNo1 = DecryptionECB(`${year}${year}${year}${year}`,userInfo.versionNo1)
// const key = versionNo1.substring(0, 16)
// const iv = versionNo1.substring(16, 32)
// if (!!userInfo.encryptPhone) {
// userInfo.decryptPhone = Decryption(key,iv,userInfo.encryptPhone)
// }
// if (!!userInfo.idnum) {
// userInfo.idnum = Decryption(key,iv,userInfo.idnum)
// console.log("取到后解密====", userInfo.idnum)
// }
// }
// } catch (error) { }
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 //留言是否成功
// 聊天消息 数据
const initialChatList = localStorage.chatList ? JSON.parse(localStorage.chatList) : []
const initialSendMessageList = localStorage.sendMessageList
? JSON.parse(localStorage.sendMessageList)
: []
const initialReceiveMessageList = localStorage.receiveMessageList
? JSON.parse(localStorage.receiveMessageList)
: []
export const useAppStore = defineStore('app', () => {
// Session 相关状态(原 apiState)
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 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(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(initialChatList)
const sendMessageList = ref(initialSendMessageList)
const receiveMessageList = ref(initialReceiveMessageList)
const chatId = ref('')
const currentItemId = ref('')
const issubmit = ref(true)
const otherTips = ref('')
const lastMessage = ref({})
const asrConfig = ref({})
const sendFailList = ref([])
const isLostMessage = ref('')
const hxSessionId = ref('')
const qaId = ref('')
const problemFeedback = ref(false)
const isBackstage = ref(false)
const sdkLoaded = ref(false)
const chatArr = ref([])
const bpErrorInfo = ref([])
const voiceDataList = ref([])
const hxOpenSucceseds = ref([])
const pcaData = ref([])
const appentry = ref('')
const tts = ref('')
const flagType = ref('')
const msgStatus = ref('')
const channelReform = ref(false)
const isHumanChat = ref(false)
const gaokeUser = ref(false)
const hotUser = ref(false)
const reviewRestricted = ref(false)
const integratedUser = ref(false)
const showHumanAppraise = ref(false)
const mydFlag = ref(false)
const isBqCalcClaim = ref(false)
const msgReply = ref(true)
const hotUserData = ref(null)
const branchCompany = ref('')
// —— Session ——
function setIsBqCalcClaim(payload) {
isBqCalcClaim.value = payload
}
function setToken(payload) {
token.value = payload
try {
sessionStorage.token = payload
} catch (e) {
console.log(e)
}
}
function setSessionId(payload) {
sessionId.value = payload
try {
localStorage.sessionId = payload
} catch (e) {
console.log(e)
}
}
function setConfigId(payload) {
configId.value = payload
try {
localStorage.configId = payload
} catch (e) {
console.log(e)
}
}
function setAppentry(payload) {
appentry.value = payload
}
function setBpErrorInfo(payload) {
bpErrorInfo.value = payload
}
function delToken() {
token.value = ''
}
function setUserId(payload) {
userId.value = payload
try {
localStorage.userId = payload
} catch (e) {
console.log(e)
}
}
function setSource(payload) {
source.value = payload
try {
localStorage.source = payload
} catch (e) {
console.log(e)
}
}
function setNotitle(payload) {
notitle.value = payload
try {
localStorage.notitle = payload
} catch (e) {
console.log(e)
}
}
function setElder(payload) {
elder.value = payload
try {
localStorage.elder = payload
} catch (e) {
console.log(e)
}
}
function setPlanCode(payload) {
planCode.value = payload
try {
localStorage.planCode = payload
} catch (e) {
console.log(e)
}
}
function setEntrance(payload) {
entrance.value = payload
try {
localStorage.entrance = payload
} catch (e) {
console.log(e)
}
}
function setUserInfo(payload) {
userInfo.value = payload
try {
localStorage.userInfo = JSON.stringify(payload)
} catch (e) {
console.log(e)
}
}
function setHtmlExtParams(payload) {
htmlExtParams.value = payload
try {
localStorage.htmlExtParams = payload
} catch (e) {
console.log(e)
}
}
function setComplaint(payload) {
complaint.value = payload
try {
localStorage.complaint = payload
} catch (e) {
console.log(e)
}
}
function setNavigationCorpus(payload) {
navigationCorpus.value = payload
try {
localStorage.navigationCorpus = payload
} catch (e) {
console.log(e)
}
}
function setManualService(payload) {
manualService.value = payload
try {
localStorage.manualService = JSON.stringify(payload)
} catch (e) {
console.log(e)
}
}
function setSysConfig(payload) {
sysConfig.value = payload
try {
localStorage.sysConfig = payload
} catch (e) {
console.log(e)
}
}
function setHeaderAvatar(payload) {
headerAvatar.value = payload
try {
localStorage.headerAvatar = JSON.stringify(payload)
} catch (e) {
console.log(e)
}
}
// —— 消息发送状态 ——
function setSendLoading(payload) {
sendLoading.value = payload
}
function setIsSendSuccess(payload) {
isSendSuccess.value = payload
}
function setQaId(payload) {
qaId.value = payload
}
function setProblemFeedback(payload) {
problemFeedback.value = payload
}
function setOtherTips(payload) {
otherTips.value = payload
}
function setLastMessage(payload) {
lastMessage.value = payload
}
function setSendFailList(payload) {
sendFailList.value.push(payload)
}
function setIsLostMessage(payload) {
isLostMessage.value = payload
}
function delSendFailList(payload) {
sendFailList.value = payload
}
function setLeaveMessage(payload) {
isLeaveMessage.value = payload
}
function setIsLeaveMessageSuccess(payload) {
isLeaveMessageSuccess.value = payload
try {
sessionStorage.isLeaveMessageSuccess = payload
} catch (e) {
console.log(e)
}
}
function setMescrollContent(payload) {
mescrollContent.value = payload
}
function setSendMessageList(payload) {
sendMessageList.value = payload
}
function setReceiveMessageList(payload) {
receiveMessageList.value = payload
}
function setTts(payload) {
tts.value = payload
}
function setHxOpenSuccesed(payload) {
hxOpenSucceseds.value = payload
}
function setTimestamp(payload) {
timestamp.value = payload
}
function setSendParmas(payload) {
sendParmas.value = payload
}
function setQueuedTimeout(payload) {
queuedTimeout.value = payload
}
// 存储发送的消息到 chatList
function addSendMessageList(payload = {}) {
console.log('接收发送的消息===', payload)
sendParmas.value = {
token: token.value,
fromFlag: payload.fromFlag || 1, // 1为自己 2为其他 other提示消息
userId: userId.value,
sessionId: sessionId.value,
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: payload.timestamp || new Date().valueOf(),
msgSource: manualService.value, // 1机器人 2人工
cmd: payload.cmd || '',
sendLoading: payload.sendLoading,
isSendSuccess: payload.isSendSuccess,
voiceNo: payload.voiceNo,
quoteData: payload.quoteData || null,
bpErrorContent: payload.bpErrorContent || '', // 电子回访断点服务
}
console.log('发送消息==', sendParmas.value)
timestamp.value = sendParmas.value.timestamp
// 存储正在发送的那条数据
setCurrentItemId(sendParmas.value.timestamp)
chatList.value.push(sendParmas.value)
}
// 消息列表
function setChatList(payload) {
const normalizedItem = utils.normalizeMessage(payload)
chatList.value.push(normalizedItem)
}
function delChatList(index) {
chatList.value.splice(index, 1)
}
function delAllChatList() {
chatList.value.splice(0, chatList.value.length)
}
function delSendFailListById(delId) {
if (sendFailList.value && sendFailList.value.length > 0) {
sendFailList.value.forEach((item, index) => {
if (delId === item.timestamp) {
sendFailList.value.splice(index, 1)
}
})
}
}
// 存储到消息队列中
function setChatId(payload) {
chatId.value.push(payload)
}
function setCurrentItemId(payload) {
currentItemId.value = payload
}
function setFindActiveItem(findActiveItem) {
if (chatList.value && chatList.value.length > 0) {
chatList.value.forEach((item) => {
if (currentItemId.value == item.timestamp) {
item.isSendSuccess = findActiveItem
item.sendLoading = false
}
})
}
}
function setActiveItemExtra(data) {
if (chatList.value && chatList.value.length > 0) {
chatList.value.forEach((item) => {
if (currentItemId.value == item.timestamp) {
if (data && data.imgKey) {
item.imgKey = data.imgKey
}
if (data && data.imgUrl) {
item.imgUrl = data.imgUrl
}
}
})
}
}
function setReSendMessage(reSendMessageId) {
if (chatList.value && chatList.value.length > 0) {
chatList.value.forEach((item, index) => {
if (reSendMessageId === item.timestamp) {
chatList.value.splice(index, 1)
}
})
}
delSendFailListById(reSendMessageId)
}
function scrollBottom() {
setTimeout(() => {
try {
mescrollContent.value.scrollTop = mescrollContent.value.scrollHeight || 0
} catch (error) {
console.log(error.message)
}
}, 500)
}
// —— 其他状态 ——
function setIsBackstage(payload) {
isBackstage.value = payload
}
// 存储语音
function setVoiceData(payload) {
voiceDataList.value.push(payload)
}
// sdk是否已加载好
function setSdkLoaded(payload) {
sdkLoaded.value = payload
}
function setPcaData(payload) {
pcaData.value = payload
}
function setChannelReform(payload) {
channelReform.value = payload
}
function setMsgStatus(payload) {
msgStatus.value = payload
}
function setMsgReply(payload) {
msgReply.value = payload
}
function setIsHumanChat(payload) {
isHumanChat.value = payload
}
function setGaokeUser(payload) {
gaokeUser.value = payload
}
function setBranchCompany(payload) {
branchCompany.value = payload
}
function setHotUser(payload) {
hotUser.value = payload
}
function setHotUserData(payload) {
hotUserData.value = payload
}
function setReviewRestricted(payload) {
reviewRestricted.value = payload
}
function setIntegratedUser(payload) {
integratedUser.value = payload
}
function setHxSessionId(payload) {
hxSessionId.value = payload
}
function setShowHumanAppraise(payload) {
showHumanAppraise.value = payload
}
return {
// State
token,
userId,
configId,
sessionId,
source,
planCode,
entrance,
elder,
notitle,
userInfo,
sysConfig,
headerAvatar,
htmlExtParams,
complaint,
navigationCorpus,
routeAction,
direction,
mescrollContent,
isLeaveMessage,
isLeaveMessageSuccess,
manualService,
queuedTimeout,
sendLoading,
isSendSuccess,
timestamp,
sendParmas,
chatList,
sendMessageList,
receiveMessageList,
chatId,
currentItemId,
issubmit,
otherTips,
lastMessage,
asrConfig,
sendFailList,
isLostMessage,
hxSessionId,
qaId,
problemFeedback,
isBackstage,
sdkLoaded,
chatArr,
bpErrorInfo,
voiceDataList,
hxOpenSucceseds,
pcaData,
appentry,
tts,
flagType,
msgStatus,
channelReform,
isHumanChat,
gaokeUser,
hotUser,
reviewRestricted,
integratedUser,
showHumanAppraise,
mydFlag,
isBqCalcClaim,
msgReply,
hotUserData,
branchCompany,
// Actions
setIsBqCalcClaim,
setToken,
setSessionId,
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

@ -13,7 +13,7 @@
<script setup> <script setup>
import { ref, onMounted, computed } from 'vue' import { ref, onMounted, computed } from 'vue'
import { useAppStore } from '@/store' import { useAppStore } from '@/store/app.js'
import { showLoadingToast, closeToast } from 'vant' import { showLoadingToast, closeToast } from 'vant'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { Post } from '@/utils/https' import { Post } from '@/utils/https'
@ -92,16 +92,17 @@ onMounted(async () => {
} }
isWX.value = Utils.isWeiXin() isWX.value = Utils.isWeiXin()
// setUserInfo(userInfo);//用户信息 console.log(setSource,store)
// setSource(urlParams.value.ht || ""); //来源 setUserInfo(userInfo);//用户信息
// setNotitle(urlParams.value.notitle || ""); //是否展示头部 setSource(urlParams.value.ht || ""); //来源
// setConfigId(urlParams.value.configId || ""); //环信参数 setNotitle(urlParams.value.notitle || ""); //是否展示头部
// setEntrance(urlParams.value.entrance || ""); //入口标识 setConfigId(urlParams.value.configId || ""); //环信参数
// setAppentry(urlParams.value.appentry || ""); // 是否为老版本app setEntrance(urlParams.value.entrance || ""); //入口标识
setAppentry(urlParams.value.appentry || ""); // 是否为老版本app
// setHtmlExtParams(urlParams.value.htmlExtParams || ""); //扩展参数
// setComplaint(urlParams.value.complaint || ""); //扩展参数 setHtmlExtParams(urlParams.value.htmlExtParams || ""); //扩展参数
// setNavigationCorpus(urlParams.value.navigationCorpus || ""); //扩展参数 setComplaint(urlParams.value.complaint || ""); //扩展参数
setNavigationCorpus(urlParams.value.navigationCorpus || ""); //扩展参数
// 渠道校验 // 渠道校验
let checkToast = null let checkToast = null
@ -115,7 +116,8 @@ onMounted(async () => {
const checkRes = await Post('config/downSource', { const checkRes = await Post('config/downSource', {
source: urlParams.value.ht || '95810000', source: urlParams.value.ht || '95810000',
}) })
checkToast.clear() console.log(checkToast,'checkToast');
checkToast.close()
if (checkRes.code === 0 && checkRes.data !== null) { if (checkRes.code === 0 && checkRes.data !== null) {
Dialog.alert({ Dialog.alert({
title: '提示', title: '提示',
@ -128,9 +130,9 @@ onMounted(async () => {
} }
} catch (error) { } catch (error) {
console.log('渠道校验异常:', error) console.log('渠道校验异常:', error)
// if (checkToast) { if (checkToast) {
// checkToast.clear(); checkToast.close();
// } }
} }
urlParams.value = Utils.getUrlParams() urlParams.value = Utils.getUrlParams()
@ -200,12 +202,11 @@ const getToken = async () => {
try { try {
const res = await Post('user/info', params) const res = await Post('user/info', params)
console.log('res', res) console.log('res', res)
// await Post('user/info', params) closeToast()
// closeToast()
return res return res
} catch (error) { } catch (error) {
console.log('error', error) console.log('error', error)
// closeToast() closeToast()
throw error throw error
} }
} }

@ -20,7 +20,7 @@ export default defineConfig(({ command }) => {
target: 'https://ssp-sit.cpic.com.cn', target: 'https://ssp-sit.cpic.com.cn',
changeOrigin: true, changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '/api'), rewrite: (path) => path.replace(/^\/api/, ''),
}, },
}, },
}, },

Loading…
Cancel
Save