user-info.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <main-layout :showBack="true">
  3. <template>
  4. <view class="header">
  5. <view class="avatar">
  6. <uni-icons type="person" size="70"></uni-icons>
  7. </view>
  8. <span class="nickname">{{userInfoStore.nickname}}</span>
  9. </view>
  10. <view class="func-wrap">
  11. <uni-list :border="true">
  12. <uni-list-item title="修改昵称"
  13. :showArrow="true" :showExtraIcon="true"
  14. :extraIcon="{color: '#000000',size: 22, type: 'compose'}"
  15. :clickable="true" @click="modifyNickname">
  16. </uni-list-item>
  17. </uni-list>
  18. </view>
  19. <view class="func-wrap">
  20. <uni-list :border="true">
  21. <uni-list-item title="奖励结算记录"
  22. :showArrow="true" :showExtraIcon="true"
  23. :extraIcon="{color: '#000000',size: 22, type: 'list'}"
  24. link="navigateTo" :to="router.SETTLE_LIST_URL">
  25. </uni-list-item>
  26. <uni-list-item title="奖励领取记录"
  27. :showArrow="true" :showExtraIcon="true"
  28. :extraIcon="{color: '#000000',size: 22, type: 'list'}"
  29. link="navigateTo" :to="router.REWARD_RECORD_LIST_URL">
  30. </uni-list-item>
  31. <uni-list-item title="刮刮乐投入与中奖记录"
  32. :showArrow="true" :showExtraIcon="true"
  33. :extraIcon="{color: '#000000',size: 22, type: 'list'}"
  34. link="navigateTo" :to="router.SCRATCH_RECORD_LIST_URL">
  35. </uni-list-item>
  36. </uni-list>
  37. </view>
  38. <view class="cancel-btn" @click="logout">注销</view>
  39. <!-- 修改昵称弹出框 -->
  40. <uni-popup ref="nicknameInputDialog" type="dialog" :is-mask-click="false">
  41. <uni-popup-dialog
  42. mode="input"
  43. :before-close="true"
  44. title="修改昵称"
  45. confirmText="保存"
  46. @confirm="nicknameFormConfirm"
  47. @close="nicknameFormClose">
  48. <view style="width: 100%;">
  49. <uni-forms ref="nicknameForm" :modelValue="nicknameFormData" :rules="nicknameFormRules" label-position="top" :label-width="150">
  50. <uni-forms-item name="nickname">
  51. <uni-easyinput type="text" placeholder="请输入昵称" v-model="nicknameFormData.nickname"></uni-easyinput>
  52. </uni-forms-item>
  53. </uni-forms>
  54. </view>
  55. </uni-popup-dialog>
  56. </uni-popup>
  57. </template>
  58. </main-layout>
  59. </template>
  60. <script setup>
  61. import { ref } from 'vue';
  62. import router from '@/common/constants/router.js';
  63. import { useUserInfoStore } from '@/stores/userInfo';
  64. import { userApi } from '@/service/apis.js';
  65. // 组件
  66. /**
  67. * 昵称弹出框
  68. */
  69. const nicknameInputDialog = ref(null);
  70. /**
  71. * 昵称表单
  72. */
  73. const nicknameForm = ref(null);
  74. // 属性
  75. /**
  76. * 用户信息
  77. */
  78. const userInfoStore = useUserInfoStore();
  79. /**
  80. * 昵称表单数据
  81. */
  82. const nicknameFormData = ref({
  83. nickname: userInfoStore.nickname
  84. });
  85. /**
  86. * 昵称表单验证规则
  87. */
  88. const nicknameFormRules = ref({
  89. nickname: {
  90. rules: [{
  91. required: true,
  92. errorMessage: '昵称不能为空'
  93. }, {
  94. maxLength: 30,
  95. errorMessage: '昵称不能超过{maxLength}个字符'
  96. }],
  97. }
  98. })
  99. // 方法
  100. /**
  101. * 注销登录
  102. */
  103. const logout = () => {
  104. userInfoStore.$reset();
  105. uni.reLaunch({
  106. url: router.INDEX_URL
  107. });
  108. }
  109. /**
  110. * 跳转结算列表页
  111. */
  112. const goSettleListPage = () => {
  113. uni.navigateTo({
  114. url: router.SETTLE_LIST_URL
  115. });
  116. }
  117. /**
  118. * 跳转奖励领取记录列表页
  119. */
  120. const goClaimRewardListPage = () => {
  121. uni.navigateTo({
  122. url: router.CLAIM_REWARD_LIST_URL
  123. });
  124. }
  125. /**
  126. * 跳转刮刮乐记录列表页
  127. */
  128. const goScratchListPage = () => {
  129. uni.navigateTo({
  130. url: router.SCRATCH_LIST_URL
  131. });
  132. }
  133. const modifyNickname = (e) => {
  134. nicknameInputDialog.value.open();
  135. }
  136. /**
  137. * 领取奖励表单提交
  138. */
  139. const nicknameFormConfirm = async () => {
  140. let data = await nicknameForm.value.validate();
  141. await userApi.modifyNickname(data);
  142. userInfoStore.nickname = data.nickname;
  143. nicknameInputDialog.value.close();
  144. uni.showToast({
  145. title: '修改成功',
  146. icon: 'success'
  147. });
  148. }
  149. /**
  150. * 领取奖励表单取消
  151. */
  152. const nicknameFormClose = async () => {
  153. nicknameInputDialog.value.close();
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. .header {
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. flex-direction: column;
  162. margin-top: 100rpx;
  163. .avatar {
  164. width: 180rpx;
  165. height: 180rpx;
  166. opacity: 1;
  167. background: #FFFFFF;
  168. border-radius: 50%;
  169. display: flex;
  170. justify-content: center;
  171. align-items: center;
  172. }
  173. .nickname {
  174. margin-top: 16rpx;
  175. font-size: 36rpx;
  176. font-weight: 400;
  177. letter-spacing: 0px;
  178. line-height: 52.13rpx;
  179. color: #000000;
  180. }
  181. }
  182. .func-wrap {
  183. background: #FFFFFF;
  184. margin-top: 24rpx;
  185. }
  186. .cancel-btn {
  187. margin-top: 24rpx;
  188. height: 54rpx;
  189. opacity: 1;
  190. border-radius: 24rpx;
  191. background: #F2607A;
  192. /** 文本1 */
  193. font-size: 26rpx;
  194. font-weight: 400;
  195. letter-spacing: 0rpx;
  196. // line-height: 37.65rpx;
  197. color: #FFFFFF;
  198. display: flex;
  199. justify-content: center;
  200. align-content: center;
  201. align-items: center;
  202. }
  203. </style>