From 51002843125a70eb2c4fe148316435da8eb9c9db Mon Sep 17 00:00:00 2001 From: ch Date: Wed, 25 May 2022 09:50:49 +0800 Subject: [PATCH] =?UTF-8?q?pref:IM=E6=B6=88=E6=81=AF=E9=87=8D=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +- src/App.vue | 22 +++++- src/common/api/index.js | 4 +- src/common/plugins/msbIm.js | 72 +++++++++++++++---- src/components/UiGoodsGroup.vue | 4 +- src/components/UiGoodsInfo.vue | 4 +- src/components/UiGoodsInfoMax.vue | 4 +- src/pages/account/address/create.vue | 4 +- src/pages/account/address/edit.vue | 4 +- src/pages/account/index.vue | 4 +- .../message/chat/components/Footer.vue | 4 +- .../message/chat/components/GoodsInfo.vue | 4 +- .../message/chat/components/OrderInfo.vue | 4 +- src/pages/account/message/chat/index.vue | 64 ++++++++++++----- src/pages/account/setting/index.vue | 11 +-- src/pages/account/setting/setUserInfo.vue | 4 +- src/pages/cart/components/PageCtx.vue | 2 +- src/pages/index/components/Pick.vue | 25 ++++--- src/pages/index/components/Seckill.vue | 8 +-- src/pages/login.vue | 4 +- .../order/detail/components/LogisitcsInfo.vue | 4 +- .../order/detail/components/OrderInfo.vue | 4 +- src/pages/order/list.vue | 4 +- .../components/SubmitLogistics.vue | 2 +- src/pages/order/submit.vue | 4 +- 25 files changed, 184 insertions(+), 90 deletions(-) diff --git a/package.json b/package.json index b1c170d..e83ad60 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,9 @@ "version": "0.1.0", "private": true, "scripts": { - "serve": "npm run dev:h5", + "serve": "node env.config.js & npm run dev:h5", + "serve:bate": "node env.config.js --ENV:beta & npm run dev:h5", + "serve:prod": "node env.config.js --ENV:prod & npm run dev:h5", "build": "npm run build:h5", "build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build", "build:custom": "cross-env NODE_ENV=production uniapp-cli custom", diff --git a/src/App.vue b/src/App.vue index 4efbe61..dc5b413 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-05-23 20:13:23 * @LastEditors: ch - * @LastEditTime: 2022-05-23 20:53:56 + * @LastEditTime: 2022-05-24 10:00:15 * @Description: file content --> - diff --git a/src/common/api/index.js b/src/common/api/index.js index 6ec6581..6ca029b 100644 --- a/src/common/api/index.js +++ b/src/common/api/index.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-03-17 16:37:45 * @LastEditors: ch - * @LastEditTime: 2022-05-16 15:52:57 + * @LastEditTime: 2022-05-24 17:25:25 * @Description: file content */ @@ -18,7 +18,7 @@ export const ApiPostLogin = (data) => ToAsyncAwait(MsbRequest.post(`${BASE_URL}/ * 退出登录 * @param {*} data */ -export const ApiGetLogout= () => ToAsyncAwait(MsbRequest.post(`${BASE_URL}/user/logout`)); +export const ApiGetLogout= () => ToAsyncAwait(MsbRequest.get(`${BASE_URL}/user/logout`)); /** * 获取手机验证码 * @param {*} params diff --git a/src/common/plugins/msbIm.js b/src/common/plugins/msbIm.js index a7cf50b..75986a4 100644 --- a/src/common/plugins/msbIm.js +++ b/src/common/plugins/msbIm.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-05-18 14:54:47 * @LastEditors: ch - * @LastEditTime: 2022-05-21 19:32:49 + * @LastEditTime: 2022-05-24 22:51:47 * @Description: file content */ import { CreateUUID, FormatDate, ToAsyncAwait } from "@/common/utils"; @@ -52,6 +52,9 @@ export default class MsbIm { this.socket.onOpen(() => { this.socket.onMessage(async (res) => { const result = JSON.parse(res.data); + if (result.content?.payload) { + result.content.payload = JSON.parse(result.content.payload); + } // 401主动退出 if (result.code === 401) { this.logout(); @@ -109,7 +112,6 @@ export default class MsbIm { return false; } let ctx = data.content; - ctx.payload = JSON.parse(ctx.payload || {}); let historyData = [...this.sessionData], newData = []; const hisIndex = historyData.findIndex(i => i.id === ctx.sessionId); @@ -263,30 +265,72 @@ export default class MsbIm { * @param {*} params */ async sendMsg(params) { - let curSession = this.sessionData.find(i => i.id === this.curSessionId); - - curSession.messageList.push({ + const index = this.sessionData.findIndex(i => i.id === this.curSessionId) + let curSession = this.sessionData[index]; + // 临时消息体 + let par = { + ...params, + traceId: CreateUUID(), + traceType: 20, + } + let msgCtx = { ...params.content, + ...par, fromId: params.fromId, createTimeStamp : (new Date()).getTime(), sendStatus : 'loading' - }); - const { error, result } = await ToAsyncAwait(this[send]({ - traceId: CreateUUID(), - traceType: 20, - ...params - })); - for (let item of curSession.messageList) { - if (item[this.option.ioKey] === params[this.option.ioKey]) { - item.sendStatus = error ? 'fail' : 'success'; + } + // 点发送,立即把消息加入消息列表,标记为发送中状态 + curSession.messageList.push(msgCtx); + // 超过时间未返回视为发送失败 + this.timerStatus(msgCtx); + const { error, result } = await ToAsyncAwait(this[send](par)); + // 接到通知,标记消息是否发送成功 + for (let i = curSession.messageList.length; i--;) { + const item = curSession.messageList[i]; + if (item[this.option.ioKey] === par[this.option.ioKey]) { + curSession.messageList[i].sendStatus = msgCtx.sendStatus = error ? 'fail' : 'success'; break; } } + let newData = [...this.sessionData]; + newData[index] = curSession; + this.setSessionData(newData); + if (error) { + return Promise.reject(error); + } + + return Promise.resolve(result); + } + /** + * 发送失败时,重新发送 + * @param {*} params + */ + async resend(params) { + params.sendStatus = 'loading'; + this.timerStatus(params) + const { error, result } = await ToAsyncAwait(this[send]({ + traceId: params.traceId, + traceType: params.traceType, + content : params.content + })); + params.createTimeStamp = result.createTimeStamp; if (error) { + params.sendStatus = 'fail'; return Promise.reject(error); } + params.sendStatus = 'success'; return Promise.resolve(result); } + timerStatus(msg) { + + setTimeout(() => { + if (msg.sendStatus === 'loading') { + msg.sendStatus = 'fail'; + delete this.queue[msg.traceId]; + } + }, 3000); + } /** * 主动创建会话 * @param {*} params diff --git a/src/components/UiGoodsGroup.vue b/src/components/UiGoodsGroup.vue index e124f8a..e74bc98 100644 --- a/src/components/UiGoodsGroup.vue +++ b/src/components/UiGoodsGroup.vue @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-04-07 17:22:44 * @LastEditors: ch - * @LastEditTime: 2022-05-23 18:17:28 + * @LastEditTime: 2022-05-24 09:57:03 * @Description: file content --> @@ -175,7 +175,7 @@ export default { } } } -::deep { +::v-deep { .goods-item--pirce{ text{ font-size: $font-size-lg; diff --git a/src/components/UiGoodsInfo.vue b/src/components/UiGoodsInfo.vue index d942509..9399d95 100644 --- a/src/components/UiGoodsInfo.vue +++ b/src/components/UiGoodsInfo.vue @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-03-31 14:49:33 * @LastEditors: ch - * @LastEditTime: 2022-05-23 18:17:30 + * @LastEditTime: 2022-05-24 09:57:04 * @Description: file content -->