login.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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="30"
  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="text"
  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 _storage = await this.$api.getStorage()
  204. this.accountParams.unionId = this.codeParams.unionId = _storage.unionId ? _storage.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. this.$api.switchTabTo('/pages/tabBar/user/user')
  236. } else {
  237. this.$util.msg(data.msg, 2000)
  238. }
  239. },
  240. navigatorRegirst(url) {
  241. this.$api.navigateTo(url)
  242. },
  243. handeleLogin(type) {
  244. this.loginType = type
  245. },
  246. async checkedAuthorize() {
  247. //是否已授权 0:为取消授权 1:为已授权 2:为未操作
  248. // wxLogin.wxLoginQuick()
  249. }
  250. },
  251. onShow() {
  252. this.infoClucbUser()
  253. }
  254. }
  255. </script>
  256. <style lang="scss">
  257. .login {
  258. width: 100%;
  259. height: auto;
  260. .model-warp.none {
  261. display: none;
  262. }
  263. .model-warp.show {
  264. display: block;
  265. }
  266. .login-main {
  267. width: 100%;
  268. display: flex;
  269. flex-direction: column;
  270. align-items: center;
  271. height: 206rpx;
  272. padding: 60rpx 0 40rpx 0;
  273. margin-bottom: 70rpx;
  274. .logo {
  275. width: 358rpx;
  276. height: 206rpx;
  277. display: block;
  278. }
  279. }
  280. .login-input {
  281. width: 600rpx;
  282. height: 88rpx;
  283. padding: 24rpx 0;
  284. margin: 0 auto;
  285. margin-bottom: 30rpx;
  286. background: #ffffff;
  287. position: relative;
  288. box-sizing: border-box;
  289. border-bottom: 1px solid #e1e1e1;
  290. .input {
  291. width: 100%;
  292. height: 100%;
  293. background: #ffffff;
  294. font-size: $font-size-28;
  295. line-height: 88rpx;
  296. color: #333333;
  297. padding-left: 100rpx;
  298. box-sizing: border-box;
  299. &.code {
  300. padding-right: 200rpx;
  301. }
  302. }
  303. .code-btn {
  304. width: 180rpx;
  305. height: 64rpx;
  306. position: absolute;
  307. right: 0;
  308. top: 10rpx;
  309. line-height: 64rpx;
  310. text-align: center;
  311. color: #FFFFFF;
  312. font-size: $font-size-24;
  313. border-radius: 32rpx;
  314. background: $btn-confirm;
  315. &.disabled{
  316. background: #E1E1E1;
  317. }
  318. }
  319. .iconfont {
  320. position: absolute;
  321. left: 0;
  322. top: 0;
  323. font-size: 48rpx;
  324. color: #333333;
  325. width: 100rpx;
  326. height: 88rpx;
  327. line-height: 88rpx;
  328. text-align: left;
  329. }
  330. &.link {
  331. background: #ffffff;
  332. margin-bottom: 40rpx;
  333. padding: 0 0;
  334. line-height: 40rpx;
  335. font-size: $font-size-24;
  336. border-bottom: none;
  337. .login-reg {
  338. float: left;
  339. color: $color-system;
  340. }
  341. .login-pwd {
  342. float: right;
  343. color: $text-color;
  344. }
  345. }
  346. }
  347. .login-btn {
  348. width: 600rpx;
  349. height: 88rpx;
  350. border-radius: 44rpx;
  351. font-size: $font-size-28;
  352. line-height: 88rpx;
  353. color: #ffffff;
  354. margin: 0 auto;
  355. text-align: center;
  356. background: $btn-confirm;
  357. &.disabled {
  358. background: #e2e2e2;
  359. }
  360. }
  361. .login-text {
  362. width: 600rpx;
  363. height: 88rpx;
  364. font-size: $font-size-28;
  365. line-height: 88rpx;
  366. color: #333333;
  367. margin: 0 auto;
  368. text-align: center;
  369. }
  370. .login-tel {
  371. width: 702rpx;
  372. font-size: $font-size-28;
  373. line-height: 80rpx;
  374. margin: 0 auto;
  375. color: $text-color;
  376. text-align: center;
  377. margin-top: 150rpx;
  378. }
  379. .model-authorization {
  380. width: 100%;
  381. height: 100%;
  382. position: fixed;
  383. top: 0;
  384. left: 0;
  385. z-index: 999;
  386. .authorization {
  387. width: 518rpx;
  388. height: 320rpx;
  389. position: absolute;
  390. background: rgba(255, 255, 255, 0.7);
  391. left: 0;
  392. right: 0;
  393. bottom: 0;
  394. top: 0;
  395. margin: auto;
  396. .to-btn {
  397. position: absolute;
  398. top: 0;
  399. left: 0;
  400. right: 0;
  401. bottom: 0;
  402. margin: auto;
  403. width: 70%;
  404. height: 88rpx;
  405. font-size: $font-size-28;
  406. line-height: 88rpx;
  407. color: #ffffff;
  408. text-align: center;
  409. border-radius: 44rpx;
  410. }
  411. }
  412. }
  413. }
  414. </style>