login.vue 12 KB

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