Skip to content

Commit 6c260cf

Browse files
authored
feat: add api and role related simple views (#13)
1 parent de134bd commit 6c260cf

File tree

13 files changed

+395
-149
lines changed

13 files changed

+395
-149
lines changed

apps/web-antd/src/adapter/vxe-table.ts

Lines changed: 2 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import type { Recordable } from '@vben/types';
22

33
import { h } from 'vue';
44

5-
import { IconifyIcon } from '@vben/icons';
6-
import { $te } from '@vben/locales';
75
import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table';
8-
import { get, isFunction, isString } from '@vben/utils';
6+
import { get } from '@vben/utils';
97

108
import { objectOmit } from '@vueuse/core';
11-
import { Button, Image, Popconfirm, Switch, Tag } from 'ant-design-vue';
9+
import { Button, Image, Switch, Tag } from 'ant-design-vue';
1210

1311
import { $t } from '#/locales';
1412

@@ -121,138 +119,6 @@ setupVbenVxeTable({
121119
},
122120
});
123121

124-
/**
125-
* 注册表格的操作按钮渲染器
126-
*/
127-
vxeUI.renderer.add('CellOperation', {
128-
renderTableDefault({ attrs, options, props }, { column, row }) {
129-
const defaultProps = { size: 'small', type: 'link', ...props };
130-
let align = 'end';
131-
switch (column.align) {
132-
case 'center': {
133-
align = 'center';
134-
break;
135-
}
136-
case 'left': {
137-
align = 'start';
138-
break;
139-
}
140-
default: {
141-
align = 'end';
142-
break;
143-
}
144-
}
145-
const presets: Recordable<Recordable<any>> = {
146-
delete: {
147-
danger: true,
148-
text: $t('common.delete'),
149-
},
150-
edit: {
151-
text: $t('common.edit'),
152-
},
153-
};
154-
const operations: Array<Recordable<any>> = (
155-
options || ['edit', 'delete']
156-
)
157-
.map((opt) => {
158-
if (isString(opt)) {
159-
return presets[opt]
160-
? { code: opt, ...presets[opt], ...defaultProps }
161-
: {
162-
code: opt,
163-
text: $te(`common.${opt}`) ? $t(`common.${opt}`) : opt,
164-
...defaultProps,
165-
};
166-
} else {
167-
return { ...defaultProps, ...presets[opt.code], ...opt };
168-
}
169-
})
170-
.map((opt) => {
171-
const optBtn: Recordable<any> = {};
172-
Object.keys(opt).forEach((key) => {
173-
optBtn[key] = isFunction(opt[key]) ? opt[key](row) : opt[key];
174-
});
175-
return optBtn;
176-
})
177-
.filter((opt) => opt.show !== false);
178-
179-
function renderBtn(opt: Recordable<any>, listen = true) {
180-
return h(
181-
Button,
182-
{
183-
...props,
184-
...opt,
185-
icon: undefined,
186-
onClick: listen
187-
? () =>
188-
attrs?.onClick?.({
189-
code: opt.code,
190-
row,
191-
})
192-
: undefined,
193-
},
194-
{
195-
default: () => {
196-
const content = [];
197-
if (opt.icon) {
198-
content.push(
199-
h(IconifyIcon, { class: 'size-5', icon: opt.icon }),
200-
);
201-
}
202-
content.push(opt.text);
203-
return content;
204-
},
205-
},
206-
);
207-
}
208-
209-
function renderConfirm(opt: Recordable<any>) {
210-
return h(
211-
Popconfirm,
212-
{
213-
getPopupContainer(el) {
214-
return el.closest('tbody') || document.body;
215-
},
216-
placement: 'topLeft',
217-
title: $t('ui.actionTitle.delete', [attrs?.nameTitle || '']),
218-
...props,
219-
...opt,
220-
icon: undefined,
221-
onConfirm: () => {
222-
attrs?.onClick?.({
223-
code: opt.code,
224-
row,
225-
});
226-
},
227-
},
228-
{
229-
default: () => renderBtn({ ...opt }, false),
230-
description: () =>
231-
h(
232-
'div',
233-
{ class: 'truncate' },
234-
$t('ui.actionMessage.deleteConfirm', [
235-
row[attrs?.nameField || 'name'],
236-
]),
237-
),
238-
},
239-
);
240-
}
241-
242-
const btns = operations.map((opt) =>
243-
opt.code === 'delete' ? renderConfirm(opt) : renderBtn(opt),
244-
);
245-
return h(
246-
'div',
247-
{
248-
class: 'flex table-operations',
249-
style: { justifyContent: align },
250-
},
251-
btns,
252-
);
253-
},
254-
});
255-
256122
// 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化
257123
// vxeUI.formats.add
258124
},

