zhouwx
2024-11-12 1e2bd6710762860f1735baef0f61be1d8edb2fe2
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
<template>
    <div class='bd'>
    <div class="hedaer">
      <h2>新疆维吾尔自治区自然灾害综合监测预警中心</h2>
      <h1>自然灾害综合风险预警发布及响应联动系统</h1>
    </div>
  <div class="login">
 
    <a-form-model
      layout="horizontal"
      :model="form"
      ref="ruleForm"
      :rules="rules"
      class="login-form"
    >
      <a-form-model-item ref="name" prop="name">
        <a-input
            placeholder="请输入用户名"
            size="large"
            v-model="form.name"
            autocomplete="new-password"
        >
          <a-icon slot="prefix" type="user" style="color:rgba(0,0,0,.25)" />
        </a-input>
      </a-form-model-item>
      <a-form-model-item ref="pwd" prop="pwd">
        <a-input-password
            type="password"
            placeholder="请输入密码"
            size="large"
            v-model="form.pwd"
            autocomplete="new-password"
        >
          <a-icon slot="prefix" type="lock" style="color:rgba(0,0,0,.25)" />
        </a-input-password>
      </a-form-model-item>
<!--      <a-tabs default-active-key="1" @change="callback">-->
<!--        <a-tab-pane key="1" tab="用户名登录">-->
<!--          <a-form-item>-->
<!--            <a-input-->
<!--              placeholder="请输入用户"-->
<!--              size="large"-->
<!--              v-model="form.name"-->
<!--            >-->
<!--              <a-icon slot="prefix" type="user" style="color:rgba(0,0,0,.25)" />-->
<!--            </a-input>-->
<!--          </a-form-item>-->
<!--          <a-form-item>-->
<!--            <a-input-password-->
<!--              type="password"-->
<!--              placeholder="请输入密码"-->
<!--              size="large"-->
<!--              v-model="form.pwd"-->
<!--            >-->
<!--              <a-icon slot="prefix" type="lock" style="color:rgba(0,0,0,.25)" />-->
<!--            </a-input-password>-->
<!--          </a-form-item>-->
<!--        </a-tab-pane>-->
<!--        <a-tab-pane key="2" tab="验证码登录" force-render>-->
<!--          <a-form-item>-->
<!--            <a-input-->
<!--              placeholder="手机号"-->
<!--              size="large"-->
<!--            >-->
<!--              <a-icon slot="prefix" type="mobile" style="color:rgba(0,0,0,.25)" />-->
<!--            </a-input>-->
<!--          </a-form-item>-->
<!--          <a-form-item>-->
<!--            <a-row :gutter="8">-->
<!--              <a-col :span="17">-->
<!--                <a-input placeholder="验证码">-->
<!--                  <a-icon slot="prefix" type="mobile" style="color:rgba(0,0,0,.25)" />-->
<!--                </a-input>-->
<!--              </a-col>-->
<!--              <a-col :span="7">-->
<!--                <a-button style="width: 100%">获取验证码</a-button>-->
<!--              </a-col>-->
<!--            </a-row>-->
<!--          </a-form-item>-->
<!--        </a-tab-pane>-->
<!--      </a-tabs>-->
      <div style="margin-bottom: 20px">
        <a-checkbox :checked="saveAccount" style="color:#fff;" @change="isSave">记住密码</a-checkbox>
<!--        <a style="float: right">忘记密码</a>-->
      </div>
      <div style="margin-bottom: 20px;height: auto;width: 100%;background-color: white;border-radius: 5px">
        <div style="margin-left: 10px;display: flex;align-items: center;justify-content: space-between;padding: 0px 12px;">
          <div v-if="keyMsg">
            <a-icon style="color: lightcoral" type="exclamation-circle"/>
            <span style="margin-left: 5px;line-height: 45px;font-size: 16px;color: lightcoral">{{keyMsg}}</span>
          </div>
          <div v-else>
            <a-icon style="color: #52c41a" type="check-circle"/>
            <span style="margin-left: 5px;line-height: 45px;font-size: 16px;color: #52c41a">加密证书检测成功</span>
          </div>
          <a-button
              type="primary"
              html-type="submit"
              style="width: 20%;"
              size="small"
              @click="checkKey"
          >
            重新检测
          </a-button>
        </div>
      </div>
      <div style="margin-bottom: 20px;float: right;" >
        <span style="color: #1890ff;cursor: pointer" @click="downLoadLKey">驱动下载</span>
      </div>
 
      <div style="text-align: center">
        <a-button
          type="primary"
          html-type="submit"
          style="width: 100%"
          size="large"
          @click="handleSubmit"
          :loading="isLoading"
          v-preventReClick="1500"
        >
          登录
        </a-button>
      </div>
      <center><p>技术支持:技术保障部</p></center>
    </a-form-model>
  </div>
  </div>
</template>
 
<script>
 
import { login, getMenuAdmin } from "@/api/login";
import Cookies from 'js-cookie';
import {Base64} from "js-base64";
import SoftKey3W from './Syunew3W.js'
 
