2023西安数博会CIM演示-【前端】-Web
AdaKing88
2023-08-21 bc03b832caa49bbcd2674fe4cae3701b5059bf95
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
<!--
 * @Author: LuLu
 * @Date: 2023-05-23 14:24:10
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2023-07-09 13:53:14
 * @FilePath: \cim-xian\src\views\login\Login0.vue
 * @Description: 登录页
-->
 
<template>
  <div class="box">
    <video src="@/assets/videos/earth_mp4.mp4" class="video_back" autoplay loop muted></video>
    <!-- <img src="@/assets/images/矩形693拷贝3.png" width="554px" height="109px" class="top_title"> -->
    <div class="title">{{ appname }}</div>
    <div class="login_form">
 
      <el-form :model="loginForm" :rules="fieldRules" ref="loginForm" label-position="left" label-width="0px"
        class="login-container">
        <el-form-item prop="username">
          <el-input class="form_input" style="top: 148px;" type="text" v-model="loginForm.username" auto-complete="off"
            placeholder="账号">
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input class="form_input" style="top: 216px;" type="password" v-model="loginForm.password"
            auto-complete="off" placeholder="密码">
          </el-input>
        </el-form-item>
        <el-form-item prop="captcha">
          <el-input class="form_input" style="top: 284px;" type="text" v-model="loginForm.captcha" auto-complete="off"
            placeholder="验证码, 单击图片刷新">
          </el-input>
          <canvas id="c1" width="100" height="30" class="form_captcha" @click="draw(showNum)"></canvas>
        </el-form-item>
      </el-form>
 
      <div class="login_btn" @click.prevent="handleLogin">
        <div id="loading" class="donut" v-show="loading"></div>
        登&nbsp;&nbsp;录
      </div>
 
 
      <span class="form_prop" style="top: 125px;">用户名</span>
      <span class="form_prop" style="top: 215px;">密&nbsp;&nbsp;&nbsp;码</span>
      <span class="form_prop" style="top: 305px;">验证码</span>
 
 
 
    </div>
 
 
  </div>
</template>
 
