zhaoxiaoqiang
2022-08-03 aaf84674b918d2683ea93b317316c72031017f24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<!--
 * @Author: 小明丶
 * @Date: 2019-08-15 10:20:56
 * @LastEditors: zxq
 * @LastEditTime: 2022-06-16 11:34:10
 * @Description: 登录页面
 -->
<template>
  <div class="login-page">
    <div class="logo-box">
      <div class="logo-img-box">
        <img src="../../../static/img/logo.png" alt="logo" class="logo-pic" />
      </div>
      <p>爱享学</p>
    </div>
    <h-ipt
      icon="iconxingming"
      :maxlength="11"
      type="text"
      :getClose="true"
      v-model="mblNo"
      placeholder="请输入手机号"
      class="myipt"
    ></h-ipt>
    <h-ipt icon="iconmima" :maxlength="6" v-model="verCode" placeholder="请输入短信验证码" class="myiptTwo">
      <template slot="right">
        <div>
          <button
            class="getcode"
            :disabled="btnDis"
            :style="btnDis?'color:#E6E6E6':'color:#62A0FF'"
            @click="sendCode"
          >{{btnText}}</button>
        </div>
      </template>
    </h-ipt>
    <div class="text-box">
      <van-checkbox v-model="checked" shape="round" icon-size="16px">
        <template #default>
          <p class="xieyi">
            <span>我已阅读并同意</span>
            <span @click.stop="showAgree(1)">《隐私政策》</span>
            <span @click.stop="showAgree(2)">《用户注册服务协议》</span>
          </p>
        </template>
      </van-checkbox>
    </div>
    <div class="btn-box">
      <button @click="loginBut">登录</button>
    </div>
    <!-- <div class="idcard-box">
      <upLoadIdCard :cardBack="idCardMation.idBackUrl" :cardFont="idCardMation.idFrontUrl"></upLoadIdCard>
    </div> -->
  </div>
</template>
 
<script>
import { mapActions } from "vuex";
import Vue from "vue";
import { RadioGroup, Radio } from "vant";
import { Checkbox, CheckboxGroup } from "vant";
import { Popup } from "vant";
import { Icon } from "vant";
Vue.use(Icon);
Vue.use(Popup);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Radio);
Vue.use(RadioGroup);
 
