小说小程序前端代码仓库(小程序)
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.

273 lines
5.7 KiB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 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. {{ configList.logo_name }}
  8. </view>
  9. <view class="title">
  10. 申请获取你的头像昵称
  11. </view>
  12. <!-- #ifdef MP-WEIXIN -->
  13. <button class="chooseAvatar" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  14. <view class="line">
  15. <view class="">
  16. 头像
  17. </view>
  18. <view class="">
  19. <image :src="userInfoForm.headImage" v-if="userInfoForm.headImage" style="width: 60rpx;height: 60rpx;"
  20. mode=""></image>
  21. <image src="../static/auth/headImage.png" v-else style="width: 50rpx;height: 50rpx;" mode=""></image>
  22. </view>
  23. </view>
  24. </button>
  25. <!-- #endif -->
  26. <!-- #ifdef H5 -->
  27. <view class="line">
  28. <view class="">
  29. 头像
  30. </view>
  31. <view class="h5-avatar-upload">
  32. <uv-upload :fileList="fileList" :maxCount="1" width="60rpx" height="60rpx"
  33. @afterRead="afterRead" @delete="deleteImage">
  34. <image src="../static/auth/headImage.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
  35. </uv-upload>
  36. </view>
  37. </view>
  38. <!-- #endif -->
  39. <view class="line">
  40. <view class="">
  41. 昵称
  42. </view>
  43. <view class="">
  44. <input type="nickname" placeholder="请输入昵称" style="text-align: right;" id="nickName"
  45. v-model="userInfoForm.nickName" />
  46. </view>
  47. </view>
  48. <view class="line">
  49. <view class="">
  50. 手机号
  51. </view>
  52. <!-- #ifdef MP-WEIXIN -->
  53. <view class=""
  54. v-if="userInfoForm.phone">
  55. <input placeholder="请输入手机号" style="text-align: right;"
  56. disabled
  57. v-model="userInfoForm.phone" />
  58. </view>
  59. <view class=""
  60. v-else>
  61. <button
  62. class="getPhoneNumber"
  63. open-type="getPhoneNumber"
  64. @getphonenumber="getPhone">
  65. 获取电话号码
  66. </button>
  67. </view>
  68. <!-- #endif -->
  69. <!-- #ifdef H5 -->
  70. <view class="">
  71. <input placeholder="请输入手机号" style="text-align: right;"
  72. v-model="userInfoForm.phone" />
  73. </view>
  74. <!-- #endif -->
  75. </view>
  76. <view class="btn" @click="submit">
  77. 确认
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. export default {
  83. data() {
  84. return {
  85. userInfoForm: {
  86. headImage: '',
  87. nickName: '',
  88. phone : '',
  89. },
  90. // #ifdef H5
  91. fileList: []
  92. // #endif
  93. };
  94. },
  95. onShow() {},
  96. onLoad() {
  97. this.userInfoForm.phone = this.userInfo.phone || ''
  98. this.userInfoForm.nickName = this.userInfo.nickName || ''
  99. this.userInfoForm.headImage = this.userInfo.headImage || ''
  100. if(this.userInfoForm.headImage){
  101. this.fileList = [{
  102. url: this.userInfoForm.headImage
  103. }]
  104. }
  105. },
  106. computed: {},
  107. methods: {
  108. // #ifdef MP-WEIXIN
  109. onChooseAvatar(res) {
  110. this.$Oss.ossUpload(res.target.avatarUrl)
  111. .then(url => {
  112. this.userInfoForm.headImage = url
  113. })
  114. },
  115. getPhone(e){
  116. this.$api('bindPhone', {
  117. code : e.detail.code
  118. }, res => {
  119. if(res.code == 200){
  120. let phoneObj = JSON.parse(res.result)
  121. if(phoneObj.errmsg == 'ok'){
  122. this.userInfoForm.phone = phoneObj.phone_info.phoneNumber
  123. }else{
  124. // uni.showModal({
  125. // title: ''
  126. // })
  127. }
  128. }
  129. })
  130. },
  131. // #endif
  132. // #ifdef H5
  133. deleteImage(e){
  134. this.fileList.splice(e.index, 1)
  135. this.userInfoForm.headImage = ''
  136. },
  137. afterRead(e){
  138. let self = this
  139. // e.file.forEach(file => {
  140. self.$Oss.ossUpload(e.file.url).then(url => {
  141. self.userInfoForm.headImage = url
  142. self.fileList = [{
  143. url
  144. }]
  145. })
  146. // })
  147. },
  148. // #endif
  149. submit() {
  150. let self = this
  151. uni.createSelectorQuery().in(this)
  152. .select("#nickName")
  153. .fields({
  154. properties: ["value"],
  155. })
  156. .exec((res) => {
  157. const nickName = res?.[0]?.value
  158. self.userInfoForm.nickName = nickName
  159. if (self.$utils.verificationAll(self.userInfoForm, {
  160. headImage: '请选择头像',
  161. nickName: '请填写昵称',
  162. phone: '请填写手机号',
  163. })) {
  164. return
  165. }
  166. // #ifdef H5
  167. // H5端需要验证手机号格式
  168. if (!self.$utils.verificationPhone(self.userInfoForm.phone)) {
  169. uni.showToast({
  170. title: '请输入正确的手机号格式',
  171. icon: 'none'
  172. })
  173. return
  174. }
  175. // #endif
  176. self.$api('updateInfo', {
  177. avatarUrl : self.userInfoForm.headImage,
  178. nickName : self.userInfoForm.nickName,
  179. phone : self.userInfoForm.phone,
  180. }, res => {
  181. if (res.code == 200) {
  182. uni.reLaunch({
  183. url:'/pages/index/index'
  184. })
  185. }
  186. })
  187. })
  188. },
  189. }
  190. }
  191. </script>
  192. <style lang="scss" scoped>
  193. .login {
  194. display: flex;
  195. flex-direction: column;
  196. justify-content: center;
  197. align-items: center;
  198. height: 80vh;
  199. .logo{
  200. height: 140rpx;
  201. width: 140rpx;
  202. image{
  203. height: 140rpx;
  204. width: 140rpx;
  205. border-radius: 30rpx;
  206. }
  207. margin-bottom: 20rpx;
  208. }
  209. .title {
  210. line-height: 45rpx;
  211. font-weight: 900;
  212. }
  213. .line {
  214. display: flex;
  215. justify-content: space-between;
  216. align-items: center;
  217. width: 80%;
  218. border-bottom: 1px solid #00000023;
  219. padding: 30rpx 0;
  220. margin: 0 auto;
  221. }
  222. .chooseAvatar {
  223. width: 100%;
  224. padding: 0;
  225. margin: 0;
  226. margin-top: 10vh;
  227. border: none;
  228. }
  229. .btn {
  230. // background: $uni-linear-gradient-btn-color;
  231. background: $uni-color;
  232. color: #fff;
  233. width: 80%;
  234. padding: 20rpx 0;
  235. text-align: center;
  236. border-radius: 15rpx;
  237. margin-top: 10vh;
  238. }
  239. .getPhoneNumber{
  240. // all: unset;
  241. display: flex;
  242. justify-content: center;
  243. align-items: center;
  244. // background: $uni-linear-gradient-btn-color;
  245. background: $uni-color;
  246. color: #fff;
  247. width: 200rpx;
  248. height: 60rpx;
  249. border-radius: 30rpx;
  250. font-size: 24rpx;
  251. }
  252. }
  253. </style>