szld-libs 0.3.26 → 0.3.28

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.
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import React, { useMemo, createElement } from "react";
3
- import { Form, Row, Col, Input, Space, Button, Cascader, TimePicker, DatePicker, Switch, Radio, InputNumber, Select, Checkbox, Rate } from "antd";
3
+ import { ConfigProvider, Form, Row, Col, Input, Space, Button, Cascader, TimePicker, DatePicker, Switch, Radio, InputNumber, Select, Checkbox, Rate } from "antd";
4
4
  import { CloseCircleFilled } from "@ant-design/icons";
5
5
  import _ from "lodash";
6
6
  import UploadFile from "../Upload";
@@ -65,31 +65,43 @@ const CreateForm = (props) => {
65
65
  }
66
66
  return ((_a = item.render) == null ? void 0 : _a.call(item, data == null ? void 0 : data[item.dataIndex], data)) || item.value || (data == null ? void 0 : data[item.dataIndex]);
67
67
  };
68
- return /* @__PURE__ */ jsx(Form, { layout: "horizontal", form: formProps == null ? void 0 : formProps.form, ...formLayout, ...formProps || {}, children: /* @__PURE__ */ jsx(Row, { gutter: 16, ...rowProps, children: items.filter((v) => !v.hidden).map((item, index) => /* @__PURE__ */ jsx(Col, { ...item.colProps || { span: 24 }, children: /* @__PURE__ */ jsx(
69
- Form.Item,
68
+ return /* @__PURE__ */ jsx(
69
+ ConfigProvider,
70
70
  {
71
- ...item.valueType === "upload" ? {
72
- getValueFromEvent: normFile
73
- } : {},
74
- label: !hiddenTitle ? item.title : "",
75
- name: item.valueType === "btns" ? void 0 : item.dataIndex,
76
- ...item.formItemProps,
77
- children: item.readonly ? /* @__PURE__ */ jsx("div", { children: renderReadOnly(item) }) : item.readonly === void 0 && readonly ? /* @__PURE__ */ jsx("div", { children: renderReadOnly(item) }) : /* @__PURE__ */ jsx(
78
- FormFields,
71
+ theme: {
72
+ components: {
73
+ Select: {
74
+ zIndexPopup: 3e4
75
+ }
76
+ }
77
+ },
78
+ children: /* @__PURE__ */ jsx(Form, { layout: "horizontal", form: formProps == null ? void 0 : formProps.form, ...formLayout, ...formProps || {}, children: /* @__PURE__ */ jsx(Row, { gutter: 16, ...rowProps, children: items.filter((v) => !v.hidden).map((item, index) => /* @__PURE__ */ jsx(Col, { ...item.colProps || { span: 24 }, children: /* @__PURE__ */ jsx(
79
+ Form.Item,
79
80
  {
80
- onChange: (e) => {
81
- var _a;
82
- return (_a = item == null ? void 0 : item.onChange) == null ? void 0 : _a.call(item, e);
83
- },
84
- valueType: item.valueType,
85
- onBtnClick,
86
- valueProps: item.valueProps,
87
- formItemProps: item.formItemProps,
88
- langId
81
+ ...item.valueType === "upload" ? {
82
+ getValueFromEvent: normFile
83
+ } : {},
84
+ label: !hiddenTitle ? item.title : "",
85
+ name: item.valueType === "btns" ? void 0 : item.dataIndex,
86
+ ...item.formItemProps,
87
+ children: item.readonly ? /* @__PURE__ */ jsx("div", { children: renderReadOnly(item) }) : item.readonly === void 0 && readonly ? /* @__PURE__ */ jsx("div", { children: renderReadOnly(item) }) : /* @__PURE__ */ jsx(
88
+ FormFields,
89
+ {
90
+ onChange: (e) => {
91
+ var _a;
92
+ return (_a = item == null ? void 0 : item.onChange) == null ? void 0 : _a.call(item, e);
93
+ },
94
+ valueType: item.valueType,
95
+ onBtnClick,
96
+ valueProps: item.valueProps,
97
+ formItemProps: item.formItemProps,
98
+ langId
99
+ }
100
+ )
89
101
  }
90
- )
102
+ ) }, item.dataIndex || index)) }) })
91
103
  }
92
- ) }, item.dataIndex || index)) }) });
104
+ );
93
105
  };
94
106
  const FormFields = (props) => {
95
107
  const { valueType, valueProps, value, onChange, onBtnClick, inputRef, formItemProps, langId } = props;
@@ -23,7 +23,7 @@ declare function useUniversalTable(): {
23
23
  searchText?: string | undefined;
24
24
  resetText?: string | undefined;
25
25
  }) => Promise<{
26
- formItems: CreateFormProps;
26
+ formItems: import("szld-libs/lib/components/CreateForm").CreateFormItemProps<import("szld-libs/lib/components/CreateForm").ValueType>[];
27
27
  selList: any[];
28
28
  }>;
