@ftjs/core 1.2.1 → 1.3.0

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.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './form';
2
2
  export * from './table';
3
+ export * from './locale';
3
4
  export type * from './type-helper';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { unref, inject, computed, ref, watch, onScopeDispose, provide, toValue, watchEffect, nextTick } from "vue";
1
+ import { unref, inject, computed, ref, watch, onScopeDispose, provide, toValue, watchEffect, nextTick, shallowRef } from "vue";
2
2
  const isBrowser = typeof window !== "undefined";
3
3
  const getField = (column) => {
4
4
  var _a;
@@ -137,6 +137,14 @@ const isEqual = (a, b) => {
137
137
  (key) => Object.prototype.hasOwnProperty.call(b, key) && isEqual(a[key], b[key])
138
138
  );
139
139
  };
140
+ function forEachTree(tree, cb) {
141
+ for (const item of tree) {
142
+ cb(item);
143
+ if (item.children) {
144
+ forEachTree(item.children, cb);
145
+ }
146
+ }
147
+ }
140
148
  function isFormGetter(fn) {
141
149
  return typeof fn === "function";
142
150
  }
@@ -253,20 +261,30 @@ const getFieldsAndValues = (column) => {
253
261
  return { fields, values };
254
262
  };
255
263
  const useForm = (props) => {
256
- var _a;
257
264
  const columns = computed(() => props.columns);
258
- const formLocal = ref(props.formData ?? {});
259
- if (props.formData == null) {
260
- (_a = props["onUpdate:formData"]) == null ? void 0 : _a.call(props, formLocal.value);
261
- }
265
+ const formLocal = ref();
266
+ watch(
267
+ () => props.formData,
268
+ (v) => {
269
+ var _a;
270
+ if (v == null) {
271
+ v = {};
272
+ (_a = props["onUpdate:formData"]) == null ? void 0 : _a.call(props, v);
273
+ }
274
+ formLocal.value = v;
275
+ },
276
+ {
277
+ immediate: true
278
+ }
279
+ );
262
280
  const form = computed({
263
281
  get() {
264
282
  return formLocal.value;
265
283
  },
266
284
  set(v) {
267
- var _a2;
285
+ var _a;
268
286
  formLocal.value = v;
269
- (_a2 = props["onUpdate:formData"]) == null ? void 0 : _a2.call(props, v);
287
+ (_a = props["onUpdate:formData"]) == null ? void 0 : _a.call(props, v);
270
288
  }
271
289
  });
272
290
  const { columnsChecked, resetColumnsChecked } = useColumnsChecked(
@@ -293,9 +311,9 @@ const useForm = (props) => {
293
311
  });
294
312
  const visibleColumns = computed(() => {
295
313
  return columns.value.filter((column) => {
296
- var _a2;
314
+ var _a;
297
315
  const key = getField(column);
298
- return !hideFieldSet.value.has(key) && (((_a2 = columnsChecked.value) == null ? void 0 : _a2.includes(key)) ?? true);
316
+ return !hideFieldSet.value.has(key) && (((_a = columnsChecked.value) == null ? void 0 : _a.includes(key)) ?? true);
299
317
  }).sort((a, b) => {
300
318
  const keyA = getField(a);
301
319
  const keyB = getField(b);
@@ -529,22 +547,26 @@ const useFormItem = (options) => {
529
547
  };
530
548
  const useTable = (props) => {
531
549
  const formColumns = computed(() => {
532
- const fromTable = props.columns.filter((e) => e.search).map((e) => {
533
- if (typeof e.search === "string") {
534
- return {
535
- field: e.field,
536
- title: e.title,
537
- type: e.search
538
- };
550
+ const tableSearch = [];
551
+ forEachTree(props.columns, (e) => {
552
+ if (e.search) {
553
+ if (typeof e.search === "string") {
554
+ tableSearch.push({
555
+ field: e.field,
556
+ title: e.title,
557
+ type: e.search
558
+ });
559
+ } else {
560
+ tableSearch.push({
561
+ field: e.field,
562
+ title: e.title,
563
+ ...e.search
564
+ });
565
+ }
539
566
  }
540
- return {
541
- field: e.field,
542
- title: e.title,
543
- ...e.search
544
- };
545
567
  });
546
568
  return [
547
- ...fromTable,
569
+ ...tableSearch,
548
570
  ...props.searchColumns ?? []
549
571
  ];
550
572
  });
@@ -552,8 +574,63 @@ const useTable = (props) => {
552
574
  formColumns
553
575
  };
554
576
  };
577
+ const zhCN = {
578
+ form: {
579
+ submit: "确认",
580
+ reset: "重置",
581
+ search: "查询",
582
+ settings: "配置"
583
+ },
584
+ searchSettings: {
585
+ title: "配置筛选项",
586
+ dragHint: "(可拖动排序)",
587
+ selectAll: "全选",
588
+ reset: "重置",
589
+ save: "保存"
590
+ },
591
+ placeholder: {
592
+ input: (label) => label ? `请输入${label}` : "请输入",
593
+ select: (label) => label ? `请选择${label}` : "请选择"
594
+ },
595
+ datePicker: {
596
+ startTime: "开始时间",
597
+ endTime: "结束时间"
598
+ }
599
+ };
600
+ const enUS = {
601
+ form: {
602
+ submit: "Submit",
603
+ reset: "Reset",
604
+ search: "Search",
605
+ settings: "Settings"
606
+ },
607
+ searchSettings: {
608
+ title: "Configure Filters",
609
+ dragHint: "(drag to sort)",
610
+ selectAll: "Select All",
611
+ reset: "Reset",
612
+ save: "Save"
613
+ },
614
+ placeholder: {
615
+ input: (label) => label ? `Please enter ${label}` : "Please enter",
616
+ select: (label) => label ? `Please select ${label}` : "Please select"
617
+ },
618
+ datePicker: {
619
+ startTime: "Start Time",
620
+ endTime: "End Time"
621
+ }
622
+ };
623
+ const currentLocale = shallowRef(zhCN);
624
+ function setLocale(locale) {
625
+ currentLocale.value = locale;
626
+ }
627
+ function useLocale() {
628
+ return currentLocale;
629
+ }
555
630
  export {
556
631
  cloneDeep,
632
+ enUS,
633
+ forEachTree,
557
634
  get,
558
635
  getDefaultValues,
559
636
  getField,
@@ -564,11 +641,14 @@ export {
564
641
  isEqual,
565
642
  isFormGetter,
566
643
  set,
644
+ setLocale,
567
645
  setStorage,
568
646
  toValueWithForm,
569
647
  unrefs,
570
648
  useForm,
571
649
  useFormInject,
572
650
  useFormItem,
573
- useTable
651
+ useLocale,
652
+ useTable,
653
+ zhCN
574
654
  };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Locale definition for ftjs components
3
+ */
4
+ export interface FtLocale {
5
+ form: {
6
+ /** 提交/确认按钮文本 */
7
+ submit: string;
8
+ /** 重置按钮文本 */
9
+ reset: string;
10
+ /** 查询按钮文本 */
11
+ search: string;
12
+ /** 配置按钮文本 */
13
+ settings: string;
14
+ };
15
+ searchSettings: {
16
+ /** 配置筛选项标题 */
17
+ title: string;
18
+ /** 可拖动排序提示 */
19
+ dragHint: string;
20
+ /** 全选文本 */
21
+ selectAll: string;
22
+ /** 重置按钮文本 */
23
+ reset: string;
24
+ /** 保存按钮文本 */
25
+ save: string;
26
+ };
27
+ placeholder: {
28
+ /** 请输入{label} */
29
+ input: (label?: string) => string;
30
+ /** 请选择{label} */
31
+ select: (label?: string) => string;
32
+ };
33
+ datePicker: {
34
+ /** 开始时间 */
35
+ startTime: string;
36
+ /** 结束时间 */
37
+ endTime: string;
38
+ };
39
+ }
40
+ /**
41
+ * 简体中文 locale
42
+ */
43
+ export declare const zhCN: FtLocale;
44
+ /**
45
+ * English locale
46
+ */
47
+ export declare const enUS: FtLocale;
48
+ /**
49
+ * 设置当前 locale
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { setLocale, enUS } from '@ftjs/core'
54
+ * setLocale(enUS)
55
+ * ```
56
+ */
57
+ export declare function setLocale(locale: FtLocale): void;
58
+ /**
59
+ * 获取当前 locale (响应式)
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * import { useLocale } from '@ftjs/core'
64
+ * const locale = useLocale()
65
+ * console.log(locale.value.form.submit) // "确认" or "Submit"
66
+ * ```
67
+ */
68
+ export declare function useLocale(): import('vue').ShallowRef<FtLocale, FtLocale>;
@@ -18,6 +18,10 @@ export interface FtTableColumn<TableData extends Record<string, any>, SColumn ex
18
18
  * 搜索配置
19
19
  */
20
20
  search?: SColumn;
21
+ /**
22
+ * 子列,用于表头合并
23
+ */
24
+ children?: FtTableColumn<TableData, SColumn>[];
21
25
  }
22
26
  export interface FtBaseTableProps<T extends Record<string, any>, TableColumn extends FtTableColumn<T>, SearchColumn extends FtFormColumnBase<any>> {
23
27
  /**
package/dist/utils.d.ts CHANGED
@@ -36,3 +36,9 @@ export declare const setStorage: (key: string, value: any, cache?: string) => vo
36
36
  * 不考虑循环引用
37
37
  */
38
38
  export declare const isEqual: (a: any, b: any) => any;
39
+ interface TreeData {
40
+ children?: TreeData[];
41
+ [key: string]: any;
42
+ }
43
+ export declare function forEachTree<T extends TreeData>(tree: T[], cb: (item: T) => void): void;
44
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ftjs/core",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "keywords": [],
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -34,6 +34,16 @@
34
34
  "peerDependencies": {
35
35
  "vue": ">=3.3.0"
36
36
  },
37
+ "publishConfig": {
38
+ "access": "public",
39
+ "registry": "https://registry.npmjs.org/",
40
+ "provenance": true
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/yuhengshen/ftjs",
45
+ "directory": "packages/core"
46
+ },
37
47
  "scripts": {
38
48
  "build": "vite build",
39
49
  "minify": "pnpm dlx esbuild ./dist/index.js --minify --outfile=./dist/index.min.js",