update: 优化铃声设置页面UI逻辑;根据铃声开关判断是否需要推送铃声提醒。

This commit is contained in:
mixtan 2025-09-15 22:23:12 +08:00
parent 0ffbddfd61
commit e0f409c726
3 changed files with 77 additions and 68 deletions

View File

@ -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,11 +90,14 @@ export default {
if (res.type == "click") {
this.handlePushClick(res.data.payload);
} else {
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("应用已打开,直接处理消息");
// UI
@ -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";

View File

@ -1,27 +1,28 @@
<template>
<view class="container">
<view class="switch-container">
<text>铃声状态</text>
<view class="header">铃声消息提醒</view>
<view class="footer">
<u-switch
v-model="isSwitchOn"
@change="handleSwitchChange"
size="20"
></u-switch>
<text>{{ isSwitchOn ? '打开' : '关闭' }}</text>
<!-- <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: {}
}
shopInfo: {},
};
},
onLoad() {
this.getRingtoneStatus();
@ -29,15 +30,14 @@ 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,
});
}
},
@ -45,52 +45,55 @@ export default {
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 {

View File

@ -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":
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
if(ringtone_is_enable){
AUDIO.src = "../../static/mp3/jinxingzhong.MP3";
AUDIO.play();
console.log("播放成功");
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
}
break;
// 异常订单
case "mchAbnormalOrderList":
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
if(ringtone_is_enable){
AUDIO.src = "../../static/mp3/yichang.MP3";
AUDIO.play();
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
}
break;
// 退款订单
case "mchRetrunOrderList":
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
if(ringtone_is_enable){
AUDIO.src = "../../static/mp3/tuihuo.MP3";
AUDIO.play();
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
}
break;
}