29
29
  handleUniversalDelete: ({ commonRequest, refresh, interfaceType, record, configData, }: {
@@ -34,7 +34,7 @@ function useUniversalTable() {
34
34
  const selectItems = searchItems.filter(
35
35
  (item) => {
36
36
  var _a;
37
- return ["select", "checkbox", "radio", "mult-select"].includes((_a = item.renderdata) == null ? void 0 : _a.input);
37
+ return ["select", "checkbox", "radio", "mult-select", "cascader"].includes((_a = item.renderdata) == null ? void 0 : _a.input);
38
38
  }
39
39
  );
40
40
  let attrList = [];
@@ -49,6 +49,7 @@ function useUniversalTable() {
49
49
  }
50
50
  const formItems = await Promise.all(
51
51
  searchItems.map(async (item) => {
52
+ var _a;
52
53
  const renderdata = item.renderdata || {};
53
54
  const { input, width, labelCol } = renderdata || {};
54
55
  const renderPlaceholder = () => {
@@ -109,15 +110,44 @@ function useUniversalTable() {
109
110
  labelCol: { span: labelCol || 6 }
110
111
  }
111
112
  };
112
- if (["select", "checkbox", "radio", "mult-select"].includes(input)) {
113
+ if (["select", "checkbox", "radio", "mult-select", "cascader"].includes(input)) {
113
114
  const attrid = item.attrid || "";
114
115
  const attrItem = attrList.find((attrItem2) => attrItem2.attrid === attrid);
115
- const options = await handleSelectOptions({
116
- item: (attrItem == null ? void 0 : attrItem.json) || {},
116
+ let json = (attrItem == null ? void 0 : attrItem.json) || {};
117
+ if (!(json == null ? void 0 : json.inputType) && (renderdata == null ? void 0 : renderdata["input-type"])) {
118
+ json = {
119
+ ...json,
120
+ inputType: renderdata == null ? void 0 : renderdata["input-type"],
121
+ "action-url": renderdata == null ? void 0 : renderdata["action-url"],
122
+ "field-names": renderdata == null ? void 0 : renderdata["field-names"],
123
+ "key-field": {
124
+ ...renderdata == null ? void 0 : renderdata["key-field"]
125
+ }
126
+ };
127
+ }
128
+ let options = await handleSelectOptions({
129
+ item: json || {},
117
130
  commonRequest,
118
131
  commonRequestWidthParams
119
132
  });
120
- formItem.valueProps.options = options || [];
133
+ if (!(options == null ? void 0 : options.length)) {
134
+ const { data = [] } = renderdata || {};
135
+ if (data == null ? void 0 : data.length) {
136
+ options = data == null ? void 0 : data.map((v) => ({
137
+ label: v || "",
138
+ value: v || ""
139
+ }));
140
+ }
141
+ if ((_a = renderdata == null ? void 0 : renderdata.options) == null ? void 0 : _a.length) {
142
+ options = (renderdata == null ? void 0 : renderdata.options) || [];
143
+ }
144
+ }
145
+ if (input === "cascader") {
146
+ const _options = handleCascaderOptions(options, renderdata == null ? void 0 : renderdata["field-names"]);
147
+ formItem.valueProps.options = _options || [];
148
+ } else {
149
+ formItem.valueProps.options = options || [];
150
+ }
121
151
  }
122
152
  return formItem;
123
153
  })
@@ -303,7 +333,9 @@ function useUniversalTable() {
303
333
  const formValue = values[item.attrid];
304
334
  let attrvalue;
305
335
  if (formValue !== void 0 && formValue !== null) {
306
- if (Array.isArray(formValue) && ["range-picker"].includes(input)) {
336
+ if (input === "cascader" && Array.isArray(formValue)) {
337
+ attrvalue = formValue.join("|");
338
+ } else if (Array.isArray(formValue) && ["range-picker"].includes(input)) {
307
339
  attrvalue = formValue.map((v) => {
308
340
  var _a2;
309
341
  return ((_a2 = v == null ? void 0 : v.format) == null ? void 0 : _a2.call(v, "YYYY-MM-DD")) || v;
@@ -360,6 +392,23 @@ function useUniversalTable() {
360
392
  setSelList(resetSelList);
361
393
  onSearch({ "sel-list": resetSelList });
362
394
  };
395
+ const handleCascaderOptions = (data, fileNames) => {
396
+ const { label, value, children } = fileNames;
397
+ const recursionTransform = (list) => {
398
+ return list.map((item) => {
399
+ const current = {
400
+ label: item[label],
401
+ value: item[value],
402
+ children: []
403
+ };
404
+ if (Array.isArray(item[children]) && item[children].length > 0) {
405
+ current.children = recursionTransform(item[children]);
406
+ }
407
+ return current;
408
+ });
409
+ };
410
+ return recursionTransform(data);
411
+ };
363
412
  return {
364
413
  handleUniversalHeaderToColumns,
365
414
  handleSelListToFormItems,
@@ -67,31 +67,43 @@ const CreateForm = (props) => {
67
67
  }
68
68
  return ((_a = item.render) == null ? void 0 : _a.call(item, data == null ? void 0 : data[item.dataIndex], data)) || item.value || (data == null ? void 0 : data[item.dataIndex]);
69
69
  };
70
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form, { layout: "horizontal", form: formProps == null ? void 0 : formProps.form, ...formLayout, ...formProps || {}, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Row, { gutter: 16, ...rowProps, children: items.filter((v) => !v.hidden).map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { ...item.colProps || { span: 24 }, children: /* @__PURE__ */ jsxRuntime.jsx(
71
- antd.Form.Item,
70
+ return /* @__PURE__ */ jsxRuntime.jsx(
71
+ antd.ConfigProvider,
72
72
  {
73
- ...item.valueType === "upload" ? {
74
- getValueFromEvent: normFile
75
- } : {},
76
- label: !hiddenTitle ? item.title : "",
77
- name: item.valueType === "btns" ? void 0 : item.dataIndex,
78
- ...item.formItemProps,
79
- children: item.readonly ? /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderReadOnly(item) }) : item.readonly === void 0 && readonly ? /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderReadOnly(item) }) : /* @__PURE__ */ jsxRuntime.jsx(
80
- FormFields,
73
+ theme: {
74
+ components: {
75
+ Select: {
76
+ zIndexPopup: 3e4
77
+ }
78
+ }
79
+ },
80
+ children: /* @__PURE__ */ jsxRuntime.jsx(antd.Form, { layout: "horizontal", form: formProps == null ? void 0 : formProps.form, ...formLayout, ...formProps || {}, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Row, { gutter: 16, ...rowProps, children: items.filter((v) => !v.hidden).map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { ...item.colProps || { span: 24 }, children: /* @__PURE__ */ jsxRuntime.jsx(
81
+ antd.Form.Item,
81
82
  {
82
- onChange: (e) => {
83
- var _a;
84
- return (_a = item == null ? void 0 : item.onChange) == null ? void 0 : _a.call(item, e);
85
- },
86
- valueType: item.valueType,
87
- onBtnClick,
88
- valueProps: item.valueProps,
89
- formItemProps: item.formItemProps,
90
- langId
83
+ ...item.valueType === "upload" ? {
84
+ getValueFromEvent: normFile
85
+ } : {},
86
+ label: !hiddenTitle ? item.title : "",
87
+ name: item.valueType === "btns" ? void 0 : item.dataIndex,
88
+ ...item.formItemProps,
89
+ children: item.readonly ? /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderReadOnly(item) }) : item.readonly === void 0 && readonly ? /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderReadOnly(item) }) : /* @__PURE__ */ jsxRuntime.jsx(
90
+ FormFields,
91
+ {
92
+ onChange: (e) => {
93
+ var _a;
94
+ return (_a = item == null ? void 0 : item.onChange) == null ? void 0 : _a.call(item, e);
95
+ },
96
+ valueType: item.valueType,
97
+ onBtnClick,
98
+ valueProps: item.valueProps,
99
+ formItemProps: item.formItemProps,
100
+ langId
101
+ }
102
+ )
91
103
  }
92
- )
104
+ ) }, item.dataIndex || index)) }) })
93
105
  }
94
- ) }, item.dataIndex || index)) }) });
106
+ );
95
107
  };
