ProfileMenu.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <template>
  2. <view>
  3. <view class="menu-list">
  4. <!-- ===== 个人 ===== -->
  5. <view class="menu-group">
  6. <view class="menu-group-title">── 个人 ──</view>
  7. <view class="menu-item" @click="goToMessageHistory">
  8. <text>📨 消息历史</text>
  9. <text class="arrow">›</text>
  10. </view>
  11. <view class="menu-item" v-if="role === 'parent'" @click="goToFamilyMembers">
  12. <text>👨‍👩‍👧‍👦 家庭成员</text>
  13. <text class="arrow">›</text>
  14. </view>
  15. <view class="menu-item" v-if="role === 'parent'" @click="goToAppointments">
  16. <text>📅 测评预约</text>
  17. <text class="arrow">›</text>
  18. </view>
  19. <view class="menu-item" @click="goToDailyTasks">
  20. <text>📋 每日任务</text>
  21. <text class="arrow">›</text>
  22. </view>
  23. <view class="menu-item" v-if="role === 'parent'" @click="goToOnboarding">
  24. <text>🎯 新手任务</text>
  25. <text class="arrow">›</text>
  26. </view>
  27. <view class="menu-item" @click="goToReportManagement">
  28. <text>📋 报告管理</text>
  29. <text class="arrow">›</text>
  30. </view>
  31. <view class="menu-item" @click="goToServiceRoleApply">
  32. <text>📋 服务角色申请</text>
  33. <text class="arrow">›</text>
  34. </view>
  35. </view>
  36. <!-- ===== 服务 ===== -->
  37. <view class="menu-group" v-if="showServices">
  38. <view class="menu-group-title">── 服务 ──</view>
  39. <view class="menu-item" @click="goToShop">
  40. <text>🛍️ 商城</text>
  41. <text class="arrow">›</text>
  42. </view>
  43. <view class="menu-item" @click="goToCart">
  44. <text>🛒 购物车</text>
  45. <text class="arrow">›</text>
  46. </view>
  47. <view class="menu-item" @click="goToMembership">
  48. <text>👑 会员中心</text>
  49. <text class="arrow">›</text>
  50. </view>
  51. <view class="menu-item" v-if="isVendor" @click="goToVendorCenter">
  52. <text>🏪 服务商中心</text>
  53. <text class="arrow">›</text>
  54. </view>
  55. <view class="menu-item" @click="goToOrders">
  56. <text>🛒 订单管理</text>
  57. <text class="arrow">›</text>
  58. </view>
  59. <view class="menu-item" @click="goToConsigneeList">
  60. <text>📍 收货人管理</text>
  61. <text class="arrow">›</text>
  62. </view>
  63. <view class="menu-item" @click="goToAfterSales">
  64. <text>🔄 售后记录</text>
  65. <text class="arrow">›</text>
  66. </view>
  67. </view>
  68. <!-- ===== 设置 ===== -->
  69. <view class="menu-group">
  70. <view class="menu-group-title">── 设置 ──</view>
  71. <view class="menu-item" @click="showFontScaleModal = true">
  72. <text>🔠 字体大小</text>
  73. <text class="font-scale-current">{{ currentFontScaleLabel }}</text>
  74. <text class="arrow">›</text>
  75. </view>
  76. <view class="menu-item" v-if="role === 'parent'" @click="showPasswordModal = true">
  77. <text>🔐 {{ hasPassword ? '重置密码' : '设置密码' }}</text>
  78. <text class="arrow">›</text>
  79. </view>
  80. <view class="menu-item menu-item-switch" v-if="role === 'parent'">
  81. <text>👁 对家庭成员可见</text>
  82. <switch :checked="showToFamily === 1" @change="onShowToFamilyChange" :color="primaryColor" />
  83. </view>
  84. <view class="menu-item" @click="logout">
  85. <text>🚪 退出登录</text>
  86. <text class="arrow">›</text>
  87. </view>
  88. </view>
  89. </view>
  90. <!-- 设置/重置密码弹窗 -->
  91. <view class="modal-mask" v-if="showPasswordModal" @click="showPasswordModal = false">
  92. <view class="modal" @click.stop>
  93. <view class="modal-title">{{ hasPassword ? '重置密码' : '设置密码' }}</view>
  94. <view class="form-item" v-if="hasPassword">
  95. <input v-model="oldPassword" type="number" password placeholder="输入旧密码" maxlength="6" />
  96. </view>
  97. <view class="form-item">
  98. <input v-model="newPassword" type="number" password placeholder="输入新密码" maxlength="6" />
  99. </view>
  100. <view class="form-item">
  101. <input v-model="confirmPassword" type="number" password placeholder="确认新密码" maxlength="6" />
  102. </view>
  103. <view class="modal-btns">
  104. <button @click="showPasswordModal = false">取消</button>
  105. <button class="btn-primary" @click="savePassword">确定</button>
  106. </view>
  107. </view>
  108. </view>
  109. <!-- 字体大小弹窗 -->
  110. <view class="modal-mask" v-if="showFontScaleModal" @click="showFontScaleModal = false">
  111. <view class="modal" @click.stop>
  112. <view class="modal-title">字体大小</view>
  113. <view class="font-scale-options">
  114. <view
  115. v-for="opt in fontScaleOptions"
  116. :key="opt.label"
  117. class="font-scale-option"
  118. :class="{ active: currentFontScale === opt.scale }"
  119. @click="onFontScaleChange(opt.scale)"
  120. >
  121. <text class="font-scale-label">{{ opt.label }}</text>
  122. <text
  123. class="font-scale-sample"
  124. :style="{ fontSize: (28 * opt.preview) + 'rpx' }"
  125. >浠艾福字体预览</text>
  126. <text class="font-scale-check" v-if="currentFontScale === opt.scale">✓</text>
  127. </view>
  128. </view>
  129. <view class="font-scale-tip">「跟随系统」时按微信「我-设置-通用-字体大小」显示</view>
  130. </view>
  131. </view>
  132. </view>
  133. </template>
  134. <script>
  135. import { BrandColors } from '@/utils/brand-colors.js'
  136. import { setPassword, verifyPassword, updateMemberVisibility, getFamilyMemberList, vendorStatus, ensureFamily, getReferralCode, extractReferralCode } from '@/utils/api.js'
  137. import { getUserFontScale, setUserFontScale } from '@/utils/fontScale.js'
  138. export default {
  139. name: 'ProfileMenu',
  140. props: {
  141. role: {
  142. type: String,
  143. default: 'parent'
  144. },
  145. showServices: {
  146. type: Boolean,
  147. default: true
  148. }
  149. },
  150. data() {
  151. return {
  152. primaryColor: BrandColors.primary,
  153. hasPassword: false,
  154. showPasswordModal: false,
  155. oldPassword: '',
  156. newPassword: '',
  157. confirmPassword: '',
  158. showToFamily: 1,
  159. isVendor: false,
  160. referralCode: '',
  161. referralCodeLoaded: false,
  162. // 字体大小设置
  163. showFontScaleModal: false,
  164. // null 表示跟随微信系统字号;数字表示用户手动设置的倍数
  165. currentFontScale: getUserFontScale(),
  166. fontScaleOptions: [
  167. { label: '跟随系统', scale: null, preview: 1 },
  168. { label: '小', scale: 0.9, preview: 0.9 },
  169. { label: '标准', scale: 1, preview: 1 },
  170. { label: '大', scale: 1.15, preview: 1.15 },
  171. { label: '特大', scale: 1.3, preview: 1.3 }
  172. ]
  173. }
  174. },
  175. mounted() {
  176. // 注意:组件不触发页面级 onShow,这里在 mounted 兜底刷新当前档位
  177. this.currentFontScale = getUserFontScale()
  178. },
  179. computed: {
  180. currentFontScaleLabel() {
  181. var opt = this.fontScaleOptions.find(function(o) {
  182. return o.scale === this.currentFontScale
  183. }, this)
  184. return opt ? opt.label : '跟随系统'
  185. }
  186. },
  187. onShow() {
  188. if (!uni.getStorageSync('token')) return
  189. this.hasPassword = !!uni.getStorageSync('passwordSet')
  190. this.loadShowToFamily()
  191. this.checkVendorStatus()
  192. this.loadReferralCode()
  193. this.currentFontScale = getUserFontScale()
  194. },
  195. methods: {
  196. onFontScaleChange(scale) {
  197. if (scale === null) {
  198. try { uni.removeStorageSync('userFontScale') } catch (e) {}
  199. } else {
  200. setUserFontScale(scale)
  201. }
  202. this.currentFontScale = scale
  203. this.showFontScaleModal = false
  204. uni.$emit('fontScaleChanged')
  205. uni.showToast({ title: '已更新字体大小', icon: 'none' })
  206. },
  207. /** 获取自己的邀请码用于分享 */
  208. async loadReferralCode() {
  209. if (this.referralCodeLoaded || !uni.getStorageSync('token')) return
  210. try {
  211. var res = await getReferralCode()
  212. this.referralCode = extractReferralCode(res)
  213. } catch (e) {}
  214. this.referralCodeLoaded = true
  215. },
  216. async loadShowToFamily() {
  217. try {
  218. const uid = this.$store.state.userId || uni.getStorageSync('userId')
  219. const res = await getFamilyMemberList({ visibleOnly: true })
  220. const members = res.data || []
  221. const self = members.find(m => m.id == uid)
  222. if (self) {
  223. this.showToFamily = self.showToFamily !== 0 ? 1 : 0
  224. }
  225. } catch (e) {}
  226. },
  227. goToOnboarding() {
  228. uni.navigateTo({ url: '/pages/profile-extra/onboarding' })
  229. },
  230. goToReportManagement() {
  231. uni.navigateTo({ url: '/pages/profile/report-management' })
  232. },
  233. goToServiceRoleApply() {
  234. uni.navigateTo({ url: '/pages/profile/service-role-apply' })
  235. },
  236. goToFamilyMembers() {
  237. uni.navigateTo({ url: '/pages/profile-extra/family-members' })
  238. },
  239. goToAppointments() {
  240. uni.navigateTo({ url: '/pages/parent/appointments' })
  241. },
  242. goToDailyTasks() {
  243. uni.navigateTo({ url: '/pages/tasks/daily-tasks' })
  244. },
  245. goToMessageHistory() {
  246. uni.navigateTo({ url: '/pages/profile/message-history' })
  247. },
  248. async onShowToFamilyChange(e) {
  249. const val = e.detail.value ? 1 : 0
  250. const uid = this.$store.state.userId || uni.getStorageSync('userId')
  251. try {
  252. await updateMemberVisibility(uid, 'parent', val)
  253. this.showToFamily = val
  254. uni.showToast({ title: val ? '已对家庭成员可见' : '已对家庭成员隐藏', icon: 'none' })
  255. } catch (e) {
  256. uni.showToast({ title: '操作失败', icon: 'none' })
  257. }
  258. },
  259. goToShop() {
  260. uni.navigateTo({ url: '/pages/shop/index/index' })
  261. },
  262. goToCart() {
  263. uni.navigateTo({ url: '/pages/shop/cart/cart' })
  264. },
  265. goToMembership() {
  266. uni.navigateTo({ url: '/pages/membership/index' })
  267. },
  268. goToVendorCenter() {
  269. uni.navigateTo({ url: '/pages/vendor/center' })
  270. },
  271. goToOrders() {
  272. uni.navigateTo({ url: '/pages/shop/order-list/order-list' })
  273. },
  274. goToConsigneeList() {
  275. uni.navigateTo({ url: '/pages/shop/consignee-list/consignee-list' })
  276. },
  277. goToAfterSales() {
  278. uni.navigateTo({ url: '/pages/shop/after-sales/after-sales' })
  279. },
  280. async savePassword() {
  281. if (this.newPassword.length !== 6) {
  282. uni.showToast({ title: '请输入6位密码', icon: 'none' })
  283. return
  284. }
  285. if (this.newPassword !== this.confirmPassword) {
  286. uni.showToast({ title: '两次密码不一致', icon: 'none' })
  287. return
  288. }
  289. if (this.hasPassword && this.oldPassword.length !== 6) {
  290. uni.showToast({ title: '请输入旧密码', icon: 'none' })
  291. return
  292. }
  293. try {
  294. if (this.hasPassword) {
  295. const verifyRes = await verifyPassword(this.oldPassword)
  296. if (verifyRes.code !== 200) {
  297. uni.showToast({ title: '旧密码错误', icon: 'none' })
  298. return
  299. }
  300. }
  301. await setPassword(this.newPassword)
  302. uni.setStorageSync('passwordSet', true)
  303. this.hasPassword = true
  304. uni.showToast({ title: '密码设置成功', icon: 'success' })
  305. this.showPasswordModal = false
  306. this.oldPassword = ''
  307. this.newPassword = ''
  308. this.confirmPassword = ''
  309. } catch (e) {
  310. console.error('设置密码失败', e)
  311. }
  312. },
  313. logout() {
  314. uni.showModal({
  315. title: '确认退出',
  316. content: '确定要退出登录吗?',
  317. success: (res) => {
  318. if (res.confirm) {
  319. this.$store.commit('logout')
  320. uni.reLaunch({ url: '/pages/index-home/index' })
  321. }
  322. }
  323. })
  324. },
  325. async checkVendorStatus() {
  326. try {
  327. const res = await vendorStatus()
  328. this.isVendor = res.data && res.data.vendorStatus === 'approved'
  329. } catch (e) {
  330. this.isVendor = false
  331. }
  332. },
  333. }
  334. }
  335. </script>
  336. <style scoped lang="scss">
  337. .menu-list {
  338. margin: 30rpx;
  339. }
  340. .menu-group {
  341. background: $app-surface;
  342. border-radius: 20rpx;
  343. margin-bottom: 20rpx;
  344. overflow: hidden;
  345. }
  346. .menu-group-title {
  347. padding: 20rpx 30rpx 10rpx;
  348. font-size: 22rpx;
  349. color: $facade-text-muted;
  350. text-align: center;
  351. }
  352. .menu-item {
  353. display: flex;
  354. align-items: center;
  355. justify-content: space-between;
  356. padding: 28rpx 30rpx;
  357. border-bottom: 1rpx solid $facade-fill-2;
  358. font-size: 28rpx;
  359. color: $facade-text-strong;
  360. }
  361. .menu-item:last-child {
  362. border-bottom: none;
  363. }
  364. .arrow {
  365. color: $facade-text-ghost;
  366. font-size: 28rpx;
  367. }
  368. .menu-item-switch {
  369. justify-content: space-between;
  370. }
  371. .menu-item-switch text {
  372. flex: 1;
  373. }
  374. .modal-mask {
  375. position: fixed;
  376. top: 0;
  377. left: 0;
  378. right: 0;
  379. bottom: 0;
  380. background: rgba(0,0,0,0.5);
  381. display: flex;
  382. align-items: center;
  383. justify-content: center;
  384. z-index: 999;
  385. }
  386. .modal {
  387. background: $app-surface;
  388. border-radius: 20rpx;
  389. padding: 40rpx;
  390. width: 80%;
  391. }
  392. .modal-title {
  393. font-size: 32rpx;
  394. font-weight: bold;
  395. text-align: center;
  396. margin-bottom: 30rpx;
  397. }
  398. .form-item {
  399. margin-bottom: 20rpx;
  400. }
  401. .form-item input {
  402. border: 1rpx solid $facade-border-soft;
  403. border-radius: 12rpx;
  404. padding: 20rpx;
  405. font-size: 28rpx;
  406. }
  407. .modal-btns {
  408. display: flex;
  409. gap: 20rpx;
  410. margin-top: 30rpx;
  411. }
  412. .modal-btns button {
  413. flex: 1;
  414. font-size: 28rpx;
  415. padding: 20rpx;
  416. border-radius: 12rpx;
  417. }
  418. .modal-btns .btn-primary {
  419. background: $accent-indigo;
  420. color: $app-surface;
  421. }
  422. .intent-reselect-hint {
  423. margin: 0 30rpx 30rpx;
  424. padding: 24rpx 30rpx;
  425. background: $app-surface;
  426. border-radius: 20rpx;
  427. display: flex;
  428. align-items: center;
  429. font-size: 26rpx;
  430. }
  431. .intent-reselect-label {
  432. color: $facade-text-muted;
  433. margin-right: 8rpx;
  434. }
  435. .intent-reselect-value {
  436. flex: 1;
  437. color: $brand-primary;
  438. font-weight: bold;
  439. }
  440. .intent-reselect-link {
  441. color: $uni-info;
  442. text-decoration: underline;
  443. }
  444. /* 字体大小弹窗 */
  445. .font-scale-current {
  446. margin-right: 16rpx;
  447. color: $facade-text-muted;
  448. font-size: 24rpx;
  449. }
  450. .font-scale-options {
  451. display: flex;
  452. flex-direction: column;
  453. gap: 20rpx;
  454. margin: 10rpx 0 20rpx;
  455. }
  456. .font-scale-option {
  457. display: flex;
  458. align-items: center;
  459. padding: 20rpx 20rpx;
  460. border: 2rpx solid $facade-gray-200;
  461. border-radius: 16rpx;
  462. background: $facade-fill-ghost;
  463. }
  464. .font-scale-option.active {
  465. border-color: $brand-primary;
  466. background: $uni-primary-pale;
  467. }
  468. .font-scale-label {
  469. width: 60rpx;
  470. font-size: 26rpx;
  471. font-weight: 600;
  472. color: $facade-text-strong;
  473. flex-shrink: 0;
  474. }
  475. .font-scale-sample {
  476. flex: 1;
  477. color: $facade-text-body;
  478. line-height: 1.4;
  479. }
  480. .font-scale-check {
  481. margin-left: 16rpx;
  482. font-size: 28rpx;
  483. color: $brand-primary;
  484. flex-shrink: 0;
  485. }
  486. .font-scale-tip {
  487. font-size: 22rpx;
  488. color: $facade-text-muted;
  489. text-align: center;
  490. line-height: 1.4;
  491. }
  492. </style>