update: 优化铃声设置页面UI逻辑;根据铃声开关判断是否需要推送铃声提醒。
This commit is contained in:
parent
0ffbddfd61
commit
e0f409c726
@ -4,7 +4,7 @@ import APPUpdate, { getCurrentNo } from "@/config/appUpdate";
|
||||
// #endif
|
||||
import { mapState, mapActions } from "vuex";
|
||||
import { webSocketManager } from "@/utils/socket.js";
|
||||
import {GetRingStatus} from '@/api/ring.js';
|
||||
import { GetShopBaseInfo } from "@/api/shop.js";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -69,7 +69,7 @@ export default {
|
||||
);
|
||||
});
|
||||
},
|
||||
initAppOrderPush() {
|
||||
async initAppOrderPush() {
|
||||
uni.getPushClientId({
|
||||
success: (res) => {
|
||||
var push_clientid = res.cid;
|
||||
@ -80,7 +80,7 @@ export default {
|
||||
},
|
||||
});
|
||||
|
||||
uni.onPushMessage((res) => {
|
||||
uni.onPushMessage(async (res) => {
|
||||
console.log("收到推送消息:", res); //监听推送消息
|
||||
|
||||
if (res.data) {
|
||||
@ -90,10 +90,13 @@ export default {
|
||||
if (res.type == "click") {
|
||||
this.handlePushClick(res.data.payload);
|
||||
} else {
|
||||
this.handlePushSound(res.data);
|
||||
uni.setStorageSync("pendingPushData", res.data);
|
||||
// 创建通知
|
||||
uni.createPushMessage(res.data);
|
||||
let res = await GetShopBaseInfo();
|
||||
if (res.data.ringtone_is_enable === 1) {
|
||||
this.handlePushSound(res.data);
|
||||
uni.setStorageSync("pendingPushData", res.data);
|
||||
// 创建通知
|
||||
uni.createPushMessage(res.data);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log("应用已打开,直接处理消息");
|
||||
@ -148,16 +151,10 @@ export default {
|
||||
try {
|
||||
// 获取category决定使用哪种声音
|
||||
const category = pushData.payload.category;
|
||||
|
||||
var AUDIO = uni.createInnerAudioContext();
|
||||
let res = await GetRingStatus();
|
||||
console.log("声音",res);
|
||||
if(res.data.ringtone_is_enable!==1){
|
||||
console.log("没声音");
|
||||
return;
|
||||
}
|
||||
// 设置音频源
|
||||
let soundFile = "";
|
||||
|
||||
switch (category) {
|
||||
case "mchOnLineOrderList":
|
||||
AUDIO.src = "/static/mp3/jinxingzhong.MP3";
|
||||
|
||||
@ -1,27 +1,28 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view class="switch-container">
|
||||
<text>铃声状态:</text>
|
||||
<u-switch
|
||||
v-model="isSwitchOn"
|
||||
@change="handleSwitchChange"
|
||||
size="20"
|
||||
></u-switch>
|
||||
<text>{{ isSwitchOn ? '打开' : '关闭' }}</text>
|
||||
<view class="header">铃声消息提醒</view>
|
||||
<view class="footer">
|
||||
<u-switch
|
||||
v-model="isSwitchOn"
|
||||
@change="handleSwitchChange"
|
||||
size="20"
|
||||
></u-switch>
|
||||
<!-- <view>{{ isSwitchOn ? '打开' : '关闭' }}</view> -->
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { GetRingStatus, UpdateRingStatus } from '../../../api/ring.js'
|
||||
import { GetShopBaseInfo, UpdataShopInfo } from "@/api/shop.js";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
ringtoneIsEnable: null,
|
||||
isSwitchOn: false,
|
||||
form: {}
|
||||
}
|
||||
isSwitchOn: false,
|
||||
shopInfo: {},
|
||||
};
|
||||
},
|
||||
onLoad() {
|
||||
this.getRingtoneStatus();
|
||||
@ -29,68 +30,70 @@ export default {
|
||||
methods: {
|
||||
async getRingtoneStatus() {
|
||||
try {
|
||||
let res = await GetRingStatus();
|
||||
this.ringtoneIsEnable = res.data.ringtone_is_enable;
|
||||
let res = await GetShopBaseInfo();
|
||||
this.isSwitchOn = res.data.ringtone_is_enable === 1;
|
||||
this.form = res.data;
|
||||
this.shopInfo = res.data;
|
||||
} catch (error) {
|
||||
uni.showToast({
|
||||
title: '获取状态失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
title: "获取状态失败",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
async handleSwitchChange(value) {
|
||||
try {
|
||||
const status = value ? 1 : 2;
|
||||
this.form.ringtone_is_enable = status;
|
||||
|
||||
const formData = new URLSearchParams();
|
||||
for (const key in this.form) {
|
||||
if (this.form.hasOwnProperty(key)) {
|
||||
formData.append(key, this.form[key]);
|
||||
}
|
||||
}
|
||||
let res = await UpdateRingStatus(formData);
|
||||
this.ringtoneIsEnable = status;
|
||||
const shopInfo = this.shopInfo
|
||||
let res = await UpdataShopInfo({
|
||||
store_logo: shopInfo.store_logo,
|
||||
store_slogan: shopInfo.store_slogan,
|
||||
store_tel: shopInfo.store_tel,
|
||||
company_description: shopInfo.company_description,
|
||||
ringtone_is_enable: status,
|
||||
});
|
||||
this.isSwitchOn = value;
|
||||
|
||||
|
||||
uni.showToast({
|
||||
title: `铃声已${value ? '开启' : '关闭'}`,
|
||||
icon: 'success',
|
||||
duration: 1500
|
||||
title: `铃声提醒已${value ? "开启" : "关闭"}`,
|
||||
icon: "success",
|
||||
duration: 1500,
|
||||
});
|
||||
} catch (error) {
|
||||
this.isSwitchOn = !value;
|
||||
uni.showToast({
|
||||
title: '更新失败,请重试',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
title: "更新失败,请重试",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
<style lang="scss">
|
||||
page {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.container {
|
||||
padding: 20rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.switch-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: 30rpx;
|
||||
gap: 15rpx;
|
||||
justify-content: space-between;
|
||||
padding: 20rpx;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 10rpx;
|
||||
background-color: #fff;
|
||||
border-bottom: 1px solid #eee;
|
||||
.footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
}
|
||||
|
||||
.switch-container text {
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import { GetOrderDetail } from "@/api/order";
|
||||
import { GetShopBaseInfo } from "@/api/shop.js";
|
||||
|
||||
const defaultState = () => {
|
||||
return {
|
||||
pushBase: {
|
||||
@ -41,6 +43,8 @@ const actions = {
|
||||
commit("SET_PUSH", pushBase);
|
||||
|
||||
var AUDIO = null;
|
||||
const res = await GetShopBaseInfo();
|
||||
const ringtone_is_enable = res.data.ringtone_is_enable === 1
|
||||
|
||||
//多次会调用播放新的文件时,提前销毁实例,可避免-99错误
|
||||
if (AUDIO) {
|
||||
@ -70,24 +74,29 @@ const actions = {
|
||||
break;
|
||||
// 订单列表
|
||||
case "mchOnLineOrderList":
|
||||
AUDIO.src = "../../static/mp3/jinxingzhong.MP3";
|
||||
AUDIO.play();
|
||||
console.log("播放成功");
|
||||
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
|
||||
if(ringtone_is_enable){
|
||||
AUDIO.src = "../../static/mp3/jinxingzhong.MP3";
|
||||
AUDIO.play();
|
||||
}
|
||||
|
||||
break;
|
||||
// 异常订单
|
||||
case "mchAbnormalOrderList":
|
||||
AUDIO.src = "../../static/mp3/yichang.MP3";
|
||||
AUDIO.play();
|
||||
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
|
||||
if(ringtone_is_enable){
|
||||
AUDIO.src = "../../static/mp3/yichang.MP3";
|
||||
AUDIO.play();
|
||||
}
|
||||
|
||||
break;
|
||||
// 退款订单
|
||||
case "mchRetrunOrderList":
|
||||
AUDIO.src = "../../static/mp3/tuihuo.MP3";
|
||||
AUDIO.play();
|
||||
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
|
||||
if(ringtone_is_enable){
|
||||
AUDIO.src = "../../static/mp3/tuihuo.MP3";
|
||||
AUDIO.play();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user