Merge branch 'develop' of https://gitee.com/youlaiorg/vue3-element-admin into develop
This commit is contained in:
@@ -90,12 +90,11 @@ export interface AiExecuteResponse {
|
|||||||
|
|
||||||
export interface AiCommandRecordPageQuery extends PageQuery {
|
export interface AiCommandRecordPageQuery extends PageQuery {
|
||||||
keywords?: string;
|
keywords?: string;
|
||||||
executeStatus?: string;
|
executeStatus?: number;
|
||||||
parseSuccess?: boolean;
|
parseStatus?: number;
|
||||||
userId?: number;
|
userId?: number;
|
||||||
isDangerous?: boolean;
|
aiProvider?: string;
|
||||||
provider?: string;
|
aiModel?: string;
|
||||||
model?: string;
|
|
||||||
functionName?: string;
|
functionName?: string;
|
||||||
createTime?: [string, string];
|
createTime?: [string, string];
|
||||||
}
|
}
|
||||||
@@ -105,33 +104,23 @@ export interface AiCommandRecordVO {
|
|||||||
userId: number;
|
userId: number;
|
||||||
username: string;
|
username: string;
|
||||||
originalCommand: string;
|
originalCommand: string;
|
||||||
provider?: string;
|
aiProvider?: string;
|
||||||
model?: string;
|
aiModel?: string;
|
||||||
parseSuccess?: boolean;
|
parseStatus?: number;
|
||||||
functionCalls?: string;
|
functionCalls?: string;
|
||||||
explanation?: string;
|
explanation?: string;
|
||||||
confidence?: number;
|
confidence?: number;
|
||||||
parseErrorMessage?: string;
|
parseErrorMessage?: string;
|
||||||
inputTokens?: number;
|
inputTokens?: number;
|
||||||
outputTokens?: number;
|
outputTokens?: number;
|
||||||
totalTokens?: number;
|
parseDurationMs?: number;
|
||||||
parseTime?: number;
|
|
||||||
functionName?: string;
|
functionName?: string;
|
||||||
functionArguments?: string;
|
functionArguments?: string;
|
||||||
executeStatus?: string;
|
executeStatus?: number;
|
||||||
executeResult?: string;
|
|
||||||
executeErrorMessage?: string;
|
executeErrorMessage?: string;
|
||||||
affectedRows?: number;
|
|
||||||
isDangerous?: boolean;
|
|
||||||
requiresConfirmation?: boolean;
|
|
||||||
userConfirmed?: boolean;
|
|
||||||
executionTime?: number;
|
|
||||||
ipAddress?: string;
|
ipAddress?: string;
|
||||||
userAgent?: string;
|
|
||||||
currentRoute?: string;
|
|
||||||
createTime?: string;
|
createTime?: string;
|
||||||
updateTime?: string;
|
updateTime?: string;
|
||||||
remark?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -180,9 +169,9 @@ class AiCommandApi {
|
|||||||
/**
|
/**
|
||||||
* 撤销命令执行(如果支持)
|
* 撤销命令执行(如果支持)
|
||||||
*/
|
*/
|
||||||
static rollbackCommand(recordId: string) {
|
static rollbackCommand(logId: string) {
|
||||||
return request({
|
return request({
|
||||||
url: `/api/v1/ai/command/rollback/${recordId}`,
|
url: `/api/v1/ai/command/rollback/${logId}`,
|
||||||
method: "post",
|
method: "post",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,18 +4,16 @@ const AUTH_BASE_URL = "/api/v1/auth";
|
|||||||
|
|
||||||
const AuthAPI = {
|
const AuthAPI = {
|
||||||
/** 登录接口*/
|
/** 登录接口*/
|
||||||
login(data: LoginFormData) {
|
login(data: LoginRequest) {
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("username", data.username);
|
|
||||||
formData.append("password", data.password);
|
|
||||||
formData.append("captchaKey", data.captchaKey);
|
|
||||||
formData.append("captchaCode", data.captchaCode);
|
|
||||||
return request<any, LoginResult>({
|
return request<any, LoginResult>({
|
||||||
url: `${AUTH_BASE_URL}/login`,
|
url: `${AUTH_BASE_URL}/login`,
|
||||||
method: "post",
|
method: "post",
|
||||||
data: formData,
|
data: {
|
||||||
headers: {
|
username: data.username,
|
||||||
"Content-Type": "multipart/form-data",
|
password: data.password,
|
||||||
|
captchaId: data.captchaId,
|
||||||
|
captchaCode: data.captchaCode,
|
||||||
|
tenantId: data.tenantId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -51,18 +49,20 @@ const AuthAPI = {
|
|||||||
|
|
||||||
export default AuthAPI;
|
export default AuthAPI;
|
||||||
|
|
||||||
/** 登录表单数据 */
|
/** 登录请求参数 */
|
||||||
export interface LoginFormData {
|
export interface LoginRequest {
|
||||||
/** 用户名 */
|
/** 用户名 */
|
||||||
username: string;
|
username: string;
|
||||||
/** 密码 */
|
/** 密码 */
|
||||||
password: string;
|
password: string;
|
||||||
/** 验证码缓存key */
|
/** 验证码缓存ID */
|
||||||
captchaKey: string;
|
captchaId?: string;
|
||||||
/** 验证码 */
|
/** 验证码 */
|
||||||
captchaCode: string;
|
captchaCode?: string;
|
||||||
/** 记住我 */
|
/** 记住我(前端使用,不发送到后端) */
|
||||||
rememberMe: boolean;
|
rememberMe?: boolean;
|
||||||
|
/** 租户ID(可选,多租户模式下用于指定租户) */
|
||||||
|
tenantId?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 登录响应 */
|
/** 登录响应 */
|
||||||
@@ -79,8 +79,8 @@ export interface LoginResult {
|
|||||||
|
|
||||||
/** 验证码信息 */
|
/** 验证码信息 */
|
||||||
export interface CaptchaInfo {
|
export interface CaptchaInfo {
|
||||||
/** 验证码缓存key */
|
/** 验证码缓存ID */
|
||||||
captchaKey: string;
|
captchaId: string;
|
||||||
/** 验证码图片Base64字符串 */
|
/** 验证码图片Base64字符串 */
|
||||||
captchaBase64: string;
|
captchaBase64: string;
|
||||||
}
|
}
|
||||||
|
|||||||
68
src/api/system/tenant-api.ts
Normal file
68
src/api/system/tenant-api.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import request from "@/utils/request";
|
||||||
|
|
||||||
|
const TENANT_BASE_URL = "/api/v1/tenants";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户信息
|
||||||
|
*/
|
||||||
|
export interface TenantInfo {
|
||||||
|
/** 租户ID */
|
||||||
|
id: number;
|
||||||
|
/** 租户名称 */
|
||||||
|
name: string;
|
||||||
|
/** 租户编码 */
|
||||||
|
code?: string;
|
||||||
|
/** 租户状态(1-正常 0-禁用) */
|
||||||
|
status?: number;
|
||||||
|
/** 联系人姓名 */
|
||||||
|
contactName?: string;
|
||||||
|
/** 联系人电话 */
|
||||||
|
contactPhone?: string;
|
||||||
|
/** 联系人邮箱 */
|
||||||
|
contactEmail?: string;
|
||||||
|
/** 租户域名 */
|
||||||
|
domain?: string;
|
||||||
|
/** 租户Logo */
|
||||||
|
logo?: string;
|
||||||
|
/** 是否默认租户 */
|
||||||
|
isDefault?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户 API
|
||||||
|
*/
|
||||||
|
const TenantAPI = {
|
||||||
|
/**
|
||||||
|
* 获取当前用户的租户列表
|
||||||
|
*/
|
||||||
|
getTenantList() {
|
||||||
|
return request<any, TenantInfo[]>({
|
||||||
|
url: `${TENANT_BASE_URL}`,
|
||||||
|
method: "get",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前租户信息
|
||||||
|
*/
|
||||||
|
getCurrentTenant() {
|
||||||
|
return request<any, TenantInfo>({
|
||||||
|
url: `${TENANT_BASE_URL}/current`,
|
||||||
|
method: "get",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切换租户
|
||||||
|
*
|
||||||
|
* @param tenantId 目标租户ID
|
||||||
|
*/
|
||||||
|
switchTenant(tenantId: number) {
|
||||||
|
return request<any, TenantInfo>({
|
||||||
|
url: `${TENANT_BASE_URL}/${tenantId}/switch`,
|
||||||
|
method: "post",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TenantAPI;
|
||||||
@@ -23,7 +23,7 @@ type ToolbarTable = "edit" | "view" | "delete";
|
|||||||
export type IToolsButton = {
|
export type IToolsButton = {
|
||||||
name: string; // 按钮名称
|
name: string; // 按钮名称
|
||||||
text?: string; // 按钮文本
|
text?: string; // 按钮文本
|
||||||
perm?: Array<string> | string; // 权限标识(可以是完整权限字符串如'sys:user:add'或操作权限如'add')
|
perm?: Array<string> | string; // 权限标识(可以是完整权限字符串如'sys:user:create'或操作权限如'create')
|
||||||
attrs?: Partial<ButtonProps> & { style?: CSSProperties }; // 按钮属性
|
attrs?: Partial<ButtonProps> & { style?: CSSProperties }; // 按钮属性
|
||||||
render?: (row: IObject) => boolean; // 条件渲染
|
render?: (row: IObject) => boolean; // 条件渲染
|
||||||
};
|
};
|
||||||
|
|||||||
152
src/components/TenantSelect/index.vue
Normal file
152
src/components/TenantSelect/index.vue
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
<template>
|
||||||
|
<el-dropdown trigger="click" @command="handleTenantSwitch">
|
||||||
|
<div class="tenant-select">
|
||||||
|
<el-icon class="tenant-select__icon"><OfficeBuilding /></el-icon>
|
||||||
|
<span class="tenant-select__name">{{ currentTenantName }}</span>
|
||||||
|
<el-icon class="tenant-select__arrow"><ArrowDown /></el-icon>
|
||||||
|
</div>
|
||||||
|
<template #dropdown>
|
||||||
|
<el-dropdown-menu>
|
||||||
|
<el-dropdown-item
|
||||||
|
v-for="tenant in tenantList"
|
||||||
|
:key="tenant.id"
|
||||||
|
:command="tenant.id"
|
||||||
|
:class="{ 'is-active': tenant.id === currentTenantId }"
|
||||||
|
>
|
||||||
|
<div class="tenant-item">
|
||||||
|
<span class="tenant-item__name">{{ tenant.name }}</span>
|
||||||
|
<el-icon v-if="tenant.id === currentTenantId" class="tenant-item__check">
|
||||||
|
<Check />
|
||||||
|
</el-icon>
|
||||||
|
</div>
|
||||||
|
</el-dropdown-item>
|
||||||
|
</el-dropdown-menu>
|
||||||
|
</template>
|
||||||
|
</el-dropdown>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, onMounted } from "vue";
|
||||||
|
import { useTenantStoreHook } from "@/store/modules/tenant-store";
|
||||||
|
import { ElMessage } from "element-plus";
|
||||||
|
import { OfficeBuilding, ArrowDown, Check } from "@element-plus/icons-vue";
|
||||||
|
|
||||||
|
const tenantStore = useTenantStoreHook();
|
||||||
|
|
||||||
|
// 当前租户名称
|
||||||
|
const currentTenantName = computed(() => {
|
||||||
|
if (tenantStore.currentTenant?.name) {
|
||||||
|
return tenantStore.currentTenant.name;
|
||||||
|
}
|
||||||
|
// 如果当前租户信息不存在,尝试从租户列表中查找
|
||||||
|
if (tenantStore.currentTenantId) {
|
||||||
|
const tenant = tenantStore.tenantList.find((t) => t.id === tenantStore.currentTenantId);
|
||||||
|
if (tenant) {
|
||||||
|
return tenant.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "未选择租户";
|
||||||
|
});
|
||||||
|
|
||||||
|
// 当前租户ID
|
||||||
|
const currentTenantId = computed(() => tenantStore.currentTenantId);
|
||||||
|
|
||||||
|
// 租户列表
|
||||||
|
const tenantList = computed(() => tenantStore.tenantList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切换租户
|
||||||
|
*/
|
||||||
|
async function handleTenantSwitch(tenantId: number) {
|
||||||
|
if (tenantId === currentTenantId.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await tenantStore.switchTenant(tenantId);
|
||||||
|
ElMessage.success("切换租户成功");
|
||||||
|
// 刷新页面以重新加载菜单和权限
|
||||||
|
window.location.reload();
|
||||||
|
} catch (error: any) {
|
||||||
|
ElMessage.error(error.message || "切换租户失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化:获取租户列表
|
||||||
|
onMounted(() => {
|
||||||
|
tenantStore.fetchTenantList().catch((error) => {
|
||||||
|
console.error("获取租户列表失败:", error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.tenant-select {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
height: 100%;
|
||||||
|
padding: 0 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: all 0.3s;
|
||||||
|
|
||||||
|
&__icon {
|
||||||
|
margin-right: 6px;
|
||||||
|
font-size: 18px;
|
||||||
|
color: inherit;
|
||||||
|
transition: color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__name {
|
||||||
|
max-width: 100px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
font-size: 14px;
|
||||||
|
color: inherit;
|
||||||
|
white-space: nowrap;
|
||||||
|
transition: color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__arrow {
|
||||||
|
margin-left: 6px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: inherit;
|
||||||
|
opacity: 0.7;
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: rgba(0, 0, 0, 0.04);
|
||||||
|
|
||||||
|
.tenant-select__icon,
|
||||||
|
.tenant-select__name {
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-select__arrow {
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
&__name {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__check {
|
||||||
|
margin-left: 8px;
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-dropdown-menu__item.is-active) {
|
||||||
|
background-color: var(--el-color-primary-light-9);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
187
src/components/TenantSelectDialog/index.vue
Normal file
187
src/components/TenantSelectDialog/index.vue
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
v-model="visible"
|
||||||
|
title="选择租户"
|
||||||
|
width="400px"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:close-on-press-escape="false"
|
||||||
|
:show-close="false"
|
||||||
|
>
|
||||||
|
<div v-if="loading" class="tenant-dialog-loading">
|
||||||
|
<el-icon class="is-loading"><Loading /></el-icon>
|
||||||
|
<span>加载租户列表...</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="tenantList.length === 0" class="tenant-dialog-empty">
|
||||||
|
<el-empty description="暂无可用租户" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-radio-group v-else v-model="selectedTenantId" class="tenant-radio-group">
|
||||||
|
<el-radio
|
||||||
|
v-for="tenant in tenantList"
|
||||||
|
:key="tenant.id"
|
||||||
|
:label="tenant.id"
|
||||||
|
class="tenant-radio-item"
|
||||||
|
>
|
||||||
|
<div class="tenant-radio-content">
|
||||||
|
<div class="tenant-radio-content__name">{{ tenant.name }}</div>
|
||||||
|
<div v-if="tenant.code" class="tenant-radio-content__code">{{ tenant.code }}</div>
|
||||||
|
</div>
|
||||||
|
</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="handleCancel">取消</el-button>
|
||||||
|
<el-button type="primary" :loading="switching" @click="handleConfirm">确定</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, watch } from "vue";
|
||||||
|
import { useTenantStoreHook } from "@/store/modules/tenant-store";
|
||||||
|
import { ElMessage } from "element-plus";
|
||||||
|
import { Loading } from "@element-plus/icons-vue";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
modelValue: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
"update:modelValue": [value: boolean];
|
||||||
|
confirm: [];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const tenantStore = useTenantStoreHook();
|
||||||
|
|
||||||
|
const visible = computed({
|
||||||
|
get: () => props.modelValue,
|
||||||
|
set: (value) => emit("update:modelValue", value),
|
||||||
|
});
|
||||||
|
|
||||||
|
const loading = ref(false);
|
||||||
|
const switching = ref(false);
|
||||||
|
const selectedTenantId = ref<number | null>(null);
|
||||||
|
const tenantList = computed(() => tenantStore.tenantList);
|
||||||
|
|
||||||
|
// 监听对话框打开,加载租户列表
|
||||||
|
watch(visible, (newVal) => {
|
||||||
|
if (newVal) {
|
||||||
|
loadTenantList();
|
||||||
|
// 默认选择当前租户或第一个租户
|
||||||
|
selectedTenantId.value = tenantStore.currentTenantId || tenantList.value[0]?.id || null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载租户列表
|
||||||
|
*/
|
||||||
|
async function loadTenantList() {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
await tenantStore.fetchTenantList();
|
||||||
|
// 如果列表为空,自动关闭对话框
|
||||||
|
if (tenantList.value.length === 0) {
|
||||||
|
visible.value = false;
|
||||||
|
ElMessage.warning("您暂无可用租户");
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
ElMessage.error(error.message || "获取租户列表失败");
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认选择
|
||||||
|
*/
|
||||||
|
async function handleConfirm() {
|
||||||
|
if (!selectedTenantId.value) {
|
||||||
|
ElMessage.warning("请选择租户");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switching.value = true;
|
||||||
|
try {
|
||||||
|
await tenantStore.switchTenant(selectedTenantId.value);
|
||||||
|
ElMessage.success("切换租户成功");
|
||||||
|
visible.value = false;
|
||||||
|
emit("confirm");
|
||||||
|
} catch (error: any) {
|
||||||
|
ElMessage.error(error.message || "切换租户失败");
|
||||||
|
} finally {
|
||||||
|
switching.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消
|
||||||
|
*/
|
||||||
|
function handleCancel() {
|
||||||
|
// 如果用户没有租户,不允许取消
|
||||||
|
if (tenantList.value.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
visible.value = false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.tenant-dialog-loading {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 40px 0;
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-dialog-empty {
|
||||||
|
padding: 20px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-radio-group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-radio-item {
|
||||||
|
width: 100%;
|
||||||
|
padding: 12px;
|
||||||
|
margin: 0;
|
||||||
|
border: 1px solid var(--el-border-color-light);
|
||||||
|
border-radius: 6px;
|
||||||
|
transition: all 0.3s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--el-color-primary-light-9);
|
||||||
|
border-color: var(--el-color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-radio__input.is-checked) {
|
||||||
|
.el-radio__inner {
|
||||||
|
background-color: var(--el-color-primary);
|
||||||
|
border-color: var(--el-color-primary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-radio-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
|
||||||
|
&__name {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--el-text-color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
&__code {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -13,7 +13,7 @@ export const hasPerm: Directive = {
|
|||||||
// 校验传入的权限值是否合法
|
// 校验传入的权限值是否合法
|
||||||
if (!requiredPerms || (typeof requiredPerms !== "string" && !Array.isArray(requiredPerms))) {
|
if (!requiredPerms || (typeof requiredPerms !== "string" && !Array.isArray(requiredPerms))) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"需要提供权限标识!例如:v-has-perm=\"'sys:user:add'\" 或 v-has-perm=\"['sys:user:add', 'sys:user:edit']\""
|
"需要提供权限标识!例如:v-has-perm=\"'sys:user:create'\" 或 v-has-perm=\"['sys:user:create', 'sys:user:update']\""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,4 +20,9 @@ export const enum ApiCodeEnum {
|
|||||||
* 刷新令牌无效或过期
|
* 刷新令牌无效或过期
|
||||||
*/
|
*/
|
||||||
REFRESH_TOKEN_INVALID = "A0231",
|
REFRESH_TOKEN_INVALID = "A0231",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 需要选择租户
|
||||||
|
*/
|
||||||
|
CHOOSE_TENANT = "A0250",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// 核心枚举定义
|
// 核心枚举定义
|
||||||
export enum MenuTypeEnum {
|
export enum MenuTypeEnum {
|
||||||
CATALOG = 2, // 目录
|
CATALOG = "C", // 目录
|
||||||
MENU = 1, // 菜单
|
MENU = "M", // 菜单
|
||||||
BUTTON = 4, // 按钮
|
BUTTON = "B", // 按钮
|
||||||
EXTLINK = 3, // 外链
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,11 @@
|
|||||||
<div class="navbar-actions__item">
|
<div class="navbar-actions__item">
|
||||||
<Notification />
|
<Notification />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 租户选择(如果启用多租户) -->
|
||||||
|
<div v-if="showTenantSelect" class="navbar-actions__item">
|
||||||
|
<TenantSelect />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- 用户菜单 -->
|
<!-- 用户菜单 -->
|
||||||
@@ -80,11 +85,14 @@ import Fullscreen from "@/components/Fullscreen/index.vue";
|
|||||||
import SizeSelect from "@/components/SizeSelect/index.vue";
|
import SizeSelect from "@/components/SizeSelect/index.vue";
|
||||||
import LangSelect from "@/components/LangSelect/index.vue";
|
import LangSelect from "@/components/LangSelect/index.vue";
|
||||||
import Notification from "@/components/Notification/index.vue";
|
import Notification from "@/components/Notification/index.vue";
|
||||||
|
import TenantSelect from "@/components/TenantSelect/index.vue";
|
||||||
|
import { useTenantStoreHook } from "@/store/modules/tenant-store";
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const settingStore = useSettingsStore();
|
const settingStore = useSettingsStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
const tenantStore = useTenantStoreHook();
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -92,6 +100,21 @@ const router = useRouter();
|
|||||||
// 是否为桌面设备
|
// 是否为桌面设备
|
||||||
const isDesktop = computed(() => appStore.device === DeviceEnum.DESKTOP);
|
const isDesktop = computed(() => appStore.device === DeviceEnum.DESKTOP);
|
||||||
|
|
||||||
|
// 是否显示租户选择(如果用户有多个租户,则显示租户选择器)
|
||||||
|
// 最小侵入:只有在多租户模式下(租户列表长度 > 1)才显示
|
||||||
|
const showTenantSelect = computed(() => {
|
||||||
|
// 如果租户列表为空,不显示
|
||||||
|
if (tenantStore.tenantList.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 如果只有一个租户,也不显示(单租户模式,用户无感知)
|
||||||
|
if (tenantStore.tenantList.length === 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 多个租户时才显示
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打开个人中心页面
|
* 打开个人中心页面
|
||||||
*/
|
*/
|
||||||
@@ -244,6 +267,16 @@ function handleSettingsClick() {
|
|||||||
.user-profile__name {
|
.user-profile__name {
|
||||||
color: rgba(255, 255, 255, 0.85);
|
color: rgba(255, 255, 255, 0.85);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 租户选择器在白色文字模式下的样式
|
||||||
|
:deep(.tenant-select) {
|
||||||
|
color: rgba(255, 255, 255, 0.85);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: #fff;
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 深色文字样式(用于浅色背景:明亮主题下的左侧布局)
|
// 深色文字样式(用于浅色背景:明亮主题下的左侧布局)
|
||||||
@@ -265,6 +298,16 @@ function handleSettingsClick() {
|
|||||||
.user-profile__name {
|
.user-profile__name {
|
||||||
color: var(--el-text-color-regular) !important;
|
color: var(--el-text-color-regular) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 租户选择器在深色文字模式下的样式
|
||||||
|
:deep(.tenant-select) {
|
||||||
|
color: var(--el-text-color-regular) !important;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: var(--el-color-primary) !important;
|
||||||
|
background: rgba(0, 0, 0, 0.04);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确保下拉菜单中的图标不受影响
|
// 确保下拉菜单中的图标不受影响
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { RouteRecordRaw } from "vue-router";
|
|||||||
import NProgress from "@/utils/nprogress";
|
import NProgress from "@/utils/nprogress";
|
||||||
import router from "@/router";
|
import router from "@/router";
|
||||||
import { usePermissionStore, useUserStore } from "@/store";
|
import { usePermissionStore, useUserStore } from "@/store";
|
||||||
|
import { useTenantStoreHook } from "@/store/modules/tenant-store";
|
||||||
|
|
||||||
export function setupPermission() {
|
export function setupPermission() {
|
||||||
const whiteList = ["/login"];
|
const whiteList = ["/login"];
|
||||||
@@ -38,6 +39,12 @@ export function setupPermission() {
|
|||||||
await userStore.getUserInfo();
|
await userStore.getUserInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 登录成功后,尝试获取租户列表和当前租户信息(如果启用多租户)
|
||||||
|
// 最小侵入:如果接口失败,不影响正常流程(可能是单租户模式)
|
||||||
|
const tenantStore = useTenantStoreHook();
|
||||||
|
// 由 tenantStore 内部自行判断前端多租户开关(VITE_APP_TENANT_ENABLED)
|
||||||
|
await tenantStore.prepareTenantContextAfterLogin();
|
||||||
|
|
||||||
const dynamicRoutes = await permissionStore.generateRoutes();
|
const dynamicRoutes = await permissionStore.generateRoutes();
|
||||||
dynamicRoutes.forEach((route: RouteRecordRaw) => {
|
dynamicRoutes.forEach((route: RouteRecordRaw) => {
|
||||||
router.addRoute(route);
|
router.addRoute(route);
|
||||||
|
|||||||
@@ -14,4 +14,5 @@ export * from "./modules/settings-store";
|
|||||||
export * from "./modules/tags-view-store";
|
export * from "./modules/tags-view-store";
|
||||||
export * from "./modules/user-store";
|
export * from "./modules/user-store";
|
||||||
export * from "./modules/dict-store";
|
export * from "./modules/dict-store";
|
||||||
|
export * from "./modules/tenant-store";
|
||||||
export { store };
|
export { store };
|
||||||
|
|||||||
172
src/store/modules/tenant-store.ts
Normal file
172
src/store/modules/tenant-store.ts
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
import { store } from "@/store";
|
||||||
|
import TenantAPI, { type TenantInfo } from "@/api/system/tenant-api";
|
||||||
|
|
||||||
|
// 前端多租户开关;默认开启,若后端未启用多租户可在 .env 设置 VITE_APP_TENANT_ENABLED=false
|
||||||
|
const TENANT_ENABLED = import.meta.env.VITE_APP_TENANT_ENABLED !== "false";
|
||||||
|
|
||||||
|
const TENANT_ID_KEY = "current_tenant_id";
|
||||||
|
const TENANT_INFO_KEY = "current_tenant_info";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户 Store
|
||||||
|
*/
|
||||||
|
export const useTenantStore = defineStore("tenant", () => {
|
||||||
|
// 当前租户ID
|
||||||
|
const currentTenantId = ref<number | null>(null);
|
||||||
|
// 当前租户信息
|
||||||
|
const currentTenant = ref<TenantInfo | null>(null);
|
||||||
|
// 用户可访问的租户列表
|
||||||
|
const tenantList = ref<TenantInfo[]>([]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化租户信息
|
||||||
|
* 从 localStorage 恢复上次使用的租户
|
||||||
|
*/
|
||||||
|
function initTenant() {
|
||||||
|
const savedTenantId = localStorage.getItem(TENANT_ID_KEY);
|
||||||
|
const savedTenantInfo = localStorage.getItem(TENANT_INFO_KEY);
|
||||||
|
|
||||||
|
if (savedTenantId) {
|
||||||
|
currentTenantId.value = Number(savedTenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (savedTenantInfo) {
|
||||||
|
try {
|
||||||
|
currentTenant.value = JSON.parse(savedTenantInfo);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("解析租户信息失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户租户列表
|
||||||
|
*/
|
||||||
|
function fetchTenantList() {
|
||||||
|
return new Promise<TenantInfo[]>((resolve, reject) => {
|
||||||
|
TenantAPI.getTenantList()
|
||||||
|
.then((data) => {
|
||||||
|
tenantList.value = data || [];
|
||||||
|
resolve(data || []);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录后初始化租户:获取列表并尽量确定当前租户
|
||||||
|
* - 忽略错误,以便单租户模式不受影响
|
||||||
|
*/
|
||||||
|
// 登录后准备租户上下文:先取租户列表,再用后端返回的当前租户;若单租户则自动选中
|
||||||
|
async function prepareTenantContextAfterLogin() {
|
||||||
|
if (!TENANT_ENABLED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fetchTenantList();
|
||||||
|
|
||||||
|
if (tenantList.value.length > 0 && !currentTenantId.value) {
|
||||||
|
try {
|
||||||
|
const currentTenantInfo = await TenantAPI.getCurrentTenant();
|
||||||
|
if (currentTenantInfo) {
|
||||||
|
setCurrentTenant(currentTenantInfo);
|
||||||
|
} else if (tenantList.value.length === 1) {
|
||||||
|
setCurrentTenant(tenantList.value[0]);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (tenantList.value.length === 1) {
|
||||||
|
setCurrentTenant(tenantList.value[0]);
|
||||||
|
}
|
||||||
|
console.debug("获取当前租户信息失败(可能是单租户模式):", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.debug("获取租户列表失败(可能是单租户模式):", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置当前租户
|
||||||
|
*
|
||||||
|
* @param tenant 租户信息
|
||||||
|
*/
|
||||||
|
function setCurrentTenant(tenant: TenantInfo) {
|
||||||
|
currentTenantId.value = tenant.id;
|
||||||
|
currentTenant.value = tenant;
|
||||||
|
|
||||||
|
// 保存到 localStorage
|
||||||
|
localStorage.setItem(TENANT_ID_KEY, String(tenant.id));
|
||||||
|
localStorage.setItem(TENANT_INFO_KEY, JSON.stringify(tenant));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切换租户
|
||||||
|
*
|
||||||
|
* @param tenantId 目标租户ID
|
||||||
|
*/
|
||||||
|
function switchTenant(tenantId: number) {
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
TenantAPI.switchTenant(tenantId)
|
||||||
|
.then((tenantInfo) => {
|
||||||
|
// 后端返回切换后的租户信息
|
||||||
|
if (tenantInfo) {
|
||||||
|
setCurrentTenant(tenantInfo);
|
||||||
|
} else {
|
||||||
|
// 如果后端未返回,从租户列表中找到对应的租户信息
|
||||||
|
const tenant = tenantList.value.find((t) => t.id === tenantId);
|
||||||
|
if (tenant) {
|
||||||
|
setCurrentTenant(tenant);
|
||||||
|
} else {
|
||||||
|
// 如果列表中没有,重新获取租户信息
|
||||||
|
TenantAPI.getCurrentTenant()
|
||||||
|
.then((info) => {
|
||||||
|
if (info) {
|
||||||
|
setCurrentTenant(info);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除租户信息
|
||||||
|
*/
|
||||||
|
function clearTenant() {
|
||||||
|
currentTenantId.value = null;
|
||||||
|
currentTenant.value = null;
|
||||||
|
tenantList.value = [];
|
||||||
|
localStorage.removeItem(TENANT_ID_KEY);
|
||||||
|
localStorage.removeItem(TENANT_INFO_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
initTenant();
|
||||||
|
|
||||||
|
return {
|
||||||
|
currentTenantId,
|
||||||
|
currentTenant,
|
||||||
|
tenantList,
|
||||||
|
prepareTenantContextAfterLogin,
|
||||||
|
fetchTenantList,
|
||||||
|
setCurrentTenant,
|
||||||
|
switchTenant,
|
||||||
|
clearTenant,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在组件外部使用 TenantStore 的钩子函数
|
||||||
|
*/
|
||||||
|
export function useTenantStoreHook() {
|
||||||
|
return useTenantStore(store);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { store } from "@/store";
|
import { store } from "@/store";
|
||||||
|
|
||||||
import AuthAPI, { type LoginFormData } from "@/api/auth-api";
|
import AuthAPI, { type LoginRequest } from "@/api/auth-api";
|
||||||
import UserAPI, { type UserInfo } from "@/api/system/user-api";
|
import UserAPI, { type UserInfo } from "@/api/system/user-api";
|
||||||
|
|
||||||
import { AuthStorage } from "@/utils/auth";
|
import { AuthStorage } from "@/utils/auth";
|
||||||
@@ -18,16 +18,16 @@ export const useUserStore = defineStore("user", () => {
|
|||||||
/**
|
/**
|
||||||
* 登录
|
* 登录
|
||||||
*
|
*
|
||||||
* @param {LoginFormData}
|
* @param {LoginRequest}
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function login(LoginFormData: LoginFormData) {
|
function login(loginRequest: LoginRequest) {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
AuthAPI.login(LoginFormData)
|
AuthAPI.login(loginRequest)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
const { accessToken, refreshToken } = data;
|
const { accessToken, refreshToken } = data;
|
||||||
// 保存记住我状态和token
|
// 保存记住我状态和token
|
||||||
rememberMe.value = LoginFormData.rememberMe;
|
rememberMe.value = loginRequest.rememberMe ?? false;
|
||||||
AuthStorage.setTokens(accessToken, refreshToken, rememberMe.value);
|
AuthStorage.setTokens(accessToken, refreshToken, rememberMe.value);
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { ApiCodeEnum } from "@/enums/api/code-enum";
|
|||||||
import { AuthStorage, redirectToLogin } from "@/utils/auth";
|
import { AuthStorage, redirectToLogin } from "@/utils/auth";
|
||||||
import { useTokenRefresh } from "@/composables/auth/useTokenRefresh";
|
import { useTokenRefresh } from "@/composables/auth/useTokenRefresh";
|
||||||
import { authConfig } from "@/settings";
|
import { authConfig } from "@/settings";
|
||||||
|
import { useTenantStoreHook } from "@/store/modules/tenant-store";
|
||||||
|
|
||||||
// 初始化token刷新组合式函数
|
// 初始化token刷新组合式函数
|
||||||
const { refreshTokenAndRetry } = useTokenRefresh();
|
const { refreshTokenAndRetry } = useTokenRefresh();
|
||||||
@@ -19,7 +20,7 @@ const httpRequest = axios.create({
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求拦截器 - 添加 Authorization 头
|
* 请求拦截器 - 添加 Authorization 头和租户ID
|
||||||
*/
|
*/
|
||||||
httpRequest.interceptors.request.use(
|
httpRequest.interceptors.request.use(
|
||||||
(config: InternalAxiosRequestConfig) => {
|
(config: InternalAxiosRequestConfig) => {
|
||||||
@@ -32,6 +33,19 @@ httpRequest.interceptors.request.use(
|
|||||||
delete config.headers.Authorization;
|
delete config.headers.Authorization;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加租户ID到请求头(如果存在)
|
||||||
|
// 注意:只有在登录成功后,tenantStore 才会初始化,所以这里需要 try-catch
|
||||||
|
try {
|
||||||
|
const tenantStore = useTenantStoreHook();
|
||||||
|
const tenantId = tenantStore.currentTenantId;
|
||||||
|
if (tenantId) {
|
||||||
|
config.headers["tenant-id"] = String(tenantId);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// 如果租户 store 未初始化(如登录前),忽略错误
|
||||||
|
// 这是正常的,因为多租户功能是可选的,未启用时不会初始化 tenantStore
|
||||||
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
@@ -57,6 +71,15 @@ httpRequest.interceptors.response.use(
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 特殊处理:需要选择租户(不显示错误提示,返回特殊对象供业务层处理)
|
||||||
|
if (code === ApiCodeEnum.CHOOSE_TENANT) {
|
||||||
|
return Promise.reject({
|
||||||
|
code: ApiCodeEnum.CHOOSE_TENANT,
|
||||||
|
data,
|
||||||
|
msg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 业务错误
|
// 业务错误
|
||||||
ElMessage.error(msg || "系统出错");
|
ElMessage.error(msg || "系统出错");
|
||||||
return Promise.reject(new Error(msg || "Business Error"));
|
return Promise.reject(new Error(msg || "Business Error"));
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item prop="provider" label="AI提供商">
|
<el-form-item prop="aiProvider" label="AI提供商">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="queryParams.provider"
|
v-model="queryParams.aiProvider"
|
||||||
placeholder="请选择"
|
placeholder="请选择"
|
||||||
clearable
|
clearable
|
||||||
style="width: 140px"
|
style="width: 140px"
|
||||||
@@ -27,9 +27,9 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item prop="model" label="AI模型">
|
<el-form-item prop="aiModel" label="AI模型">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="queryParams.model"
|
v-model="queryParams.aiModel"
|
||||||
placeholder="如 qwen-plus"
|
placeholder="如 qwen-plus"
|
||||||
clearable
|
clearable
|
||||||
style="width: 160px"
|
style="width: 160px"
|
||||||
@@ -37,15 +37,15 @@
|
|||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item prop="parseSuccess" label="解析状态">
|
<el-form-item prop="parseStatus" label="解析状态">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="queryParams.parseSuccess"
|
v-model="queryParams.parseStatus"
|
||||||
placeholder="请选择"
|
placeholder="请选择"
|
||||||
clearable
|
clearable
|
||||||
style="width: 140px"
|
style="width: 140px"
|
||||||
>
|
>
|
||||||
<el-option label="成功" :value="true" />
|
<el-option label="成功" :value="1" />
|
||||||
<el-option label="失败" :value="false" />
|
<el-option label="失败" :value="0" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
@@ -56,21 +56,9 @@
|
|||||||
clearable
|
clearable
|
||||||
style="width: 140px"
|
style="width: 140px"
|
||||||
>
|
>
|
||||||
<el-option label="待执行" value="pending" />
|
<el-option label="待执行" :value="0" />
|
||||||
<el-option label="成功" value="success" />
|
<el-option label="成功" :value="1" />
|
||||||
<el-option label="失败" value="failed" />
|
<el-option label="失败" :value="-1" />
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item prop="isDangerous" label="风险操作">
|
|
||||||
<el-select
|
|
||||||
v-model="queryParams.isDangerous"
|
|
||||||
placeholder="请选择"
|
|
||||||
clearable
|
|
||||||
style="width: 140px"
|
|
||||||
>
|
|
||||||
<el-option label="是" :value="true" />
|
|
||||||
<el-option label="否" :value="false" />
|
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
@@ -117,29 +105,27 @@
|
|||||||
min-width="160"
|
min-width="160"
|
||||||
show-overflow-tooltip
|
show-overflow-tooltip
|
||||||
/>
|
/>
|
||||||
<el-table-column label="AI提供商" prop="provider" width="120" />
|
<el-table-column label="AI提供商" prop="aiProvider" width="120" />
|
||||||
<el-table-column label="AI模型" prop="model" width="160" show-overflow-tooltip />
|
<el-table-column label="AI模型" prop="aiModel" width="160" show-overflow-tooltip />
|
||||||
<el-table-column label="解析状态" width="110" align="center">
|
<el-table-column label="解析状态" width="110" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag :type="row.parseSuccess ? 'success' : 'danger'" size="small">
|
<el-tag :type="row.parseStatus === 1 ? 'success' : 'danger'" size="small">
|
||||||
{{ row.parseSuccess ? "成功" : "失败" }}
|
{{ row.parseStatus === 1 ? "成功" : "失败" }}
|
||||||
</el-tag>
|
</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="执行状态" width="110" align="center">
|
<el-table-column label="执行状态" width="110" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag v-if="row.executeStatus" :type="statusTagType[row.executeStatus]" size="small">
|
<el-tag
|
||||||
{{ statusText[row.executeStatus] }}
|
v-if="row.executeStatus !== null && row.executeStatus !== undefined"
|
||||||
|
:type="getExecuteStatusTagType(row.executeStatus)"
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
{{ getExecuteStatusText(row.executeStatus) }}
|
||||||
</el-tag>
|
</el-tag>
|
||||||
<span v-else>-</span>
|
<span v-else>-</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="风险" width="90" align="center">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-tag v-if="row.isDangerous" type="warning" size="small">风险</el-tag>
|
|
||||||
<span v-else>-</span>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="置信度" prop="confidence" width="100" align="center">
|
<el-table-column label="置信度" prop="confidence" width="100" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<span v-if="row.confidence !== undefined && row.confidence !== null">
|
<span v-if="row.confidence !== undefined && row.confidence !== null">
|
||||||
@@ -148,8 +134,7 @@
|
|||||||
<span v-else>-</span>
|
<span v-else>-</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="解析耗时(ms)" prop="parseTime" width="120" align="center" />
|
<el-table-column label="解析耗时(ms)" prop="parseDurationMs" width="120" align="center" />
|
||||||
<el-table-column label="执行耗时(ms)" prop="executionTime" width="120" align="center" />
|
|
||||||
<el-table-column label="IP地址" prop="ipAddress" width="140" />
|
<el-table-column label="IP地址" prop="ipAddress" width="140" />
|
||||||
<el-table-column label="操作" width="100" align="center" fixed="right">
|
<el-table-column label="操作" width="100" align="center" fixed="right">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
@@ -180,15 +165,15 @@
|
|||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
|
|
||||||
<el-descriptions-item label="AI提供商">
|
<el-descriptions-item label="AI提供商">
|
||||||
{{ currentRow.provider || "-" }}
|
{{ currentRow.aiProvider || "-" }}
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item label="AI模型">
|
<el-descriptions-item label="AI模型">
|
||||||
{{ currentRow.model || "-" }}
|
{{ currentRow.aiModel || "-" }}
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
|
|
||||||
<el-descriptions-item label="解析状态">
|
<el-descriptions-item label="解析状态">
|
||||||
<el-tag :type="currentRow.parseSuccess ? 'success' : 'danger'" size="small">
|
<el-tag :type="currentRow.parseStatus === 1 ? 'success' : 'danger'" size="small">
|
||||||
{{ currentRow.parseSuccess ? "成功" : "失败" }}
|
{{ currentRow.parseStatus === 1 ? "成功" : "失败" }}
|
||||||
</el-tag>
|
</el-tag>
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item label="置信度">
|
<el-descriptions-item label="置信度">
|
||||||
@@ -199,11 +184,10 @@
|
|||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
|
|
||||||
<el-descriptions-item label="解析耗时">
|
<el-descriptions-item label="解析耗时">
|
||||||
{{ formatNumber(currentRow.parseTime) }} ms
|
{{ formatNumber(currentRow.parseDurationMs) }} ms
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item label="Token统计">
|
<el-descriptions-item label="Token统计">
|
||||||
输入 {{ currentRow.inputTokens || 0 }} / 输出 {{ currentRow.outputTokens || 0 }} / 总计
|
输入 {{ currentRow.inputTokens || 0 }} / 输出 {{ currentRow.outputTokens || 0 }}
|
||||||
{{ currentRow.totalTokens || 0 }}
|
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
|
|
||||||
<el-descriptions-item label="原始命令" :span="2">
|
<el-descriptions-item label="原始命令" :span="2">
|
||||||
@@ -232,22 +216,15 @@
|
|||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item label="执行状态">
|
<el-descriptions-item label="执行状态">
|
||||||
<el-tag
|
<el-tag
|
||||||
v-if="currentRow.executeStatus"
|
v-if="currentRow.executeStatus !== null && currentRow.executeStatus !== undefined"
|
||||||
:type="statusTagType[currentRow.executeStatus]"
|
:type="getExecuteStatusTagType(currentRow.executeStatus)"
|
||||||
size="small"
|
size="small"
|
||||||
>
|
>
|
||||||
{{ statusText[currentRow.executeStatus] }}
|
{{ getExecuteStatusText(currentRow.executeStatus) }}
|
||||||
</el-tag>
|
</el-tag>
|
||||||
<span v-else>-</span>
|
<span v-else>-</span>
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
|
|
||||||
<el-descriptions-item label="执行耗时">
|
|
||||||
{{ formatNumber(currentRow.executionTime) }} ms
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="影响行数">
|
|
||||||
{{ formatNumber(currentRow.affectedRows) }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
|
|
||||||
<el-descriptions-item v-if="currentRow.functionArguments" label="执行参数" :span="2">
|
<el-descriptions-item v-if="currentRow.functionArguments" label="执行参数" :span="2">
|
||||||
<el-input
|
<el-input
|
||||||
:model-value="formatJson(currentRow.functionArguments)"
|
:model-value="formatJson(currentRow.functionArguments)"
|
||||||
@@ -257,39 +234,13 @@
|
|||||||
/>
|
/>
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
|
|
||||||
<el-descriptions-item v-if="currentRow.executeResult" label="执行结果" :span="2">
|
|
||||||
<el-input
|
|
||||||
:model-value="formatJson(currentRow.executeResult)"
|
|
||||||
type="textarea"
|
|
||||||
:rows="4"
|
|
||||||
readonly
|
|
||||||
/>
|
|
||||||
</el-descriptions-item>
|
|
||||||
|
|
||||||
<el-descriptions-item v-if="currentRow.executeErrorMessage" label="执行错误" :span="2">
|
<el-descriptions-item v-if="currentRow.executeErrorMessage" label="执行错误" :span="2">
|
||||||
<el-alert :title="currentRow.executeErrorMessage" type="error" :closable="false" />
|
<el-alert :title="currentRow.executeErrorMessage" type="error" :closable="false" />
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
|
|
||||||
<el-descriptions-item label="风险操作">
|
|
||||||
<el-tag v-if="currentRow.isDangerous" type="warning" size="small">风险操作</el-tag>
|
|
||||||
<span v-else>-</span>
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="是否确认">
|
|
||||||
<span v-if="currentRow.requiresConfirmation">
|
|
||||||
{{ currentRow.userConfirmed ? "已确认" : "待确认" }}
|
|
||||||
</span>
|
|
||||||
<span v-else>-</span>
|
|
||||||
</el-descriptions-item>
|
|
||||||
|
|
||||||
<el-descriptions-item label="IP地址">
|
<el-descriptions-item label="IP地址">
|
||||||
{{ currentRow.ipAddress || "-" }}
|
{{ currentRow.ipAddress || "-" }}
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item label="页面路由">
|
|
||||||
{{ currentRow.currentRoute || "-" }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="User-Agent" :span="2">
|
|
||||||
{{ currentRow.userAgent || "-" }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
|
|
||||||
<el-descriptions-item label="创建时间">
|
<el-descriptions-item label="创建时间">
|
||||||
{{ currentRow.createTime }}
|
{{ currentRow.createTime }}
|
||||||
@@ -297,9 +248,6 @@
|
|||||||
<el-descriptions-item label="更新时间">
|
<el-descriptions-item label="更新时间">
|
||||||
{{ currentRow.updateTime || "-" }}
|
{{ currentRow.updateTime || "-" }}
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item label="备注" :span="2">
|
|
||||||
{{ currentRow.remark || "-" }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
@@ -327,11 +275,10 @@ const queryParams = reactive<AiCommandRecordPageQuery>({
|
|||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
keywords: "",
|
keywords: "",
|
||||||
provider: "",
|
aiProvider: "",
|
||||||
model: "",
|
aiModel: "",
|
||||||
parseSuccess: undefined,
|
parseStatus: undefined,
|
||||||
executeStatus: "",
|
executeStatus: undefined,
|
||||||
isDangerous: undefined,
|
|
||||||
createTime: ["", ""],
|
createTime: ["", ""],
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -340,17 +287,31 @@ const pageData = ref<AiCommandRecordVO[]>([]);
|
|||||||
const detailDialogVisible = ref(false);
|
const detailDialogVisible = ref(false);
|
||||||
const currentRow = ref<AiCommandRecordVO>();
|
const currentRow = ref<AiCommandRecordVO>();
|
||||||
|
|
||||||
const statusText: Record<string, string> = {
|
function getExecuteStatusText(status: number): string {
|
||||||
pending: "待执行",
|
switch (status) {
|
||||||
success: "成功",
|
case 0:
|
||||||
failed: "失败",
|
return "待执行";
|
||||||
};
|
case 1:
|
||||||
|
return "成功";
|
||||||
|
case -1:
|
||||||
|
return "失败";
|
||||||
|
default:
|
||||||
|
return "-";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const statusTagType: Record<string, "info" | "success" | "danger"> = {
|
function getExecuteStatusTagType(status: number): "info" | "success" | "danger" {
|
||||||
pending: "info",
|
switch (status) {
|
||||||
success: "success",
|
case 0:
|
||||||
failed: "danger",
|
return "info";
|
||||||
};
|
case 1:
|
||||||
|
return "success";
|
||||||
|
case -1:
|
||||||
|
return "danger";
|
||||||
|
default:
|
||||||
|
return "info";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function fetchData() {
|
function fetchData() {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
|||||||
@@ -86,6 +86,36 @@
|
|||||||
</el-link>
|
</el-link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 租户选择对话框 -->
|
||||||
|
<el-dialog
|
||||||
|
v-model="tenantDialogVisible"
|
||||||
|
title="选择登录租户"
|
||||||
|
width="500px"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:close-on-press-escape="false"
|
||||||
|
:show-close="false"
|
||||||
|
>
|
||||||
|
<div class="tenant-select-content">
|
||||||
|
<p class="tenant-select-tip">检测到你的账号属于多个租户,请选择登录租户:</p>
|
||||||
|
<el-radio-group v-model="selectedTenantId" class="tenant-radio-group">
|
||||||
|
<el-radio
|
||||||
|
v-for="tenant in pendingTenants"
|
||||||
|
:key="tenant.id"
|
||||||
|
:label="tenant.id"
|
||||||
|
class="tenant-radio"
|
||||||
|
>
|
||||||
|
{{ tenant.name }}
|
||||||
|
</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</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="third-party-login">
|
||||||
<div class="divider-container">
|
<div class="divider-container">
|
||||||
@@ -112,11 +142,12 @@
|
|||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { FormInstance } from "element-plus";
|
import type { FormInstance } from "element-plus";
|
||||||
import AuthAPI, { type LoginFormData } from "@/api/auth-api";
|
import AuthAPI, { type LoginRequest } from "@/api/auth-api";
|
||||||
import router from "@/router";
|
import router from "@/router";
|
||||||
import { useUserStore } from "@/store";
|
import { useUserStore } from "@/store";
|
||||||
import CommonWrapper from "@/components/CommonWrapper/index.vue";
|
import CommonWrapper from "@/components/CommonWrapper/index.vue";
|
||||||
import { AuthStorage } from "@/utils/auth";
|
import { AuthStorage } from "@/utils/auth";
|
||||||
|
import { ApiCodeEnum } from "@/enums/api/code-enum";
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
@@ -132,11 +163,14 @@ const isCapsLock = ref(false);
|
|||||||
const captchaBase64 = ref();
|
const captchaBase64 = ref();
|
||||||
// 记住我
|
// 记住我
|
||||||
const rememberMe = AuthStorage.getRememberMe();
|
const rememberMe = AuthStorage.getRememberMe();
|
||||||
|
// 租户选择对话框
|
||||||
|
const tenantDialogVisible = ref(false);
|
||||||
|
const selectedTenantId = ref<number | null>(null);
|
||||||
|
|
||||||
const loginFormData = ref<LoginFormData>({
|
const loginFormData = ref<LoginRequest>({
|
||||||
username: "admin",
|
username: "admin",
|
||||||
password: "123456",
|
password: "123456",
|
||||||
captchaKey: "",
|
captchaId: "",
|
||||||
captchaCode: "",
|
captchaCode: "",
|
||||||
rememberMe,
|
rememberMe,
|
||||||
});
|
});
|
||||||
@@ -178,12 +212,15 @@ function getCaptcha() {
|
|||||||
codeLoading.value = true;
|
codeLoading.value = true;
|
||||||
AuthAPI.getCaptcha()
|
AuthAPI.getCaptcha()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
loginFormData.value.captchaKey = data.captchaKey;
|
loginFormData.value.captchaId = data.captchaId;
|
||||||
captchaBase64.value = data.captchaBase64;
|
captchaBase64.value = data.captchaBase64;
|
||||||
})
|
})
|
||||||
.finally(() => (codeLoading.value = false));
|
.finally(() => (codeLoading.value = false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 待选择的租户列表
|
||||||
|
const pendingTenants = ref<Array<{ id: number; name: string }>>([]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录提交
|
* 登录提交
|
||||||
*/
|
*/
|
||||||
@@ -196,14 +233,52 @@ async function handleLoginSubmit() {
|
|||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
|
||||||
// 2. 执行登录
|
// 2. 执行登录
|
||||||
await userStore.login(loginFormData.value);
|
try {
|
||||||
|
await userStore.login(loginFormData.value);
|
||||||
|
// 登录成功,跳转到目标页面
|
||||||
|
const redirectPath = (route.query.redirect as string) || "/";
|
||||||
|
await router.push(decodeURIComponent(redirectPath));
|
||||||
|
} catch (error: any) {
|
||||||
|
// 检查是否是 choose_tenant 响应
|
||||||
|
if (error?.code === ApiCodeEnum.CHOOSE_TENANT && error?.data?.tenants) {
|
||||||
|
// 需要选择租户
|
||||||
|
pendingTenants.value = error.data.tenants;
|
||||||
|
tenantDialogVisible.value = true;
|
||||||
|
return; // 等待用户选择租户
|
||||||
|
}
|
||||||
|
// 其他错误,刷新验证码并显示错误
|
||||||
|
getCaptcha();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// 统一错误处理
|
||||||
|
console.error("登录失败:", error);
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户选择确认后的处理
|
||||||
|
*/
|
||||||
|
async function handleTenantSelected() {
|
||||||
|
if (!selectedTenantId.value) {
|
||||||
|
ElMessage.warning("请选择租户");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
loading.value = true;
|
||||||
|
// 使用选中的租户ID重新登录(将 tenantId 设置到表单数据中)
|
||||||
|
const loginData = { ...loginFormData.value, tenantId: selectedTenantId.value };
|
||||||
|
await userStore.login(loginData);
|
||||||
|
// 登录成功,关闭对话框并跳转
|
||||||
|
tenantDialogVisible.value = false;
|
||||||
const redirectPath = (route.query.redirect as string) || "/";
|
const redirectPath = (route.query.redirect as string) || "/";
|
||||||
|
|
||||||
await router.push(decodeURIComponent(redirectPath));
|
await router.push(decodeURIComponent(redirectPath));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// 4. 统一错误处理
|
// 登录失败,刷新验证码
|
||||||
getCaptcha(); // 刷新验证码
|
getCaptcha();
|
||||||
console.error("登录失败:", error);
|
console.error("登录失败:", error);
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
@@ -257,4 +332,42 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-radio-group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
.tenant-radio {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 12px 16px;
|
||||||
|
border: 1px solid var(--el-border-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
transition: all 0.3s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--el-color-primary-light-9);
|
||||||
|
border-color: var(--el-color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-radio__input.is-checked) {
|
||||||
|
+ .el-radio__label {
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -98,7 +98,7 @@
|
|||||||
import type { FormInstance } from "element-plus";
|
import type { FormInstance } from "element-plus";
|
||||||
import { Lock } from "@element-plus/icons-vue";
|
import { Lock } from "@element-plus/icons-vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import AuthAPI, { type LoginFormData } from "@/api/auth-api";
|
import AuthAPI, { type LoginRequest } from "@/api/auth-api";
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ const isCapsLock = ref(false); // 是否大写锁定
|
|||||||
const captchaBase64 = ref(); // 验证码图片Base64字符串
|
const captchaBase64 = ref(); // 验证码图片Base64字符串
|
||||||
const isRead = ref(false);
|
const isRead = ref(false);
|
||||||
|
|
||||||
interface Model extends LoginFormData {
|
interface Model extends LoginRequest {
|
||||||
confirmPassword: string;
|
confirmPassword: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ const model = ref<Model>({
|
|||||||
username: "admin",
|
username: "admin",
|
||||||
password: "123456",
|
password: "123456",
|
||||||
confirmPassword: "",
|
confirmPassword: "",
|
||||||
captchaKey: "",
|
captchaId: "",
|
||||||
captchaCode: "",
|
captchaCode: "",
|
||||||
rememberMe: false,
|
rememberMe: false,
|
||||||
});
|
});
|
||||||
@@ -182,7 +182,7 @@ function getCaptcha() {
|
|||||||
codeLoading.value = true;
|
codeLoading.value = true;
|
||||||
AuthAPI.getCaptcha()
|
AuthAPI.getCaptcha()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
model.value.captchaKey = data.captchaKey;
|
model.value.captchaId = data.captchaId;
|
||||||
captchaBase64.value = data.captchaBase64;
|
captchaBase64.value = data.captchaBase64;
|
||||||
})
|
})
|
||||||
.finally(() => (codeLoading.value = false));
|
.finally(() => (codeLoading.value = false));
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
<div class="table-section__toolbar">
|
<div class="table-section__toolbar">
|
||||||
<div class="table-section__toolbar--actions">
|
<div class="table-section__toolbar--actions">
|
||||||
<el-button
|
<el-button
|
||||||
v-hasPerm="['sys:config:add']"
|
v-hasPerm="['sys:config:create']"
|
||||||
type="success"
|
type="success"
|
||||||
icon="plus"
|
icon="plus"
|
||||||
@click="handleOpenDialog()"
|
@click="handleOpenDialog()"
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
<div class="table-section__toolbar">
|
<div class="table-section__toolbar">
|
||||||
<div class="table-section__toolbar--actions">
|
<div class="table-section__toolbar--actions">
|
||||||
<el-button
|
<el-button
|
||||||
v-hasPerm="['sys:dept:add']"
|
v-hasPerm="['sys:dept:create']"
|
||||||
type="success"
|
type="success"
|
||||||
icon="plus"
|
icon="plus"
|
||||||
@click="handleOpenDialog()"
|
@click="handleOpenDialog()"
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
<el-table-column label="操作" fixed="right" align="left" width="200">
|
<el-table-column label="操作" fixed="right" align="left" width="200">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button
|
<el-button
|
||||||
v-hasPerm="['sys:dept:add']"
|
v-hasPerm="['sys:dept:create']"
|
||||||
type="primary"
|
type="primary"
|
||||||
link
|
link
|
||||||
size="small"
|
size="small"
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
新增
|
新增
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
v-hasPerm="['sys:dept:edit']"
|
v-hasPerm="['sys:dept:update']"
|
||||||
type="primary"
|
type="primary"
|
||||||
link
|
link
|
||||||
size="small"
|
size="small"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<div class="table-section__toolbar">
|
<div class="table-section__toolbar">
|
||||||
<div class="table-section__toolbar--actions">
|
<div class="table-section__toolbar--actions">
|
||||||
<el-button
|
<el-button
|
||||||
v-hasPerm="['sys:menu:add']"
|
v-hasPerm="['sys:menu:create']"
|
||||||
type="success"
|
type="success"
|
||||||
icon="plus"
|
icon="plus"
|
||||||
@click="handleOpenDialog('0')"
|
@click="handleOpenDialog('0')"
|
||||||
@@ -64,7 +64,6 @@
|
|||||||
<el-tag v-if="scope.row.type === MenuTypeEnum.CATALOG" type="warning">目录</el-tag>
|
<el-tag v-if="scope.row.type === MenuTypeEnum.CATALOG" type="warning">目录</el-tag>
|
||||||
<el-tag v-if="scope.row.type === MenuTypeEnum.MENU" type="success">菜单</el-tag>
|
<el-tag v-if="scope.row.type === MenuTypeEnum.MENU" type="success">菜单</el-tag>
|
||||||
<el-tag v-if="scope.row.type === MenuTypeEnum.BUTTON" type="danger">按钮</el-tag>
|
<el-tag v-if="scope.row.type === MenuTypeEnum.BUTTON" type="danger">按钮</el-tag>
|
||||||
<el-tag v-if="scope.row.type === MenuTypeEnum.EXTLINK" type="info">外链</el-tag>
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="路由名称" align="left" width="150" prop="routeName" />
|
<el-table-column label="路由名称" align="left" width="150" prop="routeName" />
|
||||||
@@ -82,7 +81,7 @@
|
|||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button
|
<el-button
|
||||||
v-if="scope.row.type == MenuTypeEnum.CATALOG || scope.row.type == MenuTypeEnum.MENU"
|
v-if="scope.row.type == MenuTypeEnum.CATALOG || scope.row.type == MenuTypeEnum.MENU"
|
||||||
v-hasPerm="['sys:menu:add']"
|
v-hasPerm="['sys:menu:create']"
|
||||||
type="primary"
|
type="primary"
|
||||||
link
|
link
|
||||||
size="small"
|
size="small"
|
||||||
@@ -93,7 +92,7 @@
|
|||||||
</el-button>
|
</el-button>
|
||||||
|
|
||||||
<el-button
|
<el-button
|
||||||
v-hasPerm="['sys:menu:edit']"
|
v-hasPerm="['sys:menu:update']"
|
||||||
type="primary"
|
type="primary"
|
||||||
link
|
link
|
||||||
size="small"
|
size="small"
|
||||||
@@ -144,15 +143,10 @@
|
|||||||
<el-radio :value="MenuTypeEnum.CATALOG">目录</el-radio>
|
<el-radio :value="MenuTypeEnum.CATALOG">目录</el-radio>
|
||||||
<el-radio :value="MenuTypeEnum.MENU">菜单</el-radio>
|
<el-radio :value="MenuTypeEnum.MENU">菜单</el-radio>
|
||||||
<el-radio :value="MenuTypeEnum.BUTTON">按钮</el-radio>
|
<el-radio :value="MenuTypeEnum.BUTTON">按钮</el-radio>
|
||||||
<el-radio :value="MenuTypeEnum.EXTLINK">外链</el-radio>
|
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item v-if="formData.type == MenuTypeEnum.EXTLINK" label="外链地址" prop="path">
|
<el-form-item v-if="formData.type == MenuTypeEnum.MENU && !isExternalLink" prop="routeName">
|
||||||
<el-input v-model="formData.routePath" placeholder="请输入外链完整路径" />
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item v-if="formData.type == MenuTypeEnum.MENU" prop="routeName">
|
|
||||||
<template #label>
|
<template #label>
|
||||||
<div class="flex-y-center">
|
<div class="flex-y-center">
|
||||||
路由名称
|
路由名称
|
||||||
@@ -192,10 +186,10 @@
|
|||||||
v-model="formData.routePath"
|
v-model="formData.routePath"
|
||||||
placeholder="system"
|
placeholder="system"
|
||||||
/>
|
/>
|
||||||
<el-input v-else v-model="formData.routePath" placeholder="user" />
|
<el-input v-else v-model="formData.routePath" placeholder="user 或 https://example.com" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item v-if="formData.type == MenuTypeEnum.MENU" prop="component">
|
<el-form-item v-if="formData.type == MenuTypeEnum.MENU && !isExternalLink" prop="component">
|
||||||
<template #label>
|
<template #label>
|
||||||
<div class="flex-y-center">
|
<div class="flex-y-center">
|
||||||
组件路径
|
组件路径
|
||||||
@@ -216,7 +210,7 @@
|
|||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item v-if="formData.type == MenuTypeEnum.MENU">
|
<el-form-item v-if="formData.type == MenuTypeEnum.MENU && !isExternalLink">
|
||||||
<template #label>
|
<template #label>
|
||||||
<div class="flex-y-center">
|
<div class="flex-y-center">
|
||||||
路由参数
|
路由参数
|
||||||
@@ -298,7 +292,10 @@
|
|||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item v-if="formData.type === MenuTypeEnum.MENU" label="缓存页面">
|
<el-form-item
|
||||||
|
v-if="formData.type === MenuTypeEnum.MENU && !isExternalLink"
|
||||||
|
label="缓存页面"
|
||||||
|
>
|
||||||
<el-radio-group v-model="formData.keepAlive">
|
<el-radio-group v-model="formData.keepAlive">
|
||||||
<el-radio :value="1">开启</el-radio>
|
<el-radio :value="1">开启</el-radio>
|
||||||
<el-radio :value="0">关闭</el-radio>
|
<el-radio :value="0">关闭</el-radio>
|
||||||
@@ -316,7 +313,7 @@
|
|||||||
|
|
||||||
<!-- 权限标识 -->
|
<!-- 权限标识 -->
|
||||||
<el-form-item v-if="formData.type == MenuTypeEnum.BUTTON" label="权限标识" prop="perm">
|
<el-form-item v-if="formData.type == MenuTypeEnum.BUTTON" label="权限标识" prop="perm">
|
||||||
<el-input v-model="formData.perm" placeholder="sys:user:add" />
|
<el-input v-model="formData.perm" placeholder="sys:user:create" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item v-if="formData.type !== MenuTypeEnum.BUTTON" label="图标" prop="icon">
|
<el-form-item v-if="formData.type !== MenuTypeEnum.BUTTON" label="图标" prop="icon">
|
||||||
@@ -382,14 +379,34 @@ const initialMenuFormData = ref<MenuForm>({
|
|||||||
});
|
});
|
||||||
// 菜单表单数据
|
// 菜单表单数据
|
||||||
const formData = ref({ ...initialMenuFormData.value });
|
const formData = ref({ ...initialMenuFormData.value });
|
||||||
|
const isExternalLink = computed(
|
||||||
|
() =>
|
||||||
|
formData.value.type === MenuTypeEnum.MENU &&
|
||||||
|
!!formData.value.routePath &&
|
||||||
|
/^https?:\/\//.test(formData.value.routePath)
|
||||||
|
);
|
||||||
|
const validateRouteName = (_: unknown, value: string, callback: (error?: Error) => void) => {
|
||||||
|
if (formData.value.type === MenuTypeEnum.MENU && !isExternalLink.value && !value) {
|
||||||
|
callback(new Error("请输入路由名称"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
const validateComponent = (_: unknown, value: string, callback: (error?: Error) => void) => {
|
||||||
|
if (formData.value.type === MenuTypeEnum.MENU && !isExternalLink.value && !value) {
|
||||||
|
callback(new Error("请输入组件路径"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
};
|
||||||
// 表单验证规则
|
// 表单验证规则
|
||||||
const rules = reactive({
|
const rules = reactive({
|
||||||
parentId: [{ required: true, message: "请选择父级菜单", trigger: "blur" }],
|
parentId: [{ required: true, message: "请选择父级菜单", trigger: "blur" }],
|
||||||
name: [{ required: true, message: "请输入菜单名称", trigger: "blur" }],
|
name: [{ required: true, message: "请输入菜单名称", trigger: "blur" }],
|
||||||
type: [{ required: true, message: "请选择菜单类型", trigger: "blur" }],
|
type: [{ required: true, message: "请选择菜单类型", trigger: "blur" }],
|
||||||
routeName: [{ required: true, message: "请输入路由名称", trigger: "blur" }],
|
routeName: [{ validator: validateRouteName, trigger: "blur" }],
|
||||||
routePath: [{ required: true, message: "请输入路由路径", trigger: "blur" }],
|
routePath: [{ required: true, message: "请输入路由路径", trigger: "blur" }],
|
||||||
component: [{ required: true, message: "请输入组件路径", trigger: "blur" }],
|
component: [{ validator: validateComponent, trigger: "blur" }],
|
||||||
visible: [{ required: true, message: "请选择显示状态", trigger: "change" }],
|
visible: [{ required: true, message: "请选择显示状态", trigger: "change" }],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
<div class="table-section__toolbar">
|
<div class="table-section__toolbar">
|
||||||
<div class="table-section__toolbar--actions">
|
<div class="table-section__toolbar--actions">
|
||||||
<el-button
|
<el-button
|
||||||
v-hasPerm="['sys:notice:add']"
|
v-hasPerm="['sys:notice:create']"
|
||||||
type="success"
|
type="success"
|
||||||
icon="plus"
|
icon="plus"
|
||||||
@click="handleOpenDialog()"
|
@click="handleOpenDialog()"
|
||||||
@@ -134,7 +134,7 @@
|
|||||||
</el-button>
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
v-if="scope.row.publishStatus != 1"
|
v-if="scope.row.publishStatus != 1"
|
||||||
v-hasPerm="['sys:notice:edit']"
|
v-hasPerm="['sys:notice:update']"
|
||||||
type="primary"
|
type="primary"
|
||||||
size="small"
|
size="small"
|
||||||
link
|
link
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
<div class="table-section__toolbar">
|
<div class="table-section__toolbar">
|
||||||
<div class="table-section__toolbar--actions">
|
<div class="table-section__toolbar--actions">
|
||||||
<el-button
|
<el-button
|
||||||
v-hasPerm="['sys:user:add']"
|
v-hasPerm="['sys:user:create']"
|
||||||
type="success"
|
type="success"
|
||||||
icon="plus"
|
icon="plus"
|
||||||
@click="handleOpenDialog()"
|
@click="handleOpenDialog()"
|
||||||
@@ -130,7 +130,7 @@
|
|||||||
重置密码
|
重置密码
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
v-hasPerm="'sys:user:edit'"
|
v-hasPerm="'sys:user:update'"
|
||||||
type="primary"
|
type="primary"
|
||||||
icon="edit"
|
icon="edit"
|
||||||
link
|
link
|
||||||
|
|||||||
Reference in New Issue
Block a user