<script>
import { mapActions } from "vuex";
export default {
  name: "Login",
  components: {
 
  },
  data() {
    return {
      appname:APP_NAME,
      loading: false,
      loginForm: {
        username: "admin",
        password: "admin",
        captcha: "",
      },
      fieldRules: {
        username: [{ required: true, message: " ", trigger: "blur" }],
        password: [{ required: true, message: " ", trigger: "blur" }],
        captcha: [{ required: true, message: " ", trigger: "blur" }],
      },
      checked: true,
      showNum: []
    };
  },
  methods: {
 
    //   获取vuex中Actions里的方法
    ...mapActions(["login", "GetInfo"]),
    handleLogin() {
      this.loading = true;
      let code = this.showNum.join("")
      if (code == this.loginForm.captcha) {
        
        this.$refs.loginForm.validate((valid) => {
          if (valid) {
            this.login(this.loginForm)
              .then(() => {
                this.loading = false;
                this.GetInfo().then(() => {
                });
                this.$router.push("/xianCim");
              })
              .catch(() => {
                this.$message({
                  message: "账号不存在或密码输入错误!",
                  type: "error",
                  duration: 4000,
                });
 
                this.loading = false;
              });
          } else {
            console.log("error submit!!");
            this.$message({
              message: "账号不存在或密码输入错误!",
              type: "error",
              duration: 4000,
            });
            this.loading = false;
            return false;
          }
        });
      } else {
        this.$message({
          message: "验证码错误",
          type: "warning",
          duration: 4000,
        });
        this.loading = true;
        return
      }
 
 
    },
    // 封装一个把随机验证码放在画布上
    draw(showNum) {
      // 获取canvas
      var canvas = $("#c1")
      var ctx = canvas[0].getContext("2d")
      // 获取画布的宽高
      var canvas_width = canvas.width()
      var canvas_height = canvas.height()
      //  清空之前绘制的内容
      // 0,0清空的起始坐标
      // 矩形的宽高
      ctx.clearRect(0, 0, canvas_width, canvas_height)
      // 开始绘制
      // var scode = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,"
      var scode = "1,2,3,4,5,6,7,8,9"
      var arrCode = scode.split(",")
      var arrLength = arrCode.length
      for (var i = 0; i < 4; i++) {
        var index = Math.floor(Math.random() * arrCode.length)
        var txt = arrCode[index]//随机一个字符
        showNum[i] = txt.toLowerCase()//转化为小写存入验证码数组
        // 开始控制字符的绘制位置
        var x = 10 + 20 * i //每一个验证码绘制的起始点x坐标
        var y = 20 + Math.random() * 8// 起始点y坐标
 
        ctx.font = "bold 20px 微软雅黑"
        // 开始旋转字符
        var deg = Math.random * -0.5
        // canvas 要实现绘制内容具有倾斜的效果,必须先平移,目的是把旋转点移动到绘制内容的地方
        ctx.translate(x, y)
        ctx.rotate(deg)
        // 设置绘制的随机颜色
        ctx.fillStyle = this.randomColor()
        ctx.fillText(txt, 0, 0)
 
        // 把canvas复原
        ctx.rotate(-deg)
        ctx.translate(-x, -y)
 
      }
      for (var i = 0; i < 30; i++) {
        if (i < 5) {
          // 绘制线
          ctx.strokeStyle = this.randomColor()
          ctx.beginPath()
          ctx.moveTo(Math.random() * canvas_width, Math.random() * canvas_height)
          ctx.lineTo(Math.random() * canvas_width, Math.random() * canvas_height)
          ctx.stroke()
        }
        // 绘制点
        ctx.strokeStyle = this.randomColor()
        ctx.beginPath()
        var x = Math.random() * canvas_width
        var y = Math.random() * canvas_height
        ctx.moveTo(x, y)
        ctx.lineTo(x + 1, y + 1)
        ctx.stroke()
 
      }
 
 
    },
 
    // 随机颜色
    randomColor() {
      var r = Math.floor(Math.random() * 256)
      var g = Math.floor(Math.random() * 256)
      var b = Math.floor(Math.random() * 256)
      return `rgb(${r},${g},${b})`
 
    }
  },
  mounted() {
    this.draw(this.showNum)
  },
  computed: {},
};
</script>
<style>
@Keyframes donut-spin {
        0% {
            transform: rotate(0deg);
        }
 
        100% {
            transform: rotate(360deg);
        }
    }
 
  .donut {
    display: inline-block;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: #21d2ff54;
    border-radius: 50%;
    width: 15px;
    height: 15px;
    margin-right: 15px;
    animation: donut-spin 1.2s linear infinite;
}
</style>
<style lang="less" scoped>
 
 
 
    
 
.box {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
 
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
 
  .video_back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    object-fit: cover;
  }
 
  .top_title {
    position: absolute;
    top: 40px;
    z-index: 2;
  }
 
  .title {
    position: absolute;
    top: 60px;
    text-align: center;
    font-size: 46px;
    font-weight: bold;
    color: #f0fafe;
    text-shadow: 0px 0px 79px #00a6e2;
    background: linear-gradient(0deg, #46aef7 0%, #1dd5e6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    z-index: 2;
    }
 
  .login_form {
    position: relative;
    width: 492px;
    height: 516px;
    background-image: url("~@/assets/images/login_form.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    z-index: 2;
    display: flex;
    flex-direction: column;
 
 
    .form_prop {
      position: absolute;
      margin-left: 91px;
      opacity: 0.76;
      font-size: 14px;
      font-weight: 400;
      color: #e6efff;
      letter-spacing: 1.05px;
    }
 
    .form_input {
      position: absolute !important;
      width: 270px !important;
      height: 40px;
      background-color: rgba(0, 0, 0, 0);
      margin-left: 137px;
    }
 
    .form_captcha {
      position: absolute;
      left: 299px;
      top: 287px;
    }
 
    .login_btn {
      position: absolute;
      width: 326px;
      height: 41px;
      top: 399px;
      align-self: center;
 
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;
 
      font-size: 18px;
      font-family: Source Han Sans CN, Source Han Sans CN-Medium;
      font-weight: 500;
      text-align: center;
      color: #e8eff4;
      letter-spacing: 2.7px;
 
      cursor: pointer;
    }
  }
}
 
/deep/.el-input__inner {
  position: absolute;
  background-color: rgba(0, 0, 0, 0) !important;
  color: #e6f6ff;
  border: none
}
</style>