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

229 lines
4.7 KiB

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