login.vue 9.8 KB

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