推拿小程序前端代码仓库
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.

323 lines
6.4 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
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.config_app_logo" mode=""></image>
  5. <view class="text">
  6. {{ configList.config_app_name }}
  7. </view>
  8. </view>
  9. <view class="title">
  10. 申请获取你的头像昵称
  11. </view>
  12. <view class="form">
  13. <view class="form-item">
  14. <view class="label">
  15. 头像
  16. </view>
  17. <view class="content">
  18. <button class="btn-avatar" :plain="true" :hairline="false" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  19. <image :src="userInfoForm.headImage" v-if="userInfoForm.headImage" class="avatar"
  20. mode=""></image>
  21. <view v-else class="avatar" style="background-color: #C7C7C7; border-radius: 50%;">
  22. <uv-icon name="account-fill" color="#ffffff" size="70rpx"></uv-icon>
  23. </view>
  24. </button>
  25. </view>
  26. </view>
  27. <view class="form-item">
  28. <view class="label">
  29. 昵称
  30. </view>
  31. <view class="content">
  32. <input type="nickname" placeholder="请输入昵称" style="text-align: right;" id="nickName"
  33. placeholder-class="uni-placeholder"
  34. v-model="userInfoForm.nickName"
  35. />
  36. </view>
  37. </view>
  38. <view class="form-item">
  39. <view class="label">
  40. 手机号
  41. </view>
  42. <!-- #ifdef MP-WEIXIN -->
  43. <view class="content">
  44. <input v-if="userInfoForm.phone"
  45. placeholder-class="uni-placeholder"
  46. placeholder="请输入手机号"
  47. style="text-align: right;"
  48. disabled
  49. v-model="userInfoForm.phone"
  50. />
  51. <view v-else>
  52. <button
  53. :plain="true" :hairline="false"
  54. class="btn-phone"
  55. open-type="getPhoneNumber"
  56. @getphonenumber="getPhone"
  57. >
  58. 获取电话号码
  59. </button>
  60. </view>
  61. </view>
  62. <!-- #endif -->
  63. <!-- #ifdef H5 -->
  64. <view class="content">
  65. <input
  66. placeholder-class="uni-placeholder"
  67. placeholder="请输入手机号"
  68. style="text-align: right;"
  69. v-model="userInfoForm.phone"
  70. />
  71. </view>
  72. <!-- #endif -->
  73. </view>
  74. </view>
  75. <view class="btn" @click="submit">
  76. 确认
  77. </view>
  78. </view>
  79. </template>
  80. <script>
  81. export default {
  82. data() {
  83. return {
  84. userInfoForm: {
  85. headImage: '',
  86. nickName: '',
  87. phone: '',
  88. }
  89. };
  90. },
  91. onShow() {},
  92. onLoad() {
  93. this.userInfoForm.nickName = this.userInfo.nickName || ''
  94. this.userInfoForm.headImage = this.userInfo.headImage || ''
  95. },
  96. computed: {},
  97. methods: {
  98. onChooseAvatar(res) {
  99. this.$Oss.ossUpload(res.target.avatarUrl)
  100. .then(url => {
  101. this.userInfoForm.headImage = url
  102. })
  103. },
  104. getPhone(e){
  105. this.$api('bindPhone', {
  106. phoneCode : e.detail.code
  107. }, res => {
  108. if(res.code == 200){
  109. let phoneObj = JSON.parse(res.result)
  110. if(phoneObj.errmsg == 'ok'){
  111. this.userInfoForm.phone = phoneObj.phone_info.phoneNumber
  112. }else{
  113. uni.showModal({
  114. title: phoneObj.errmsg
  115. })
  116. }
  117. }
  118. })
  119. },
  120. validatePhone(phone) {
  121. // let fixedLindReg = /(\d{3,4}-)?\d{7,8}$/g // 常见座机格式
  122. let mobileReg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/g // 中国大陆手机号
  123. // if (fixedLindReg.test(phone)) {
  124. // return true
  125. // }
  126. if (mobileReg.test(phone)) {
  127. return true
  128. }
  129. uni.showToast({
  130. title: '请填写正确手机号',
  131. icon: "none"
  132. })
  133. return false
  134. },
  135. submit() {
  136. let self = this
  137. uni.createSelectorQuery().in(this)
  138. .select("#nickName")
  139. .fields({
  140. properties: ["value"],
  141. })
  142. .exec((res) => {
  143. const nickName = res?.[0]?.value
  144. self.userInfoForm.nickName = nickName
  145. if (self.$utils.verificationAll(self.userInfoForm, {
  146. headImage: '请选择头像',
  147. nickName: '请填写昵称',
  148. phone: '请填写手机号',
  149. })) {
  150. return
  151. }
  152. if (!this.validatePhone(self.userInfoForm.phone)) {
  153. return
  154. }
  155. self.$api('updateInfo', {
  156. headImage : self.userInfoForm.headImage,
  157. nickName : self.userInfoForm.nickName,
  158. phone : self.userInfoForm.phone,
  159. }, res => {
  160. if (res.code == 200) {
  161. uni.reLaunch({
  162. url:'/pages/index/index'
  163. })
  164. }
  165. })
  166. })
  167. },
  168. }
  169. }
  170. </script>
  171. <style lang="scss" scoped>
  172. .login {
  173. display: flex;
  174. justify-content: flex-start;
  175. align-items: center;
  176. height: 100vh;
  177. flex-direction: column;
  178. position: relative;
  179. background: $uni-fg-color;
  180. .logo{
  181. margin-top: 334rpx;
  182. width: 320rpx;
  183. image{
  184. height: 150rpx;
  185. width: 320rpx;
  186. }
  187. .text{
  188. margin-top: 90rpx;
  189. font-size: 38rpx;
  190. font-family: PingFang SC, PingFang SC-Bold;
  191. font-weight: 700;
  192. text-align: center;
  193. color: #000000;
  194. }
  195. }
  196. .title {
  197. margin-top: 48rpx;
  198. font-size: 32rpx;
  199. font-family: PingFang SC, PingFang SC-Regular;
  200. font-weight: 400;
  201. color: #000000;
  202. }
  203. .form {
  204. margin-top: 45rpx;
  205. width: 100%;
  206. display: flex;
  207. flex-direction: column;
  208. align-items: center;
  209. .form-item {
  210. width: 85%;
  211. display: flex;
  212. align-items: baseline;
  213. padding: 11rpx 23rpx;
  214. position: relative;
  215. &::after {
  216. position: absolute;
  217. bottom: 0;
  218. left: 0;
  219. content: " ";
  220. width: 100%;
  221. height: 1rpx;
  222. border-top: 1px solid rgba(112, 112, 112, 0.35);
  223. transform: scaleY(.5);
  224. }
  225. .label {
  226. width: 90rpx;
  227. font-size: 30rpx;
  228. font-family: SimSun, SimSun-Regular;
  229. font-weight: 400;
  230. text-align: left;
  231. color: #000000;
  232. }
  233. .content {
  234. flex: 1;
  235. text-align: right;
  236. }
  237. }
  238. .form-item + .form-item {
  239. margin-top: 50rpx;
  240. }
  241. .btn-avatar {
  242. background: transparent;
  243. border: none;
  244. border-radius: none;
  245. box-shadow: none;
  246. padding: 0;
  247. margin: 0;
  248. font-size: 0;
  249. text-align: right;
  250. }
  251. .avatar {
  252. display: inline-block;
  253. width: 70rpx;
  254. height: 70rpx;
  255. margin-right: 63rpx;
  256. }
  257. .btn-phone {
  258. border: none;
  259. border-radius: 0;
  260. padding: 7rpx;
  261. margin: 0;
  262. text-align: right;
  263. color: #C7C7C7;
  264. font-size: 30rpx;
  265. line-height: 1;
  266. }
  267. }
  268. .btn {
  269. text-align: center;
  270. margin-top: 155rpx;
  271. width: 80%;
  272. height: 100rpx;
  273. border-radius: 50rpx;
  274. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  275. color: #fff;
  276. display: flex;
  277. justify-content: center;
  278. align-items: center;
  279. border-radius: 50rpx;
  280. border: none;
  281. }
  282. }
  283. </style>