login.vue 9.8 KB

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