Commit 0d42faab4d93423a6a1a4e5f04e98586dcef0ad0

Authored by ww
1 parent 94c86f67

perf: 实现退出登录

1 # port 1 # port
2 -VITE_DEV_PORT = '8001' 2 +VITE_DEV_PORT = 5555
3 3
4 # development path 4 # development path
5 VITE_DEV_PATH = '/' 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 import { resolve } from "path" 1 import { resolve } from "path"
2 import { ConfigEnv } from "vite" 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 export function parseEnv(env: ImportMetaEnv) { 5 export function parseEnv(env: ImportMetaEnv) {
12 const res: Record<string, any> = {} 6 const res: Record<string, any> = {}
@@ -35,7 +29,7 @@ export function parseEnv(env: ImportMetaEnv) { @@ -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 export function getEnvConfig(match = 'VITE_GLOB_',) { 35 export function getEnvConfig(match = 'VITE_GLOB_',) {
@@ -22,6 +22,7 @@ import { GoSystemInfo } from '@/components/GoSystemInfo/index' @@ -22,6 +22,7 @@ import { GoSystemInfo } from '@/components/GoSystemInfo/index'
22 import Person from './person.png' 22 import Person from './person.png'
23 23
24 import { icon } from '@/plugins' 24 import { icon } from '@/plugins'
  25 +import { useUserStore } from '@/store/external/module/user'
25 const { ChatboxEllipsesIcon, PersonIcon, LogOutOutlineIcon, SettingsSharpIcon } = icon.ionicons5 26 const { ChatboxEllipsesIcon, PersonIcon, LogOutOutlineIcon, SettingsSharpIcon } = icon.ionicons5
26 27
27 const t = window['$t'] 28 const t = window['$t']
@@ -97,6 +98,8 @@ const sysInfoHandle = () => { @@ -97,6 +98,8 @@ const sysInfoHandle = () => {
97 modelShowInfo.value = true 98 modelShowInfo.value = true
98 } 99 }
99 100
  101 +// THINGS_KIT 修改退出登录
  102 +const userStore = useUserStore()
100 const handleSelect = (key: string) => { 103 const handleSelect = (key: string) => {
101 switch (key) { 104 switch (key) {
102 case 'contact': 105 case 'contact':
@@ -106,7 +109,9 @@ const handleSelect = (key: string) => { @@ -106,7 +109,9 @@ const handleSelect = (key: string) => {
106 sysSetHandle() 109 sysSetHandle()
107 break 110 break
108 case 'logout': 111 case 'logout':
109 - logout() 112 + // THINGS_KIT 修改退出登录
  113 + userStore.logout(true)
  114 + // logout()
110 break 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 export const PageEnum = { 2 export const PageEnum = {
2 - SYSTEM_PASSWORD: '/system/changePassword',  
3 // basic login path 3 // basic login path
4 BASE_LOGIN: '/login', 4 BASE_LOGIN: '/login',
5 // basic home path 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 import { useUserStoreWithOut } from "@/store/external/module/user"; 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 const whitePathList: string[] = [PageEnum.BASE_LOGIN]; 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 window.location.replace(`${origin}/login?redirect=${import.meta.env.VITE_GLOB_PUBLIC_PATH}`) 22 window.location.replace(`${origin}/login?redirect=${import.meta.env.VITE_GLOB_PUBLIC_PATH}`)
14 } 23 }
15 24
16 export function createPermissionGuard(router: Router) { 25 export function createPermissionGuard(router: Router) {
17 - const userStore = useUserStoreWithOut() 26 + const userStore = useUserStoreWithOut()
18 27
19 router.beforeEach((to, from, next) => { 28 router.beforeEach((to, from, next) => {
20 if (from.path === '/' && 29 if (from.path === '/' &&
@@ -22,7 +31,6 @@ export function createPermissionGuard(router: Router) { @@ -22,7 +31,6 @@ export function createPermissionGuard(router: Router) {
22 userStore.getUserInfo.homePath && 31 userStore.getUserInfo.homePath &&
23 userStore.getUserInfo.homePath !== PageEnum.BASE_HOME 32 userStore.getUserInfo.homePath !== PageEnum.BASE_HOME
24 ) { 33 ) {
25 - console.log(userStore.getUserInfo.homePath)  
26 next(userStore.getUserInfo.homePath) 34 next(userStore.getUserInfo.homePath)
27 return 35 return
28 } 36 }
@@ -33,7 +41,7 @@ export function createPermissionGuard(router: Router) { @@ -33,7 +41,7 @@ export function createPermissionGuard(router: Router) {
33 if (to.path === PageEnum.BASE_LOGIN && token) { 41 if (to.path === PageEnum.BASE_LOGIN && token) {
34 const isSessionTimeout = userStore.getSessionTimeout 42 const isSessionTimeout = userStore.getSessionTimeout
35 try { 43 try {
36 - if (!isSessionTimeout) { 44 + if (isSessionTimeout) {
37 next('/') 45 next('/')
38 } 46 }
39 } catch (error) { 47 } catch (error) {
@@ -41,8 +49,9 @@ export function createPermissionGuard(router: Router) { @@ -41,8 +49,9 @@ export function createPermissionGuard(router: Router) {
41 } 49 }
42 } 50 }
43 else { 51 else {
44 - if (isIndependenceMode) {  
45 - toIotPlatformLogin() 52 + if (!isAloneMode) {
  53 + console.log({ to, from })
  54 + toIotPlatformLogin({ to, from, next })
46 return 55 return
47 } 56 }
48 next() 57 next()
@@ -55,8 +64,9 @@ export function createPermissionGuard(router: Router) { @@ -55,8 +64,9 @@ export function createPermissionGuard(router: Router) {
55 path: PageEnum.BASE_LOGIN, 64 path: PageEnum.BASE_LOGIN,
56 redirect: true 65 redirect: true
57 } as RouteLocationRaw 66 } as RouteLocationRaw
58 - if (isIndependenceMode) {  
59 - toIotPlatformLogin() 67 + if (!isAloneMode) {
  68 + console.log({ to, from })
  69 + toIotPlatformLogin({ to, from, next })
60 return 70 return
61 } 71 }
62 next(redirectData) 72 next(redirectData)
@@ -2,7 +2,7 @@ import type { UserInfo, UserUpdateInfo } from '/#/external/store'; @@ -2,7 +2,7 @@ import type { UserInfo, UserUpdateInfo } from '/#/external/store';
2 import type { ErrorMessageMode } from '/#/external/axios'; 2 import type { ErrorMessageMode } from '/#/external/axios';
3 import { defineStore } from 'pinia'; 3 import { defineStore } from 'pinia';
4 import { pinia as store } from '@/store'; 4 import { pinia as store } from '@/store';
5 -import { RoleEnum } from '@/enums/external/roleEnum'; 5 +import { RoleEnum } from '@/enums/external/roleEnum';
6 import { JWT_TOKEN_KEY, REFRESH_TOKEN_KEY, ROLES_KEY, USER_INFO_KEY } from '@/enums/external/cacheEnum'; 6 import { JWT_TOKEN_KEY, REFRESH_TOKEN_KEY, ROLES_KEY, USER_INFO_KEY } from '@/enums/external/cacheEnum';
7 import { getAuthCache, setAuthCache } from '@/utils/external/auth'; 7 import { getAuthCache, setAuthCache } from '@/utils/external/auth';
8 import { 8 import {
@@ -16,7 +16,7 @@ import router from '@/router'; @@ -16,7 +16,7 @@ import router from '@/router';
16 import { createLocalStorage } from '@/utils/external/cache'; 16 import { createLocalStorage } from '@/utils/external/cache';
17 import { useI18n } from 'vue-i18n'; 17 import { useI18n } from 'vue-i18n';
18 import { useDialog } from 'naive-ui'; 18 import { useDialog } from 'naive-ui';
19 -import { PageEnum } from '@/enums/pageEnum'; 19 +import { PageEnum } from '@/enums/external/pageEnum';
20 20
21 interface UserState { 21 interface UserState {
22 platInfo: any; 22 platInfo: any;
@@ -177,9 +177,9 @@ export const useUserStore = defineStore({ @@ -177,9 +177,9 @@ export const useUserStore = defineStore({
177 this.setSessionTimeout(false); 177 this.setSessionTimeout(false);
178 setAuthCache(REFRESH_TOKEN_KEY, undefined); 178 setAuthCache(REFRESH_TOKEN_KEY, undefined);
179 this.setUserInfo(null); 179 this.setUserInfo(null);
180 - goLogin && router.push(PageEnum.BASE_LOGIN);  
181 window.localStorage.clear(); 180 window.localStorage.clear();
182 window.localStorage.removeItem('updateUserInfo'); 181 window.localStorage.removeItem('updateUserInfo');
  182 + goLogin && router.push(PageEnum.BASE_LOGIN);
183 }, 183 },
184 184
185 async doRefresh() { 185 async doRefresh() {
@@ -2,12 +2,13 @@ import type { GlobEnvConfig } from '/#/external/config'; @@ -2,12 +2,13 @@ import type { GlobEnvConfig } from '/#/external/config';
2 2
3 // import pkg from '../../../../package.json'; 3 // import pkg from '../../../../package.json';
4 import { getGlobalConfigName } from '../../../../build/external/vite/plugins/globConfig/getGlobConfigName'; 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 export function getCommonStoragePrefix() { 8 export function getCommonStoragePrefix() {
8 // const { VITE_GLOB_APP_SHORT_NAME } = getAppEnvConfig(); 9 // const { VITE_GLOB_APP_SHORT_NAME } = getAppEnvConfig();
9 const VITE_GLOB_APP_SHORT_NAME = 'undefined' 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 return `${VITE_GLOB_APP_SHORT_NAME}__${ENV.toUpperCase()}`.toUpperCase(); 12 return `${VITE_GLOB_APP_SHORT_NAME}__${ENV.toUpperCase()}`.toUpperCase();
12 } 13 }
13 14
1 <template> 1 <template>
2 <div class="go-items-list"> 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 <n-grid-item v-for="(item, index) in list" :key="item.id"> 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 </n-grid-item> 7 </n-grid-item>
17 </n-grid> 8 </n-grid>
18 <div class="list-pagination"> 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 </div> 11 </div>
25 </div> 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 </template> 15 </template>
34 16
35 <script setup lang="ts"> 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 // THINGS_KIT 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 // THINGS_KIT 32 // THINGS_KIT
51 const list = ref<ChartList>([]) 33 const list = ref<ChartList>([])
52 onMounted(async () => { 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 </script> 43 </script>
58 44
59 <style lang="scss" scoped> 45 <style lang="scss" scoped>
60 $contentHeight: 250px; 46 $contentHeight: 250px;
  47 +
61 @include go('items-list') { 48 @include go('items-list') {
62 display: flex; 49 display: flex;
63 flex-direction: column; 50 flex-direction: column;
64 justify-content: space-between; 51 justify-content: space-between;
65 min-height: calc(100vh - #{$--header-height} * 2 - 2px); 52 min-height: calc(100vh - #{$--header-height} * 2 - 2px);
  53 +
66 .list-content { 54 .list-content {
67 position: relative; 55 position: relative;
68 height: $contentHeight; 56 height: $contentHeight;
69 } 57 }
  58 +
70 .list-pagination { 59 .list-pagination {
71 display: flex; 60 display: flex;
72 justify-content: flex-end; 61 justify-content: flex-end;
@@ -89,7 +89,7 @@ export default defineConfig(({ mode, command }) => { @@ -89,7 +89,7 @@ export default defineConfig(({ mode, command }) => {
89 chunkSizeWarningLimit: chunkSizeWarningLimit 89 chunkSizeWarningLimit: chunkSizeWarningLimit
90 }, 90 },
91 server: { 91 server: {
92 - port: 5555, 92 + port: viteEnv.VITE_DEV_PORT,
93 proxy: createProxy(viteEnv), 93 proxy: createProxy(viteEnv),
94 }, 94 },
95 } 95 }