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 // #endif
import { mapState, mapActions } from "vuex"; import { mapState, mapActions } from "vuex";
import { webSocketManager } from "@/utils/socket.js"; import { webSocketManager } from "@/utils/socket.js";
import {GetRingStatus} from '@/api/ring.js'; import { GetShopBaseInfo } from "@/api/shop.js";
export default { export default {
data() { data() {
return { return {
@ -69,7 +69,7 @@ export default {
); );
}); });
}, },
initAppOrderPush() { async initAppOrderPush() {
uni.getPushClientId({ uni.getPushClientId({
success: (res) => { success: (res) => {
var push_clientid = res.cid; var push_clientid = res.cid;
@ -80,7 +80,7 @@ export default {
}, },
}); });
uni.onPushMessage((res) => { uni.onPushMessage(async (res) => {
console.log("收到推送消息:", res); // console.log("收到推送消息:", res); //
if (res.data) { if (res.data) {
@ -90,11 +90,14 @@ export default {
if (res.type == "click") { if (res.type == "click") {
this.handlePushClick(res.data.payload); this.handlePushClick(res.data.payload);
} else { } else {
let res = await GetShopBaseInfo();
if (res.data.ringtone_is_enable === 1) {
this.handlePushSound(res.data); this.handlePushSound(res.data);
uni.setStorageSync("pendingPushData", res.data); uni.setStorageSync("pendingPushData", res.data);
// //
uni.createPushMessage(res.data); uni.createPushMessage(res.data);
} }
}
} else { } else {
console.log("应用已打开,直接处理消息"); console.log("应用已打开,直接处理消息");
// UI // UI
@ -148,16 +151,10 @@ export default {
try { try {
// category使 // category使
const category = pushData.payload.category; const category = pushData.payload.category;
var AUDIO = uni.createInnerAudioContext(); var AUDIO = uni.createInnerAudioContext();
let res = await GetRingStatus();
console.log("声音",res);
if(res.data.ringtone_is_enable!==1){
console.log("没声音");
return;
}
// //
let soundFile = ""; let soundFile = "";
switch (category) { switch (category) {
case "mchOnLineOrderList": case "mchOnLineOrderList":
AUDIO.src = "/static/mp3/jinxingzhong.MP3"; AUDIO.src = "/static/mp3/jinxingzhong.MP3";

View File

@ -1,27 +1,28 @@
<template> <template>
<view class="container"> <view class="container">
<view class="switch-container"> <view class="switch-container">
<text>铃声状态</text> <view class="header">铃声消息提醒</view>
<view class="footer">
<u-switch <u-switch
v-model="isSwitchOn" v-model="isSwitchOn"
@change="handleSwitchChange" @change="handleSwitchChange"
size="20" size="20"
></u-switch> ></u-switch>
<text>{{ isSwitchOn ? '打开' : '关闭' }}</text> <!-- <view>{{ isSwitchOn ? '打开' : '关闭' }}</view> -->
</view>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import { GetRingStatus, UpdateRingStatus } from '../../../api/ring.js' import { GetShopBaseInfo, UpdataShopInfo } from "@/api/shop.js";
export default { export default {
data() { data() {
return { return {
ringtoneIsEnable: null,
isSwitchOn: false, isSwitchOn: false,
form: {} shopInfo: {},
} };
}, },
onLoad() { onLoad() {
this.getRingtoneStatus(); this.getRingtoneStatus();
@ -29,15 +30,14 @@ export default {
methods: { methods: {
async getRingtoneStatus() { async getRingtoneStatus() {
try { try {
let res = await GetRingStatus(); let res = await GetShopBaseInfo();
this.ringtoneIsEnable = res.data.ringtone_is_enable;
this.isSwitchOn = res.data.ringtone_is_enable === 1; this.isSwitchOn = res.data.ringtone_is_enable === 1;
this.form = res.data; this.shopInfo = res.data;
} catch (error) { } catch (error) {
uni.showToast({ uni.showToast({
title: '获取状态失败', title: "获取状态失败",
icon: 'none', icon: "none",
duration: 2000 duration: 2000,
}); });
} }
}, },
@ -45,52 +45,55 @@ export default {
async handleSwitchChange(value) { async handleSwitchChange(value) {
try { try {
const status = value ? 1 : 2; const status = value ? 1 : 2;
this.form.ringtone_is_enable = status; const shopInfo = this.shopInfo
let res = await UpdataShopInfo({
const formData = new URLSearchParams(); store_logo: shopInfo.store_logo,
for (const key in this.form) { store_slogan: shopInfo.store_slogan,
if (this.form.hasOwnProperty(key)) { store_tel: shopInfo.store_tel,
formData.append(key, this.form[key]); company_description: shopInfo.company_description,
} ringtone_is_enable: status,
} });
let res = await UpdateRingStatus(formData);
this.ringtoneIsEnable = status;
this.isSwitchOn = value; this.isSwitchOn = value;
uni.showToast({ uni.showToast({
title: `铃声${value ? '开启' : '关闭'}`, title: `铃声提醒已${value ? "开启" : "关闭"}`,
icon: 'success', icon: "success",
duration: 1500 duration: 1500,
}); });
} catch (error) { } catch (error) {
this.isSwitchOn = !value; this.isSwitchOn = !value;
uni.showToast({ uni.showToast({
title: '更新失败,请重试', title: "更新失败,请重试",
icon: 'none', icon: "none",
duration: 2000 duration: 2000,
}); });
} }
} },
} },
} };
</script> </script>
<style> <style lang="scss">
page {
background-color: #fff;
}
.container { .container {
padding: 20rpx; padding: 20rpx;
display: flex;
flex-direction: column;
min-height: 100vh;
} }
.switch-container { .switch-container {
display: flex; display: flex;
align-items: center; align-items: center;
margin-top: 30rpx; justify-content: space-between;
gap: 15rpx;
padding: 20rpx; padding: 20rpx;
background-color: #f5f5f5; background-color: #fff;
border-radius: 10rpx; border-bottom: 1px solid #eee;
.footer {
display: flex;
align-items: center;
justify-content: space-between;
}
} }
.switch-container text { .switch-container text {

View File

@ -1,4 +1,6 @@
import { GetOrderDetail } from "@/api/order"; import { GetOrderDetail } from "@/api/order";
import { GetShopBaseInfo } from "@/api/shop.js";
const defaultState = () => { const defaultState = () => {
return { return {
pushBase: { pushBase: {
@ -41,6 +43,8 @@ const actions = {
commit("SET_PUSH", pushBase); commit("SET_PUSH", pushBase);
var AUDIO = null; var AUDIO = null;
const res = await GetShopBaseInfo();
const ringtone_is_enable = res.data.ringtone_is_enable === 1
//多次会调用播放新的文件时,提前销毁实例,可避免-99错误 //多次会调用播放新的文件时,提前销毁实例,可避免-99错误
if (AUDIO) { if (AUDIO) {
@ -70,24 +74,29 @@ const actions = {
break; break;
// 订单列表 // 订单列表
case "mchOnLineOrderList": case "mchOnLineOrderList":
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
if(ringtone_is_enable){
AUDIO.src = "../../static/mp3/jinxingzhong.MP3"; AUDIO.src = "../../static/mp3/jinxingzhong.MP3";
AUDIO.play(); AUDIO.play();
console.log("播放成功"); }
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
break; break;
// 异常订单 // 异常订单
case "mchAbnormalOrderList": case "mchAbnormalOrderList":
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
if(ringtone_is_enable){
AUDIO.src = "../../static/mp3/yichang.MP3"; AUDIO.src = "../../static/mp3/yichang.MP3";
AUDIO.play(); AUDIO.play();
commit("SET_ORDER_STATUS_API", pushBase.payload.category); }
break; break;
// 退款订单 // 退款订单
case "mchRetrunOrderList": case "mchRetrunOrderList":
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
if(ringtone_is_enable){
AUDIO.src = "../../static/mp3/tuihuo.MP3"; AUDIO.src = "../../static/mp3/tuihuo.MP3";
AUDIO.play(); AUDIO.play();
commit("SET_ORDER_STATUS_API", pushBase.payload.category); }
break; break;
} }