新增设置语音播报开关并完善收货列表语音播报逻辑
This commit is contained in:
parent
eaa0d03207
commit
7c7639a1e9
@ -13,6 +13,9 @@ const defaultSettings = {
|
|||||||
'scan.vibrate': 'true',
|
'scan.vibrate': 'true',
|
||||||
'scan.auto_focus': 'true',
|
'scan.auto_focus': 'true',
|
||||||
|
|
||||||
|
// 声音与通知
|
||||||
|
'voice.enabled': 'true',
|
||||||
|
|
||||||
// 界面相关
|
// 界面相关
|
||||||
'ui.theme': 'light',
|
'ui.theme': 'light',
|
||||||
'ui.language': 'zh_CN',
|
'ui.language': 'zh_CN',
|
||||||
@ -243,6 +246,19 @@ const getters = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 获取声音与通知设置
|
||||||
|
voiceSettings: state => {
|
||||||
|
if (Object.keys(state.settings).length === 0) {
|
||||||
|
return {
|
||||||
|
enabled: defaultSettings['voice.enabled'] === 'true'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
enabled: state.settings['voice.enabled'] === 'true'
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
// 获取界面设置
|
// 获取界面设置
|
||||||
uiSettings: state => {
|
uiSettings: state => {
|
||||||
if (Object.keys(state.settings).length === 0) {
|
if (Object.keys(state.settings).length === 0) {
|
||||||
|
|||||||
@ -148,6 +148,22 @@ export default {
|
|||||||
* @return {Promise<Boolean>}
|
* @return {Promise<Boolean>}
|
||||||
*/
|
*/
|
||||||
speakText(text = '', options = {}) {
|
speakText(text = '', options = {}) {
|
||||||
|
try {
|
||||||
|
const saved = uni.getStorageSync('app_settings');
|
||||||
|
let settings = null;
|
||||||
|
if (typeof saved === 'string' && saved) {
|
||||||
|
settings = JSON.parse(saved);
|
||||||
|
} else if (saved && typeof saved === 'object') {
|
||||||
|
settings = saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings && settings['voice.enabled'] === 'false') {
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('[tools.speakText] 读取语音播报开关失败,使用默认开启:', error);
|
||||||
|
}
|
||||||
|
|
||||||
return voice.speak(text, options);
|
return voice.speak(text, options);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -12,12 +12,22 @@
|
|||||||
<view class="settings-list">
|
<view class="settings-list">
|
||||||
<u-cell-group :border="false">
|
<u-cell-group :border="false">
|
||||||
<u-cell v-for="(item, index) in operationList" :key="index" :title="item.title" :icon="item.icon"
|
<u-cell v-for="(item, index) in operationList" :key="index" :title="item.title" :icon="item.icon"
|
||||||
:icon-color="item.iconColor" @click="handleOperationClick(item)">
|
:icon-color="item.iconColor" :isLink="true" @click="handleOperationClick(item)">
|
||||||
<!-- 角标 -->
|
</u-cell>
|
||||||
<template #right-icon>
|
</u-cell-group>
|
||||||
<u-badge v-if="item.badge && item.badge > 0" :value="item.badge" type="error"
|
</view>
|
||||||
size="mini"></u-badge>
|
|
||||||
<u-icon v-else name="arrow-right" size="20" color="#ccc"></u-icon>
|
<!-- 声音与通知 -->
|
||||||
|
<view class="settings-list settings-list--notification">
|
||||||
|
<view class="settings-section-title">声音与通知</view>
|
||||||
|
<u-cell-group :border="false">
|
||||||
|
<u-cell title="语音播报" icon="volume" icon-color="#ff9900">
|
||||||
|
<template #value>
|
||||||
|
<u-switch
|
||||||
|
v-model="voiceBroadcastEnabled"
|
||||||
|
:active-color="'#4cd964'"
|
||||||
|
@change="handleVoiceBroadcastToggle"
|
||||||
|
></u-switch>
|
||||||
</template>
|
</template>
|
||||||
</u-cell>
|
</u-cell>
|
||||||
</u-cell-group>
|
</u-cell-group>
|
||||||
@ -94,12 +104,14 @@
|
|||||||
|
|
||||||
// 登出相关
|
// 登出相关
|
||||||
showLogoutModal: false,
|
showLogoutModal: false,
|
||||||
logoutLoading: false
|
logoutLoading: false,
|
||||||
|
voiceBroadcastEnabled: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
// 页面显示时加载用户信息
|
// 页面显示时加载用户信息
|
||||||
this.loadUserInfo();
|
this.loadUserInfo();
|
||||||
|
this.loadVoiceSettings();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 加载用户信息
|
// 加载用户信息
|
||||||
@ -115,6 +127,36 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async loadVoiceSettings() {
|
||||||
|
try {
|
||||||
|
const enabled = await this.$store.dispatch('setting/getValue', 'voice.enabled');
|
||||||
|
this.voiceBroadcastEnabled = enabled !== 'false';
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('加载语音播报设置失败:', error);
|
||||||
|
this.voiceBroadcastEnabled = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handleVoiceBroadcastToggle(value) {
|
||||||
|
const enabled = value !== false;
|
||||||
|
this.voiceBroadcastEnabled = enabled;
|
||||||
|
try {
|
||||||
|
await this.$store.dispatch('setting/setValue', {
|
||||||
|
key: 'voice.enabled',
|
||||||
|
value: enabled ? 'true' : 'false'
|
||||||
|
});
|
||||||
|
uni.showToast({
|
||||||
|
title: enabled ? '已开启语音播报' : '已关闭语音播报',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('保存语音播报设置失败:', error);
|
||||||
|
this.voiceBroadcastEnabled = !enabled;
|
||||||
|
uni.showToast({
|
||||||
|
title: '保存失败,请重试',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
// 处理设置项点击
|
// 处理设置项点击
|
||||||
handleOperationClick(item) {
|
handleOperationClick(item) {
|
||||||
console.log('点击了:', item.title);
|
console.log('点击了:', item.title);
|
||||||
@ -269,6 +311,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.settings-list--notification {
|
||||||
|
padding-top: 6rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-section-title {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #909399;
|
||||||
|
padding: 10rpx 24rpx 6rpx;
|
||||||
|
}
|
||||||
|
|
||||||
// 登出按钮区域
|
// 登出按钮区域
|
||||||
.logout-section {
|
.logout-section {
|
||||||
padding: 40rpx 30rpx;
|
padding: 40rpx 30rpx;
|
||||||
|
|||||||
@ -259,15 +259,19 @@
|
|||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
this.$store.dispatch('broadcast/resume');
|
this.$store.dispatch('broadcast/resume');
|
||||||
this.loadReceivingList();
|
this.loadReceivingList({
|
||||||
|
silentVoice: true
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onHide() {
|
onHide() {
|
||||||
this.$store.dispatch('broadcast/stop');
|
this.$store.dispatch('broadcast/stop');
|
||||||
|
this.stopReceivingSpeak();
|
||||||
},
|
},
|
||||||
|
|
||||||
onUnload() {
|
onUnload() {
|
||||||
this.$store.dispatch('broadcast/stop');
|
this.$store.dispatch('broadcast/stop');
|
||||||
|
this.stopReceivingSpeak();
|
||||||
},
|
},
|
||||||
|
|
||||||
onPullDownRefresh() {
|
onPullDownRefresh() {
|
||||||
@ -277,11 +281,88 @@
|
|||||||
watch: {
|
watch: {
|
||||||
currentPage(newval) {
|
currentPage(newval) {
|
||||||
console.log('页码变化:', newval);
|
console.log('页码变化:', newval);
|
||||||
this.loadReceivingList();
|
this.loadReceivingList({
|
||||||
|
silentVoice: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
normalizeSpeechText(message) {
|
||||||
|
const rawText = String(message || '').trim();
|
||||||
|
if (!rawText) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const digitMap = {
|
||||||
|
'0': '零',
|
||||||
|
'1': '一',
|
||||||
|
'2': '二',
|
||||||
|
'3': '三',
|
||||||
|
'4': '四',
|
||||||
|
'5': '五',
|
||||||
|
'6': '六',
|
||||||
|
'7': '七',
|
||||||
|
'8': '八',
|
||||||
|
'9': '九'
|
||||||
|
};
|
||||||
|
|
||||||
|
const normalizeCodeSegment = (segment) => {
|
||||||
|
return segment
|
||||||
|
.split('-')
|
||||||
|
.map(part => String(part || '')
|
||||||
|
.split('')
|
||||||
|
.map(char => (digitMap[char] || char))
|
||||||
|
.join(''))
|
||||||
|
.join('的');
|
||||||
|
};
|
||||||
|
|
||||||
|
return rawText.replace(/([A-Za-z0-9]+(?:-[A-Za-z0-9]+)+)/g, normalizeCodeSegment);
|
||||||
|
},
|
||||||
|
speakReceivingMessage(message, options = {}) {
|
||||||
|
const text = this.normalizeSpeechText(message);
|
||||||
|
if (!text) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tools = this.$tools;
|
||||||
|
if (!tools || typeof tools.speakText !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const task = tools.speakText(text, options);
|
||||||
|
if (task && typeof task.catch === 'function') {
|
||||||
|
task.catch(error => {
|
||||||
|
console.warn('[ReceivingList] 语音播报失败:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('[ReceivingList] 语音播报异常:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
stopReceivingSpeak() {
|
||||||
|
const tools = this.$tools;
|
||||||
|
if (!tools || typeof tools.stopSpeak !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
tools.stopSpeak();
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('[ReceivingList] 停止语音播报异常:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getReceivingListVoiceText() {
|
||||||
|
const modeText = this.activeStatus === 'all'
|
||||||
|
? '全部状态'
|
||||||
|
: this.getStatusText(this.activeStatus);
|
||||||
|
const count = Number(this.totalItems || 0);
|
||||||
|
if (count > 0) {
|
||||||
|
return `${modeText},查询到${count}条收货任务`;
|
||||||
|
}
|
||||||
|
return `${modeText},未查询到收货任务`;
|
||||||
|
},
|
||||||
// 日期格式化函数
|
// 日期格式化函数
|
||||||
formatDate(date) {
|
formatDate(date) {
|
||||||
const d = new Date(date);
|
const d = new Date(date);
|
||||||
@ -448,7 +529,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 加载收货列表
|
// 加载收货列表
|
||||||
async loadReceivingList() {
|
async loadReceivingList(options = {}) {
|
||||||
|
const silentVoice = !!(options && options.silentVoice);
|
||||||
if (this.loading) return;
|
if (this.loading) return;
|
||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
@ -514,6 +596,10 @@
|
|||||||
if (summary) {
|
if (summary) {
|
||||||
this.updateStatusCount(summary);
|
this.updateStatusCount(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!silentVoice) {
|
||||||
|
this.speakReceivingMessage(this.getReceivingListVoiceText());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载收货列表失败:', error);
|
console.error('加载收货列表失败:', error);
|
||||||
@ -521,6 +607,9 @@
|
|||||||
title: '加载失败',
|
title: '加载失败',
|
||||||
icon: 'error'
|
icon: 'error'
|
||||||
});
|
});
|
||||||
|
if (!silentVoice) {
|
||||||
|
this.speakReceivingMessage('加载收货列表失败,请重试');
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.refreshing = false;
|
this.refreshing = false;
|
||||||
@ -561,22 +650,37 @@
|
|||||||
},
|
},
|
||||||
// 搜索处理
|
// 搜索处理
|
||||||
handleSearch() {
|
handleSearch() {
|
||||||
this.currentPage = 1;
|
if (this.currentPage !== 1) {
|
||||||
this.loadReceivingList();
|
this.currentPage = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loadReceivingList({
|
||||||
|
silentVoice: false
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 状态切换
|
// 状态切换
|
||||||
changeStatus(status) {
|
changeStatus(status) {
|
||||||
this.activeStatus = status;
|
this.activeStatus = status;
|
||||||
this.currentPage = 1;
|
if (this.currentPage !== 1) {
|
||||||
this.loadReceivingList();
|
this.currentPage = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loadReceivingList({
|
||||||
|
silentVoice: false
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 下拉刷新
|
// 下拉刷新
|
||||||
onRefresh() {
|
onRefresh() {
|
||||||
this.refreshing = true;
|
this.refreshing = true;
|
||||||
this.currentPage = 1;
|
if (this.currentPage !== 1) {
|
||||||
this.loadReceivingList();
|
this.currentPage = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loadReceivingList({
|
||||||
|
silentVoice: false
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 显示筛选弹窗
|
// 显示筛选弹窗
|
||||||
@ -600,8 +704,13 @@
|
|||||||
// 应用筛选
|
// 应用筛选
|
||||||
applyFilter() {
|
applyFilter() {
|
||||||
this.filterVisible = false;
|
this.filterVisible = false;
|
||||||
this.currentPage = 1;
|
if (this.currentPage !== 1) {
|
||||||
this.loadReceivingList();
|
this.currentPage = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loadReceivingList({
|
||||||
|
silentVoice: false
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 新建收货
|
// 新建收货
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user