@ticatec/uniface-element 0.1.10 → 0.1.12

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,4 +1,4 @@
1
- import dayjs from "dayjs";
1
+ import dayjs, { isDayjs } from "dayjs";
2
2
  /**
3
3
  * 获取今日的日期,时间清空
4
4
  */
@@ -3,9 +3,10 @@
3
3
  import {DisplayMode} from "../common/DisplayMode";
4
4
  import iconLoading from "../assets/loading.gif";
5
5
  import OptionsBox from "./OptionsBox.svelte";
6
- import {tick} from "svelte";
6
+ import {onMount, tick} from "svelte";
7
7
  import CommonPicker from "../common/CommonPicker.svelte";
8
8
  import type {OnChangeHandler} from "../common/OnChangeHandler";
9
+ import type {IsLeafDetermine} from "./isLeafDetermine";
9
10
 
10
11
  type OnSelectOption = (item: any) => Promise<Array<any>>;
11
12
 
@@ -18,12 +19,14 @@
18
19
  export let keyField: string = "code";
19
20
  export let textField: string = "text";
20
21
  export let abbrField: string = 'abbr';
22
+ export let childrenField: string = 'children';
21
23
  export let style: string = '';
22
24
  export let placeholder: string = "";
23
25
  export let displayMode: DisplayMode = DisplayMode.Edit;
24
26
  export let emptyText: string | null = null;
27
+ export let checkLeaf: IsLeafDetermine | null = null;
25
28
  export let text: string = '';
26
- export let nodes: Array<Array<any>> = [];
29
+ export let nodes: Array<any> = [];
27
30
  export let menu$height: number = 150;
28
31
  export let onSelect: OnSelectOption;
29
32
  export let box$style: string = "";
@@ -32,22 +35,45 @@
32
35
  let oldValue = value;
33
36
  let selectedItems: Array<any> = [];
34
37
  let busy: boolean = false;
38
+ let list: Array<Array<any>> = [];
39
+
40
+ onMount(async () => {
41
+ list = [...nodes];
42
+ })
35
43
 
