|
@@ -3,36 +3,10 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
-import { onMounted } from 'vue'
|
|
|
|
|
-import { useUserStore } from '@/store/modules/user'
|
|
|
|
|
-import { UserService } from '@/api/usersApi'
|
|
|
|
|
-import { ApiStatus } from '@/utils/http/status'
|
|
|
|
|
-
|
|
|
|
|
-const userStore = useUserStore()
|
|
|
|
|
-
|
|
|
|
|
-onMounted(() => {
|
|
|
|
|
- // 初始化用户状态
|
|
|
|
|
- if (userStore.isLogin && userStore.accessToken) {
|
|
|
|
|
- getUserInfo()
|
|
|
|
|
- }
|
|
|
|
|
-})
|
|
|
|
|
-
|
|
|
|
|
-// 获取用户信息
|
|
|
|
|
-const getUserInfo = async () => {
|
|
|
|
|
- try {
|
|
|
|
|
- const userRes = await UserService.getUserInfo()
|
|
|
|
|
- if (userRes.code === ApiStatus.success) {
|
|
|
|
|
- userStore.setUserInfo(userRes.data)
|
|
|
|
|
- } else if (userRes.code === 401) {
|
|
|
|
|
- userStore.logOut()
|
|
|
|
|
- }
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- // 静默处理错误
|
|
|
|
|
- if (userStore.isLogin) {
|
|
|
|
|
- userStore.logOut()
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 用户信息在登录时写入 Pinia;H5 不额外拉取门户 current-user。
|
|
|
|
|
+ * 401 由 HTTP 拦截器统一处理登出。
|
|
|
|
|
+ */
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
<style lang="scss">
|
|
@@ -42,15 +16,14 @@ const getUserInfo = async () => {
|
|
|
box-sizing: border-box;
|
|
box-sizing: border-box;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-body {
|
|
|
|
|
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
|
|
|
|
|
+html,
|
|
|
|
|
+body,
|
|
|
|
|
+#app {
|
|
|
|
|
+ width: 100%;
|
|
|
|
|
+ height: 100%;
|
|
|
|
|
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
|
|
|
|
|
+ sans-serif;
|
|
|
-webkit-font-smoothing: antialiased;
|
|
-webkit-font-smoothing: antialiased;
|
|
|
-moz-osx-font-smoothing: grayscale;
|
|
-moz-osx-font-smoothing: grayscale;
|
|
|
- background-color: #f5f7fa;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-#app {
|
|
|
|
|
- min-height: 100vh;
|
|
|
|
|
}
|
|
}
|
|
|
</style>
|
|
</style>
|
|
|
-
|
|
|