Compare commits
66 Commits
1.3.5-back
...
1.4.0-back
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2141c93399 | ||
![]() |
906502f49b | ||
![]() |
1f68fd31b7 | ||
![]() |
f31360ba4e | ||
![]() |
4eb16d6d3a | ||
![]() |
9db6ade1ed | ||
![]() |
2569e1da0d | ||
![]() |
2de9cd2334 | ||
![]() |
739e04816a | ||
![]() |
d9c57dfb61 | ||
![]() |
2217c96cd9 | ||
![]() |
752c1ac3ed | ||
![]() |
53304514b6 | ||
![]() |
cf913f8b8d | ||
![]() |
ad9c465622 | ||
![]() |
bea7c1a094 | ||
![]() |
95859e36a2 | ||
![]() |
8bfc482a7f | ||
![]() |
6fbf1387f5 | ||
![]() |
c3edbec3f0 | ||
![]() |
e5c937396d | ||
![]() |
45de9b7547 | ||
![]() |
6daedd1de5 | ||
![]() |
c45eed90d9 | ||
![]() |
845719d951 | ||
![]() |
4ef974ca4e | ||
![]() |
af186f878d | ||
![]() |
2dc7e564b2 | ||
![]() |
97894a940e | ||
![]() |
48d70182b4 | ||
![]() |
a1091bad46 | ||
![]() |
9f9be21e2a | ||
![]() |
a2bdcd6e49 | ||
![]() |
a38f2de982 | ||
![]() |
d039c53053 | ||
![]() |
11b2b5bcc2 | ||
![]() |
ebef2c91e2 | ||
![]() |
0c3edb10b0 | ||
![]() |
801514dbe3 | ||
![]() |
2dce7718d6 | ||
![]() |
8a8e090792 | ||
![]() |
6fc2c4e3cc | ||
![]() |
8ac97688da | ||
![]() |
c89ec0088b | ||
![]() |
0a076f5e6e | ||
![]() |
4fd68bc083 | ||
![]() |
2efacb3e5b | ||
![]() |
dae46abb71 | ||
![]() |
5ee2a74e2d | ||
![]() |
79d89005b6 | ||
![]() |
d0b8349a2d | ||
![]() |
34c4ecb047 | ||
![]() |
3d9dba965f | ||
![]() |
96b8ae94fd | ||
![]() |
024c01d350 | ||
![]() |
10b8b81954 | ||
![]() |
2adb8acd80 | ||
![]() |
a23bc4cb5c | ||
![]() |
cf17a45d8d | ||
![]() |
b46ebe756e | ||
![]() |
1f50c95c66 | ||
![]() |
cd4706b717 | ||
![]() |
769aceb55f | ||
![]() |
e89cf400c0 | ||
![]() |
9e67929ee7 | ||
![]() |
90625782c0 |
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,3 +1,24 @@
|
||||
# 1.4.0
|
||||
|
||||
**FEATURES**
|
||||
|
||||
- 菜单管理(通用方法) 保存表格滚动/展开状态并执行回调 用于树表在执行 新增/编辑/删除等操作后 依然在当前位置(体验优化)
|
||||
|
||||
- 菜单管理 级联删除 删除菜单和children
|
||||
|
||||
**REFACTOR**
|
||||
|
||||
- 除个人中心外所有本地路由改为从后端返回(需要执行更新sql)
|
||||
- 流程图预览改为logicflow预览而非图片
|
||||
- 菜单管理 新增角色校验(与后端权限保持一致) 只有superadmin可进行增删改
|
||||
|
||||
# 1.3.6
|
||||
|
||||
**BUG FIX**
|
||||
|
||||
- oss配置switch切换 导致报错`存储类型找不到`
|
||||
- 文件上传无法正确清除(innerList)
|
||||
|
||||
# 1.3.5
|
||||
|
||||
**BUG FIX**
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
v5版本采用分仓(包)目录结构, 具体开发路径为: `根目录/apps/web-antd`
|
||||
|
||||
目前对应后端版本: **分布式5.3.1/微服务2.3.0**
|
||||
目前对应后端版本: **分布式5.4.0/微服务2.4.0**
|
||||
|
||||
V1.1.0版本已支持离线图标
|
||||
|
||||
@@ -18,7 +18,7 @@ V1.2.0版本对接warmflow工作流
|
||||
|
||||
| 组件/框架 | 版本 |
|
||||
| :------------- | :----- |
|
||||
| vben | 5.5.4 |
|
||||
| vben | 5.5.6 |
|
||||
| ant-design-vue | 4.2.6 |
|
||||
| vue | 3.5.13 |
|
||||
|
||||
@@ -46,14 +46,6 @@ admin 账号: admin admin123
|
||||
|
||||
[RuoYi-Plus 文档地址](https://plus-doc.dromara.org/#/)
|
||||
|
||||
## 关于表单
|
||||
|
||||
如果你觉得`useVbenForm`难度很大, 完全可以**使用原生antd表单**进行开发, 不一定非得用`useVbenForm`进行开发
|
||||
|
||||
`apps/web-antd/src/views/system/notice/notice-modal.vue`即`通知公告modal`使用**原生antd form**进行(反向🤔)重构, 不想用`useVbenForm`可参考该页面进行表单开发
|
||||
|
||||
复杂表单(如各种联动, 需要自定义样式布局, 需要自定义组件)**优先使用原生表单**(反正说了也没人听听😅)
|
||||
|
||||
## 预览图
|
||||
|
||||
        
|
||||
|
28
apps/backend-mock/api/demo/bigint.ts
Normal file
28
apps/backend-mock/api/demo/bigint.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
export default eventHandler(async (event) => {
|
||||
const userinfo = verifyAccessToken(event);
|
||||
if (!userinfo) {
|
||||
return unAuthorizedResponse(event);
|
||||
}
|
||||
const data = `
|
||||
{
|
||||
"code": 0,
|
||||
"message": "success",
|
||||
"data": [
|
||||
{
|
||||
"id": 123456789012345678901234567890123456789012345678901234567890,
|
||||
"name": "John Doe",
|
||||
"age": 30,
|
||||
"email": "john-doe@demo.com"
|
||||
},
|
||||
{
|
||||
"id": 987654321098765432109876543210987654321098765432109876543210,
|
||||
"name": "Jane Smith",
|
||||
"age": 25,
|
||||
"email": "jane@demo.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
`;
|
||||
setHeader(event, 'Content-Type', 'application/json');
|
||||
return data;
|
||||
});
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vben/web-antd",
|
||||
"version": "1.3.5",
|
||||
"version": "1.4.0",
|
||||
"homepage": "https://vben.pro",
|
||||
"bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
|
||||
"repository": {
|
||||
@@ -27,6 +27,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@ant-design/icons-vue": "^7.0.1",
|
||||
"@logicflow/core": "^2.0.13",
|
||||
"@tinymce/tinymce-vue": "^6.0.1",
|
||||
"@vben/access": "workspace:*",
|
||||
"@vben/common-ui": "workspace:*",
|
||||
|
@@ -10,44 +10,46 @@ import { $t } from '@vben/locales';
|
||||
|
||||
import { isArray } from 'lodash-es';
|
||||
|
||||
setupVbenForm<ComponentType>({
|
||||
config: {
|
||||
// ant design vue组件库默认都是 v-model:value
|
||||
baseModelPropName: 'value',
|
||||
async function initSetupVbenForm() {
|
||||
setupVbenForm<ComponentType>({
|
||||
config: {
|
||||
// ant design vue组件库默认都是 v-model:value
|
||||
baseModelPropName: 'value',
|
||||
|
||||
// 一些组件是 v-model:checked 或者 v-model:fileList
|
||||
modelPropNameMap: {
|
||||
Checkbox: 'checked',
|
||||
Radio: 'checked',
|
||||
RichTextarea: 'modelValue',
|
||||
Switch: 'checked',
|
||||
Upload: 'fileList',
|
||||
// 一些组件是 v-model:checked 或者 v-model:fileList
|
||||
modelPropNameMap: {
|
||||
Checkbox: 'checked',
|
||||
Radio: 'checked',
|
||||
RichTextarea: 'modelValue',
|
||||
Switch: 'checked',
|
||||
Upload: 'fileList',
|
||||
},
|
||||
},
|
||||
},
|
||||
defineRules: {
|
||||
// 输入项目必填国际化适配
|
||||
required: (value, _params, ctx) => {
|
||||
if (value === undefined || value === null || value.length === 0) {
|
||||
return $t('ui.formRules.required', [ctx.label]);
|
||||
}
|
||||
return true;
|
||||
defineRules: {
|
||||
// 输入项目必填国际化适配
|
||||
required: (value, _params, ctx) => {
|
||||
if (value === undefined || value === null || value.length === 0) {
|
||||
return $t('ui.formRules.required', [ctx.label]);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
// 选择项目必填国际化适配
|
||||
selectRequired: (value, _params, ctx) => {
|
||||
if (
|
||||
[false, null, undefined].includes(value) ||
|
||||
(isArray(value) && value.length === 0)
|
||||
) {
|
||||
return $t('ui.formRules.selectRequired', [ctx.label]);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
// 选择项目必填国际化适配
|
||||
selectRequired: (value, _params, ctx) => {
|
||||
if (
|
||||
[false, null, undefined].includes(value) ||
|
||||
(isArray(value) && value.length === 0)
|
||||
) {
|
||||
return $t('ui.formRules.selectRequired', [ctx.label]);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const useVbenForm = useForm<ComponentType>;
|
||||
|
||||
export { useVbenForm, z };
|
||||
export { initSetupVbenForm, useVbenForm, z };
|
||||
|
||||
export type VbenFormSchema = FormSchema<ComponentType>;
|
||||
export type { VbenFormProps };
|
||||
|
@@ -1,7 +1,12 @@
|
||||
import type { GrantType } from '@vben/common-ui';
|
||||
import type { HttpResponse } from '@vben/request';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { useAppConfig } from '@vben/hooks';
|
||||
|
||||
import { Modal } from 'ant-design-vue';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
const { clientId, sseEnable } = useAppConfig(
|
||||
@@ -90,8 +95,32 @@ export async function loginApi(data: AuthApi.LoginParams) {
|
||||
* 用户登出
|
||||
* @returns void
|
||||
*/
|
||||
export function doLogout() {
|
||||
return requestClient.post<void>('/auth/logout');
|
||||
export async function doLogout() {
|
||||
const resp = await requestClient.post<HttpResponse<void>>(
|
||||
'/auth/logout',
|
||||
null,
|
||||
{
|
||||
isTransformResponse: false,
|
||||
},
|
||||
);
|
||||
// 无奈之举 对错误用法的提示
|
||||
if (resp.code === 401 && import.meta.env.DEV) {
|
||||
Modal.destroyAll();
|
||||
Modal.warn({
|
||||
title: '后端配置出现错误',
|
||||
centered: true,
|
||||
content: h('div', { class: 'flex flex-col gap-2' }, [
|
||||
`检测到你的logout接口返回了401, 导致前端一直进入循环逻辑???`,
|
||||
...Array.from({ length: 3 }, () =>
|
||||
h(
|
||||
'span',
|
||||
{ class: 'font-bold text-red-500 text-[18px]' },
|
||||
'去检查你的后端配置!别盯着前端找问题了!这不是前端问题!',
|
||||
),
|
||||
),
|
||||
]),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -81,3 +81,12 @@ export function tenantPackageMenuTreeSelect(packageId: ID) {
|
||||
`${Api.tenantPackageMenuTreeselect}/${packageId}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除菜单
|
||||
* @param menuIds 菜单ids
|
||||
* @returns void
|
||||
*/
|
||||
export function menuCascadeRemove(menuIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/cascade/${menuIds}`);
|
||||
}
|
||||
|
@@ -37,9 +37,10 @@ export function ossConfigRemove(ossConfigIds: IDS) {
|
||||
|
||||
// 更改OSS配置的状态
|
||||
export function ossConfigChangeStatus(data: any) {
|
||||
const requestData = {
|
||||
const requestData: Partial<OssConfig> = {
|
||||
ossConfigId: data.ossConfigId,
|
||||
status: data.status,
|
||||
configKey: data.configKey,
|
||||
};
|
||||
return requestClient.putWithMsg(Api.ossConfigChangeStatus, requestData);
|
||||
}
|
||||
|
@@ -38,4 +38,9 @@ export interface Flow {
|
||||
export interface FlowInfoResponse {
|
||||
image: string;
|
||||
list: Flow[];
|
||||
defChart: {
|
||||
defJson: Record<string, any>;
|
||||
nodeJsonList: Record<string, any>[];
|
||||
skipJsonList: Record<string, any>[];
|
||||
};
|
||||
}
|
||||
|
@@ -8,6 +8,8 @@ import { App, ConfigProvider, theme } from 'ant-design-vue';
|
||||
|
||||
import { antdLocale } from '#/locales';
|
||||
|
||||
import { useUploadTip } from './upload-tip';
|
||||
|
||||
defineOptions({ name: 'App' });
|
||||
|
||||
const { isDark } = usePreferences();
|
||||
@@ -28,6 +30,8 @@ const tokenTheme = computed(() => {
|
||||
token: tokens,
|
||||
};
|
||||
});
|
||||
|
||||
useUploadTip();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@@ -13,6 +13,7 @@ import { setupGlobalComponent } from '#/components/global';
|
||||
import { $t, setupI18n } from '#/locales';
|
||||
|
||||
import { initComponentAdapter } from './adapter/component';
|
||||
import { initSetupVbenForm } from './adapter/form';
|
||||
import App from './app.vue';
|
||||
import { router } from './router';
|
||||
|
||||
@@ -20,6 +21,9 @@ async function bootstrap(namespace: string) {
|
||||
// 初始化组件适配器
|
||||
await initComponentAdapter();
|
||||
|
||||
// 初始化表单组件
|
||||
await initSetupVbenForm();
|
||||
|
||||
// // 设置弹窗的默认配置
|
||||
// setDefaultModalProps({
|
||||
// fullscreenButton: false,
|
||||
|
@@ -322,6 +322,8 @@ export function useUpload(
|
||||
() => bindValue.value,
|
||||
async (value) => {
|
||||
if (value.length === 0) {
|
||||
// 清空绑定值时,同时清空innerFileList,避免外部使用时还能读取到
|
||||
innerFileList.value = [];
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import type {
|
||||
ComponentRecordType,
|
||||
GenerateMenuAndRoutesOptions,
|
||||
RouteMeta,
|
||||
RouteRecordStringComponent,
|
||||
} from '@vben/types';
|
||||
|
||||
@@ -21,6 +22,37 @@ import { localMenuList } from './routes/local';
|
||||
const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');
|
||||
const NotFoundComponent = () => import('#/views/_core/fallback/not-found.vue');
|
||||
|
||||
/**
|
||||
* 后端返回的meta有时候不包括需要的信息 比如activePath等
|
||||
* 在这里定义映射
|
||||
*/
|
||||
const routeMetaMapping: Record<string, Omit<RouteMeta, 'title'>> = {
|
||||
'/system/role-auth/user/:roleId(\\d+)': {
|
||||
activePath: '/system/role',
|
||||
requireHomeRedirect: true,
|
||||
},
|
||||
|
||||
'/system/oss-config/index': {
|
||||
activePath: '/system/oss',
|
||||
requireHomeRedirect: true,
|
||||
},
|
||||
|
||||
'/tool/gen-edit/index/:tableId(\\d+)': {
|
||||
activePath: '/tool/gen',
|
||||
requireHomeRedirect: true,
|
||||
},
|
||||
|
||||
'/workflow/design/index': {
|
||||
activePath: '/workflow/processDefinition',
|
||||
requireHomeRedirect: true,
|
||||
},
|
||||
|
||||
'/workflow/leaveEdit/index': {
|
||||
activePath: '/demo/leave',
|
||||
requireHomeRedirect: true,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 后台路由转vben路由
|
||||
* @param menuList 后台菜单
|
||||
@@ -98,6 +130,17 @@ function backMenuToVbenMenu(
|
||||
path: menu.path,
|
||||
};
|
||||
|
||||
// 处理meta映射
|
||||
if (Object.keys(routeMetaMapping).includes(vbenRoute.path)) {
|
||||
const routeMeta = routeMetaMapping[vbenRoute.path];
|
||||
if (routeMeta) {
|
||||
vbenRoute.meta = {
|
||||
...vbenRoute.meta,
|
||||
...(routeMeta as RouteMeta),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 添加路由参数信息
|
||||
if (menu.query) {
|
||||
try {
|
||||
|
@@ -18,7 +18,7 @@ function setupCommonGuard(router: Router) {
|
||||
// 记录已经加载的页面
|
||||
const loadedPaths = new Set<string>();
|
||||
|
||||
router.beforeEach(async (to) => {
|
||||
router.beforeEach((to) => {
|
||||
to.meta.loaded = loadedPaths.has(to.path);
|
||||
|
||||
// 页面加载进度条
|
||||
|
@@ -9,6 +9,7 @@ const {
|
||||
|
||||
/**
|
||||
* 该文件放非后台返回的路由 比如个人中心 等需要跳转显示的页面
|
||||
* 也可以直接在菜单管理配置
|
||||
*/
|
||||
const localRoutes: RouteRecordStringComponent[] = [
|
||||
{
|
||||
@@ -22,69 +23,6 @@ const localRoutes: RouteRecordStringComponent[] = [
|
||||
name: 'Profile',
|
||||
path: '/profile',
|
||||
},
|
||||
{
|
||||
component: '/system/oss-config/index',
|
||||
meta: {
|
||||
activePath: '/system/oss',
|
||||
icon: 'ant-design:setting-outlined',
|
||||
title: 'oss配置',
|
||||
hideInMenu: true,
|
||||
requireHomeRedirect: true,
|
||||
},
|
||||
name: 'OssConfig',
|
||||
path: '/system/oss-config',
|
||||
},
|
||||
{
|
||||
component: '/tool/gen/edit-gen',
|
||||
meta: {
|
||||
activePath: '/tool/gen',
|
||||
icon: 'tabler:code',
|
||||
title: '生成配置',
|
||||
hideInMenu: true,
|
||||
requireHomeRedirect: true,
|
||||
},
|
||||
name: 'GenConfig',
|
||||
path: '/code-gen/edit/:tableId',
|
||||
},
|
||||
{
|
||||
component: '/system/role-assign/index',
|
||||
meta: {
|
||||
activePath: '/system/role',
|
||||
icon: 'eos-icons:role-binding-outlined',
|
||||
title: '分配角色',
|
||||
hideInMenu: true,
|
||||
requireHomeRedirect: true,
|
||||
},
|
||||
name: 'RoleAssign',
|
||||
path: '/system/role-assign/:roleId',
|
||||
},
|
||||
{
|
||||
component: '/workflow/components/flow-designer',
|
||||
meta: {
|
||||
activePath: '/workflow/processDefinition',
|
||||
icon: 'fluent-mdl2:flow',
|
||||
title: '流程设计',
|
||||
hideInMenu: true,
|
||||
requireHomeRedirect: true,
|
||||
},
|
||||
name: 'WorkflowDesigner',
|
||||
path: '/workflow/designer',
|
||||
},
|
||||
/**
|
||||
* 需要添加iframe路由 同目录的./workflow-iframe.ts
|
||||
*/
|
||||
{
|
||||
component: 'workflow/leave/leave-form',
|
||||
meta: {
|
||||
icon: 'flat-color-icons:leave',
|
||||
title: '请假申请',
|
||||
activePath: '/demo/leave',
|
||||
hideInMenu: true,
|
||||
requireHomeRedirect: true,
|
||||
},
|
||||
name: 'WorkflowLeaveIndex',
|
||||
path: '/workflow/leaveEdit/index',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
|
36
apps/web-antd/src/upload-tip.ts
Normal file
36
apps/web-antd/src/upload-tip.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { onMounted } from 'vue';
|
||||
|
||||
import { useLocalStorage } from '@vueuse/core';
|
||||
import { Modal } from 'ant-design-vue';
|
||||
|
||||
export function useUploadTip() {
|
||||
const readTip = useLocalStorage<boolean>('__upload_tip_read_5.4.0', false);
|
||||
onMounted(() => {
|
||||
if (readTip.value || !import.meta.env.DEV) {
|
||||
return;
|
||||
}
|
||||
const modalInstance = Modal.info({
|
||||
title: '提示',
|
||||
centered: true,
|
||||
content:
|
||||
'如果你的版本是从低版本升级到后端>5.4.0, 记得执行升级sql, 否则跳转页面(如oss 代码生成配置)等会404',
|
||||
okButtonProps: { disabled: true },
|
||||
onOk() {
|
||||
modalInstance.destroy();
|
||||
readTip.value = true;
|
||||
},
|
||||
});
|
||||
|
||||
let time = 3;
|
||||
const interval = setInterval(() => {
|
||||
modalInstance.update({
|
||||
okText: time === 0 ? '我知道了, 不再弹出' : `${time}秒后关闭`,
|
||||
okButtonProps: { disabled: time > 0 },
|
||||
});
|
||||
if (time <= 0) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
time--;
|
||||
}, 1000);
|
||||
});
|
||||
}
|
@@ -30,7 +30,6 @@ export const columns: VxeGridProps['columns'] = [
|
||||
field: 'deptName',
|
||||
title: '部门名称',
|
||||
treeNode: true,
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
field: 'deptCategory',
|
||||
@@ -39,13 +38,9 @@ export const columns: VxeGridProps['columns'] = [
|
||||
{
|
||||
field: 'orderNum',
|
||||
title: '排序',
|
||||
resizable: false,
|
||||
width: 'auto',
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
resizable: false,
|
||||
width: 'auto',
|
||||
title: '状态',
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
@@ -62,7 +57,8 @@ export const columns: VxeGridProps['columns'] = [
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
title: '操作',
|
||||
width: 200,
|
||||
resizable: false,
|
||||
width: 'auto',
|
||||
},
|
||||
];
|
||||
|
||||
|
6
apps/web-antd/src/views/system/dict/data.vue
Normal file
6
apps/web-antd/src/views/system/dict/data.vue
Normal file
@@ -0,0 +1,6 @@
|
||||
<template>
|
||||
<div>
|
||||
ele版本会使用这个文件 只是为了不报错`未找到对应组件`才新建的这个文件
|
||||
无实际意义
|
||||
</div>
|
||||
</template>
|
281
apps/web-antd/src/views/system/dict/type/index-refactor.vue
Normal file
281
apps/web-antd/src/views/system/dict/type/index-refactor.vue
Normal file
@@ -0,0 +1,281 @@
|
||||
<!-- 使用vxe实现成本最小 且自带虚拟滚动 -->
|
||||
<script setup lang="ts">
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { DictType } from '#/api/system/dict/dict-type-model';
|
||||
|
||||
import { h, ref, shallowRef, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { cn } from '@vben/utils';
|
||||
|
||||
import {
|
||||
DeleteOutlined,
|
||||
EditOutlined,
|
||||
ExportOutlined,
|
||||
PlusOutlined,
|
||||
SyncOutlined,
|
||||
} from '@ant-design/icons-vue';
|
||||
import {
|
||||
Alert,
|
||||
Input,
|
||||
Modal,
|
||||
Popconfirm,
|
||||
Space,
|
||||
Tooltip,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
dictTypeExport,
|
||||
dictTypeList,
|
||||
dictTypeRemove,
|
||||
refreshDictTypeCache,
|
||||
} from '#/api/system/dict/dict-type';
|
||||
import { commonDownloadExcel } from '#/utils/file/download';
|
||||
|
||||
import { emitter } from '../mitt';
|
||||
import dictTypeModal from './dict-type-modal.vue';
|
||||
|
||||
const tableAllData = shallowRef<DictType[]>([]);
|
||||
const gridOptions: VxeGridProps = {
|
||||
columns: [
|
||||
{
|
||||
title: 'name',
|
||||
field: 'render',
|
||||
slots: { default: 'render' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async () => {
|
||||
const resp = await dictTypeList();
|
||||
|
||||
total.value = resp.total;
|
||||
tableAllData.value = resp.rows;
|
||||
return resp;
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'dictId',
|
||||
// 高亮当前行
|
||||
isCurrent: true,
|
||||
},
|
||||
cellConfig: {
|
||||
height: 60,
|
||||
},
|
||||
showHeader: false,
|
||||
toolbarConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
// 开启虚拟滚动
|
||||
scrollY: {
|
||||
enabled: false,
|
||||
gt: 0,
|
||||
},
|
||||
rowClassName: 'cursor-pointer',
|
||||
id: 'system-dict-data-index',
|
||||
};
|
||||
|
||||
const [BasicTable, tableApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
gridEvents: {
|
||||
cellClick: ({ row }) => {
|
||||
handleRowClick(row);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const [DictTypeModal, modalApi] = useVbenModal({
|
||||
connectedComponent: dictTypeModal,
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
modalApi.setData({});
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
async function handleEdit(record: DictType) {
|
||||
modalApi.setData({ id: record.dictId });
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
async function handleDelete(row: DictType) {
|
||||
await dictTypeRemove([row.dictId]);
|
||||
await tableApi.query();
|
||||
}
|
||||
|
||||
async function handleReset() {
|
||||
currentRowId.value = '';
|
||||
searchValue.value = '';
|
||||
await tableApi.query();
|
||||
}
|
||||
|
||||
function handleDownloadExcel() {
|
||||
commonDownloadExcel(dictTypeExport, '字典类型数据');
|
||||
}
|
||||
|
||||
function handleRefreshCache() {
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
content: '确认刷新字典类型缓存吗?',
|
||||
okButtonProps: {
|
||||
danger: true,
|
||||
},
|
||||
onOk: async () => {
|
||||
await refreshDictTypeCache();
|
||||
await tableApi.query();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const lastDictType = ref<string>('');
|
||||
const currentRowId = ref<null | number | string>(null);
|
||||
function handleRowClick(row: DictType) {
|
||||
if (lastDictType.value === row.dictType) {
|
||||
return;
|
||||
}
|
||||
currentRowId.value = row.dictId;
|
||||
emitter.emit('rowClick', row.dictType);
|
||||
}
|
||||
|
||||
const searchValue = ref('');
|
||||
const total = ref(0);
|
||||
watch(searchValue, (value) => {
|
||||
if (!tableApi) {
|
||||
return;
|
||||
}
|
||||
if (value) {
|
||||
const names = tableAllData.value.filter((item) =>
|
||||
item.dictName.includes(searchValue.value),
|
||||
);
|
||||
const types = tableAllData.value.filter((item) =>
|
||||
item.dictType.includes(searchValue.value),
|
||||
);
|
||||
const filtered = [...new Set([...names, ...types])];
|
||||
total.value = filtered.length;
|
||||
tableApi.grid.loadData(filtered);
|
||||
} else {
|
||||
total.value = tableAllData.value.length;
|
||||
tableApi.grid.loadData(tableAllData.value);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
:class="
|
||||
cn(
|
||||
'bg-background flex max-h-[100vh] w-[360px] flex-col overflow-y-hidden',
|
||||
'rounded-lg',
|
||||
'dict-type-card',
|
||||
)
|
||||
"
|
||||
>
|
||||
<div :class="cn('flex items-center justify-between', 'border-b px-4 py-2')">
|
||||
<span class="font-semibold">字典项列表</span>
|
||||
<Space>
|
||||
<Tooltip title="刷新缓存">
|
||||
<a-button
|
||||
v-access:code="['system:dict:edit']"
|
||||
:icon="h(SyncOutlined)"
|
||||
@click="handleRefreshCache"
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip :title="$t('pages.common.export')">
|
||||
<a-button
|
||||
v-access:code="['system:dict:export']"
|
||||
:icon="h(ExportOutlined)"
|
||||
@click="handleDownloadExcel"
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip :title="$t('pages.common.add')">
|
||||
<a-button
|
||||
v-access:code="['system:dict:add']"
|
||||
:icon="h(PlusOutlined)"
|
||||
@click="handleAdd"
|
||||
/>
|
||||
</Tooltip>
|
||||
</Space>
|
||||
</div>
|
||||
<div class="flex flex-1 flex-col overflow-y-hidden p-4">
|
||||
<Alert
|
||||
class="mb-4"
|
||||
show-icon
|
||||
message="如果你的数据量大 自行开启虚拟滚动"
|
||||
/>
|
||||
<Input
|
||||
placeholder="搜索字典项名称/类型"
|
||||
v-model:value="searchValue"
|
||||
allow-clear
|
||||
>
|
||||
<template #addonAfter>
|
||||
<Tooltip title="重置/刷新">
|
||||
<SyncOutlined
|
||||
v-access:code="['system:dict:edit']"
|
||||
@click="handleReset"
|
||||
/>
|
||||
</Tooltip>
|
||||
</template>
|
||||
</Input>
|
||||
<BasicTable class="flex-1 overflow-hidden">
|
||||
<template #render="{ row: item }">
|
||||
<div :class="cn('flex items-center justify-between px-2 py-2')">
|
||||
<div class="flex flex-col items-baseline overflow-hidden">
|
||||
<span class="font-medium">{{ item.dictName }}</span>
|
||||
<div
|
||||
class="max-w-full overflow-hidden text-ellipsis whitespace-nowrap"
|
||||
>
|
||||
{{ item.dictType }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-3 text-[17px]">
|
||||
<EditOutlined
|
||||
class="text-primary"
|
||||
v-access:code="['system:dict:edit']"
|
||||
@click.stop="handleEdit(item)"
|
||||
/>
|
||||
<Popconfirm
|
||||
placement="left"
|
||||
:title="`确认删除 [${item.dictName}]?`"
|
||||
@confirm="handleDelete(item)"
|
||||
>
|
||||
<DeleteOutlined
|
||||
v-access:code="['system:dict:remove']"
|
||||
class="text-destructive"
|
||||
@click.stop=""
|
||||
/>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</BasicTable>
|
||||
</div>
|
||||
<div class="border-t px-4 py-3">共 {{ total }} 条数据</div>
|
||||
<DictTypeModal @reload="tableApi.query()" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss">
|
||||
.dict-type-card {
|
||||
.vxe-grid {
|
||||
padding: 12px 0 0;
|
||||
|
||||
.vxe-body--row {
|
||||
&.row--current {
|
||||
// 选中行背景色
|
||||
background-color: hsl(var(--accent-hover)) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-alert {
|
||||
padding: 6px 12px;
|
||||
}
|
||||
}
|
||||
</style>
|
@@ -219,6 +219,7 @@ export const drawerSchema: FormSchemaGetter = () => [
|
||||
fieldName: 'orderNum',
|
||||
help: '排序, 数字越小越靠前',
|
||||
label: '显示排序',
|
||||
defaultValue: 0,
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
|
25
apps/web-antd/src/views/system/menu/helper.ts
Normal file
25
apps/web-antd/src/views/system/menu/helper.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { MaybePromise } from '@vben/types';
|
||||
|
||||
import type { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
|
||||
/**
|
||||
* 保存表格滚动/展开状态并执行回调 用于树表在执行 新增/编辑/删除等操作后 依然在当前位置(体验优化)
|
||||
*
|
||||
* @param tableApi 表格api
|
||||
* @param callback 回调
|
||||
*/
|
||||
export async function preserveTreeTableState(
|
||||
tableApi: ReturnType<typeof useVbenVxeGrid>[1],
|
||||
callback: () => MaybePromise<void>,
|
||||
) {
|
||||
// 保存当前状态
|
||||
const scrollState = tableApi.grid.getScroll();
|
||||
const expandRecords = tableApi.grid.getTreeExpandRecords();
|
||||
|
||||
// 执行回调
|
||||
await callback();
|
||||
|
||||
// 恢复状态
|
||||
tableApi.grid.setTreeExpand(expandRecords, true);
|
||||
tableApi.grid.scrollTo(scrollState.scrollLeft, scrollState.scrollTop);
|
||||
}
|
@@ -4,18 +4,20 @@ import type { VbenFormProps } from '@vben/common-ui';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { Menu } from '#/api/system/menu/model';
|
||||
|
||||
import { computed } from 'vue';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useAccess } from '@vben/access';
|
||||
import { Fallback, Page, useVbenDrawer } from '@vben/common-ui';
|
||||
import { eachTree, getVxePopupContainer } from '@vben/utils';
|
||||
import { $t } from '@vben/locales';
|
||||
import { eachTree, getVxePopupContainer, treeToList } from '@vben/utils';
|
||||
|
||||
import { Popconfirm, Space } from 'ant-design-vue';
|
||||
import { Popconfirm, Space, Switch, Tooltip } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { menuList, menuRemove } from '#/api/system/menu';
|
||||
import { menuCascadeRemove, menuList, menuRemove } from '#/api/system/menu';
|
||||
|
||||
import { columns, querySchema } from './data';
|
||||
import { preserveTreeTableState } from './helper';
|
||||
import menuDrawer from './menu-drawer.vue';
|
||||
|
||||
/**
|
||||
@@ -111,9 +113,41 @@ async function handleEdit(record: Menu) {
|
||||
drawerApi.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否级联删除
|
||||
*/
|
||||
const cascadingDeletion = ref(false);
|
||||
async function handleDelete(row: Menu) {
|
||||
await menuRemove([row.menuId]);
|
||||
await tableApi.query();
|
||||
await preserveTreeTableState(tableApi, async () => {
|
||||
if (cascadingDeletion.value) {
|
||||
// 级联删除
|
||||
const menuAndChildren: Menu[] = treeToList([row], { id: 'menuId' });
|
||||
await menuCascadeRemove(menuAndChildren.map((item) => item.menuId));
|
||||
} else {
|
||||
// 单删除
|
||||
await menuRemove([row.menuId]);
|
||||
}
|
||||
await tableApi.query();
|
||||
});
|
||||
}
|
||||
|
||||
function removeConfirmTitle(row: Menu) {
|
||||
const menuName = $t(row.menuName);
|
||||
if (!cascadingDeletion.value) {
|
||||
return `是否确认删除 [${menuName}] ?`;
|
||||
}
|
||||
const menuAndChildren = treeToList([row], { id: 'menuId' });
|
||||
if (menuAndChildren.length === 1) {
|
||||
return `是否确认删除 [${menuName}] ?`;
|
||||
}
|
||||
return `是否确认删除 [${menuName}] 及 [${menuAndChildren.length - 1}]个子项目 ?`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑/添加成功后刷新表格
|
||||
*/
|
||||
async function afterEditOrAdd() {
|
||||
await preserveTreeTableState(tableApi, () => tableApi.query());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,6 +162,9 @@ function setExpandOrCollapse(expand: boolean) {
|
||||
/**
|
||||
* 与后台逻辑相同
|
||||
* 只有租户管理和超级管理能访问菜单管理
|
||||
* 注意: 只有超管才能对菜单进行`增删改`操作
|
||||
* 注意: 只有超管才能对菜单进行`增删改`操作
|
||||
* 注意: 只有超管才能对菜单进行`增删改`操作
|
||||
*/
|
||||
const { hasAccessByRoles } = useAccess();
|
||||
const isAdmin = computed(() => {
|
||||
@@ -140,6 +177,16 @@ const isAdmin = computed(() => {
|
||||
<BasicTable table-title="菜单列表" table-title-help="双击展开/收起子菜单">
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Tooltip title="删除菜单以及子菜单">
|
||||
<div
|
||||
v-access:role="['superadmin']"
|
||||
v-access:code="['system:menu:remove']"
|
||||
class="flex items-center"
|
||||
>
|
||||
<span class="mr-2 text-sm text-[#666666]">级联删除</span>
|
||||
<Switch v-model:checked="cascadingDeletion" />
|
||||
</div>
|
||||
</Tooltip>
|
||||
<a-button @click="setExpandOrCollapse(false)">
|
||||
{{ $t('pages.common.collapse') }}
|
||||
</a-button>
|
||||
@@ -149,6 +196,7 @@ const isAdmin = computed(() => {
|
||||
<a-button
|
||||
type="primary"
|
||||
v-access:code="['system:menu:add']"
|
||||
v-access:role="['superadmin']"
|
||||
@click="handleAdd"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
@@ -159,6 +207,7 @@ const isAdmin = computed(() => {
|
||||
<Space>
|
||||
<ghost-button
|
||||
v-access:code="['system:menu:edit']"
|
||||
v-access:role="['superadmin']"
|
||||
@click="handleEdit(row)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
@@ -168,6 +217,7 @@ const isAdmin = computed(() => {
|
||||
v-if="row.menuType !== 'F'"
|
||||
class="btn-success"
|
||||
v-access:code="['system:menu:add']"
|
||||
v-access:role="['superadmin']"
|
||||
@click="handleSubAdd(row)"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
@@ -175,12 +225,13 @@ const isAdmin = computed(() => {
|
||||
<Popconfirm
|
||||
:get-popup-container="getVxePopupContainer"
|
||||
placement="left"
|
||||
title="确认删除?"
|
||||
:title="removeConfirmTitle(row)"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<ghost-button
|
||||
danger
|
||||
v-access:code="['system:menu:remove']"
|
||||
v-access:role="['superadmin']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
@@ -189,7 +240,7 @@ const isAdmin = computed(() => {
|
||||
</Space>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<MenuDrawer @reload="tableApi.query()" />
|
||||
<MenuDrawer @reload="afterEditOrAdd" />
|
||||
</Page>
|
||||
<Fallback v-else description="您没有菜单管理的访问权限" status="403" />
|
||||
</template>
|
||||
|
@@ -28,7 +28,10 @@ export const querySchema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: getDictOptions(DictEnum.SYS_YES_NO),
|
||||
options: [
|
||||
{ label: '是', value: '0' },
|
||||
{ label: '否', value: '1' },
|
||||
],
|
||||
},
|
||||
fieldName: 'status',
|
||||
label: '是否默认',
|
||||
|
@@ -131,6 +131,8 @@ const { hasAccessByCodes } = useAccess();
|
||||
v-model:value="row.status"
|
||||
:api="() => ossConfigChangeStatus(row)"
|
||||
:disabled="!hasAccessByCodes(['system:ossConfig:edit'])"
|
||||
checked-text="是"
|
||||
un-checked-text="否"
|
||||
@reload="tableApi.query()"
|
||||
/>
|
||||
</template>
|
||||
|
11
apps/web-antd/src/views/system/oss/config.vue
Normal file
11
apps/web-antd/src/views/system/oss/config.vue
Normal file
@@ -0,0 +1,11 @@
|
||||
<!--
|
||||
后端版本>=5.4.0 这个从本地路由变为从后台返回
|
||||
未修改文件名 而是新加了这个文件
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import OssConfigPage from '#/views/system/oss-config/index.vue';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<OssConfigPage />
|
||||
</template>
|
2
apps/web-antd/src/views/system/oss/constant.ts
Normal file
2
apps/web-antd/src/views/system/oss/constant.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
/** 支持的图片列表 */
|
||||
export const supportImageList = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
|
@@ -73,9 +73,3 @@ export const columns: VxeGridProps['columns'] = [
|
||||
width: 'auto',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* 图片加载失败的fallback
|
||||
*/
|
||||
export const fallbackImageBase64 =
|
||||
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMIAAADDCAYAAADQvc6UAAABRWlDQ1BJQ0MgUHJvZmlsZQAAKJFjYGASSSwoyGFhYGDIzSspCnJ3UoiIjFJgf8LAwSDCIMogwMCcmFxc4BgQ4ANUwgCjUcG3awyMIPqyLsis7PPOq3QdDFcvjV3jOD1boQVTPQrgSkktTgbSf4A4LbmgqISBgTEFyFYuLykAsTuAbJEioKOA7DkgdjqEvQHEToKwj4DVhAQ5A9k3gGyB5IxEoBmML4BsnSQk8XQkNtReEOBxcfXxUQg1Mjc0dyHgXNJBSWpFCYh2zi+oLMpMzyhRcASGUqqCZ16yno6CkYGRAQMDKMwhqj/fAIcloxgHQqxAjIHBEugw5sUIsSQpBobtQPdLciLEVJYzMPBHMDBsayhILEqEO4DxG0txmrERhM29nYGBddr//5/DGRjYNRkY/l7////39v///y4Dmn+LgeHANwDrkl1AuO+pmgAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAwqADAAQAAAABAAAAwwAAAAD9b/HnAAAHlklEQVR4Ae3dP3PTWBSGcbGzM6GCKqlIBRV0dHRJFarQ0eUT8LH4BnRU0NHR0UEFVdIlFRV7TzRksomPY8uykTk/zewQfKw/9znv4yvJynLv4uLiV2dBoDiBf4qP3/ARuCRABEFAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghgg0Aj8i0JO4OzsrPv69Wv+hi2qPHr0qNvf39+iI97soRIh4f3z58/u7du3SXX7Xt7Z2enevHmzfQe+oSN2apSAPj09TSrb+XKI/f379+08+A0cNRE2ANkupk+ACNPvkSPcAAEibACyXUyfABGm3yNHuAECRNgAZLuYPgEirKlHu7u7XdyytGwHAd8jjNyng4OD7vnz51dbPT8/7z58+NB9+/bt6jU/TI+AGWHEnrx48eJ/EsSmHzx40L18+fLyzxF3ZVMjEyDCiEDjMYZZS5wiPXnyZFbJaxMhQIQRGzHvWR7XCyOCXsOmiDAi1HmPMMQjDpbpEiDCiL358eNHurW/5SnWdIBbXiDCiA38/Pnzrce2YyZ4//59F3ePLNMl4PbpiL2J0L979+7yDtHDhw8vtzzvdGnEXdvUigSIsCLAWavHp/+qM0BcXMd/q25n1vF57TYBp0a3mUzilePj4+7k5KSLb6gt6ydAhPUzXnoPR0dHl79WGTNCfBnn1uvSCJdegQhLI1vvCk+fPu2ePXt2tZOYEV6/fn31dz+shwAR1sP1cqvLntbEN9MxA9xcYjsxS1jWR4AIa2Ibzx0tc44fYX/16lV6NDFLXH+YL32jwiACRBiEbf5KcXoTIsQSpzXx4N28Ja4BQoK7rgXiydbHjx/P25TaQAJEGAguWy0+2Q8PD6/Ki4R8EVl+bzBOnZY95fq9rj9zAkTI2SxdidBHqG9+skdw43borCXO/ZcJdraPWdv22uIEiLA4q7nvvCug8WTqzQveOH26fodo7g6uFe/a17W3+nFBAkRYENRdb1vkkz1CH9cPsVy/jrhr27PqMYvENYNlHAIesRiBYwRy0V+8iXP8+/fvX11Mr7L7ECueb/r48eMqm7FuI2BGWDEG8cm+7G3NEOfmdcTQw4h9/55lhm7DekRYKQPZF2ArbXTAyu4kDYB2YxUzwg0gi/41ztHnfQG26HbGel/crVrm7tNY+/1btkOEAZ2M05r4FB7r9GbAIdxaZYrHdOsgJ/wCEQY0J74TmOKnbxxT9n3FgGGWWsVdowHtjt9Nnvf7yQM2aZU/TIAIAxrw6dOnAWtZZcoEnBpNuTuObWMEiLAx1HY0ZQJEmHJ3HNvGCBBhY6jtaMoEiJB0Z29vL6ls58vxPcO8/zfrdo5qvKO+d3Fx8Wu8zf1dW4p/cPzLly/dtv9Ts/EbcvGAHhHyfBIhZ6NSiIBTo0LNNtScABFyNiqFCBChULMNNSdAhJyNSiECRCjUbEPNCRAhZ6NSiAARCjXbUHMCRMjZqBQiQIRCzTbUnAARcjYqhQgQoVCzDTUnQIScjUohAkQo1GxDzQkQIWejUogAEQo121BzAkTI2agUIkCEQs021JwAEXI2KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiECRCjUbEPNCRAhZ6NSiAARCjXbUHMCRMjZqBQiQIRCzTbUnAARcjYqhQgQoVCzDTUnQIScjUohAkQo1GxDzQkQIWejUogAEQo121BzAkTI2agUIkCEQs021JwAEXI2KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiECRCjUbEPNCRAhZ6NSiAARCjXbUHMCRMjZqBQiQIRCzTbUnAARcjYqhQgQoVCzDTUnQIScjUohAkQo1GxDzQkQIWejUogAEQo121BzAkTI2agUIkCEQs021JwAEXI2KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiEC/wGgKKC4YMA4TAAAAABJRU5ErkJggg==';
|
||||
|
1
apps/web-antd/src/views/system/oss/fallback-image.txt
Normal file
1
apps/web-antd/src/views/system/oss/fallback-image.txt
Normal file
@@ -0,0 +1 @@
|
||||
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMIAAADDCAYAAADQvc6UAAABRWlDQ1BJQ0MgUHJvZmlsZQAAKJFjYGASSSwoyGFhYGDIzSspCnJ3UoiIjFJgf8LAwSDCIMogwMCcmFxc4BgQ4ANUwgCjUcG3awyMIPqyLsis7PPOq3QdDFcvjV3jOD1boQVTPQrgSkktTgbSf4A4LbmgqISBgTEFyFYuLykAsTuAbJEioKOA7DkgdjqEvQHEToKwj4DVhAQ5A9k3gGyB5IxEoBmML4BsnSQk8XQkNtReEOBxcfXxUQg1Mjc0dyHgXNJBSWpFCYh2zi+oLMpMzyhRcASGUqqCZ16yno6CkYGRAQMDKMwhqj/fAIcloxgHQqxAjIHBEugw5sUIsSQpBobtQPdLciLEVJYzMPBHMDBsayhILEqEO4DxG0txmrERhM29nYGBddr//5/DGRjYNRkY/l7////39v///y4Dmn+LgeHANwDrkl1AuO+pmgAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAwqADAAQAAAABAAAAwwAAAAD9b/HnAAAHlklEQVR4Ae3dP3PTWBSGcbGzM6GCKqlIBRV0dHRJFarQ0eUT8LH4BnRU0NHR0UEFVdIlFRV7TzRksomPY8uykTk/zewQfKw/9znv4yvJynLv4uLiV2dBoDiBf4qP3/ARuCRABEFAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghggQAQZQKAnYEaQBAQaASKIAQJEkAEEegJmBElAoBEgghgg0Aj8i0JO4OzsrPv69Wv+hi2qPHr0qNvf39+iI97soRIh4f3z58/u7du3SXX7Xt7Z2enevHmzfQe+oSN2apSAPj09TSrb+XKI/f379+08+A0cNRE2ANkupk+ACNPvkSPcAAEibACyXUyfABGm3yNHuAECRNgAZLuYPgEirKlHu7u7XdyytGwHAd8jjNyng4OD7vnz51dbPT8/7z58+NB9+/bt6jU/TI+AGWHEnrx48eJ/EsSmHzx40L18+fLyzxF3ZVMjEyDCiEDjMYZZS5wiPXnyZFbJaxMhQIQRGzHvWR7XCyOCXsOmiDAi1HmPMMQjDpbpEiDCiL358eNHurW/5SnWdIBbXiDCiA38/Pnzrce2YyZ4//59F3ePLNMl4PbpiL2J0L979+7yDtHDhw8vtzzvdGnEXdvUigSIsCLAWavHp/+qM0BcXMd/q25n1vF57TYBp0a3mUzilePj4+7k5KSLb6gt6ydAhPUzXnoPR0dHl79WGTNCfBnn1uvSCJdegQhLI1vvCk+fPu2ePXt2tZOYEV6/fn31dz+shwAR1sP1cqvLntbEN9MxA9xcYjsxS1jWR4AIa2Ibzx0tc44fYX/16lV6NDFLXH+YL32jwiACRBiEbf5KcXoTIsQSpzXx4N28Ja4BQoK7rgXiydbHjx/P25TaQAJEGAguWy0+2Q8PD6/Ki4R8EVl+bzBOnZY95fq9rj9zAkTI2SxdidBHqG9+skdw43borCXO/ZcJdraPWdv22uIEiLA4q7nvvCug8WTqzQveOH26fodo7g6uFe/a17W3+nFBAkRYENRdb1vkkz1CH9cPsVy/jrhr27PqMYvENYNlHAIesRiBYwRy0V+8iXP8+/fvX11Mr7L7ECueb/r48eMqm7FuI2BGWDEG8cm+7G3NEOfmdcTQw4h9/55lhm7DekRYKQPZF2ArbXTAyu4kDYB2YxUzwg0gi/41ztHnfQG26HbGel/crVrm7tNY+/1btkOEAZ2M05r4FB7r9GbAIdxaZYrHdOsgJ/wCEQY0J74TmOKnbxxT9n3FgGGWWsVdowHtjt9Nnvf7yQM2aZU/TIAIAxrw6dOnAWtZZcoEnBpNuTuObWMEiLAx1HY0ZQJEmHJ3HNvGCBBhY6jtaMoEiJB0Z29vL6ls58vxPcO8/zfrdo5qvKO+d3Fx8Wu8zf1dW4p/cPzLly/dtv9Ts/EbcvGAHhHyfBIhZ6NSiIBTo0LNNtScABFyNiqFCBChULMNNSdAhJyNSiECRCjUbEPNCRAhZ6NSiAARCjXbUHMCRMjZqBQiQIRCzTbUnAARcjYqhQgQoVCzDTUnQIScjUohAkQo1GxDzQkQIWejUogAEQo121BzAkTI2agUIkCEQs021JwAEXI2KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiECRCjUbEPNCRAhZ6NSiAARCjXbUHMCRMjZqBQiQIRCzTbUnAARcjYqhQgQoVCzDTUnQIScjUohAkQo1GxDzQkQIWejUogAEQo121BzAkTI2agUIkCEQs021JwAEXI2KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiECRCjUbEPNCRAhZ6NSiAARCjXbUHMCRMjZqBQiQIRCzTbUnAARcjYqhQgQoVCzDTUnQIScjUohAkQo1GxDzQkQIWejUogAEQo121BzAkTI2agUIkCEQs021JwAEXI2KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiEC/wGgKKC4YMA4TAAAAABJRU5ErkJggg==
|
@@ -31,7 +31,11 @@ const [BasicModal, modalApi] = useVbenModal({
|
||||
title="文件上传"
|
||||
>
|
||||
<div class="flex flex-col gap-4">
|
||||
<FileUpload v-model:value="fileList" :enable-drag-upload="true" />
|
||||
<FileUpload
|
||||
v-model:value="fileList"
|
||||
:enable-drag-upload="true"
|
||||
:max-count="3"
|
||||
/>
|
||||
</div>
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
@@ -31,7 +31,7 @@ const [BasicModal, modalApi] = useVbenModal({
|
||||
title="图片上传"
|
||||
>
|
||||
<div class="flex flex-col gap-4">
|
||||
<ImageUpload v-model:value="fileList" />
|
||||
<ImageUpload v-model:value="fileList" :max-count="3" />
|
||||
</div>
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
@@ -33,7 +33,9 @@ import { ossDownload, ossList, ossRemove } from '#/api/system/oss';
|
||||
import { calculateFileSize } from '#/utils/file';
|
||||
import { downloadByData } from '#/utils/file/download';
|
||||
|
||||
import { columns, fallbackImageBase64, querySchema } from './data';
|
||||
import { supportImageList } from './constant';
|
||||
import { columns, querySchema } from './data';
|
||||
import fallbackImageBase64 from './fallback-image.txt?raw';
|
||||
import fileUploadModal from './file-upload-modal.vue';
|
||||
import imageUploadModal from './image-upload-modal.vue';
|
||||
|
||||
@@ -154,7 +156,7 @@ function handleMultiDelete() {
|
||||
|
||||
const router = useRouter();
|
||||
function handleToSettings() {
|
||||
router.push('/system/oss-config');
|
||||
router.push('/system/oss-config/index');
|
||||
}
|
||||
|
||||
const preview = ref(false);
|
||||
@@ -163,10 +165,32 @@ onMounted(async () => {
|
||||
preview.value = previewStr === 'true';
|
||||
});
|
||||
|
||||
/**
|
||||
* 根据拓展名判断是否是图片
|
||||
* @param ext 拓展名
|
||||
*/
|
||||
function isImageFile(ext: string) {
|
||||
const supportList = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
|
||||
return supportList.some((item) => ext.toLocaleLowerCase().includes(item));
|
||||
return supportImageList.some((item) =>
|
||||
ext.toLocaleLowerCase().includes(item),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是pdf文件
|
||||
* @param ext 扩展名
|
||||
*/
|
||||
function isPdfFile(ext: string) {
|
||||
return ext.toLocaleLowerCase().includes('pdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* pdf预览 使用浏览器接管
|
||||
* @param url 文件地址
|
||||
*/
|
||||
function pdfPreview(url: string) {
|
||||
window.open(url);
|
||||
}
|
||||
|
||||
const [ImageUploadModal, imageUploadApi] = useVbenModal({
|
||||
connectedComponent: imageUploadModal,
|
||||
});
|
||||
@@ -230,6 +254,12 @@ const [FileUploadModal, fileUploadApi] = useVbenModal({
|
||||
</div>
|
||||
</template>
|
||||
</Image>
|
||||
<!-- pdf预览 使用浏览器开新窗口 -->
|
||||
<span
|
||||
v-else-if="preview && isPdfFile(row.url)"
|
||||
class="icon-[vscode-icons--file-type-pdf2] size-10 cursor-pointer"
|
||||
@click.stop="pdfPreview(row.url)"
|
||||
></span>
|
||||
<span v-else>{{ row.url }}</span>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
|
11
apps/web-antd/src/views/system/role/authUser.vue
Normal file
11
apps/web-antd/src/views/system/role/authUser.vue
Normal file
@@ -0,0 +1,11 @@
|
||||
<!--
|
||||
后端版本>=5.4.0 这个从本地路由变为从后台返回
|
||||
未修改文件名 而是新加了这个文件
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import RoleAssignPage from '#/views/system/role-assign/index.vue';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RoleAssignPage />
|
||||
</template>
|
@@ -142,7 +142,7 @@ function handleAuthEdit(record: Role) {
|
||||
|
||||
const router = useRouter();
|
||||
function handleAssignRole(record: Role) {
|
||||
router.push(`/system/role-assign/${record.roleId}`);
|
||||
router.push(`/system/role-auth/user/${record.roleId}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
6
apps/web-antd/src/views/system/user/authRole.vue
Normal file
6
apps/web-antd/src/views/system/user/authRole.vue
Normal file
@@ -0,0 +1,6 @@
|
||||
<template>
|
||||
<div>
|
||||
ele版本会使用这个文件 只是为了不报错`未找到对应组件`才新建的这个文件
|
||||
无实际意义
|
||||
</div>
|
||||
</template>
|
10
apps/web-antd/src/views/tool/gen/editTable.vue
Normal file
10
apps/web-antd/src/views/tool/gen/editTable.vue
Normal file
@@ -0,0 +1,10 @@
|
||||
<!--
|
||||
后端版本>=5.4.0 这个从本地路由变为从后台返回
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import EditGenPage from './edit-gen.vue';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<EditGenPage />
|
||||
</template>
|
@@ -110,7 +110,7 @@ function handlePreview(record: Recordable<any>) {
|
||||
|
||||
const router = useRouter();
|
||||
function handleEdit(record: Recordable<any>) {
|
||||
router.push(`/code-gen/edit/${record.tableId}`);
|
||||
router.push(`/tool/gen-edit/index/${record.tableId}`);
|
||||
}
|
||||
|
||||
async function handleSync(record: Recordable<any>) {
|
||||
|
@@ -41,6 +41,7 @@ import {
|
||||
import { renderDict } from '#/utils/render';
|
||||
|
||||
import { approvalModal, approvalRejectionModal, flowInterfereModal } from '.';
|
||||
import FlowPreview from '../components/flow-preview/index.vue';
|
||||
import ApprovalDetails from './approval-details.vue';
|
||||
import { approveWithReasonModal } from './helper';
|
||||
import userSelectModal from './user-select-modal.vue';
|
||||
@@ -442,9 +443,9 @@ async function handleCopy(text: string) {
|
||||
/>
|
||||
</TabPane>
|
||||
<TabPane key="2" tab="审批流程图">
|
||||
<img
|
||||
:src="`data:image/png;base64,${currentFlowInfo.image}`"
|
||||
class="rounded-lg border"
|
||||
<FlowPreview
|
||||
v-if="currentFlowInfo.defChart"
|
||||
:data="currentFlowInfo.defChart.defJson"
|
||||
/>
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
|
@@ -0,0 +1,121 @@
|
||||
<script setup lang="ts">
|
||||
import type { ZoomParamType } from '@logicflow/core';
|
||||
|
||||
import { onMounted, shallowRef, useTemplateRef, watch } from 'vue';
|
||||
|
||||
import { usePreferences } from '@vben/preferences';
|
||||
|
||||
import {
|
||||
MinusCircleOutlined,
|
||||
PlusCircleOutlined,
|
||||
ShrinkOutlined,
|
||||
} from '@ant-design/icons-vue';
|
||||
import LogicFlow from '@logicflow/core';
|
||||
|
||||
import Between from './model/between';
|
||||
import End from './model/end';
|
||||
import Parallel from './model/parallel';
|
||||
import Serial from './model/serial';
|
||||
import Skip from './model/skip';
|
||||
import Start from './model/start';
|
||||
import { json2LogicFlowJson } from './model/tool';
|
||||
|
||||
import '@logicflow/core/lib/style/index.css';
|
||||
|
||||
const props = withDefaults(defineProps<{ data?: object }>(), {
|
||||
data: () => ({}),
|
||||
});
|
||||
|
||||
const container = useTemplateRef('container');
|
||||
const lf = shallowRef<LogicFlow | null>(null);
|
||||
|
||||
function zoomViewport(zoom: ZoomParamType) {
|
||||
if (!lf.value) {
|
||||
return;
|
||||
}
|
||||
lf.value.zoom(zoom);
|
||||
// 将内容平移至画布中心
|
||||
lf.value.translateCenter();
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (props.data && container.value) {
|
||||
const data = json2LogicFlowJson(props.data);
|
||||
lf.value = new LogicFlow({
|
||||
container: container.value,
|
||||
isSilentMode: true,
|
||||
textEdit: false,
|
||||
grid: {
|
||||
size: 20,
|
||||
type: 'dot',
|
||||
config: {
|
||||
color: '#ccc',
|
||||
thickness: 1,
|
||||
},
|
||||
},
|
||||
background: {
|
||||
backgroundColor: '#fff',
|
||||
},
|
||||
});
|
||||
|
||||
lf.value.register(Start);
|
||||
lf.value.register(Between);
|
||||
lf.value.register(Serial);
|
||||
lf.value.register(Parallel);
|
||||
lf.value.register(End);
|
||||
lf.value.register(Skip);
|
||||
|
||||
lf.value.render(data);
|
||||
lf.value.translateCenter();
|
||||
}
|
||||
});
|
||||
|
||||
const { isDark } = usePreferences();
|
||||
watch(isDark, (v) => {
|
||||
if (!lf.value) {
|
||||
return;
|
||||
}
|
||||
lf.value.graphModel.background = {
|
||||
background: v ? '#333' : '#fff',
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="flex items-center justify-between py-2">
|
||||
<div class="flex items-center gap-3">
|
||||
<a-button @click="zoomViewport(1)">
|
||||
<template #icon>
|
||||
<ShrinkOutlined />
|
||||
</template>
|
||||
</a-button>
|
||||
<a-button @click="zoomViewport(true)">
|
||||
<template #icon>
|
||||
<PlusCircleOutlined />
|
||||
</template>
|
||||
</a-button>
|
||||
<a-button @click="zoomViewport(false)">
|
||||
<template #icon>
|
||||
<MinusCircleOutlined />
|
||||
</template>
|
||||
</a-button>
|
||||
</div>
|
||||
<div class="flex items-center gap-3 font-semibold">
|
||||
<span class="rounded-md border border-[#000] px-2">未办理</span>
|
||||
<span
|
||||
class="rounded-md border border-dashed border-[#ffcd17] bg-[#fff8dc] px-2 dark:text-black"
|
||||
>
|
||||
待办理
|
||||
</span>
|
||||
<span
|
||||
class="rounded-md border border-[#9dff00] bg-[#f0ffd9] px-2 dark:text-black"
|
||||
>
|
||||
已完成
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 容器区域 -->
|
||||
<div class="h-[500px] w-full border" ref="container"></div>
|
||||
</div>
|
||||
</template>
|
@@ -0,0 +1,21 @@
|
||||
import LogicFlow, { RectNode, RectNodeModel } from '@logicflow/core';
|
||||
|
||||
class BetweenModel extends RectNodeModel {
|
||||
override getNodeStyle() {
|
||||
return super.getNodeStyle();
|
||||
}
|
||||
override initNodeData(data: LogicFlow.NodeConfig) {
|
||||
super.initNodeData(data);
|
||||
this.width = 100;
|
||||
this.height = 80;
|
||||
this.radius = 5;
|
||||
}
|
||||
}
|
||||
|
||||
class BetweenView extends RectNode {}
|
||||
|
||||
export default {
|
||||
type: 'between',
|
||||
model: BetweenModel,
|
||||
view: BetweenView,
|
||||
};
|
@@ -0,0 +1,16 @@
|
||||
import LogicFlow, { CircleNode, CircleNodeModel } from '@logicflow/core';
|
||||
|
||||
class endModel extends CircleNodeModel {
|
||||
override initNodeData(data: LogicFlow.NodeConfig) {
|
||||
super.initNodeData(data);
|
||||
this.r = 20;
|
||||
}
|
||||
}
|
||||
|
||||
class endView extends CircleNode {}
|
||||
|
||||
export default {
|
||||
type: 'end',
|
||||
model: endModel,
|
||||
view: endView,
|
||||
};
|
@@ -0,0 +1,59 @@
|
||||
import type { GraphModel } from '@logicflow/core';
|
||||
|
||||
import LogicFlow, { h, PolygonNode, PolygonNodeModel } from '@logicflow/core';
|
||||
|
||||
class ParallelModel extends PolygonNodeModel {
|
||||
static extendKey = 'ParallelModel';
|
||||
|
||||
constructor(data: LogicFlow.NodeConfig, graphModel: GraphModel) {
|
||||
if (!data.text) {
|
||||
data.text = '';
|
||||
}
|
||||
if (data.text && typeof data.text === 'string') {
|
||||
data.text = {
|
||||
value: data.text,
|
||||
x: data.x,
|
||||
y: data.y + 40,
|
||||
};
|
||||
}
|
||||
super(data, graphModel);
|
||||
this.points = [
|
||||
[25, 0],
|
||||
[50, 25],
|
||||
[25, 50],
|
||||
[0, 25],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class ParallelView extends PolygonNode {
|
||||
static extendKey = 'ParallelNode';
|
||||
|
||||
override getShape() {
|
||||
const { model } = this.props;
|
||||
const { x, y, width, height, points } = model;
|
||||
const style = model.getNodeStyle();
|
||||
return h(
|
||||
'g',
|
||||
{
|
||||
transform: `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`,
|
||||
},
|
||||
h('polygon', {
|
||||
...style,
|
||||
x,
|
||||
y,
|
||||
points,
|
||||
}),
|
||||
h('path', {
|
||||
d: 'm 23,10 0,12.5 -12.5,0 0,5 12.5,0 0,12.5 5,0 0,-12.5 12.5,0 0,-5 -12.5,0 0,-12.5 -5,0 z',
|
||||
...style,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
type: 'parallel',
|
||||
view: ParallelView,
|
||||
model: ParallelModel,
|
||||
};
|
@@ -0,0 +1,59 @@
|
||||
import type { GraphModel } from '@logicflow/core';
|
||||
|
||||
import LogicFlow, { h, PolygonNode, PolygonNodeModel } from '@logicflow/core';
|
||||
|
||||
class SerialModel extends PolygonNodeModel {
|
||||
static extendKey = 'SerialModel';
|
||||
|
||||
constructor(data: LogicFlow.NodeConfig, graphModel: GraphModel) {
|
||||
if (!data.text) {
|
||||
data.text = '';
|
||||
}
|
||||
if (data.text && typeof data.text === 'string') {
|
||||
data.text = {
|
||||
value: data.text,
|
||||
x: data.x,
|
||||
y: data.y + 40,
|
||||
};
|
||||
}
|
||||
super(data, graphModel);
|
||||
this.points = [
|
||||
[25, 0],
|
||||
[50, 25],
|
||||
[25, 50],
|
||||
[0, 25],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class SerialView extends PolygonNode {
|
||||
static extendKey = 'SerialNode';
|
||||
|
||||
override getShape() {
|
||||
const { model } = this.props;
|
||||
const { x, y, width, height, points } = model;
|
||||
const style = model.getNodeStyle();
|
||||
return h(
|
||||
'g',
|
||||
{
|
||||
transform: `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`,
|
||||
},
|
||||
h('polygon', {
|
||||
...style,
|
||||
x,
|
||||
y,
|
||||
points,
|
||||
}),
|
||||
h('path', {
|
||||
d: 'm 16,15 7.42857142857143,9.714285714285715 -7.42857142857143,9.714285714285715 3.428571428571429,0 5.714285714285715,-7.464228571428572 5.714285714285715,7.464228571428572 3.428571428571429,0 -7.42857142857143,-9.714285714285715 7.42857142857143,-9.714285714285715 -3.428571428571429,0 -5.714285714285715,7.464228571428572 -5.714285714285715,-7.464228571428572 -3.428571428571429,0 z',
|
||||
...style,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
type: 'serial',
|
||||
view: SerialView,
|
||||
model: SerialModel,
|
||||
};
|
@@ -0,0 +1,32 @@
|
||||
import { PolylineEdge, PolylineEdgeModel } from '@logicflow/core';
|
||||
|
||||
class SkipModel extends PolylineEdgeModel {
|
||||
/**
|
||||
* 重写此方法,使保存数据是能带上锚点数据。
|
||||
*/
|
||||
override getData() {
|
||||
const data = super.getData();
|
||||
data.sourceAnchorId = this.sourceAnchorId;
|
||||
data.targetAnchorId = this.targetAnchorId;
|
||||
return data;
|
||||
}
|
||||
|
||||
override getEdgeStyle() {
|
||||
const style = super.getEdgeStyle();
|
||||
const { properties } = this;
|
||||
if (properties.isActived) {
|
||||
style.strokeDasharray = '4 4';
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
override setAttributes() {
|
||||
this.offset = 20;
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
type: 'skip',
|
||||
view: PolylineEdge,
|
||||
model: SkipModel,
|
||||
};
|
@@ -0,0 +1,16 @@
|
||||
import LogicFlow, { CircleNode, CircleNodeModel } from '@logicflow/core';
|
||||
|
||||
class StartModel extends CircleNodeModel {
|
||||
override initNodeData(data: LogicFlow.NodeConfig) {
|
||||
super.initNodeData(data);
|
||||
this.r = 20;
|
||||
}
|
||||
}
|
||||
|
||||
class StartView extends CircleNode {}
|
||||
|
||||
export default {
|
||||
type: 'start',
|
||||
model: StartModel,
|
||||
view: StartView,
|
||||
};
|
@@ -0,0 +1,248 @@
|
||||
/* eslint-disable unicorn/no-array-reduce */
|
||||
const NODE_TYPE_MAP = {
|
||||
0: 'start',
|
||||
1: 'between',
|
||||
2: 'end',
|
||||
3: 'serial',
|
||||
4: 'parallel',
|
||||
};
|
||||
|
||||
/**
|
||||
* 将warm-flow的定义json数据转成LogicFlow支持的数据格式
|
||||
* @param {*} json
|
||||
* @returns LogicFlow的数据
|
||||
*/
|
||||
export const json2LogicFlowJson = (definition: any) => {
|
||||
const graphData: any = {
|
||||
nodes: [],
|
||||
edges: [],
|
||||
};
|
||||
// 解析definition属性
|
||||
graphData.flowCode = definition.flowCode;
|
||||
graphData.flowName = definition.flowName;
|
||||
graphData.version = definition.version;
|
||||
graphData.fromCustom = definition.fromCustom;
|
||||
graphData.fromPath = definition.fromPath;
|
||||
// 解析节点
|
||||
const allSkips = definition.nodeList.reduce((acc: any, node: any) => {
|
||||
if (node.skipList && Array.isArray(node.skipList)) {
|
||||
acc.push(...node.skipList);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
const allNodes = definition.nodeList;
|
||||
// 解析节点
|
||||
if (allNodes.length > 0) {
|
||||
for (let i = 0, len = allNodes.length; i < len; i++) {
|
||||
const node = allNodes[i];
|
||||
const lfNode: any = {
|
||||
text: {},
|
||||
properties: {},
|
||||
};
|
||||
// 处理节点
|
||||
lfNode.type = (NODE_TYPE_MAP as any)[node.nodeType];
|
||||
lfNode.id = node.nodeCode;
|
||||
const coordinate = node.coordinate;
|
||||
if (coordinate) {
|
||||
const attr = coordinate.split('|');
|
||||
const nodeXy = attr[0].split(',');
|
||||
lfNode.x = Number.parseInt(nodeXy[0]);
|
||||
lfNode.y = Number.parseInt(nodeXy[1]);
|
||||
if (attr.length === 2) {
|
||||
const textXy = attr[1].split(',');
|
||||
lfNode.text.x = Number.parseInt(textXy[0]);
|
||||
lfNode.text.y = Number.parseInt(textXy[1]);
|
||||
}
|
||||
}
|
||||
lfNode.text.value = node.nodeName;
|
||||
lfNode.properties.nodeRatio = node.nodeRatio.toString();
|
||||
lfNode.properties.permissionFlag = node.permissionFlag;
|
||||
lfNode.properties.anyNodeSkip = node.anyNodeSkip;
|
||||
lfNode.properties.listenerType = node.listenerType;
|
||||
lfNode.properties.listenerPath = node.listenerPath;
|
||||
lfNode.properties.formCustom = node.formCustom;
|
||||
lfNode.properties.formPath = node.formPath;
|
||||
lfNode.properties.ext = {};
|
||||
if (node.ext && typeof node.ext === 'string') {
|
||||
try {
|
||||
node.ext = JSON.parse(node.ext);
|
||||
node.ext.forEach((e: any) => {
|
||||
lfNode.properties.ext[e.code] = String(e.value).includes(',')
|
||||
? e.value.split(',')
|
||||
: String(e.value);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error parsing JSON:', error);
|
||||
}
|
||||
}
|
||||
lfNode.properties.style = {};
|
||||
if (node.status === 2) {
|
||||
lfNode.properties.style.fill = '#F0FFD9';
|
||||
lfNode.properties.style.stroke = '#9DFF00';
|
||||
}
|
||||
if (node.status === 1) {
|
||||
lfNode.properties.style.fill = '#FFF8DC';
|
||||
lfNode.properties.style.stroke = '#FFCD17';
|
||||
}
|
||||
graphData.nodes.push(lfNode);
|
||||
}
|
||||
}
|
||||
if (allSkips.length > 0) {
|
||||
// 处理边
|
||||
let skipEle = null;
|
||||
let edge: any = {};
|
||||
for (let j = 0, lenn = allSkips.length; j < lenn; j++) {
|
||||
skipEle = allSkips[j];
|
||||
edge = {
|
||||
text: {},
|
||||
properties: {},
|
||||
};
|
||||
edge.id = skipEle.id;
|
||||
edge.type = 'skip';
|
||||
edge.sourceNodeId = skipEle.nowNodeCode;
|
||||
edge.targetNodeId = skipEle.nextNodeCode;
|
||||
edge.text = { value: skipEle.skipName };
|
||||
edge.properties.skipCondition = skipEle.skipCondition;
|
||||
edge.properties.skipName = skipEle.skipName;
|
||||
edge.properties.skipType = skipEle.skipType;
|
||||
const expr = skipEle.expr;
|
||||
if (expr) {
|
||||
edge.properties.expr = skipEle.expr;
|
||||
}
|
||||
const coordinate = skipEle.coordinate;
|
||||
if (coordinate) {
|
||||
const coordinateXy = coordinate.split('|');
|
||||
edge.pointsList = [];
|
||||
coordinateXy[0].split(';').forEach((item: any) => {
|
||||
const pointArr = item.split(',');
|
||||
edge.pointsList.push({
|
||||
x: Number.parseInt(pointArr[0]),
|
||||
y: Number.parseInt(pointArr[1]),
|
||||
});
|
||||
});
|
||||
edge.startPoint = edge.pointsList[0];
|
||||
edge.endPoint = edge.pointsList[edge.pointsList.length - 1];
|
||||
if (coordinateXy.length > 1) {
|
||||
const textXy = coordinateXy[1].split(',');
|
||||
edge.text.x = Number.parseInt(textXy[0]);
|
||||
edge.text.y = Number.parseInt(textXy[1]);
|
||||
}
|
||||
}
|
||||
graphData.edges.push(edge);
|
||||
}
|
||||
}
|
||||
console.log(graphData);
|
||||
return graphData;
|
||||
};
|
||||
|
||||
/**
|
||||
* 将LogicFlow的数据转成warm-flow的json定义文件
|
||||
* @param {*} data(...definitionInfo,nodes,edges)
|
||||
* @returns
|
||||
*/
|
||||
export const logicFlowJsonToWarmFlow = (data: any) => {
|
||||
// 先构建成流程对象
|
||||
const definition: any = {
|
||||
nodeList: [],
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据节点的类型值,获取key
|
||||
* @param {*} mapValue 节点类型映射
|
||||
* @returns
|
||||
*/
|
||||
const getNodeTypeValue = (mapValue: any) => {
|
||||
for (const key in NODE_TYPE_MAP) {
|
||||
if ((NODE_TYPE_MAP as any)[key] === mapValue) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 根据节点的编码,获取节点的类型
|
||||
* @param {*} nodeCode 当前节点名称
|
||||
* @returns
|
||||
*/
|
||||
const getNodeType = (nodeCode: any) => {
|
||||
for (const node of definition.nodeList) {
|
||||
if (nodeCode === node.nodeCode) {
|
||||
return node.nodeType;
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 拼接skip坐标
|
||||
* @param {*} edge logicFlow的edge
|
||||
* @returns
|
||||
*/
|
||||
const getCoordinate = (edge: any) => {
|
||||
let coordinate = '';
|
||||
for (let i = 0; i < edge.pointsList.length; i++) {
|
||||
coordinate = `${
|
||||
coordinate + Number.parseInt(edge.pointsList[i].x)
|
||||
},${Number.parseInt(edge.pointsList[i].y)}`;
|
||||
if (i !== edge.pointsList.length - 1) {
|
||||
coordinate = `${coordinate};`;
|
||||
}
|
||||
}
|
||||
if (edge.text) {
|
||||
coordinate = `${coordinate}|${Number.parseInt(edge.text.x)},${Number.parseInt(edge.text.y)}`;
|
||||
}
|
||||
return coordinate;
|
||||
};
|
||||
// 流程定义
|
||||
definition.id = data.id;
|
||||
definition.flowCode = data.flowCode;
|
||||
definition.flowName = data.flowName;
|
||||
definition.version = data.version;
|
||||
definition.fromCustom = data.fromCustom;
|
||||
definition.fromPath = data.fromPath;
|
||||
// 流程节点
|
||||
data.nodes.forEach((anyNode: any) => {
|
||||
const node: any = {};
|
||||
node.nodeType = getNodeTypeValue(anyNode.type);
|
||||
node.nodeCode = anyNode.id;
|
||||
if (anyNode.text) {
|
||||
node.nodeName = anyNode.text.value;
|
||||
}
|
||||
node.permissionFlag = anyNode.properties.permissionFlag;
|
||||
node.nodeRatio = anyNode.properties.nodeRatio;
|
||||
node.anyNodeSkip = anyNode.properties.anyNodeSkip;
|
||||
node.listenerType = anyNode.properties.listenerType;
|
||||
node.listenerPath = anyNode.properties.listenerPath;
|
||||
node.formCustom = anyNode.properties.formCustom;
|
||||
node.formPath = anyNode.properties.formPath;
|
||||
node.ext = [];
|
||||
for (const key in anyNode.properties.ext) {
|
||||
if (Object.prototype.hasOwnProperty.call(anyNode.properties.ext, key)) {
|
||||
const e = anyNode.properties.ext[key];
|
||||
node.ext.push({ code: key, value: Array.isArray(e) ? e.join(',') : e });
|
||||
}
|
||||
}
|
||||
node.ext = JSON.stringify(node.ext);
|
||||
node.coordinate = `${anyNode.x},${anyNode.y}`;
|
||||
if (anyNode.text && anyNode.text.x && anyNode.text.y) {
|
||||
node.coordinate = `${node.coordinate}|${anyNode.text.x},${anyNode.text.y}`;
|
||||
}
|
||||
node.handlerType = anyNode.properties.handlerType;
|
||||
node.handlerPath = anyNode.properties.handlerPath;
|
||||
node.version = definition.version;
|
||||
node.skipList = [];
|
||||
data.edges.forEach((anyEdge: any) => {
|
||||
if (anyEdge.sourceNodeId === anyNode.id) {
|
||||
const skip: any = {};
|
||||
skip.skipType = anyEdge.properties.skipType;
|
||||
skip.skipCondition = anyEdge.properties.skipCondition;
|
||||
skip.skipName = anyEdge?.text?.value || anyEdge.properties.skipName;
|
||||
skip.nowNodeCode = anyEdge.sourceNodeId;
|
||||
skip.nowNodeType = getNodeType(skip.nowNodeCode);
|
||||
skip.nextNodeCode = anyEdge.targetNodeId;
|
||||
skip.nextNodeType = getNodeType(skip.nextNodeCode);
|
||||
skip.coordinate = getCoordinate(anyEdge);
|
||||
node.skipList.push(skip);
|
||||
}
|
||||
});
|
||||
definition.nodeList.push(node);
|
||||
});
|
||||
return JSON.stringify(definition);
|
||||
};
|
11
apps/web-antd/src/views/workflow/leave/leaveEdit.vue
Normal file
11
apps/web-antd/src/views/workflow/leave/leaveEdit.vue
Normal file
@@ -0,0 +1,11 @@
|
||||
<!--
|
||||
后端版本>=5.4.0 这个从本地路由变为从后台返回
|
||||
未修改文件名 而是新加了这个文件
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import LeaveFormPage from './leave-form.vue';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<LeaveFormPage />
|
||||
</template>
|
@@ -0,0 +1,11 @@
|
||||
<!--
|
||||
后端版本>=5.4.0 这个从本地路由变为从后台返回
|
||||
未修改文件名 而是新加了这个文件
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import FlowDesignerPage from '../components/flow-designer.vue';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FlowDesignerPage />
|
||||
</template>
|
@@ -154,7 +154,7 @@ const router = useRouter();
|
||||
*/
|
||||
function handleDesign(row: any, disabled: boolean) {
|
||||
router.push({
|
||||
path: '/workflow/designer',
|
||||
path: '/workflow/design/index',
|
||||
query: { definitionId: row.id, disabled: String(disabled) },
|
||||
});
|
||||
}
|
||||
|
@@ -26,6 +26,12 @@ outline: deep
|
||||
|
||||
<DemoPreview dir="demos/vben-ellipsis-text/tooltip" />
|
||||
|
||||
## 自动显示 tooltip
|
||||
|
||||
通过`tooltip-when-ellipsis`设置,仅在文本长度超出导致省略号出现时才触发 tooltip。
|
||||
|
||||
<DemoPreview dir="demos/vben-ellipsis-text/auto-display" />
|
||||
|
||||
## API
|
||||
|
||||
### Props
|
||||
@@ -37,6 +43,8 @@ outline: deep
|
||||
| maxWidth | 文本区域最大宽度 | `number \| string` | `'100%'` |
|
||||
| placement | 提示浮层的位置 | `'bottom'\|'left'\|'right'\|'top'` | `'top'` |
|
||||
| tooltip | 启用文本提示 | `boolean` | `true` |
|
||||
| tooltipWhenEllipsis | 内容超出,自动启用文本提示 | `boolean` | `false` |
|
||||
| ellipsisThreshold | 设置 tooltipWhenEllipsis 后才生效,文本截断检测的像素差异阈值,越大则判断越严格,如果碰见异常情况可以自己设置阈值 | `number` | `3` |
|
||||
| tooltipBackgroundColor | 提示文本的背景颜色 | `string` | - |
|
||||
| tooltipColor | 提示文本的颜色 | `string` | - |
|
||||
| tooltipFontSize | 提示文本的大小 | `string` | - |
|
||||
|
16
docs/src/demos/vben-ellipsis-text/auto-display/index.vue
Normal file
16
docs/src/demos/vben-ellipsis-text/auto-display/index.vue
Normal file
@@ -0,0 +1,16 @@
|
||||
<script lang="ts" setup>
|
||||
import { EllipsisText } from '@vben/common-ui';
|
||||
|
||||
const text = `
|
||||
Vben Admin 是一个基于 Vue3.0、Vite、 TypeScript 的后台解决方案,目标是为开发中大型项目提供开箱即用的解决方案。
|
||||
`;
|
||||
</script>
|
||||
<template>
|
||||
<EllipsisText :line="2" :tooltip-when-ellipsis="true">
|
||||
{{ text }}
|
||||
</EllipsisText>
|
||||
|
||||
<EllipsisText :line="3" :tooltip-when-ellipsis="true">
|
||||
{{ text }}
|
||||
</EllipsisText>
|
||||
</template>
|
@@ -186,6 +186,12 @@ const defaultPreferences: Preferences = {
|
||||
colorWeakMode: false,
|
||||
compact: false,
|
||||
contentCompact: 'wide',
|
||||
contentCompactWidth: 1200,
|
||||
contentPadding: 0,
|
||||
contentPaddingBottom: 0,
|
||||
contentPaddingLeft: 0,
|
||||
contentPaddingRight: 0,
|
||||
contentPaddingTop: 0,
|
||||
defaultAvatar:
|
||||
'https://unpkg.com/@vbenjs/static-source@0.1.7/source/avatar-v1.webp',
|
||||
defaultHomePath: '/analytics',
|
||||
@@ -200,6 +206,7 @@ const defaultPreferences: Preferences = {
|
||||
name: 'Vben Admin',
|
||||
preferencesButtonPosition: 'auto',
|
||||
watermark: false,
|
||||
zIndex: 200,
|
||||
},
|
||||
breadcrumb: {
|
||||
enable: true,
|
||||
@@ -220,15 +227,18 @@ const defaultPreferences: Preferences = {
|
||||
footer: {
|
||||
enable: false,
|
||||
fixed: false,
|
||||
height: 32,
|
||||
},
|
||||
header: {
|
||||
enable: true,
|
||||
height: 50,
|
||||
hidden: false,
|
||||
menuAlign: 'start',
|
||||
mode: 'fixed',
|
||||
},
|
||||
logo: {
|
||||
enable: true,
|
||||
fit: 'contain',
|
||||
source: 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp',
|
||||
},
|
||||
navigation: {
|
||||
@@ -248,11 +258,14 @@ const defaultPreferences: Preferences = {
|
||||
collapsed: false,
|
||||
collapsedButton: true,
|
||||
collapsedShowTitle: false,
|
||||
collapseWidth: 60,
|
||||
enable: true,
|
||||
expandOnHover: true,
|
||||
extraCollapse: false,
|
||||
extraCollapsedWidth: 60,
|
||||
fixedButton: true,
|
||||
hidden: false,
|
||||
mixedWidth: 80,
|
||||
width: 224,
|
||||
},
|
||||
tabbar: {
|
||||
@@ -319,6 +332,18 @@ interface AppPreferences {
|
||||
compact: boolean;
|
||||
/** Whether to enable content compact mode */
|
||||
contentCompact: ContentCompactType;
|
||||
/** Content compact width */
|
||||
contentCompactWidth: number;
|
||||
/** Content padding */
|
||||
contentPadding: number;
|
||||
/** Content bottom padding */
|
||||
contentPaddingBottom: number;
|
||||
/** Content left padding */
|
||||
contentPaddingLeft: number;
|
||||
/** Content right padding */
|
||||
contentPaddingRight: number;
|
||||
/** Content top padding */
|
||||
contentPaddingTop: number;
|
||||
// /** Default application avatar */
|
||||
defaultAvatar: string;
|
||||
/** Default homepage path */
|
||||
@@ -349,6 +374,8 @@ interface AppPreferences {
|
||||
* @zh_CN Whether to enable watermark
|
||||
*/
|
||||
watermark: boolean;
|
||||
/** z-index */
|
||||
zIndex: number;
|
||||
}
|
||||
interface BreadcrumbPreferences {
|
||||
/** Whether breadcrumbs are enabled */
|
||||
@@ -385,11 +412,15 @@ interface FooterPreferences {
|
||||
enable: boolean;
|
||||
/** Whether the footer is fixed */
|
||||
fixed: boolean;
|
||||
/** Footer height */
|
||||
height: number;
|
||||
}
|
||||
|
||||
interface HeaderPreferences {
|
||||
/** Whether the header is enabled */
|
||||
enable: boolean;
|
||||
/** Header height */
|
||||
height: number;
|
||||
/** Whether the header is hidden, css-hidden */
|
||||
hidden: boolean;
|
||||
/** Header menu alignment */
|
||||
@@ -401,6 +432,8 @@ interface HeaderPreferences {
|
||||
interface LogoPreferences {
|
||||
/** Whether the logo is visible */
|
||||
enable: boolean;
|
||||
/** Logo image fitting method */
|
||||
fit: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
||||
/** Logo URL */
|
||||
source: string;
|
||||
}
|
||||
@@ -422,16 +455,22 @@ interface SidebarPreferences {
|
||||
collapsedButton: boolean;
|
||||
/** Whether to show title when sidebar is collapsed */
|
||||
collapsedShowTitle: boolean;
|
||||
/** Sidebar collapse width */
|
||||
collapseWidth: number;
|
||||
/** Whether the sidebar is visible */
|
||||
enable: boolean;
|
||||
/** Menu auto-expand state */
|
||||
expandOnHover: boolean;
|
||||
/** Whether the sidebar extension area is collapsed */
|
||||
extraCollapse: boolean;
|
||||
/** Sidebar extension area collapse width */
|
||||
extraCollapsedWidth: number;
|
||||
/** Whether the sidebar fixed button is visible */
|
||||
fixedButton: boolean;
|
||||
/** Whether the sidebar is hidden - css */
|
||||
hidden: boolean;
|
||||
/** Mixed sidebar width */
|
||||
mixedWidth: number;
|
||||
/** Sidebar width */
|
||||
width: number;
|
||||
}
|
||||
|
@@ -4,10 +4,11 @@ outline: deep
|
||||
|
||||
# Access Control
|
||||
|
||||
The framework has built-in two types of access control methods:
|
||||
The framework has built-in three types of access control methods:
|
||||
|
||||
- Determining whether a menu or button can be accessed based on user roles
|
||||
- Determining whether a menu or button can be accessed through an API
|
||||
- Mixed mode: Using both frontend and backend access control simultaneously
|
||||
|
||||
## Frontend Access Control
|
||||
|
||||
@@ -151,6 +152,43 @@ const dashboardMenus = [
|
||||
|
||||
At this point, the configuration is complete. You need to ensure that after logging in, the format of the menu returned by the interface is correct; otherwise, access will not be possible.
|
||||
|
||||
## Mixed Access Control
|
||||
|
||||
**Implementation Principle**: Mixed mode combines both frontend access control and backend access control methods. The system processes frontend fixed route permissions and backend dynamic menu data in parallel, ultimately merging both parts of routes to provide a more flexible access control solution.
|
||||
|
||||
**Advantages**: Combines the performance advantages of frontend control with the flexibility of backend control, suitable for complex business scenarios requiring permission management.
|
||||
|
||||
### Steps
|
||||
|
||||
- Ensure the current mode is set to mixed access control
|
||||
|
||||
Adjust `preferences.ts` in the corresponding application directory to ensure `accessMode='mixed'`.
|
||||
|
||||
```ts
|
||||
import { defineOverridesPreferences } from '@vben/preferences';
|
||||
|
||||
export const overridesPreferences = defineOverridesPreferences({
|
||||
// overrides
|
||||
app: {
|
||||
accessMode: 'mixed',
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
- Configure frontend route permissions
|
||||
|
||||
Same as the route permission configuration method in [Frontend Access Control](#frontend-access-control) mode.
|
||||
|
||||
- Configure backend menu interface
|
||||
|
||||
Same as the interface configuration method in [Backend Access Control](#backend-access-control) mode.
|
||||
|
||||
- Ensure roles and permissions match
|
||||
|
||||
Must satisfy both frontend route permission configuration and backend menu data return requirements, ensuring user roles match the permission configurations of both modes.
|
||||
|
||||
At this point, the configuration is complete. Mixed mode will automatically merge frontend and backend routes, providing complete access control functionality.
|
||||
|
||||
## Fine-grained Control of Buttons
|
||||
|
||||
In some cases, we need to control the display of buttons with fine granularity. We can control the display of buttons through interfaces or roles.
|
||||
|
@@ -214,7 +214,7 @@ server {
|
||||
|
||||
使用 nginx 处理项目部署后的跨域问题
|
||||
|
||||
1. 配置前端项目接口地址,在项目目录下的``.env.production`文件中配置:
|
||||
1. 配置前端项目接口地址,在项目目录下的`.env.production`文件中配置:
|
||||
|
||||
```bash
|
||||
VITE_GLOB_API_URL=/api
|
||||
|
@@ -339,6 +339,10 @@ interface RouteMeta {
|
||||
| 'success'
|
||||
| 'warning'
|
||||
| string;
|
||||
/**
|
||||
* 路由的完整路径作为key(默认true)
|
||||
*/
|
||||
fullPathKey?: boolean;
|
||||
/**
|
||||
* 当前路由的子级在菜单中不展现
|
||||
* @default false
|
||||
@@ -502,6 +506,13 @@ interface RouteMeta {
|
||||
|
||||
用于配置页面的徽标颜色。
|
||||
|
||||
### fullPathKey
|
||||
|
||||
- 类型:`boolean`
|
||||
- 默认值:`true`
|
||||
|
||||
是否将路由的完整路径作为tab key(默认true)
|
||||
|
||||
### activePath
|
||||
|
||||
- 类型:`string`
|
||||
@@ -602,3 +613,32 @@ const { refresh } = useRefresh();
|
||||
refresh();
|
||||
</script>
|
||||
```
|
||||
|
||||
## 标签页与路由控制
|
||||
|
||||
在某些场景下,需要单个路由打开多个标签页,或者修改路由的query不打开新的标签页
|
||||
|
||||
每个标签页Tab使用唯一的key标识,设置Tab key有三种方式,优先级由高到低:
|
||||
|
||||
- 使用路由query参数pageKey
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { useRouter } from 'vue-router';
|
||||
// 跳转路由
|
||||
const router = useRouter();
|
||||
router.push({
|
||||
path: 'path',
|
||||
query: {
|
||||
pageKey: 'key',
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
- 路由的完整路径作为key
|
||||
|
||||
`meta` 属性中的 `fullPathKey`不为false,则使用路由`fullPath`作为key
|
||||
|
||||
- 路由的path作为key
|
||||
|
||||
`meta` 属性中的 `fullPathKey`为false,则使用路由`path`作为key
|
||||
|
@@ -185,6 +185,12 @@ const defaultPreferences: Preferences = {
|
||||
colorWeakMode: false,
|
||||
compact: false,
|
||||
contentCompact: 'wide',
|
||||
contentCompactWidth: 1200,
|
||||
contentPadding: 0,
|
||||
contentPaddingBottom: 0,
|
||||
contentPaddingLeft: 0,
|
||||
contentPaddingRight: 0,
|
||||
contentPaddingTop: 0,
|
||||
defaultAvatar:
|
||||
'https://unpkg.com/@vbenjs/static-source@0.1.7/source/avatar-v1.webp',
|
||||
defaultHomePath: '/analytics',
|
||||
@@ -199,6 +205,7 @@ const defaultPreferences: Preferences = {
|
||||
name: 'Vben Admin',
|
||||
preferencesButtonPosition: 'auto',
|
||||
watermark: false,
|
||||
zIndex: 200,
|
||||
},
|
||||
breadcrumb: {
|
||||
enable: true,
|
||||
@@ -219,15 +226,18 @@ const defaultPreferences: Preferences = {
|
||||
footer: {
|
||||
enable: false,
|
||||
fixed: false,
|
||||
height: 32,
|
||||
},
|
||||
header: {
|
||||
enable: true,
|
||||
height: 50,
|
||||
hidden: false,
|
||||
menuAlign: 'start',
|
||||
mode: 'fixed',
|
||||
},
|
||||
logo: {
|
||||
enable: true,
|
||||
fit: 'contain',
|
||||
source: 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp',
|
||||
},
|
||||
navigation: {
|
||||
@@ -247,11 +257,14 @@ const defaultPreferences: Preferences = {
|
||||
collapsed: false,
|
||||
collapsedButton: true,
|
||||
collapsedShowTitle: false,
|
||||
collapseWidth: 60,
|
||||
enable: true,
|
||||
expandOnHover: true,
|
||||
extraCollapse: false,
|
||||
extraCollapsedWidth: 60,
|
||||
fixedButton: true,
|
||||
hidden: false,
|
||||
mixedWidth: 80,
|
||||
width: 224,
|
||||
},
|
||||
tabbar: {
|
||||
@@ -318,6 +331,18 @@ interface AppPreferences {
|
||||
compact: boolean;
|
||||
/** 是否开启内容紧凑模式 */
|
||||
contentCompact: ContentCompactType;
|
||||
/** 内容紧凑宽度 */
|
||||
contentCompactWidth: number;
|
||||
/** 内容内边距 */
|
||||
contentPadding: number;
|
||||
/** 内容底部内边距 */
|
||||
contentPaddingBottom: number;
|
||||
/** 内容左侧内边距 */
|
||||
contentPaddingLeft: number;
|
||||
/** 内容右侧内边距 */
|
||||
contentPaddingRight: number;
|
||||
/** 内容顶部内边距 */
|
||||
contentPaddingTop: number;
|
||||
// /** 应用默认头像 */
|
||||
defaultAvatar: string;
|
||||
/** 默认首页地址 */
|
||||
@@ -348,6 +373,8 @@ interface AppPreferences {
|
||||
* @zh_CN 是否开启水印
|
||||
*/
|
||||
watermark: boolean;
|
||||
/** z-index */
|
||||
zIndex: number;
|
||||
}
|
||||
|
||||
interface BreadcrumbPreferences {
|
||||
@@ -385,11 +412,15 @@ interface FooterPreferences {
|
||||
enable: boolean;
|
||||
/** 底栏是否固定 */
|
||||
fixed: boolean;
|
||||
/** 底栏高度 */
|
||||
height: number;
|
||||
}
|
||||
|
||||
interface HeaderPreferences {
|
||||
/** 顶栏是否启用 */
|
||||
enable: boolean;
|
||||
/** 顶栏高度 */
|
||||
height: number;
|
||||
/** 顶栏是否隐藏,css-隐藏 */
|
||||
hidden: boolean;
|
||||
/** 顶栏菜单位置 */
|
||||
@@ -401,6 +432,8 @@ interface HeaderPreferences {
|
||||
interface LogoPreferences {
|
||||
/** logo是否可见 */
|
||||
enable: boolean;
|
||||
/** logo图片适应方式 */
|
||||
fit: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
||||
/** logo地址 */
|
||||
source: string;
|
||||
}
|
||||
@@ -423,16 +456,22 @@ interface SidebarPreferences {
|
||||
collapsedButton: boolean;
|
||||
/** 侧边栏折叠时,是否显示title */
|
||||
collapsedShowTitle: boolean;
|
||||
/** 侧边栏折叠宽度 */
|
||||
collapseWidth: number;
|
||||
/** 侧边栏是否可见 */
|
||||
enable: boolean;
|
||||
/** 菜单自动展开状态 */
|
||||
expandOnHover: boolean;
|
||||
/** 侧边栏扩展区域是否折叠 */
|
||||
extraCollapse: boolean;
|
||||
/** 侧边栏扩展区域折叠宽度 */
|
||||
extraCollapsedWidth: number;
|
||||
/** 侧边栏固定按钮是否可见 */
|
||||
fixedButton: boolean;
|
||||
/** 侧边栏是否隐藏 - css */
|
||||
hidden: boolean;
|
||||
/** 混合侧边栏宽度 */
|
||||
mixedWidth: number;
|
||||
/** 侧边栏宽度 */
|
||||
width: number;
|
||||
}
|
||||
|
@@ -4,10 +4,11 @@ outline: deep
|
||||
|
||||
# 权限
|
||||
|
||||
框架内置了两种权限控制方式:
|
||||
框架内置了三种权限控制方式:
|
||||
|
||||
- 通过用户角色来判断菜单或者按钮是否可以访问
|
||||
- 通过接口来判断菜单或者按钮是否可以访问
|
||||
- 混合模式:同时使用前端和后端权限控制
|
||||
|
||||
## 前端访问控制
|
||||
|
||||
@@ -159,6 +160,43 @@ const dashboardMenus = [
|
||||
|
||||
到这里,就已经配置完成,你需要确保登录后,接口返回的菜单格式正确,否则无法访问。
|
||||
|
||||
## 混合访问控制
|
||||
|
||||
**实现原理**: 混合模式同时结合了前端访问控制和后端访问控制两种方式。系统会并行处理前端固定路由权限和后端动态菜单数据,最终将两部分路由合并,提供更灵活的权限控制方案。
|
||||
|
||||
**优点**: 兼具前端控制的性能优势和后端控制的灵活性,适合复杂业务场景下的权限管理。
|
||||
|
||||
### 步骤
|
||||
|
||||
- 确保当前模式为混合访问控制模式
|
||||
|
||||
调整对应应用目录下的`preferences.ts`,确保`accessMode='mixed'`。
|
||||
|
||||
```ts
|
||||
import { defineOverridesPreferences } from '@vben/preferences';
|
||||
|
||||
export const overridesPreferences = defineOverridesPreferences({
|
||||
// overrides
|
||||
app: {
|
||||
accessMode: 'mixed',
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
- 配置前端路由权限
|
||||
|
||||
同[前端访问控制](#前端访问控制)模式的路由权限配置方式。
|
||||
|
||||
- 配置后端菜单接口
|
||||
|
||||
同[后端访问控制](#后端访问控制)模式的接口配置方式。
|
||||
|
||||
- 确保角色和权限匹配
|
||||
|
||||
需要同时满足前端路由权限配置和后端菜单数据返回的要求,确保用户角色与两种模式的权限配置都匹配。
|
||||
|
||||
到这里,就已经配置完成,混合模式会自动合并前端和后端的路由,提供完整的权限控制功能。
|
||||
|
||||
## 按钮细粒度控制
|
||||
|
||||
在某些情况下,我们需要对按钮进行细粒度的控制,我们可以借助接口或者角色来控制按钮的显示。
|
||||
|
@@ -12,7 +12,7 @@
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"stub": "pnpm unbuild"
|
||||
"stub": "pnpm unbuild --stub"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
|
3
packages/@core/base/typings/src/app.d.ts
vendored
3
packages/@core/base/typings/src/app.d.ts
vendored
@@ -60,8 +60,9 @@ type BreadcrumbStyleType = 'background' | 'normal';
|
||||
* 权限模式
|
||||
* backend 后端权限模式
|
||||
* frontend 前端权限模式
|
||||
* mixed 混合权限模式
|
||||
*/
|
||||
type AccessModeType = 'backend' | 'frontend';
|
||||
type AccessModeType = 'backend' | 'frontend' | 'mixed';
|
||||
|
||||
/**
|
||||
* 导航风格
|
||||
|
@@ -1,3 +1,8 @@
|
||||
import type { RouteLocationNormalized } from 'vue-router';
|
||||
|
||||
export type TabDefinition = RouteLocationNormalized;
|
||||
export interface TabDefinition extends RouteLocationNormalized {
|
||||
/**
|
||||
* 标签页的key
|
||||
*/
|
||||
key?: string;
|
||||
}
|
||||
|
@@ -43,6 +43,10 @@ interface RouteMeta {
|
||||
| 'success'
|
||||
| 'warning'
|
||||
| string;
|
||||
/**
|
||||
* 路由的完整路径作为key(默认true)
|
||||
*/
|
||||
fullPathKey?: boolean;
|
||||
/**
|
||||
* 当前路由的子级在菜单中不展现
|
||||
* @default false
|
||||
|
@@ -10,6 +10,12 @@ exports[`defaultPreferences immutability test > should not modify the config obj
|
||||
"colorWeakMode": false,
|
||||
"compact": false,
|
||||
"contentCompact": "wide",
|
||||
"contentCompactWidth": 1200,
|
||||
"contentPadding": 0,
|
||||
"contentPaddingBottom": 0,
|
||||
"contentPaddingLeft": 0,
|
||||
"contentPaddingRight": 0,
|
||||
"contentPaddingTop": 0,
|
||||
"defaultAvatar": "https://unpkg.com/@vbenjs/static-source@0.1.7/source/avatar-v1.webp",
|
||||
"defaultHomePath": "/analytics",
|
||||
"dynamicTitle": true,
|
||||
@@ -23,6 +29,7 @@ exports[`defaultPreferences immutability test > should not modify the config obj
|
||||
"name": "Vben Admin",
|
||||
"preferencesButtonPosition": "auto",
|
||||
"watermark": false,
|
||||
"zIndex": 200,
|
||||
},
|
||||
"breadcrumb": {
|
||||
"enable": true,
|
||||
@@ -43,15 +50,18 @@ exports[`defaultPreferences immutability test > should not modify the config obj
|
||||
"footer": {
|
||||
"enable": false,
|
||||
"fixed": false,
|
||||
"height": 32,
|
||||
},
|
||||
"header": {
|
||||
"enable": true,
|
||||
"height": 50,
|
||||
"hidden": false,
|
||||
"menuAlign": "start",
|
||||
"mode": "fixed",
|
||||
},
|
||||
"logo": {
|
||||
"enable": true,
|
||||
"fit": "contain",
|
||||
"source": "https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp",
|
||||
},
|
||||
"navigation": {
|
||||
@@ -68,14 +78,17 @@ exports[`defaultPreferences immutability test > should not modify the config obj
|
||||
},
|
||||
"sidebar": {
|
||||
"autoActivateChild": false,
|
||||
"collapseWidth": 60,
|
||||
"collapsed": false,
|
||||
"collapsedButton": true,
|
||||
"collapsedShowTitle": false,
|
||||
"enable": true,
|
||||
"expandOnHover": true,
|
||||
"extraCollapse": false,
|
||||
"extraCollapsedWidth": 60,
|
||||
"fixedButton": true,
|
||||
"hidden": false,
|
||||
"mixedWidth": 80,
|
||||
"width": 224,
|
||||
},
|
||||
"tabbar": {
|
||||
|
@@ -9,6 +9,12 @@ const defaultPreferences: Preferences = {
|
||||
colorWeakMode: false,
|
||||
compact: false,
|
||||
contentCompact: 'wide',
|
||||
contentCompactWidth: 1200,
|
||||
contentPadding: 0,
|
||||
contentPaddingBottom: 0,
|
||||
contentPaddingLeft: 0,
|
||||
contentPaddingRight: 0,
|
||||
contentPaddingTop: 0,
|
||||
defaultAvatar:
|
||||
'https://unpkg.com/@vbenjs/static-source@0.1.7/source/avatar-v1.webp',
|
||||
defaultHomePath: '/analytics',
|
||||
@@ -23,6 +29,7 @@ const defaultPreferences: Preferences = {
|
||||
name: 'Vben Admin',
|
||||
preferencesButtonPosition: 'auto',
|
||||
watermark: false,
|
||||
zIndex: 200,
|
||||
},
|
||||
breadcrumb: {
|
||||
enable: true,
|
||||
@@ -43,15 +50,19 @@ const defaultPreferences: Preferences = {
|
||||
footer: {
|
||||
enable: false,
|
||||
fixed: false,
|
||||
height: 32,
|
||||
},
|
||||
header: {
|
||||
enable: true,
|
||||
height: 50,
|
||||
hidden: false,
|
||||
menuAlign: 'start',
|
||||
mode: 'fixed',
|
||||
},
|
||||
|
||||
logo: {
|
||||
enable: true,
|
||||
fit: 'contain',
|
||||
source: 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp',
|
||||
},
|
||||
navigation: {
|
||||
@@ -71,11 +82,14 @@ const defaultPreferences: Preferences = {
|
||||
collapsed: false,
|
||||
collapsedButton: true,
|
||||
collapsedShowTitle: false,
|
||||
collapseWidth: 60,
|
||||
enable: true,
|
||||
expandOnHover: true,
|
||||
extraCollapse: false,
|
||||
extraCollapsedWidth: 60,
|
||||
fixedButton: true,
|
||||
hidden: false,
|
||||
mixedWidth: 80,
|
||||
width: 224,
|
||||
},
|
||||
tabbar: {
|
||||
|
@@ -33,6 +33,18 @@ interface AppPreferences {
|
||||
compact: boolean;
|
||||
/** 是否开启内容紧凑模式 */
|
||||
contentCompact: ContentCompactType;
|
||||
/** 内容紧凑宽度 */
|
||||
contentCompactWidth: number;
|
||||
/** 内容内边距 */
|
||||
contentPadding: number;
|
||||
/** 内容底部内边距 */
|
||||
contentPaddingBottom: number;
|
||||
/** 内容左侧内边距 */
|
||||
contentPaddingLeft: number;
|
||||
/** 内容右侧内边距 */
|
||||
contentPaddingRight: number;
|
||||
/** 内容顶部内边距 */
|
||||
contentPaddingTop: number;
|
||||
// /** 应用默认头像 */
|
||||
defaultAvatar: string;
|
||||
/** 默认首页地址 */
|
||||
@@ -63,6 +75,8 @@ interface AppPreferences {
|
||||
* @zh_CN 是否开启水印
|
||||
*/
|
||||
watermark: boolean;
|
||||
/** z-index */
|
||||
zIndex: number;
|
||||
}
|
||||
|
||||
interface BreadcrumbPreferences {
|
||||
@@ -100,11 +114,15 @@ interface FooterPreferences {
|
||||
enable: boolean;
|
||||
/** 底栏是否固定 */
|
||||
fixed: boolean;
|
||||
/** 底栏高度 */
|
||||
height: number;
|
||||
}
|
||||
|
||||
interface HeaderPreferences {
|
||||
/** 顶栏是否启用 */
|
||||
enable: boolean;
|
||||
/** 顶栏高度 */
|
||||
height: number;
|
||||
/** 顶栏是否隐藏,css-隐藏 */
|
||||
hidden: boolean;
|
||||
/** 顶栏菜单位置 */
|
||||
@@ -116,6 +134,8 @@ interface HeaderPreferences {
|
||||
interface LogoPreferences {
|
||||
/** logo是否可见 */
|
||||
enable: boolean;
|
||||
/** logo图片适应方式 */
|
||||
fit: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
||||
/** logo地址 */
|
||||
source: string;
|
||||
}
|
||||
@@ -138,16 +158,22 @@ interface SidebarPreferences {
|
||||
collapsedButton: boolean;
|
||||
/** 侧边栏折叠时,是否显示title */
|
||||
collapsedShowTitle: boolean;
|
||||
/** 侧边栏折叠宽度 */
|
||||
collapseWidth: number;
|
||||
/** 侧边栏是否可见 */
|
||||
enable: boolean;
|
||||
/** 菜单自动展开状态 */
|
||||
expandOnHover: boolean;
|
||||
/** 侧边栏扩展区域是否折叠 */
|
||||
extraCollapse: boolean;
|
||||
/** 侧边栏扩展区域折叠宽度 */
|
||||
extraCollapsedWidth: number;
|
||||
/** 侧边栏固定按钮是否可见 */
|
||||
fixedButton: boolean;
|
||||
/** 侧边栏是否隐藏 - css */
|
||||
hidden: boolean;
|
||||
/** 混合侧边栏宽度 */
|
||||
mixedWidth: number;
|
||||
/** 侧边栏宽度 */
|
||||
width: number;
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ import type { Recordable } from '@vben-core/typings';
|
||||
|
||||
import type { FormActions, FormSchema, VbenFormProps } from './types';
|
||||
|
||||
import { toRaw } from 'vue';
|
||||
import { isRef, toRaw } from 'vue';
|
||||
|
||||
import { Store } from '@vben-core/shared/store';
|
||||
import {
|
||||
@@ -100,9 +100,26 @@ export class FormApi {
|
||||
getFieldComponentRef<T = ComponentPublicInstance>(
|
||||
fieldName: string,
|
||||
): T | undefined {
|
||||
return this.componentRefMap.has(fieldName)
|
||||
? (this.componentRefMap.get(fieldName) as T)
|
||||
let target = this.componentRefMap.has(fieldName)
|
||||
? (this.componentRefMap.get(fieldName) as ComponentPublicInstance)
|
||||
: undefined;
|
||||
if (
|
||||
target &&
|
||||
target.$.type.name === 'AsyncComponentWrapper' &&
|
||||
target.$.subTree.ref
|
||||
) {
|
||||
if (Array.isArray(target.$.subTree.ref)) {
|
||||
if (
|
||||
target.$.subTree.ref.length > 0 &&
|
||||
isRef(target.$.subTree.ref[0]?.r)
|
||||
) {
|
||||
target = target.$.subTree.ref[0]?.r.value as ComponentPublicInstance;
|
||||
}
|
||||
} else if (isRef(target.$.subTree.ref.r)) {
|
||||
target = target.$.subTree.ref.r.value as ComponentPublicInstance;
|
||||
}
|
||||
}
|
||||
return target as T;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -10,7 +10,7 @@ import { createContext } from '@vben-core/shadcn-ui';
|
||||
import { isString, mergeWithArrayOverride, set } from '@vben-core/shared/utils';
|
||||
|
||||
import { useForm } from 'vee-validate';
|
||||
import { object } from 'zod';
|
||||
import { object, ZodIntersection, ZodNumber, ZodObject, ZodString } from 'zod';
|
||||
import { getDefaultsForSchema } from 'zod-defaults';
|
||||
|
||||
type ExtendFormProps = VbenFormProps & { formApi: ExtendedFormApi };
|
||||
@@ -52,7 +52,12 @@ export function useFormInitial(
|
||||
if (Reflect.has(item, 'defaultValue')) {
|
||||
set(initialValues, item.fieldName, item.defaultValue);
|
||||
} else if (item.rules && !isString(item.rules)) {
|
||||
// 检查规则是否适合提取默认值
|
||||
const customDefaultValue = getCustomDefaultValue(item.rules);
|
||||
zodObject[item.fieldName] = item.rules;
|
||||
if (customDefaultValue !== undefined) {
|
||||
initialValues[item.fieldName] = customDefaultValue;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -64,6 +69,38 @@ export function useFormInitial(
|
||||
}
|
||||
return mergeWithArrayOverride(initialValues, zodDefaults);
|
||||
}
|
||||
// 自定义默认值提取逻辑
|
||||
function getCustomDefaultValue(rule: any): any {
|
||||
if (rule instanceof ZodString) {
|
||||
return ''; // 默认为空字符串
|
||||
} else if (rule instanceof ZodNumber) {
|
||||
return null; // 默认为 null(避免显示 0)
|
||||
} else if (rule instanceof ZodObject) {
|
||||
// 递归提取嵌套对象的默认值
|
||||
const defaultValues: Record<string, any> = {};
|
||||
for (const [key, valueSchema] of Object.entries(rule.shape)) {
|
||||
defaultValues[key] = getCustomDefaultValue(valueSchema);
|
||||
}
|
||||
return defaultValues;
|
||||
} else if (rule instanceof ZodIntersection) {
|
||||
// 对于交集类型,从schema 提取默认值
|
||||
const leftDefaultValue = getCustomDefaultValue(rule._def.left);
|
||||
const rightDefaultValue = getCustomDefaultValue(rule._def.right);
|
||||
|
||||
// 如果左右两边都能提取默认值,合并它们
|
||||
if (
|
||||
typeof leftDefaultValue === 'object' &&
|
||||
typeof rightDefaultValue === 'object'
|
||||
) {
|
||||
return { ...leftDefaultValue, ...rightDefaultValue };
|
||||
}
|
||||
|
||||
// 否则优先使用左边的默认值
|
||||
return leftDefaultValue ?? rightDefaultValue;
|
||||
} else {
|
||||
return undefined; // 其他类型不提供默认值
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
delegatedSlots,
|
||||
|
@@ -5,6 +5,8 @@ import type {
|
||||
AvatarRootProps,
|
||||
} from 'radix-vue';
|
||||
|
||||
import type { CSSProperties } from 'vue';
|
||||
|
||||
import type { ClassType } from '@vben-core/typings';
|
||||
|
||||
import { computed } from 'vue';
|
||||
@@ -16,6 +18,7 @@ interface Props extends AvatarFallbackProps, AvatarImageProps, AvatarRootProps {
|
||||
class?: ClassType;
|
||||
dot?: boolean;
|
||||
dotClass?: ClassType;
|
||||
fit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
||||
size?: number;
|
||||
}
|
||||
|
||||
@@ -28,6 +31,15 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
as: 'button',
|
||||
dot: false,
|
||||
dotClass: 'bg-green-500',
|
||||
fit: 'cover',
|
||||
});
|
||||
|
||||
const imageStyle = computed<CSSProperties>(() => {
|
||||
const { fit } = props;
|
||||
if (fit) {
|
||||
return { objectFit: fit };
|
||||
}
|
||||
return {};
|
||||
});
|
||||
|
||||
const text = computed(() => {
|
||||
@@ -51,7 +63,7 @@ const rootStyle = computed(() => {
|
||||
class="relative flex flex-shrink-0 items-center"
|
||||
>
|
||||
<Avatar :class="props.class" class="size-full">
|
||||
<AvatarImage :alt="alt" :src="src" />
|
||||
<AvatarImage :alt="alt" :src="src" :style="imageStyle" />
|
||||
<AvatarFallback>{{ text }}</AvatarFallback>
|
||||
</Avatar>
|
||||
<span
|
||||
|
@@ -36,7 +36,7 @@ export interface VbenButtonGroupProps
|
||||
btnClass?: any;
|
||||
gap?: number;
|
||||
multiple?: boolean;
|
||||
options?: { label: CustomRenderType; value: ValueType }[];
|
||||
options?: { [key: string]: any; label: CustomRenderType; value: ValueType }[];
|
||||
showIcon?: boolean;
|
||||
size?: 'large' | 'middle' | 'small';
|
||||
}
|
||||
|
@@ -119,7 +119,7 @@ async function onBtnClick(value: ValueType) {
|
||||
<CircleCheckBig v-else-if="innerValue.includes(btn.value)" />
|
||||
<Circle v-else />
|
||||
</div>
|
||||
<slot name="option" :label="btn.label" :value="btn.value">
|
||||
<slot name="option" :label="btn.label" :value="btn.value" :data="btn">
|
||||
<VbenRenderContent :content="btn.label" />
|
||||
</slot>
|
||||
</Button>
|
||||
@@ -127,6 +127,9 @@ async function onBtnClick(value: ValueType) {
|
||||
</template>
|
||||
<style lang="scss" scoped>
|
||||
.vben-check-button-group {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
&:deep(.size-large) button {
|
||||
.icon-wrapper {
|
||||
margin-right: 0.3rem;
|
||||
@@ -159,5 +162,16 @@ async function onBtnClick(value: ValueType) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.no-gap > :deep(button):nth-of-type(1) {
|
||||
border-right-width: 0;
|
||||
}
|
||||
|
||||
&.no-gap {
|
||||
:deep(button + button) {
|
||||
margin-right: -1px;
|
||||
border-left-width: 1px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
@@ -6,6 +6,10 @@ interface Props {
|
||||
* @zh_CN 是否收起文本
|
||||
*/
|
||||
collapsed?: boolean;
|
||||
/**
|
||||
* @zh_CN Logo 图片适应方式
|
||||
*/
|
||||
fit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
||||
/**
|
||||
* @zh_CN Logo 跳转地址
|
||||
*/
|
||||
@@ -38,6 +42,7 @@ withDefaults(defineProps<Props>(), {
|
||||
logoSize: 32,
|
||||
src: '',
|
||||
theme: 'light',
|
||||
fit: 'cover',
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -53,6 +58,7 @@ withDefaults(defineProps<Props>(), {
|
||||
:alt="text"
|
||||
:src="src"
|
||||
:size="logoSize"
|
||||
:fit="fit"
|
||||
class="relative rounded-none bg-transparent"
|
||||
/>
|
||||
<template v-if="!collapsed">
|
||||
|
@@ -224,15 +224,20 @@ defineExpose({
|
||||
:class="
|
||||
cn('cursor-pointer', getNodeClass?.(item), {
|
||||
'data-[selected]:bg-accent': !multiple,
|
||||
'cursor-not-allowed': disabled,
|
||||
})
|
||||
"
|
||||
v-bind="
|
||||
Object.assign(item.bind, {
|
||||
onfocus: disabled ? 'this.blur()' : undefined,
|
||||
})
|
||||
"
|
||||
v-bind="item.bind"
|
||||
@select="
|
||||
(event) => {
|
||||
if (event.detail.originalEvent.type === 'click') {
|
||||
event.preventDefault();
|
||||
}
|
||||
onSelect(item, event.detail.isSelected);
|
||||
!disabled && onSelect(item, event.detail.isSelected);
|
||||
}
|
||||
"
|
||||
@toggle="
|
||||
@@ -240,7 +245,7 @@ defineExpose({
|
||||
if (event.detail.originalEvent.type === 'click') {
|
||||
event.preventDefault();
|
||||
}
|
||||
onToggle(item);
|
||||
!disabled && onToggle(item);
|
||||
}
|
||||
"
|
||||
class="tree-node focus:ring-grass8 my-0.5 flex items-center rounded px-2 py-1 outline-none focus:ring-2"
|
||||
@@ -262,10 +267,11 @@ defineExpose({
|
||||
<Checkbox
|
||||
v-if="multiple"
|
||||
:checked="isSelected"
|
||||
:disabled="disabled"
|
||||
:indeterminate="isIndeterminate"
|
||||
@click="
|
||||
() => {
|
||||
handleSelect();
|
||||
!disabled && handleSelect();
|
||||
// onSelect(item, !isSelected);
|
||||
}
|
||||
"
|
||||
@@ -276,7 +282,7 @@ defineExpose({
|
||||
(_event) => {
|
||||
// $event.stopPropagation();
|
||||
// $event.preventDefault();
|
||||
handleSelect();
|
||||
!disabled && handleSelect();
|
||||
// onSelect(item, !isSelected);
|
||||
}
|
||||
"
|
||||
|
@@ -40,14 +40,14 @@ const style = computed(() => {
|
||||
|
||||
const tabsView = computed(() => {
|
||||
return props.tabs.map((tab) => {
|
||||
const { fullPath, meta, name, path } = tab || {};
|
||||
const { fullPath, meta, name, path, key } = tab || {};
|
||||
const { affixTab, icon, newTabTitle, tabClosable, title } = meta || {};
|
||||
return {
|
||||
affixTab: !!affixTab,
|
||||
closable: Reflect.has(meta, 'tabClosable') ? !!tabClosable : true,
|
||||
fullPath,
|
||||
icon: icon as string,
|
||||
key: fullPath || path,
|
||||
key,
|
||||
meta,
|
||||
name,
|
||||
path,
|
||||
|
@@ -47,14 +47,14 @@ const typeWithClass = computed(() => {
|
||||
|
||||
const tabsView = computed(() => {
|
||||
return props.tabs.map((tab) => {
|
||||
const { fullPath, meta, name, path } = tab || {};
|
||||
const { fullPath, meta, name, path, key } = tab || {};
|
||||
const { affixTab, icon, newTabTitle, tabClosable, title } = meta || {};
|
||||
return {
|
||||
affixTab: !!affixTab,
|
||||
closable: Reflect.has(meta, 'tabClosable') ? !!tabClosable : true,
|
||||
fullPath,
|
||||
icon: icon as string,
|
||||
key: fullPath || path,
|
||||
key,
|
||||
meta,
|
||||
name,
|
||||
path,
|
||||
|
@@ -104,6 +104,15 @@ async function generateRoutes(
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'mixed': {
|
||||
const [frontend_resultRoutes, backend_resultRoutes] = await Promise.all([
|
||||
generateRoutesByFrontend(routes, roles || [], forbiddenComponent),
|
||||
generateRoutesByBackend(options),
|
||||
]);
|
||||
|
||||
resultRoutes = [...frontend_resultRoutes, ...backend_resultRoutes];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,7 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import type { CSSProperties } from 'vue';
|
||||
|
||||
import { computed, ref, watchEffect } from 'vue';
|
||||
import {
|
||||
computed,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
onUpdated,
|
||||
ref,
|
||||
watchEffect,
|
||||
} from 'vue';
|
||||
|
||||
import { VbenTooltip } from '@vben-core/shadcn-ui';
|
||||
|
||||
@@ -33,6 +40,16 @@ interface Props {
|
||||
* @default true
|
||||
*/
|
||||
tooltip?: boolean;
|
||||
/**
|
||||
* 是否只在文本被截断时显示提示框
|
||||
* @default false
|
||||
*/
|
||||
tooltipWhenEllipsis?: boolean;
|
||||
/**
|
||||
* 文本截断检测的像素差异阈值,越大则判断越严格
|
||||
* @default 3
|
||||
*/
|
||||
ellipsisThreshold?: number;
|
||||
/**
|
||||
* 提示框背景颜色,优先级高于 overlayStyle
|
||||
*/
|
||||
@@ -62,12 +79,15 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
maxWidth: '100%',
|
||||
placement: 'top',
|
||||
tooltip: true,
|
||||
tooltipWhenEllipsis: false,
|
||||
ellipsisThreshold: 3,
|
||||
tooltipBackgroundColor: '',
|
||||
tooltipColor: '',
|
||||
tooltipFontSize: 14,
|
||||
tooltipMaxWidth: undefined,
|
||||
tooltipOverlayStyle: () => ({ textAlign: 'justify' }),
|
||||
});
|
||||
|
||||
const emit = defineEmits<{ expandChange: [boolean] }>();
|
||||
|
||||
const textMaxWidth = computed(() => {
|
||||
@@ -79,9 +99,67 @@ const textMaxWidth = computed(() => {
|
||||
const ellipsis = ref();
|
||||
const isExpand = ref(false);
|
||||
const defaultTooltipMaxWidth = ref();
|
||||
const isEllipsis = ref(false);
|
||||
|
||||
const { width: eleWidth } = useElementSize(ellipsis);
|
||||
|
||||
// 检测文本是否被截断
|
||||
const checkEllipsis = () => {
|
||||
if (!ellipsis.value || !props.tooltipWhenEllipsis) return;
|
||||
|
||||
const element = ellipsis.value;
|
||||
|
||||
const originalText = element.textContent || '';
|
||||
const originalTrimmed = originalText.trim();
|
||||
|
||||
// 对于空文本直接返回 false
|
||||
if (!originalTrimmed) {
|
||||
isEllipsis.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const widthDiff = element.scrollWidth - element.clientWidth;
|
||||
const heightDiff = element.scrollHeight - element.clientHeight;
|
||||
|
||||
// 使用足够大的差异阈值确保只有真正被截断的文本才会显示 tooltip
|
||||
isEllipsis.value =
|
||||
props.line === 1
|
||||
? widthDiff > props.ellipsisThreshold
|
||||
: heightDiff > props.ellipsisThreshold;
|
||||
};
|
||||
|
||||
// 使用 ResizeObserver 监听尺寸变化
|
||||
let resizeObserver: null | ResizeObserver = null;
|
||||
|
||||
onMounted(() => {
|
||||
if (typeof ResizeObserver !== 'undefined' && props.tooltipWhenEllipsis) {
|
||||
resizeObserver = new ResizeObserver(() => {
|
||||
checkEllipsis();
|
||||
});
|
||||
|
||||
if (ellipsis.value) {
|
||||
resizeObserver.observe(ellipsis.value);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始检测
|
||||
checkEllipsis();
|
||||
});
|
||||
|
||||
// 使用onUpdated钩子检测内容变化
|
||||
onUpdated(() => {
|
||||
if (props.tooltipWhenEllipsis) {
|
||||
checkEllipsis();
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (resizeObserver) {
|
||||
resizeObserver.disconnect();
|
||||
resizeObserver = null;
|
||||
}
|
||||
});
|
||||
|
||||
watchEffect(
|
||||
() => {
|
||||
if (props.tooltip && eleWidth.value) {
|
||||
@@ -91,9 +169,13 @@ watchEffect(
|
||||
},
|
||||
{ flush: 'post' },
|
||||
);
|
||||
|
||||
function onExpand() {
|
||||
isExpand.value = !isExpand.value;
|
||||
emit('expandChange', isExpand.value);
|
||||
if (props.tooltipWhenEllipsis) {
|
||||
checkEllipsis();
|
||||
}
|
||||
}
|
||||
|
||||
function handleExpand() {
|
||||
@@ -110,7 +192,9 @@ function handleExpand() {
|
||||
color: tooltipColor,
|
||||
backgroundColor: tooltipBackgroundColor,
|
||||
}"
|
||||
:disabled="!props.tooltip || isExpand"
|
||||
:disabled="
|
||||
!props.tooltip || isExpand || (props.tooltipWhenEllipsis && !isEllipsis)
|
||||
"
|
||||
:side="placement"
|
||||
>
|
||||
<slot name="tooltip">
|
||||
|
@@ -193,67 +193,107 @@ export function useElementPlusDesignTokens() {
|
||||
|
||||
'--el-border-radius-base': getCssVariableValue('--radius', false),
|
||||
'--el-color-danger': getCssVariableValue('--destructive-500'),
|
||||
'--el-color-danger-dark-2': getCssVariableValue('--destructive'),
|
||||
'--el-color-danger-light-3': getCssVariableValue('--destructive-400'),
|
||||
'--el-color-danger-light-5': getCssVariableValue('--destructive-300'),
|
||||
'--el-color-danger-light-7': getCssVariableValue('--destructive-200'),
|
||||
'--el-color-danger-dark-2': isDark.value
|
||||
? getCssVariableValue('--destructive-400')
|
||||
: getCssVariableValue('--destructive-600'),
|
||||
'--el-color-danger-light-3': isDark.value
|
||||
? getCssVariableValue('--destructive-600')
|
||||
: getCssVariableValue('--destructive-400'),
|
||||
'--el-color-danger-light-5': isDark.value
|
||||
? getCssVariableValue('--destructive-700')
|
||||
: getCssVariableValue('--destructive-300'),
|
||||
'--el-color-danger-light-7': isDark.value
|
||||
? getCssVariableValue('--destructive-800')
|
||||
: getCssVariableValue('--destructive-200'),
|
||||
'--el-color-danger-light-8': isDark.value
|
||||
? border
|
||||
? getCssVariableValue('--destructive-900')
|
||||
: getCssVariableValue('--destructive-100'),
|
||||
'--el-color-danger-light-9': isDark.value
|
||||
? accent
|
||||
? getCssVariableValue('--destructive-950')
|
||||
: getCssVariableValue('--destructive-50'),
|
||||
|
||||
'--el-color-error': getCssVariableValue('--destructive-500'),
|
||||
'--el-color-error-dark-2': getCssVariableValue('--destructive'),
|
||||
'--el-color-error-light-3': getCssVariableValue('--destructive-400'),
|
||||
'--el-color-error-light-5': getCssVariableValue('--destructive-300'),
|
||||
'--el-color-error-light-7': getCssVariableValue('--destructive-200'),
|
||||
'--el-color-error-dark-2': isDark.value
|
||||
? getCssVariableValue('--destructive-400')
|
||||
: getCssVariableValue('--destructive-600'),
|
||||
'--el-color-error-light-3': isDark.value
|
||||
? getCssVariableValue('--destructive-600')
|
||||
: getCssVariableValue('--destructive-400'),
|
||||
'--el-color-error-light-5': isDark.value
|
||||
? getCssVariableValue('--destructive-700')
|
||||
: getCssVariableValue('--destructive-300'),
|
||||
'--el-color-error-light-7': isDark.value
|
||||
? getCssVariableValue('--destructive-800')
|
||||
: getCssVariableValue('--destructive-200'),
|
||||
'--el-color-error-light-8': isDark.value
|
||||
? border
|
||||
? getCssVariableValue('--destructive-900')
|
||||
: getCssVariableValue('--destructive-100'),
|
||||
'--el-color-error-light-9': isDark.value
|
||||
? accent
|
||||
? getCssVariableValue('--destructive-950')
|
||||
: getCssVariableValue('--destructive-50'),
|
||||
|
||||
'--el-color-info-light-5': border,
|
||||
'--el-color-info-light-8': border,
|
||||
'--el-color-info-light-9': getCssVariableValue('--info'), // getCssVariableValue('--secondary'),
|
||||
|
||||
'--el-color-primary': getCssVariableValue('--primary-500'),
|
||||
'--el-color-primary-dark-2': getCssVariableValue('--primary'),
|
||||
'--el-color-primary-light-3': getCssVariableValue('--primary-400'),
|
||||
'--el-color-primary-light-5': getCssVariableValue('--primary-300'),
|
||||
'--el-color-primary-dark-2': isDark.value
|
||||
? getCssVariableValue('--primary-400')
|
||||
: getCssVariableValue('--primary-600'),
|
||||
'--el-color-primary-light-3': isDark.value
|
||||
? getCssVariableValue('--primary-600')
|
||||
: getCssVariableValue('--primary-400'),
|
||||
'--el-color-primary-light-5': isDark.value
|
||||
? getCssVariableValue('--primary-700')
|
||||
: getCssVariableValue('--primary-300'),
|
||||
'--el-color-primary-light-7': isDark.value
|
||||
? border
|
||||
? getCssVariableValue('--primary-800')
|
||||
: getCssVariableValue('--primary-200'),
|
||||
'--el-color-primary-light-8': isDark.value
|
||||
? border
|
||||
? getCssVariableValue('--primary-900')
|
||||
: getCssVariableValue('--primary-100'),
|
||||
'--el-color-primary-light-9': isDark.value
|
||||
? accent
|
||||
? getCssVariableValue('--primary-950')
|
||||
: getCssVariableValue('--primary-50'),
|
||||
|
||||
'--el-color-success': getCssVariableValue('--success-500'),
|
||||
'--el-color-success-dark-2': getCssVariableValue('--success'),
|
||||
'--el-color-success-light-3': getCssVariableValue('--success-400'),
|
||||
'--el-color-success-light-5': getCssVariableValue('--success-300'),
|
||||
'--el-color-success-light-7': getCssVariableValue('--success-200'),
|
||||
'--el-color-success-dark-2': isDark.value
|
||||
? getCssVariableValue('--success-400')
|
||||
: getCssVariableValue('--success-600'),
|
||||
'--el-color-success-light-3': isDark.value
|
||||
? getCssVariableValue('--success-600')
|
||||
: getCssVariableValue('--success-400'),
|
||||
'--el-color-success-light-5': isDark.value
|
||||
? getCssVariableValue('--success-700')
|
||||
: getCssVariableValue('--success-300'),
|
||||
'--el-color-success-light-7': isDark.value
|
||||
? getCssVariableValue('--success-800')
|
||||
: getCssVariableValue('--success-200'),
|
||||
'--el-color-success-light-8': isDark.value
|
||||
? border
|
||||
? getCssVariableValue('--success-900')
|
||||
: getCssVariableValue('--success-100'),
|
||||
'--el-color-success-light-9': isDark.value
|
||||
? accent
|
||||
? getCssVariableValue('--success-950')
|
||||
: getCssVariableValue('--success-50'),
|
||||
|
||||
'--el-color-warning': getCssVariableValue('--warning-500'),
|
||||
'--el-color-warning-dark-2': getCssVariableValue('--warning'),
|
||||
'--el-color-warning-light-3': getCssVariableValue('--warning-400'),
|
||||
'--el-color-warning-light-5': getCssVariableValue('--warning-300'),
|
||||
'--el-color-warning-light-7': getCssVariableValue('--warning-200'),
|
||||
'--el-color-warning-dark-2': isDark.value
|
||||
? getCssVariableValue('--warning-400')
|
||||
: getCssVariableValue('--warning-600'),
|
||||
'--el-color-warning-light-3': isDark.value
|
||||
? getCssVariableValue('--warning-600')
|
||||
: getCssVariableValue('--warning-400'),
|
||||
'--el-color-warning-light-5': isDark.value
|
||||
? getCssVariableValue('--warning-700')
|
||||
: getCssVariableValue('--warning-300'),
|
||||
'--el-color-warning-light-7': isDark.value
|
||||
? getCssVariableValue('--warning-800')
|
||||
: getCssVariableValue('--warning-200'),
|
||||
'--el-color-warning-light-8': isDark.value
|
||||
? border
|
||||
? getCssVariableValue('--warning-900')
|
||||
: getCssVariableValue('--warning-100'),
|
||||
'--el-color-warning-light-9': isDark.value
|
||||
? accent
|
||||
? getCssVariableValue('--warning-950')
|
||||
: getCssVariableValue('--warning-50'),
|
||||
|
||||
'--el-fill-color': getCssVariableValue('--accent'),
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import type { ComputedRef } from 'vue';
|
||||
import type { RouteLocationNormalized } from 'vue-router';
|
||||
|
||||
import { useTabbarStore } from '@vben/stores';
|
||||
@@ -40,8 +41,8 @@ export function useTabs() {
|
||||
await tabbarStore.toggleTabPin(tab || route);
|
||||
}
|
||||
|
||||
async function refreshTab() {
|
||||
await tabbarStore.refresh(router);
|
||||
async function refreshTab(name?: string) {
|
||||
await tabbarStore.refresh(name || router);
|
||||
}
|
||||
|
||||
async function openTabInNewWindow(tab?: RouteLocationNormalized) {
|
||||
@@ -52,7 +53,24 @@ export function useTabs() {
|
||||
await tabbarStore.closeTabByKey(key, router);
|
||||
}
|
||||
|
||||
async function setTabTitle(title: string) {
|
||||
/**
|
||||
* 设置当前标签页的标题
|
||||
*
|
||||
* @description 支持设置静态标题字符串或动态计算标题
|
||||
* @description 动态标题会在每次渲染时重新计算,适用于多语言或状态相关的标题
|
||||
*
|
||||
* @param title - 标题内容
|
||||
* - 静态标题: 直接传入字符串
|
||||
* - 动态标题: 传入 ComputedRef
|
||||
*
|
||||
* @example
|
||||
* // 静态标题
|
||||
* setTabTitle('标签页')
|
||||
*
|
||||
* // 动态标题(多语言)
|
||||
* setTabTitle(computed(() => t('page.title')))
|
||||
*/
|
||||
async function setTabTitle(title: ComputedRef<string> | string) {
|
||||
tabbarStore.setUpdateTime();
|
||||
await tabbarStore.setTabTitle(route, title);
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
||||
|
||||
<template>
|
||||
<div
|
||||
:class="[isDark]"
|
||||
:class="[isDark ? 'dark' : '']"
|
||||
class="flex min-h-full flex-1 select-none overflow-x-hidden"
|
||||
>
|
||||
<template v-if="toolbar">
|
||||
|
@@ -1 +1,2 @@
|
||||
export { default as AuthPageLayout } from './authentication.vue';
|
||||
export * from './types';
|
||||
|
@@ -9,7 +9,7 @@ import { computed } from 'vue';
|
||||
import { RouterView } from 'vue-router';
|
||||
|
||||
import { preferences, usePreferences } from '@vben/preferences';
|
||||
import { storeToRefs, useTabbarStore } from '@vben/stores';
|
||||
import { getTabKey, storeToRefs, useTabbarStore } from '@vben/stores';
|
||||
|
||||
import { IFrameRouterView } from '../../iframe';
|
||||
|
||||
@@ -115,13 +115,13 @@ function transformComponent(
|
||||
:is="transformComponent(Component, route)"
|
||||
v-if="renderRouteView"
|
||||
v-show="!route.meta.iframeSrc"
|
||||
:key="route.fullPath"
|
||||
:key="getTabKey(route)"
|
||||
/>
|
||||
</KeepAlive>
|
||||
<component
|
||||
:is="Component"
|
||||
v-else-if="renderRouteView"
|
||||
:key="route.fullPath"
|
||||
:key="getTabKey(route)"
|
||||
/>
|
||||
</Transition>
|
||||
<template v-else>
|
||||
@@ -134,13 +134,13 @@ function transformComponent(
|
||||
:is="transformComponent(Component, route)"
|
||||
v-if="renderRouteView"
|
||||
v-show="!route.meta.iframeSrc"
|
||||
:key="route.fullPath"
|
||||
:key="getTabKey(route)"
|
||||
/>
|
||||
</KeepAlive>
|
||||
<component
|
||||
:is="Component"
|
||||
v-else-if="renderRouteView"
|
||||
:key="route.fullPath"
|
||||
:key="getTabKey(route)"
|
||||
/>
|
||||
</template>
|
||||
</RouterView>
|
||||
|
@@ -180,8 +180,16 @@ const headerSlots = computed(() => {
|
||||
<VbenAdminLayout
|
||||
v-model:sidebar-extra-visible="sidebarExtraVisible"
|
||||
:content-compact="preferences.app.contentCompact"
|
||||
:content-compact-width="preferences.app.contentCompactWidth"
|
||||
:content-padding="preferences.app.contentPadding"
|
||||
:content-padding-bottom="preferences.app.contentPaddingBottom"
|
||||
:content-padding-left="preferences.app.contentPaddingLeft"
|
||||
:content-padding-right="preferences.app.contentPaddingRight"
|
||||
:content-padding-top="preferences.app.contentPaddingTop"
|
||||
:footer-enable="preferences.footer.enable"
|
||||
:footer-fixed="preferences.footer.fixed"
|
||||
:footer-height="preferences.footer.height"
|
||||
:header-height="preferences.header.height"
|
||||
:header-hidden="preferences.header.hidden"
|
||||
:header-mode="preferences.header.mode"
|
||||
:header-theme="headerTheme"
|
||||
@@ -196,11 +204,15 @@ const headerSlots = computed(() => {
|
||||
:sidebar-fixed-button="preferences.sidebar.fixedButton"
|
||||
:sidebar-expand-on-hover="preferences.sidebar.expandOnHover"
|
||||
:sidebar-extra-collapse="preferences.sidebar.extraCollapse"
|
||||
:sidebar-extra-collapsed-width="preferences.sidebar.extraCollapsedWidth"
|
||||
:sidebar-hidden="preferences.sidebar.hidden"
|
||||
:sidebar-mixed-width="preferences.sidebar.mixedWidth"
|
||||
:sidebar-theme="sidebarTheme"
|
||||
:sidebar-width="preferences.sidebar.width"
|
||||
:side-collapse-width="preferences.sidebar.collapseWidth"
|
||||
:tabbar-enable="preferences.tabbar.enable"
|
||||
:tabbar-height="preferences.tabbar.height"
|
||||
:z-index="preferences.app.zIndex"
|
||||
@side-mouse-leave="handleSideMouseLeave"
|
||||
@toggle-sidebar="toggleSidebar"
|
||||
@update:sidebar-collapse="
|
||||
@@ -222,6 +234,7 @@ const headerSlots = computed(() => {
|
||||
<template #logo>
|
||||
<VbenLogo
|
||||
v-if="preferences.logo.enable"
|
||||
:fit="preferences.logo.fit"
|
||||
:class="logoClass"
|
||||
:collapsed="logoCollapsed"
|
||||
:src="preferences.logo.source"
|
||||
@@ -312,6 +325,7 @@ const headerSlots = computed(() => {
|
||||
<template #side-extra-title>
|
||||
<VbenLogo
|
||||
v-if="preferences.logo.enable"
|
||||
:fit="preferences.logo.fit"
|
||||
:text="preferences.app.name"
|
||||
:theme="theme"
|
||||
>
|
||||
|
@@ -140,7 +140,10 @@ function useMixedMenu() {
|
||||
watch(
|
||||
() => route.path,
|
||||
(path) => {
|
||||
const currentPath = (route?.meta?.activePath as string) ?? path;
|
||||
const currentPath = route?.meta?.activePath ?? route?.meta?.link ?? path;
|
||||
if (willOpenedByWindow(currentPath)) {
|
||||
return;
|
||||
}
|
||||
calcSideMenus(currentPath);
|
||||
if (rootMenuPath.value)
|
||||
defaultSubMap.set(rootMenuPath.value, currentPath);
|
||||
|
@@ -30,7 +30,7 @@ const {
|
||||
} = useTabbar();
|
||||
|
||||
const menus = computed(() => {
|
||||
const tab = tabbarStore.getTabByPath(currentActive.value);
|
||||
const tab = tabbarStore.getTabByKey(currentActive.value);
|
||||
const menus = createContextMenus(tab);
|
||||
return menus.map((item) => {
|
||||
return {
|
||||
|
@@ -22,7 +22,7 @@ import {
|
||||
X,
|
||||
} from '@vben/icons';
|
||||
import { $t, useI18n } from '@vben/locales';
|
||||
import { useAccessStore, useTabbarStore } from '@vben/stores';
|
||||
import { getTabKey, useAccessStore, useTabbarStore } from '@vben/stores';
|
||||
import { filterTree } from '@vben/utils';
|
||||
|
||||
export function useTabbar() {
|
||||
@@ -44,8 +44,11 @@ export function useTabbar() {
|
||||
toggleTabPin,
|
||||
} = useTabs();
|
||||
|
||||
/**
|
||||
* 当前路径对应的tab的key
|
||||
*/
|
||||
const currentActive = computed(() => {
|
||||
return route.fullPath;
|
||||
return getTabKey(route);
|
||||
});
|
||||
|
||||
const { locale } = useI18n();
|
||||
@@ -73,7 +76,8 @@ export function useTabbar() {
|
||||
|
||||
// 点击tab,跳转路由
|
||||
const handleClick = (key: string) => {
|
||||
router.push(key);
|
||||
const { fullPath, path } = tabbarStore.getTabByKey(key);
|
||||
router.push(fullPath || path);
|
||||
};
|
||||
|
||||
// 关闭tab
|
||||
@@ -100,7 +104,7 @@ export function useTabbar() {
|
||||
);
|
||||
|
||||
watch(
|
||||
() => route.path,
|
||||
() => route.fullPath,
|
||||
() => {
|
||||
const meta = route.matched?.[route.matched.length - 1]?.meta;
|
||||
tabbarStore.addTab({
|
||||
@@ -158,7 +162,7 @@ export function useTabbar() {
|
||||
},
|
||||
{
|
||||
disabled: disabledRefresh,
|
||||
handler: refreshTab,
|
||||
handler: () => refreshTab(),
|
||||
icon: RotateCw,
|
||||
key: 'reload',
|
||||
text: $t('preferences.tabbar.contextMenu.reload'),
|
||||
|
@@ -4,7 +4,7 @@ import { useVbenModal } from '@vben-core/popup-ui';
|
||||
import { onMounted, onUnmounted, ref } from 'vue';
|
||||
|
||||
interface Props {
|
||||
// 轮训时间,分钟
|
||||
// 轮询时间,分钟
|
||||
checkUpdatesInterval?: number;
|
||||
// 检查更新的地址
|
||||
checkUpdateUrl?: string;
|
||||
@@ -44,6 +44,7 @@ async function getVersionTag() {
|
||||
const response = await fetch(props.checkUpdateUrl, {
|
||||
cache: 'no-cache',
|
||||
method: 'HEAD',
|
||||
redirect: 'manual',
|
||||
});
|
||||
|
||||
return (
|
||||
|
@@ -2,8 +2,8 @@ export { setupVbenVxeTable } from './init';
|
||||
export type { VxeTableGridOptions } from './types';
|
||||
export * from './use-vxe-grid';
|
||||
export { default as VbenVxeGrid } from './use-vxe-grid.vue';
|
||||
export type { VxeGridDefines } from 'vxe-table';
|
||||
export type {
|
||||
VxeGridDefines,
|
||||
VxeGridListeners,
|
||||
VxeGridProps,
|
||||
VxeGridPropTypes,
|
||||
|
@@ -59,6 +59,7 @@ const FORM_SLOT_PREFIX = 'form-';
|
||||
|
||||
const TOOLBAR_ACTIONS = 'toolbar-actions';
|
||||
const TOOLBAR_TOOLS = 'toolbar-tools';
|
||||
const TABLE_TITLE = 'table-title';
|
||||
|
||||
const gridRef = useTemplateRef<VxeGridInstance>('gridRef');
|
||||
|
||||
@@ -131,7 +132,7 @@ const [Form, formApi] = useTableForm({
|
||||
});
|
||||
|
||||
const showTableTitle = computed(() => {
|
||||
return !!slots.tableTitle?.() || tableTitle.value;
|
||||
return !!slots[TABLE_TITLE]?.() || tableTitle.value;
|
||||
});
|
||||
|
||||
const showToolbar = computed(() => {
|
||||
|
@@ -22,12 +22,13 @@ describe('useAccessStore', () => {
|
||||
const tab: any = {
|
||||
fullPath: '/home',
|
||||
meta: {},
|
||||
key: '/home',
|
||||
name: 'Home',
|
||||
path: '/home',
|
||||
};
|
||||
store.addTab(tab);
|
||||
const addNewTab = store.addTab(tab);
|
||||
expect(store.tabs.length).toBe(1);
|
||||
expect(store.tabs[0]).toEqual(tab);
|
||||
expect(store.tabs[0]).toEqual(addNewTab);
|
||||
});
|
||||
|
||||
it('adds a new tab if it does not exist', () => {
|
||||
@@ -38,20 +39,22 @@ describe('useAccessStore', () => {
|
||||
name: 'New',
|
||||
path: '/new',
|
||||
};
|
||||
store.addTab(newTab);
|
||||
expect(store.tabs).toContainEqual(newTab);
|
||||
const addNewTab = store.addTab(newTab);
|
||||
expect(store.tabs).toContainEqual(addNewTab);
|
||||
});
|
||||
|
||||
it('updates an existing tab instead of adding a new one', () => {
|
||||
const store = useTabbarStore();
|
||||
const initialTab: any = {
|
||||
fullPath: '/existing',
|
||||
meta: {},
|
||||
meta: {
|
||||
fullPathKey: false,
|
||||
},
|
||||
name: 'Existing',
|
||||
path: '/existing',
|
||||
query: {},
|
||||
};
|
||||
store.tabs.push(initialTab);
|
||||
store.addTab(initialTab);
|
||||
const updatedTab = { ...initialTab, query: { id: '1' } };
|
||||
store.addTab(updatedTab);
|
||||
expect(store.tabs.length).toBe(1);
|
||||
@@ -60,9 +63,12 @@ describe('useAccessStore', () => {
|
||||
|
||||
it('closes all tabs', async () => {
|
||||
const store = useTabbarStore();
|
||||
store.tabs = [
|
||||
{ fullPath: '/home', meta: {}, name: 'Home', path: '/home' },
|
||||
] as any;
|
||||
store.addTab({
|
||||
fullPath: '/home',
|
||||
meta: {},
|
||||
name: 'Home',
|
||||
path: '/home',
|
||||
} as any);
|
||||
router.replace = vi.fn();
|
||||
|
||||
await store.closeAllTabs(router);
|
||||
@@ -157,7 +163,7 @@ describe('useAccessStore', () => {
|
||||
path: '/contact',
|
||||
} as any);
|
||||
|
||||
await store._bulkCloseByPaths(['/home', '/contact']);
|
||||
await store._bulkCloseByKeys(['/home', '/contact']);
|
||||
|
||||
expect(store.tabs).toHaveLength(1);
|
||||
expect(store.tabs[0]?.name).toBe('About');
|
||||
@@ -183,9 +189,8 @@ describe('useAccessStore', () => {
|
||||
name: 'Contact',
|
||||
path: '/contact',
|
||||
};
|
||||
store.addTab(targetTab);
|
||||
|
||||
await store.closeLeftTabs(targetTab);
|
||||
const addTargetTab = store.addTab(targetTab);
|
||||
await store.closeLeftTabs(addTargetTab);
|
||||
|
||||
expect(store.tabs).toHaveLength(1);
|
||||
expect(store.tabs[0]?.name).toBe('Contact');
|
||||
@@ -205,7 +210,7 @@ describe('useAccessStore', () => {
|
||||
name: 'About',
|
||||
path: '/about',
|
||||
};
|
||||
store.addTab(targetTab);
|
||||
const addTargetTab = store.addTab(targetTab);
|
||||
store.addTab({
|
||||
fullPath: '/contact',
|
||||
meta: {},
|
||||
@@ -213,7 +218,7 @@ describe('useAccessStore', () => {
|
||||
path: '/contact',
|
||||
} as any);
|
||||
|
||||
await store.closeOtherTabs(targetTab);
|
||||
await store.closeOtherTabs(addTargetTab);
|
||||
|
||||
expect(store.tabs).toHaveLength(1);
|
||||
expect(store.tabs[0]?.name).toBe('About');
|
||||
@@ -227,7 +232,7 @@ describe('useAccessStore', () => {
|
||||
name: 'Home',
|
||||
path: '/home',
|
||||
};
|
||||
store.addTab(targetTab);
|
||||
const addTargetTab = store.addTab(targetTab);
|
||||
store.addTab({
|
||||
fullPath: '/about',
|
||||
meta: {},
|
||||
@@ -241,7 +246,7 @@ describe('useAccessStore', () => {
|
||||
path: '/contact',
|
||||
} as any);
|
||||
|
||||
await store.closeRightTabs(targetTab);
|
||||
await store.closeRightTabs(addTargetTab);
|
||||
|
||||
expect(store.tabs).toHaveLength(1);
|
||||
expect(store.tabs[0]?.name).toBe('Home');
|
||||
|
@@ -1,4 +1,9 @@
|
||||
import type { Router, RouteRecordNormalized } from 'vue-router';
|
||||
import type { ComputedRef } from 'vue';
|
||||
import type {
|
||||
RouteLocationNormalized,
|
||||
Router,
|
||||
RouteRecordNormalized,
|
||||
} from 'vue-router';
|
||||
|
||||
import type { TabDefinition } from '@vben-core/typings';
|
||||
|
||||
@@ -52,23 +57,23 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
/**
|
||||
* Close tabs in bulk
|
||||
*/
|
||||
async _bulkCloseByPaths(paths: string[]) {
|
||||
this.tabs = this.tabs.filter((item) => {
|
||||
return !paths.includes(getTabPath(item));
|
||||
});
|
||||
async _bulkCloseByKeys(keys: string[]) {
|
||||
const keySet = new Set(keys);
|
||||
this.tabs = this.tabs.filter(
|
||||
(item) => !keySet.has(getTabKeyFromTab(item)),
|
||||
);
|
||||
|
||||
this.updateCacheTabs();
|
||||
await this.updateCacheTabs();
|
||||
},
|
||||
/**
|
||||
* @zh_CN 关闭标签页
|
||||
* @param tab
|
||||
*/
|
||||
_close(tab: TabDefinition) {
|
||||
const { fullPath } = tab;
|
||||
if (isAffixTab(tab)) {
|
||||
return;
|
||||
}
|
||||
const index = this.tabs.findIndex((item) => item.fullPath === fullPath);
|
||||
const index = this.tabs.findIndex((item) => equalTab(item, tab));
|
||||
index !== -1 && this.tabs.splice(index, 1);
|
||||
},
|
||||
/**
|
||||
@@ -101,14 +106,17 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
* @zh_CN 添加标签页
|
||||
* @param routeTab
|
||||
*/
|
||||
addTab(routeTab: TabDefinition) {
|
||||
const tab = cloneTab(routeTab);
|
||||
addTab(routeTab: TabDefinition): TabDefinition {
|
||||
let tab = cloneTab(routeTab);
|
||||
if (!tab.key) {
|
||||
tab.key = getTabKey(routeTab);
|
||||
}
|
||||
if (!isTabShown(tab)) {
|
||||
return;
|
||||
return tab;
|
||||
}
|
||||
|
||||
const tabIndex = this.tabs.findIndex((tab) => {
|
||||
return getTabPath(tab) === getTabPath(routeTab);
|
||||
const tabIndex = this.tabs.findIndex((item) => {
|
||||
return equalTab(item, tab);
|
||||
});
|
||||
|
||||
if (tabIndex === -1) {
|
||||
@@ -154,10 +162,11 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
mergedTab.meta.newTabTitle = curMeta.newTabTitle;
|
||||
}
|
||||
}
|
||||
|
||||
tab = mergedTab;
|
||||
this.tabs.splice(tabIndex, 1, mergedTab);
|
||||
}
|
||||
this.updateCacheTabs();
|
||||
return tab;
|
||||
},
|
||||
/**
|
||||
* @zh_CN 关闭所有标签页
|
||||
@@ -173,65 +182,63 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
* @param tab
|
||||
*/
|
||||
async closeLeftTabs(tab: TabDefinition) {
|
||||
const index = this.tabs.findIndex(
|
||||
(item) => getTabPath(item) === getTabPath(tab),
|
||||
);
|
||||
const index = this.tabs.findIndex((item) => equalTab(item, tab));
|
||||
|
||||
if (index < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const leftTabs = this.tabs.slice(0, index);
|
||||
const paths: string[] = [];
|
||||
const keys: string[] = [];
|
||||
|
||||
for (const item of leftTabs) {
|
||||
if (!isAffixTab(item)) {
|
||||
paths.push(getTabPath(item));
|
||||
keys.push(item.key as string);
|
||||
}
|
||||
}
|
||||
await this._bulkCloseByPaths(paths);
|
||||
await this._bulkCloseByKeys(keys);
|
||||
},
|
||||
/**
|
||||
* @zh_CN 关闭其他标签页
|
||||
* @param tab
|
||||
*/
|
||||
async closeOtherTabs(tab: TabDefinition) {
|
||||
const closePaths = this.tabs.map((item) => getTabPath(item));
|
||||
const closeKeys = this.tabs.map((item) => getTabKeyFromTab(item));
|
||||
|
||||
const paths: string[] = [];
|
||||
const keys: string[] = [];
|
||||
|
||||
for (const path of closePaths) {
|
||||
if (path !== tab.fullPath) {
|
||||
const closeTab = this.tabs.find((item) => getTabPath(item) === path);
|
||||
for (const key of closeKeys) {
|
||||
if (key !== getTabKeyFromTab(tab)) {
|
||||
const closeTab = this.tabs.find(
|
||||
(item) => getTabKeyFromTab(item) === key,
|
||||
);
|
||||
if (!closeTab) {
|
||||
continue;
|
||||
}
|
||||
if (!isAffixTab(closeTab)) {
|
||||
paths.push(getTabPath(closeTab));
|
||||
keys.push(closeTab.key as string);
|
||||
}
|
||||
}
|
||||
}
|
||||
await this._bulkCloseByPaths(paths);
|
||||
await this._bulkCloseByKeys(keys);
|
||||
},
|
||||
/**
|
||||
* @zh_CN 关闭右侧标签页
|
||||
* @param tab
|
||||
*/
|
||||
async closeRightTabs(tab: TabDefinition) {
|
||||
const index = this.tabs.findIndex(
|
||||
(item) => getTabPath(item) === getTabPath(tab),
|
||||
);
|
||||
const index = this.tabs.findIndex((item) => equalTab(item, tab));
|
||||
|
||||
if (index !== -1 && index < this.tabs.length - 1) {
|
||||
const rightTabs = this.tabs.slice(index + 1);
|
||||
|
||||
const paths: string[] = [];
|
||||
const keys: string[] = [];
|
||||
for (const item of rightTabs) {
|
||||
if (!isAffixTab(item)) {
|
||||
paths.push(getTabPath(item));
|
||||
keys.push(item.key as string);
|
||||
}
|
||||
}
|
||||
await this._bulkCloseByPaths(paths);
|
||||
await this._bulkCloseByKeys(keys);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -242,15 +249,14 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
*/
|
||||
async closeTab(tab: TabDefinition, router: Router) {
|
||||
const { currentRoute } = router;
|
||||
|
||||
// 关闭不是激活选项卡
|
||||
if (getTabPath(currentRoute.value) !== getTabPath(tab)) {
|
||||
if (getTabKey(currentRoute.value) !== getTabKeyFromTab(tab)) {
|
||||
this._close(tab);
|
||||
this.updateCacheTabs();
|
||||
return;
|
||||
}
|
||||
const index = this.getTabs.findIndex(
|
||||
(item) => getTabPath(item) === getTabPath(currentRoute.value),
|
||||
(item) => getTabKeyFromTab(item) === getTabKey(currentRoute.value),
|
||||
);
|
||||
|
||||
const before = this.getTabs[index - 1];
|
||||
@@ -277,7 +283,7 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
async closeTabByKey(key: string, router: Router) {
|
||||
const originKey = decodeURIComponent(key);
|
||||
const index = this.tabs.findIndex(
|
||||
(item) => getTabPath(item) === originKey,
|
||||
(item) => getTabKeyFromTab(item) === originKey,
|
||||
);
|
||||
if (index === -1) {
|
||||
return;
|
||||
@@ -290,12 +296,12 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据路径获取标签页
|
||||
* @param path
|
||||
* 根据tab的key获取tab
|
||||
* @param key
|
||||
*/
|
||||
getTabByPath(path: string) {
|
||||
getTabByKey(key: string) {
|
||||
return this.getTabs.find(
|
||||
(item) => getTabPath(item) === path,
|
||||
(item) => getTabKeyFromTab(item) === key,
|
||||
) as TabDefinition;
|
||||
},
|
||||
/**
|
||||
@@ -311,22 +317,19 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
* @param tab
|
||||
*/
|
||||
async pinTab(tab: TabDefinition) {
|
||||
const index = this.tabs.findIndex(
|
||||
(item) => getTabPath(item) === getTabPath(tab),
|
||||
);
|
||||
if (index !== -1) {
|
||||
const oldTab = this.tabs[index];
|
||||
tab.meta.affixTab = true;
|
||||
tab.meta.title = oldTab?.meta?.title as string;
|
||||
// this.addTab(tab);
|
||||
this.tabs.splice(index, 1, tab);
|
||||
const index = this.tabs.findIndex((item) => equalTab(item, tab));
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
const oldTab = this.tabs[index];
|
||||
tab.meta.affixTab = true;
|
||||
tab.meta.title = oldTab?.meta?.title as string;
|
||||
// this.addTab(tab);
|
||||
this.tabs.splice(index, 1, tab);
|
||||
// 过滤固定tabs,后面更改affixTabOrder的值的话可能会有问题,目前行464排序affixTabs没有设置值
|
||||
const affixTabs = this.tabs.filter((tab) => isAffixTab(tab));
|
||||
// 获得固定tabs的index
|
||||
const newIndex = affixTabs.findIndex(
|
||||
(item) => getTabPath(item) === getTabPath(tab),
|
||||
);
|
||||
const newIndex = affixTabs.findIndex((item) => equalTab(item, tab));
|
||||
// 交换位置重新排序
|
||||
await this.sortTabs(index, newIndex);
|
||||
},
|
||||
@@ -334,7 +337,13 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
/**
|
||||
* 刷新标签页
|
||||
*/
|
||||
async refresh(router: Router) {
|
||||
async refresh(router: Router | string) {
|
||||
// 如果是Router路由,那么就根据当前路由刷新
|
||||
// 如果是string字符串,为路由名称,则定向刷新指定标签页,不能是当前路由名称,否则不会刷新
|
||||
if (typeof router === 'string') {
|
||||
return await this.refreshByName(router);
|
||||
}
|
||||
|
||||
const { currentRoute } = router;
|
||||
const { name } = currentRoute.value;
|
||||
|
||||
@@ -349,6 +358,15 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
stopProgress();
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据路由名称刷新指定标签页
|
||||
*/
|
||||
async refreshByName(name: string) {
|
||||
this.excludeCachedTabs.add(name);
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
this.excludeCachedTabs.delete(name);
|
||||
},
|
||||
|
||||
/**
|
||||
* @zh_CN 重置标签页标题
|
||||
*/
|
||||
@@ -356,9 +374,7 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
if (tab?.meta?.newTabTitle) {
|
||||
return;
|
||||
}
|
||||
const findTab = this.tabs.find(
|
||||
(item) => getTabPath(item) === getTabPath(tab),
|
||||
);
|
||||
const findTab = this.tabs.find((item) => equalTab(item, tab));
|
||||
if (findTab) {
|
||||
findTab.meta.newTabTitle = undefined;
|
||||
await this.updateCacheTabs();
|
||||
@@ -386,13 +402,24 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
|
||||
/**
|
||||
* @zh_CN 设置标签页标题
|
||||
* @param tab
|
||||
* @param title
|
||||
*
|
||||
* @zh_CN 支持设置静态标题字符串或计算属性作为动态标题
|
||||
* @zh_CN 当标题为计算属性时,标题会随计算属性值变化而自动更新
|
||||
* @zh_CN 适用于需要根据状态或多语言动态更新标题的场景
|
||||
*
|
||||
* @param {TabDefinition} tab - 标签页对象
|
||||
* @param {ComputedRef<string> | string} title - 标题内容,支持静态字符串或计算属性
|
||||
*
|
||||
* @example
|
||||
* // 设置静态标题
|
||||
* setTabTitle(tab, '新标签页');
|
||||
*
|
||||
* @example
|
||||
* // 设置动态标题
|
||||
* setTabTitle(tab, computed(() => t('common.dashboard')));
|
||||
*/
|
||||
async setTabTitle(tab: TabDefinition, title: string) {
|
||||
const findTab = this.tabs.find(
|
||||
(item) => getTabPath(item) === getTabPath(tab),
|
||||
);
|
||||
async setTabTitle(tab: TabDefinition, title: ComputedRef<string> | string) {
|
||||
const findTab = this.tabs.find((item) => equalTab(item, tab));
|
||||
|
||||
if (findTab) {
|
||||
findTab.meta.newTabTitle = title;
|
||||
@@ -433,17 +460,15 @@ export const useTabbarStore = defineStore('core-tabbar', {
|
||||
* @param tab
|
||||
*/
|
||||
async unpinTab(tab: TabDefinition) {
|
||||
const index = this.tabs.findIndex(
|
||||
(item) => getTabPath(item) === getTabPath(tab),
|
||||
);
|
||||
|
||||
if (index !== -1) {
|
||||
const oldTab = this.tabs[index];
|
||||
tab.meta.affixTab = false;
|
||||
tab.meta.title = oldTab?.meta?.title as string;
|
||||
// this.addTab(tab);
|
||||
this.tabs.splice(index, 1, tab);
|
||||
const index = this.tabs.findIndex((item) => equalTab(item, tab));
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
const oldTab = this.tabs[index];
|
||||
tab.meta.affixTab = false;
|
||||
tab.meta.title = oldTab?.meta?.title as string;
|
||||
// this.addTab(tab);
|
||||
this.tabs.splice(index, 1, tab);
|
||||
// 过滤固定tabs,后面更改affixTabOrder的值的话可能会有问题,目前行464排序affixTabs没有设置值
|
||||
const affixTabs = this.tabs.filter((tab) => isAffixTab(tab));
|
||||
// 获得固定tabs的index,使用固定tabs的下一个位置也就是活动tabs的第一个位置
|
||||
@@ -576,11 +601,49 @@ function isTabShown(tab: TabDefinition) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh_CN 获取标签页路径
|
||||
* 从route获取tab页的key
|
||||
* @param tab
|
||||
*/
|
||||
function getTabPath(tab: RouteRecordNormalized | TabDefinition) {
|
||||
return decodeURIComponent((tab as TabDefinition).fullPath || tab.path);
|
||||
function getTabKey(tab: RouteLocationNormalized | RouteRecordNormalized) {
|
||||
const {
|
||||
fullPath,
|
||||
path,
|
||||
meta: { fullPathKey } = {},
|
||||
query = {},
|
||||
} = tab as RouteLocationNormalized;
|
||||
// pageKey可能是数组(查询参数重复时可能出现)
|
||||
const pageKey = Array.isArray(query.pageKey)
|
||||
? query.pageKey[0]
|
||||
: query.pageKey;
|
||||
let rawKey;
|
||||
if (pageKey) {
|
||||
rawKey = pageKey;
|
||||
} else {
|
||||
rawKey = fullPathKey === false ? path : (fullPath ?? path);
|
||||
}
|
||||
try {
|
||||
return decodeURIComponent(rawKey);
|
||||
} catch {
|
||||
return rawKey;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从tab获取tab页的key
|
||||
* 如果tab没有key,那么就从route获取key
|
||||
* @param tab
|
||||
*/
|
||||
function getTabKeyFromTab(tab: TabDefinition): string {
|
||||
return tab.key ?? getTabKey(tab);
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较两个tab是否相等
|
||||
* @param a
|
||||
* @param b
|
||||
*/
|
||||
function equalTab(a: TabDefinition, b: TabDefinition) {
|
||||
return getTabKeyFromTab(a) === getTabKeyFromTab(b);
|
||||
}
|
||||
|
||||
function routeToTab(route: RouteRecordNormalized) {
|
||||
@@ -588,5 +651,8 @@ function routeToTab(route: RouteRecordNormalized) {
|
||||
meta: route.meta,
|
||||
name: route.name,
|
||||
path: route.path,
|
||||
key: getTabKey(route),
|
||||
} as TabDefinition;
|
||||
}
|
||||
|
||||
export { getTabKey };
|
||||
|
@@ -48,8 +48,12 @@
|
||||
"@vueuse/core": "catalog:",
|
||||
"ant-design-vue": "catalog:",
|
||||
"dayjs": "catalog:",
|
||||
"json-bigint": "catalog:",
|
||||
"pinia": "catalog:",
|
||||
"vue": "catalog:",
|
||||
"vue-router": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/json-bigint": "catalog:"
|
||||
}
|
||||
}
|
||||
|
@@ -8,38 +8,40 @@ import type { ComponentType } from './component';
|
||||
import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
setupVbenForm<ComponentType>({
|
||||
config: {
|
||||
// ant design vue组件库默认都是 v-model:value
|
||||
baseModelPropName: 'value',
|
||||
// 一些组件是 v-model:checked 或者 v-model:fileList
|
||||
modelPropNameMap: {
|
||||
Checkbox: 'checked',
|
||||
Radio: 'checked',
|
||||
Switch: 'checked',
|
||||
Upload: 'fileList',
|
||||
async function initSetupVbenForm() {
|
||||
setupVbenForm<ComponentType>({
|
||||
config: {
|
||||
// ant design vue组件库默认都是 v-model:value
|
||||
baseModelPropName: 'value',
|
||||
// 一些组件是 v-model:checked 或者 v-model:fileList
|
||||
modelPropNameMap: {
|
||||
Checkbox: 'checked',
|
||||
Radio: 'checked',
|
||||
Switch: 'checked',
|
||||
Upload: 'fileList',
|
||||
},
|
||||
},
|
||||
},
|
||||
defineRules: {
|
||||
// 输入项目必填国际化适配
|
||||
required: (value, _params, ctx) => {
|
||||
if (value === undefined || value === null || value.length === 0) {
|
||||
return $t('ui.formRules.required', [ctx.label]);
|
||||
}
|
||||
return true;
|
||||
defineRules: {
|
||||
// 输入项目必填国际化适配
|
||||
required: (value, _params, ctx) => {
|
||||
if (value === undefined || value === null || value.length === 0) {
|
||||
return $t('ui.formRules.required', [ctx.label]);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
// 选择项目必填国际化适配
|
||||
selectRequired: (value, _params, ctx) => {
|
||||
if (value === undefined || value === null) {
|
||||
return $t('ui.formRules.selectRequired', [ctx.label]);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
// 选择项目必填国际化适配
|
||||
selectRequired: (value, _params, ctx) => {
|
||||
if (value === undefined || value === null) {
|
||||
return $t('ui.formRules.selectRequired', [ctx.label]);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const useVbenForm = useForm<ComponentType>;
|
||||
|
||||
export { useVbenForm, z };
|
||||
export { initSetupVbenForm, useVbenForm, z };
|
||||
export type VbenFormSchema = FormSchema<ComponentType>;
|
||||
export type { VbenFormProps };
|
||||
|
10
playground/src/api/examples/json-bigint.ts
Normal file
10
playground/src/api/examples/json-bigint.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 发起请求
|
||||
*/
|
||||
async function getBigIntData() {
|
||||
return requestClient.get('/demo/bigint');
|
||||
}
|
||||
|
||||
export { getBigIntData };
|
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* 该文件可自行根据业务逻辑进行调整
|
||||
*/
|
||||
import type { RequestClientOptions } from '@vben/request';
|
||||
import type { AxiosResponseHeaders, RequestClientOptions } from '@vben/request';
|
||||
|
||||
import { useAppConfig } from '@vben/hooks';
|
||||
import { preferences } from '@vben/preferences';
|
||||
@@ -12,8 +12,10 @@ import {
|
||||
RequestClient,
|
||||
} from '@vben/request';
|
||||
import { useAccessStore } from '@vben/stores';
|
||||
import { cloneDeep } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
import JSONBigInt from 'json-bigint';
|
||||
|
||||
import { useAuthStore } from '#/store';
|
||||
|
||||
@@ -25,6 +27,14 @@ function createRequestClient(baseURL: string, options?: RequestClientOptions) {
|
||||
const client = new RequestClient({
|
||||
...options,
|
||||
baseURL,
|
||||
transformResponse: (data: any, header: AxiosResponseHeaders) => {
|
||||
// storeAsString指示将BigInt存储为字符串,设为false则会存储为内置的BigInt类型
|
||||
return header.getContentType()?.toString().includes('application/json')
|
||||
? cloneDeep(
|
||||
JSONBigInt({ storeAsString: true, strict: true }).parse(data),
|
||||
)
|
||||
: data;
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
|
@@ -13,12 +13,16 @@ import { $t, setupI18n } from '#/locales';
|
||||
import { router } from '#/router';
|
||||
|
||||
import { initComponentAdapter } from './adapter/component';
|
||||
import { initSetupVbenForm } from './adapter/form';
|
||||
import App from './app.vue';
|
||||
|
||||
async function bootstrap(namespace: string) {
|
||||
// 初始化组件适配器
|
||||
await initComponentAdapter();
|
||||
|
||||
// 初始化表单组件
|
||||
await initSetupVbenForm();
|
||||
|
||||
// 设置弹窗的默认配置
|
||||
// setDefaultModalProps({
|
||||
// fullscreenButton: false,
|
||||
|
@@ -18,7 +18,7 @@ function setupCommonGuard(router: Router) {
|
||||
// 记录已经加载的页面
|
||||
const loadedPaths = new Set<string>();
|
||||
|
||||
router.beforeEach(async (to) => {
|
||||
router.beforeEach((to) => {
|
||||
to.meta.loaded = loadedPaths.has(to.path);
|
||||
|
||||
// 页面加载进度条
|
||||
|
@@ -255,6 +255,16 @@ const routes: RouteRecordRaw[] = [
|
||||
title: $t('demos.features.requestParamsSerializer'),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'BigIntDemo',
|
||||
path: '/demos/features/json-bigint',
|
||||
component: () =>
|
||||
import('#/views/demos/features/json-bigint/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:grape',
|
||||
title: 'JSON BigInt',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
// 面包屑导航
|
||||
|
@@ -111,10 +111,11 @@ const loginRef =
|
||||
async function onSubmit(params: Recordable<any>) {
|
||||
authStore.authLogin(params).catch(() => {
|
||||
// 登陆失败,刷新验证码的演示
|
||||
|
||||
const formApi = loginRef.value?.getFormApi();
|
||||
// 重置验证码组件的值
|
||||
formApi?.setFieldValue('captcha', false, false);
|
||||
// 使用表单API获取验证码组件实例,并调用其resume方法来重置验证码
|
||||
loginRef.value
|
||||
?.getFormApi()
|
||||
formApi
|
||||
?.getFieldComponentRef<InstanceType<typeof SliderCaptcha>>('captcha')
|
||||
?.resume();
|
||||
});
|
||||
|
39
playground/src/views/demos/features/json-bigint/index.vue
Normal file
39
playground/src/views/demos/features/json-bigint/index.vue
Normal file
@@ -0,0 +1,39 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { Alert, Button, Card } from 'ant-design-vue';
|
||||
|
||||
import { getBigIntData } from '#/api/examples/json-bigint';
|
||||
|
||||
const response = ref('');
|
||||
function fetchData() {
|
||||
getBigIntData().then((res) => {
|
||||
response.value = res;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<Page
|
||||
title="JSON BigInt Support"
|
||||
description="解析后端返回的长整数(long/bigInt)。代码位置:playground/src/api/request.ts中的transformResponse"
|
||||
>
|
||||
<Card>
|
||||
<Alert>
|
||||
<template #message>
|
||||
有些后端接口返回的ID是长整数,但javascript原生的JSON解析是不支持超过2^53-1的长整数的。
|
||||
这种情况可以建议后端返回数据前将长整数转换为字符串类型。如果后端不接受我们的建议😡……
|
||||
<br />
|
||||
下面的按钮点击后会发起请求,接口返回的JSON数据中的id字段是超出整数范围的数字,已自动将其解析为字符串
|
||||
</template>
|
||||
</Alert>
|
||||
<Button class="mt-4" type="primary" @click="fetchData">发起请求</Button>
|
||||
<div>
|
||||
<pre>
|
||||
{{ response }}
|
||||
</pre>
|
||||
</div>
|
||||
</Card>
|
||||
</Page>
|
||||
</template>
|
@@ -19,7 +19,7 @@ const checkValue = ref(['a', 'b']);
|
||||
|
||||
const options = [
|
||||
{ label: '选项1', value: 'a' },
|
||||
{ label: '选项2', value: 'b' },
|
||||
{ label: '选项2', value: 'b', num: 999 },
|
||||
{ label: '选项3', value: 'c' },
|
||||
{ label: '选项4', value: 'd' },
|
||||
{ label: '选项5', value: 'e' },
|
||||
@@ -168,10 +168,11 @@ function onBtnClick(value: any) {
|
||||
:options="options"
|
||||
v-bind="compProps"
|
||||
>
|
||||
<template #option="{ label, value }">
|
||||
<template #option="{ label, value, data }">
|
||||
<div class="flex items-center">
|
||||
<span>{{ label }}</span>
|
||||
<span class="ml-2 text-gray-400">{{ value }}</span>
|
||||
<span v-if="data.num" class="white ml-2">{{ data.num }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</VbenCheckButtonGroup>
|
||||
|
@@ -134,7 +134,7 @@ function handleClick(
|
||||
}
|
||||
case 'componentRef': {
|
||||
// 获取下拉组件的实例,并调用它的focus方法
|
||||
formApi.getFieldComponentRef<RefSelectProps>('fieldOptions')?.focus();
|
||||
formApi.getFieldComponentRef<RefSelectProps>('fieldOptions')?.focus?.();
|
||||
break;
|
||||
}
|
||||
case 'disabled': {
|
||||
|
@@ -11,7 +11,7 @@ export function getMenuTypeOptions() {
|
||||
value: 'catalog',
|
||||
},
|
||||
{ color: 'default', label: $t('system.menu.typeMenu'), value: 'menu' },
|
||||
{ color: 'error', label: $t('system.menu.typeButton'), value: 'action' },
|
||||
{ color: 'error', label: $t('system.menu.typeButton'), value: 'button' },
|
||||
{
|
||||
color: 'success',
|
||||
label: $t('system.menu.typeEmbedded'),
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user