Commit 0d42faab4d93423a6a1a4e5f04e98586dcef0ad0

Authored by ww
1 parent 94c86f67

perf: 实现退出登录

1 1 # port
2   -VITE_DEV_PORT = '8001'
  2 +VITE_DEV_PORT = 5555
3 3
4 4 # development path
5 5 VITE_DEV_PATH = '/'
... ...
  1 +export enum ProjectRuntimeEnvEnum {
  2 + DEV = 'development',
  3 + PROD = 'production',
  4 + DEV_ALONE = 'alone.dev',
  5 + PROD_ALONE = 'alone.prod'
  6 +}
... ...
1 1 import { resolve } from "path"
2 2 import { ConfigEnv } from "vite"
3 3
4   -export enum ProjectRuntimeEnvEnum {
5   - DEV = 'development',
6   - PROD = 'production',
7   - DEV_ALONE = 'alone.dev',
8   - PROD_ALONE = 'alone.prod'
9   -}
10 4
11 5 export function parseEnv(env: ImportMetaEnv) {
12 6 const res: Record<string, any> = {}
... ... @@ -35,7 +29,7 @@ export function parseEnv(env: ImportMetaEnv) {
35 29
36 30 }
37 31
38   - return res
  32 + return res as ViteEnv
39 33 }
40 34
41 35 export function getEnvConfig(match = 'VITE_GLOB_',) {
... ...
... ... @@ -22,6 +22,7 @@ import { GoSystemInfo } from '@/components/GoSystemInfo/index'
22 22 import Person from './person.png'
23 23
24 24 import { icon } from '@/plugins'
  25 +import { useUserStore } from '@/store/external/module/user'
25 26 const { ChatboxEllipsesIcon, PersonIcon, LogOutOutlineIcon, SettingsSharpIcon } = icon.ionicons5
26 27
27 28 const t = window['$t']
... ... @@ -97,6 +98,8 @@ const sysInfoHandle = () => {
97 98 modelShowInfo.value = true
98 99 }
99 100
  101 +// THINGS_KIT 修改退出登录
  102 +const userStore = useUserStore()
100 103 const handleSelect = (key: string) => {
101 104 switch (key) {
102 105 case 'contact':
... ... @@ -106,7 +109,9 @@ const handleSelect = (key: string) => {
106 109 sysSetHandle()
107 110 break
108 111 case 'logout':
109   - logout()
  112 + // THINGS_KIT 修改退出登录
  113 + userStore.logout(true)
  114 + // logout()
110 115 break
111 116 }
112 117 }
... ...
1   -export enum RuntimeEnvironment {
2   - DEVELOPMENT = 'development',
3   - PRODUCTION = 'production',
4   - INDEPENDENCE = 'independence'
5   -}
  1 +import { ProjectRuntimeEnvEnum } from '../../../build/external/envEnum'
  2 +
  3 +export { ProjectRuntimeEnvEnum }
... ...
  1 +import { PageEnum as NPageEnum } from '../pageEnum'
1 2 export const PageEnum = {
2   - SYSTEM_PASSWORD: '/system/changePassword',
3 3 // basic login path
4 4 BASE_LOGIN: '/login',
5 5 // basic home path
6   - BASE_HOME: '/dashboard/workbench',
7   - // error page path
8   - ERROR_PAGE: '/exception',
9   - // error log page path
10   - ERROR_LOG_PAGE: '/error-log/list',
11   - //消息配置
12   - MESSAGE_CONFIG: '/message/config',
13   - //设备配置
14   - DEVICE_PROFILE: '/product/profiles',
15   - DEVICE_LIST: '/device/list',
  6 + BASE_HOME: NPageEnum.BASE_HOME_ITEMS,
16 7 };
... ...
1   -import { RuntimeEnvironment } from "@/enums/external/envEnum";
2   -import { PageEnum } from "@/enums/pageEnum";
  1 +import { ProjectRuntimeEnvEnum } from "@/enums/external/envEnum";
  2 +import { PageEnum } from "@/enums/external/pageEnum";
3 3 import { useUserStoreWithOut } from "@/store/external/module/user";
4   -import { RouteLocationRaw, Router } from "vue-router";
  4 +import { NavigationGuardNext, NavigationGuardWithThis, RouteLocationNormalized, RouteLocationRaw, Router } from "vue-router";
5 5
6 6
7 7 const whitePathList: string[] = [PageEnum.BASE_LOGIN];
8 8
9   -const isIndependenceMode = import.meta.env.MODE === RuntimeEnvironment.INDEPENDENCE
  9 +const isAloneMode = [ProjectRuntimeEnvEnum.DEV_ALONE, ProjectRuntimeEnvEnum.PROD_ALONE].includes(import.meta.env.MODE as ProjectRuntimeEnvEnum)
10 10
11   -const toIotPlatformLogin = () => {
12   - const { origin } = window.location
  11 +const toIotPlatformLogin = ({ to, from, next }: { to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext }) => {
  12 + const { origin, port } = window.location
  13 + if (Number(port) === Number(import.meta.env.VITE_DEV_PORT)) {
  14 + if (whitePathList.includes(to.path)) {
  15 + next()
  16 + return
  17 + } else {
  18 + next(PageEnum.BASE_LOGIN)
  19 + }
  20 + return
  21 + }
13 22 window.location.replace(`${origin}/login?redirect=${import.meta.env.VITE_GLOB_PUBLIC_PATH}`)
14 23 }
15 24
16 25 export function createPermissionGuard(router: Router) {
17   - const userStore = useUserStoreWithOut()
  26 + const userStore = useUserStoreWithOut()
18 27
19 28 router.beforeEach((to, from, next) => {
20 29 if (from.path === '/' &&
... ... @@ -22,7 +31,6 @@ export function createPermissionGuard(router: Router) {
22 31 userStore.getUserInfo.homePath &&
23 32 userStore.getUserInfo.homePath !== PageEnum.BASE_HOME
24 33 ) {
25   - console.log(userStore.getUserInfo.homePath)
26 34 next(userStore.getUserInfo.homePath)
27 35 return
28 36 }
... ... @@ -33,7 +41,7 @@ export function createPermissionGuard(router: Router) {
33 41 if (to.path === PageEnum.BASE_LOGIN && token) {
34 42 const isSessionTimeout = userStore.getSessionTimeout
35 43 try {
36   - if (!isSessionTimeout) {
  44 + if (isSessionTimeout) {
37 45 next('/')
38 46 }
39 47 } catch (error) {
... ... @@ -41,8 +49,9 @@ export function createPermissionGuard(router: Router) {
41 49 }
42 50 }
43 51 else {
44   - if (isIndependenceMode) {
45   - toIotPlatformLogin()
  52 + if (!isAloneMode) {
  53 + console.log({ to, from })
  54 + toIotPlatformLogin({ to, from, next })
46 55 return
47 56 }
48 57 next()
... ... @@ -55,8 +64,9 @@ export function createPermissionGuard(router: Router) {
55 64 path: PageEnum.BASE_LOGIN,
56 65 redirect: true
57 66 } as RouteLocationRaw
58   - if (isIndependenceMode) {
59   - toIotPlatformLogin()
  67 + if (!isAloneMode) {
  68 + console.log({ to, from })
  69 + toIotPlatformLogin({ to, from, next })
60 70 return
61 71 }
62 72 next(redirectData)
... ...
... ... @@ -2,7 +2,7 @@ import type { UserInfo, UserUpdateInfo } from '/#/external/store';
2 2 import type { ErrorMessageMode } from '/#/external/axios';
3 3 import { defineStore } from 'pinia';
4 4 import { pinia as store } from '@/store';
5   -import { RoleEnum } from '@/enums/external/roleEnum';
  5 +import { RoleEnum } from '@/enums/external/roleEnum';
6 6 import { JWT_TOKEN_KEY, REFRESH_TOKEN_KEY, ROLES_KEY, USER_INFO_KEY } from '@/enums/external/cacheEnum';
7 7 import { getAuthCache, setAuthCache } from '@/utils/external/auth';
8 8 import {
... ... @@ -16,7 +16,7 @@ import router from '@/router';
16 16 import { createLocalStorage } from '@/utils/external/cache';
17 17 import { useI18n } from 'vue-i18n';
18 18 import { useDialog } from 'naive-ui';
19   -import { PageEnum } from '@/enums/pageEnum';
  19 +import { PageEnum } from '@/enums/external/pageEnum';
20 20
21 21 interface UserState {
22 22 platInfo: any;
... ... @@ -177,9 +177,9 @@ export const useUserStore = defineStore({
177 177 this.setSessionTimeout(false);
178 178 setAuthCache(REFRESH_TOKEN_KEY, undefined);
179 179 this.setUserInfo(null);
180   - goLogin && router.push(PageEnum.BASE_LOGIN);
181 180 window.localStorage.clear();
182 181 window.localStorage.removeItem('updateUserInfo');
  182 + goLogin && router.push(PageEnum.BASE_LOGIN);
183 183 },
184 184
185 185 async doRefresh() {
... ...
... ... @@ -2,12 +2,13 @@ import type { GlobEnvConfig } from '/#/external/config';
2 2
3 3 // import pkg from '../../../../package.json';
4 4 import { getGlobalConfigName } from '../../../../build/external/vite/plugins/globConfig/getGlobConfigName';
5   -import { RuntimeEnvironment } from '@/enums/external/envEnum';
  5 +import { ProjectRuntimeEnvEnum } from '@/enums/external/envEnum';
  6 +
6 7
7 8 export function getCommonStoragePrefix() {
8 9 // const { VITE_GLOB_APP_SHORT_NAME } = getAppEnvConfig();
9 10 const VITE_GLOB_APP_SHORT_NAME = 'undefined'
10   - const ENV = [RuntimeEnvironment.DEVELOPMENT, RuntimeEnvironment.INDEPENDENCE].includes(import.meta.env.MODE as RuntimeEnvironment) ? RuntimeEnvironment.DEVELOPMENT : RuntimeEnvironment.PRODUCTION
  11 + const ENV = [ProjectRuntimeEnvEnum.DEV, ProjectRuntimeEnvEnum.DEV_ALONE].includes(import.meta.env.MODE as ProjectRuntimeEnvEnum) ? ProjectRuntimeEnvEnum.DEV : ProjectRuntimeEnvEnum.PROD
11 12 return `${VITE_GLOB_APP_SHORT_NAME}__${ENV.toUpperCase()}`.toUpperCase();
12 13 }
13 14
... ...
1 1 <template>
2 2 <div class="go-items-list">
3   - <n-grid
4   - :x-gap="20"
5   - :y-gap="20"
6   - cols="2 s:2 m:3 l:4 xl:4 xxl:4"
7   - responsive="screen"
8   - >
  3 + <n-grid :x-gap="20" :y-gap="20" cols="2 s:2 m:3 l:4 xl:4 xxl:4" responsive="screen">
9 4 <n-grid-item v-for="(item, index) in list" :key="item.id">
10   - <project-items-card
11   - :cardData="item"
12   - @resize="resizeHandle"
13   - @delete="deleteHandle($event, index)"
14   - @edit="editHandle"
15   - ></project-items-card>
  5 + <project-items-card :cardData="item" @resize="resizeHandle" @delete="deleteHandle($event, index)"
  6 + @edit="editHandle"></project-items-card>
16 7 </n-grid-item>
17 8 </n-grid>
18 9 <div class="list-pagination">
19   - <n-pagination
20   - :item-count="10"
21   - :page-sizes="[10, 20, 30, 40]"
22   - show-size-picker
23   - />
  10 + <n-pagination :item-count="10" :page-sizes="[10, 20, 30, 40]" show-size-picker />
24 11 </div>
25 12 </div>
26   - <project-items-modal-card
27   - v-if="modalData"
28   - :modalShow="modalShow"
29   - :cardData="modalData"
30   - @close="closeModal"
31   - @edit="editHandle"
32   - ></project-items-modal-card>
  13 + <project-items-modal-card v-if="modalData" :modalShow="modalShow" :cardData="modalData" @close="closeModal"
  14 + @edit="editHandle"></project-items-modal-card>
33 15 </template>
34 16
35 17 <script setup lang="ts">
36   -import {ProjectItemsCard} from '../ProjectItemsCard/index'
37   -import {ProjectItemsModalCard} from '../ProjectItemsModalCard/index'
38   -import {icon} from '@/plugins'
39   -import {useModalDataInit} from './hooks/useModal.hook'
40   -import {useDataListInit} from './hooks/useData.hook'
41   -import {getDataViewList} from "@/api/external/contentSave/content";
42   -import {onMounted, ref} from "vue";
  18 +import { ProjectItemsCard } from '../ProjectItemsCard/index'
  19 +import { ProjectItemsModalCard } from '../ProjectItemsModalCard/index'
  20 +import { icon } from '@/plugins'
  21 +import { useModalDataInit } from './hooks/useModal.hook'
  22 +import { useDataListInit } from './hooks/useData.hook'
  23 +import { getDataViewList } from "@/api/external/contentSave/content";
  24 +import { onMounted, ref } from "vue";
43 25 // THINGS_KIT
44   -import {ChartList} from '../../index.d'
  26 +import { ChartList } from '../../index.d'
45 27
46   -const {CopyIcon, EllipsisHorizontalCircleSharpIcon} = icon.ionicons5
47   -const {deleteHandle} = useDataListInit()
48   -const {modalData, modalShow, closeModal, resizeHandle, editHandle} = useModalDataInit()
  28 +const { CopyIcon, EllipsisHorizontalCircleSharpIcon } = icon.ionicons5
  29 +const { deleteHandle } = useDataListInit()
  30 +const { modalData, modalShow, closeModal, resizeHandle, editHandle } = useModalDataInit()
49 31
50 32 // THINGS_KIT
51 33 const list = ref<ChartList>([])
52 34 onMounted(async () => {
53   - const {items} = await getDataViewList({page: 1, pageSize: 10})
54   - list.value = items
  35 + try {
  36 + const { items } = await getDataViewList({ page: 1, pageSize: 10 })
  37 + list.value = items
  38 + } catch (error) {
  39 + console.log(error)
  40 + }
55 41 })
56 42
57 43 </script>
58 44
59 45 <style lang="scss" scoped>
60 46 $contentHeight: 250px;
  47 +
61 48 @include go('items-list') {
62 49 display: flex;
63 50 flex-direction: column;
64 51 justify-content: space-between;
65 52 min-height: calc(100vh - #{$--header-height} * 2 - 2px);
  53 +
66 54 .list-content {
67 55 position: relative;
68 56 height: $contentHeight;
69 57 }
  58 +
70 59 .list-pagination {
71 60 display: flex;
72 61 justify-content: flex-end;
... ...
... ... @@ -89,7 +89,7 @@ export default defineConfig(({ mode, command }) => {
89 89 chunkSizeWarningLimit: chunkSizeWarningLimit
90 90 },
91 91 server: {
92   - port: 5555,
  92 + port: viteEnv.VITE_DEV_PORT,
93 93 proxy: createProxy(viteEnv),
94 94 },
95 95 }
... ...