centaline-data-driven-v3 0.1.42 → 0.1.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "centaline-data-driven-v3",
3
- "version": "0.1.42",
3
+ "version": "0.1.43",
4
4
  "private": false,
5
5
  "description": "centaline-data-driven-v3",
6
6
  "main": "dist/centaline-data-driven-v3.umd.js",
@@ -103,6 +103,7 @@ const fullTreeData = ref([])
103
103
  // 新增:缓存所有节点的Map,用于快速查找
104
104
  const nodeCodeMap = ref(new Map())
105
105
 
106
+ const isExpandAll = ref(false);
106
107
  /** 动态设置Input Ref */
107
108
  const handleSetInputMap = (el: refItem, item) => {
108
109
  if (el) {
@@ -118,22 +119,29 @@ onBeforeUnmount(() => {
118
119
  }
119
120
  })
120
121
 
121
- // 递归获取前两级节点的key
122
- function getFirstTwoLevelKeys(nodes, level = 0, result = []) {
123
- if (!nodes || nodes.length === 0 || level >= 1) {
122
+ function getFirstNLevelKeys(nodes, targetLevel = 1) {
123
+ const result = [];
124
+
125
+ if (!nodes || nodes.length === 0 || targetLevel < 0) {
124
126
  return result;
125
127
  }
126
128
 
127
- nodes.forEach(node => {
128
- if (node.code) {
129
- result.push(node.code);
130
- }
129
+ const traverse = (nodes, currentLevel) => {
130
+ if (currentLevel > targetLevel || !nodes) return;
131
131
 
132
- if (level < 1 && node.children && node.children.length > 0) {
133
- getFirstTwoLevelKeys(node.children, level + 1, result);
134
- }
135
- });
132
+ nodes.forEach(node => {
133
+ if (node.code) {
134
+ result.push(node.code);
135
+ }
136
+
137
+ // 如果还有下一层且没超过目标层级,继续遍历
138
+ if (currentLevel < targetLevel && node.children && node.children.length > 0) {
139
+ traverse(node.children, currentLevel + 1);
140
+ }
141
+ });
142
+ };
136
143
 
144
+ traverse(nodes, 0);
137
145
  return result;
138
146
  }
139
147
 
@@ -163,10 +171,36 @@ function setDefaultExpandedNodes() {
163
171
  }
164
172
 
165
173
  if (isSearching.value) {
174
+ isExpandAll.value = true;
166
175
  const allKeys = getAllNodeKeys(fullTreeData.value);
167
176
  defaultExpandedKeys.value = allKeys;
168
177
  } else {
169
- defaultExpandedKeys.value = getFirstTwoLevelKeys(fullTreeData.value);
178
+ isExpandAll.value = false;
179
+ // 检查是否有全展开搜索条件
180
+ const expandValue = findSearchFieldValue(screenPara.value, 'expanded', {
181
+ caseInsensitive: true, // 添加不区分大小写的选项
182
+ keyFields: ['fieldName1', 'groupName', 'fieldLabel'] // 扩展可能的key字段
183
+ });
184
+
185
+ // 如果找到expanded=all的搜索条件,设置全展开
186
+ if (expandValue && expandValue.toString().toLowerCase() === 'all') {
187
+ isExpandAll.value = true;
188
+ const allKeys = getAllNodeKeys(fullTreeData.value);
189
+ defaultExpandedKeys.value = allKeys;
190
+ } else {
191
+ // 处理非'all'的情况
192
+ let expandLevel = 1; // 默认展开级别为1
193
+
194
+ if (expandValue) {
195
+ const numericValue = Number(expandValue);
196
+ if (!isNaN(numericValue) && numericValue > 0) {
197
+ expandLevel = Math.max(0, numericValue - 1); // 减1但最小为1
198
+
199
+ }
200
+ }
201
+
202
+ defaultExpandedKeys.value = getFirstNLevelKeys(fullTreeData.value, expandLevel);
203
+ }
170
204
  }
171
205
 
172
206
  hasSetDefaultExpand.value = true;
@@ -626,8 +660,8 @@ function loadNode(node, resolve) {
626
660
  loading.value = false;
627
661
 
628
662
 
629
- const { tree, hasAnyLeaf } = buildDeptTreeByField(data.rows, data.source.content.columns || [], {
630
- pathKey: 'deptPath',
663
+ const { tree, hasAnyLeaf } = buildDeptTreeByField(data.rows, {
664
+ pathKey: 'path',
631
665
  separator: '.'
632
666
  });
633
667
 
@@ -665,7 +699,7 @@ function loadNode(node, resolve) {
665
699
  ...(screenPara.value?.searchData?.fields || [])
666
700
  ]
667
701
  }
668
- };
702
+ };
669
703
 
670
704
  return SearchTree(filter).then(data => {
671
705
  loading.value = false;
@@ -771,6 +805,7 @@ function clearSearch() {
771
805
 
772
806
  //节点点击事件
773
807
  function handleNodeClick(data, formType) {
808
+
774
809
  closeMenu();
775
810
  if (data && formType) {
776
811
  refTree.value.setCurrentKey(data.code)
@@ -784,6 +819,7 @@ function handleNodeClick(data, formType) {
784
819
  SearchData[v] = data[v];
785
820
  }
786
821
  })
822
+
787
823
  model.value.requestAction(rowRouter.action, SearchData, function (rowdata) {
788
824
  var newdata = common.deepClone(data);
789
825
  delete newdata.children;
@@ -859,8 +895,9 @@ function routerClickHandler(field) {
859
895
 
860
896
  //删除树节点
861
897
  function removeNode(newData) {
862
- getNextClickNode()
898
+ getNextClickNode(currentNode.value)
863
899
  refTree.value.remove(currentNode.value);
900
+
864
901
  }
865
902
 
866
903
  //新增树节点
@@ -882,13 +919,13 @@ function updateNode(newData) {
882
919
  }
883
920
 
884
921
  function getNextClickNode() {
885
- const node = refTree.value.getNode(currentData.value.code);
922
+ const node = refTree.value.getNode((currentData.value.code || currentNode.value.key));
886
923
  let data = {};
887
- if (node.nextSibling) {
924
+ if (node?.nextSibling) {
888
925
  data = node.nextSibling.data;
889
926
  } else if (node.previousSibling) {
890
927
  data = node.previousSibling.data;
891
- } else if (node.parent) {
928
+ } else if (node?.parent) {
892
929
  data = node.parent.data;
893
930
  }
894
931
  handleNodeClick(data, true)
@@ -900,18 +937,17 @@ function filterNode(value, data) {
900
937
  return data.name.toLowerCase().includes(value.toLowerCase())
901
938
  }
902
939
 
903
- function buildDeptTreeByField(flatList, fieldDefine, opt = {}) {
940
+ function buildDeptTreeByField(flatList, opt = {}) {
904
941
  const {
905
942
  pathKey = 'path',
906
943
  separator = '.',
907
- sortKey = 'path'
944
+ sortKey = 'sort'
908
945
  } = opt;
909
946
 
910
- const keepFields = fieldDefine
911
- .filter(f => f.visible && f.isDataField)
912
- .sort((a, b) => a.trOrder - b.trOrder)
913
- .map(f => f.fieldName);
914
-
947
+ // 检查第一行是否有 sort 字段
948
+ const firstItem = flatList.length > 0 ? flatList[0] : null;
949
+ const actualSortKey = firstItem && firstItem.hasOwnProperty(sortKey) ? sortKey : 'path';
950
+
915
951
  const createNode = (tplItem, path) => {
916
952
  const node = { children: [] };
917
953
 
@@ -929,7 +965,6 @@ function buildDeptTreeByField(flatList, fieldDefine, opt = {}) {
929
965
  const nodeMap = new Map();
930
966
 
931
967
  for (const item of flatList) {
932
-
933
968
  if (!item[pathKey]) {
934
969
  break;
935
970
  }
@@ -967,20 +1002,22 @@ function buildDeptTreeByField(flatList, fieldDefine, opt = {}) {
967
1002
  }
968
1003
  }
969
1004
 
1005
+ // 按实际排序键排序子节点
970
1006
  for (const node of nodeMap.values()) {
971
1007
  if (node.children && node.children.length > 0) {
972
1008
  node.children.sort((a, b) => {
973
- const aVal = a[sortKey] || '';
974
- const bVal = b[sortKey] || '';
1009
+ const aVal = a[actualSortKey] || '';
1010
+ const bVal = b[actualSortKey] || '';
975
1011
  return String(aVal).localeCompare(String(bVal));
976
1012
  });
977
1013
  }
978
1014
  node.isLeaf = node.children.length === 0;
979
1015
  }
980
1016
 
1017
+ // 按实际排序键排序根节点
981
1018
  root.sort((a, b) => {
982
- const aVal = a[sortKey] || '';
983
- const bVal = b[sortKey] || '';
1019
+ const aVal = a[actualSortKey] || '';
1020
+ const bVal = b[actualSortKey] || '';
984
1021
  return String(aVal).localeCompare(String(bVal));
985
1022
  });
986
1023
 
@@ -988,6 +1025,38 @@ function buildDeptTreeByField(flatList, fieldDefine, opt = {}) {
988
1025
  return { tree: root, hasAnyLeaf };
989
1026
  }
990
1027
 
1028
+ function findSearchFieldValue(searchFields, targetKey, options = {}) {
1029
+ const {
1030
+ keyFields = ['fieldName1', 'groupName'], // 要查找的key字段列表
1031
+ valueField = 'searchValue1', // 要返回值的字段
1032
+ defaultValue = 2
1033
+ } = options;
1034
+
1035
+ // 检查数据结构
1036
+ if (!searchFields?.searchData?.fields?.length) {
1037
+ return defaultValue;
1038
+ }
1039
+
1040
+ // 遍历fields数组
1041
+ for (const field of searchFields.searchData.fields) {
1042
+ // 检查所有可能的key字段
1043
+ for (const keyField of keyFields) {
1044
+ if (field[keyField] === targetKey) {
1045
+ // 找到了匹配的key,返回对应的值
1046
+ const value = field[valueField];
1047
+ // 如果值为undefined、null或空字符串,返回默认值
1048
+ return value !== undefined && value !== null && value !== ''
1049
+ ? value
1050
+ : defaultValue;
1051
+ }
1052
+ }
1053
+ }
1054
+
1055
+ return defaultValue;
1056
+ }
1057
+
1058
+
1059
+
991
1060
  // 暴露方法
992
1061
  defineExpose({
993
1062
  search,