zhangzengfei
2021-09-17 8512f4ae542325e15058c9fabb019db6ef1000ef
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
<template>
  <div class v-loading="vLoading" :style="`width: ${currentWidth}px;height:${currentHeight}px`">
    <div class="web-site">
      <a href="http://www.smartai.com" target="_blank">www.smartai.com</a>
    </div>
 
    <!-- 授权信息 -->
    <lang-select class="lang-select"/>
    <licence />
    <div class="right-bg" style>
      <particle-network />
    </div>
    <div class="left-bg">
      <div class="login-logo">
        <img src="/images/login-logo.png" alt width="105px" height="105px" />
      </div>
      <div class="login-com">
        <span>{{ $t('login.company') }}</span>
      </div>
      <div class="login-form">
        <el-form
          :model="user"
          status-icon
          :rules="nullRule"
          :validate-on-rule-change="false"
          ref="ruleForm"
          class="demo-ruleForm"
        >
          <el-form-item prop="loginName">
            <el-input v-model="user.loginName" style="width:280px" :placeholder="$t('placeholder.enterUsername')">
              <i slot="prefix" class="iconfont iconyonghu1"></i>
            </el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              show-password
              @keyup.enter.native="systemLogin()"
              v-model="user.password"
              autocomplete="off"
              style="width:280px"
              :placeholder="$t('placeholder.enterPassword')"
            >
              <i slot="prefix" class="iconfont iconmima"></i>
            </el-input>
          </el-form-item>
          <el-form-item>
            <el-button ref="submit" type="warning" @click="systemLogin()" style="width:280px">{{ $t('button.login') }}</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- <p class="gradient-text gradient-text-one">——— {{serverTitle || 'SmartAI — ReID'}} ———</p> -->
      <p class="gradient-text gradient-text-one">
        ——
        <b>SmartAI</b> {{ $t('login.aios') }} ——
      </p>
      <p
        class="gradient-text gradient-text-one"
        style="letter-spacing: 1.8px;font-size:15px;"
      >V1.0.0</p>
    </div>
  </div>
</template>
 
<script>
import { tologin, getLoginUserData, getServerName } from './api.ts';
import ParticleNetwork from './ParticleNetwork'
import Licence from '@/components/licence'
import LangSelect from '@/components/langSelect'
import { getMenuListData } from "@/api/utils";
 
