login.vue 8.8 KB

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