【新增】订阅消息:订单发货消息订阅

pull/64/head
puhui999 2024-07-31 12:51:49 +08:00
parent 59c6613102
commit 8b73d488ca
3 changed files with 43 additions and 13 deletions

View File

@ -233,10 +233,6 @@
sheep.$store('cart').getList();
}
// #ifdef MP
sheep.$platform.useProvider('wechat').subscribeMessage(SubscribeTemplate.DELIVERY_ORDER);
// #endif
//
sheep.$router.redirect('/pages/pay/index', {
id: data.payOrderId,

View File

@ -51,7 +51,7 @@
<!-- TODO 芋艿订阅 -->
<!-- #ifdef MP -->
<view class="subscribe-box ss-flex ss-m-t-44">
<view class="subscribe-box ss-flex ss-m-t-44" v-if="showSubscribeBtn">
<image class="subscribe-img" :src="sheep.$url.static('/static/img/shop/order/cargo.png')" />
<view class="subscribe-title ss-m-r-48 ss-m-l-16">获取实时发货信息与订单状态</view>
<view class="subscribe-start" @tap="subscribeMessage"></view>
@ -63,12 +63,13 @@
<script setup>
import { onLoad, onHide, onShow } from '@dcloudio/uni-app';
import { reactive, computed } from 'vue';
import { reactive, computed, ref } from 'vue';
import { isEmpty } from 'lodash';
import sheep from '@/sheep';
import PayOrderApi from '@/sheep/api/pay/order';
import { fen2yuan } from '../../sheep/hooks/useGoods';
import { fen2yuan } from '@/sheep/hooks/useGoods';
import OrderApi from '@/sheep/api/trade/order';
import { SubscribeTemplate } from '@/sheep/util/const';
const state = reactive({
id: 0, //
@ -111,7 +112,16 @@
// 退
state.result = 'paid';
// #ifdef MP
subscribeMessage();
uni.showModal({
title: '支付结果',
showCancel: false, //
content: "支付成功",
success: () => {
// showModal
autoSubscribeMessage();
}
})
// #endif
//
if (state.orderType === 'goods') {
@ -146,13 +156,33 @@
// TODO
// #ifdef MP
const showSubscribeBtn = ref(false) //
const SUBSCRIBE_BTN_STATUS_STORAGE_KEY = "subscribe_btn_status"
function subscribeMessage() {
let event = ['order_dispatched'];
let event = [SubscribeTemplate.DELIVERY_ORDER];
if (state.tradeOrder.type === 3) {
event.push('groupon_finish');
event.push('groupon_fail');
// TODO puhui999:
event.push('拼团成功');
event.push('拼团失败');
}
sheep.$platform.useProvider('wechat').subscribeMessage(event);
sheep.$platform.useProvider('wechat').subscribeMessage(event, () => {
//
uni.removeStorageSync(SUBSCRIBE_BTN_STATUS_STORAGE_KEY);
uni.setStorageSync(SUBSCRIBE_BTN_STATUS_STORAGE_KEY, '已订阅');
//
showSubscribeBtn.value = false;
});
}
async function autoSubscribeMessage() {
// 1.
const subscribeBtnStatus = uni.getStorageSync(SUBSCRIBE_BTN_STATUS_STORAGE_KEY);
if (!subscribeBtnStatus) {
showSubscribeBtn.value = true;
return
}
// 2.
subscribeMessage()
}
// #endif

View File

@ -171,7 +171,7 @@ async function getSubscribeTemplate() {
}
// 订阅消息
function subscribeMessage(event) {
function subscribeMessage(event, callback= undefined) {
let tmplIds = [];
if (typeof event === 'string') {
const temp = subscribeEventList.find(item => item.title.includes(event));
@ -191,6 +191,10 @@ function subscribeMessage(event) {
uni.requestSubscribeMessage({
tmplIds,
success: ()=>{
// 不管是拒绝还是同意都触发
callback && callback()
},
fail: (err) => {
console.log(err);
},