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 -->