export default {
  data() {
    return {
      checked: false, //协议勾选
      radio: "",
      //数据
      // 18108048791 1234qwer
      mblNo: "", //用户手机号
      verCode: "", //验证码
      openId: 456, //微信openId
      //点击显示密码为明文,眼睛的样式也是根据这个来判断的
      pwdType: "password",
      test: false,
      loginImg: "static/img/logo.png",
      timer: "",
      showSend: true,
      btnText: "发送验证码",
      btnDis: false,
      miao: 60,
      code: "",
      ShowAgreen: false, //协议展示框
      Agreend: "", //协议
    };
  },
  created() {
    // 存储倒计时
    if(this.$route.query.whichPage && sessionStorage.beforeDate){
      this.miao = Math.round(new Date().getTime()/1000 - sessionStorage.beforeDate/1000)
      if(this.miao < 60){
        this.getSecond(60 - this.miao)
      }else{
        this.miao = 60
      }
    }
    if(sessionStorage.mblNo){
      this.mblNo = sessionStorage.mblNo
    }
    if(sessionStorage.verCode){
      this.verCode = sessionStorage.verCode
    }
   
    this.code = this.getUrlCode("code");
    console.log('this.code:',this.code)
    console.log('this.$route.query.whichPage:',this.$route.query.whichPage)
    if (this.code && !this.$route.query.whichPage) {
      this.$api.wechatUserInfo({ code: this.code}).then(res => {
          console.log('res.body.openid:',res.body.openid)
          localStorage.edu_ins_client_openId = res.body.openid;
          localStorage.edu_ins_client_userMation = JSON.stringify(res.body);
      });
    }
  },
  methods: {
    ...mapActions(["login", "getVercode", "openIdLogin"]),
    //截取code值
    getUrlCode(name) {
      return (
        decodeURIComponent(
          (new RegExp("[?|&]" + name + "=" + "([^&;]+?)(&|#|;|$)").exec(
            location.href
          ) || [, ""])[1].replace(/\+/g, "%20")
        ) || null
      );
    },
    //登录验证
    loginBut() {
      let v = this.$tool;
      if (v.checkValEmpty(this.mblNo)) {
        v.toast("请输入手机号");
        return;
      }
      if (!v.checkPhone(this.mblNo)) {
        v.toast("请输入正确手机号");
        return;
      }
      if (v.checkValEmpty(this.verCode)) {
        v.toast("请输入验证码");
        return;
      }
      if (!this.checked) {
        v.toast("请确认并勾选用户协议");
        return;
      }
      this.login({
        vm: this,
        mblNo: this.mblNo,
        verCode: this.verCode,
        openId: localStorage.edu_ins_client_openId
      });
    },
    sendCode() {
      let v = this.$tool;
      if (v.checkValEmpty(this.mblNo)) {
        v.toast("请输入手机号");
        return;
      }
      if (!v.checkPhone(this.mblNo)) {
        v.toast("请输入正确手机号");
        return;
      }
      this.$api.getVerCode({
        mblNo: this.mblNo,
        verCodeType: 1
      }).then(res=>{
        sessionStorage.beforeDate = new Date().getTime()
        this.getSecond(60);
      })
      // this.$store.dispatch("getVercode", {
      //   vm: this,
      //   mblNo: this.mblNo,
      //   verCodeType: 1
      // });
     
    },
    //发送验证码计时函数
    getSecond(wait) {
      let _this = this;
      let _wait = wait;
      if (wait == 0) {
        this.btnText = "获取验证码";
        wait = _wait;
        this.btnDis = false;
        clearTimeout(this.timer)
      } else {
        this.btnDis = true;
        this.btnText = "验证码(" + wait + "s)";
        wait--;
        this.timer = setTimeout(function() {
          _this.getSecond(wait);
        }, 1000);
      }
    },
    // 展示协议
    showAgree(which) {
      sessionStorage.mblNo = this.mblNo
      sessionStorage.verCode = this.verCode
      if(which == 1){
        this.$router.push({
          path:'/agreement',
          query:{
            from:'login',
            tit:'隐私协议',
            agrUrl:'./static/ys.pdf'
          }
        })
      }
      if(which == 2){
        this.$router.push({
          path:'/agreement',
          query:{
            from:'login',
            tit:'用户注册服务协议',
            agrUrl:'./static/zc.pdf'
          }
        })
      }
    },
  },
  
  beforeRouteLeave (to, from, next) {
    // ...
    
    clearTimeout(this.timer)
    next()
  }
};
</script>
<style lang="less" scoped>
.login-page {
  padding-top: 42px;
  box-sizing: border-box;
  .logo-box {
    & {
      text-align: center;
      font-size: 18px;
      margin-bottom: 30px;
    }
    img {
      width: 55px;
      height: 83px;
    }
    .logo-img-box {
      display: inline-block;
      width: 100px;
      height: 100px;
      background: rgba(255, 255, 255, 1);
      box-shadow: 0px 0px 12px 0px rgba(34, 105, 209, 0.2);
      border-radius: 15px;
      box-sizing: border-box;
      padding-top: 11px;
    }
    p {
      margin-top: 16px;
      font-size: 17px;
      font-family: PingFang SC;
      font-weight: 500;
      color: rgba(51, 51, 51, 1);
    }
  }
  .myipt {
    margin-top: 51px;
  }
  .myiptTwo {
    margin-top: 20px;
    margin-bottom: 17px;
  }
  .getcode {
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 500;
    text-decoration: underline;
    color: rgba(98, 160, 255, 1);
    outline: none;
    height: 30px;
    border: 0;
    background: #fff;
  }
  .text-box {
    & {
      width: 100%;
      padding: 0 10%;
      box-sizing: border-box;
    }
    .xieyi {
      span:nth-of-type(1) {
        font-size: 12px;
        font-family: PingFang SC;
        font-weight: 500;
        color: rgba(153, 153, 153, 1);
      }
      span:nth-of-type(2) {
        font-size: 12px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #5194fe;
      }
      span:nth-of-type(3) {
        font-size: 12px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #5194fe;
      }
    }
  }
  .btn-box {
    & {
      width: 100%;
      text-align: center;
      margin-top: 37px;
    }
    button {
      width: 80%;
      height: 44px;
      background: linear-gradient(
        90deg,
        rgba(82, 142, 255, 1),
        rgba(105, 167, 255, 1)
      );
      box-shadow: 0px 8px 15px 0px rgba(91, 152, 255, 0.28);
      border-radius: 22px;
      outline: none;
      border: 0;
      color: #fff;
    }
  }
  .agreenBox {
    width: 80vw;
    height: 70vh;
    padding: 60px 20px 30px 20px;
    position: relative;
  }
 
  .agreen-html {
    width: 100%;
    height: 100%;
    overflow: scroll;
    box-sizing: border-box;
  }
 
  .close-agreen {
    .lh(30px);
    .flex(center, center);
 
    .van-icon {
      font-size: @font-16;
    }
  }
}
</style>