mp-authorization.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <!-- 微信授权信息 mpAuthorization -->
  2. <template>
  3. <view>
  4. <!-- 标题栏 -->
  5. <view class="head-box ss-m-b-60 ss-flex-col">
  6. <view class="ss-flex ss-m-b-20">
  7. <view class="head-title ss-m-r-40 head-title-animation">授权信息</view>
  8. </view>
  9. <view class="head-subtitle">完善您的头像、昵称、手机号</view>
  10. </view>
  11. <!-- 表单项 -->
  12. <uni-forms
  13. ref="accountLoginRef"
  14. v-model="state.model"
  15. :rules="state.rules"
  16. validateTrigger="bind"
  17. labelWidth="140"
  18. labelAlign="center"
  19. >
  20. <uni-forms-item name="avatar" label="头像">
  21. <button
  22. class="ss-reset-button avatar-btn"
  23. open-type="chooseAvatar"
  24. @chooseavatar="onChooseAvatar"
  25. >
  26. <image
  27. class="avatar-img"
  28. :src="sheep.$url.cdn(state.model.avatar)"
  29. mode="aspectFill"
  30. @tap="sheep.$router.go('/pages/user/info')"
  31. ></image>
  32. <text class="cicon-forward"></text>
  33. </button>
  34. </uni-forms-item>
  35. <uni-forms-item name="nickname" label="昵称">
  36. <uni-easyinput
  37. type="nickname"
  38. placeholder="请输入昵称"
  39. v-model="state.model.nickname"
  40. :inputBorder="false"
  41. >
  42. </uni-easyinput>
  43. </uni-forms-item>
  44. <view class="foot-box">
  45. <button class="ss-reset-button authorization-btn" @tap="onConfirm"> 确认授权 </button>
  46. </view>
  47. </uni-forms>
  48. </view>
  49. </template>
  50. <script setup>
  51. import { computed, watch, ref, reactive, unref } from 'vue';
  52. import sheep from '@/sheep';
  53. import { showAuthModal, closeAuthModal } from '@/sheep/hooks/useModal';
  54. const props = defineProps({
  55. agreeStatus: {
  56. type: Boolean,
  57. default: false,
  58. },
  59. });
  60. const userInfo = computed(() => sheep.$store('user').userInfo);
  61. const accountLoginRef = ref(null);
  62. // 数据
  63. const state = reactive({
  64. model: {
  65. nickname: userInfo.value.nickname,
  66. avatar: userInfo.value.avatar,
  67. },
  68. rules: {
  69. },
  70. disabledStyle: {
  71. color: '#999',
  72. disableColor: '#fff',
  73. },
  74. });
  75. // 选择头像
  76. function onChooseAvatar(e) {
  77. const tempUrl = e.detail.avatarUrl || '';
  78. uploadAvatar(tempUrl);
  79. }
  80. async function uploadAvatar(tempUrl) {
  81. if (!tempUrl) return;
  82. let { path } = await sheep.$api.app.upload(tempUrl, 'ugc');
  83. state.model.avatar = path;
  84. }
  85. // 确认授权
  86. async function onConfirm() {
  87. const { model } = state;
  88. const { nickname, avatar } = model;
  89. if (!nickname) {
  90. sheep.$helper.toast('请输入昵称');
  91. return;
  92. }
  93. if (!avatar) {
  94. sheep.$helper.toast('请选择头像');
  95. return;
  96. }
  97. const { error, msg } = await sheep.$api.user.updateMpUserInfo(model);
  98. if (error === 0) {
  99. sheep.$helper.toast('授权成功');
  100. await sheep.$store('user').getInfo();
  101. closeAuthModal();
  102. }else {
  103. sheep.$helper.toast(msg);
  104. }
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. @import '../index.scss';
  109. .foot-box {
  110. width: 100%;
  111. display: flex;
  112. justify-content: center;
  113. }
  114. .authorization-btn {
  115. width: 686rpx;
  116. height: 80rpx;
  117. background-color: var(--ui-BG-Main);
  118. border-radius: 40rpx;
  119. color: #fff;
  120. }
  121. .avatar-img {
  122. width: 72rpx;
  123. height: 72rpx;
  124. border-radius: 36rpx;
  125. }
  126. .cicon-forward {
  127. font-size: 30rpx;
  128. color: #595959;
  129. }
  130. .avatar-btn {
  131. width: 100%;
  132. justify-content: space-between;
  133. }
  134. </style>