@ftjs/tdesign 0.5.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/dist/index.js ADDED
@@ -0,0 +1,457 @@
1
+ import { computed, toValue, createVNode, mergeProps, defineComponent, createBlock, openBlock, resolveDynamicComponent, unref, createElementBlock, Fragment, renderList, ref, useId, withCtx, renderSlot, createCommentVNode, createTextVNode, createElementVNode } from "vue";
2
+ import { getField, set, useFormItem, unrefs, useFormInject, useForm } from "@ftjs/core";
3
+ import { FormItem, AutoComplete as AutoComplete$1, Cascader as Cascader$1, Form, Button, Dialog, Tree } from "tdesign-vue-next";
4
+ import { MoveIcon, SettingIcon } from "tdesign-icons-vue-next";
5
+ const useFormItemProps = (column) => {
6
+ return computed(() => {
7
+ const name = getField(column);
8
+ const label = toValue(column.title) ?? "";
9
+ return {
10
+ name,
11
+ label
12
+ };
13
+ });
14
+ };
15
+ const useRules = (props) => {
16
+ const rules = computed(() => {
17
+ const rulesObj = {};
18
+ for (const column of props.columns) {
19
+ if (column.rules) {
20
+ const field = getField(column);
21
+ set(rulesObj, field, toValue(column.rules));
22
+ }
23
+ }
24
+ return rulesObj;
25
+ });
26
+ return { rules };
27
+ };
28
+ const AutoComplete = defineFormItem((props) => {
29
+ const {
30
+ valueComputed
31
+ } = useFormItem({
32
+ props
33
+ });
34
+ const formItemProps = useFormItemProps(props.column);
35
+ return () => {
36
+ const _props = unrefs(props.column.props);
37
+ return createVNode(FormItem, formItemProps.value, {
38
+ default: () => [props.isView ? createVNode("div", null, [valueComputed.value || "-"]) : createVNode(AutoComplete$1, mergeProps({
39
+ "value": valueComputed.value,
40
+ "onUpdate:value": ($event) => valueComputed.value = $event,
41
+ "placeholder": `请输入${formItemProps.value.label}`
42
+ }, _props), null)]
43
+ });
44
+ };
45
+ });
46
+ const Cascader = defineFormItem((props) => {
47
+ const {
48
+ valueComputed
49
+ } = useFormItem({
50
+ props
51
+ });
52
+ const formItemProps = useFormItemProps(props.column);
53
+ return () => {
54
+ const _props = unrefs(props.column.props);
55
+ return createVNode(FormItem, formItemProps.value, {
56
+ default: () => [props.isView ? createVNode("div", null, [valueComputed.value || "-"]) : (
57
+ // @ts-expect-error Type 'TdSelectInputProps | SelectInputValue | undefined' is not assignable to type 'TdSelectInputProps | undefined'.
58
+ createVNode(Cascader$1, mergeProps({
59
+ "value": valueComputed.value,
60
+ "onUpdate:value": ($event) => valueComputed.value = $event,
61
+ "placeholder": `请输入${formItemProps.value.label}`
62
+ }, _props), null)
63
+ )]
64
+ });
65
+ };
66
+ });
67
+ function defineFormItem(setup) {
68
+ return /* @__PURE__ */ defineComponent(setup, {
69
+ props: {
70
+ column: Object,
71
+ isView: Boolean
72
+ }
73
+ });
74
+ }
75
+ const formRenderMap = /* @__PURE__ */ new Map([["auto-complete", AutoComplete], ["cascader", Cascader]]);
76
+ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
77
+ ...{
78
+ name: "FtTdFormContentItem",
79
+ inheritAttrs: false
80
+ },
81
+ __name: "form-content-item",
82
+ props: {
83
+ column: {},
84
+ isView: { type: Boolean }
85
+ },
86
+ setup(__props) {
87
+ const props = __props;
88
+ const { form } = useFormInject();
89
+ const isView = computed(() => {
90
+ return toValue(props.column.isView) ?? props.isView;
91
+ });
92
+ return (_ctx, _cache) => {
93
+ return isView.value && _ctx.column.viewRender ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.column.viewRender), {
94
+ key: 0,
95
+ formData: unref(form)
96
+ }, null, 8, ["formData"])) : !isView.value && _ctx.column.editRender ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.column.editRender), {
97
+ key: 1,
98
+ formData: unref(form)
99
+ }, null, 8, ["formData"])) : (openBlock(), createBlock(resolveDynamicComponent(unref(formRenderMap).get(_ctx.column.type)), {
100
+ key: 2,
101
+ column: _ctx.column,
102
+ "is-view": isView.value
103
+ }, null, 8, ["column", "is-view"]));
104
+ };
105
+ }
106
+ });
107
+ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
108
+ ...{
109
+ name: "FtTdFormContent",
110
+ inheritAttrs: false
111
+ },
112
+ __name: "form-content",
113
+ props: {
114
+ columns: {},
115
+ isView: { type: Boolean }
116
+ },
117
+ setup(__props) {
118
+ return (_ctx, _cache) => {
119
+ return openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.columns, (column) => {
120
+ return openBlock(), createBlock(_sfc_main$3, {
121
+ key: unref(getField)(column),
122
+ column,
123
+ "is-view": _ctx.isView
124
+ }, null, 8, ["column", "is-view"]);
125
+ }), 128);
126
+ };
127
+ }
128
+ });
129
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
130
+ ...{
131
+ name: "FtTdForm",
132
+ inheritAttrs: false
133
+ },
134
+ __name: "ft-td-form",
135
+ props: {
136
+ width: {},
137
+ hideFooter: { type: Boolean },
138
+ hideConfirm: { type: Boolean },
139
+ hideReset: { type: Boolean },
140
+ columns: {},
141
+ internalFormProps: {},
142
+ formData: {},
143
+ "onUpdate:formData": { type: Function },
144
+ onSubmit: { type: Function },
145
+ isView: { type: Boolean },
146
+ cache: {}
147
+ },
148
+ setup(__props, { expose: __expose }) {
149
+ const props = __props;
150
+ const { getFormData, visibleColumns, form, resetToDefault, setAsDefault } = useForm(props);
151
+ const formRef = ref();
152
+ const { rules } = useRules(props);
153
+ const formProps = computed(() => {
154
+ return {
155
+ data: form.value,
156
+ onSubmit: async (context) => {
157
+ var _a;
158
+ if (context.firstError) return;
159
+ const formData = getFormData();
160
+ (_a = props.onSubmit) == null ? void 0 : _a.call(props, formData);
161
+ },
162
+ ...props.internalFormProps
163
+ };
164
+ });
165
+ const id = useId();
166
+ __expose({
167
+ formInstance: formRef,
168
+ resetToDefault,
169
+ getFormData,
170
+ setAsDefault
171
+ });
172
+ return (_ctx, _cache) => {
173
+ return openBlock(), createBlock(unref(Form), mergeProps({
174
+ ref_key: "formRef",
175
+ ref: formRef,
176
+ name: unref(id),
177
+ style: { width: _ctx.width },
178
+ rules: unref(rules)
179
+ }, { ..._ctx.$attrs, ...formProps.value }), {
180
+ default: withCtx(() => [
181
+ createVNode(_sfc_main$2, {
182
+ columns: unref(visibleColumns),
183
+ "is-view": _ctx.isView
184
+ }, null, 8, ["columns", "is-view"]),
185
+ renderSlot(_ctx.$slots, "footer"),
186
+ !_ctx.hideFooter && !_ctx.$slots.footer && !_ctx.isView ? (openBlock(), createBlock(unref(FormItem), {
187
+ key: 0,
188
+ label: " ",
189
+ colon: false
190
+ }, {
191
+ default: withCtx(() => [
192
+ !_ctx.hideConfirm ? (openBlock(), createBlock(unref(Button), {
193
+ key: 0,
194
+ theme: "primary",
195
+ type: "submit"
196
+ }, {
197
+ default: withCtx(() => _cache[1] || (_cache[1] = [
198
+ createTextVNode(" 提交 ")
199
+ ])),
200
+ _: 1
201
+ })) : createCommentVNode("", true),
202
+ !_ctx.hideReset ? (openBlock(), createBlock(unref(Button), {
203
+ key: 1,
204
+ style: { "margin-left": "10px" },
205
+ theme: "danger",
206
+ onClick: _cache[0] || (_cache[0] = () => unref(resetToDefault)())
207
+ }, {
208
+ default: withCtx(() => _cache[2] || (_cache[2] = [
209
+ createTextVNode(" 重置 ")
210
+ ])),
211
+ _: 1
212
+ })) : createCommentVNode("", true)
213
+ ]),
214
+ _: 1
215
+ })) : createCommentVNode("", true)
216
+ ]),
217
+ _: 3
218
+ }, 16, ["name", "style", "rules"]);
219
+ };
220
+ }
221
+ });
222
+ const _hoisted_1 = { style: { "text-align": "center" } };
223
+ const _hoisted_2 = { style: { "display": "flex", "gap": "10px" } };
224
+ const _sfc_main = /* @__PURE__ */ defineComponent({
225
+ ...{
226
+ name: "FtTdFormSearch",
227
+ inheritAttrs: false
228
+ },
229
+ __name: "ft-td-form-search",
230
+ props: {
231
+ columns: {},
232
+ internalFormProps: {},
233
+ formData: {},
234
+ "onUpdate:formData": { type: Function },
235
+ onSubmit: { type: Function },
236
+ isView: { type: Boolean },
237
+ cache: {}
238
+ },
239
+ setup(__props, { expose: __expose }) {
240
+ const props = __props;
241
+ const {
242
+ visibleColumns,
243
+ form,
244
+ resetToDefault,
245
+ getFormData,
246
+ columnsSort,
247
+ columnsChecked,
248
+ resetColumnsChecked,
249
+ resetColumnsSort,
250
+ setAsDefault
251
+ } = useForm(props);
252
+ const formRef = ref();
253
+ const { rules } = useRules(props);
254
+ const formProps = computed(() => {
255
+ return {
256
+ layout: "inline",
257
+ ...props.internalFormProps,
258
+ data: form.value,
259
+ onSubmit: async (context) => {
260
+ var _a;
261
+ if (context.firstError) return;
262
+ const formData = getFormData();
263
+ (_a = props.onSubmit) == null ? void 0 : _a.call(props, formData);
264
+ }
265
+ };
266
+ });
267
+ const settingModal = ref(false);
268
+ let oldSortList = [];
269
+ const createColumnsTree = () => {
270
+ const treeData = [
271
+ { label: "全选", value: "__all", draggable: false, children: [] }
272
+ ];
273
+ const children = [];
274
+ for (const column of props.columns) {
275
+ const key = getField(column);
276
+ children.push({
277
+ label: toValue(column.title),
278
+ value: key
279
+ });
280
+ }
281
+ children.sort((a, b) => {
282
+ const aSort = columnsSort.value[a.value];
283
+ const bSort = columnsSort.value[b.value];
284
+ return aSort - bSort;
285
+ });
286
+ oldSortList = [...children];
287
+ treeData[0].children = children;
288
+ return { treeData };
289
+ };
290
+ const columnsTree = ref([]);
291
+ const columnsCheckedTree = ref([]);
292
+ const setting = () => {
293
+ const { treeData } = createColumnsTree();
294
+ columnsTree.value = treeData;
295
+ columnsCheckedTree.value = JSON.parse(JSON.stringify(columnsChecked.value));
296
+ settingModal.value = true;
297
+ };
298
+ const onSettingOk = () => {
299
+ settingModal.value = false;
300
+ columnsChecked.value = columnsCheckedTree.value;
301
+ const list = columnsTree.value[0].children;
302
+ const oldColumnsSort = {
303
+ ...columnsSort.value
304
+ };
305
+ const newColumnsSort = {};
306
+ list.forEach((e, idx) => {
307
+ const oldNode = oldSortList[idx];
308
+ const oldField = oldNode.value;
309
+ const oldSort = oldColumnsSort[oldField];
310
+ const curField = e.value;
311
+ newColumnsSort[curField] = oldSort;
312
+ });
313
+ columnsSort.value = newColumnsSort;
314
+ };
315
+ const onReset = () => {
316
+ resetColumnsChecked();
317
+ resetColumnsSort();
318
+ settingModal.value = false;
319
+ };
320
+ const allowDrop = ({ dropNode, dropPosition }) => {
321
+ if (dropNode.value === "__all") return false;
322
+ if (dropPosition === 0) return false;
323
+ return true;
324
+ };
325
+ const onDrop = ({ dragNode, dropPosition, dropNode }) => {
326
+ const list = columnsTree.value[0].children;
327
+ const fromIndex = list.findIndex((e) => e.value === dragNode.value);
328
+ list.splice(fromIndex, 1);
329
+ const toIndex = list.findIndex((e) => e.value === dropNode.value) + dropPosition;
330
+ list.splice(toIndex, 0, dragNode);
331
+ };
332
+ __expose({
333
+ formInstance: formRef,
334
+ formData: form,
335
+ resetToDefault,
336
+ getFormData,
337
+ setAsDefault
338
+ });
339
+ return (_ctx, _cache) => {
340
+ return openBlock(), createElementBlock(Fragment, null, [
341
+ createVNode(unref(Dialog), {
342
+ visible: settingModal.value,
343
+ "onUpdate:visible": _cache[1] || (_cache[1] = ($event) => settingModal.value = $event),
344
+ mode: "modeless",
345
+ width: 260,
346
+ destroyOnClose: ""
347
+ }, {
348
+ header: withCtx(() => _cache[3] || (_cache[3] = [
349
+ createElementVNode("span", null, [
350
+ createTextVNode(" 配置筛选项 "),
351
+ createElementVNode("span", { style: { "font-size": "12px", "color": "gray" } }, " (可拖动排序) ")
352
+ ], -1)
353
+ ])),
354
+ footer: withCtx(() => [
355
+ createElementVNode("div", _hoisted_1, [
356
+ createVNode(unref(Button), {
357
+ theme: "danger",
358
+ onClick: onReset
359
+ }, {
360
+ default: withCtx(() => _cache[4] || (_cache[4] = [
361
+ createTextVNode(" 重置 ")
362
+ ])),
363
+ _: 1
364
+ }),
365
+ createVNode(unref(Button), {
366
+ theme: "primary",
367
+ onClick: onSettingOk
368
+ }, {
369
+ default: withCtx(() => _cache[5] || (_cache[5] = [
370
+ createTextVNode(" 保存 ")
371
+ ])),
372
+ _: 1
373
+ })
374
+ ])
375
+ ]),
376
+ default: withCtx(() => [
377
+ createVNode(unref(Tree), {
378
+ data: columnsTree.value,
379
+ modelValue: columnsCheckedTree.value,
380
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => columnsCheckedTree.value = $event),
381
+ expanded: ["__all"],
382
+ checkable: "",
383
+ draggable: "",
384
+ line: "",
385
+ style: { "--td-brand-color-light": "none" },
386
+ allowDrop,
387
+ onDrop
388
+ }, {
389
+ operations: withCtx(({ node }) => [
390
+ node.value !== "__all" ? (openBlock(), createBlock(unref(MoveIcon), { key: 0 })) : createCommentVNode("", true)
391
+ ]),
392
+ _: 1
393
+ }, 8, ["data", "modelValue"])
394
+ ]),
395
+ _: 1
396
+ }, 8, ["visible"]),
397
+ createVNode(unref(Form), mergeProps({
398
+ ref_key: "formRef",
399
+ ref: formRef,
400
+ style: { "gap": "10px" },
401
+ rules: unref(rules)
402
+ }, { ..._ctx.$attrs, ...formProps.value }), {
403
+ default: withCtx(() => [
404
+ createVNode(_sfc_main$2, {
405
+ columns: unref(visibleColumns),
406
+ "is-view": _ctx.isView
407
+ }, null, 8, ["columns", "is-view"]),
408
+ createVNode(unref(FormItem), { style: { "--ft-form-control-width": "220px" } }, {
409
+ default: withCtx(() => [
410
+ createElementVNode("div", _hoisted_2, [
411
+ _ctx.cache ? (openBlock(), createBlock(unref(Button), {
412
+ key: 0,
413
+ theme: "primary",
414
+ ghost: "",
415
+ onClick: setting
416
+ }, {
417
+ icon: withCtx(() => [
418
+ createVNode(unref(SettingIcon))
419
+ ]),
420
+ default: withCtx(() => [
421
+ _cache[6] || (_cache[6] = createTextVNode(" 配置 "))
422
+ ]),
423
+ _: 1
424
+ })) : createCommentVNode("", true),
425
+ createVNode(unref(Button), {
426
+ theme: "primary",
427
+ type: "submit"
428
+ }, {
429
+ default: withCtx(() => _cache[7] || (_cache[7] = [
430
+ createTextVNode(" 查询 ")
431
+ ])),
432
+ _: 1
433
+ }),
434
+ createVNode(unref(Button), {
435
+ theme: "danger",
436
+ onClick: _cache[2] || (_cache[2] = () => unref(resetToDefault)())
437
+ }, {
438
+ default: withCtx(() => _cache[8] || (_cache[8] = [
439
+ createTextVNode(" 重置 ")
440
+ ])),
441
+ _: 1
442
+ })
443
+ ])
444
+ ]),
445
+ _: 1
446
+ })
447
+ ]),
448
+ _: 1
449
+ }, 16, ["rules"])
450
+ ], 64);
451
+ };
452
+ }
453
+ });
454
+ export {
455
+ _sfc_main$1 as FtTdForm,
456
+ _sfc_main as FtTdFormSearch
457
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@ftjs/tdesign",
3
+ "version": "0.5.3",
4
+ "keywords": [],
5
+ "author": "",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "dependencies": {},
20
+ "devDependencies": {
21
+ "dayjs": "^1.11.13",
22
+ "tdesign-vue-next": "^1.11.5",
23
+ "tdesign-icons-vue-next": "^0.3.5",
24
+ "vue": "^3.5.13",
25
+ "vue-component-type-helpers": "^2.2.0",
26
+ "@vitejs/plugin-vue": "^5.2.1",
27
+ "@vitejs/plugin-vue-jsx": "^4.1.1",
28
+ "typescript": "^5.8.3",
29
+ "vite": "^6.1.0",
30
+ "vite-plugin-dts": "^4.5.0",
31
+ "vue-tsc": "2.2.0",
32
+ "@ftjs/core": "0.5.3"
33
+ },
34
+ "peerDependencies": {
35
+ "vue": ">=3.3.0",
36
+ "@ftjs/core": ">=0.0.1",
37
+ "dayjs": ">=1.0.0",
38
+ "tdesign-vue-next": ">=1.11.5"
39
+ },
40
+ "scripts": {
41
+ "build": "vite build",
42
+ "minify": "pnpm dlx esbuild ./dist/index.js --minify --outfile=./dist/index.min.js",
43
+ "pub": "tsx ../../scripts/publish.ts"
44
+ }
45
+ }