update: 优化铃声设置页面UI逻辑;根据铃声开关判断是否需要推送铃声提醒。
This commit is contained in:
parent
0ffbddfd61
commit
e0f409c726
@ -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,10 +90,13 @@ export default {
|
|||||||
if (res.type == "click") {
|
if (res.type == "click") {
|
||||||
this.handlePushClick(res.data.payload);
|
this.handlePushClick(res.data.payload);
|
||||||
} else {
|
} else {
|
||||||
this.handlePushSound(res.data);
|
let res = await GetShopBaseInfo();
|
||||||
uni.setStorageSync("pendingPushData", res.data);
|
if (res.data.ringtone_is_enable === 1) {
|
||||||
// 创建通知
|
this.handlePushSound(res.data);
|
||||||
uni.createPushMessage(res.data);
|
uni.setStorageSync("pendingPushData", res.data);
|
||||||
|
// 创建通知
|
||||||
|
uni.createPushMessage(res.data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("应用已打开,直接处理消息");
|
console.log("应用已打开,直接处理消息");
|
||||||
@ -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";
|
||||||
|
|||||||
@ -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>
|
||||||
<u-switch
|
<view class="footer">
|
||||||
v-model="isSwitchOn"
|
<u-switch
|
||||||
@change="handleSwitchChange"
|
v-model="isSwitchOn"
|
||||||
size="20"
|
@change="handleSwitchChange"
|
||||||
></u-switch>
|
size="20"
|
||||||
<text>{{ isSwitchOn ? '打开' : '关闭' }}</text>
|
></u-switch>
|
||||||
|
<!-- <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,
|
shopInfo: {},
|
||||||
form: {}
|
};
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.getRingtoneStatus();
|
this.getRingtoneStatus();
|
||||||
@ -29,68 +30,70 @@ 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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
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 {
|
||||||
|
|||||||
@ -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":
|
||||||
AUDIO.src = "../../static/mp3/jinxingzhong.MP3";
|
|
||||||
AUDIO.play();
|
|
||||||
console.log("播放成功");
|
|
||||||
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
|
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
|
||||||
|
if(ringtone_is_enable){
|
||||||
|
AUDIO.src = "../../static/mp3/jinxingzhong.MP3";
|
||||||
|
AUDIO.play();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
// 异常订单
|
// 异常订单
|
||||||
case "mchAbnormalOrderList":
|
case "mchAbnormalOrderList":
|
||||||
AUDIO.src = "../../static/mp3/yichang.MP3";
|
|
||||||
AUDIO.play();
|
|
||||||
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
|
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
|
||||||
|
if(ringtone_is_enable){
|
||||||
|
AUDIO.src = "../../static/mp3/yichang.MP3";
|
||||||
|
AUDIO.play();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
// 退款订单
|
// 退款订单
|
||||||
case "mchRetrunOrderList":
|
case "mchRetrunOrderList":
|
||||||
AUDIO.src = "../../static/mp3/tuihuo.MP3";
|
|
||||||
AUDIO.play();
|
|
||||||
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
|
commit("SET_ORDER_STATUS_API", pushBase.payload.category);
|
||||||
|
if(ringtone_is_enable){
|
||||||
|
AUDIO.src = "../../static/mp3/tuihuo.MP3";
|
||||||
|
AUDIO.play();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user