96
108
  const FormFields = (props) => {
97
109
  const { valueType, valueProps, value, onChange, onBtnClick, inputRef, formItemProps, langId } = props;
@@ -23,7 +23,7 @@ declare function useUniversalTable(): {
23
23
  searchText?: string | undefined;
24
24
  resetText?: string | undefined;
25
25
  }) => Promise<{
26
- formItems: CreateFormProps;
26
+ formItems: import("szld-libs/lib/components/CreateForm").CreateFormItemProps<import("szld-libs/lib/components/CreateForm").ValueType>[];
27
27
  selList: any[];
28
28
  }>;
29
29
  handleUniversalDelete: ({ commonRequest, refresh, interfaceType, record, configData, }: {
@@ -35,7 +35,7 @@ function useUniversalTable() {
35
35
  const selectItems = searchItems.filter(
36
36
  (item) => {
37
37
  var _a;
38
- return ["select", "checkbox", "radio", "mult-select"].includes((_a = item.renderdata) == null ? void 0 : _a.input);
38
+ return ["select", "checkbox", "radio", "mult-select", "cascader"].includes((_a = item.renderdata) == null ? void 0 : _a.input);
39
39
  }
40
40
  );
41
41
  let attrList = [];
@@ -50,6 +50,7 @@ function useUniversalTable() {
50
50
  }
51
51
  const formItems = await Promise.all(
52
52
  searchItems.map(async (item) => {
53
+ var _a;
53
54
  const renderdata = item.renderdata || {};
54
55
  const { input, width, labelCol } = renderdata || {};
55
56
  const renderPlaceholder = () => {
@@ -110,15 +111,44 @@ function useUniversalTable() {
110
111
  labelCol: { span: labelCol || 6 }
111
112
  }
112
113
  };
113
- if (["select", "checkbox", "radio", "mult-select"].includes(input)) {
114
+ if (["select", "checkbox", "radio", "mult-select", "cascader"].includes(input)) {
114
115
  const attrid = item.attrid || "";
115
116
  const attrItem = attrList.find((attrItem2) => attrItem2.attrid === attrid);
116
- const options = await method.handleSelectOptions({
117
- item: (attrItem == null ? void 0 : attrItem.json) || {},
117
+ let json = (attrItem == null ? void 0 : attrItem.json) || {};
118
+ if (!(json == null ? void 0 : json.inputType) && (renderdata == null ? void 0 : renderdata["input-type"])) {
119
+ json = {
120
+ ...json,
121
+ inputType: renderdata == null ? void 0 : renderdata["input-type"],
122
+ "action-url": renderdata == null ? void 0 : renderdata["action-url"],
123
+ "field-names": renderdata == null ? void 0 : renderdata["field-names"],
124
+ "key-field": {
125
+ ...renderdata == null ? void 0 : renderdata["key-field"]
126
+ }
127
+ };
128
+ }
129
+ let options = await method.handleSelectOptions({
130
+ item: json || {},
118
131
  commonRequest,
119
132
  commonRequestWidthParams
120
133
  });
121
- formItem.valueProps.options = options || [];
134
+ if (!(options == null ? void 0 : options.length)) {
135
+ const { data = [] } = renderdata || {};
136
+ if (data == null ? void 0 : data.length) {
137
+ options = data == null ? void 0 : data.map((v) => ({
138
+ label: v || "",
139
+ value: v || ""
140
+ }));
141
+ }
142
+ if ((_a = renderdata == null ? void 0 : renderdata.options) == null ? void 0 : _a.length) {
143
+ options = (renderdata == null ? void 0 : renderdata.options) || [];
144
+ }
145
+ }
146
+ if (input === "cascader") {
147
+ const _options = handleCascaderOptions(options, renderdata == null ? void 0 : renderdata["field-names"]);
148
+ formItem.valueProps.options = _options || [];
149
+ } else {
150
+ formItem.valueProps.options = options || [];
151
+ }
122
152
  }
123
153
  return formItem;
124
154
  })
@@ -304,7 +334,9 @@ function useUniversalTable() {
304
334
  const formValue = values[item.attrid];
305
335
  let attrvalue;
306
336
  if (formValue !== void 0 && formValue !== null) {
307
- if (Array.isArray(formValue) && ["range-picker"].includes(input)) {
337
+ if (input === "cascader" && Array.isArray(formValue)) {
338
+ attrvalue = formValue.join("|");
339
+ } else if (Array.isArray(formValue) && ["range-picker"].includes(input)) {
308
340
  attrvalue = formValue.map((v) => {
309
341
  var _a2;
310
342
  return ((_a2 = v == null ? void 0 : v.format) == null ? void 0 : _a2.call(v, "YYYY-MM-DD")) || v;
@@ -361,6 +393,23 @@ function useUniversalTable() {
361
393
  setSelList(resetSelList);
362
394
  onSearch({ "sel-list": resetSelList });
363
395
  };
396
+ const handleCascaderOptions = (data, fileNames) => {
397
+ const { label, value, children } = fileNames;
398
+ const recursionTransform = (list) => {
399
+ return list.map((item) => {
400
+ const current = {
401
+ label: item[label],
402
+ value: item[value],
403
+ children: []
404
+ };
405
+ if (Array.isArray(item[children]) && item[children].length > 0) {
406
+ current.children = recursionTransform(item[children]);
407
+ }
408
+ return current;
409
+ });
410
+ };
411
+ return recursionTransform(data);
412
+ };
364
413
  return {
365
414
  handleUniversalHeaderToColumns,
366
415
  handleSelListToFormItems,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "szld-libs",
3
3
  "private": false,
4
- "version": "0.3.26",
4
+ "version": "0.3.28",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",