mobile.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <view class="container bg-main pos-r">
  3. <use-tabbar :tabbar="false"></use-tabbar>
  4. <form>
  5. <view class="padding-xl dflex-c dflex-flow-c">
  6. <!-- 头像 -->
  7. <view class="headimg-box margin-top margin-bottom-xl" style="width: 100px; height: 100px;">
  8. <image class="headimg border-radius-c" :src="logo"
  9. style="width: 100%; height: 100%; object-fit: cover;" />
  10. </view>
  11. <!-- swiper 轮播登录方式 -->
  12. <swiper class="w-full" :current="current">
  13. <!-- 验证码登录 -->
  14. <swiper-item>
  15. <view class="w-full dflex padding-bottom-sm">
  16. <view class="iconfont iconshouji margin-right"></view>
  17. <view class="flex1 dflex">
  18. <input class="border-line padding-sm flex1" type="number" maxlength="11" v-model="phone"
  19. placeholder="请输入手机号" />
  20. </view>
  21. </view>
  22. <view class="w-full dflex padding-bottom-sm">
  23. <view class="iconfont iconyanzheng margin-right"></view>
  24. <view class="border-line flex1 dflex">
  25. <input class="padding-sm flex1" type="number" maxlength="6" v-model="code"
  26. placeholder="请输入验证码" />
  27. <view class="pos-r" @tap="sendCode">
  28. <view class="vertical-line" style="right: calc(100% + 9px);"></view>
  29. <view class="padding-tb-sm ft-dark-4">{{ codeText }}</view>
  30. </view>
  31. </view>
  32. </view>
  33. </swiper-item>
  34. </swiper>
  35. <!-- 登录按钮 -->
  36. <view class="w-full margin-top-xxl">
  37. <view class="dflex-b border-radius-lg">
  38. <view class="tac padding-tb-sm flex1 bg-base fs" @tap="login">绑定手机号</view>
  39. </view>
  40. </view>
  41. <!-- 协议勾选 -->
  42. <view class="dflex w-full margin-top" @tap="toggleAgree">
  43. <view class="iconfont" :class="agree ? 'iconxuanzhongzhuangtai' : 'iconweixuanzhongzhuangtai'">
  44. </view>
  45. <view class="ft-dark-3" style="margin-left:10rpx;margin-top:5rpx;">
  46. 已阅读并同意
  47. <text class="ft-base" @click.stop="Dever.location('tool/page?title=隐私政策')">《隐私政策》</text>
  48. <text class="ft-base" @click.stop="Dever.location('tool/page?title=使用协议')">《使用协议》</text>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="pos-f pos-bottom dflex-c w-full padding-bottom-lg safe-area-inset-bottom-plus"></view>
  53. </form>
  54. </view>
  55. </template>
  56. <script>
  57. export default {
  58. data() {
  59. return {
  60. logo: '',
  61. inputType: 'text',
  62. current: 0,
  63. phone: '',
  64. password: '',
  65. code: '',
  66. codeText: '发送验证码',
  67. countdown: 0,
  68. agree: false
  69. }
  70. },
  71. onLoad() {
  72. if (!this.DeverApi.getToken()) {
  73. return this.Dever.goHome();
  74. }
  75. this.Dever.config().then(config => {
  76. this.logo = config.l;
  77. });
  78. this.loadData()
  79. },
  80. methods: {
  81. loadData() {
  82. this.DeverApi.get(this, 'user.my', {}, res => {
  83. if (res.user.avatar) {
  84. this.logo = res.user.avatar
  85. }
  86. });
  87. },
  88. switchLoginType() {
  89. this.current = this.current === 0 ? 1 : 0
  90. },
  91. toggleAgree() {
  92. this.agree = !this.agree
  93. },
  94. sendCode() {
  95. if (!/^1\d{10}$/.test(this.phone)) {
  96. return this.Dever.alert('请输入有效手机号')
  97. }
  98. if (this.countdown > 0) return
  99. this.DeverApi.post('bind.sms', {
  100. mobile: this.phone
  101. }, r => {
  102. if (r.indexOf('::') != -1) {
  103. var t = r.split('::');
  104. r = t[0];
  105. this.code = t[1];
  106. }
  107. this.Dever.success(r)
  108. this.countdown = 60
  109. this.updateCodeText()
  110. });
  111. },
  112. updateCodeText() {
  113. if (this.countdown === 0) {
  114. this.codeText = '发送验证码'
  115. return
  116. }
  117. this.codeText = `${this.countdown}s`
  118. setTimeout(() => {
  119. this.countdown--
  120. this.updateCodeText()
  121. }, 1000)
  122. },
  123. async login() {
  124. if (!this.agree) {
  125. return this.Dever.alert('请勾选协议');
  126. }
  127. if (!/^1\d{10}$/.test(this.phone)) {
  128. return this.Dever.alert('请输入有效手机号');
  129. }
  130. var param = {}
  131. param.mobile = this.phone;
  132. if (this.Dever.env === 5) { // 小程序
  133. try {
  134. const loginRes = await new Promise((resolve, reject) => {
  135. uni.login({
  136. provider: 'weixin',
  137. success: resolve,
  138. fail: reject
  139. })
  140. })
  141. param.applet_code = loginRes.code
  142. } catch (err) {
  143. return this.Dever.alert('登录失败,请重试')
  144. }
  145. }
  146. if (!this.code) {
  147. return this.Dever.alert('请输入验证码');
  148. }
  149. param.code = this.code;
  150. this.DeverApi.post('bind.mobile', param, r => {
  151. this.Dever.success('绑定成功')
  152. this.DeverApi.setToken(r.t);
  153. this.Dever.location('user/index');
  154. });
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss">
  160. page {
  161. background: #f4f4f4;
  162. }
  163. .container {
  164. padding-top: 5vh;
  165. width: 100vw;
  166. min-height: 100vh;
  167. overflow: hidden;
  168. }
  169. .headimg-box {
  170. image {
  171. width: 130rpx;
  172. height: 130rpx;
  173. border: 5rpx solid #fff;
  174. }
  175. }
  176. </style>