Skip to content

Commit

Permalink
feat: type支持数组,可以多个继承合并
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed May 9, 2021
1 parent 897eba7 commit 7f75a39
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 25 deletions.
11 changes: 6 additions & 5 deletions packages/demo-antdv/src/views/advanced/nest/crud.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ export default function ({ expose, asideTableRef }) {
},
nestId: {
title: "嵌套表格",
type: ["number", "colspan"],
form: {
// 嵌套表格字段
rules: [{ required: true, message: "请选择用户" }],
component: {
name: shallowRef(SubTable)
},
// antdv 的跨列配置,需要配置如下三个
col: { span: 24 },
labelCol: { span: 2 },
wrapperCol: { span: 21 }
}
// antdv 的跨列配置,需要配置如下三个, 可以通过colspan简化
// col: { span: 24 },
// labelCol: { span: 2 },
// wrapperCol: { span: 21 }
}
}
}
Expand Down
20 changes: 6 additions & 14 deletions packages/fast-crud/src/types/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ function dateFormatter(value, format = "YYYY-MM-DD HH:mm:ss") {
return undefined;
}
const { t } = useI18n();
return `${doFormat(value[0], format)} ${t(
"fs.date.formatter.to"
)} ${doFormat(value[1], format)}`;
return `${doFormat(value[0], format)} ${t("fs.date.formatter.to")} ${doFormat(value[1], format)}`;
}
return doFormat(value, format);
}
Expand All @@ -35,7 +33,7 @@ const shortcuts = [
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
picker.$emit("pick", [start, end]);
},
}
},
{
text: "最近一个月",
Expand All @@ -44,7 +42,7 @@ const shortcuts = [
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
picker.$emit("pick", [start, end]);
},
}
},
{
text: "最近三个月",
Expand All @@ -53,14 +51,8 @@ const shortcuts = [
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
picker.$emit("pick", [start, end]);
},
},
}
}
];

export {
daterangeFormatter,
datetimerangeFormatter,
dateFormatter,
doFormat,
shortcuts,
};
export { daterangeFormatter, datetimerangeFormatter, dateFormatter, doFormat, shortcuts };
2 changes: 1 addition & 1 deletion packages/fast-crud/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ export default {
});
}
logger.debug("types installed:", defaultTypes);
},
}
};
21 changes: 21 additions & 0 deletions packages/fast-crud/src/types/list/assist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { uiContext } from "../../ui";

function antdvColspan(ui) {
return ui.type !== "antdv" ? {} : { labelCol: { span: 2 }, wrapperCol: { span: 21 } };
}

/**
* 辅助type
*/
export default function () {
const ui = uiContext.get();
return {
colspan: {
//跨列
form: {
col: { span: 24 },
...antdvColspan(ui)
}
}
};
}
20 changes: 15 additions & 5 deletions packages/fast-crud/src/use/use-crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { uiContext } from "../ui";
import { useI18n } from "../local";
import { useMerge } from "../use/use-merge";
import { CrudExpose } from "../use/use-expose";
import crud from "../../../demo-element/src/views/basis/compute/crud";
export interface CrudOptions {
table?: {};
columns?: [];
Expand Down Expand Up @@ -50,12 +49,23 @@ function mergeColumnDict(item) {
return item;
}
function mergeColumnType(item) {
if (item.type) {
const typeOptions = types.getType(item.type);
if (!item.type) {
return item;
}
let typeChain: any = [];
if (typeof item.type === "string") {
typeChain = [item.type];
} else if (item.type instanceof Array) {
typeChain = item.type;
}
const base = {};
for (const type of typeChain) {
const typeOptions = types.getType(type);
if (typeOptions) {
item = merge({}, typeOptions, item);
merge(base, typeOptions);
}
}
item = merge(base, item);
return item;
}
registerMergeColumnPlugin(mergeColumnType);
Expand Down Expand Up @@ -192,7 +202,7 @@ export function useCrud(ctx: UseCrudProps) {
expose.doRefresh();
},
// 监听a-table的服务端排序
onChange(pagination, filters, sorter, { currentDataSource }) {
onChange(pagination, filters, sorter) {
console.log("table change", sorter);
const { column, field, order } = sorter;
crudBinding.value.sort =
Expand Down

0 comments on commit 7f75a39

Please sign in to comment.