login.vue 9.8 KB

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