update:新增语音开关

This commit is contained in:
lihaoyuan 2025-09-15 14:36:13 +08:00
parent c8ed6d1739
commit 0ffbddfd61
5 changed files with 145 additions and 4 deletions

View File

@ -4,6 +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';
export default {
data() {
return {
@ -142,14 +143,19 @@ export default {
},
// -
// handlePushSound
handlePushSound(pushData) {
async handlePushSound(pushData) {
console.log(pushData.payload);
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) {

View File

@ -0,0 +1,21 @@
import http from "../utils/http";
import config from "../config/config";
export function GetRingStatus() {
return http({
url: '/shop/shop-store-base/get',
method: 'get',
baseURL: config.adminApi,
});
}
export function UpdateRingStatus(formData) {
return http({
url: '/shop/shop-store-base/storeSetUp',
method: 'post',
baseURL: config.adminApi,
data: formData, // 提交表单数据
headers: {
'Content-Type': 'application/x-www-form-urlencoded' // 设置请求头为表单格式
}
});
}

View File

@ -271,6 +271,13 @@
"style": {
"navigationBarTitleText": "我的举报"
}
},
{
"path" : "pages/my/rings/rings",
"style" :
{
"navigationBarTitleText" : "铃声设置"
}
}
],
"globalStyle": {

View File

@ -151,7 +151,7 @@
iconStyle="marginRight:6px; color: #62BBAE"
:border="false"
isLink
url="/pages/my/printer/printerList"
url="/pages/my/rings/rings"
icon="bell-fill"
title="铃声设置"
></u-cell>

View File

@ -0,0 +1,107 @@
<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>
</view>
</template>
<script>
import { GetRingStatus, UpdateRingStatus } from '../../../api/ring.js'
export default {
data() {
return {
ringtoneIsEnable: null,
isSwitchOn: false,
form: {}
}
},
onLoad() {
this.getRingtoneStatus();
},
methods: {
async getRingtoneStatus() {
try {
let res = await GetRingStatus();
this.ringtoneIsEnable = res.data.ringtone_is_enable;
this.isSwitchOn = res.data.ringtone_is_enable === 1;
this.form = res.data;
} catch (error) {
uni.showToast({
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;
this.isSwitchOn = value;
uni.showToast({
title: `铃声已${value ? '开启' : '关闭'}`,
icon: 'success',
duration: 1500
});
} catch (error) {
this.isSwitchOn = !value;
uni.showToast({
title: '更新失败,请重试',
icon: 'none',
duration: 2000
});
}
}
}
}
</script>
<style>
.container {
padding: 20rpx;
display: flex;
flex-direction: column;
min-height: 100vh;
}
.switch-container {
display: flex;
align-items: center;
margin-top: 30rpx;
gap: 15rpx;
padding: 20rpx;
background-color: #f5f5f5;
border-radius: 10rpx;
}
.switch-container text {
font-size: 32rpx;
color: #333;
}
.loading-text {
margin-top: 30rpx;
font-size: 30rpx;
color: #666;
padding: 20rpx;
}
</style>