@ftjs/antd 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/antd-table/column-edit.d.ts +11 -3
- package/dist/index.js +51 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InputProps, SelectProps } from 'ant-design-vue';
|
|
1
|
+
import { InputProps, SelectProps, SwitchProps } from 'ant-design-vue';
|
|
2
2
|
import { Component } from 'vue';
|
|
3
3
|
export interface Edit<Type, Props> {
|
|
4
4
|
type: Type;
|
|
@@ -8,6 +8,14 @@ export interface Edit<Type, Props> {
|
|
|
8
8
|
export interface EditMap<_TableData extends Record<string, any>> {
|
|
9
9
|
input: Edit<"input", InputProps>;
|
|
10
10
|
select: Edit<"select", SelectProps>;
|
|
11
|
+
switch: Edit<"switch", SwitchProps>;
|
|
11
12
|
}
|
|
12
|
-
export
|
|
13
|
-
|
|
13
|
+
export interface ComponentInfo {
|
|
14
|
+
model?: string;
|
|
15
|
+
}
|
|
16
|
+
type ComponentTuple = [Component, ComponentInfo];
|
|
17
|
+
export type EditMapValue = Component | ComponentTuple;
|
|
18
|
+
export declare function isComponentTuple(value: EditMapValue): value is ComponentTuple;
|
|
19
|
+
export declare const editMap: Map<keyof EditMap<any>, EditMapValue>;
|
|
20
|
+
export declare const registerEdit: (type: keyof EditMap<any>, component: EditMapValue) => void;
|
|
21
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -266,7 +266,8 @@ const inputNumber = defineFormComponent((props) => {
|
|
|
266
266
|
return createVNode(FormItem, formItemProps.value, {
|
|
267
267
|
default: () => [toValue(isView.value) ? createVNode("div", null, [valueComputed.value]) : createVNode(InputNumber, mergeProps({
|
|
268
268
|
"value": valueComputed.value,
|
|
269
|
-
"onUpdate:value": ($event) => valueComputed.value = $event
|
|
269
|
+
"onUpdate:value": ($event) => valueComputed.value = $event,
|
|
270
|
+
"placeholder": `请输入${formItemProps.value.label}`
|
|
270
271
|
}, _props), null)]
|
|
271
272
|
});
|
|
272
273
|
};
|
|
@@ -441,7 +442,7 @@ const FtForm = /* @__PURE__ */ defineFtForm((_, ctx) => {
|
|
|
441
442
|
"ref": formRef,
|
|
442
443
|
"name": id,
|
|
443
444
|
"style": {
|
|
444
|
-
width
|
|
445
|
+
width: width.value
|
|
445
446
|
}
|
|
446
447
|
}, ctx.attrs, formProps.value), {
|
|
447
448
|
default: () => [ctx.slots.formContent(), !hideFooter.value && createVNode(FormItem, {
|
|
@@ -681,9 +682,21 @@ const FtFormSearch = /* @__PURE__ */ defineFtForm((_, ctx) => {
|
|
|
681
682
|
})]
|
|
682
683
|
})]);
|
|
683
684
|
}, formRenderMap, ["exposed", "onUpdate:exposed"]);
|
|
685
|
+
function isComponentTuple(value) {
|
|
686
|
+
return Array.isArray(value);
|
|
687
|
+
}
|
|
684
688
|
const editMap = /* @__PURE__ */ new Map([
|
|
685
689
|
["input", Input],
|
|
686
|
-
["select", Select]
|
|
690
|
+
["select", Select],
|
|
691
|
+
[
|
|
692
|
+
"switch",
|
|
693
|
+
[
|
|
694
|
+
Switch,
|
|
695
|
+
{
|
|
696
|
+
model: "checked"
|
|
697
|
+
}
|
|
698
|
+
]
|
|
699
|
+
]
|
|
687
700
|
]);
|
|
688
701
|
const registerEdit = (type, component) => {
|
|
689
702
|
editMap.set(type, component);
|
|
@@ -934,13 +947,24 @@ function useEdit(tableData) {
|
|
|
934
947
|
edit = column.edit;
|
|
935
948
|
}
|
|
936
949
|
const field = edit.field ?? column.field;
|
|
937
|
-
const
|
|
938
|
-
if (
|
|
950
|
+
const componentOrTuple = editMap.get(edit.type);
|
|
951
|
+
if (componentOrTuple) {
|
|
952
|
+
let component;
|
|
953
|
+
let model = "value";
|
|
954
|
+
if (isComponentTuple(componentOrTuple)) {
|
|
955
|
+
component = componentOrTuple[0];
|
|
956
|
+
const info = componentOrTuple[1];
|
|
957
|
+
if (info.model) {
|
|
958
|
+
model = info.model;
|
|
959
|
+
}
|
|
960
|
+
} else {
|
|
961
|
+
component = componentOrTuple;
|
|
962
|
+
}
|
|
939
963
|
return h(component, {
|
|
940
964
|
...edit.props,
|
|
941
965
|
class: "ft-table-edit",
|
|
942
|
-
|
|
943
|
-
|
|
966
|
+
[model]: get(scopeProps.record, field),
|
|
967
|
+
[`onUpdate:${model}`]: (value) => {
|
|
944
968
|
set(scopeProps.record, field, value);
|
|
945
969
|
}
|
|
946
970
|
});
|
|
@@ -1054,18 +1078,31 @@ const FtVxeTable = defineFtTable((_, ctx) => {
|
|
|
1054
1078
|
} = params;
|
|
1055
1079
|
const type = editObj.type;
|
|
1056
1080
|
const field = editObj.field ?? column.field;
|
|
1057
|
-
const
|
|
1058
|
-
if (!
|
|
1081
|
+
const componentOrTuple = editMap.get(type);
|
|
1082
|
+
if (!componentOrTuple) {
|
|
1059
1083
|
console.warn(`[@ftjs/antd] 不支持的编辑类型: ${type}`);
|
|
1060
1084
|
return "";
|
|
1061
1085
|
}
|
|
1062
|
-
|
|
1086
|
+
let component;
|
|
1087
|
+
let model = "value";
|
|
1088
|
+
if (isComponentTuple(componentOrTuple)) {
|
|
1089
|
+
component = componentOrTuple[0];
|
|
1090
|
+
const info = componentOrTuple[1];
|
|
1091
|
+
if (info.model) {
|
|
1092
|
+
model = info.model;
|
|
1093
|
+
}
|
|
1094
|
+
} else {
|
|
1095
|
+
component = componentOrTuple;
|
|
1096
|
+
}
|
|
1097
|
+
const modelEvent = `onUpdate:${model}`;
|
|
1098
|
+
const props = {
|
|
1063
1099
|
...editObj.props,
|
|
1064
|
-
|
|
1065
|
-
|
|
1100
|
+
[model]: row[field],
|
|
1101
|
+
[modelEvent]: (value) => {
|
|
1066
1102
|
row[field] = value;
|
|
1067
1103
|
}
|
|
1068
|
-
}
|
|
1104
|
+
};
|
|
1105
|
+
return h(component, props);
|
|
1069
1106
|
} : null,
|
|
1070
1107
|
...column.slots
|
|
1071
1108
|
};
|
|
@@ -1217,6 +1254,7 @@ export {
|
|
|
1217
1254
|
FtTable,
|
|
1218
1255
|
FtVxeTable,
|
|
1219
1256
|
editMap,
|
|
1257
|
+
isComponentTuple,
|
|
1220
1258
|
registerEdit,
|
|
1221
1259
|
registerForm,
|
|
1222
1260
|
useRules
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ftjs/antd",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"vite": "^6.1.0",
|
|
31
31
|
"vite-plugin-dts": "^4.5.0",
|
|
32
32
|
"vue-tsc": "2.2.0",
|
|
33
|
-
"@ftjs/core": "0.1.
|
|
33
|
+
"@ftjs/core": "0.1.3"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@ant-design/icons-vue": ">=7.0.0",
|