From bb0aeef750e0adf7b81b23d7ea98c0662d836c6b Mon Sep 17 00:00:00 2001 From: hejin Date: Tue, 2 Sep 2025 23:47:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9C=A8=E7=BA=BF=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 +- .env.production | 4 +- .env.test | 3 +- src/api/index.js | 50 +++++++++------ src/application/online.vue | 102 ++++++++++++++++++++++++++++--- src/locale/en.json | 3 +- src/locale/zh-Hans.json | 3 +- src/pages/article-page/index.vue | 2 +- src/pages/products/index.vue | 3 +- src/stores/index.js | 21 ++----- 10 files changed, 144 insertions(+), 51 deletions(-) diff --git a/.env.development b/.env.development index 3ab5f6c..0651156 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,4 @@ NODE_ENV='development' VITE_APP_TITLE='开发环境' -VITE_APP_BASE_API='http://114.132.197.85:8099' -VITE_APP_SCOKET='ws://114.132.197.85:8099/ws/asset/' \ No newline at end of file +VITE_APP_BASE_API='http://1.92.99.15:8099' +VITE_APP_SCOKET='ws://1.92.99.15:8099/ws/asset/' \ No newline at end of file diff --git a/.env.production b/.env.production index 4b8ace8..da510a0 100644 --- a/.env.production +++ b/.env.production @@ -1,4 +1,4 @@ NODE_ENV='production' VITE_APP_TITLE='生产环境' -VITE_APP_BASE_API='http://114.132.197.85:8099' -VITE_APP_SCOKET='ws://114.132.197.85:8099/ws/asset/' \ No newline at end of file +VITE_APP_BASE_API='http://1.92.99.15:8099' +VITE_APP_SCOKET='ws://1.92.99.15:8099/ws/asset/' \ No newline at end of file diff --git a/.env.test b/.env.test index de1999c..5fc6719 100644 --- a/.env.test +++ b/.env.test @@ -1,3 +1,4 @@ NODE_ENV='test' VITE_APP_TITLE='测试环境' -VITE_APP_BASE_API='' +VITE_APP_BASE_API='http://1.92.99.15:8099' +VITE_APP_SCOKET='ws://1.92.99.15:8099/ws/asset/' diff --git a/src/api/index.js b/src/api/index.js index bb79dfc..fc1207b 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -95,23 +95,6 @@ export const articlePageApi = (params) => { return request.get('/web/newsPageList', {params}) } -/** - * @function 获取聊天窗口信息 - * @param {string} cusCode 设备唯一值 - * @param {string} prodId 产品ID -**/ -export const msgListApi = (data) => { - return request.post('/web/chatMain',data) -} - -/** - * @function 保存消息 - * @param {string} id - * @param {array} jsonArray 最新的消息列表 -**/ -export const saveMsg = (data) => { - return request.post('/web/saveMessage', data) -} /** * @function 全站搜索 @@ -133,4 +116,37 @@ export const appInfoApi = () => { **/ export const newAppApi = () => { return request.get('/web/getNewApp') +} + +/** + * @function 获取活跃聊天 + * @param {string} deviceCode 唯一 + * @param {string} prodId 产品id +**/ +export const activeMsgApi = (params) => { + return request.get('/chat/active', {params}) +} + +/** + * @function 加载指定会话内容 + * @param {string} sessionId +**/ +export const sessionMsgApi = (sessionId) => { + return request.get(`/chat/session/${sessionId}`) +} + +/** + * @function 创建新聊天会话 + * @param {string} cusCode deviceCode + * @param {string} prodId 产品id +**/ +export const createSessiongMsgApi = (data) => { + return request.post('/chat/newChat', data) +} + +/** + * @function 发送消息 +**/ +export const newsMsgApi = (data) => { + return request.post('/chat/newMes', data) } \ No newline at end of file diff --git a/src/application/online.vue b/src/application/online.vue index ced832a..75a6f88 100644 --- a/src/application/online.vue +++ b/src/application/online.vue @@ -5,6 +5,9 @@ :scroll-y="true" :scroll-top="msgScroll" > + + {{t('online.littleTitle')}} + {{item.content}} + + {{dayJs(item.createTime).format('HH:mm')}} + @@ -45,24 +51,48 @@ @@ -107,16 +179,28 @@ width: max-content; max-width: 80%; height: min-content; + position: relative; margin-bottom: 46rpx; padding: 23rpx 34rpx; word-break: break-word; border-radius: 8rpx; border: 2rpx solid #eeeeef; font-size: 28rpx; + .time { + position: absolute; + bottom: -40rpx; + right: 0; + color: #ccc; + font-size: 24rpx; + } } .opposite { color: #0d0e0e; background-color: #fff; + .time { + left: 0; + right: unset; + } } .oneself { margin-left: auto; diff --git a/src/locale/en.json b/src/locale/en.json index b9ab055..d6b1a84 100644 --- a/src/locale/en.json +++ b/src/locale/en.json @@ -132,7 +132,8 @@ }, "online": { "placeholder": "Send your requiremen", - "Retry": "Please try again later" + "Retry": "Please try again later", + "littleTitle": "Hello! It's a pleasure to assist you. How may I help you?" }, "seo": { "news": { diff --git a/src/locale/zh-Hans.json b/src/locale/zh-Hans.json index 7c56683..f8cdcec 100644 --- a/src/locale/zh-Hans.json +++ b/src/locale/zh-Hans.json @@ -132,7 +132,8 @@ }, "online": { "placeholder": "Send your requiremen", - "Retry": "请稍后重试" + "Retry": "请稍后重试", + "littleTitle": "您好!很高兴为您服务,请问有什么可以帮您?" }, "seo": { "news": { diff --git a/src/pages/article-page/index.vue b/src/pages/article-page/index.vue index 2a0b767..272de5c 100644 --- a/src/pages/article-page/index.vue +++ b/src/pages/article-page/index.vue @@ -196,7 +196,7 @@ const catgTreeInit = () => { return prodOrNewsCatgApi(params.value.maxCatgId).then(({data:res}) => { catgTree.value = res.data - if (res.data.length) { + if (res.data.length && !finalCatgId.value) { params.value.catgId = res.data[0].children.length ? res.data[0].children[0].id : res.data[0].id } }) diff --git a/src/pages/products/index.vue b/src/pages/products/index.vue index 233d80f..e44df92 100644 --- a/src/pages/products/index.vue +++ b/src/pages/products/index.vue @@ -217,7 +217,7 @@ const catgTreeInit = () => { return prodOrNewsCatgApi(params.value.maxCatgId).then(({data:res}) => { catgTree.value = res.data - if (res.data.length) { + if (res.data.length && !finalCatgId.value) { params.value.catgId = res.data[0].children.length ? res.data[0].children[0].id : res.data[0].id } }) @@ -249,6 +249,7 @@ } onShow( async() => { + console.log(level2.value) await getMaxCatgId() await catgTreeInit() init() diff --git a/src/stores/index.js b/src/stores/index.js index 95090b3..29f9c72 100644 --- a/src/stores/index.js +++ b/src/stores/index.js @@ -3,8 +3,6 @@ import { ref } from 'vue'; import { useI18n } from 'vue-i18n'; import { menuCategoryApi, - msgListApi, - saveMsg, appInfoApi, newAppApi } from '@/api/index.js'; @@ -95,18 +93,6 @@ export const useScoketMsg = defineStore('scoketMsg', () => { const chatMain = ref({}) - const getMsgList = (prodId) => { - const data = { - cusCode: onlyId.value, - prodId - } - return msgListApi(data).then(({data:res}) => { - chatMain.value = res.data - if (res.data.jsonArray) { - msgList.value = res.data.jsonArray - } - }) - } const scoketInit = () => { scoket.value = uni.connectSocket({ @@ -119,6 +105,9 @@ export const useScoketMsg = defineStore('scoketMsg', () => { } }) scoket.value.onMessage((e) => { + if (e.data === '连接成功') { + return + } if (e.data.startsWith("C")) { count.value = e.data; } @@ -129,7 +118,6 @@ export const useScoketMsg = defineStore('scoketMsg', () => { } else { msgList.value.push(JSON.parse(e.data)) msgCallback.value && msgCallback.value() - saveMsg({id:chatMain.value.id,jsonArray:msgList.value}) } }) scoket.value.onError((err) => { @@ -153,16 +141,17 @@ export const useScoketMsg = defineStore('scoketMsg', () => { } const closeScoket = () => { if (scoket.value) { + msgList.value = [] scoket.value.close() scoket.value = null } } return { scoket, + onlyId, scoketInit, closeScoket, msgList, - getMsgList, chatMain, send, msgCallback