UserRealName.vue
1.54 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
<template>
<template v-if="userName==='系统默认'">
系统默认
</template>
<template v-else>
{{ user?.realName ?? userName }}
</template>
</template>
<script lang="ts">
import {Component, Prop, Vue, Watch} from "vue-facing-decorator";
import {User} from "lib/src/entity/security/entity/User";
import {Getter, Mutation} from 'vuex-facing-decorator';
import {SecurityController} from "@/api/SecurityController";
@Component({
components: {}
})
export default class UserRealName extends Vue {
@Prop({type: String})
userName: string;
user: User = null;
@Getter getUserByName;
@Mutation cacheUser;
created(): void {
this.user = this.getUserByName(this.userName);
if (!this.user && this.userName) {
SecurityController.getUserByUserName(this.axios, this.userName).then(res => {
this.user = res.data;
if (this.user) {
this.cacheUser(this.user);
}
});
}
}
@Watch('userName', {deep: true, immediate: true})
watchUserName(value: string): void {
if (value) {
this.user = this.getUserByName(value);
if (!this.user) {
SecurityController.getUserByUserName(this.axios, value).then(res => {
this.user = res.data;
if (this.user) {
this.cacheUser(this.user);
}
});
}
}
}
}
</script>
<style lang="scss" scoped>
</style>