WMS_PDA/pages/settings/index.vue

360 lines
8.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="normar_container">
<page-nav title="设置"></page-nav>
<view class="settings-page">
<!-- 当前登录信息 -->
<view class="login-info">
<text class="login-title">当前登录工号:</text>
<text class="login-user">{{ userInfo.employees_name || '未登录' }}</text>
</view>
<!-- 设置列表 -->
<view class="settings-list">
<u-cell-group :border="false">
<u-cell v-for="(item, index) in operationList" :key="index" :title="item.title" :icon="item.icon"
:icon-color="item.iconColor" :isLink="true" @click="handleOperationClick(item)">
</u-cell>
</u-cell-group>
</view>
<!-- 声音与通知 -->
<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>
</u-cell>
</u-cell-group>
</view>
<!-- 底部登出按钮 -->
<view class="logout-section">
<u-button type="error" shape="circle" @click="showLogoutConfirm" :loading="logoutLoading">
退出登录
</u-button>
</view>
<!-- 登出确认弹窗 -->
<u-modal :show="showLogoutModal" :show-cancel-button="true" confirm-text="确定退出" cancel-text="取消"
@confirm="logout" @cancel="showLogoutModal = false">
<view class="modal-content">
<u-icon name="info-circle" size="60" color="#f0ad4e"></u-icon>
<text class="modal-title">确认退出登录?</text>
<text class="modal-desc">退出后将需要重新登录</text>
</view>
</u-modal>
</view>
</view>
</template>
<script>
import { goLogin, isLoginRoute, getCurrentRoute } from '@/core/utils/auth-guard'
export default {
data() {
return {
// 用户信息
userInfo: {},
// 设置列表数据
operationList: [{
title: '账号与安全',
icon: 'lock',
iconColor: '#4cd964',
pageName: 'accountSecurity',
url: '/pages/settings/accountSecurity',
needLogin: true
},
{
title: '广播设置',
icon: 'scan',
iconColor: '#dd524d',
pageName: 'broadcastSettings',
url: '/pages/settings/broadcastSettings'
},
{
title: '设备查找',
icon: 'search',
iconColor: '#007aff',
pageName: 'deviceSearch',
url: '/pages/settings/deviceSearch'
},
{
title: '扫描音效',
icon: 'bell',
iconColor: '#f0ad4e',
pageName: 'scanSound',
url: '/pages/settings/scanSound',
badge: 0
},
{
title: '关于',
icon: 'info-circle',
iconColor: '#808080',
pageName: 'about',
url: '/pages/settings/about'
}
],
// 登出相关
showLogoutModal: false,
logoutLoading: false,
voiceBroadcastEnabled: true
}
},
onShow() {
// 页面显示时加载用户信息
this.loadUserInfo();
this.loadVoiceSettings();
},
methods: {
// 加载用户信息
loadUserInfo() {
const token = uni.getStorageSync('token');
const userData = this.$store.getters.user || {};
if (token && Object.keys(userData).length > 0) {
this.userInfo = userData;
} else {
this.userInfo = {};
// 如果未登录,跳转到登录页
goLogin();
}
},
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) {
console.log('点击了:', item.title);
// 检查是否需要登录
if (item.needLogin && !this.checkLogin()) {
uni.showToast({
title: '请先登录',
icon: 'none'
});
return;
}
// 跳转到对应页面
this.navigateTo(item.pageName, item.url);
},
// 检查登录状态
checkLogin() {
const token = uni.getStorageSync('token');
return !!token;
},
// 页面跳转
navigateTo(pageName, customUrl = null) {
const routeMap = {
accountSecurity: '/pages/settings/accountSecurity',
broadcastSettings: '/pages/settings/broadcastSettings',
deviceSearch: '/pages/settings/deviceSearch',
scanSound: '/pages/settings/scanSound',
about: '/pages/settings/about'
};
const url = customUrl || routeMap[pageName];
if (!url) {
console.error('未找到页面路由:', pageName);
uni.showToast({
title: '页面不存在',
icon: 'error'
});
return;
}
uni.navigateTo({
url: url,
fail: (err) => {
console.error('跳转失败:', err);
uni.showToast({
title: '页面跳转失败',
icon: 'none'
});
}
});
},
// 显示登出确认弹窗
showLogoutConfirm() {
this.showLogoutModal = true;
},
// 登出
async logout() {
this.logoutLoading = true;
try {
// 调用登出 action
await this.$store.dispatch('logout');
if (!isLoginRoute(getCurrentRoute())) {
await goLogin();
}
// 登出成功提示
uni.showToast({
title: '已退出登录',
icon: 'success',
duration: 1500
});
} catch (error) {
console.error('登出失败:', error);
uni.showToast({
title: '登出失败,请重试',
icon: 'error'
});
} finally {
this.logoutLoading = false;
this.showLogoutModal = false;
}
}
}
}
</script>
<style lang="scss" scoped>
.settings-page {
background-color: #f8f8f8;
height: calc(100% - 44px - env(safe-area-inset-top));
// 页面标题
.page-header {
height: 120rpx;
background: linear-gradient(135deg, #4cd964, #5ac8fa);
display: flex;
align-items: center;
justify-content: center;
.page-title {
font-size: 40rpx;
font-weight: bold;
color: #fff;
text-align: center;
}
}
// 登录信息
.login-info {
background-color: #fff;
padding: 30rpx;
margin-bottom: 20rpx;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #f0f0f0;
.login-title {
font-size: 32rpx;
color: #333;
font-weight: 500;
}
.login-user {
font-size: 34rpx;
color: #4cd964;
font-weight: bold;
}
}
// 设置列表
.settings-list {
background-color: #fff;
margin-bottom: 20rpx;
::v-deep .u-cell {
padding: 10rpx 20rpx !important;
}
::v-deep .u-cell_title {
font-size: 34rpx !important;
}
}
.settings-list--notification {
padding-top: 6rpx;
}
.settings-section-title {
font-size: 26rpx;
color: #909399;
padding: 10rpx 24rpx 6rpx;
}
// 登出按钮区域
.logout-section {
padding: 40rpx 30rpx;
::v-deep .u-btn {
height: 100rpx;
font-size: 36rpx;
display: flex;
align-items: center;
justify-content: center;
}
}
// 模态框内容
.modal-content {
padding: 40rpx 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.modal-title {
font-size: 36rpx;
font-weight: bold;
color: #333;
margin-top: 30rpx;
margin-bottom: 20rpx;
}
.modal-desc {
font-size: 28rpx;
color: #666;
text-align: center;
}
}
}
</style>