login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <view class="container login">
  3. <view class="login-main">
  4. <image class="logo" :src="staticUrl + 'logo@2x.png'" mode=""></image>
  5. </view>
  6. <tui-skeleton
  7. v-if="skeletonShow"
  8. backgroundColor="#fafafa"
  9. borderRadius="10rpx"
  10. :isLoading="true"
  11. :loadingType="5"
  12. ></tui-skeleton>
  13. <template else>
  14. <view class="login-form" v-if="loginType === 0">
  15. <view class="login-input">
  16. <text class="iconfont icon-shoujihao"></text>
  17. <input
  18. type="number"
  19. v-model="codeParams.mobile"
  20. maxlength="11"
  21. class="input"
  22. placeholder="请输入已注册的手机号"
  23. @input="handleMobile"
  24. />
  25. </view>
  26. <view class="login-input">
  27. <text class="iconfont icon-duanxin"></text>
  28. <input
  29. type="number"
  30. v-model="codeParams.code"
  31. maxlength="6"
  32. class="input code"
  33. placeholder="请输入短信验证码"
  34. @input="handleSmsCode"
  35. />
  36. <view class="code-btn" :class="isMobileDisabled ? 'disabled':''" @click.stop="handleMobileCode"> {{ mobileCodeText }} </view>
  37. </view>
  38. <view class="login-input link">
  39. <view class="login-reg" v-if="!isUnderLogin" @click.stop="navigatorRegirst('/pages/login/register')">免费注册</view>
  40. <view class="login-pwd" @click.stop="handeleLogin(1)">密码登录</view>
  41. </view>
  42. </view>
  43. <view class="login-form" v-if="loginType === 1">
  44. <view class="login-input">
  45. <text class="iconfont icon-shoujihao"></text>
  46. <input
  47. type="text"
  48. v-model="accountParams.mobileOrEmail"
  49. maxlength="11"
  50. class="input"
  51. placeholder="请输入已注册的手机号"
  52. @input="handleMobileOrEmail"
  53. />
  54. </view>
  55. <view class="login-input">
  56. <text class="iconfont icon-mima"></text>
  57. <input
  58. type="password"
  59. v-model="accountParams.password"
  60. maxlength="18"
  61. class="input"
  62. placeholder="请输入密码"
  63. autocomplete="new-password"
  64. @input="handlePassword"
  65. />
  66. </view>
  67. <view class="login-input link">
  68. <view class="login-reg" v-if="!isUnderLogin" @click.stop="navigatorRegirst('/pages/login/register')">免费注册</view>
  69. <view class="login-pwd" @click.stop="handeleLogin(0)">验证码登录</view>
  70. </view>
  71. </view>
  72. <button class="login-btn" :disabled="isDisabled" :class="isDisabled ? 'disabled' : ''" @click="handleSubLogin">
  73. 登录
  74. </button>
  75. <view class="login-text" v-if="loginType === 1" @click.stop="this.$api.navigateTo('/pages/login/password')"
  76. >忘记密码?</view
  77. >
  78. </template>
  79. </view>
  80. </template>
  81. <script>
  82. import { mapState, mapMutations } from 'vuex'
  83. import authorize from '@/common/config/authorize.js'
  84. import wxLogin from '@/common/config/wxLogin.js'
  85. export default {
  86. data() {
  87. return {
  88. staticUrl:this.global.staticUrl,
  89. skeletonShow:true,
  90. getOption: '', //页面传递参数
  91. accountParams: {
  92. mobileOrEmail: '', //用户登录账号
  93. password: '', //用户登录密码
  94. unionId: ''
  95. },
  96. codeParams: {
  97. mobile: '', //用户登录手机号
  98. code: '',
  99. unionId: ''
  100. },
  101. smsCodeParams: {
  102. mobile: '' ,//用户登录手机号
  103. imgCode:'',
  104. platformType:0,
  105. isCheckCaptcha:1,
  106. activateCodeType:9
  107. },
  108. loginType: 0,
  109. isMobileDisabled: false, //手机验证码按钮控制
  110. mobilCount: '', //倒计时
  111. mobileCodeText: '获取验证码',
  112. mobilTime: null,
  113. isDisabled: true,
  114. isUnderLogin:false
  115. }
  116. },
  117. onLoad(option) {
  118. this.getOption = JSON.stringify(option)
  119. },
  120. computed: {
  121. ...mapState(['hasLogin', 'isWxAuthorize', 'isLoginType'])
  122. },
  123. methods: {
  124. ...mapMutations(['login']),
  125. async infoClucbUser(){
  126. const user = await this.$api.getStorage()
  127. if(user.clubStatus === 1 || user.clubStatus === 99){
  128. this.isUnderLogin = true
  129. }
  130. this.skeletonShow = false
  131. },
  132. handleMobileOrEmail(e) {
  133. //账号输入
  134. this.accountParams.mobileOrEmail = e.detail.value
  135. this.handldeCheckInput()
  136. },
  137. handlePassword(e) {
  138. //密码输入
  139. this.accountParams.password = e.detail.value
  140. this.handldeCheckInput()
  141. },
  142. handleMobile(e) {
  143. //短信验证手机号输入
  144. this.codeParams.mobile = this.smsCodeParams.mobile = e.detail.value
  145. this.handldeCheckInput()
  146. },
  147. handleSmsCode(e) {
  148. //短信验证码输入
  149. this.codeParams.code = e.detail.value
  150. this.handldeCheckInput()
  151. },
  152. handldeCheckInput() {
  153. // 控制按钮按钮高亮
  154. if (this.loginType === 0) {
  155. this.isDisabled = !(this.codeParams.mobile !== '' && this.codeParams.code !== '')
  156. } else {
  157. this.isDisabled = !(this.accountParams.mobileOrEmail !== '' && this.accountParams.password !== '')
  158. }
  159. },
  160. handleMobileCode() {
  161. // 获取短信验证码
  162. if(this.isMobileDisabled){ return }
  163. if (this.smsCodeParams.mobile == '') {
  164. this.$util.msg('请输入手机号', 2000)
  165. return
  166. }
  167. if (!this.$reg.isMobile(this.smsCodeParams.mobile)) {
  168. this.$util.msg('请输入正确的手机号', 2000)
  169. return
  170. }
  171. this.isMobileDisabled = true
  172. this.userLoginCode(this.smsCodeParams)
  173. },
  174. async userLoginCode(params) {
  175. // 获取登录短息验证码
  176. try{
  177. const res = await this.UserService.userLoginCode(params)
  178. this.$util.msg('获取验证码成功', 2000)
  179. const TIME_COUNT = 60
  180. if (!this.mobilTime) {
  181. this.mobilCount = TIME_COUNT
  182. this.isMobileDisabled = true
  183. this.mobilTime = setInterval(() => {
  184. if (this.mobilCount > 1 && this.mobilCount <= TIME_COUNT) {
  185. this.mobilCount--
  186. this.mobileCodeText = this.mobilCount + 's'
  187. } else {
  188. this.isMobileDisabled = false
  189. clearInterval(this.mobilTime)
  190. this.mobilTime = null
  191. this.mobileCodeText = '获取验证码'
  192. }
  193. }, 1000)
  194. }
  195. }catch(error){
  196. //TODO handle the exception
  197. this.$util.msg(error.msg, 2000)
  198. this.isMobileDisabled = false
  199. }
  200. },
  201. async handleSubLogin() {
  202. // 点击登录
  203. const stor = await this.$api.getStorage()
  204. this.accountParams.unionId = this.codeParams.unionId = stor.unionId ? stor.unionId : ''
  205. if (this.loginType === 0) {
  206. this.userCodeLogin()
  207. } else {
  208. this.userPasswordLogin()
  209. }
  210. },
  211. async userCodeLogin() {
  212. // 短信验证码登录
  213. try{
  214. const res =await this.UserService.userCodeLogin(this.codeParams)
  215. this.updataeStatus(res)
  216. }catch(error){
  217. this.$util.msg(error.msg, 2000)
  218. }
  219. },
  220. async userPasswordLogin() {
  221. // 账号密码登录
  222. try{
  223. const res =await this.UserService.AorganizationLogin(this.accountParams)
  224. this.updataeStatus(res)
  225. }catch(error){
  226. this.$util.msg(error.msg, 2000)
  227. }
  228. },
  229. updataeStatus(data) {
  230. // 处理返回数据
  231. if (data.code === 0) {
  232. uni.setStorageSync('token', data.data.token)
  233. this.$store.commit('updateStatus', data.data)
  234. this.login(data.data)
  235. // 登录成功处理
  236. const url = uni.getStorageSync('LOGIN_REDIRECT_URL')
  237. if (url) {
  238. if (url.indexOf('tabBar') > -1) {
  239. uni.switchTabTo(url)
  240. } else {
  241. this.$api.redirectTo(url)
  242. }
  243. } else {
  244. this.$api.switchTabTo('/pages/tabBar/user/user')
  245. }
  246. } else {
  247. this.$util.msg(data.msg, 2000)
  248. }
  249. },
  250. navigatorRegirst(url) {
  251. this.$api.navigateTo(url)
  252. },
  253. handeleLogin(type) {
  254. this.loginType = type
  255. },
  256. async checkedAuthorize() {
  257. //是否已授权 0:为取消授权 1:为已授权 2:为未操作
  258. // wxLogin.wxLoginQuick()
  259. }
  260. },
  261. onShow() {
  262. this.infoClucbUser()
  263. }
  264. }
  265. </script>
  266. <style lang="scss">
  267. .login {
  268. width: 100%;
  269. height: auto;
  270. .model-warp.none {
  271. display: none;
  272. }
  273. .model-warp.show {
  274. display: block;
  275. }
  276. .login-main {
  277. width: 100%;
  278. display: flex;
  279. flex-direction: column;
  280. align-items: center;
  281. height: 206rpx;
  282. padding: 60rpx 0 40rpx 0;
  283. margin-bottom: 70rpx;
  284. .logo {
  285. width: 358rpx;
  286. height: 206rpx;
  287. display: block;
  288. }
  289. }
  290. .login-input {
  291. width: 600rpx;
  292. height: 88rpx;
  293. padding: 24rpx 0;
  294. margin: 0 auto;
  295. margin-bottom: 30rpx;
  296. background: #ffffff;
  297. position: relative;
  298. box-sizing: border-box;
  299. border-bottom: 1px solid #e1e1e1;
  300. .input {
  301. width: 100%;
  302. height: 100%;
  303. background: #ffffff;
  304. font-size: $font-size-28;
  305. line-height: 88rpx;
  306. color: #333333;
  307. padding-left: 100rpx;
  308. box-sizing: border-box;
  309. &.code {
  310. padding-right: 200rpx;
  311. }
  312. }
  313. .code-btn {
  314. width: 180rpx;
  315. height: 64rpx;
  316. position: absolute;
  317. right: 0;
  318. top: 10rpx;
  319. line-height: 64rpx;
  320. text-align: center;
  321. color: #FFFFFF;
  322. font-size: $font-size-24;
  323. border-radius: 32rpx;
  324. background: $btn-confirm;
  325. &.disabled{
  326. background: #E1E1E1;
  327. }
  328. }
  329. .iconfont {
  330. position: absolute;
  331. left: 0;
  332. top: 0;
  333. font-size: 48rpx;
  334. color: #333333;
  335. width: 100rpx;
  336. height: 88rpx;
  337. line-height: 88rpx;
  338. text-align: left;
  339. }
  340. &.link {
  341. background: #ffffff;
  342. margin-bottom: 40rpx;
  343. padding: 0 0;
  344. line-height: 40rpx;
  345. font-size: $font-size-24;
  346. border-bottom: none;
  347. .login-reg {
  348. float: left;
  349. color: $color-system;
  350. }
  351. .login-pwd {
  352. float: right;
  353. color: $text-color;
  354. }
  355. }
  356. }
  357. .login-btn {
  358. width: 600rpx;
  359. height: 88rpx;
  360. border-radius: 44rpx;
  361. font-size: $font-size-28;
  362. line-height: 88rpx;
  363. color: #ffffff;
  364. margin: 0 auto;
  365. text-align: center;
  366. background: $btn-confirm;
  367. &.disabled {
  368. background: #e2e2e2;
  369. }
  370. }
  371. .login-text {
  372. width: 600rpx;
  373. height: 88rpx;
  374. font-size: $font-size-28;
  375. line-height: 88rpx;
  376. color: #333333;
  377. margin: 0 auto;
  378. text-align: center;
  379. }
  380. .login-tel {
  381. width: 702rpx;
  382. font-size: $font-size-28;
  383. line-height: 80rpx;
  384. margin: 0 auto;
  385. color: $text-color;
  386. text-align: center;
  387. margin-top: 150rpx;
  388. }
  389. .model-authorization {
  390. width: 100%;
  391. height: 100%;
  392. position: fixed;
  393. top: 0;
  394. left: 0;
  395. z-index: 999;
  396. .authorization {
  397. width: 518rpx;
  398. height: 320rpx;
  399. position: absolute;
  400. background: rgba(255, 255, 255, 0.7);
  401. left: 0;
  402. right: 0;
  403. bottom: 0;
  404. top: 0;
  405. margin: auto;
  406. .to-btn {
  407. position: absolute;
  408. top: 0;
  409. left: 0;
  410. right: 0;
  411. bottom: 0;
  412. margin: auto;
  413. width: 70%;
  414. height: 88rpx;
  415. font-size: $font-size-28;
  416. line-height: 88rpx;
  417. color: #ffffff;
  418. text-align: center;
  419. border-radius: 44rpx;
  420. }
  421. }
  422. }
  423. }
  424. </style>