|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- <template>
- <div class="app-container">
- <div class="focus-logo">
- <img src="@/assets/images/login-logo.png" />
- <p class="describe">登录页</p>
- </div>
-
- <div class="login-main">
- <ul class="head_nav clear">
- <li @click="isSmsLogin = false" :class="{ active: !isSmsLogin }">
- 账号登录
- </li>
- <li @click="isSmsLogin = true" :class="{ active: isSmsLogin }">
- 验证码登录
- </li>
- </ul>
-
- <div class="form_main">
- <van-form @submit="handleLogin">
- <div v-show="!isSmsLogin">
- <van-field
- v-model="formData.username"
- name="username"
- label="用户名"
- placeholder="用户名"
- />
- <van-field
- v-model="formData.password"
- type="password"
- name="password"
- label="密码"
- placeholder="密码"
- />
- <van-field
- v-model="formData.code"
- center
- clearable
- label="验证码"
- placeholder="图形验证码"
-
- >
- <template #button>
- <img class="code-img" :src="codeUrl" @click="getCode" />
- </template>
- </van-field>
- </div>
- <div v-show="isSmsLogin">
- <van-field
- v-model="formData.mobile"
- label="手机号"
- placeholder="请输入手机号码"
- />
- <van-field
- v-model="formData.smsCode"
- center
- clearable
- label="短信验证码"
- placeholder="请输入短信验证码"
- >
- <template #button>
- <van-button
- size="small"
- type="primary"
- @click.native.prevent="getSmsCode"
- >{{
- computeTime > 0 ? `(${computeTime}s)已发送` : "获取验证码"
- }}</van-button
- >
- </template>
- </van-field>
- </div>
- <div class="form-submit">
- <van-button
- round
- block
- type="info"
- native-type="submit"
- :loading="loading"
- >登录</van-button
- >
- </div>
- </van-form>
- </div>
- </div>
-
- <div class="reveal-modal-con">
- <div class="dd_txt">
- <router-link to="/register">注册账户</router-link>
- </div>
- <div class="other-login">
- <p class="desc">—— 更多登录方式 ——</p>
- <p class="icon-other-logins">
- <router-link class="wx" to="/"></router-link>
- <router-link class="rlsb" to="/"></router-link>
- </p>
- </div>
- </div>
- </div>
- </template>
-
- <script>
- import { getCodeImg, getSmsCode } from "@/api/login";
- import Cookies from "js-cookie";
- //引用wx sdk
- import wx from "weixin-js-sdk";
- export default {
- name: "login",
- data() {
- return {
- formData: {
- username: "admin", //账号
- password: "admin123", //密码
- // username:'',
- // password:'',
- code: null, //图片验证码
- uuid: null, //识别uuid
- mobile: null, //手机号
- smsCode: null, //短信验证码
- },
- loading: false,
- codeUrl: "", //验证码
- isSmsLogin: false, //是否手机验证码
- computeTime: 0,
- };
- },
- created() {
- this.getCode();
- //调用微信公众号方法
- // wx.config({
- // debug: true, // 开启调试模式,
- // appId: res.appId, // 必填,企业号的唯一标识,此处填写企业号corpid
- // timestamp: res.timestamp, // 必填,生成签名的时间戳
- // nonceStr: res.nonceStr, // 必填,生成签名的随机串
- // signature: res.signature,// 必填,签名,见附录1
- // jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
- // });
- //分享要用encodeURIComponent()方法
- },
- methods: {
- getCode() {
- getCodeImg().then((res) => {
- this.formData.uuid = res.uuid;
- this.codeUrl = "data:image/gif;base64," + res.img;
- });
- },
- getSmsCode() {
- if (!this.computeTime) {
- let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
- if (!myreg.test(this.formData.mobile)) {
- this.$dialog.alert({
- message: '手机号格式不正确',
- });
- return false;
- }
- getSmsCode(this.formData.mobile).then((res) => {
- if (res.code === 200) {
- this.$dialog.alert({
- message: '验证码已发送',
- });
- this.loginForm.uuid = res.uuid;
- this.computeTime = 60;
- this.timer = setInterval(() => {
- this.computeTime--;
- if (this.computeTime <= 0) {
- clearInterval(this.timer);
- }
- }, 1000);
- }
- });
- }
- },
- handleLogin(values) {
- if (this.isSmsLogin) {
- //短信登录
- let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
- if (!myreg.test(this.formData.mobile)) {
- this.$dialog.alert({
- message: '手机号格式不正确',
- });
- return false;
- } else if (this.formData.smsCode == "") {
- this.$dialog.alert({
- message: '短信验证码不能为空',
- });
- return false;
- }
- this.loading = true;
- this.$store
- .dispatch("SmsLogin", this.formData)
- .then(() => {
- this.$router.push({ path: this.redirect || "/" }).catch(() => {});
- })
- .catch(() => {
- this.loading = false;
- });
- } else {
- //账号密码登录
- if (this.formData.username == "") {
- this.$dialog.alert({
- message: '账号不能为空',
- });
- return false;
- } else if (this.formData.password == "") {
- this.$dialog.alert({
- message: '密码不能为空',
- });
- return false;
- } else if (this.formData.code == "") {
- this.$dialog.alert({
- message: '图片验证码不能为空',
- });
- return false;
- }
- this.$store
- .dispatch("Login", this.formData)
- .then(() => {
- this.$router.push({ path: this.redirect || "/" }).catch(() => {});
- })
- .catch(() => {
- this.loading = false;
- this.getCode();
- });
- }
- },
- },
- };
- </script>
-
- <!-- Add "scoped" attribute to limit CSS to this component only -->
- <style scoped lang="scss">
- .app-container {
- .focus-logo {
- width: 310px;
- margin: 0 auto 40px;
- padding-top: 60px;
- img {
- width: 100%;
- }
- .describe{
- text-align: center;
- font-size: 34px;
- padding:10px 0 0;
- color: #666;
- }
- }
-
- .login-main{
- width: 95%;
- margin: 0 auto;
- background: #fff;
- border-radius: 20px;
- overflow: hidden;
- border: 1px solid #ddd;
- padding-bottom:40px;
- }
- .head_nav {
- li {
- width: 50%;
- float: left;
- height: 90px;
- line-height: 90px;
- text-align: center;
- font-size: 30px;
- border-bottom: 2px solid #ddd;
- &.active {
- background: #fff;
- border-bottom: 2px solid #fff;
- color: #2386ee;
- }
- &:last-child {
- border-left: 2px solid #ddd;
- }
- }
- background: #f5f5f5;
- }
- .form_main {
- padding-top: 20px;
- .form-submit {
- margin: 40px 40px 0;
- }
- .code-img {
- width: 220px;
- }
- }
- .reveal-modal-con {
- margin: 30px 40px 0;
- .dd_txt {
- text-align: center;
- font-size: 28px;
- a {
- color: #666;
- }
- }
- .other-login {
- text-align: center;
- .desc {
- font-family: PingFangSC-Regular;
- font-size: 24px;
- color: #666;
- letter-spacing: 0;
- line-height: 30px;
- height: 30px;
- margin-top: 40px;
- opacity: 0.7;
- }
- .icon-other-logins {
- margin-top: 26px;
- a {
- &.wx {
- background-image: url("~@/assets/images/icon/wx.svg");
- }
- &.rlsb {
- background-image: url("~@/assets/images/icon/rlsb.svg");
- }
- position: relative;
- display: inline-block;
- margin: 0 12px;
- width: 60px;
- height: 60px;
- // border-radius: 50%;
- text-indent: -9999px;
- background-size: 100% 100%;
- background-repeat: no-repeat;
- background-position: left top;
- }
- }
- }
- }
- }
- </style>
|