export default {
  name: "login",
  data() {
    return {
      isLoading: false,
      saveAccount: false,
      // hasErrors,
      // form: this.$form.createForm(this),
      form: {
        name: '',
        pwd: '',
        keyId:'',//锁id
        keyUserName:'',//锁中的用户身份
        returnEncData:'',//签名数据
        rnd:"123"//随机字符
      },
      rules: {
        name: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
        pwd: [{ required: true, message: '请输入用户密码', trigger: 'blur' }]
      },
      menu: [],
      keyMsg: '未检测到加密证书,请确保已连接',
    };
  },
  created() {
    // this.$nextTick(() => {
    //   this.form.validateFields();
    // });
    this.hasUserCodeOrPassword()
    //检测key
    this.checkKey()
  },
  methods: {
    downLoadLKey () {
      console.log('222')
      const { href } = this.$router.resolve({
        path: '/downKey'
      })
      window.open(href,'_blank')
 
    },
    hasUserCodeOrPassword(){
      if (localStorage.getItem('userName') && localStorage.getItem('userPassword')) {
        this.form.name = localStorage.getItem('userName')
        this.form.pwd = Base64.decode(localStorage.getItem('userPassword'))//解密
        this.saveAccount = true
      }
    },
    async checkKey() {
      let mSoftKey3A = new SoftKey3W();//注意,由于USB的操作是异步的,所以所有函数的调用前必须加await !!!!!!!!!
      let DevicePath = await mSoftKey3A.FindPort(1);//'查找是否存在多把加密锁
      if (mSoftKey3A.GetLastError() == 0) {
        this.keyMsg = "系统发现有2把及以上的加密证书"
        return false
      }
      DevicePath = await mSoftKey3A.FindPort(0);//'查找是否存在加密锁
      if (mSoftKey3A.GetLastError() != 0) {
        this.keyMsg = "未检测到加密证书,请确保已连接"
        return false
      }
      this.keyMsg = ""
    },
 
    isSave(e){
      const t = this
      t.saveAccount = !t.saveAccount
    },
    async checkUsbkeyData(){
      let mSoftKey3A = new SoftKey3W();//注意,由于USB的操作是异步的,所以所有函数的调用前必须加await !!!!!!!!!
      let DevicePath = await mSoftKey3A.FindPort(1);//'查找是否存在多把加密锁
      console.log(mSoftKey3A,'mSoftKey3A')
      if (mSoftKey3A.GetLastError() == 0) {
        this.keyMsg = "系统发现有2把及以上的加密证书"
        this.$message.warning( "系统发现有2把及以上的加密证书");
        return false
      }
      DevicePath = await mSoftKey3A.FindPort(0);//'查找是否存在加密锁
      if (mSoftKey3A.GetLastError() != 0) {
        this.keyMsg = "未检测到加密证书,请确保已连接"
        this.$message.warning( "未检测到加密证书,请确保已连接");
        return false
      }
      console.log(DevicePath,'devpathhh')
      //'读取锁的唯一ID
      this.form.keyId=await mSoftKey3A.GetChipID(DevicePath);
 
      if( mSoftKey3A.GetLastError()!= 0 )
      {
          this.$message.warning("返回芯片唯一ID时出现错误,错误码为:"+mSoftKey3A.GetLastError().toString())
          return false
      }
      console.log(this.form.keyId,'this.form.keyId')
      //从锁中取出用户身份,与签名后的数据一并送到服务端进行验证。以验证用户身份
      this.form.keyUserName=await mSoftKey3A.GetSm2UserName(DevicePath);
 
      if( mSoftKey3A.GetLastError()!= 0 )
      {
        this.$message.warning( "返回用户身份时出现错误,错误码为:"+mSoftKey3A.GetLastError().toString());
        return false
      }
      console.log(this.form.keyUserName,'this.form.keyUserName')
      //使用默认的PIN码
      var Pin="123"
      //这里使用锁中的私钥对身份-用户名及消息-随机数的进行数字签名,使用默认的PIN码,返回签名后的数据
      this.form.rnd=String(parseInt(Math.random()*(65536+1),10));
      this.form.returnEncData=await mSoftKey3A.YtSign(this.form.rnd,Pin,DevicePath);
      if( mSoftKey3A.GetLastError()!= 0 )
      {
        this.$message.warning( "进行签名时出现错误,错误码为:"+mSoftKey3A.GetLastError().toString());
          return false
      }
      if(this.form.name!=this.form.keyUserName){
        this.$message.warning( "用户身份不一致,无法登陆");
        return false
      }
      console.log(this.form.returnEncData,'this.form.returnEncData')
      console.log(this.form,'this.form')
      return true
    },
 
    async handleSubmit() {
      this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          let checkUsb=await this.checkUsbkeyData()
          if(!checkUsb){
            return
          }
          this.isLoading = true
          const res = await login(this.form)
          if (res.data.code === 100) {
            Cookies.set('resTk', res.data.data.tk);
            Cookies.set('resUid', res.data.data.uid);
            Cookies.set('userInfo',JSON.stringify(res.data.data),{expires: 7})
            if (this.saveAccount) {
              localStorage.setItem('userName', this.form.name)
              localStorage.setItem('userPassword', Base64.encode(this.form.pwd))
            } else {
              localStorage.removeItem('userName')
              localStorage.removeItem('userPassword')
            }
            this.$router.push('/home')
          } else {
            this.$message.warning(res.data.msg);
          }
          this.isLoading = false
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
 
  },
};
</script>
 
<style lang="less" scoped>
    p{
        color:#fff;
        margin-top: 55px;
    }
h2{
    font-size: 30px;
}
.bd {
    width: 100%;
    height: 100vh;
    background: url('../assets/img/bg.jpeg') no-repeat;
    background-size: 100% 100%;
    background-attachment: fixed;/* 不设置的话页面滑动时,背景会不铺满*/
}
 
 
/deep/ .ant-tabs-bar {
  border-bottom: 0px;
  text-align: center;
}
  .hedaer {
    margin: 0px auto;
    padding-top:200px;
    width: 1000px;
    text-align: center;
    text-shadow:0 0 1px #000;
    h2{font-size: 36px;color:#fff;}
    h1{font-size: 48px;color:#fff;}
    }
.login {
 
  .login-form {
    width: 400px;
    margin: 60px auto 0px;
 
  }
}
.ant-tabs{
    color:#fff;
    }
</style>