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

246 lines
5.1 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year 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 class="title">
  7. 申请获取你的头像昵称
  8. </view>
  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. <!-- 客服组件 -->
  48. <CustomerService />
  49. </view>
  50. </template>
  51. <script setup>
  52. import {
  53. ref,
  54. getCurrentInstance,
  55. computed,
  56. onMounted
  57. } from 'vue'
  58. import {
  59. ossUpload
  60. } from "@/utils/oss-upload/oss/index.js"
  61. import {
  62. getPhoneNumber
  63. } from "@/api/system/user.js"
  64. import {
  65. updateUserInfo
  66. } from "@/api/user/user.js"
  67. import {
  68. useStore
  69. } from 'vuex'
  70. import {
  71. onShow,
  72. onLoad
  73. } from "@dcloudio/uni-app"
  74. const instance = getCurrentInstance()
  75. const store = useStore()
  76. const userInfoForm = ref({
  77. headImage: '',
  78. nickName: '',
  79. phone: '',
  80. })
  81. const configList = computed(() => {
  82. return store.getters.configList
  83. })
  84. const userInfo = computed(() => {
  85. return store.getters.userInfo
  86. })
  87. onShow(() => {
  88. // 可以在这里添加 onShow 的逻辑
  89. })
  90. onLoad(() => {
  91. userInfoForm.value.phone = userInfo.value?.userTelephone || ''
  92. userInfoForm.value.nickName = userInfo.value?.userName || ''
  93. userInfoForm.value.headImage = configList.value?.applet_info?.paramValueImage || ''
  94. })
  95. const onChooseAvatar = (res) => {
  96. ossUpload(res.target.avatarUrl)
  97. .then(url => {
  98. userInfoForm.value.headImage = url
  99. })
  100. }
  101. const getPhone = async (e) => {
  102. let result = await getPhoneNumber({
  103. code: e.detail.code
  104. })
  105. result = JSON.parse(result.msg);
  106. userInfoForm.value.phone = result.phone_info.phoneNumber;
  107. }
  108. const submit = () => {
  109. uni.createSelectorQuery().in(instance.proxy)
  110. .select("#nickName")
  111. .fields({
  112. properties: ["value"],
  113. })
  114. .exec((res) => {
  115. console.log(res)
  116. const nickName = res?.[0]?.value
  117. userInfoForm.value.nickName = nickName
  118. if (!userInfoForm.value.headImage) {
  119. return uni.showToast({
  120. title: '请选择头像',
  121. icon: "none"
  122. })
  123. } else if (!userInfoForm.value.nickName) {
  124. return uni.showToast({
  125. title: '请填写昵称',
  126. icon: "none"
  127. })
  128. } else if (!userInfoForm.value.phone) {
  129. return uni.showToast({
  130. title: '请填写手机号',
  131. icon: "none"
  132. })
  133. }
  134. updateUserInfo({
  135. userId: store.state.user.userInfo.userId,
  136. userImage: userInfoForm.value.headImage,
  137. userName: userInfoForm.value.nickName,
  138. userTelephone: userInfoForm.value.phone
  139. }).then(res => {
  140. if (res.code == 200) {
  141. store.dispatch("getUserInfo")
  142. uni.switchTab({
  143. url: "/pages/workbenchManage/index"
  144. })
  145. }
  146. })
  147. })
  148. }
  149. </script>
  150. <style lang="scss" scoped>
  151. .login {
  152. display: flex;
  153. flex-direction: column;
  154. // justify-content: center;
  155. align-items: center;
  156. height: 100vh;
  157. background-color: #fff;
  158. .title{
  159. margin-top: 60rpx;
  160. }
  161. .logo {
  162. display: flex;
  163. flex-direction: column;
  164. justify-content: center;
  165. align-items: center;
  166. height: 504rpx;
  167. width: 100%;
  168. background: linear-gradient(360deg, #FFFFFF 0%, #FFBF60 99%);
  169. .logo-img {
  170. width: 180rpx;
  171. height: 180rpx;
  172. }
  173. .d {
  174. width: 200rpx;
  175. height: 80rpx;
  176. margin-top: 20rpx;
  177. }
  178. margin-bottom: 20rpx;
  179. }
  180. .line {
  181. display: flex;
  182. justify-content: space-between;
  183. align-items: center;
  184. width: 80%;
  185. border-bottom: 1px solid #00000023;
  186. padding: 30rpx 0;
  187. margin: 0 auto;
  188. }
  189. .chooseAvatar {
  190. width: 100%;
  191. padding: 0;
  192. margin: 0;
  193. margin-top: 10vh;
  194. border: none;
  195. background-color: #FFFFFF;
  196. }
  197. .btn {
  198. background: #FFBF60;
  199. // background: $uni-color;
  200. color: #fff;
  201. width: 80%;
  202. padding: 20rpx 0;
  203. text-align: center;
  204. border-radius: 15rpx;
  205. margin-top: 10vh;
  206. }
  207. .getPhoneNumber {
  208. display: flex;
  209. justify-content: center;
  210. align-items: center;
  211. color: #fff;
  212. width: 200rpx;
  213. height: 60rpx;
  214. border-radius: 30rpx;
  215. font-size: 24rpx;
  216. background-color: #FFBF60;
  217. }
  218. }
  219. </style>