lyfO_o
2022-10-26 3c0a5d95d84c7321227f9252475ccb8ce4b07e1b
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<template>
  <div class="login-container">
    <div v-title :data-title="titleName" class="main"/>
 
        <div class="left-container">
            <div class="login_title"></div>
            <div v-if="action==='login'" class="login-component">
                <login-form
                  @on-success-valid="handleLogin"
                  ref="getdata"
                />
            </div>
        </div>
      <div class="bottom-container">
        <span class="bottom-container_title">中国科学院苏州纳米技术与纳米仿生研究所监制</span>
      </div>
  </div>
</template>
 
<script>
import { loginByUsername } from '@/api/login'
import { checkcheck } from '@/api/enterprise'
import { getToken, setToken, removeToken } from '@/utils/auth'
import Cookies from 'js-cookie'
import { initRouter } from '@/utils/router'
 
import { parseError } from '@/utils/messageDialog'
import { createUser } from '@/api/user'
import LoginForm from './components/login-form'
import Vue from 'vue'
export default {
  name: 'Login',
  components: { LoginForm },
  data() {
    return {
      websocket:'',
      url:process.env.BASE_API.replace("http","ws").replace("https","wss"),
      action: 'login',
      screenWidth: '',
      screenHeight: '',
      logincontainer: 'login-container',
      isSafe: process.env.isSafe,
      titleName: '新疆维吾尔自治区烟花爆竹流向管理信息实名登记系统',
      safeLoginTitle: '新疆维吾尔自治区烟花爆竹流向管理信息实名登记系统'
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  created() {
    // window.addEventListener('hashchange', this.afterQRScan)
    this.screenWidth = window.innerWidth
    this.screenHeight = window.innerHeight
    this.setSize()
    window.onresize = () => {
      this.screenWidth = window.innerWidth
      this.screenHeight = window.innerHeight
      this.setSize()
    }
  },
  destroyed() {
    // window.removeEventListener('hashchange', this.afterQRScan)
  },
  methods: {
    setSize: function() {
      if (this.screenWidth <= 1200) {
        this.logincontainer = 'login-container-1'
      } else {
        this.logincontainer = 'login-container'
      }
    },
    handleLogin(loginForm) {
      const _this = this
      _this.$refs.getdata.submitLoading = false
      _this.loading = true
      loginByUsername(loginForm)
        .then((response) => {
          const res = response.data
          _this.$refs.getdata.submitLoading = false
          if (res.code == 200) {
            _this.loading = false
            const data = res.result
            if (data.type != 1 && data.type != 2) {
              if (!data.roles || data.roles.length == 0) {
                // 验证返回的roles是否是一个非空数组
                _this.$store.commit('SET_ROLES', [])
                parseError({
                  error: '该用户没有权限登录,请联系所配置管理员分配角色',
                  vm: _this
                })
                // reject('用户未分配角色,没有权限登录')
                return
              }
            }
            this._initConnect(data.id)
            _this.$store.commit('SET_ROLES', data.roles)
            Cookies.set('roles', JSON.stringify(data.roles))
            setToken(data.token)
            Cookies.set('roleType',data.roleType)
            Cookies.set('isSupervision',data.companyid)
            Cookies.set('company',data.company)
            Cookies.set('userName', data.username)
            Cookies.set('name', data.username)
            Cookies.set('userId', data.id)
            Cookies.set('token_expired_at', data.tokenexpired)
            _this.$store.commit('SET_NAME', data.username)
            _this.$store.commit('SET_USER_TYPE', data.type)
            // 加载菜单
            initRouter(_this)
           _this.$router.replace('/enterprise/basic')
          } else {
            _this.$message({
              showClose: true,
              message: res.message,
              type: 'error'
            })
            _this.loading = false
          }
        })
        .catch((error) => {
          _this.loading = false
          _this.$refs.getdata.submitLoading = false
          _this.$alert({
            confirmButtonText: '确认',
            showClose: true,
            message: error,
            type: 'error'
          })
        })
    },
    handleChangeToLogin() {
      this.action = 'login'
    },
    async _initConnect(uid){
      if ('WebSocket' in window) {
        this.websocket = new WebSocket(this.url+'/push/' + uid)
        this.initWebSocket()
      } else {
        alert('当前浏览器 不支持')
      }
    },
    initWebSocket(){
      // 连接错误
      this.websocket.onerror = this.setErrorMessage
 
      // 连接成功
      this.websocket.onopen = this.setOnopenMessage
 
      // 收到消息的回调
      this.websocket.onmessage = this.setOnmessageMessage
 
      // 连接关闭的回调
      this.websocket.onclose = this.setOncloseMessage
 
      // 监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
      window.onbeforeunload = this.onbeforeunload
 
    },
    setErrorMessage () {
      console.log('连接发生错误   状态码:' + this.websocket.readyState)
    },
    setOnopenMessage () {
      console.log('连接成功    状态码:' + this.websocket.readyState)
      //发送一个请求 去执行检查,传过去一个userid 用来给自己发送信息
      checkcheck()
 
    },
    setOnmessageMessage (event) {
      // 根据服务器推送的消息做自己的业务处理
      let jsonMsg = JSON.parse(event.data)
      let _this = this
      console.log(jsonMsg)
      if (jsonMsg.type === 'notify') {
        _this.$notify.warning({
          message: jsonMsg.message,
          duration:0,
          title: '提示',
          onClick:function() {
            if (jsonMsg.supervision && jsonMsg.contentType === 'info' ) {
              _this.$undone({
                unDoneFormVisible:true
              })
            }
            if (jsonMsg.supervision && jsonMsg.contentType === 'license'){
              _this.$expired({
                expiredFormVisible:true
              })
            }
 
          }
        });
      }
 
    },
    setOncloseMessage () {
      console.log('连接关闭    状态码:' + this.websocket.readyState)
    },
    onbeforeunload () {
      this.closeWebSocket()
    },
    closeWebSocket () {
      this.websocket.close()
    }
  }
}
</script>
 
<style rel="stylesheet/scss" lang="scss">
.login-container {
  min-height: 100%;
  width: 100%;
  background: url("../../assets/bg2.png") center no-repeat;
    //background-size: auto 100%;
    background-size: cover;
    background-position: center;
  position: relative;
  background-color: #fff;
  // background-color: #2d3a4b;
  overflow: hidden;
  .login-logo {
    position: relative;
    color: #fff;
    text-align: center;
    padding: 0 35px 0 35px;
    margin: 0 auto;
    margin-top: 25%;
    margin-left: -100px;
  }
  .login-font {
    position: relative;
    text-align: center;
    margin-left: -10%;
  }
 
  .login-font span {
    display: inline-block;
    width: 600px;
    height: 72px;
    font-size: 45px;
    font-family: PingFangSC-Semibold;
    font-weight: 600;
    color: white;
    line-height: 60px;
    vertical-align: middle;
    margin-top:50px;
    //padding: 20px 0; /* 撑开高度 */
  }
  .login-logo span {
    display: inline-block;
    width: 500px;
    height: 72px;
    font-size: 45px;
    font-family: PingFangSC-Semibold;
    font-weight: 600;
    color: rgba(51, 51, 51, 1);
    line-height: 60px;
    vertical-align: middle;
    margin-top: 50px;
    //padding: 20px 0; /* 撑开高度 */
  }
  //使用图片来替换
  //before属性中的content文本是用来占位的,必须有
  //可以设置字体大小来确定大小
  //使用visibility: hidden;来隐藏文字
  .el-icon-logo {
    background: url("../../assets/logo.png") center no-repeat;
    background-size: cover;
    height: 128px;
    width: 128px;
    color: #fff;
    vertical-align: middle;
  }
  .el-icon-logo:before {
    content: "替";
    font-size: 25px;
    visibility: hidden;
  }
    .login_title{
        background: url("../../assets/title@2x.png") center no-repeat;
        width:747px;
        height:300px;
        margin:auto;
 
    }
  .left-container {
    margin: 0 auto;
      margin-top:3%;
    .login-component {
      max-width: 100%;
      margin: 0 auto;
      overflow: hidden;
        width: 820px;
        height: 480px;
        background: #FFFFFF;
        border-radius: 10px;
        opacity: 0.65;
    }
    .register-component {
      position: relative;
      width: 600px;
      max-width: 100%;
      padding: 40px 35px 0 35px;
      margin: 0 auto;
      overflow: hidden;
      background-color: #fff;
    }
  }
  .bottom-container{
      margin-top:3%;
      text-align: center;
      .bottom-container_title{
          width: 527px;
          height: 20px;
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #FFFFFF;
          line-height: 20px;
      }
  }
 
}
 
.login-container-1 {
  min-height: 100%;
  width: 100%;
  background: url("../../assets/login-bg-1.png") center no-repeat;
  //background-size: auto 100%;
  background-size: cover;
  background-position: center;
  position: relative;
  background-color: #fff;
  // background-color: #2d3a4b;
  overflow: hidden;
  .login-logo {
    position: relative;
    color: #fff;
    margin-top: 5%;
  }
  .login-font {
    position: relative;
    margin-top: -15%;
    text-align: center;
  }
 
  .login-font span {
    display: inline-block;
    width: 700px;
    height: 72px;
    font-size: 30px;
    font-family: PingFangSC-Semibold;
    font-weight: 600;
    color: white;
    line-height: 60px;
    vertical-align: middle;
    //padding: 20px 0; /* 撑开高度 */
  }
  .login-logo span {
    display: inline-block;
    width: 500px;
    height: 72px;
    font-size: 45px;
    font-family: PingFangSC-Semibold;
    font-weight: 600;
    color: rgba(51, 51, 51, 1);
    line-height: 60px;
    vertical-align: middle;
    margin-top: 50px;
    //padding: 20px 0; /* 撑开高度 */
  }
  //使用图片来替换
  //before属性中的content文本是用来占位的,必须有
  //可以设置字体大小来确定大小
  //使用visibility: hidden;来隐藏文字
  .el-icon-logo {
    background: url("../../assets/logo.png") center no-repeat;
    background-size: cover;
    height: 128px;
    width: 128px;
    color: #fff;
    vertical-align: middle;
  }
  .el-icon-logo:before {
    content: "替";
    font-size: 25px;
    visibility: hidden;
  }
  .left-container {
    margin: 0 auto;
    .login-component {
      background-color: white;
      position: relative;
      width: 500px;
      max-width: 100%;
      padding: 15px 35px 0 30px;
      margin: 0 auto;
    }
    .register-component {
      position: relative;
      width: 600px;
      max-width: 100%;
      padding: 40px 35px 0 35px;
      margin: 0 auto;
      overflow: hidden;
      background-color: #fff;
    }
  }
  .bottom-container{
    position: absolute;
    bottom: 0;
    left: 20%;
  }
}
.login_main{
    margin:auto;
}
</style>