Compare commits

...

4 Commits

5 changed files with 130 additions and 17 deletions

View File

@ -8,7 +8,9 @@ import { GetShopBaseInfo } from "@/api/shop.js";
export default {
data() {
return {
version: "",
version: "",
lastPlayTime: 0, //
playInterval: 20000 // 20
};
},
onLaunch: function () {
@ -30,18 +32,26 @@ export default {
computed: {
...mapState("user", ["uid", "userInfo"]),
},
onShow: function () {
this.globalData.isAppActive = true;
onShow: function () {
this.globalData.isAppActive = true;
const globalConnName = 'globalSocket';
if (this.userInfo && Object.keys(this.userInfo).length > 0) {
//
if (!webSocketManager.isConnected(globalConnName)) {
this.connectSocket(this.userInfo); // connectSocketglobalConnName
}
} else {
//
webSocketManager.closeAllGlobalConnections();
setTimeout(() => {
if (this.userInfo && Object.keys(this.userInfo).length > 0) {
this.connectSocket(this.userInfo);
}
});
},
}
//
this.initPushListener();
},
onHide: function () {
this.globalData.isAppActive = false;
webSocketManager.closeAllGlobalConnections();
// webSocketManager.closeAllGlobalConnections();
},
globalData: {
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() {
uni.getPushClientId({
success: (res) => {
@ -149,6 +192,12 @@ export default {
async handlePushSound(pushData) {
console.log(pushData.payload);
try {
const currentTime = Date.now();
// 10
if (currentTime - this.lastPlayTime < this.playInterval) {
console.log("10秒内已播放过语音本次不播放");
return; // 10
}
// category使
const category = pushData.payload.category;
var AUDIO = uni.createInnerAudioContext();
@ -169,7 +218,7 @@ export default {
AUDIO.play();
break;
}
this.lastPlayTime = currentTime; //
//
AUDIO.onError((res) => {
console.error("播放声音失败:", res);

View File

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

View File

@ -10,12 +10,17 @@
<view class="name">{{ orderItem.sf_order_info.operator_name }}</view>
<view class="btn_call" @click="handerExpedite">催快递</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")
}}前送达
</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"
class="icon"
name="arrow-right"
@ -60,7 +65,7 @@
<view class="box"></view>
</view>
<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>
</view>
@ -220,11 +225,17 @@
</view>
<view
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 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>
@ -471,6 +482,8 @@ import {
GetExpediteSFOrder,
GetInitiativeOrderRefund,
GetOrderPicking,
SelDelivery,
SelFinishDelivery
} from "@/api/order";
import { makePhoneCall } from "@/utils/callPhone";
@ -666,6 +679,26 @@ export default {
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) {
console.log(makePhoneCall);

View File

@ -188,6 +188,7 @@
:isErrorOrder="true"
@cancelOrder="handerCancelOrder"
@showRefundOrderInfo="handerShowRefundOrderInfo"
@refreshOrderList="handleRefresh"
></OrderItem>
<view
class="no-data"

View File

@ -182,6 +182,18 @@ class WebSocketManager {
this.connections = {};
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;
}
}
// 导出单例实例