Compare commits
4 Commits
1b7bbd6646
...
0632e36723
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0632e36723 | ||
|
|
079d305a36 | ||
|
|
667ad68af1 | ||
|
|
ca5879b350 |
@ -8,7 +8,9 @@ import { GetShopBaseInfo } from "@/api/shop.js";
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
version: "",
|
version: "",
|
||||||
|
lastPlayTime: 0, // 记录最后一次播放语音的时间戳
|
||||||
|
playInterval: 20000 // 20秒的间隔限制
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onLaunch: function () {
|
onLaunch: function () {
|
||||||
@ -30,18 +32,26 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
...mapState("user", ["uid", "userInfo"]),
|
...mapState("user", ["uid", "userInfo"]),
|
||||||
},
|
},
|
||||||
onShow: function () {
|
onShow: function () {
|
||||||
this.globalData.isAppActive = true;
|
this.globalData.isAppActive = true;
|
||||||
|
const globalConnName = 'globalSocket';
|
||||||
|
if (this.userInfo && Object.keys(this.userInfo).length > 0) {
|
||||||
|
// 检查指定的全局连接是否已连接,未连接则重建
|
||||||
|
if (!webSocketManager.isConnected(globalConnName)) {
|
||||||
|
this.connectSocket(this.userInfo); // 这里的connectSocket应该会创建名为globalConnName的连接
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 用户未登录时关闭所有全局连接
|
||||||
webSocketManager.closeAllGlobalConnections();
|
webSocketManager.closeAllGlobalConnections();
|
||||||
setTimeout(() => {
|
}
|
||||||
if (this.userInfo && Object.keys(this.userInfo).length > 0) {
|
// 重新注册推送监听
|
||||||
this.connectSocket(this.userInfo);
|
this.initPushListener();
|
||||||
}
|
},
|
||||||
});
|
|
||||||
},
|
|
||||||
onHide: function () {
|
onHide: function () {
|
||||||
this.globalData.isAppActive = false;
|
this.globalData.isAppActive = false;
|
||||||
webSocketManager.closeAllGlobalConnections();
|
// webSocketManager.closeAllGlobalConnections();
|
||||||
},
|
},
|
||||||
globalData: {
|
globalData: {
|
||||||
isAppActive: false,
|
isAppActive: false,
|
||||||
@ -69,6 +79,39 @@ export default {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
// 新增推送监听初始化方法
|
||||||
|
initPushListener() {
|
||||||
|
const _self = this;
|
||||||
|
// 先移除旧监听再添加新监听,避免重复注册
|
||||||
|
uni.offPushMessage();
|
||||||
|
uni.onPushMessage(async (res) => {
|
||||||
|
console.log("收到推送消息:", res);
|
||||||
|
|
||||||
|
// 检查用户登录状态,未登录直接返回
|
||||||
|
if (!_self.userInfo || Object.keys(_self.userInfo).length === 0) {
|
||||||
|
console.log("用户未登录,忽略推送");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res.data) {
|
||||||
|
if (!_self.globalData.isAppActive) {
|
||||||
|
if (res.type == "click") {
|
||||||
|
_self.handlePushClick(res.data.payload);
|
||||||
|
} else {
|
||||||
|
let shopRes = await GetShopBaseInfo();
|
||||||
|
if (shopRes.data.ringtone_is_enable === 1) {
|
||||||
|
_self.handlePushSound(res.data);
|
||||||
|
uni.setStorageSync("pendingPushData", res.data);
|
||||||
|
uni.createPushMessage(res.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log("应用已打开,直接处理消息");
|
||||||
|
_self.$store.dispatch("push/setPush", res.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
async initAppOrderPush() {
|
async initAppOrderPush() {
|
||||||
uni.getPushClientId({
|
uni.getPushClientId({
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
@ -149,6 +192,12 @@ export default {
|
|||||||
async handlePushSound(pushData) {
|
async handlePushSound(pushData) {
|
||||||
console.log(pushData.payload);
|
console.log(pushData.payload);
|
||||||
try {
|
try {
|
||||||
|
const currentTime = Date.now();
|
||||||
|
// 检查是否在10秒内已经播放过语音
|
||||||
|
if (currentTime - this.lastPlayTime < this.playInterval) {
|
||||||
|
console.log("10秒内已播放过语音,本次不播放");
|
||||||
|
return; // 10秒内不重复播放
|
||||||
|
}
|
||||||
// 获取category决定使用哪种声音
|
// 获取category决定使用哪种声音
|
||||||
const category = pushData.payload.category;
|
const category = pushData.payload.category;
|
||||||
var AUDIO = uni.createInnerAudioContext();
|
var AUDIO = uni.createInnerAudioContext();
|
||||||
@ -169,7 +218,7 @@ export default {
|
|||||||
AUDIO.play();
|
AUDIO.play();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
this.lastPlayTime = currentTime; // 更新最后播放时间戳
|
||||||
// 处理播放错误
|
// 处理播放错误
|
||||||
AUDIO.onError((res) => {
|
AUDIO.onError((res) => {
|
||||||
console.error("播放声音失败:", res);
|
console.error("播放声音失败:", res);
|
||||||
|
|||||||
@ -164,6 +164,24 @@ export function GetExpediteSFOrder(params) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//商家自行发货
|
||||||
|
export function SelDelivery(params) {
|
||||||
|
return http({
|
||||||
|
url: "/shop/sf-express/selDelivery",
|
||||||
|
method: "post",
|
||||||
|
params,
|
||||||
|
baseURL: config.apiMobile,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//订单完成
|
||||||
|
export function SelFinishDelivery(params) {
|
||||||
|
return http({
|
||||||
|
url: "/shop/sf-express/selFinishOrder",
|
||||||
|
method: "post",
|
||||||
|
params,
|
||||||
|
baseURL: config.apiMobile,
|
||||||
|
});
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 拣货完成
|
* 拣货完成
|
||||||
* @author Seven
|
* @author Seven
|
||||||
|
|||||||
@ -10,12 +10,17 @@
|
|||||||
<view class="name">{{ orderItem.sf_order_info.operator_name }}</view>
|
<view class="name">{{ orderItem.sf_order_info.operator_name }}</view>
|
||||||
<view class="btn_call" @click="handerExpedite">催快递</view>
|
<view class="btn_call" @click="handerExpedite">催快递</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="item time">
|
<view class="item time" v-if="orderItem.booking_state==1">
|
||||||
立即送达/{{
|
立即送达/{{
|
||||||
$u.timeFormat(orderItem.arrival_time, "mm-dd hh:MM")
|
$u.timeFormat(orderItem.arrival_time, "mm-dd hh:MM")
|
||||||
}}前送达
|
}}前送达
|
||||||
</view>
|
</view>
|
||||||
<u-icon
|
<view class="item time" v-if="orderItem.booking_state==2">
|
||||||
|
预订单/{{
|
||||||
|
$u.timeFormat(orderItem.booking_begin_time, "mm-dd hh:MM")
|
||||||
|
}}前送达
|
||||||
|
</view>
|
||||||
|
<u-icon
|
||||||
v-if="currOrderItem.sf_order_info.feed && !isErrorOrder"
|
v-if="currOrderItem.sf_order_info.feed && !isErrorOrder"
|
||||||
class="icon"
|
class="icon"
|
||||||
name="arrow-right"
|
name="arrow-right"
|
||||||
@ -60,7 +65,7 @@
|
|||||||
<view class="box"></view>
|
<view class="box"></view>
|
||||||
</view>
|
</view>
|
||||||
<view class="order_picking_box" v-if="!isErrorOrder">
|
<view class="order_picking_box" v-if="!isErrorOrder">
|
||||||
<view class="order_picking_text">
|
<view class="order_picking_text" v-if="orderItem.booking_state==1">
|
||||||
拣货中:
|
拣货中:
|
||||||
<text>{{ getRemainingTime(orderItem.arrival_time) }}</text>
|
<text>{{ getRemainingTime(orderItem.arrival_time) }}</text>
|
||||||
</view>
|
</view>
|
||||||
@ -220,11 +225,17 @@
|
|||||||
</view>
|
</view>
|
||||||
<view
|
<view
|
||||||
class="body"
|
class="body"
|
||||||
v-if="orderItem.is_deny_return"
|
v-if="orderItem.is_deny_return==2"
|
||||||
>
|
>
|
||||||
<view class="btn btn_cancel" @click="handerShowCancelOrder" >
|
<view v-if="orderItem.operate_flag==0&&isErrorOrder"class="btn btn_cancel" @click="handerSelDelivery" >
|
||||||
取消订单
|
自行发货
|
||||||
</view>
|
</view>
|
||||||
|
<view v-if="orderItem.operate_flag==1&&isErrorOrder"class="btn btn_cancel" @click="handerFinishOrder" >
|
||||||
|
订单完成
|
||||||
|
</view>
|
||||||
|
<view class="btn btn_cancel" @click="handerShowCancelOrder" >
|
||||||
|
取消订单
|
||||||
|
</view>
|
||||||
<view class="btn btn_refund" @click="handerShowPartOrderRefund" >
|
<view class="btn btn_refund" @click="handerShowPartOrderRefund" >
|
||||||
部分退款
|
部分退款
|
||||||
</view>
|
</view>
|
||||||
@ -471,6 +482,8 @@ import {
|
|||||||
GetExpediteSFOrder,
|
GetExpediteSFOrder,
|
||||||
GetInitiativeOrderRefund,
|
GetInitiativeOrderRefund,
|
||||||
GetOrderPicking,
|
GetOrderPicking,
|
||||||
|
SelDelivery,
|
||||||
|
SelFinishDelivery
|
||||||
} from "@/api/order";
|
} from "@/api/order";
|
||||||
|
|
||||||
import { makePhoneCall } from "@/utils/callPhone";
|
import { makePhoneCall } from "@/utils/callPhone";
|
||||||
@ -666,6 +679,26 @@ export default {
|
|||||||
this.orderItemIndex
|
this.orderItemIndex
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
async handerSelDelivery(){
|
||||||
|
let params = {
|
||||||
|
order_id: this.orderItem.order_id,
|
||||||
|
};
|
||||||
|
let res=await SelDelivery(params);
|
||||||
|
if(res&&res.status==200){
|
||||||
|
uni.$u.toast("处理完成");
|
||||||
|
this.$emit('refreshOrderList');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handerFinishOrder(){
|
||||||
|
let params = {
|
||||||
|
order_id: this.orderItem.order_id,
|
||||||
|
};
|
||||||
|
let res=await SelFinishDelivery(params);
|
||||||
|
if(res&&res.status==200){
|
||||||
|
uni.$u.toast("处理完成");
|
||||||
|
this.$emit('refreshOrderList');
|
||||||
|
}
|
||||||
|
},
|
||||||
makePhone(phone) {
|
makePhone(phone) {
|
||||||
console.log(makePhoneCall);
|
console.log(makePhoneCall);
|
||||||
|
|
||||||
|
|||||||
@ -188,6 +188,7 @@
|
|||||||
:isErrorOrder="true"
|
:isErrorOrder="true"
|
||||||
@cancelOrder="handerCancelOrder"
|
@cancelOrder="handerCancelOrder"
|
||||||
@showRefundOrderInfo="handerShowRefundOrderInfo"
|
@showRefundOrderInfo="handerShowRefundOrderInfo"
|
||||||
|
@refreshOrderList="handleRefresh"
|
||||||
></OrderItem>
|
></OrderItem>
|
||||||
<view
|
<view
|
||||||
class="no-data"
|
class="no-data"
|
||||||
|
|||||||
@ -182,6 +182,18 @@ class WebSocketManager {
|
|||||||
this.connections = {};
|
this.connections = {};
|
||||||
this.globalConnections = [];
|
this.globalConnections = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新增:判断指定名称的连接是否处于连接状态
|
||||||
|
isConnected(connectionName) {
|
||||||
|
// 获取指定名称的连接实例
|
||||||
|
const connection = this.connections[connectionName];
|
||||||
|
if (!connection) return false;
|
||||||
|
|
||||||
|
// 检查连接状态:WebsocketUtil的is_open_socket为true,且socketTask的readyState为1(连接中)
|
||||||
|
return connection.is_open_socket &&
|
||||||
|
connection.socketTask &&
|
||||||
|
connection.socketTask.readyState === 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出单例实例
|
// 导出单例实例
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user