fix: 文件乱码修复,代码生成指定ts类型,登录移除租户选择
This commit is contained in:
@@ -31,11 +31,18 @@ const GeneratorAPI = {
|
||||
},
|
||||
|
||||
/** 获取代码生成预览数据 */
|
||||
getPreviewData(tableName: string, pageType?: "classic" | "curd") {
|
||||
getPreviewData(tableName: string, pageType?: "classic" | "curd", type?: "ts" | "js") {
|
||||
const params: Record<string, string> = {};
|
||||
if (pageType) {
|
||||
params.pageType = pageType;
|
||||
}
|
||||
if (type) {
|
||||
params.type = type;
|
||||
}
|
||||
return request<any, GeneratorPreviewItem[]>({
|
||||
url: `${GENERATOR_BASE_URL}/${tableName}/preview`,
|
||||
method: "get",
|
||||
params: pageType ? { pageType } : undefined,
|
||||
params: Object.keys(params).length ? params : undefined,
|
||||
});
|
||||
},
|
||||
|
||||
@@ -52,11 +59,18 @@ const GeneratorAPI = {
|
||||
* @param url
|
||||
* @param fileName
|
||||
*/
|
||||
download(tableName: string, pageType?: "classic" | "curd") {
|
||||
download(tableName: string, pageType?: "classic" | "curd", type?: "ts" | "js") {
|
||||
const params: Record<string, string> = {};
|
||||
if (pageType) {
|
||||
params.pageType = pageType;
|
||||
}
|
||||
if (type) {
|
||||
params.type = type;
|
||||
}
|
||||
return request({
|
||||
url: `${GENERATOR_BASE_URL}/${tableName}/download`,
|
||||
method: "get",
|
||||
params: pageType ? { pageType } : undefined,
|
||||
params: Object.keys(params).length ? params : undefined,
|
||||
responseType: "blob",
|
||||
}).then((response) => {
|
||||
const contentDisposition = response?.headers?.["content-disposition"] as string | undefined;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<template>
|
||||
<template>
|
||||
<el-select
|
||||
v-if="type === 'select'"
|
||||
v-model="selectedValue"
|
||||
@@ -90,7 +90,7 @@ const selectedValue = ref<any>(
|
||||
: undefined
|
||||
);
|
||||
|
||||
// 监å<EFBFBD>¬ modelValue å’?options çš„å<EFBFBD>˜åŒ?
|
||||
// 监听 modelValue 和 options 的变化
|
||||
watch(
|
||||
[() => props.modelValue, () => options.value],
|
||||
([newValue, newOptions]) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<template>
|
||||
<template>
|
||||
<template v-if="tagType">
|
||||
<el-tag :type="tagType" :size="tagSize">{{ label }}</el-tag>
|
||||
</template>
|
||||
@@ -12,7 +12,7 @@ import { useDictStore } from "@/store";
|
||||
|
||||
const props = defineProps({
|
||||
code: String, // 字典编码
|
||||
modelValue: [String, Number], // å—典项的å€?
|
||||
modelValue: [String, Number], // 字典项的值
|
||||
size: {
|
||||
type: String,
|
||||
default: "default", // 标签大小
|
||||
@@ -26,10 +26,10 @@ const tagSize = ref<"default" | "large" | "small">(props.size as "default" | "la
|
||||
const dictStore = useDictStore();
|
||||
|
||||
/**
|
||||
* æ ¹æ<EFBFBD>®å—典项的值获å<EFBFBD>–对应的 label å’?tagType
|
||||
* 根据字典项的值获取对应的 label 和 tagType
|
||||
* @param dictCode 字典编码
|
||||
* @param value å—典项的å€?
|
||||
* @returns 包å<EFBFBD>« label å’?tagType 的对è±?
|
||||
* @param value 字典项的值
|
||||
* @returns 包含 label 和 tagType 的对象
|
||||
*/
|
||||
const getLabelAndTagByValue = async (dictCode: string, value: any) => {
|
||||
// 按需加载字典数据
|
||||
@@ -45,7 +45,7 @@ const getLabelAndTagByValue = async (dictCode: string, value: any) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* æ›´æ–° label å’?tagType
|
||||
* 更新 label 和 tagType
|
||||
*/
|
||||
const updateLabelAndTag = async () => {
|
||||
if (!props.code || props.modelValue === undefined) return;
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
<div class="flex-y-center">
|
||||
<!-- 菜单折叠按钮 -->
|
||||
<Hamburger :is-active="isSidebarOpened" @toggle-click="toggleSideBar" />
|
||||
<!-- é<EFBFBD>¢åŒ…屑导èˆ?-->
|
||||
<!-- 面包屑导行栏-->
|
||||
<Breadcrumb />
|
||||
</div>
|
||||
<!-- 导航æ <EFBFBD>æ“<EFBFBD>作区åŸ?-->
|
||||
<!-- 导航栏操作区域-->
|
||||
<div class="navbar__actions">
|
||||
<LayoutToolbar />
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
@open="onMenuOpen"
|
||||
@close="onMenuClose"
|
||||
>
|
||||
<!-- 闖懷黒鬘?-->
|
||||
<!-- 菜单项 -->
|
||||
<LayoutSidebarItem
|
||||
v-for="route in data"
|
||||
:key="route.path"
|
||||
@@ -63,10 +63,10 @@ const expandedMenuIndexes = ref<string[]>([]);
|
||||
// 获取主题
|
||||
const theme = computed(() => settingsStore.theme);
|
||||
|
||||
// 闔キ蜿匁オ<EFBFBD>牡荳サ鬚倅ク狗噪萓ァ霎ケ譬城<EFBFBD>濶イ譁ケ譯?
|
||||
// 获取浅色主题下的侧边栏配色方案
|
||||
const sidebarColorScheme = computed(() => settingsStore.sidebarColorScheme);
|
||||
|
||||
// 闖懷黒荳サ鬚伜ア樊?
|
||||
// 菜单主题属性
|
||||
const menuThemeProps = computed(() => {
|
||||
const isDarkOrClassicBlue =
|
||||
theme.value === "dark" || sidebarColorScheme.value === SidebarColor.CLASSIC_BLUE;
|
||||
@@ -78,11 +78,11 @@ const menuThemeProps = computed(() => {
|
||||
};
|
||||
});
|
||||
|
||||
// 隶。邂怜ス灘燕豼豢サ逧<EFBFBD>除蜊暮。?
|
||||
// 计算当前激活的菜单项
|
||||
const activeMenuPath = computed((): string => {
|
||||
const { meta, path } = currentRoute;
|
||||
|
||||
// 螯よ棡霍ッ逕アmeta荳ュ隶セ鄂ョ莠<EFBFBD>ctiveMenu<EFBFBD>悟<EFBFBD>菴ソ逕ィ螳<EFBFBD>シ育畑莠主、<EFBFBD>炊荳莠帷音谿頑ュ蜀オ<EFBFBD>悟ヲりッヲ諠<EFBFBD>。オ<EFBFBD>?
|
||||
// 如果路由 meta 中设置了 activeMenu,则使用它(用于处理一些特殊情况,如详情页等)
|
||||
if (meta?.activeMenu && typeof meta.activeMenu === "string") {
|
||||
return meta.activeMenu;
|
||||
}
|
||||
@@ -94,8 +94,8 @@ const activeMenuPath = computed((): string => {
|
||||
/**
|
||||
* 获取完整路径
|
||||
*
|
||||
* @param routePath 蠖灘燕霍ッ逕ア逧<EFBFBD>嶌蟇ケ霍ッ蠕? /user
|
||||
* @returns 螳梧紛逧<EFBFBD>サ晏ッケ霍ッ蠕?D://vue3-element-admin/system/user
|
||||
* @param routePath 当前路由的相对路径 /user
|
||||
* @returns 完整的绝对路径 D://vue3-element-admin/system/user
|
||||
*/
|
||||
function resolveFullPath(routePath: string) {
|
||||
if (isExternal(routePath)) {
|
||||
@@ -143,8 +143,8 @@ watch(
|
||||
);
|
||||
|
||||
/**
|
||||
* 逶大成闖懷黒讓。蠑丞序蛹厄シ壼ス楢除蜊墓ィ。蠑丞<EFBFBD>謐「荳コ豌エ蟷ウ讓。蠑乗慮<EFBFBD>悟<EFBFBD>髣ュ謇譛牙ア募シ逧<EFBFBD>除蜊暮。ケ<EFBFBD>?
|
||||
* 驕ソ蜈榊惠豌エ蟷ウ讓。蠑丈ク玖除蜊暮。ケ譏セ遉コ髞吩ス阪?
|
||||
* 监听菜单模式变化:当菜单模式切换为水平模式时,关闭所有展开的菜单项
|
||||
* 避免在水平模式下菜单项显示错位
|
||||
*/
|
||||
watch(
|
||||
() => props.menuMode,
|
||||
@@ -156,7 +156,7 @@ watch(
|
||||
);
|
||||
|
||||
/**
|
||||
* 逶大成豼豢サ闖懷黒蜿伜喧<EFBFBD>御クコ蛹<EFBFBD>性豼豢サ蟄占除蜊慕噪辷カ闖懷黒豺サ蜉<EFBFBD>譬キ蠑冗ア?
|
||||
* 监听激活菜单变化,为包含激活子菜单的父菜单添加样式
|
||||
*/
|
||||
watch(
|
||||
() => activeMenuPath.value,
|
||||
@@ -169,7 +169,7 @@ watch(
|
||||
);
|
||||
|
||||
/**
|
||||
* 逶大成霍ッ逕ア蜿伜喧<EFBFBD>檎。ョ菫晁除蜊戊<EFBFBD>髫週agsView蛻<EFBFBD>困閠梧ュ」遑ョ豼豢?
|
||||
* 监听路由变化,确保菜单能随 TagsView 切换而正确激活
|
||||
*/
|
||||
watch(
|
||||
() => currentRoute.path,
|
||||
@@ -181,7 +181,7 @@ watch(
|
||||
);
|
||||
|
||||
/**
|
||||
* 譖エ譁ー辷カ闖懷黒譬キ蠑?- 荳コ蛹<EFBDBA>性豼豢サ蟄占除蜊慕噪辷カ闖懷黒豺サ蜉<EFBDBB> has-active-child 邀?
|
||||
* 更新父菜单样式 - 为包含激活子菜单的父菜单添加 has-active-child 类
|
||||
*/
|
||||
function updateParentMenuStyles() {
|
||||
if (!menuRef.value?.$el) return;
|
||||
@@ -191,13 +191,13 @@ function updateParentMenuStyles() {
|
||||
const menuEl = menuRef.value?.$el as HTMLElement;
|
||||
if (!menuEl) return;
|
||||
|
||||
// 遘サ髯、謇譛臥鴫譛臥噪 has-active-child 邀?
|
||||
// 移除所有现有的 has-active-child 类
|
||||
const allSubMenus = menuEl.querySelectorAll(".el-sub-menu");
|
||||
allSubMenus.forEach((subMenu) => {
|
||||
subMenu.classList.remove("has-active-child");
|
||||
});
|
||||
|
||||
// 譟・謇セ蠖灘燕豼豢サ逧<EFBFBD>除蜊暮。?
|
||||
// 查找当前激活的菜单项
|
||||
const activeMenuItem = menuEl.querySelector(".el-menu-item.is-active");
|
||||
|
||||
if (activeMenuItem) {
|
||||
@@ -210,12 +210,12 @@ function updateParentMenuStyles() {
|
||||
parent = parent.parentElement;
|
||||
}
|
||||
} else {
|
||||
// 豌エ蟷ウ讓。蠑丈ク句庄閭ス髴隕∫音谿雁、<EFBFBD><EFBFBD>?
|
||||
// 水平模式下可能需要特殊处理
|
||||
if (props.menuMode === "horizontal") {
|
||||
// 蟇ケ莠取ーエ蟷ウ闖懷黒<EFBFBD>御スソ逕ィ霍ッ蠕<EFBFBD>源驟肴擂謇セ蛻ー辷カ闖懷<EFBFBD>?
|
||||
// 对于水平菜单,使用路径匹配来找到父菜单
|
||||
const currentPath = activeMenuPath.value;
|
||||
|
||||
// 譟・謇セ謇譛臥宛闖懷黒鬘ケ<EFBFBD>梧」譟・蜩ェ荳ェ蛹<EFBFBD>性蠖灘燕霍ッ蠕?
|
||||
// 查找所有父菜单项,检查哪个包含当前路径
|
||||
allSubMenus.forEach((subMenu) => {
|
||||
const subMenuEl = subMenu as HTMLElement;
|
||||
const subMenuPath =
|
||||
@@ -239,7 +239,7 @@ function updateParentMenuStyles() {
|
||||
* 组件挂载后立即更新父菜单样式
|
||||
*/
|
||||
onMounted(() => {
|
||||
// 遑ョ菫晏惠扈<EFBFBD>サカ謖りスス蜷取峩譁ー譬キ蠑擾シ御ク堺セ晁オ紋コ主シよュ・謫堺ス?
|
||||
// 确保在组件挂载后更新样式,不依赖于异步操作
|
||||
updateParentMenuStyles();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -94,18 +94,18 @@ const router = useRouter();
|
||||
// 是否为桌面设备
|
||||
const isDesktop = computed(() => appStore.device === DeviceEnum.DESKTOP);
|
||||
|
||||
// 是否显示租户选择(如果用户有多个租户,则显示租户选择器)
|
||||
// 最小侵入:只有在多租户模式下(租户列表长度 > 1)才显示
|
||||
const isPlatformUser = computed(() => {
|
||||
return (userStore.userInfo?.tenantScope || "").toUpperCase() === "PLATFORM";
|
||||
});
|
||||
|
||||
// 是否显示租户选择(仅平台用户可显式切换租户)
|
||||
const showTenantSelect = computed(() => {
|
||||
// 如果租户列表为空,不显示
|
||||
if (tenantStore.tenantList.length === 0) {
|
||||
if (!isPlatformUser.value) {
|
||||
return false;
|
||||
}
|
||||
// 如果只有一个租户,也不显示(单租户模式,用户无感知)
|
||||
if (tenantStore.tenantList.length === 1) {
|
||||
if (tenantStore.tenantList.length <= 1) {
|
||||
return false;
|
||||
}
|
||||
// 多个租户时才显示
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ export interface UserInfo {
|
||||
nickname?: string;
|
||||
/** 头像URL */
|
||||
avatar?: string;
|
||||
/** 租户身份标识(PLATFORM/TENANT) */
|
||||
tenantScope?: string;
|
||||
/** 角色集合 */
|
||||
roles: string[];
|
||||
/** 权限集合 */
|
||||
|
||||
@@ -540,6 +540,7 @@ const treeData = ref<TreeNode[]>([]);
|
||||
const previewScope = ref<"all" | "frontend" | "backend">("all");
|
||||
const previewTypeOptions = ["ts", "vue", "java", "xml"];
|
||||
const previewTypes = ref<string[]>([...previewTypeOptions]);
|
||||
const frontendType = "ts";
|
||||
|
||||
const filteredTreeData = computed<TreeNode[]>(() => {
|
||||
if (!treeData.value.length) return [];
|
||||
@@ -808,7 +809,11 @@ function handleNextClick() {
|
||||
return;
|
||||
}
|
||||
if (outputMode.value === "zip" || !supportsFSAccess) {
|
||||
GeneratorAPI.download(tableName, (genConfigFormData.value.pageType as any) || "classic");
|
||||
GeneratorAPI.download(
|
||||
tableName,
|
||||
(genConfigFormData.value.pageType as any) || "classic",
|
||||
frontendType
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -904,7 +909,8 @@ async function handlePreview(tableName: string) {
|
||||
try {
|
||||
const data = await GeneratorAPI.getPreviewData(
|
||||
tableName,
|
||||
(genConfigFormData.value.pageType as any) || "classic"
|
||||
(genConfigFormData.value.pageType as any) || "classic",
|
||||
frontendType
|
||||
);
|
||||
dialog.title = `代码生成 ${tableName}`;
|
||||
const tree = buildTree(data);
|
||||
|
||||
@@ -91,30 +91,6 @@
|
||||
</el-link>
|
||||
</div>
|
||||
|
||||
<!-- 租户选择对话框 -->
|
||||
<el-dialog
|
||||
v-model="tenantDialogVisible"
|
||||
title="选择登录租户"
|
||||
:width="isSmallScreen ? '92vw' : '500px'"
|
||||
:fullscreen="isSmallScreen"
|
||||
append-to-body
|
||||
:teleported="true"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="false"
|
||||
:show-close="false"
|
||||
>
|
||||
<div class="tenant-select-content" :style="tenantDialogBodyStyle">
|
||||
<p class="tenant-select-tip">检测到你的账号属于多个租户,请选择登录租户:</p>
|
||||
<TenantSwitcher @change="handleTenantSwitcherChange" />
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="tenantDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :disabled="!selectedTenantId" @click="handleTenantSelected">
|
||||
继续
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 第三方登录 -->
|
||||
<div class="third-party-login">
|
||||
<div class="divider-container">
|
||||
@@ -145,14 +121,10 @@ import AuthAPI from "@/api/auth";
|
||||
import type { LoginRequest } from "@/types/api";
|
||||
import router from "@/router";
|
||||
import { useUserStore } from "@/store";
|
||||
import { useTenantStoreHook } from "@/store/modules/tenant";
|
||||
import TenantSwitcher from "@/components/TenantSwitcher/index.vue";
|
||||
import { AuthStorage } from "@/utils/auth";
|
||||
import { ApiCodeEnum } from "@/enums";
|
||||
|
||||
const { t } = useI18n();
|
||||
const userStore = useUserStore();
|
||||
const tenantStore = useTenantStoreHook();
|
||||
const route = useRoute();
|
||||
|
||||
onMounted(() => getCaptcha());
|
||||
@@ -161,35 +133,10 @@ const loginFormRef = ref<FormInstance>();
|
||||
const loading = ref(false);
|
||||
// 是否大写锁定
|
||||
const isCapsLock = ref(false);
|
||||
const isSmallScreen = useMediaQuery("(max-width: 768px)");
|
||||
// 验证码图片 Base64
|
||||
const captchaBase64 = ref();
|
||||
// 记住我
|
||||
const rememberMe = AuthStorage.getRememberMe();
|
||||
// 租户选择对话框
|
||||
const tenantDialogVisible = ref(false);
|
||||
const selectedTenantId = ref<number | null>(null);
|
||||
|
||||
function handleTenantSwitcherChange(id: number) {
|
||||
selectedTenantId.value = id;
|
||||
tenantStore.currentTenantId = id;
|
||||
const matched = tenantStore.tenantList?.find((t) => t.id === id) || null;
|
||||
tenantStore.currentTenant = matched;
|
||||
}
|
||||
|
||||
const tenantDialogBodyStyle = computed(() => {
|
||||
if (isSmallScreen.value) {
|
||||
return {
|
||||
maxHeight: "calc(100vh - 160px)",
|
||||
overflow: "auto",
|
||||
};
|
||||
}
|
||||
return {
|
||||
maxHeight: "60vh",
|
||||
overflow: "auto",
|
||||
};
|
||||
});
|
||||
|
||||
const loginFormData = ref<LoginRequest>({
|
||||
username: "admin",
|
||||
password: "123456",
|
||||
@@ -258,25 +205,8 @@ async function handleLoginSubmit() {
|
||||
// 登录成功,跳转到目标页面
|
||||
const redirectPath = (route.query.redirect as string) || "/";
|
||||
await router.push(decodeURIComponent(redirectPath));
|
||||
} catch (error: any) {
|
||||
// 检查是否是 choose_tenant 响应
|
||||
if (
|
||||
error?.code === ApiCodeEnum.CHOOSE_TENANT &&
|
||||
Array.isArray(error?.data) &&
|
||||
error.data.length > 0
|
||||
) {
|
||||
// 需要选择租户
|
||||
tenantStore.setTenantList(error.data);
|
||||
selectedTenantId.value = error.data[0]?.id || null;
|
||||
if (selectedTenantId.value) {
|
||||
tenantStore.currentTenantId = selectedTenantId.value;
|
||||
tenantStore.currentTenant =
|
||||
error.data.find((t: any) => t.id === selectedTenantId.value) || null;
|
||||
}
|
||||
tenantDialogVisible.value = true;
|
||||
return; // 等待用户选择租户
|
||||
}
|
||||
// 其他错误,刷新验证码
|
||||
} catch (error) {
|
||||
// 登录失败,刷新验证码
|
||||
getCaptcha();
|
||||
throw error;
|
||||
}
|
||||
@@ -288,36 +218,6 @@ async function handleLoginSubmit() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 租户选择确认后的处理
|
||||
*/
|
||||
async function handleTenantSelected() {
|
||||
if (!selectedTenantId.value) {
|
||||
ElMessage.warning("请选择租户");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
loading.value = true;
|
||||
// 使用选中的租户ID重新登录
|
||||
const loginData = {
|
||||
...loginFormData.value,
|
||||
tenantId: selectedTenantId.value,
|
||||
};
|
||||
await userStore.login(loginData);
|
||||
// 登录成功,关闭对话框并跳转
|
||||
tenantDialogVisible.value = false;
|
||||
const redirectPath = (route.query.redirect as string) || "/";
|
||||
await router.push(decodeURIComponent(redirectPath));
|
||||
} catch (error) {
|
||||
// 登录失败,刷新验证码
|
||||
getCaptcha();
|
||||
console.error("登录失败:", error);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查输入大小写
|
||||
function checkCapsLock(event: KeyboardEvent) {
|
||||
// 防止浏览器密码自动填充时报错
|
||||
@@ -389,14 +289,4 @@ function toOtherForm(type: "register" | "resetPwd") {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tenant-select-content {
|
||||
padding: 20px 0;
|
||||
|
||||
.tenant-select-tip {
|
||||
margin: 0 0 20px;
|
||||
font-size: 14px;
|
||||
color: var(--el-text-color-regular);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user