Skip to content

Commit 7e01c97

Browse files
committed
perf: element 增加自定义列头示例
1 parent 25c607b commit 7e01c97

5 files changed

Lines changed: 152 additions & 0 deletions

File tree

src/router/source/modules/crud.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,12 @@ export const crudResources = [
501501
path: "/crud/feature/tree",
502502
component: "/crud/feature/tree/index.vue"
503503
},
504+
{
505+
title: "自定义表头",
506+
name: "FeatureHeader",
507+
path: "/crud/feature/header",
508+
component: "/crud/feature/header/index.vue"
509+
},
504510
{
505511
title: "多级表头",
506512
name: "FeatureHeaderGroup",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { requestForMock } from "/src/api/service";
2+
const request = requestForMock;
3+
const apiPrefix = "/mock/FeatureHeader";
4+
export function GetList(query: any) {
5+
return request({
6+
url: apiPrefix + "/page",
7+
method: "get",
8+
data: query
9+
});
10+
}
11+
12+
export function AddObj(obj: any) {
13+
return request({
14+
url: apiPrefix + "/add",
15+
method: "post",
16+
data: obj
17+
});
18+
}
19+
20+
export function UpdateObj(obj: any) {
21+
return request({
22+
url: apiPrefix + "/update",
23+
method: "post",
24+
data: obj
25+
});
26+
}
27+
28+
export function DelObj(id: any) {
29+
return request({
30+
url: apiPrefix + "/delete",
31+
method: "post",
32+
params: { id }
33+
});
34+
}
35+
36+
export function GetObj(id: any) {
37+
return request({
38+
url: apiPrefix + "/get",
39+
method: "get",
40+
params: { id }
41+
});
42+
}
43+
44+
export function BatchDelete(ids: any[]) {
45+
return request({
46+
url: apiPrefix + "/batchDelete",
47+
method: "post",
48+
data: { ids }
49+
});
50+
}
51+
52+
export function ColumnUpdate(key: string, value: any) {
53+
return request({
54+
url: apiPrefix + "/columnUpdate",
55+
method: "post",
56+
data: { key, value }
57+
});
58+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as api from "./api.js";
2+
import { CreateCrudOptionsProps, dict, CreateCrudOptionsRet, EditReq, DelReq, AddReq } from "@fast-crud/fast-crud";
3+
export default async function ({ crudExpose }: CreateCrudOptionsProps): Promise<CreateCrudOptionsRet> {
4+
const editRequest = async ({ form, row }: EditReq) => {
5+
if (form.id == null) {
6+
form.id = row.id;
7+
}
8+
return await api.UpdateObj(form);
9+
};
10+
const delRequest = async ({ row }: DelReq) => {
11+
return await api.DelObj(row.id);
12+
};
13+
const addRequest = async ({ form }: AddReq) => {
14+
return await api.AddObj(form);
15+
};
16+
17+
return {
18+
crudOptions: {
19+
request: {
20+
pageRequest: api.GetList,
21+
addRequest,
22+
editRequest,
23+
delRequest
24+
},
25+
columns: {
26+
text: {
27+
title: "text",
28+
type: "text",
29+
search: { show: true },
30+
column: {
31+
columnSlots: {
32+
header() {
33+
return (
34+
<span class={"flex "}>
35+
Text
36+
<el-tooltip content={"tooltip 提示"}>
37+
<fs-icon class={"ml-5"} icon={"ion:alert-circle-outline"}></fs-icon>
38+
</el-tooltip>
39+
</span>
40+
);
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}
47+
};
48+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<fs-page>
3+
<template #header>
4+
<div class="title">
5+
<span>自定义header</span>
6+
<span class="sub"></span>
7+
</div>
8+
</template>
9+
<fs-crud ref="crudRef" v-bind="crudBinding" />
10+
</fs-page>
11+
</template>
12+
13+
<script lang="ts" setup>
14+
import { onMounted } from "vue";
15+
import createCrudOptions from "./crud.js";
16+
import { useFsAsync, useFsRef } from "@fast-crud/fast-crud";
17+
18+
defineOptions({
19+
name: "FeatureHeader"
20+
});
21+
const { crudRef, crudBinding, crudExpose, context } = useFsRef();
22+
onMounted(async () => {
23+
await useFsAsync({ crudBinding, crudRef, crudExpose, context, createCrudOptions });
24+
await crudExpose.doRefresh();
25+
});
26+
</script>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @ts-ignore
2+
import mockUtil from "/src/mock/base";
3+
const options: any = {
4+
name: "FeatureHeader",
5+
idGenerator: 0
6+
};
7+
const list = [
8+
{
9+
text: "上面自定义表头"
10+
}
11+
];
12+
options.list = list;
13+
const mock = mockUtil.buildMock(options);
14+
export default mock;

0 commit comments

Comments
 (0)