Skip to content

Commit

Permalink
perf: 增加固定列示例
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Jun 15, 2021
1 parent 602798a commit 90d73b3
Show file tree
Hide file tree
Showing 16 changed files with 415 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/demo-antdv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.10.1",
"private": true,
"scripts": {
"dev": "vite --force",
"dev": "vite",
"debug": "vite --mode debug",
"debug:force": "vite --force --mode debug",
"build": "vite build",
Expand Down
5 changes: 5 additions & 0 deletions packages/demo-antdv/src/router/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ const resources = [
path: "/feature/sortable",
component: "/feature/sortable/index.vue"
},
{
title: "固定列",
path: "/feature/fixed",
component: "/feature/fixed/index.vue"
},
{
title: "可编辑",
path: "/feature/editable",
Expand Down
1 change: 1 addition & 0 deletions packages/demo-antdv/src/style/common.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import './scroll.less';
html,body{
margin:0;
padding:0;
Expand Down
28 changes: 28 additions & 0 deletions packages/demo-antdv/src/style/scroll.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
::-webkit-scrollbar {
width: 8px;
height: 8px;
}

::-webkit-scrollbar-track {
width: 8px;
background: rgba(#101F1C, 0.1);
-webkit-border-radius: 2em;
-moz-border-radius: 2em;
border-radius: 2em;
}

::-webkit-scrollbar-thumb {
// background-color: rgba(#101F1C, 0.5);
background-clip: padding-box;
min-height: 28px;
-webkit-border-radius: 2em;
-moz-border-radius: 2em;
border-radius: 2em;
background-color: #b3b3b3;
box-shadow: 0px 1px 1px #eee inset;
}

::-webkit-scrollbar-thumb:hover {

//background-color: rgba(#101F1C, 1);
}
50 changes: 50 additions & 0 deletions packages/demo-antdv/src/views/feature/fixed/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { requestForMock } from "/src/api/service";
const request = requestForMock;
const apiPrefix = "/FeatureFixed";
export function GetList(query) {
return request({
url: apiPrefix + "/page",
method: "get",
data: query
});
}

export function AddObj(obj) {
return request({
url: apiPrefix + "/add",
method: "post",
data: obj
});
}

export function UpdateObj(obj) {
return request({
url: apiPrefix + "/update",
method: "post",
data: obj
});
}

export function DelObj(id) {
return request({
url: apiPrefix + "/delete",
method: "post",
params: { id }
});
}

export function GetObj(id) {
return request({
url: apiPrefix + "/info",
method: "get",
params: { id }
});
}

export function BatchDelete(ids) {
return request({
url: apiPrefix + "/batchDelete",
method: "post",
data: { ids }
});
}
88 changes: 88 additions & 0 deletions packages/demo-antdv/src/views/feature/fixed/crud.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import * as api from "./api";
import { dict } from "@fast-crud/fast-crud";
export default function ({ expose }) {
const editRequest = async ({ form, row }) => {
form.id = row.id;
return await api.UpdateObj(form);
};
const delRequest = async ({ row }) => {
return await api.DelObj(row.id);
};
const addRequest = async ({ form }) => {
return await api.AddObj(form);
};

return {
crudOptions: {
request: {
pageRequest: api.GetList,
addRequest,
editRequest,
delRequest
},
rowHandle: {
//固定右侧
fixed: "right"
},
table: {
scroll: {
//需要设置它,否则滚动条拖动时,表头不会动
fixed: true
}
},
columns: {
text1: {
title: "text1",
type: "text",
column: {
//固定左侧,并且被固定在左侧列要放在最前面
fixed: "left",
width: 260
}
},
id: {
title: "id",
type: "text",
column: {
width: 100
}
},
text2: {
title: "text2",
type: "text",
column: {
width: 260
}
},
text3: {
title: "text3",
type: "text",
column: {
width: 260
}
},
text4: {
title: "text4",
type: "text",
column: {
width: 260
}
},
text5: {
title: "text5",
type: "text",
column: {
width: 260
}
},
last: {
title: "last",
type: "text",
column: {
width: 260
}
}
}
}
};
}
37 changes: 37 additions & 0 deletions packages/demo-antdv/src/views/feature/fixed/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<fs-crud ref="crudRef" v-bind="crudBinding" />
</template>

<script>
import { defineComponent, ref, onMounted } from "vue";
import createCrudOptions from "./crud";
import { useExpose, useCrud } from "@fast-crud/fast-crud";
export default defineComponent({
name: "FeatureFixed",
setup() {
// crud组件的ref
const crudRef = ref();
// crud 配置的ref
const crudBinding = ref();
// 暴露的方法
const { expose } = useExpose({ crudRef, crudBinding });
// 你的crud配置
const { crudOptions, selectedIds } = createCrudOptions({ expose });
// 初始化crud配置
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
const { resetCrudOptions } = useCrud({ expose, crudOptions });
// 你可以调用此方法,重新初始化crud配置
// resetCrudOptions(options)
// 页面打开后获取列表数据
onMounted(() => {
expose.doRefresh();
});
return {
crudBinding,
crudRef
};
}
});
</script>
14 changes: 14 additions & 0 deletions packages/demo-antdv/src/views/feature/fixed/mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import mockUtil from "/src/mock/base";
const options = {
name: "FeatureFixed",
idGenerator: 0
};
const list = [
{
text1: "我会被固定在左侧",
last: "操作列被固定在右侧"
}
];
options.list = list;
const mock = mockUtil.buildMock(options);
export default mock;
5 changes: 5 additions & 0 deletions packages/demo-element/src/router/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ const resources = [
path: "/feature/sortable",
component: "/feature/sortable/index.vue"
},
{
title: "列固定",
path: "/feature/fixed",
component: "/feature/fixed/index.vue"
},
{
title: "可编辑",
path: "/feature/editable",
Expand Down
50 changes: 50 additions & 0 deletions packages/demo-element/src/views/feature/fixed/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { requestForMock } from "/src/api/service";
const request = requestForMock;
const apiPrefix = "/FeatureFixed";
export function GetList(query) {
return request({
url: apiPrefix + "/page",
method: "get",
data: query
});
}

export function AddObj(obj) {
return request({
url: apiPrefix + "/add",
method: "post",
data: obj
});
}

export function UpdateObj(obj) {
return request({
url: apiPrefix + "/update",
method: "post",
data: obj
});
}

export function DelObj(id) {
return request({
url: apiPrefix + "/delete",
method: "post",
params: { id }
});
}

export function GetObj(id) {
return request({
url: apiPrefix + "/info",
method: "get",
params: { id }
});
}

export function BatchDelete(ids) {
return request({
url: apiPrefix + "/batchDelete",
method: "post",
data: { ids }
});
}
80 changes: 80 additions & 0 deletions packages/demo-element/src/views/feature/fixed/crud.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import * as api from "./api";
import { dict } from "@fast-crud/fast-crud";
export default function ({ expose }) {
const editRequest = async ({ form, row }) => {
form.id = row.id;
return await api.UpdateObj(form);
};
const delRequest = async ({ row }) => {
return await api.DelObj(row.id);
};
const addRequest = async ({ form }) => {
return await api.AddObj(form);
};

return {
crudOptions: {
request: {
pageRequest: api.GetList,
addRequest,
editRequest,
delRequest
},
rowHandle: {
fixed: "right"
},
columns: {
text1: {
title: "text1",
type: "text",
column: {
fixed: "left",
width: 260
}
},
id: {
title: "id",
type: "text",
column: {
width: 100
}
},
text2: {
title: "text2",
type: "text",
column: {
width: 260
}
},
text3: {
title: "text3",
type: "text",
column: {
width: 260
}
},
text4: {
title: "text4",
type: "text",
column: {
width: 260
}
},
text5: {
title: "text5",
type: "text",
column: {
width: 260
}
},
last: {
title: "last",
type: "text",
column: {
width: 260
}
}
}
}
};
}
Loading

0 comments on commit 90d73b3

Please sign in to comment.