猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
4.9 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. <template>
  2. <view class="login">
  3. <view class="logo">
  4. <image class="logo-img" :src="configList?.applet_info?.paramValueImage" mode="aspectFill"></image>
  5. <image class="d" :src="configList?.logo_icon?.paramValueImage" mode="aspectFill"></image>
  6. </view>
  7. <view class="title">
  8. 申请获取你的头像昵称
  9. </view>
  10. <button class="chooseAvatar" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  11. <view class="line">
  12. <view class="">
  13. 头像
  14. </view>
  15. <view class="">
  16. <image :src="userInfoForm.headImage" v-if="userInfoForm.headImage"
  17. style="width: 60rpx;height: 60rpx;" mode=""></image>
  18. <!-- <image src="../static/auth/headImage.png" v-else style="width: 50rpx;height: 50rpx;" mode=""></image> -->
  19. </view>
  20. </view>
  21. </button>
  22. <view class="line">
  23. <view class="">
  24. 昵称
  25. </view>
  26. <view class="">
  27. <input type="nickname" placeholder="请输入昵称" style="text-align: right;" id="nickName"
  28. v-model="userInfoForm.nickName" />
  29. </view>
  30. </view>
  31. <view class="line">
  32. <view class="">
  33. 手机号
  34. </view>
  35. <view class="" v-if="userInfoForm.phone">
  36. <input placeholder="请输入手机号" style="text-align: right;" disabled v-model="userInfoForm.phone" />
  37. </view>
  38. <view class="" v-else>
  39. <button class="getPhoneNumber" open-type="getPhoneNumber" @getphonenumber="getPhone">
  40. 获取电话号码
  41. </button>
  42. </view>
  43. </view>
  44. <view class="btn" @click="submit">
  45. 确认
  46. </view>
  47. </view>
  48. </template>
  49. <script setup>
  50. import {
  51. ref,
  52. getCurrentInstance,
  53. computed
  54. } from 'vue'
  55. import {
  56. ossUpload
  57. } from "@/utils/oss-upload/oss/index.js"
  58. import {
  59. getPhoneNumber
  60. } from "@/api/system/user.js"
  61. import {
  62. updateUserInfo
  63. } from "@/api/user/user.js"
  64. import {
  65. useStore
  66. } from 'vuex'
  67. import {
  68. onShow,
  69. onLoad
  70. } from "@dcloudio/uni-app"
  71. const instance = getCurrentInstance()
  72. const store = useStore()
  73. const userInfo = ref({
  74. phone: "",
  75. nickName: "",
  76. headImage: ""
  77. })
  78. const userInfoForm = ref({
  79. headImage: '',
  80. nickName: '',
  81. phone: '',
  82. })
  83. const configList = computed(() => {
  84. return store.getters.configList
  85. })
  86. onShow(() => {
  87. // 可以在这里添加 onShow 的逻辑
  88. })
  89. onLoad(() => {
  90. userInfoForm.value.phone = userInfo.value.phone || ''
  91. userInfoForm.value.nickName = userInfo.value.nickName || ''
  92. userInfoForm.value.headImage = userInfo.value.headImage || ''
  93. })
  94. const onChooseAvatar = (res) => {
  95. ossUpload(res.target.avatarUrl)
  96. .then(url => {
  97. userInfoForm.value.headImage = url
  98. })
  99. }
  100. const getPhone = async (e) => {
  101. let result = await getPhoneNumber({
  102. code: e.detail.code
  103. })
  104. result = JSON.parse(result.msg);
  105. userInfoForm.value.phone = result.phone_info.phoneNumber;
  106. }
  107. const submit = () => {
  108. uni.createSelectorQuery().in(instance.proxy)
  109. .select("#nickName")
  110. .fields({
  111. properties: ["value"],
  112. })
  113. .exec((res) => {
  114. const nickName = res?.[0]?.value
  115. userInfoForm.value.nickName = nickName
  116. if (!userInfoForm.value.headImage) {
  117. return uni.showToast({
  118. title: '请选择头像',
  119. icon: "none"
  120. })
  121. } else if (!userInfoForm.value.nickName) {
  122. return uni.showToast({
  123. title: '请填写昵称',
  124. icon: "none"
  125. })
  126. } else if (!userInfoForm.value.phone) {
  127. return uni.showToast({
  128. title: '请填写手机号',
  129. icon: "none"
  130. })
  131. }
  132. updateUserInfo({
  133. userId: store.state.user.userInfo.userId,
  134. userImage: userInfoForm.value.headImage,
  135. userName: userInfoForm.value.nickName,
  136. userTelephone: userInfoForm.value.phone
  137. }).then(res => {
  138. if (res.code == 200) {
  139. uni.switchTab({
  140. url: "/pages/workbenchManage/index"
  141. })
  142. }
  143. })
  144. })
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .login {
  149. display: flex;
  150. flex-direction: column;
  151. justify-content: center;
  152. align-items: center;
  153. height: 80vh;
  154. .logo {
  155. display: flex;
  156. flex-direction: column;
  157. justify-content: center;
  158. align-items: center;
  159. .logo-img {
  160. width: 180rpx;
  161. height: 180rpx;
  162. }
  163. .d {
  164. width: 200rpx;
  165. height: 80rpx;
  166. margin-top: 20rpx;
  167. }
  168. margin-bottom: 20rpx;
  169. }
  170. .line {
  171. display: flex;
  172. justify-content: space-between;
  173. align-items: center;
  174. width: 80%;
  175. border-bottom: 1px solid #00000023;
  176. padding: 30rpx 0;
  177. margin: 0 auto;
  178. }
  179. .chooseAvatar {
  180. width: 100%;
  181. padding: 0;
  182. margin: 0;
  183. margin-top: 10vh;
  184. border: none;
  185. }
  186. .btn {
  187. background: #FFBF60;
  188. // background: $uni-color;
  189. color: #fff;
  190. width: 80%;
  191. padding: 20rpx 0;
  192. text-align: center;
  193. border-radius: 15rpx;
  194. margin-top: 10vh;
  195. }
  196. .getPhoneNumber {
  197. // all: unset;
  198. display: flex;
  199. justify-content: center;
  200. align-items: center;
  201. // background: $uni-linear-gradient-btn-color;
  202. // background: $uni-color;
  203. color: #fff;
  204. width: 200rpx;
  205. height: 60rpx;
  206. border-radius: 30rpx;
  207. font-size: 24rpx;
  208. }
  209. }
  210. </style>