From 38f9ff0929f1d948ed0693b61a492ce8eeffb9b3 Mon Sep 17 00:00:00 2001 From: 396316021 <396316021@qq.com> Date: Wed, 15 Nov 2023 16:07:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/other.js | 13 +++++++++++++ pages.json | 7 +++++++ pages/ChatDetail/index.vue | 37 +++++++++++++++++++++++++++++++++++-- pages/SeizeOrders/index.vue | 27 +++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 pages/SeizeOrders/index.vue diff --git a/api/other.js b/api/other.js index d855ca7..b2cb2ba 100644 --- a/api/other.js +++ b/api/other.js @@ -39,4 +39,17 @@ export function feedback(data){ method: "post", data:data }) +} + +/** + * 抢单 + * @param data + * @returns {Promise | Promise} + */ +export function seizeChat(data){ + return request({ + url:`/user/seize-chat`, + method: "post", + data:data + }) } \ No newline at end of file diff --git a/pages.json b/pages.json index 6983526..40d99d6 100644 --- a/pages.json +++ b/pages.json @@ -165,6 +165,13 @@ "navigationBarTitleText": "优惠券", "enablePullDownRefresh": true } + }, + { + "path": "pages/SeizeOrders/index", + "style": { + "navigationBarTitleText": "抢单", + "enablePullDownRefresh": true + } } ], "globalStyle": { diff --git a/pages/ChatDetail/index.vue b/pages/ChatDetail/index.vue index 41ff14f..f977d71 100644 --- a/pages/ChatDetail/index.vue +++ b/pages/ChatDetail/index.vue @@ -63,6 +63,7 @@ import MzButton from '../../components/MzButton/Index.vue'; import {getToken} from "@/api/chat"; import log from "@/utils/log"; import {waitToken} from "../../api/chat"; +import {seizeChat} from "../../api/other"; export default { components: { @@ -94,9 +95,11 @@ export default { title:"在线咨询" }, onLoad(options) { - - if(this.$store.state.userInfo.is_waitstaff !== 1 ){ + let user = uni.getStorageSync('user'); + if(user.is_waitstaff !== 1 ){ this.getToken(options.id, options.type ?? 1); + }else if(options.is_seize == 1){ + this.connectChat(options.id); }else{ if(options.type ==='2'){ this.getToken(options.id, options.type ?? 1); @@ -147,6 +150,36 @@ export default { }) }) }, + connectChat(chat_id) { + seizeChat({chat_id:chat_id}).then(data => { + this.chat_id = data.data.chat_id; + this.type = data.data.type; + this.user_id = data.data.user_id; + uni.connectSocket({ + url: data.data.chat_url + }); + + uni.onSocketOpen((res) => { + this.ableChat = true; + console.log('WebSocket连接已打开!'); + }); + + uni.onSocketClose((res) => { + this.ableChat = false; + console.log('WebSocket 已关闭!'); + }); + + uni.onSocketMessage((res) => { + this.newMessage(res); + }) + }).catch(err => { + api.error(err.msg).then(() => { + uni.redirectTo({url:'/pages/Index/index'}) + return; + }); + + }) + }, getWaitToken(order_id) { waitToken(order_id).then(data => { this.chat_id = data.data.chat_id; diff --git a/pages/SeizeOrders/index.vue b/pages/SeizeOrders/index.vue new file mode 100644 index 0000000..8614aa7 --- /dev/null +++ b/pages/SeizeOrders/index.vue @@ -0,0 +1,27 @@ + + + + + \ No newline at end of file