companyLogin.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view class="pages">
  3. <image :src="$getimg+'logo.png'" class="logo" mode="widthFix"></image>
  4. <view class="title">企业用户登陆</view>
  5. <view class="login-form">
  6. <view class="login-form-item">
  7. <view class="login-form-item-til">账号</view>
  8. <view class="login-form-item-con">
  9. <input type="text" value="" v-model="params.loginStr" placeholder="请输入账号" />
  10. </view>
  11. </view>
  12. <view class="login-form-item">
  13. <view class="login-form-item-til">密码</view>
  14. <view class="login-form-item-con">
  15. <input type="password" value="" v-model="params.pwd" placeholder="请输入密码" />
  16. </view>
  17. </view>
  18. </view>
  19. <view class="wrap">
  20. <view class="full-btn" @click="handleLogin">登录</view>
  21. </view>
  22. <view class="bottom-btn-wrap">
  23. <view class="bottom-btn forgetpass">忘记密码</view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import { mapState, mapMutations } from 'vuex';
  29. export default {
  30. data() {
  31. return {
  32. $getimg:this.$getimg,
  33. params:{
  34. // loginStr:'66432356',
  35. loginStr:'64676376',
  36. pwd:'123456',
  37. },
  38. rules: {
  39. loginStr: {rule: /^[A-Za-z0-9]+$/,msg: "填写用户名"},
  40. pwd: {rule: /\S/,msg: "填写密码"},
  41. },
  42. }
  43. },
  44. onShow() {
  45. },
  46. onLoad() {
  47. },
  48. computed: mapState(['hasLogin', 'userInfo','hPage']),
  49. methods: {
  50. ...mapMutations(['login', 'logout','upInfo']),
  51. handleLogin(){
  52. console.log('params',this.params);
  53. for (let x in this.params) {
  54. // console.log('x',x)
  55. if(!this.validate(x)) return;
  56. }
  57. this.$api.http.post(this.config.apiBaseurl + '/carbon-h5/wap/customer/customerLogin',this.params,{
  58. // header: {
  59. // Accept:'application/json',
  60. // Authorization: 'Bearer '+ this.token, //注意Bearer后面有一空格
  61. // },
  62. }).then(res => {
  63. // console.log('res.data.retBody.token',res.data.retBody)
  64. const token = res.data.retBody;
  65. //保存token
  66. // console.log('this.login',this.login);
  67. this.login(token);
  68. //取得用户信息
  69. this.upInfo();
  70. uni.switchTab({
  71. url: '/pages/index/index'
  72. });
  73. }).catch(err =>{
  74. console.log('err',err)
  75. });
  76. },
  77. //判断验证是否符合要求
  78. validate(key) {
  79. let bool = true;
  80. if (!this.rules[key].rule.test(this.params[key])) {
  81. //提示信息
  82. uni.showToast({
  83. icon:"none",
  84. title: this.rules[key].msg,
  85. })
  86. //取反
  87. bool = false;
  88. return false;
  89. }
  90. return bool;
  91. },
  92. }
  93. }
  94. </script>
  95. <style scoped>
  96. /* @import url("./index.css"); */
  97. .logo{display: block;margin: 128rpx auto 26rpx;width: 99rpx;height: 99rpx;}
  98. .title{margin-bottom: 80rpx;font-size: 36rpx;color: #333;line-height: 50rpx;font-weight: bold;text-align: center;}
  99. .login-form{margin-bottom: 40rpx;border-top: 1px solid #eee;border-bottom: 1px solid #eee;}
  100. .login-form-item{display: flex;position: relative;height: 96rpx;align-items: center;border-bottom: 1px solid #eee;}
  101. .login-form-item::before{content: '';width: 24rpx;height: 1px;background-color: #fff;position: absolute;left: 0;bottom: -1px;}
  102. .login-form .login-form-item:last-of-type{border-bottom: 0;}
  103. .login-form .login-form-item:last-of-type::before{height: 0;}
  104. .login-form-item-til{margin-left: 24rpx;padding-left: 16rpx;}
  105. .login-form-item-con{padding-left: 100rpx;}
  106. .forgetpass{font-size: 30rpx;color: #999;}
  107. </style>