猫妈狗爸伴宠师小程序前端代码
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.

233 lines
4.9 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 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 >
  13. 头像
  14. </view>
  15. <view >
  16. <image :src="userInfoForm.headImage" v-if="userInfoForm.headImage"
  17. style="width: 60rpx;height: 60rpx;border-radius: 50%;" 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 >
  24. 昵称
  25. </view>
  26. <view >
  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 >
  33. 手机号
  34. </view>
  35. <view v-if="userInfoForm.phone">
  36. <input placeholder="请输入手机号" style="text-align: right;" disabled v-model="userInfoForm.phone" />
  37. </view>
  38. <view 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. onMounted
  55. } from 'vue'
  56. import {
  57. ossUpload
  58. } from "@/utils/oss-upload/oss/index.js"
  59. import {
  60. getPhoneNumber
  61. } from "@/api/system/user.js"
  62. import {
  63. updateUserInfo
  64. } from "@/api/user/user.js"
  65. import {
  66. useStore
  67. } from 'vuex'
  68. import {
  69. onShow,
  70. onLoad
  71. } from "@dcloudio/uni-app"
  72. const instance = getCurrentInstance()
  73. const store = useStore()
  74. const userInfoForm = ref({
  75. headImage: '',
  76. nickName: '',
  77. phone: '',
  78. })
  79. const configList = computed(() => {
  80. return store.getters.configList
  81. })
  82. const userInfo = computed(() => {
  83. return store.getters.userInfo
  84. })
  85. onShow(() => {
  86. // 可以在这里添加 onShow 的逻辑
  87. })
  88. onLoad(() => {
  89. userInfoForm.value.phone = userInfo.value?.userTelephone || ''
  90. userInfoForm.value.nickName = userInfo.value?.userName || ''
  91. userInfoForm.value.headImage = configList.value?.applet_info?.paramValueImage || ''
  92. })
  93. const onChooseAvatar = (res) => {
  94. ossUpload(res.target.avatarUrl)
  95. .then(url => {
  96. userInfoForm.value.headImage = url
  97. })
  98. }
  99. const getPhone = async (e) => {
  100. let result = await getPhoneNumber({
  101. code: e.detail.code
  102. })
  103. result = JSON.parse(result.msg);
  104. userInfoForm.value.phone = result.phone_info.phoneNumber;
  105. }
  106. const submit = () => {
  107. uni.createSelectorQuery().in(instance.proxy)
  108. .select("#nickName")
  109. .fields({
  110. properties: ["value"],
  111. })
  112. .exec((res) => {
  113. console.log(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. store.dispatch("getUserInfo")
  140. uni.switchTab({
  141. url: "/pages/workbenchManage/index"
  142. })
  143. }
  144. })
  145. })
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .login {
  150. display: flex;
  151. flex-direction: column;
  152. justify-content: center;
  153. align-items: center;
  154. height: 80vh;
  155. .logo {
  156. display: flex;
  157. flex-direction: column;
  158. justify-content: center;
  159. align-items: center;
  160. .logo-img {
  161. width: 180rpx;
  162. height: 180rpx;
  163. }
  164. .d {
  165. width: 200rpx;
  166. height: 80rpx;
  167. margin-top: 20rpx;
  168. }
  169. margin-bottom: 20rpx;
  170. }
  171. .line {
  172. display: flex;
  173. justify-content: space-between;
  174. align-items: center;
  175. width: 80%;
  176. border-bottom: 1px solid #00000023;
  177. padding: 30rpx 0;
  178. margin: 0 auto;
  179. }
  180. .chooseAvatar {
  181. width: 100%;
  182. padding: 0;
  183. margin: 0;
  184. margin-top: 10vh;
  185. border: none;
  186. }
  187. .btn {
  188. background: #FFBF60;
  189. // background: $uni-color;
  190. color: #fff;
  191. width: 80%;
  192. padding: 20rpx 0;
  193. text-align: center;
  194. border-radius: 15rpx;
  195. margin-top: 10vh;
  196. }
  197. .getPhoneNumber {
  198. display: flex;
  199. justify-content: center;
  200. align-items: center;
  201. color: #fff;
  202. width: 200rpx;
  203. height: 60rpx;
  204. border-radius: 30rpx;
  205. font-size: 24rpx;
  206. background-color: #FFBF60;
  207. }
  208. }
  209. </style>