租房小程序前端代码
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.

169 lines
4.3 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
5 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
  1. <template>
  2. <view>
  3. <view class="se-pt-200 se-flex se-flex-h-c se-flex-ff-cw">
  4. <image class="se-w-150 se-h-150" src="@/static/image/logo.png" mode=""></image>
  5. <view class="se-flex se-flex-h-c se-fs-34 se-fw-6 se-c-black se-mt-40">
  6. 租房小程序
  7. </view>
  8. <view class="se-mt-20 se-fs-26 se-c-black se-flex se-flex-h-c">
  9. 申请获取您的头像昵称
  10. </view>
  11. </view>
  12. <view class="se-mx-40 se-py-100">
  13. <view class="se-b-t se-b-b se-flex se-h-140 se-lh-140 se-flex-h-sb">
  14. <text>头像</text>
  15. <button class="se-w-100 se-h-100 se-p-0 se-m-0"
  16. open-type="chooseAvatar"
  17. @chooseavatar="onChooseAvatar">
  18. <image v-if="imagUrl" class="se-w-100 se-h-100"
  19. :src="imagUrl"></image>
  20. <image v-else class="se-w-100 se-h-100" src="@/static/image/header.png" mode=""></image>
  21. </button>
  22. </view>
  23. <view class=" se-b-b se-flex se-h-140 se-lh-140 se-flex-h-sb">
  24. <text>昵称</text>
  25. <input type="nickname" placeholder="请输入昵称" v-model="nameUser"
  26. @blur="bindblur" class="se-h-80 se-lh-80 se-w-320 se-fs-24 se-ta-r" placeholder-class="se-fs-24 se-ta-r" />
  27. </view>
  28. <view class=" se-b-b se-flex se-h-140 se-lh-140 se-flex-h-sb">
  29. <text>手机号</text>
  30. <button v-if="phone" class="default-btn se-h-100 se-p-0 se-m-0" open-type="getPhoneNumber" @getphonenumber="onPhonenumber">{{phone}}</button>
  31. <button v-else class="se-w-140 se-h-60 se-lh-60 se-fs-20 se-bgc-green se-c-white se-py-0 se-br-30 se-px-20 se-m-0" open-type="getPhoneNumber" @getphonenumber="onPhonenumber">
  32. 获取手机号
  33. </button>
  34. </view>
  35. </view>
  36. <view class="se-mx-40">
  37. <view @click="onUpdateInfo" class="se-br-40 se-flex-h-c se-h-80 se-lh-80 se-ta-c se-fs-32 se-c-white se-bgc-green">
  38. 确认
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import { UpdateInfo,bindPhone } from "@/common/api.js"
  45. export default {
  46. name : 'Login',
  47. data() {
  48. return {
  49. nameUser:"",
  50. imagUrl:"",
  51. phone:"",
  52. back:0
  53. }
  54. },
  55. onLoad(options) {
  56. if(options.back==1){
  57. this.back = options.back
  58. }
  59. // 加载用户信息
  60. this.loadUserInfo()
  61. },
  62. onShow() {
  63. // 页面显示时重新获取最新的用户信息
  64. this.loadUserInfo()
  65. },
  66. methods: {
  67. // 加载用户信息
  68. loadUserInfo() {
  69. // 从Vuex store获取用户信息(如果存在)
  70. const storeUserInfo = this.$store.state.userInfo || {}
  71. this.imagUrl = storeUserInfo.headImage || ''
  72. this.nameUser = storeUserInfo.nickName || ''
  73. this.phone = storeUserInfo.phone || ''
  74. },
  75. bindblur(event) {
  76. this.nameUser = event.target.value
  77. },
  78. onChooseAvatar(res) {
  79. console.log(res);
  80. let self = this
  81. self.$Oss.ossUpload(res.target.avatarUrl).then(url => {
  82. self.imagUrl = url
  83. })
  84. },
  85. onPhonenumber(event){
  86. let that = this
  87. var detail = event.detail;
  88. if(detail.errMsg=='getPhoneNumber:ok'){
  89. let params={
  90. code : detail.code,
  91. encryptedData: detail.encryptedData,
  92. iv:detail.iv,
  93. }
  94. bindPhone(params).then((response) => {
  95. console.info(response)
  96. let data = JSON.parse(response.result)
  97. that.phone = data.phone_info.phoneNumber
  98. }).catch(error=>{
  99. })
  100. }
  101. },
  102. onUpdateInfo(){
  103. let that = this
  104. let params={
  105. avatarUrl:that.imagUrl,
  106. nickName:that.nameUser,
  107. phone:that.phone
  108. }
  109. // &&that.phone
  110. if (that.$utils.verificationAll(params, {
  111. avatarUrl: '请选择头像',
  112. nickName: '请填写昵称',
  113. phone: '请填写手机号',
  114. })) {
  115. return
  116. }
  117. UpdateInfo(params).then((response) => {
  118. // 更新成功后,更新本地存储和Vuex store
  119. const updatedUserInfo = {
  120. ...uni.getStorageSync('userInfo'),
  121. headImage: that.imagUrl,
  122. nickName: that.nameUser,
  123. phone: that.phone
  124. }
  125. // 更新本地存储
  126. uni.setStorageSync('userInfo', updatedUserInfo)
  127. // 更新Vuex store
  128. if(that.$store) {
  129. that.$store.state.userInfo = updatedUserInfo
  130. }
  131. if(this.back==1){
  132. uni.navigateBack({
  133. delta:1
  134. })
  135. }else{
  136. uni.switchTab({
  137. url:"/pages/home/index"
  138. })
  139. }
  140. }).catch((error) =>{
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style scoped lang="scss">
  147. .default-btn{
  148. background-color: #fff;
  149. }
  150. .default-btn::after{
  151. content: "";
  152. border: none;
  153. }
  154. </style>