ProfileMenu.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. <template>
  2. <view :style="{ '--font-scale': fontScale }">
  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. import fontScaleMixin from '@/mixins/font-scale.js'
  139. export default {
  140. mixins: [fontScaleMixin],
  141. name: 'ProfileMenu',
  142. props: {
  143. role: {
  144. type: String,
  145. default: 'parent'
  146. },
  147. showServices: {
  148. type: Boolean,
  149. default: true
  150. }
  151. },
  152. data() {
  153. return {
  154. primaryColor: BrandColors.primary,
  155. hasPassword: false,
  156. showPasswordModal: false,
  157. oldPassword: '',
  158. newPassword: '',
  159. confirmPassword: '',
  160. showToFamily: 1,
  161. isVendor: false,
  162. referralCode: '',
  163. referralCodeLoaded: false,
  164. // 字体大小设置
  165. showFontScaleModal: false,
  166. // null 表示跟随微信系统字号;数字表示用户手动设置的倍数
  167. currentFontScale: getUserFontScale(),
  168. fontScaleOptions: [
  169. { label: '跟随系统', scale: null, preview: 1 },
  170. { label: '小', scale: 0.9, preview: 0.9 },
  171. { label: '标准', scale: 1, preview: 1 },
  172. { label: '大', scale: 1.15, preview: 1.15 },
  173. { label: '特大', scale: 1.3, preview: 1.3 }
  174. ]
  175. }
  176. },
  177. mounted() {
  178. // 注意:组件不触发页面级 onShow,这里在 mounted 兜底刷新当前档位
  179. this.currentFontScale = getUserFontScale()
  180. },
  181. computed: {
  182. currentFontScaleLabel() {
  183. var opt = this.fontScaleOptions.find(function(o) {
  184. return o.scale === this.currentFontScale
  185. }, this)
  186. return opt ? opt.label : '跟随系统'
  187. }
  188. },
  189. onShow() {
  190. if (!uni.getStorageSync('token')) return
  191. this.hasPassword = !!uni.getStorageSync('passwordSet')
  192. this.loadShowToFamily()
  193. this.checkVendorStatus()
  194. this.loadReferralCode()
  195. this.currentFontScale = getUserFontScale()
  196. },
  197. methods: {
  198. onFontScaleChange(scale) {
  199. if (scale === null) {
  200. try { uni.removeStorageSync('userFontScale') } catch (e) {}
  201. } else {
  202. setUserFontScale(scale)
  203. }
  204. this.currentFontScale = scale
  205. this.showFontScaleModal = false
  206. uni.$emit('fontScaleChanged')
  207. uni.showToast({ title: '已更新字体大小', icon: 'none' })
  208. },
  209. /** 获取自己的邀请码用于分享 */
  210. async loadReferralCode() {
  211. if (this.referralCodeLoaded || !uni.getStorageSync('token')) return
  212. try {
  213. var res = await getReferralCode()
  214. this.referralCode = extractReferralCode(res)
  215. } catch (e) {}
  216. this.referralCodeLoaded = true
  217. },
  218. async loadShowToFamily() {
  219. try {
  220. const uid = this.$store.state.userId || uni.getStorageSync('userId')
  221. const res = await getFamilyMemberList({ visibleOnly: true })
  222. const members = res.data || []
  223. const self = members.find(m => m.id == uid)
  224. if (self) {
  225. this.showToFamily = self.showToFamily !== 0 ? 1 : 0
  226. }
  227. } catch (e) {}
  228. },
  229. goToOnboarding() {
  230. uni.navigateTo({ url: '/pages/profile-extra/onboarding' })
  231. },
  232. goToReportManagement() {
  233. uni.navigateTo({ url: '/pages/profile/report-management' })
  234. },
  235. goToServiceRoleApply() {
  236. uni.navigateTo({ url: '/pages/profile/service-role-apply' })
  237. },
  238. goToFamilyMembers() {
  239. uni.navigateTo({ url: '/pages/profile-extra/family-members' })
  240. },
  241. goToAppointments() {
  242. uni.navigateTo({ url: '/pages/parent/appointments' })
  243. },
  244. goToDailyTasks() {
  245. uni.navigateTo({ url: '/pages/tasks/daily-tasks' })
  246. },
  247. goToMessageHistory() {
  248. uni.navigateTo({ url: '/pages/profile/message-history' })
  249. },
  250. async onShowToFamilyChange(e) {
  251. const val = e.detail.value ? 1 : 0
  252. const uid = this.$store.state.userId || uni.getStorageSync('userId')
  253. try {
  254. await updateMemberVisibility(uid, 'parent', val)
  255. this.showToFamily = val
  256. uni.showToast({ title: val ? '已对家庭成员可见' : '已对家庭成员隐藏', icon: 'none' })
  257. } catch (e) {
  258. uni.showToast({ title: '操作失败', icon: 'none' })
  259. }
  260. },
  261. goToShop() {
  262. uni.navigateTo({ url: '/pages/shop/index/index' })
  263. },
  264. goToCart() {
  265. uni.navigateTo({ url: '/pages/shop/cart/cart' })
  266. },
  267. goToMembership() {
  268. uni.navigateTo({ url: '/pages/membership/index' })
  269. },
  270. goToVendorCenter() {
  271. uni.navigateTo({ url: '/pages/vendor/center' })
  272. },
  273. goToOrders() {
  274. uni.navigateTo({ url: '/pages/shop/order-list/order-list' })
  275. },
  276. goToConsigneeList() {
  277. uni.navigateTo({ url: '/pages/shop/consignee-list/consignee-list' })
  278. },
  279. goToAfterSales() {
  280. uni.navigateTo({ url: '/pages/shop/after-sales/after-sales' })
  281. },
  282. async savePassword() {
  283. if (this.newPassword.length !== 6) {
  284. uni.showToast({ title: '请输入6位密码', icon: 'none' })
  285. return
  286. }
  287. if (this.newPassword !== this.confirmPassword) {
  288. uni.showToast({ title: '两次密码不一致', icon: 'none' })
  289. return
  290. }
  291. if (this.hasPassword && this.oldPassword.length !== 6) {
  292. uni.showToast({ title: '请输入旧密码', icon: 'none' })
  293. return
  294. }
  295. try {
  296. if (this.hasPassword) {
  297. const verifyRes = await verifyPassword(this.oldPassword)
  298. if (verifyRes.code !== 200) {
  299. uni.showToast({ title: '旧密码错误', icon: 'none' })
  300. return
  301. }
  302. }
  303. await setPassword(this.newPassword)
  304. uni.setStorageSync('passwordSet', true)
  305. this.hasPassword = true
  306. uni.showToast({ title: '密码设置成功', icon: 'success' })
  307. this.showPasswordModal = false
  308. this.oldPassword = ''
  309. this.newPassword = ''
  310. this.confirmPassword = ''
  311. } catch (e) {
  312. console.error('设置密码失败', e)
  313. }
  314. },
  315. logout() {
  316. uni.showModal({
  317. title: '确认退出',
  318. content: '确定要退出登录吗?',
  319. success: (res) => {
  320. if (res.confirm) {
  321. this.$store.commit('logout')
  322. uni.reLaunch({ url: '/pages/index-home/index' })
  323. }
  324. }
  325. })
  326. },
  327. async checkVendorStatus() {
  328. try {
  329. const res = await vendorStatus()
  330. this.isVendor = res.data && res.data.vendorStatus === 'approved'
  331. } catch (e) {
  332. this.isVendor = false
  333. }
  334. },
  335. }
  336. }
  337. </script>
  338. <style scoped lang="scss">
  339. .menu-list {
  340. margin: $uni-space-lg;
  341. }
  342. .menu-group {
  343. background: $app-surface;
  344. border-radius: 24rpx;
  345. margin-bottom: 20rpx;
  346. overflow: hidden;
  347. }
  348. .menu-group-title {
  349. padding: 20rpx $uni-space-page 10rpx;
  350. font-size: calc(22rpx * var(--font-scale, 1));
  351. color: $facade-text-muted;
  352. text-align: center;
  353. }
  354. .menu-item {
  355. display: flex;
  356. align-items: center;
  357. justify-content: space-between;
  358. padding: 28rpx $uni-space-page;
  359. border-bottom: 1rpx solid $facade-fill-2;
  360. font-size: calc(28rpx * var(--font-scale, 1));
  361. color: $facade-text-strong;
  362. }
  363. .menu-item:last-child {
  364. border-bottom: none;
  365. }
  366. .arrow {
  367. color: $facade-text-ghost;
  368. font-size: calc(28rpx * var(--font-scale, 1));
  369. }
  370. .menu-item-switch {
  371. justify-content: space-between;
  372. }
  373. .menu-item-switch text {
  374. flex: 1;
  375. }
  376. .modal-mask {
  377. position: fixed;
  378. top: 0;
  379. left: 0;
  380. right: 0;
  381. bottom: 0;
  382. background: rgba(0,0,0,0.5);
  383. display: flex;
  384. align-items: center;
  385. justify-content: center;
  386. z-index: 999;
  387. }
  388. .modal {
  389. background: $app-surface;
  390. border-radius: 24rpx;
  391. padding: 40rpx;
  392. width: 80%;
  393. }
  394. .modal-title {
  395. font-size: calc(32rpx * var(--font-scale, 1));
  396. font-weight: bold;
  397. text-align: center;
  398. margin-bottom: $uni-space-lg;
  399. }
  400. .form-item {
  401. margin-bottom: 20rpx;
  402. }
  403. .form-item input {
  404. border: 1rpx solid $facade-border-soft;
  405. border-radius: 16rpx;
  406. padding: 20rpx;
  407. font-size: calc(28rpx * var(--font-scale, 1));
  408. }
  409. .modal-btns {
  410. display: flex;
  411. gap: 20rpx;
  412. margin-top: $uni-space-lg;
  413. }
  414. .modal-btns button {
  415. flex: 1;
  416. font-size: calc(28rpx * var(--font-scale, 1));
  417. padding: 20rpx;
  418. border-radius: 16rpx;
  419. }
  420. .modal-btns .btn-primary {
  421. background: $accent-indigo;
  422. color: $app-surface;
  423. }
  424. .intent-reselect-hint {
  425. margin: 0 $uni-space-lg $uni-space-lg;
  426. padding: 24rpx $uni-space-page;
  427. background: $app-surface;
  428. border-radius: 24rpx;
  429. display: flex;
  430. align-items: center;
  431. font-size: calc(26rpx * var(--font-scale, 1));
  432. }
  433. .intent-reselect-label {
  434. color: $facade-text-muted;
  435. margin-right: 8rpx;
  436. }
  437. .intent-reselect-value {
  438. flex: 1;
  439. color: $brand-primary;
  440. font-weight: bold;
  441. }
  442. .intent-reselect-link {
  443. color: $uni-info;
  444. text-decoration: underline;
  445. }
  446. /* 字体大小弹窗 */
  447. .font-scale-current {
  448. margin-right: 16rpx;
  449. color: $facade-text-muted;
  450. font-size: calc(24rpx * var(--font-scale, 1));
  451. }
  452. .font-scale-options {
  453. display: flex;
  454. flex-direction: column;
  455. gap: 20rpx;
  456. margin: 10rpx 0 20rpx;
  457. }
  458. .font-scale-option {
  459. display: flex;
  460. align-items: center;
  461. padding: 20rpx 20rpx;
  462. border: 2rpx solid $facade-gray-200;
  463. border-radius: 16rpx;
  464. background: $facade-fill-ghost;
  465. }
  466. .font-scale-option.active {
  467. border-color: $brand-primary;
  468. background: $uni-primary-pale;
  469. }
  470. .font-scale-label {
  471. width: 60rpx;
  472. font-size: calc(26rpx * var(--font-scale, 1));
  473. font-weight: 600;
  474. color: $facade-text-strong;
  475. flex-shrink: 0;
  476. }
  477. .font-scale-sample {
  478. flex: 1;
  479. color: $facade-text-body;
  480. line-height: 1.4;
  481. }
  482. .font-scale-check {
  483. margin-left: 16rpx;
  484. font-size: calc(28rpx * var(--font-scale, 1));
  485. color: $brand-primary;
  486. flex-shrink: 0;
  487. }
  488. .font-scale-tip {
  489. font-size: calc(22rpx * var(--font-scale, 1));
  490. color: $facade-text-muted;
  491. text-align: center;
  492. line-height: 1.4;
  493. }
  494. </style>