Skip to content

Commit 23263d3

Browse files
committed
perf: 增加card列表示例
1 parent fac103f commit 23263d3

File tree

5 files changed

+204
-0
lines changed

5 files changed

+204
-0
lines changed

src/router/modules/crud.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,15 @@ const advancedRoutes = {
958958
path: 'custom-layout',
959959
component: () => import('@/views/crud/advanced/custom-layout/index.vue'),
960960
},
961+
{
962+
meta: {
963+
title: '列表以card方式显示',
964+
keepAlive: true,
965+
},
966+
name: 'AdvancedCard',
967+
path: 'card',
968+
component: () => import('@/views/crud/advanced/card/index.vue'),
969+
},
961970
],
962971
};
963972

src/views/crud/advanced/card/api.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { requestForMock } from '@/utils/http/service';
2+
const request = (req: any) => {
3+
return requestForMock(req);
4+
};
5+
const apiPrefix = '/mock/AdvancedCard';
6+
export function GetList(query: any) {
7+
return request({
8+
url: apiPrefix + '/page',
9+
method: 'get',
10+
data: query,
11+
});
12+
}
13+
14+
export function AddObj(obj: any) {
15+
return request({
16+
url: apiPrefix + '/add',
17+
method: 'post',
18+
data: obj,
19+
});
20+
}
21+
22+
export function UpdateObj(obj: any) {
23+
return request({
24+
url: apiPrefix + '/update',
25+
method: 'post',
26+
data: obj,
27+
});
28+
}
29+
30+
export function DelObj(id: any) {
31+
return request({
32+
url: apiPrefix + '/delete',
33+
method: 'post',
34+
params: { id },
35+
});
36+
}
37+
38+
export function GetObj(id: any) {
39+
return request({
40+
url: apiPrefix + '/get',
41+
method: 'get',
42+
params: { id },
43+
});
44+
}

src/views/crud/advanced/card/crud.tsx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import * as api from './api';
2+
import {
3+
AddReq,
4+
CreateCrudOptionsProps,
5+
CreateCrudOptionsRet,
6+
DelReq,
7+
EditReq,
8+
UserPageQuery,
9+
UserPageRes,
10+
} from '@fast-crud/fast-crud';
11+
12+
export default async function ({
13+
crudExpose,
14+
}: CreateCrudOptionsProps): Promise<CreateCrudOptionsRet> {
15+
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
16+
return await api.GetList(query);
17+
};
18+
const editRequest = async ({ form, row }: EditReq) => {
19+
if (form.id == null) {
20+
form.id = row.id;
21+
}
22+
return await api.UpdateObj(form);
23+
};
24+
const delRequest = async ({ row }: DelReq) => {
25+
return await api.DelObj(row.id);
26+
};
27+
28+
const addRequest = async ({ form }: AddReq) => {
29+
return await api.AddObj(form);
30+
};
31+
32+
return {
33+
crudOptions: {
34+
request: {
35+
pageRequest,
36+
addRequest,
37+
editRequest,
38+
delRequest,
39+
},
40+
rowHandle: {
41+
align: 'center',
42+
},
43+
table: {
44+
show: false,
45+
},
46+
toolbar: {
47+
compact: false,
48+
},
49+
columns: {
50+
id: {
51+
title: 'ID',
52+
type: 'number',
53+
column: {
54+
width: 50,
55+
},
56+
form: {
57+
show: false,
58+
},
59+
},
60+
title: {
61+
title: '标题',
62+
type: 'text',
63+
},
64+
content: {
65+
title: '内容',
66+
type: 'text',
67+
},
68+
},
69+
},
70+
};
71+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<template>
2+
<fs-crud ref="crudRef" v-bind="crudBinding">
3+
<n-row
4+
v-if="crudBinding?.data?.length > 0"
5+
gutter="10"
6+
style="height: 100%; width: 100%; overflow: auto"
7+
>
8+
<n-col
9+
v-for="(item, index) of crudBinding.data"
10+
:key="item.id"
11+
:span="6"
12+
style="margin-bottom: 10px"
13+
>
14+
<n-card :title="item.title">
15+
{{ item.content }}
16+
<template #header-extra> 操作 </template>
17+
<template #action>
18+
<div style="display: flex; justify-content: space-evenly">
19+
<fs-icon icon="ion:eye-outline" @click="openView({ index: index, row: item })" />
20+
<fs-icon icon="ion:create-outline" @click="openEdit({ index: index, row: item })" />
21+
<fs-icon icon="ion:trash-outline" @click="doRemove({ index: index, row: item })" />
22+
</div>
23+
</template>
24+
</n-card>
25+
</n-col>
26+
</n-row>
27+
</fs-crud>
28+
</template>
29+
30+
<script lang="ts" setup>
31+
import { onMounted } from 'vue';
32+
import { useFsAsync, useFsRef } from '@fast-crud/fast-crud';
33+
import createCrudOptions from './crud';
34+
35+
const { crudRef, crudBinding, crudExpose, context } = useFsRef();
36+
37+
// 页面打开后获取列表数据
38+
onMounted(async () => {
39+
await useFsAsync({ crudBinding, crudRef, crudExpose, context, createCrudOptions });
40+
41+
await crudExpose.doRefresh();
42+
});
43+
44+
function openView(opts: any) {
45+
crudExpose.openView(opts);
46+
}
47+
function openEdit(opts: any) {
48+
crudExpose.openEdit(opts);
49+
}
50+
function doRemove(opts: any) {
51+
crudExpose.doRemove(opts);
52+
}
53+
</script>

src/views/crud/advanced/card/mock.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// @ts-ignore
2+
import mockUtil from '/src/mock/base';
3+
import _ from 'lodash-es';
4+
const options: any = {
5+
name: 'AdvancedCard',
6+
idGenerator: 0,
7+
};
8+
const list = [
9+
{
10+
title: 'fast-crud怎么样',
11+
content: '很好用',
12+
},
13+
{
14+
title: '大环境不好呀',
15+
content: '好好学习提升自己吧',
16+
},
17+
{
18+
title: 'Certd是什么',
19+
content: 'Certd是一款开源的证书全自动管理系统',
20+
},
21+
];
22+
23+
options.list = list;
24+
options.copyTimes = 100;
25+
const mock = mockUtil.buildMock(options);
26+
27+
export default mock;

0 commit comments

Comments
 (0)