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

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