apps/web-antd/src/api/api.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { PaginationResult } from '#/types';
2+
3+
import { requestClient } from './request';
4+
5+
export interface SysApiParams {
6+
name?: string;
7+
method?: string;
8+
path?: string;
9+
page?: number;
10+
size?: number;
11+
}
12+
13+
export interface SysApiResult {
14+
id: number;
15+
name: string;
16+
method: string;
17+
path: string;
18+
remark?: string;
19+
}
20+
21+
/**
22+
* 获取系统 API 列表
23+
*/
24+
export function getSysApiList(params: SysApiParams) {
25+
return requestClient.get<PaginationResult>('/api/v1/sys/apis', { params });
26+
}

apps/web-antd/src/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
export * from './api';
12
export * from './auth';
23
export * from './log';
34
export * from './menu';
5+
export * from './monitor';
6+
export * from './role';
47
export * from './user';

apps/web-antd/src/api/menu.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@ import type { RouteRecordStringComponent } from '@vben/types';
22

33
import { requestClient } from '#/api/request';
44

5+
export interface SysMenuResult {
6+
id: number;
7+
title: string;
8+
name: string;
9+
path: string;
10+
sort: number;
11+
icon?: string;
12+
type: number;
13+
component?: string;
14+
perms?: string;
15+
status: 0 | 1;
16+
display: 0 | 1;
17+
cache: 0 | 1;
18+
remark?: string;
19+
parent_id?: number;
20+
created_time: string;
21+
}
22+
523
/**
624
* 获取用户所有菜单
725
*/

apps/web-antd/src/api/monitor.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { requestClient } from './request';
2+
3+
export interface ServerMonitorResult {
4+
cpu: Record<string, any>;
5+
mem: Record<string, any>;
6+
sys: Record<string, any>;
7+
disk: Record<string, any>[];
8+
service: Record<string, any>;
9+
}
10+
11+
export interface RedisMonitorResult {
12+
info: Record<string, any>;
13+
stats: Record<string, any>[];
14+
}
15+
16+
export function getServerMonitor() {
17+
return requestClient.get<ServerMonitorResult>('/api/v1/monitors/server');
18+
}
19+
20+
export function getRedisMonitor() {
21+
return requestClient.get<RedisMonitorResult>('/api/v1/monitors/redis');
22+
}

apps/web-antd/src/api/role.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { SysMenuResult } from '.';
2+
3+
import { requestClient } from './request';
4+
5+
export interface SysRoleParams {
6+
name?: string;
7+
status?: number;
8+
page?: number;
9+
size?: number;
10+
}
11+
12+
export interface SysRoleResult {
13+
id: number;
14+
name: string;
15+
status: number;
16+
remark?: string;
17+
created_time: string;
18+
updated_time: string;
19+
menus?: SysMenuResult[];
20+
}
21+
22+
/**
23+
* 获取系统角色列表
24+
*/
25+
export function getSysRoleList(params: SysRoleParams) {
26+
return requestClient.get<SysRoleResult>('/api/v1/sys/roles', { params });
27+
}

apps/web-antd/src/locales/langs/en-US/page.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"created_time": "Create Time",
4040
"id": "ID",
4141
"mark": "Mark",
42-
"operation": "Operation"
42+
"operation": "Operation",
43+
"updated_time": "Update time"
4344
}
4445
}

apps/web-antd/src/locales/langs/zh-CN/page.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"created_time": "创建时间",
4040
"id": "序号",
4141
"mark": "备注",
42-
"operation": "操作"
42+
"operation": "操作",
43+
"updated_time": "更新时间"
4344
}
4445
}

0 commit comments

Comments
 (0)