login.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view class="login-page">
  3. <image :src="globalImgUrls.loginTop" class="top-img" mode="aspectFill"></image>
  4. <view class="form-wrap tel-wrap" v-if="active==='手机号'">
  5. <van-field
  6. :value="tel"
  7. placeholder="请输入手机号"
  8. :border="false"
  9. center
  10. type="number"
  11. title-width="60px"
  12. @change="inputChange('tel', $event)"
  13. >
  14. <template slot="label">
  15. <picker
  16. mode="selector"
  17. :range="telAreaList"
  18. range-key="name"
  19. :value="telAreaIndex"
  20. @change="telAreaChange"
  21. header-text="请选择您的国际区号"
  22. >
  23. <view>
  24. +{{ telAreaList[telAreaIndex].value}}
  25. <van-icon name="arrow-down" style="margin-left: 4px"/>
  26. </view>
  27. </picker>
  28. </template>
  29. </van-field>
  30. <van-field
  31. :value="verifyCode"
  32. placeholder="请输入4位验证码"
  33. :border="false"
  34. title-width="60px"
  35. type="number"
  36. maxlength='4'
  37. center
  38. @change="inputChange('verifyCode', $event)"
  39. >
  40. <text slot="button" class="sendcode-btn" v-if="!isSendVerifyCode" @click="handleSendVerifyCode('tel')">发送验证码</text>
  41. <van-count-down slot="button" :time="countDownTime" format="ss S" @finish="timeFinished" v-else/>
  42. </van-field>
  43. <view class="global-btn-yellow-change submit-btn" @click="handleSubmit('tel')">提交</view>
  44. </view>
  45. <view class="form-wrap email-wrap" v-else>
  46. <van-field
  47. :value="email"
  48. placeholder="请输入邮箱地址"
  49. :border="false"
  50. center
  51. title-width="60px"
  52. @change="inputChange('email',$event)"
  53. />
  54. <van-field
  55. :value="verifyCode"
  56. placeholder="请输入4位验证码"
  57. :border="false"
  58. title-width="60px"
  59. center
  60. type="number"
  61. maxlength='4'
  62. @change="inputChange('verifyCode',$event)"
  63. >
  64. <text slot="button" class="sendcode-btn" type="primary" v-if="!isSendVerifyCode" @click="handleSendVerifyCode('email')">发送验证码</text>
  65. <van-count-down slot="button" :time="countDownTime" format="ss S" @finish="timeFinished" v-else/>
  66. </van-field>
  67. <view class="global-btn-yellow-change submit-btn" @click="handleSubmit('email')">提交</view>
  68. </view>
  69. <!-- 底部 -->
  70. <view class="change-wrap">
  71. <view class="text">{{active==='手机号'?'使用邮箱登录':'使用手机号登录'}}</view>
  72. <image class="img" @click="handleChange" mode="aspectFill" :src="active==='手机号'?'../static/login-email.png':'../static/login-phone.png'"></image>
  73. </view>
  74. <view class="bot-text">专注为全球投资者提供中立客观的研究服务</view>
  75. </view>
  76. </template>
  77. <script>
  78. import { apiGetSMSCode, apiGetEmailCode } from '@/api/common'
  79. import { apiUserLogin } from '@/api/user'
  80. import { telVerify, emailVerify } from '@/utils/common'
  81. export default {
  82. data() {
  83. return {
  84. active: "手机号",
  85. telAreaList: [
  86. {
  87. name: "大陆+86",
  88. value: "86",
  89. },
  90. {
  91. name: "香港+852",
  92. value: "852",
  93. },
  94. {
  95. name: "台湾+886",
  96. value: "886",
  97. },
  98. {
  99. name: "美国+1",
  100. value: "1",
  101. },
  102. {
  103. name: "新加坡+65",
  104. value: "65",
  105. },
  106. ], //手机号区号
  107. telAreaIndex: 0, //选择手机号区号第几个
  108. tel: "",//手机号
  109. email: "",//邮箱
  110. verifyCode: "",//验证码
  111. isSendVerifyCode: false,//是否已经发送验证码
  112. countDownTime: 60 * 1000,//倒计时60秒
  113. };
  114. },
  115. onShow(){
  116. uni.hideHomeButton()
  117. },
  118. methods: {
  119. handleChange(){
  120. if(this.active==='手机号'){
  121. this.active='邮箱'
  122. }else{
  123. this.active='手机号'
  124. }
  125. },
  126. // 区号改变
  127. telAreaChange(e) {
  128. this.telAreaIndex = e.detail.value;
  129. },
  130. //倒计时结束
  131. timeFinished() {
  132. this.isSendVerifyCode = false
  133. },
  134. inputChange(key, event) {
  135. this[key] = event.detail
  136. },
  137. //发送验证码
  138. async handleSendVerifyCode(type) {
  139. let res
  140. if (type === 'tel') {
  141. if (!this.tel) {
  142. uni.showToast({
  143. title: "请输入手机号",
  144. icon: "none"
  145. })
  146. return
  147. }
  148. res = await apiGetSMSCode({
  149. mobile: this.tel,
  150. area_num: this.telAreaList[this.telAreaIndex].value
  151. })
  152. } else {
  153. if (!this.email) {
  154. uni.showToast({
  155. title: "请输入邮箱地址",
  156. icon: "none"
  157. })
  158. return
  159. }
  160. res = await apiGetEmailCode({
  161. email: this.email
  162. })
  163. }
  164. if (res.code === 200) {
  165. this.isSendVerifyCode = true
  166. uni.showToast({
  167. title: "验证码已发送",
  168. icon: "success"
  169. })
  170. }
  171. },
  172. // 提交
  173. async handleSubmit(type) {
  174. let params = {}
  175. if (type === 'tel') {
  176. params = {
  177. area_num: Number(this.telAreaList[this.telAreaIndex].value),
  178. mobile: this.tel,
  179. verify_code: this.verifyCode,
  180. bind_type: 1
  181. }
  182. } else {
  183. params = {
  184. email: this.email,
  185. verify_code: this.verifyCode,
  186. bind_type: 2
  187. }
  188. }
  189. if (!params.verify_code) {
  190. uni.showToast({
  191. title: "请输入验证码",
  192. icon: "none"
  193. })
  194. return
  195. }
  196. const res = await apiUserLogin(params)
  197. if (res.code === 200) {
  198. uni.switchTab({
  199. url: '/pages/activity/activity'
  200. })
  201. this.$store.dispatch('getUserInfo')
  202. this.$store.dispatch('getTabBar')
  203. }
  204. }
  205. },
  206. };
  207. </script>
  208. <style lang="scss">
  209. .login-page {
  210. padding: 34rpx;
  211. text-align: center;
  212. }
  213. .top-img {
  214. width: 140rpx;
  215. height: 140rpx;
  216. margin-top: 70rpx;
  217. margin-bottom: 100rpx;
  218. }
  219. .van-cell {
  220. border-bottom: 1px solid $global-border-color;
  221. }
  222. .sendcode-btn{
  223. color:$global-text-color-main;
  224. }
  225. .change-wrap{
  226. margin-top: 100rpx;
  227. .text{
  228. color: #CFCFCF;
  229. display: flex;
  230. align-items: center;
  231. justify-content: center;
  232. &::before{
  233. content: '';
  234. width: 140rpx;
  235. height: 1rpx;
  236. display: inline-block;
  237. background-color: #E1E2E6;
  238. margin-right: 20rpx;
  239. }
  240. &::after{
  241. content: '';
  242. width: 140rpx;
  243. height: 1rpx;
  244. display: inline-block;
  245. background-color: #E1E2E6;
  246. margin-left: 20rpx;
  247. }
  248. }
  249. .img{
  250. margin-top: 40rpx;
  251. width: 80rpx;
  252. height: 80rpx;
  253. }
  254. }
  255. .submit-btn {
  256. width: 490rpx;
  257. margin-left: auto;
  258. margin-right: auto;
  259. margin-top: 100rpx;
  260. }
  261. .bot-text{
  262. position: fixed;
  263. left: 50%;
  264. transform: translateX(-50%);
  265. bottom: 100rpx;
  266. color: $global-text-color-999;
  267. width: 100%;
  268. }
  269. </style>