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

225 lines
4.6 KiB

2 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>
  52. import {
  53. ossUpload
  54. } from "@/utils/oss-upload/oss/index.js"
  55. import {
  56. getPhoneNumber
  57. } from "@/api/system/user.js"
  58. import {
  59. updateUserInfo
  60. } from "@/api/user/user.js"
  61. export default {
  62. data() {
  63. return {
  64. userInfo: {
  65. phone: "",
  66. nickName: "",
  67. headImage: ""
  68. },
  69. userInfoForm: {
  70. headImage: '',
  71. nickName: '',
  72. phone: '',
  73. }
  74. };
  75. },
  76. onShow() {},
  77. onLoad() {
  78. this.userInfoForm.phone = this.userInfo.phone || ''
  79. this.userInfoForm.nickName = this.userInfo.nickName || ''
  80. this.userInfoForm.headImage = this.userInfo.headImage || ''
  81. },
  82. computed: {},
  83. methods: {
  84. onChooseAvatar(res) {
  85. let self = this
  86. ossUpload(res.target.avatarUrl)
  87. .then(url => {
  88. self.userInfoForm.headImage = url
  89. })
  90. },
  91. async getPhone(e) {
  92. let result = await getPhoneNumber({
  93. code: e.detail.code
  94. })
  95. result = JSON.parse(result.msg);
  96. this.userInfoForm.phone = result.phone_info.phoneNumber;
  97. },
  98. submit() {
  99. let self = this
  100. uni.createSelectorQuery().in(this)
  101. .select("#nickName")
  102. .fields({
  103. properties: ["value"],
  104. })
  105. .exec((res) => {
  106. const nickName = res?.[0]?.value
  107. self.userInfoForm.nickName = nickName
  108. if (!this.userInfoForm.headImage) {
  109. return uni.showToast({
  110. title: '请选择头像',
  111. icon: "none"
  112. })
  113. } else if (!this.userInfoForm.nickName) {
  114. return uni.showToast({
  115. title: '请填写昵称',
  116. icon: "none"
  117. })
  118. } else if (!this.userInfoForm.phone) {
  119. return uni.showToast({
  120. title: '请填写手机号',
  121. icon: "none"
  122. })
  123. }
  124. // 获取用户Id
  125. const baseUserInfo = JSON.parse(uni.getStorageSync("baseInfo"));
  126. updateUserInfo({
  127. userId: baseUserInfo.userId,
  128. userImage: self.userInfoForm.headImage,
  129. userName: self.userInfoForm.nickName,
  130. userTelephone: self.userInfoForm.phone
  131. }).then(res => {
  132. if (res.code == 200) {
  133. uni.switchTab({
  134. url: "/pages/workbenchManage/index"
  135. })
  136. }
  137. })
  138. })
  139. },
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. .login {
  145. display: flex;
  146. flex-direction: column;
  147. justify-content: center;
  148. align-items: center;
  149. height: 80vh;
  150. .logo {
  151. height: 140rpx;
  152. width: 140rpx;
  153. image {
  154. height: 140rpx;
  155. width: 140rpx;
  156. border-radius: 30rpx;
  157. }
  158. margin-bottom: 20rpx;
  159. }
  160. .title {
  161. line-height: 45rpx;
  162. font-weight: 900;
  163. }
  164. .line {
  165. display: flex;
  166. justify-content: space-between;
  167. align-items: center;
  168. width: 80%;
  169. border-bottom: 1px solid #00000023;
  170. padding: 30rpx 0;
  171. margin: 0 auto;
  172. }
  173. .chooseAvatar {
  174. width: 100%;
  175. padding: 0;
  176. margin: 0;
  177. margin-top: 10vh;
  178. border: none;
  179. }
  180. .btn {
  181. background: #FFBF60;
  182. // background: $uni-color;
  183. color: #fff;
  184. width: 80%;
  185. padding: 20rpx 0;
  186. text-align: center;
  187. border-radius: 15rpx;
  188. margin-top: 10vh;
  189. }
  190. .getPhoneNumber {
  191. // all: unset;
  192. display: flex;
  193. justify-content: center;
  194. align-items: center;
  195. // background: $uni-linear-gradient-btn-color;
  196. // background: $uni-color;
  197. color: #fff;
  198. width: 200rpx;
  199. height: 60rpx;
  200. border-radius: 30rpx;
  201. font-size: 24rpx;
  202. }
  203. }
  204. </style>