@ftjs/antd 0.1.2 → 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 CHANGED
@@ -9,7 +9,7 @@ ant-design-vue 适配器
9
9
 
10
10
  ## 文档
11
11
 
12
- 请查看 [@ftjs/antd 文档](https://ftjs-docs.yhs.ink/@ftjs/antd/introduction.html)。
12
+ 请查看 [@ftjs/antd 文档](https://ftjs-docs.yhs.ink/antd/)。
13
13
 
14
14
  ## 许可证
15
15
 
@@ -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 declare const editMap: Map<keyof EditMap<any>, Component>;
13
- export declare const registerEdit: (type: keyof EditMap<any>, component: Component) => void;
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
@@ -682,9 +682,21 @@ const FtFormSearch = /* @__PURE__ */ defineFtForm((_, ctx) => {
682
682
  })]
683
683
  })]);
684
684
  }, formRenderMap, ["exposed", "onUpdate:exposed"]);
685
+ function isComponentTuple(value) {
686
+ return Array.isArray(value);
687
+ }
685
688
  const editMap = /* @__PURE__ */ new Map([
686
689
  ["input", Input],
687
- ["select", Select]
690
+ ["select", Select],
691
+ [
692
+ "switch",
693
+ [
694
+ Switch,
695
+ {
696
+ model: "checked"
697
+ }
698
+ ]
699
+ ]
688
700
  ]);
689
701
  const registerEdit = (type, component) => {
690
702
  editMap.set(type, component);
@@ -935,13 +947,24 @@ function useEdit(tableData) {
935
947
  edit = column.edit;
936
948
  }
937
949
  const field = edit.field ?? column.field;
938
- const component = editMap.get(edit.type);
939
- if (component) {
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
+ }
940
963
  return h(component, {
941
964
  ...edit.props,
942
965
  class: "ft-table-edit",
943
- value: get(scopeProps.record, field),
944
- "onUpdate:value": (value) => {
966
+ [model]: get(scopeProps.record, field),
967
+ [`onUpdate:${model}`]: (value) => {
945
968
  set(scopeProps.record, field, value);
946
969
  }
947
970
  });
@@ -1055,18 +1078,31 @@ const FtVxeTable = defineFtTable((_, ctx) => {
1055
1078
  } = params;
1056
1079
  const type = editObj.type;
1057
1080
  const field = editObj.field ?? column.field;
1058
- const component = editMap.get(type);
1059
- if (!component) {
1081
+ const componentOrTuple = editMap.get(type);
1082
+ if (!componentOrTuple) {
1060
1083
  console.warn(`[@ftjs/antd] 不支持的编辑类型: ${type}`);
1061
1084
  return "";
1062
1085
  }
1063
- return h(component, {
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 = {
1064
1099
  ...editObj.props,
1065
- value: row[field],
1066
- "onUpdate:value": (value) => {
1100
+ [model]: row[field],
1101
+ [modelEvent]: (value) => {
1067
1102
  row[field] = value;
1068
1103
  }
1069
- });
1104
+ };
1105
+ return h(component, props);
1070
1106
  } : null,
1071
1107
  ...column.slots
1072
1108
  };
@@ -1218,6 +1254,7 @@ export {
1218
1254
  FtTable,
1219
1255
  FtVxeTable,
1220
1256
  editMap,
1257
+ isComponentTuple,
1221
1258
  registerEdit,
1222
1259
  registerForm,
1223
1260
  useRules
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ftjs/antd",
3
- "version": "0.1.2",
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.2"
33
+ "@ftjs/core": "0.1.3"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@ant-design/icons-vue": ">=7.0.0",