36
44
  const selectOption = (level: number) => async (item: any) => {
37
45
  value = item?.[keyField];
38
- let newArr = nodes.slice(0, level + 1)
46
+ let newList = list.slice(0, level + 1)
39
47
  if (level == 0) {
40
48
  selectedItems = [item];
41
49
  } else {
42
50
  selectedItems = [...selectedItems.slice(0, level), item];
43
51
  }
44
- busy = true;
45
- let list = await (onSelect?.(item));
46
- busy = false;
47
- if (list && list.length > 0) {
48
- nodes = [...newArr, list];
49
- await tick();
50
- contentPanel.scrollLeft = contentPanel.scrollWidth;
52
+ let isLeaf = checkLeaf == null ? false : checkLeaf(item);
53
+ if (!isLeaf) {
54
+ if (item[childrenField] == null && onSelect != null) {
55
+ busy = true;
56
+ let children = (await (onSelect(item))) ?? [];
57
+ busy = false;
58
+ item[childrenField] = children;
59
+ if (children.length > 0) {
60
+ list = [...newList, children];
61
+ await tick();
62
+ contentPanel.scrollLeft = contentPanel.scrollWidth;
63
+ } else {
64
+ showPopup = false;
65
+ }
66
+ } else {
67
+
68
+ if (item[childrenField] && item[childrenField].length > 0) {
69
+ console.log('存在子节点')
70
+ list = [...newList, item[childrenField]];
71
+ await tick();
72
+ contentPanel.scrollLeft = contentPanel.scrollWidth;
73
+ } else {
74
+ showPopup = false;
75
+ }
76
+ }
51
77
  } else {
52
78
  showPopup = false;
53
79
  }
@@ -68,6 +94,8 @@
68
94
 
69
95
  $: mh = `height: ${menu$height}px`;
70
96
 
97
+ $: list = [...nodes];
98
+
71
99
  $: text = selectedItems && selectedItems.length > 0 ? selectedItems[selectedItems.length - 1][textField] : emptyText ?? '';
72
100
 
73
101
  const cleanData = () => {
@@ -91,7 +119,7 @@
91
119
  <div class="cascade-options-popover" style={mh} slot="popup-panel">
92
120
  <div style="width: 100%; height: 100%; position: relative">
93
121
  <div bind:this={contentPanel} style="width: 100%; height: 100%; display: flex; flex-direction: row; overflow: auto">
94
- {#each nodes as node, idx}
122
+ {#each list as node, idx}
95
123
  <OptionsBox options={node} {keyField} textField={abbrField} {box$style} onSelect={selectOption(idx)}
96
124
  selectedItem={selectedItems[idx]}/>
97
125
  {/each}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 判断当前节点是否为末端节点
3
+ */
4
+ export type IsLeafDetermine = (item: any) => boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -9,7 +9,7 @@
9
9
  {#if visible}
10
10
  <Portal target="body">
11
11
  <div class="uniface-mask-overlay">
12
- <div style="position: relative; width: 100%; height: 100%;"
12
+ <div style="position: relative; width: 100%; height: 100%; overflow: hidden"
13
13
  on:click={()=>{visible = false}} aria-hidden="true">
14
14
  <slot></slot>
15
15
  </div>
@@ -3,7 +3,7 @@
3
3
  import type {OnChangeHandler} from "../common/OnChangeHandler";
4
4
  import type {UniDate} from "../base-calendar/dateUtils";
5
5
  import {DateFormats} from "../common/DateFormats";
6
- import dateUtils from "../common/date-utils";
6
+ import dateUtils from "../base-calendar/dateUtils";
7
7
 
8
8
  export let disabled: boolean = false;
9
9
  export let readonly: boolean = false;
@@ -45,15 +45,18 @@
45
45
 
46
46
  </script>
47
47
 
48
- <div class="action-panel" bind:this={panel} style="user-select: none; width: {actionsColumn.width}px;">
48
+ <div class="action-panel" bind:this={panel} style="user-select: none; width: {actionsColumn.width}px;">
49
49
  <div bind:this={scrollPanel} class="scroll-panel" on:scroll|passive={handleActionPanelScroll}>
50
- {#each rows as row, idx}
51
- <ActionsRow {row} {rowHeight} parentRect={rect} alternative={idx % 2 == 1} width={actionsColumn.width} actions={actionsColumn.getActions(row)}/>
52
- {#if row == expandRow}
53
- <div class="inline-panel" style="height: {inlineRowHeight??0}px">
54
- </div>
55
- {/if}
56
- {/each}
50
+ <div>
51
+ {#each rows as row, idx}
52
+ <ActionsRow {row} {rowHeight} parentRect={rect} alternative={idx % 2 == 1} width={actionsColumn.width}
53
+ actions={actionsColumn.getActions(row.data)}/>
54
+ {#if row == expandRow}
55
+ <div class="inline-panel" style="height: {inlineRowHeight??0}px">
56
+ </div>
57
+ {/if}
58
+ {/each}
59
+ </div>
57
60
  </div>
58
61
  <div class="bottom-mask-overlay">
59
62
  <!-- 用于匹配中间数据区域的滚动条 -->
@@ -27,7 +27,7 @@
27
27
 
28
28
  $: if (row.selected != selected) {
29
29
  row.selected = selected;
30
- handleRowSelectChange(row.selected);
30
+ handleRowSelectChange(row);
31
31
  }
32
32
 
33
33
  $: style = rowHeight== null ? '' : `height: ${rowHeight}px`
@@ -4,7 +4,7 @@
4
4
  import dayjs from "dayjs";
5
5
  import type {OnChangeHandler} from "../common/OnChangeHandler";
6
6
  import type {UniDate} from "../base-calendar/dateUtils";
7
- import {dateUtils} from "../../lib/base-calendar";
7
+ import dateUtils from "../base-calendar/dateUtils";
8
8
 
9
9
  export let value: UniDate;
10
10
  export let style: string = '';
@@ -41,7 +41,7 @@
41
41
 
42
42
  </script>
43
43
  <CommonEditor {displayMode} {style} {value} {suffix} {prefix} {readonly} {disabled} {variant} {compact}
44
- showActionIcon={!readonly && !disabled && removable && value?.length > 0}
44
+ showActionIcon={!readonly && !disabled && removable && value?.length > 0} placeholder={input$['placeholder']}
45
45
  class={className} clean={clean}>
46
46
  <svelte:fragment slot="leading-icon">
47
47
  {#if $$slots['leading-icon']}
@@ -203,6 +203,9 @@
203
203
  --uniface-context-menu-box-shadow: rgba(60, 64, 67, 0.3) 0px 1px 2px 0px, rgba(60, 64, 67, 0.15) 0px 2px 6px 2px;
204
204
  }
205
205
 
206
+ .uniface-common-picker {
207
+ padding: 0 8px;
208
+ }
206
209
  .uniface-common-picker .editor-dropdown {
207
210
  visibility: hidden;
208
211
  margin-left: 8px;
@@ -213,7 +216,6 @@
213
216
  font-size: 18px;
214
217
  color: var(--uniface-editor-text-color, #374151);
215
218
  align-self: center;
216
- margin-right: 4px;
217
219
  cursor: pointer;
218
220
  }
219
221
  .uniface-common-picker .action-icon:active {
@@ -3632,6 +3634,11 @@
3632
3634
  flex-wrap: nowrap;
3633
3635
  flex-direction: row;
3634
3636
  align-items: center;
3637
+ background-color: var(--uniface-data-table-background-color, #ffffff);
3638
+ height: 36px;
3639
+ }
3640
+ .uniface-data-table .table-row.alternative {
3641
+ background-color: var(--uniface-data-table-background-color, #f7f7f7);
3635
3642
  }
3636
3643
  .uniface-data-table.row-border .table-row {
3637
3644
  border-bottom: 1px solid var(--uniface-data-table-row-border-color, #f0f0f0);
@@ -50,3 +50,11 @@ export interface LazyLoader {
50
50
  */
51
51
  load: LoadChildrenFun;
52
52
  }
53
+ /**
54
+ * 判断是否是根节点
55
+ */
56
+ export type RootDetermine = (item: any) => boolean;
57
+ /**
58
+ * 层级排序
59
+ */
60
+ export type NodeLevelCompare = (e1: any, e2: any) => number;
@@ -1,10 +1,6 @@
1
1
  import type TreeNode from "./TreeNode";
2
- /**
3
- * 把数组构建成一棵树
4
- * @param arr
5
- * @param keyField
6
- * @param textField
7
- * @param parentField
8
- * @param rootParentCode
9
- */
10
- export declare const buildTree: (arr: Array<any>, keyField: string, textField: string, parentField: string, rootParentCode?: string | null) => Array<TreeNode>;
2
+ import type { NodeLevelCompare, RootDetermine } from "./TreeNode";
3
+ declare const _default: {
4
+ buildTreeNode: (list: Array<any>, idKey: string, joinKey: string, textField: string, valueField?: string, isRoot?: RootDetermine, sortFun?: NodeLevelCompare) => Array<TreeNode>;
5
+ };
6
+ export default _default;
@@ -1,36 +1,53 @@
1
1
  /**
2
- *
3
- * @param data
4
- * @param keyField
5
- * @param textField
6
- * @param parentField
7
- * @param parentCode
8
- * @param parent
2
+ * 将一个数组转换成树状结构
3
+ * @param list 待转换的数组
4
+ * @param idKey 元素的主键
5
+ * @param joinKey 父子间连接字段
6
+ * @param valueField 取值的字段
7
+ * @param textField 显示文字的字段
8
+ * @param isRoot 判断是否是根节点,如果函数不存在,通过连接字段查询,无法获取到父节点就是根节点
9
+ * @param sortFun 比较函数,用于曾经排序
9
10
  */
10
- const convertArrayToTree = (data, keyField, textField, parentField, parentCode = null, parent = null) => {
11
+ const buildTreeNode = (list, idKey, joinKey, textField, valueField, isRoot, sortFun) => {
12
+ if (sortFun != null) {
13
+ list = list.sort(sortFun);
14
+ }
11
15
  let nodes = [];
12
- for (let i = 0; i < data.length; i++) {
13
- let pCode = data[i][parentField];
14
- if ((parentCode == null && pCode == null) || (pCode == parentCode)) {
15
- let code = data[i][keyField];
16
- let node = { value: code, text: data[i][textField], data: data[i], parent };
17
- let children = convertArrayToTree(data, keyField, textField, parentField, code, node);
18
- if (children.length > 0) {
19
- node.children = children;
16
+ let map = new Map();
17
+ list.forEach(item => {
18
+ let node = { value: item[valueField ?? idKey], text: item[textField], data: item };
19
+ if (isRoot != null) {
20
+ if (isRoot(item)) {
21
+ nodes.push(node);
22
+ map.set(item[idKey], node);
23
+ }
24
+ else {
25
+ let parent = map.get(item[joinKey]);
26
+ if (parent != null) {
27
+ parent.children = [...parent.children, node];
28
+ node.parent = parent;
29
+ map.set(item[idKey], node);
30
+ }
31
+ else {
32
+ console.warn('Isolated node:', item);
33
+ }
20
34
  }
21
- nodes.push(node);
22
35
  }
23
- }
36
+ else {
37
+ let parent = map.get(item[joinKey]);
38
+ if (parent != null) {
39
+ parent.children = [...parent.children, item];
40
+ node.parent = parent;
41
+ map.set(item[idKey], node);
42
+ }
43
+ else {
44
+ nodes.push(node);
45
+ map.set(item[idKey], node);
46
+ }
47
+ }
48
+ });
24
49
  return nodes;
25
50
  };
26
- /**
27
- * 把数组构建成一棵树
28
- * @param arr
29
- * @param keyField
30
- * @param textField
31
- * @param parentField
32
- * @param rootParentCode
33
- */
34
- export const buildTree = (arr, keyField, textField, parentField, rootParentCode = null) => {
35
- return convertArrayToTree(arr, keyField, textField, parentField, rootParentCode);
51
+ export default {
52
+ buildTreeNode
36
53
  };
@@ -1,7 +1,7 @@
1
1
  import TreeView from "./TreeView.svelte";
2
2
  import type TreeNode from "./TreeNode";
3
- import type { LazyLoader, NodeVisibleFun, OnNodeSelectionChange, CheckBranchFun, LoadChildrenFun } from "./TreeNode";
4
- import { buildTree } from "./TreeUtils";
3
+ import type { LazyLoader, NodeVisibleFun, OnNodeSelectionChange, CheckBranchFun, LoadChildrenFun, NodeLevelCompare, RootDetermine } from "./TreeNode";
4
+ import treeUtils from "./TreeUtils";
5
5
  export default TreeView;
6
- export { buildTree };
7
- export type { TreeNode, LazyLoader, NodeVisibleFun, OnNodeSelectionChange, CheckBranchFun, LoadChildrenFun };
6
+ export { treeUtils };
7
+ export type { TreeNode, LazyLoader, NodeVisibleFun, OnNodeSelectionChange, CheckBranchFun, LoadChildrenFun, NodeLevelCompare, RootDetermine };
@@ -1,4 +1,4 @@
1
1
  import TreeView from "./TreeView.svelte";
2
- import { buildTree } from "./TreeUtils";
2
+ import treeUtils from "./TreeUtils";
3
3
  export default TreeView;
4
- export { buildTree };
4
+ export { treeUtils };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ticatec/uniface-element",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "uniface web elements",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -96,7 +96,7 @@
96
96
  "types": "./dist/checkbox/index.d.ts",
97
97
  "import": "./dist/checkbox/index.js"
98
98
  },
99
- "./FullscreenOverlay": {
99
+ "./FullScreenOverlay": {
100
100
  "types": "./dist/common/FullscreenOverlay.svelte.d.ts",
101
101
  "import": "./dist/common/FullscreenOverlay.svelte"
102
102
  },
@@ -1,5 +0,0 @@
1
- import type { UniDate } from "../calendar/dateUtils";
2
- declare const _default: {
3
- formatDate: (d: UniDate, fmt: string) => string;
4
- };
5
- export default _default;
@@ -1,7 +0,0 @@
1
- import dayjs, { isDayjs } from "dayjs";
2
- const formatDate = (d, fmt) => {
3
- return (d == null) ? '' : isDayjs(d) ? d.format(fmt) : dayjs(d).format(fmt);
4
- };
5
- export default {
6
- formatDate
7
- };