store和接口调用代码提交

master
wujingling0908 2 weeks ago
parent 034020d5f9
commit b9ff01e056
  1. 3
      src/main.js
  2. 849
      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 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) {
const appName = ref('xiaolan-chat') token.value = payload
const loading = ref(false) try {
// 保单是否基金类型,默认为非基金 N sessionStorage.token = payload
const jjxFlag = ref('N') } catch (e) {
// 保单是否保障类型,默认为非基金 N console.log(e)
const bzxFlag = ref('N') }
// }
const sfFlag = ref('N')
const isUserSelctLoading = ref(false)
const buttonLoading = ref(false)
// Getters function setSessionId(payload) {
const hasSession = computed(() => !!sessionId.value) sessionId.value = payload
const isLoading = computed(() => loading.value) try {
const userInfo = computed(() => ({ localStorage.sessionId = payload
userId: userId.value, } catch (e) {
code: code.value, console.log(e)
channel: channel.value, }
})) }
// Actions - Session 管理 function setConfigId(payload) {
function setSessionId(id) { configId.value = payload
sessionId.value = id try {
localStorage.configId = payload
} catch (e) {
console.log(e)
}
} }
function setMessageId(id) { function setAppentry(payload) {
messageId.value = id || '' appentry.value = payload
console.log('MessageId-------->', messageId.value)
console.log('SessionId-------->', sessionId.value)
} }
function setServerLastMessageId(id) {
serverLastMessageId.value = id || '' function setBpErrorInfo(payload) {
bpErrorInfo.value = payload
} }
function clearMessageId() { function delToken() {
messageId.value = '' token.value = ''
} }
function setUserInfo(info) { function setUserId(payload) {
if (info.userId !== undefined) userId.value = info.userId userId.value = payload
if (info.channel !== undefined) channel.value = info.channel try {
if (info.code !== undefined) code.value = info.code localStorage.userId = payload
} catch (e) {
console.log(e)
}
} }
function setFlowPosition({ node, stage }) { function setSource(payload) {
if (node !== undefined) currentNode.value = node source.value = payload
if (stage !== undefined) currentStage.value = stage try {
localStorage.source = payload
} catch (e) {
console.log(e)
}
} }
function setCardType(type) { function setNotitle(payload) {
cardType.value = type notitle.value = payload
try {
localStorage.notitle = payload
} catch (e) {
console.log(e)
}
} }
// 允许外部在特殊场景下直接覆盖幂等键。 function setElder(payload) {
function setIdempotentKey(key) { elder.value = payload
idempotentKey.value = key || '' try {
localStorage.elder = payload
} catch (e) {
console.log(e)
}
} }
// 请求成功后刷新出下一次交互要使用的幂等键。 function setPlanCode(payload) {
function refreshIdempotentKey() { planCode.value = payload
const nextKey = createIdempotentKey() try {
idempotentKey.value = nextKey localStorage.planCode = payload
return nextKey } catch (e) {
console.log(e)
}
} }
// 兼容现有调用方按方法读取幂等键。 function setEntrance(payload) {
function getIdempotentKey() { entrance.value = payload
return idempotentKey.value try {
localStorage.entrance = payload
} catch (e) {
console.log(e)
}
} }
// 清理时不置空,直接生成新键,避免后续请求误拿空值。 function setUserInfo(payload) {
function clearIdempotentKey() { userInfo.value = payload
idempotentKey.value = createIdempotentKey() try {
localStorage.userInfo = JSON.stringify(payload)
} catch (e) {
console.log(e)
}
} }
// 统一替换整段聊天记录,适合会话恢复或回放场景。 function setHtmlExtParams(payload) {
function setChatArr(list) { htmlExtParams.value = payload
chatArr.value = Array.isArray(list) ? list : [] try {
localStorage.htmlExtParams = payload
} catch (e) {
console.log(e)
}
} }
// 新消息统一从 store 入口追加,便于后续集中扩展。 function setComplaint(payload) {
function pushChatMessage(message) { complaint.value = payload
if (message) { try {
chatArr.value.push(message) localStorage.complaint = payload
} catch (e) {
console.log(e)
} }
} }
/** function setNavigationCorpus(payload) {
* 创建并推送用户消息到聊天列表 navigationCorpus.value = payload
* @param {String} content - 消息内容 try {
* @param {String} messageType - 消息类型,默认为 'user' localStorage.navigationCorpus = payload
* @param {String} systemType - 系统类型,默认为 'CARD' } catch (e) {
* @returns {Object|null} 创建的消息对象,失败返回 null console.log(e)
*/
function pushUserMessage(content, messageType = 'user', systemType = 'CARD') {
if (!content) {
console.warn('pushUserMessage: 消息内容不能为空')
return null
} }
}
const model = JSON.parse( function setManualService(payload) {
JSON.stringify([ manualService.value = payload
{ try {
value: '', localStorage.manualService = JSON.stringify(payload)
param: '', } catch (e) {
type: 'text', console.log(e)
options: {
label: '',
readOnly: false,
placeholder: '',
},
},
]),
)
model[0].options.label = content
const messageObj = {
type: messageType,
system: systemType,
isSendSuccess: true,
message: model,
} }
}
if (messageType === 'user') { function setSysConfig(payload) {
messageObj.idempotentKey = idempotentKey.value sysConfig.value = payload
isChatLoading.value = true 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)
}
}
chatArr.value.push(messageObj) // —— 消息发送状态 ——
function setSendLoading(payload) {
sendLoading.value = payload
}
function setIsSendSuccess(payload) {
isSendSuccess.value = payload
}
function setQaId(payload) {
qaId.value = payload
}
function setProblemFeedback(payload) {
problemFeedback.value = payload
}
return messageObj function setOtherTips(payload) {
otherTips.value = payload
} }
// 根据幂等键回写指定消息的发送状态,必要时同步记录失败请求参数。 function setLastMessage(payload) {
function updateChatMessageSendStatus(idempotentKeyValue, isSendSuccess, requestParams = null) { lastMessage.value = payload
if (!idempotentKeyValue) { }
return false
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
}
for (let index = chatArr.value.length - 1; index >= 0; index -= 1) { function setTimestamp(payload) {
const item = chatArr.value[index] timestamp.value = payload
if (item?.idempotentKey === idempotentKeyValue) { }
item.isSendSuccess = isSendSuccess
if (requestParams) { function setSendParmas(payload) {
item.requestParams = requestParams 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)
} }
return true })
} }
}
// 存储到消息队列中
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
}
return false function setMsgStatus(payload) {
msgStatus.value = payload
} }
function clearChatArr() { function setMsgReply(payload) {
chatArr.value = [] msgReply.value = payload
} }
// 会话级状态统一回收,并重置一份新的幂等键给下一轮会话使用。 function setIsHumanChat(payload) {
function clearSession() { isHumanChat.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 setGaokeUser(payload) {
function setLoading(value) { gaokeUser.value = payload
loading.value = Boolean(value)
} }
function setAppName(name) { function setBranchCompany(payload) {
appName.value = name || appName.value branchCompany.value = payload
} }
//
function setJjxFlag(name) { function setHotUser(payload) {
jjxFlag.value = name || appName.value hotUser.value = payload
}
function setHotUserData(payload) {
hotUserData.value = payload
}
function setReviewRestricted(payload) {
reviewRestricted.value = payload
}
function setIntegratedUser(payload) {
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