refactor: 管理员租户切换不再返回首页 直接刷新当前页(除特殊页面外会回到首页)

This commit is contained in:
dap 2025-04-01 19:59:28 +08:00
parent b67be83a19
commit 362bc84cfb
4 changed files with 44 additions and 12 deletions

View File

@ -5,6 +5,7 @@
- 文件上传/图片上传重构(破坏性更新 不兼容之前的api) - 文件上传/图片上传重构(破坏性更新 不兼容之前的api)
- 文件上传/图片上传**不再支持**url用法 强制使用ossId - 文件上传/图片上传**不再支持**url用法 强制使用ossId
- TableSwitch组件重构 - TableSwitch组件重构
- 管理员租户切换不再返回首页 直接刷新当前页(除特殊页面外会回到首页)
**BUG FIX** **BUG FIX**

View File

@ -1,13 +1,13 @@
<script setup lang="ts"> <script setup lang="ts">
import type { MessageType } from 'ant-design-vue/es/message';
import type { SelectHandler } from 'ant-design-vue/es/vc-select/Select'; import type { SelectHandler } from 'ant-design-vue/es/vc-select/Select';
import type { TenantOption } from '#/api'; import type { TenantOption } from '#/api';
import { computed, onMounted, ref, unref } from 'vue'; import { computed, onMounted, ref, shallowRef, unref } from 'vue';
import { useRouter } from 'vue-router'; import { useRoute } from 'vue-router';
import { useAccess } from '@vben/access'; import { useAccess } from '@vben/access';
import { DEFAULT_HOME_PATH } from '@vben/constants';
import { useTabs } from '@vben/hooks'; import { useTabs } from '@vben/hooks';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
@ -41,15 +41,26 @@ onMounted(async () => {
await initTenant(); await initTenant();
}); });
const { closeAllTabs } = useTabs(); const route = useRoute();
const router = useRouter();
function close(checked: boolean) { const messageInstance = shallowRef<MessageType | null>();
const { closeOtherTabs, refreshTab, closeAllTabs } = useTabs();
async function close(checked: boolean) {
// store // store
setChecked(checked); setChecked(checked);
//
closeAllTabs(); /**
// * 切换租户需要回到首页的页面 一般为带id的页面
router.push(DEFAULT_HOME_PATH); * 其他则直接刷新页面
*/
if (route.meta.requireHomeRedirect) {
await closeAllTabs();
} else {
// Promise.all()
await closeOtherTabs();
await refreshTab();
}
} }
const dictStore = useDictStore(); const dictStore = useDictStore();
@ -65,9 +76,13 @@ const onSelected: SelectHandler = async (tenantId: string, option: any) => {
} }
await tenantDynamicToggle(tenantId); await tenantDynamicToggle(tenantId);
lastSelected.value = tenantId; lastSelected.value = tenantId;
message.success(
// message
messageInstance.value?.();
messageInstance.value = message.success(
`${$t('component.tenantToggle.switch')} ${option.companyName}`, `${$t('component.tenantToggle.switch')} ${option.companyName}`,
); );
close(true); close(true);
// (unknown) // (unknown)
setTimeout(() => dictStore.resetCache()); setTimeout(() => dictStore.resetCache());
@ -75,7 +90,11 @@ const onSelected: SelectHandler = async (tenantId: string, option: any) => {
async function onDeselect() { async function onDeselect() {
await tenantDynamicClear(); await tenantDynamicClear();
message.success($t('component.tenantToggle.reset'));
// message
messageInstance.value?.();
messageInstance.value = message.success($t('component.tenantToggle.reset'));
lastSelected.value = ''; lastSelected.value = '';
close(false); close(false);
// (unknown) // (unknown)

View File

@ -12,6 +12,7 @@ const localRoutes: RouteRecordStringComponent[] = [
icon: 'mingcute:profile-line', icon: 'mingcute:profile-line',
title: $t('ui.widgets.profile'), title: $t('ui.widgets.profile'),
hideInMenu: true, hideInMenu: true,
requireHomeRedirect: true,
}, },
name: 'Profile', name: 'Profile',
path: '/profile', path: '/profile',
@ -23,6 +24,7 @@ const localRoutes: RouteRecordStringComponent[] = [
icon: 'ant-design:setting-outlined', icon: 'ant-design:setting-outlined',
title: 'oss配置', title: 'oss配置',
hideInMenu: true, hideInMenu: true,
requireHomeRedirect: true,
}, },
name: 'OssConfig', name: 'OssConfig',
path: '/system/oss-config', path: '/system/oss-config',
@ -34,6 +36,7 @@ const localRoutes: RouteRecordStringComponent[] = [
icon: 'tabler:code', icon: 'tabler:code',
title: '生成配置', title: '生成配置',
hideInMenu: true, hideInMenu: true,
requireHomeRedirect: true,
}, },
name: 'GenConfig', name: 'GenConfig',
path: '/code-gen/edit/:tableId', path: '/code-gen/edit/:tableId',
@ -45,6 +48,7 @@ const localRoutes: RouteRecordStringComponent[] = [
icon: 'eos-icons:role-binding-outlined', icon: 'eos-icons:role-binding-outlined',
title: '分配角色', title: '分配角色',
hideInMenu: true, hideInMenu: true,
requireHomeRedirect: true,
}, },
name: 'RoleAssign', name: 'RoleAssign',
path: '/system/role-assign/:roleId', path: '/system/role-assign/:roleId',
@ -56,6 +60,7 @@ const localRoutes: RouteRecordStringComponent[] = [
icon: 'fluent-mdl2:flow', icon: 'fluent-mdl2:flow',
title: '流程设计', title: '流程设计',
hideInMenu: true, hideInMenu: true,
requireHomeRedirect: true,
}, },
name: 'WorkflowDesigner', name: 'WorkflowDesigner',
path: '/workflow/designer', path: '/workflow/designer',
@ -70,6 +75,7 @@ const localRoutes: RouteRecordStringComponent[] = [
title: '请假申请', title: '请假申请',
activePath: '/demo/leave', activePath: '/demo/leave',
hideInMenu: true, hideInMenu: true,
requireHomeRedirect: true,
}, },
name: 'WorkflowLeaveIndex', name: 'WorkflowLeaveIndex',
path: '/workflow/leaveEdit/index', path: '/workflow/leaveEdit/index',

View File

@ -113,6 +113,12 @@ interface RouteMeta {
* *
*/ */
query?: Recordable; query?: Recordable;
/**
*
* /oss/:id
* false
*/
requireHomeRedirect?: boolean;
/** /**
* *
*/ */