user-info.vue 4.8 KB

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