login.vue 12 KB

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