|
@@ -31,27 +31,40 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { ref } from 'vue'
|
|
|
-import { ElMessage } from 'element-plus'
|
|
|
-import { ArrowDownBold } from '@element-plus/icons-vue'
|
|
|
-import { useUserStore } from '@/store/user'
|
|
|
+import { ref } from "vue";
|
|
|
+import { ElMessage } from "element-plus";
|
|
|
+import { ArrowDownBold } from "@element-plus/icons-vue";
|
|
|
+import { useUserStore } from "@/store/user";
|
|
|
|
|
|
-const imgUrl = ref('https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png')
|
|
|
-const store = useUserStore()
|
|
|
-const name = store.$state.username
|
|
|
-const errorHandler = () => true
|
|
|
+const imgUrl = ref(
|
|
|
+ "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
|
|
|
+);
|
|
|
+const store = useUserStore();
|
|
|
+const name = store.$state.username;
|
|
|
+const errorHandler = () => true;
|
|
|
/*
|
|
|
* 退出登录
|
|
|
* */
|
|
|
-const router = useRouter()
|
|
|
-const route = useRoute()
|
|
|
-const loginOut = () => {
|
|
|
- const userStore = useUserStore()
|
|
|
- userStore.logout().then(() => {
|
|
|
- ElMessage({ message: '退出登录成功', type: 'success' })
|
|
|
- router.push(`/login?redirect=/`)
|
|
|
- })
|
|
|
-}
|
|
|
+const router = useRouter();
|
|
|
+const route = useRoute();
|
|
|
+const loginOut = async () => {
|
|
|
+ const userStore = useUserStore();
|
|
|
+ const result: any = await userStore.logout();
|
|
|
+ if (result.code == 0) {
|
|
|
+ ElMessage({
|
|
|
+ message: "退出成功",
|
|
|
+ type: "success",
|
|
|
+ duration: 2 * 1000,
|
|
|
+ onClose: () => {
|
|
|
+ useUserStore().resetState();
|
|
|
+ router.push(`/login`);
|
|
|
+ location.reload();
|
|
|
+ },
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ ElMessage.error(result.message);
|
|
|
+ }
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|