export default {
  name: 'login-pgae',
  metaInfo: {
    title: '登录页'
  },
  components: {
    ParticleNetwork,
    Licence,
    LangSelect
  },
  computed: {
    rules() {
      return {
        loginName: [{ required: true, message: this.$t('placeholder.enterUsername'), trigger: 'change' } ],
        password: [{ required: true, message: this.$t('placeholder.enterPassword'), trigger: 'change' }]
        }
    },
  },
  data: () => ({
    serverTitle: "",
    user: {
      loginName: '',
      password: '',
      rememberMe: false
    },
    nullRule: {},
 
    loading: '',
    vLoading: false,
    currentHeight: 1057,
    currentWidth: 1920
  }),
  created() {
    this.getServerName()
    this.getScreenHeight()
  },
  mounted() {
    // 自动登录接口
    this.loginRobot();
  },
  watch: {},
  beforeDestroy() {
    window.onresize = null
  },
  methods: {
    loginRobot() {
      // 解析路由参数,并缓存
      let user = this.getQueryVariable("username");
      let passwd = this.getQueryVariable("password");
      if (user.length && passwd.length) {
        sessionStorage.setItem("autoLogin", JSON.stringify({ username: user, passwd: passwd }));
 
        this.user.loginName = user;
        this.user.password = passwd;
        this.systemLogin();
        return;
      }
 
      // 登陆超时后的重新登陆
      let sessionInfo = sessionStorage.getItem('autoLogin');
      if (sessionInfo) {
        let authority = JSON.parse(sessionInfo);
        this.user.loginName = authority.username;
        this.user.password = authority.passwd;
        this.systemLogin();
      }
    },
    systemLogin() {
      this.nullRule = this.rules
      this.$nextTick(() => {
        this.$refs['ruleForm'].validate(valid => {
          if (valid) {
            this.loading = this.$loading({
              lock: true,
              text: 'Loading',
              spinner: 'el-icon-loading',
              background: 'rgba(0, 0, 0, 0.7)'
            })
            this.testLogin()
          } else {
            this.nullRule = {}
          }
        })
        this.nullRule = {}
      })
    },
    async testLogin() {
      // location.assign("/view/desktop/")
      tologin({ username: this.user.loginName, password: this.user.password })
        .then(json => {
          const loginedInfo = {
            access_token: json.token_type + ' ' + json.access_token,
            refresh_token: json.refresh_token
          }
          sessionStorage.setItem('expires_in', json.expires_in)
          sessionStorage.setItem('loginedInfo', JSON.stringify(loginedInfo))
          this.loading.close()
          this.getLoginUserData()
        })
        .catch(err => {
          this.loading.close()
          this.$notify({
            title: '提示',
            type: 'error',
            message: err.msg
          })
          this.$refs.pwd.focus()
        })
    },
    async getLoginUserData() {
      let res = await getLoginUserData()
      if (res.success) {
        sessionStorage.setItem('userInfo', JSON.stringify(res.data))
        this.$notify.success("登录成功!")
        // 获取权限
        await this.getMenuList()
        location.assign("/view/desktop/")
        return res.data
      } else {
        this.$notify.error("登录失败!")
      }
    },
 
    getScreenHeight() {
      this.currentHeight = document.documentElement.clientHeight
      this.currentWidth = document.documentElement.clientWidth
      window.onresize = () => {
        this.currentHeight = document.documentElement.clientHeight
        this.currentWidth = document.documentElement.clientWidth
        this.$forceUpdate()
      }
    },
    async getServerName() {
      let res = await getServerName()
      if (res && res.success) {
        this.serverTitle = res.data.serverName
        window.document.title = res.data.serverName
          ? res.data.serverName
          : 'SmartAI'
        sessionStorage.setItem('title', res.data.serverName)
      }
    },
    async getMenuList() {
      let results = await getMenuListData({});
      if (results && results.success) {
        /* 存储权限 */
        let buttonAuthoritys = results.data;
        if (results && results.length && this.$route.query.is_login) {
          this.$router.replace(results[0].url);
        }
        sessionStorage.setItem("buttonAuthoritys", "," + buttonAuthoritys + ",");
        sessionStorage.setItem("menuInfo", JSON.stringify(results));
      } else {
        this.$toast({
          type: "error",
          message: "菜单获取失败"
        });
      }
    },
    getQueryVariable(variable) {
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) { return pair[1]; }
      }
      return (false);
    }
  },
}
</script>
<style lang="scss">
.right-bg {
  position: fixed;
  top: 0;
  left: 0;
  background-image: url("/images/login-net.png");
 
  width: 100%;
  height: 100%;
  min-width: 1000px;
  z-index: -10;
  zoom: 1;
  background-color: #fff;
  background-repeat: no-repeat;
  background-size: cover;
  -webkit-background-size: cover;
  -o-background-size: cover;
  background-position: center 0;
}
.web-site {
  position: absolute;
  top: 55px;
  left: 41px;
  font-family: PingFangSC-Medium;
  font-size: 20px;
  color: #6170e1;
  letter-spacing: 6.15px;
}
.lang-select {
  float: right;
  color: white !important;
  font-size: 14px;
  margin: 13px;
  cursor: pointer;
}
.left-bg {
  position: absolute;
  top: 29%;
  right: 18%;
  width: 390px;
  height: 426px;
  background: rgba(146, 208, 255, 0.23);
  border-radius: 4px;
  text-align: center;
  .login-logo {
    margin-top: -53px;
  }
 
  .login-com {
    font-family: PingFangSC-Medium;
    font-size: 22px;
    color: #ffffff;
    letter-spacing: 0.44px;
    margin: 15px;
  }
  .login-form {
    margin: 40px 10px;
  }
  .gradient-text {
    line-height: 36px;
    font-size: 17px;
    font-family: -webkit-pictograph;
    font-weight: bolder;
    position: relative;
    b {
      font-size: 20px;
    }
  }
  .gradient-text-one {
    background-image: linear-gradient(to right, #51feff 5%, #ff8725 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
 
  .el-input__prefix {
    left: 8px;
  }
 
  .el-form-item__error {
    left: 54px;
  }
}
</style>