wode-shezhi.vue
8.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<template>
<view class="settings-page">
<!-- 手机号设置 -->
<view class="setting-item">
<view class="setting-label">手机号</view>
<view class="setting-value">{{ phone || '未设置' }}</view>
</view>
<!-- 微信绑定状态 -->
<view class="setting-item">
<view class="setting-label">微信绑定</view>
<view class="setting-status" :class="{ bound: isBindWx === 1, unbound: isBindWx === 0 }">
{{ isBindWx === 1 ? '已绑定' : '未绑定' }}
</view>
<!-- <button v-if="isBindWx === 0" class="bind-btn" @click="bindWeChat">绑定微信</button>
<button v-else class="unbind-btn" @click="unbindWeChat">解绑</button> -->
</view>
<!-- 推送通知开关 -->
<!-- <view class="setting-item notice">
<view class="content">
<view class="setting-label">推送通知</view>
<switch :checked="pushNoticeSwitch === 1" @change="onPushNoticeChange" color="#007AFF" />
</view>
<view class="tip">包含订单状态、优惠促销等重要信息的推送</view>
</view> -->
<!-- 个性化推荐开关 -->
<!-- <view class="setting-item">
<view class="setting-label">个性化推荐</view>
<switch :checked="personRecommendSwitch === 1" @change="onRecommendChange" color="#007AFF" />
</view> -->
<!-- 退出登录 -->
<view class="logout-section">
<button class="logout-btn" @click="logout">退出登录</button>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import SettingApi from '@/sheep/api/setting/setting';
import AuthUtil from '@/sheep/api/member/auth';
import useUserStore from '@/sheep/store/user';
import UserApi from '@/sheep/api/member/user';
// 数据状态
const phone = ref('');
const isBindWx = ref(0); // 0:未绑定, 1:已绑定
const pushNoticeSwitch = ref(0); // 0:关闭, 1:开启
const personRecommendSwitch = ref(0); // 0:关闭, 1:开启
const userStore = useUserStore();
// 生命周期
onShow(() => {
loadUserSettings();
});
// 加载用户设置
const loadUserSettings = async () => {
// 这里调用后端接口获取设置数据
const res = await SettingApi.getSetting();
phone.value = res.data.phone;
isBindWx.value = res.data.isBindWx;
pushNoticeSwitch.value = res.data.pushNoticeSwitch;
personRecommendSwitch.value = res.data.personRecommendSwitch;
};
// // 微信绑定
// const bindWeChat = () => {
// uni.showModal({
// title: '绑定微信',
// content: '确定要绑定微信吗?',
// success: async (res) => {
// if (res.confirm) {
// try {
// // 这里调用绑定微信接口
// // await uni.request({
// // url: '/api/user/bind-wechat',
// // method: 'POST'
// // })
// isBindWx.value = 1;
// uni.showToast({
// title: '绑定成功',
// icon: 'success',
// });
// } catch (error) {
// console.error('绑定失败:', error);
// uni.showToast({
// title: '绑定失败',
// icon: 'none',
// });
// }
// }
// },
// });
// };
// // 微信解绑
// const unbindWeChat = () => {
// uni.showModal({
// title: '解绑微信',
// content: '确定要解绑微信吗?',
// success: async (res) => {
// if (res.confirm) {
// try {
// // 这里调用解绑微信接口
// // await uni.request({
// // url: '/api/user/unbind-wechat',
// // method: 'POST'
// // })
// isBindWx.value = 0;
// uni.showToast({
// title: '解绑成功',
// icon: 'success',
// });
// } catch (error) {
// console.error('解绑失败:', error);
// uni.showToast({
// title: '解绑失败',
// icon: 'none',
// });
// }
// }
// },
// });
// };
// 推送通知开关改变
const onPushNoticeChange = async (e) => {
const newValue = e.detail.value ? 1 : 0;
try {
// 这里调用更新设置接口
await SettingApi.updateNoticeSetting({
pushNoticeSwitch: newValue,
personRecommendSwitch: personRecommendSwitch.value,
});
pushNoticeSwitch.value = newValue;
uni.showToast({
title: newValue ? '已开启推送' : '已关闭推送',
icon: 'success',
});
} catch (error) {
console.error('更新推送设置失败:', error);
// 恢复原状态
pushNoticeSwitch.value = pushNoticeSwitch.value === 1 ? 0 : 1;
uni.showToast({
title: '设置失败',
icon: 'none',
});
}
};
// 个性化推荐开关改变
const onRecommendChange = async (e) => {
const newValue = e.detail.value ? 1 : 0;
try {
// 这里调用更新设置接口
await SettingApi.updateNoticeSetting({
personRecommendSwitch: newValue,
pushNoticeSwitch: pushNoticeSwitch.value,
});
personRecommendSwitch.value = newValue;
uni.showToast({
title: newValue ? '已开启推荐' : '已关闭推荐',
icon: 'success',
});
} catch (error) {
console.error('更新推荐设置失败:', error);
// 恢复原状态
personRecommendSwitch.value = personRecommendSwitch.value === 1 ? 0 : 1;
uni.showToast({
title: '设置失败',
icon: 'none',
});
}
};
// 退出登录
const logout = () => {
uni.showModal({
title: '提示',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
// 调用退出登录接口
AuthUtil.logout().then(() => {
// 清空用户信息
userStore.logout();
// 跳转到登录页
uni.reLaunch({ url: '/pages/index/index' });
});
}
},
});
};
</script>
<style lang="scss" scoped>
// 定义全局变量,方便统一管理
$primary-color: #007aff;
$danger-color: #ff4757;
$danger-active-color: #e63946;
$bg-color: #f5f5f5;
$white-color: #ffffff;
$text-primary: #333333;
$text-secondary: #666666;
$text-tertiary: #999999;
$border-radius-base: 16rpx;
$border-radius-small: 8rpx;
$padding-base: 30rpx;
$padding-small: 20rpx;
.settings-page {
background-color: $bg-color;
padding: $padding-small;
// 设置项通用样式
.setting-item {
background-color: $white-color;
margin-bottom: $padding-small;
padding: $padding-base;
border-radius: $border-radius-base;
display: flex;
align-items: center;
justify-content: space-between;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
// 标签样式
.setting-label {
font-size: 32rpx;
color: $text-primary;
font-weight: 500;
}
// 值样式
.setting-value {
font-size: 28rpx;
color: $text-secondary;
}
// 状态样式
.setting-status {
font-size: 28rpx;
font-weight: 500;
margin-right: 20rpx;
&.bound {
color: $primary-color;
}
&.unbound {
color: $text-tertiary;
}
}
// 绑定/解绑按钮
.bind-btn,
.unbind-btn {
background-color: $primary-color;
color: $white-color;
border: none;
border-radius: $border-radius-small;
padding: 16rpx 24rpx;
font-size: 26rpx;
&.unbind-btn {
background-color: $danger-color;
}
}
// 通知设置特殊样式
&.notice {
display: block;
.content {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16rpx;
}
.tip {
font-size: 24rpx;
color: $text-tertiary;
line-height: 1.4;
}
}
}
.notice {
display: flex;
flex-direction: column;
}
// 退出登录区域
.logout-section {
margin-top: 60rpx;
padding: $padding-small;
.logout-btn {
width: 100%;
background-color: $danger-color;
color: $white-color;
border: none;
border-radius: $border-radius-base;
padding: $padding-base;
font-size: 32rpx;
font-weight: 500;
&:active {
background-color: $danger-active-color;
}
}
}
}
</style>