ProfileMenu.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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="goToEditInfo">
  8. <text>📝 修改个人资料</text>
  9. <text class="arrow">›</text>
  10. </view>
  11. <view class="menu-item" v-if="role === 'parent'" @click="goToChildren">
  12. <text>👶 我的孩子</text>
  13. <text class="arrow">›</text>
  14. </view>
  15. <view class="menu-item" v-if="role === 'parent'" @click="goToFamilyMembers">
  16. <text>👨‍👩‍👧‍👦 家庭成员</text>
  17. <text class="arrow">›</text>
  18. </view>
  19. </view>
  20. <!-- ===== 财富 ===== -->
  21. <view class="menu-group">
  22. <view class="menu-group-title">── 财富 ──</view>
  23. <view class="menu-item" @click="goToPromotion">
  24. <text>📢 推广中心</text>
  25. <text class="arrow">›</text>
  26. </view>
  27. <view class="menu-item" @click="goToPointsLogs">
  28. <text>📊 积分记录</text>
  29. <text class="arrow">›</text>
  30. </view>
  31. </view>
  32. <!-- ===== 服务 ===== -->
  33. <view class="menu-group">
  34. <view class="menu-group-title">── 服务 ──</view>
  35. <view class="menu-item" @click="goToMembership">
  36. <text>👑 会员中心</text>
  37. <text class="arrow">›</text>
  38. </view>
  39. <view class="menu-item" v-if="isVendor" @click="goToVendorCenter">
  40. <text>🏪 服务商中心</text>
  41. <text class="arrow">›</text>
  42. </view>
  43. <view class="menu-item" @click="goToOrders">
  44. <text>🛒 订单管理</text>
  45. <text class="arrow">›</text>
  46. </view>
  47. </view>
  48. <!-- ===== 设置 ===== -->
  49. <view class="menu-group">
  50. <view class="menu-group-title">── 设置 ──</view>
  51. <view class="menu-item" v-if="role === 'parent'" @click="showPasswordModal = true">
  52. <text>🔐 {{ hasPassword ? '重置密码' : '设置密码' }}</text>
  53. <text class="arrow">›</text>
  54. </view>
  55. <view class="menu-item menu-item-switch" v-if="role === 'parent'">
  56. <text>👁 对家庭成员可见</text>
  57. <switch :checked="showToFamily === 1" @change="onShowToFamilyChange" color="#5B9BD5" />
  58. </view>
  59. <view class="menu-item" @click="showInviteActionSheet">
  60. <text>📨 邀请加入</text>
  61. <text class="arrow">›</text>
  62. </view>
  63. <view class="menu-item" @click="logout">
  64. <text>🚪 退出登录</text>
  65. <text class="arrow">›</text>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 设置/重置密码弹窗 -->
  70. <view class="modal-mask" v-if="showPasswordModal" @click="showPasswordModal = false">
  71. <view class="modal" @click.stop>
  72. <view class="modal-title">{{ hasPassword ? '重置密码' : '设置密码' }}</view>
  73. <view class="form-item" v-if="hasPassword">
  74. <input v-model="oldPassword" type="number" password placeholder="输入旧密码" maxlength="6" />
  75. </view>
  76. <view class="form-item">
  77. <input v-model="newPassword" type="number" password placeholder="输入新密码" maxlength="6" />
  78. </view>
  79. <view class="form-item">
  80. <input v-model="confirmPassword" type="number" password placeholder="确认新密码" maxlength="6" />
  81. </view>
  82. <view class="modal-btns">
  83. <button @click="showPasswordModal = false">取消</button>
  84. <button class="btn-primary" @click="savePassword">确定</button>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. import { setPassword, verifyPassword, updateMemberVisibility, getVisibleFamilyMembers, vendorStatus } from '../../utils/api.js'
  92. export default {
  93. name: 'ProfileMenu',
  94. props: {
  95. role: {
  96. type: String,
  97. default: 'parent'
  98. }
  99. },
  100. data() {
  101. return {
  102. hasPassword: false,
  103. showPasswordModal: false,
  104. oldPassword: '',
  105. newPassword: '',
  106. confirmPassword: '',
  107. showToFamily: 1,
  108. isVendor: false
  109. }
  110. },
  111. onShow() {
  112. if (!uni.getStorageSync('token')) return
  113. this.hasPassword = !!uni.getStorageSync('passwordSet')
  114. this.loadShowToFamily()
  115. this.checkVendorStatus()
  116. },
  117. methods: {
  118. async loadShowToFamily() {
  119. try {
  120. const uid = this.$store.state.userId || uni.getStorageSync('userId')
  121. const res = await getVisibleFamilyMembers()
  122. const members = res.data || []
  123. const self = members.find(m => m.id == uid)
  124. if (self) {
  125. this.showToFamily = self.showToFamily !== 0 ? 1 : 0
  126. }
  127. } catch (e) {}
  128. },
  129. goToEditInfo() {
  130. uni.navigateTo({ url: '/pages/user-edit/user-edit' })
  131. },
  132. goToChildren() {
  133. uni.navigateTo({ url: '/pages/profile/children' })
  134. },
  135. goToFamilyMembers() {
  136. uni.navigateTo({ url: '/pages/profile/family-members' })
  137. },
  138. goToPointsLogs() {
  139. uni.navigateTo({ url: '/pages/points/points' })
  140. },
  141. async onShowToFamilyChange(e) {
  142. const val = e.detail.value ? 1 : 0
  143. const uid = this.$store.state.userId || uni.getStorageSync('userId')
  144. try {
  145. await updateMemberVisibility(uid, 'parent', val)
  146. this.showToFamily = val
  147. uni.showToast({ title: val ? '已对家庭成员可见' : '已对家庭成员隐藏', icon: 'none' })
  148. } catch (e) {
  149. uni.showToast({ title: '操作失败', icon: 'none' })
  150. }
  151. },
  152. goToMembership() {
  153. uni.showToast({ title: '即将上线', icon: 'none' })
  154. },
  155. goToVendorCenter() {
  156. uni.navigateTo({ url: '/pages/vendor/center' })
  157. },
  158. goToOrders() {
  159. uni.showToast({ title: '即将上线', icon: 'none' })
  160. },
  161. goToPromotion() {
  162. uni.navigateTo({ url: '/pages/promotion/index' })
  163. },
  164. showInviteActionSheet() {
  165. const familyId = uni.getStorageSync('familyId')
  166. const userInfo = uni.getStorageSync('userInfo')
  167. if (!familyId) {
  168. uni.showToast({ title: '您暂未加入家庭', icon: 'none' })
  169. return
  170. }
  171. const items = ['👨‍👩‍👧‍👦 邀请家人', '👨‍🏫 邀请成长规划师']
  172. const types = ['family', 'guide']
  173. uni.showActionSheet({
  174. itemList: items,
  175. success: (res) => {
  176. this.inviteGenerate(types[res.tapIndex], familyId, userInfo)
  177. }
  178. })
  179. },
  180. inviteGenerate(type, familyId, userInfo) {
  181. const inviteTypes = {
  182. family: {
  183. title: (userInfo && userInfo.nickname ? userInfo.nickname : '家人') + ' 邀请你加入家庭',
  184. path: '/pages/login/login?invite_type=family'
  185. },
  186. guide: {
  187. title: (userInfo && userInfo.nickname ? userInfo.nickname : '家长') + ' 邀请你成为家庭成长规划师',
  188. path: '/pages/login/login?invite_type=guide'
  189. }
  190. }
  191. const config = inviteTypes[type] || inviteTypes.family
  192. this.$emit('invite-generate', {
  193. title: config.title,
  194. path: config.path + '&invite_code=',
  195. imageUrl: '/static/invite-card.png'
  196. })
  197. uni.showToast({ title: '点击右上角转发给TA', icon: 'none' })
  198. },
  199. async savePassword() {
  200. if (this.newPassword.length !== 6) {
  201. uni.showToast({ title: '请输入6位密码', icon: 'none' })
  202. return
  203. }
  204. if (this.newPassword !== this.confirmPassword) {
  205. uni.showToast({ title: '两次密码不一致', icon: 'none' })
  206. return
  207. }
  208. if (this.hasPassword && this.oldPassword.length !== 6) {
  209. uni.showToast({ title: '请输入旧密码', icon: 'none' })
  210. return
  211. }
  212. try {
  213. if (this.hasPassword) {
  214. const verifyRes = await verifyPassword(this.oldPassword)
  215. if (verifyRes.code !== 200) {
  216. uni.showToast({ title: '旧密码错误', icon: 'none' })
  217. return
  218. }
  219. }
  220. await setPassword(this.newPassword)
  221. uni.setStorageSync('passwordSet', true)
  222. this.hasPassword = true
  223. uni.showToast({ title: '密码设置成功', icon: 'success' })
  224. this.showPasswordModal = false
  225. this.oldPassword = ''
  226. this.newPassword = ''
  227. this.confirmPassword = ''
  228. } catch (e) {
  229. console.error('设置密码失败', e)
  230. }
  231. },
  232. logout() {
  233. uni.showModal({
  234. title: '确认退出',
  235. content: '确定要退出登录吗?',
  236. success: (res) => {
  237. if (res.confirm) {
  238. this.$store.commit('logout')
  239. uni.reLaunch({ url: '/pages/index/index' })
  240. }
  241. }
  242. })
  243. },
  244. async checkVendorStatus() {
  245. try {
  246. const res = await vendorStatus()
  247. this.isVendor = res.data && res.data.vendorStatus === 'approved'
  248. } catch (e) {
  249. this.isVendor = false
  250. }
  251. }
  252. }
  253. }
  254. </script>
  255. <style scoped>
  256. .menu-list {
  257. margin: 30rpx;
  258. }
  259. .menu-group {
  260. background: #fff;
  261. border-radius: 20rpx;
  262. margin-bottom: 20rpx;
  263. overflow: hidden;
  264. }
  265. .menu-group-title {
  266. padding: 20rpx 30rpx 10rpx;
  267. font-size: 22rpx;
  268. color: #999;
  269. text-align: center;
  270. }
  271. .menu-item {
  272. display: flex;
  273. align-items: center;
  274. justify-content: space-between;
  275. padding: 28rpx 30rpx;
  276. border-bottom: 1rpx solid #f5f5f5;
  277. font-size: 28rpx;
  278. color: #333;
  279. }
  280. .menu-item:last-child {
  281. border-bottom: none;
  282. }
  283. .arrow {
  284. color: #ccc;
  285. font-size: 28rpx;
  286. }
  287. .menu-item-switch {
  288. justify-content: space-between;
  289. }
  290. .menu-item-switch text {
  291. flex: 1;
  292. }
  293. .modal-mask {
  294. position: fixed;
  295. top: 0;
  296. left: 0;
  297. right: 0;
  298. bottom: 0;
  299. background: rgba(0,0,0,0.5);
  300. display: flex;
  301. align-items: center;
  302. justify-content: center;
  303. z-index: 999;
  304. }
  305. .modal {
  306. background: #fff;
  307. border-radius: 20rpx;
  308. padding: 40rpx;
  309. width: 80%;
  310. }
  311. .modal-title {
  312. font-size: 32rpx;
  313. font-weight: bold;
  314. text-align: center;
  315. margin-bottom: 30rpx;
  316. }
  317. .form-item {
  318. margin-bottom: 20rpx;
  319. }
  320. .form-item input {
  321. border: 1rpx solid #ddd;
  322. border-radius: 12rpx;
  323. padding: 20rpx;
  324. font-size: 28rpx;
  325. }
  326. .modal-btns {
  327. display: flex;
  328. gap: 20rpx;
  329. margin-top: 30rpx;
  330. }
  331. .modal-btns button {
  332. flex: 1;
  333. font-size: 28rpx;
  334. padding: 20rpx;
  335. border-radius: 12rpx;
  336. }
  337. .modal-btns .btn-primary {
  338. background: #667eea;
  339. color: #fff;
  340. }
  341. </style>