|
|
@@ -39,6 +39,8 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+ import CryptoJS from "crypto-js";
|
|
|
+
|
|
|
export default {
|
|
|
name: "Login",
|
|
|
data(){
|
|
|
@@ -48,7 +50,7 @@
|
|
|
sob:"",
|
|
|
username:"",
|
|
|
password:"",
|
|
|
- workshop:""
|
|
|
+ workshop:"SMT"
|
|
|
},
|
|
|
checked: true,
|
|
|
rules:{
|
|
|
@@ -67,9 +69,16 @@
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
+ //默认数据
|
|
|
+ this.getCookies();
|
|
|
+ //监听enter键
|
|
|
+ this.$refs.loginForm.$el.addEventListener('keydown',this.handleEnter);
|
|
|
//获取账套信息
|
|
|
this.getMasters();
|
|
|
},
|
|
|
+ beforeDestroy(){
|
|
|
+ this.$refs.loginForm.$el.removeEventListener('keydown',this.handleEnter);
|
|
|
+ },
|
|
|
methods:{
|
|
|
//获取账套
|
|
|
getMasters(){
|
|
|
@@ -99,23 +108,54 @@
|
|
|
wccode:this.loginForm.workshop
|
|
|
}}).then(
|
|
|
(result)=>{
|
|
|
- console.info(result.data);
|
|
|
var res = result.data;
|
|
|
if(res.success || "检测到您已登录本系统,请不要重复登录、打开空白页!" == res.reason) {
|
|
|
//登录成功返回session
|
|
|
sessionStorage.setItem('x-access-token', res.token);
|
|
|
sessionStorage.setItem('user',res);
|
|
|
- if(res.linedata) {
|
|
|
- sessionStorage.setItem('li_code',res.linedata[0].LI_CODE);
|
|
|
- }else{
|
|
|
- sessionStorage.setItem('li_code','');
|
|
|
- }
|
|
|
this.$store.commit('setUser',res);
|
|
|
+ this.setCookieData();
|
|
|
if(this.loginForm.workshop =='SMT'){
|
|
|
+ if(res.linedata) {
|
|
|
+ if(this.$cookie.get("SMT_LI_CODE") && res.linedata.some(item => item.LI_CODE === this.$cookie.get("SMT_LI_CODE")) ){
|
|
|
+ sessionStorage.setItem('li_code', this.$cookie.get("SMT_LI_CODE"));
|
|
|
+ }else {
|
|
|
+ sessionStorage.setItem('li_code', res.linedata[0].LI_CODE);
|
|
|
+ this.$cookie.set("SMT_LI_CODE", res.linedata[0].LI_CODE, {
|
|
|
+ expires: 30,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ sessionStorage.setItem('li_code','');
|
|
|
+ }
|
|
|
this.$router.push({path: this.redirect || '/smt'});
|
|
|
}else if(this.loginForm.workshop =='包装'){
|
|
|
+ if(res.linedata) {
|
|
|
+ if(this.$cookie.get("PC_LI_CODE") && res.linedata.some(item => item.LI_CODE === this.$cookie.get("PC_LI_CODE")) ){
|
|
|
+ sessionStorage.setItem('li_code', this.$cookie.get("PC_LI_CODE"));
|
|
|
+ }else {
|
|
|
+ sessionStorage.setItem('li_code', res.linedata[0].LI_CODE);
|
|
|
+ this.$cookie.set("PC_LI_CODE", res.linedata[0].LI_CODE, {
|
|
|
+ expires: 30,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ sessionStorage.setItem('li_code','');
|
|
|
+ }
|
|
|
this.$router.push({path: this.redirect || '/package'});
|
|
|
}else if(this.loginForm.workshop =='组装'){
|
|
|
+ if(res.linedata) {
|
|
|
+ if(this.$cookie.get("AS_LI_CODE") && res.linedata.some(item => item.LI_CODE === this.$cookie.get("AS_LI_CODE")) ){
|
|
|
+ sessionStorage.setItem('li_code', this.$cookie.get("AS_LI_CODE"));
|
|
|
+ }else {
|
|
|
+ sessionStorage.setItem('li_code', res.linedata[0].LI_CODE);
|
|
|
+ this.$cookie.set("AS_LI_CODE", res.linedata[0].LI_CODE, {
|
|
|
+ expires: 30,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ sessionStorage.setItem('li_code','');
|
|
|
+ }
|
|
|
this.$router.push({path: this.redirect || '/assembly'});
|
|
|
}
|
|
|
}else{
|
|
|
@@ -137,6 +177,54 @@
|
|
|
});
|
|
|
|
|
|
|
|
|
+ },
|
|
|
+ handleEnter(event){
|
|
|
+ if(event.key === 'Enter'){
|
|
|
+ //处理回车键按下时间
|
|
|
+ this.submitLogin();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ setCookieData(){
|
|
|
+ if (this.checked) {
|
|
|
+ this.$cookie.set(
|
|
|
+ "password",
|
|
|
+ CryptoJS.AES.encrypt(this.loginForm.password, "123456"),
|
|
|
+ {
|
|
|
+ expires: 30
|
|
|
+ }
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ this.$cookie.remove("password");
|
|
|
+ }
|
|
|
+ this.$cookie.set("username", this.loginForm.username, {
|
|
|
+ expires: 30,
|
|
|
+ });
|
|
|
+ this.$cookie.set("sob", this.loginForm.sob, {
|
|
|
+ expires: 30,
|
|
|
+ });
|
|
|
+ this.$cookie.set("workshop", this.loginForm.workshop, {
|
|
|
+ expires: 30,
|
|
|
+ });
|
|
|
+ this.$cookie.set("checked", this.checked, {
|
|
|
+ expires: 30,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ getCookies(){
|
|
|
+ this.loginForm.username = this.$cookie.get("username");
|
|
|
+ if (this.$cookie.get("password")) {
|
|
|
+ this.loginForm.password = CryptoJS.AES.decrypt(
|
|
|
+ this.$cookie.get("password"),
|
|
|
+ "123456"
|
|
|
+ ).toString(CryptoJS.enc.Utf8);
|
|
|
+ }
|
|
|
+ if(this.$cookie.get("workshop")) {
|
|
|
+ this.loginForm.workshop = this.$cookie.get("workshop");
|
|
|
+ }
|
|
|
+ if(this.$cookie.get("checked")) {
|
|
|
+ if(this.$cookie.get("checked") == 'false') {
|
|
|
+ this.checked = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
};
|