login.vue 10 KB

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