auth.js
3.11 KB
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
import {
mapState
} from 'vuex';
export default {
props: {
// 模型;auth、suggest
model: {
type: String,
default: "auth"
},
checkProfile: {
type: Boolean,
default: false
},
// m1 、m2、m3
tipModel: {
type: String,
default: "m3"
}
},
data() {
return {
key: 'value',
showProfileInfo: false,
showUnAuth: false,
showSuggest: true,
tips: {
}
}
},
components: {},
computed: {
...mapState({
userInfo: state => state.userInfo
}),
locale() {
return this.$i18n.locale || 'tc';
},
i18n() {
return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
},
showPanel() {
let b1 = this.model == "auth" && (this.showProfileInfo || this.showUnAuth);
let b2 = this.model == "suggest" && this.showSuggest;
return b1 || b2;
}
},
methods: {
initData() {
this.tips = this.i18n.customService.unauth[this.tipModel];
if (this.userInfo && this.userInfo.name) {
this.loginAction();
} else {
this.logoutAction();
}
},
loginAction() {
this.showUnAuth = false;
if (this.checkProfile) {
if (this.userInfo.hadFullInfo == 1) {
this.$emit("onLogin", this.userInfo);
} else {
this.showProfileInfo = true;
}
} else {
this.$emit("onLogin", this.userInfo);
}
},
logoutAction() {
this.showUnAuth = true;
this.showProfileInfo = false;
this.$emit("onLogout", {});
},
gotoLoginPage() {
let callback = this.$route.path;
let separator = "?";
for (let key in this.$route.query) {
callback += separator + key + "=" + this.$route.query[key];
separator = "&";
}
this.$router.push({ path: "/login?callback=" + callback });
},
gotoRegisterPage() {
this.$router.push({ path: "/register" });
},
gotoInformationPage() {
let c = this.$route.fullPath;
this.$router.push({ path: "/infomation/improve", query: { c: c, a: 1 } });
},
noAuth() {
this.$store.commit("SET_USER_INFO", null);
this.initData();
this.$emit("onLogout", {});
}
},
mounted() {
this.initData();
},
created() {
this.$root.eventBus.$on("langChange", () => {
try {
this.tips = this.i18n.customService.unauth[this.tipModel];
} catch (e) { }
});
},
watch: {
userInfo(val) {
if (val && val.name) {
this.loginAction();
} else {
this.logoutAction();
}
}
},
}