login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. <!-- 弹窗提示 -->
  80. <tui-modal
  81. :show="modal"
  82. @click="handleClick"
  83. @cancel="modal = false"
  84. :content="modalContent"
  85. :button="modalButton"
  86. color="#333"
  87. :size="32"
  88. shape="circle"
  89. :maskClosable="false"
  90. >
  91. </tui-modal>
  92. </view>
  93. </template>
  94. <script>
  95. import { mapState, mapMutations } from 'vuex'
  96. import authorize from '@/common/config/authorize.js'
  97. import wxLogin from '@/common/config/wxLogin.js'
  98. export default {
  99. data() {
  100. return {
  101. staticUrl:this.global.staticUrl,
  102. skeletonShow:true,
  103. getOption: '', //页面传递参数
  104. accountParams: {
  105. mobileOrEmail: '', //用户登录账号
  106. password: '', //用户登录密码
  107. unionId: ''
  108. },
  109. codeParams: {
  110. mobile: '', //用户登录手机号
  111. code: '',
  112. unionId: ''
  113. },
  114. smsCodeParams: {
  115. mobile: '' ,//用户登录手机号
  116. imgCode:'',
  117. platformType:0,
  118. isCheckCaptcha:1,
  119. activateCodeType:9
  120. },
  121. loginType: 0,
  122. isMobileDisabled: false, //手机验证码按钮控制
  123. mobilCount: '', //倒计时
  124. mobileCodeText: '获取验证码',
  125. mobilTime: null,
  126. isDisabled: true,
  127. isUnderLogin:false,
  128. modal:false,
  129. modalButton: [
  130. {
  131. text: '取消',
  132. type: 'gray',
  133. plain: true //是否空心
  134. },
  135. {
  136. text: '去修改',
  137. customStyle: {
  138. color: '#fff',
  139. bgColor: '#F3B574'
  140. },
  141. plain: false
  142. }
  143. ],
  144. modalContent:''
  145. }
  146. },
  147. onLoad(option) {
  148. this.getOption = JSON.stringify(option)
  149. },
  150. computed: {
  151. ...mapState(['hasLogin', 'isWxAuthorize', 'isLoginType'])
  152. },
  153. methods: {
  154. ...mapMutations(['login']),
  155. async infoClucbUser(){
  156. const user = await this.$api.getStorage()
  157. if(user.clubStatus === 1 || user.clubStatus === 99){
  158. this.isUnderLogin = true
  159. }
  160. this.skeletonShow = false
  161. },
  162. handleMobileOrEmail(e) {
  163. //账号输入
  164. this.accountParams.mobileOrEmail = e.detail.value
  165. this.handldeCheckInput()
  166. },
  167. handlePassword(e) {
  168. //密码输入
  169. this.accountParams.password = e.detail.value
  170. this.handldeCheckInput()
  171. },
  172. handleMobile(e) {
  173. //短信验证手机号输入
  174. this.codeParams.mobile = this.smsCodeParams.mobile = e.detail.value
  175. this.handldeCheckInput()
  176. },
  177. handleSmsCode(e) {
  178. //短信验证码输入
  179. this.codeParams.code = e.detail.value
  180. this.handldeCheckInput()
  181. },
  182. handldeCheckInput() {
  183. // 控制按钮按钮高亮
  184. if (this.loginType === 0) {
  185. this.isDisabled = !(this.codeParams.mobile !== '' && this.codeParams.code !== '')
  186. } else {
  187. this.isDisabled = !(this.accountParams.mobileOrEmail !== '' && this.accountParams.password !== '')
  188. }
  189. },
  190. handleMobileCode() {
  191. // 获取短信验证码
  192. if(this.isMobileDisabled){ return }
  193. if (this.smsCodeParams.mobile == '') {
  194. this.$util.msg('请输入手机号', 2000)
  195. return
  196. }
  197. if (!this.$reg.isMobile(this.smsCodeParams.mobile)) {
  198. this.$util.msg('请输入正确的手机号', 2000)
  199. return
  200. }
  201. this.isMobileDisabled = true
  202. this.userLoginCode(this.smsCodeParams)
  203. },
  204. async userLoginCode(params) {
  205. // 获取登录短息验证码
  206. try{
  207. const res = await this.UserService.userLoginCode(params)
  208. this.$util.msg('获取验证码成功', 2000)
  209. const TIME_COUNT = 60
  210. if (!this.mobilTime) {
  211. this.mobilCount = TIME_COUNT
  212. this.isMobileDisabled = true
  213. this.mobilTime = setInterval(() => {
  214. if (this.mobilCount > 1 && this.mobilCount <= TIME_COUNT) {
  215. this.mobilCount--
  216. this.mobileCodeText = this.mobilCount + 's'
  217. } else {
  218. this.isMobileDisabled = false
  219. clearInterval(this.mobilTime)
  220. this.mobilTime = null
  221. this.mobileCodeText = '获取验证码'
  222. }
  223. }, 1000)
  224. }
  225. }catch(error){
  226. //TODO handle the exception
  227. this.$util.msg(error.msg, 2000)
  228. this.isMobileDisabled = false
  229. }
  230. },
  231. async handleSubLogin() {
  232. // 点击登录
  233. const stor = await this.$api.getStorage()
  234. this.accountParams.unionId = this.codeParams.unionId = stor.unionId ? stor.unionId : ''
  235. if (this.loginType === 0) {
  236. this.userCodeLogin()
  237. } else {
  238. this.userPasswordLogin()
  239. }
  240. },
  241. async userCodeLogin() {
  242. // 短信验证码登录
  243. try{
  244. const res =await this.UserService.userCodeLogin(this.codeParams)
  245. this.updataeStatus(res)
  246. }catch(error){
  247. this.$util.msg(error.msg, 2000)
  248. }
  249. },
  250. async userPasswordLogin() {
  251. // 账号密码登录
  252. try{
  253. const res =await this.UserService.AorganizationLogin(this.accountParams)
  254. this.updataeStatus(res)
  255. }catch(error){
  256. this.$util.msg(error.msg, 2000)
  257. }
  258. },
  259. updataeStatus(data) {
  260. // 处理返回数据
  261. if (data.code === 0) {
  262. uni.setStorageSync('token', data.data.token)
  263. this.$store.commit('updateStatus', data.data)
  264. this.login(data.data)
  265. // 登录成功处理
  266. const url = uni.getStorageSync('LOGIN_REDIRECT_URL')
  267. if (url) {
  268. if (url.indexOf('tabBar') > -1) {
  269. uni.switchTabTo(url)
  270. } else {
  271. this.$api.redirectTo(url)
  272. }
  273. } else {
  274. this.$api.switchTabTo('/pages/tabBar/user/user')
  275. }
  276. uni.removeStorageSync('LOGIN_REDIRECT_URL')
  277. } else if(data.code === -3) {
  278. this.modal = true
  279. this.modalContent = data.msg
  280. }else{
  281. this.$util.msg(data.msg, 2000)
  282. }
  283. },
  284. handleClick(e) {
  285. //确认删除
  286. if (e.index == 1) {
  287. this.$api.navigateTo('/pages/login/register-unid')
  288. }
  289. this.modal = false
  290. },
  291. navigatorRegirst(url) {
  292. this.$api.navigateTo(url)
  293. },
  294. handeleLogin(type) {
  295. this.loginType = type
  296. },
  297. async checkedAuthorize() {
  298. //是否已授权 0:为取消授权 1:为已授权 2:为未操作
  299. wxLogin.wxLoginQuick()
  300. }
  301. },
  302. onShow() {
  303. this.infoClucbUser()
  304. }
  305. }
  306. </script>
  307. <style lang="scss">
  308. .login {
  309. width: 100%;
  310. height: auto;
  311. .model-warp.none {
  312. display: none;
  313. }
  314. .model-warp.show {
  315. display: block;
  316. }
  317. .login-main {
  318. width: 100%;
  319. display: flex;
  320. flex-direction: column;
  321. align-items: center;
  322. height: 206rpx;
  323. padding: 60rpx 0 40rpx 0;
  324. margin-bottom: 70rpx;
  325. .logo {
  326. width: 358rpx;
  327. height: 206rpx;
  328. display: block;
  329. }
  330. }
  331. .login-input {
  332. width: 600rpx;
  333. height: 88rpx;
  334. padding: 24rpx 0;
  335. margin: 0 auto;
  336. margin-bottom: 30rpx;
  337. background: #ffffff;
  338. position: relative;
  339. box-sizing: border-box;
  340. border-bottom: 1px solid #e1e1e1;
  341. .input {
  342. width: 100%;
  343. height: 100%;
  344. background: #ffffff;
  345. font-size: $font-size-28;
  346. line-height: 88rpx;
  347. color: #333333;
  348. padding-left: 100rpx;
  349. box-sizing: border-box;
  350. &.code {
  351. padding-right: 200rpx;
  352. }
  353. }
  354. .code-btn {
  355. width: 180rpx;
  356. height: 64rpx;
  357. position: absolute;
  358. right: 0;
  359. top: 10rpx;
  360. line-height: 64rpx;
  361. text-align: center;
  362. color: #FFFFFF;
  363. font-size: $font-size-24;
  364. border-radius: 32rpx;
  365. background: $btn-confirm;
  366. &.disabled{
  367. background: #E1E1E1;
  368. }
  369. }
  370. .iconfont {
  371. position: absolute;
  372. left: 0;
  373. top: 0;
  374. font-size: 48rpx;
  375. color: #333333;
  376. width: 100rpx;
  377. height: 88rpx;
  378. line-height: 88rpx;
  379. text-align: left;
  380. }
  381. &.link {
  382. background: #ffffff;
  383. margin-bottom: 40rpx;
  384. padding: 0 0;
  385. line-height: 40rpx;
  386. font-size: $font-size-24;
  387. border-bottom: none;
  388. .login-reg {
  389. float: left;
  390. color: $color-system;
  391. }
  392. .login-pwd {
  393. float: right;
  394. color: $text-color;
  395. }
  396. }
  397. }
  398. .login-btn {
  399. width: 600rpx;
  400. height: 88rpx;
  401. border-radius: 44rpx;
  402. font-size: $font-size-28;
  403. line-height: 88rpx;
  404. color: #ffffff;
  405. margin: 0 auto;
  406. text-align: center;
  407. background: $btn-confirm;
  408. &.disabled {
  409. background: #e2e2e2;
  410. }
  411. }
  412. .login-text {
  413. width: 600rpx;
  414. height: 88rpx;
  415. font-size: $font-size-28;
  416. line-height: 88rpx;
  417. color: #333333;
  418. margin: 0 auto;
  419. text-align: center;
  420. }
  421. .login-tel {
  422. width: 702rpx;
  423. font-size: $font-size-28;
  424. line-height: 80rpx;
  425. margin: 0 auto;
  426. color: $text-color;
  427. text-align: center;
  428. margin-top: 150rpx;
  429. }
  430. .model-authorization {
  431. width: 100%;
  432. height: 100%;
  433. position: fixed;
  434. top: 0;
  435. left: 0;
  436. z-index: 999;
  437. .authorization {
  438. width: 518rpx;
  439. height: 320rpx;
  440. position: absolute;
  441. background: rgba(255, 255, 255, 0.7);
  442. left: 0;
  443. right: 0;
  444. bottom: 0;
  445. top: 0;
  446. margin: auto;
  447. .to-btn {
  448. position: absolute;
  449. top: 0;
  450. left: 0;
  451. right: 0;
  452. bottom: 0;
  453. margin: auto;
  454. width: 70%;
  455. height: 88rpx;
  456. font-size: $font-size-28;
  457. line-height: 88rpx;
  458. color: #ffffff;
  459. text-align: center;
  460. border-radius: 44rpx;
  461. }
  462. }
  463. }
  464. }
  465. </style>