消逝
2024-07-11 8610c5c35b7de98fb254922ea70629c104143be8
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
<template>
    <div class="user-panel max-w-sm min-w-96 h-fit">
        <el-card class="card">
            <div class="panel-content flex flex-col items-center">
                <!-- 学生信息 -->
                <el-dropdown>
                    <div
                        class="avatar-container w-40 h-40 rounded-full overflow-hidden el-dropdown-link"
                        @click="stateClick()"
                    >
                        <div
                            class="avatar-content"
                            v-if="userInfo.imagePath"
                        >
                            <img
                                :src="userInfo.imagePath"
                                class="avatar-img"
                                alt=""
                            />
                        </div>
                        <div
                            class="avatar-content"
                            :style="{ backgroundColor: getColor }"
                            v-else
                        >
                            <div class="name text-5xl font-bold text-white">
                                {{ getFirstName }}
                            </div>
                        </div>
                    </div>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item>修改密码</el-dropdown-item>
                            <el-dropdown-item>个人中心</el-dropdown-item>
                            <el-dropdown-item @click="quit()"
                                >退出登录</el-dropdown-item
                            >
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
 
                <div class="name-container text-lg font-bold mt-5 mb-2">
                    {{ userInfo.realName }}
                </div>
 
                <div class="department-container text-base mb-10">
                    {{ userInfo.userName }}
                </div>
                <!-- 学生选项 -->
                <div class="tool-container grid grid-cols-3 gap-10">
                    <div
                        class="tool-item text-center cursor-pointer"
                        v-for="item in toolList"
                        @click="toolClick(item)"
                    >
                        <div class="tool-icon mb-1">
                            <img
                                :src="item.iconPath"
                                class="width-img"
                                alt=""
                            />
                        </div>
                        <div class="tool-title">
                            {{ item.title }}
                        </div>
                    </div>
                </div>
            </div>
        </el-card>
    </div>
</template>
 
<script setup>
import { ref, computed } from "vue";
import randomColor from "@/utils/randomColor.js";
import { useRouter } from "vue-router";
import { storeToRefs } from "pinia";
import { useUserStore } from "@/store/index.js";
import { logout } from "@/api/modules/user.js";
 
const userStore = useUserStore();
const { userInfo } = storeToRefs(userStore);
 
const router = useRouter();
// 获取列表
const toolList = ref([
    {
        id: 1,
        title: "在线培训",
        iconPath: new URL("@/assets/icons/icon1.png", import.meta.url).href,
        path: "/train",
    },
    {
        id: 2,
        title: "我的考试",
        iconPath: new URL("@/assets/icons/icon2.png", import.meta.url).href,
        path: "/exam-list",
    },
    {
        id: 3,
        title: "我的成绩",
        iconPath: new URL("@/assets/icons/icon2.png", import.meta.url).href,
        path: "/grade-list",
    },
]);
 
// 获取颜色
const getColor = computed(() => {
    return randomColor();
});
// 获取用户信息
const getFirstName = computed(() => {
    return userInfo.value.realName && userInfo.value.realName[0];
});
// 点击事件
const toolClick = (item) => {
    if (item.path) {
        router.push(item.path);
    }
};
 
// 用户选项
const dropdownRef = ref();
// 退出登录
const quit = () => {
    logout()
        .then(() => {
            router.push("/login").then(() => {
                userStore.setUserInfo(null);
                localStorage.clear("user");
            });
        })
        .catch((err) => {
            console.log("退出登录失败,失败原因;", err);
        });
};
</script>
 
<style lang="scss" scoped>
.card {
    border-radius: 30px;
}
 
.avatar-content {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}
 
.avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.avatar-container {
    cursor: pointer;
    color: var(--el-color-primary);
    display: flex;
    align-items: center;
}
.example-showcase .el-dropdown-link {
    cursor: pointer;
    color: var(--el-color-primary);
    display: flex;
    align-items: center;
}
</style>