@gingkoo/pandora-metabase 1.0.0-alpha.2 → 1.0.0-alpha.21

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/lib/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @gingkoo/pandora-metabase v1.0.0-alpha.2
2
+ * @gingkoo/pandora-metabase v1.0.0-alpha.21
3
3
  */
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import * as React from 'react';
@@ -8,12 +8,12 @@ import cloneDeep from 'lodash/cloneDeep';
8
8
  import cx from 'classnames';
9
9
  import { Tooltip, Button, Modal, Input, DatePicker, Dropdown, InputNumber, Select, Modal2, Toast } from '@gingkoo/pandora';
10
10
  import Styled from 'styled-components';
11
+ import { ChevronODown, Repeat, Function, RelatedWork, FfPlus, FfLine } from '@gingkoo/pandora-icons';
12
+ import isEqual from 'lodash/isEqual';
11
13
  import 'underscore';
12
14
  import ReactDOM from 'react-dom';
13
15
  import ReactDOMServer from 'react-dom/server';
14
- import { ChevronODown, Repeat, Function, RelatedWork, FfPlus, FfLine } from '@gingkoo/pandora-icons';
15
16
  import moment from 'dayjs';
16
- import isEqual from 'lodash/isEqual';
17
17
 
18
18
  // 创建 Context
19
19
  const Context = /*#__PURE__*/createContext({});
@@ -89,7 +89,7 @@ var TypeEnum;
89
89
  TypeEnum["summarize"] = "summarize";
90
90
  TypeEnum["sort"] = "sort";
91
91
  TypeEnum["rowLimit"] = "rowLimit";
92
- TypeEnum["group"] = "group";
92
+ TypeEnum["union"] = "union";
93
93
  })(TypeEnum || (TypeEnum = {}));
94
94
  var JoinEnum;
95
95
  (function (JoinEnum) {
@@ -278,7 +278,6 @@ const summarizeToSql = (arr, record) => {
278
278
  condition,
279
279
  alias,
280
280
  name,
281
- fieldAlias,
282
281
  realName = ''
283
282
  } = record;
284
283
  let index = arr.indexOf(record);
@@ -339,9 +338,10 @@ const summarizeToSql = (arr, record) => {
339
338
  count++;
340
339
  }
341
340
  });
342
- as = fieldAlias || as + (count ? '_' + (count + 1) : '');
341
+ as = as + (count ? '_' + (count + 1) : '');
343
342
  return {
344
- sql: sql + ' AS ' + as,
343
+ sql: sql,
344
+ // + ' AS ' + as,
345
345
  fieldAlias: as
346
346
  };
347
347
  };
@@ -467,15 +467,15 @@ const handleNesting = data => {
467
467
  if (customColumn && customColumn.customColumn.length) {
468
468
  obj.customColumns = customColumn.customColumn.map(v => {
469
469
  return {
470
- alias: v.name,
471
- formula: v.formula.replace(/\[.*?\]/g, column => {
472
- let str = column.substr(1, column.length - 2);
473
- if (~str.indexOf('->')) {
474
- let _str = str.replace(/ /g, '').split('->');
475
- return `${_str[0]}.${_str[1]}`;
476
- }
477
- return str;
478
- })
470
+ alias: v.name
471
+ // formula: v.formula.replace(/\[.*?\]/g, (column: string): string => {
472
+ // let str = column.substr(1, column.length - 2);
473
+ // if (~str.indexOf('->')) {
474
+ // let _str = str.replace(/ /g, '').split('->');
475
+ // return `${_str[0]}.${_str[1]}`;
476
+ // }
477
+ // return str;
478
+ // }),
479
479
  };
480
480
  });
481
481
  }
@@ -626,9 +626,8 @@ const getSubColumns = metaList => {
626
626
  metaKey: -1,
627
627
  type: TypeEnum.customColumn,
628
628
  customColumn: [{
629
- name: '',
630
- // 用户起的别名
631
- formula: '' // 公式}];
629
+ name: '' // 用户起的别名
630
+ // formula: '', // 公式}];
632
631
  }]
633
632
  };
634
633
  let {
@@ -650,7 +649,7 @@ const getSubColumns = metaList => {
650
649
  return {
651
650
  name_zh: v.quotes,
652
651
  ...v,
653
- name: v.quotes,
652
+ name: v.fieldAlias,
654
653
  realName: v.sql?.split(' AS ')?.[1] || '',
655
654
  // name_zh: '',
656
655
  database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
@@ -664,7 +663,7 @@ const getSubColumns = metaList => {
664
663
  return {
665
664
  name_zh: v.quotes,
666
665
  ...v,
667
- name: v.quotes,
666
+ name: v.fieldAlias,
668
667
  realName: v.sql?.split(' AS ')?.[1] || '',
669
668
  // name_zh: '',
670
669
  database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
@@ -726,18 +725,25 @@ const changeTableAlias = (list, curObj) => {
726
725
  alias
727
726
  } = cloneDeep(curObj);
728
727
  const newList = cloneDeep(list);
729
- newList.map(v => {
730
- if (v.type === TypeEnum.data) ;
728
+ newList?.map(v => {
729
+ if (v.type === TypeEnum.data) {
730
+ if (v.table.tableUuid === tableUuid) {
731
+ v.table.alias = alias;
732
+ }
733
+ }
731
734
  if (v.type === TypeEnum.joinData) {
732
735
  if (v.table1.tableUuid === tableUuid) {
733
736
  v.table1.alias = alias;
734
737
  }
738
+ if (v.table2.tableUuid === tableUuid) {
739
+ v.table2.alias = alias;
740
+ }
735
741
  }
736
742
  if (v.type === TypeEnum.customColumn) {
737
743
  v.customColumn.map(item => {
738
744
  item.formulaList?.map(formula => {
739
- if (formula.tableUuid === tableUuid) {
740
- formula.alias = alias;
745
+ if (formula.expression && formula.expression.tableUuid === tableUuid) {
746
+ formula.expression.alias = alias;
741
747
  }
742
748
  });
743
749
  });
@@ -775,27 +781,48 @@ const changeTableAlias = (list, curObj) => {
775
781
  if (v.type === TypeEnum.filter) {
776
782
  v.filter.map(item => {
777
783
  if (item.tableUuid === tableUuid) {
778
- if (item.alias === SummarizeAlias$1) {
779
- //有groupBy 特殊处理
780
- const {
781
- prevGroupBy
782
- } = getHelper(list, v);
783
- let groupBy = prevGroupBy?.by.filter(v => v.fieldUuid === item.fieldUuid)[0] || prevGroupBy?.group.filter(v => v.fieldUuid === item.fieldUuid)[0] || null;
784
- groupBy.alias = alias;
785
- const sql = groupBy.sql;
786
- if (groupBy) {
787
- item.sql = sql;
788
- item.groupSql = sql;
789
- }
790
- } else {
791
- item.alias = alias;
792
- item.sql = '';
793
- }
784
+ // if (item.alias === SummarizeAlias) {
785
+ // //有groupBy 特殊处理
786
+ // const { prevGroupBy } = getHelper(list, v);
787
+ // let groupBy: any =
788
+ // prevGroupBy?.by.filter((v) => v.fieldUuid === item.fieldUuid)[0] ||
789
+ // prevGroupBy?.group.filter((v) => v.fieldUuid === item.fieldUuid)[0] ||
790
+ // null;
791
+ // groupBy.alias = alias;
792
+ // const sql = groupBy.sql;
793
+ // if (groupBy) {
794
+ // item.sql = sql;
795
+ // item.groupSql = sql;
796
+ // }
797
+ // }
798
+ item.alias = alias;
799
+ item.sql = '';
800
+ }
801
+ if (item.table2 && item.table2.tableUuid === tableUuid) {
802
+ // if (item.table2.alias === SummarizeAlias) {
803
+ // //有groupBy 特殊处理
804
+ // const { prevGroupBy } = getHelper(list, v);
805
+ // let groupBy: any =
806
+ // prevGroupBy?.by.filter((v) => v.fieldUuid === item.table2?.fieldUuid)[0] ||
807
+ // prevGroupBy?.group.filter((v) => v.fieldUuid === item.table2?.fieldUuid)[0] ||
808
+ // null;
809
+ // groupBy.alias = alias;
810
+ // const sql = groupBy.sql;
811
+ // if (groupBy) {
812
+ // item.table2.sql = sql;
813
+ // item.table2.groupSql = sql;
814
+ // }
815
+ // }
816
+ item.table2.alias = alias;
817
+ // item.table2.sql = '';
794
818
  }
795
819
  });
796
820
  }
821
+ if (v.subquery) {
822
+ v.subquery = changeTableAlias(v.subquery || [], curObj);
823
+ }
797
824
  });
798
- return newList;
825
+ return newList || [];
799
826
  };
800
827
  const changeFieldAlias = (list, curObj) => {
801
828
  const {
@@ -805,12 +832,30 @@ const changeFieldAlias = (list, curObj) => {
805
832
  const newList = cloneDeep(list);
806
833
  newList.map(v => {
807
834
  if (v.type === TypeEnum.data) ;
808
- if (v.type === TypeEnum.joinData) ;
835
+ if (v.type === TypeEnum.joinData) {
836
+ if (v.table1.fieldUuid === fieldUuid) {
837
+ v.table1.fieldAlias = fieldAlias;
838
+ }
839
+ if (v.table2.fieldUuid === fieldUuid) {
840
+ v.table2.fieldAlias = fieldAlias;
841
+ }
842
+ v.expressions.map(column => {
843
+ if (column.left_fieldUuid === fieldUuid) {
844
+ column.left_fieldAlias = fieldAlias;
845
+ }
846
+ if (column.right_fieldUuid === fieldUuid) {
847
+ column.right_fieldAlias = fieldAlias;
848
+ }
849
+ });
850
+ // if (v.table1.tableUuid === tableUuid) {
851
+ // v.table1.alias = alias;
852
+ // }
853
+ }
809
854
  if (v.type === TypeEnum.customColumn) {
810
855
  v.customColumn.map(item => {
811
856
  item.formulaList?.map(formula => {
812
- if (formula.fieldUuid === fieldUuid) {
813
- formula.fieldAlias = fieldAlias;
857
+ if (formula.expression && formula.expression.fieldUuid === fieldUuid) {
858
+ formula.expression.fieldAlias = fieldAlias;
814
859
  }
815
860
  });
816
861
  });
@@ -864,11 +909,196 @@ const changeFieldAlias = (list, curObj) => {
864
909
  }
865
910
  }
866
911
  }
912
+ if (item.table2 && item.table2.fieldUuid === fieldUuid) {
913
+ item.table2.fieldAlias = fieldAlias;
914
+ // if (item.table2.alias === SummarizeAlias) {
915
+ // //有groupBy 特殊处理
916
+ // const { prevGroupBy } = getHelper(list, v);
917
+ // let groupBy: any =
918
+ // prevGroupBy?.by.filter((v) => v.fieldUuid === item.table2?.fieldUuid)[0] ||
919
+ // prevGroupBy?.group.filter((v) => v.fieldUuid === item.table2?.fieldUuid)[0] ||
920
+ // null;
921
+ // groupBy.fieldAlias = fieldAlias;
922
+ // const sql = groupBy.sql;
923
+ // if (groupBy) {
924
+ // item.table2.sql = sql;
925
+ // item.table2.groupSql = sql;
926
+ // }
927
+ // }
928
+ }
867
929
  });
868
930
  }
869
931
  });
870
932
  return newList;
871
933
  };
934
+ function splitByUnion(data) {
935
+ if (!data) return [];
936
+ const original = cloneDeep(data);
937
+ const result = [];
938
+ let i = 0;
939
+ while (i < original.length) {
940
+ const item = original[i];
941
+ if (item.type === 'group') {
942
+ // group.list 中每一项原样推入结果
943
+ for (const subItem of item.list) {
944
+ result.push(subItem);
945
+ }
946
+ i++;
947
+ } else if (item.type === 'union') {
948
+ const {
949
+ list,
950
+ ...otehr
951
+ } = item;
952
+ // 查找下一个 group,并将其 list 转成 subquery
953
+ const nextItem = original[i + 1];
954
+ if (nextItem && nextItem.type === 'group') {
955
+ result.push({
956
+ ...otehr,
957
+ subquery: nextItem.list.map(subItem => subItem)
958
+ });
959
+ i += 2;
960
+ } else {
961
+ result.push({
962
+ ...otehr,
963
+ subquery: []
964
+ });
965
+ i++;
966
+ }
967
+ }
968
+ }
969
+ return result;
970
+ }
971
+ function reassembleByUnion(target = []) {
972
+ if (!target) return [];
973
+ const result = [];
974
+ let i = 0;
975
+ const len = target.length;
976
+ // 如果没有任何 union,直接放入一个 group.list
977
+ const hasUnion = target.some(item => item.type === 'union');
978
+ if (!hasUnion) {
979
+ return [{
980
+ type: 'group',
981
+ name: 'default',
982
+ list: [...target]
983
+ }];
984
+ }
985
+ // 否则正常处理
986
+ while (i < len) {
987
+ const item = target[i];
988
+ if (item.type !== 'union') {
989
+ // 收集连续非 union 的 item,统一放入一个 group.list
990
+ const groupList = [];
991
+ while (i < len && target[i].type !== 'union') {
992
+ groupList.push(target[i]);
993
+ i++;
994
+ }
995
+ result.push({
996
+ type: 'group',
997
+ name: 'default',
998
+ list: groupList
999
+ });
1000
+ } else {
1001
+ // 处理 union
1002
+ result.push({
1003
+ type: 'union',
1004
+ name: 'union',
1005
+ union: item.union ?? 'UNION',
1006
+ list: []
1007
+ });
1008
+ const subquery = item.subquery || [];
1009
+ const convertedSubquery = reassembleByUnion(subquery);
1010
+ result.push(...convertedSubquery);
1011
+ i++; // 跳过当前 union
1012
+ }
1013
+ }
1014
+ return result;
1015
+ }
1016
+ // export const buildSqlQuery = (data?: MetaListType[]): string => {
1017
+ // if (!data || data.length === 0) return '';
1018
+ // let sqlClauses: string[] = ['not exitis ( '];
1019
+ // data.forEach((item) => {
1020
+ // if (item.type === TypeEnum.data) {
1021
+ // const meta = item as MetaData;
1022
+ // const tableName = meta.table.name;
1023
+ // const alias = meta.table.alias ? `AS ${meta.table.alias}` : '';
1024
+ // const dataSource = meta.table.datasourceName;
1025
+ // sqlClauses.push(`SELECT 1 FROM ${dataSource}.${tableName} ${alias}`);
1026
+ // }
1027
+ // if (item.type === TypeEnum.joinData) {
1028
+ // const meta = item as MetaJoin;
1029
+ // const table1 = meta.table1.alias ? meta.table1.alias : meta.table1.name;
1030
+ // const table2 = `${meta.table2.datasourceName}.${meta.table2.name}`;
1031
+ // const alias2 = meta.table2.alias ? meta.table2.alias : '';
1032
+ // joins.push(`LEFT JOIN ${table2} ${alias2} ON ${table1}.${meta.columns[0]?.name} = ${alias2}.${meta.columns[0]?.name}`);
1033
+ // }
1034
+ // if (item.type === TypeEnum.filter) {
1035
+ // const filterStrings = (item as MetaFilter).filter.map((f) => f.quotes).filter(Boolean); // 排除空条件
1036
+ // if (filterStrings.length > 0) {
1037
+ // sqlClauses.push(`WHERE ${filterStrings.join(' AND ')}`);
1038
+ // }
1039
+ // }
1040
+ // });
1041
+ // // 简单拼接 SQL 片段
1042
+ // return sqlClauses.join(' ') + ' )' + ';';
1043
+ // };
1044
+ const buildSqlQuery = data => {
1045
+ if (!data || data.length === 0) return '';
1046
+ let sqlClauses = ['NOT EXISTS ('];
1047
+ let tables = [];
1048
+ let joins = [];
1049
+ let wheres = [];
1050
+ data.forEach(item => {
1051
+ if (item.type === TypeEnum.data) {
1052
+ const meta = item;
1053
+ const tableName = `${meta.table.name}`;
1054
+ const alias = meta.table.alias ? ` AS ${meta.table.alias}` : '';
1055
+ tables.push(`${tableName}${alias}`);
1056
+ }
1057
+ if (item.type === TypeEnum.joinData) {
1058
+ const meta = item;
1059
+ const table2Name = `${meta.table2.name}`;
1060
+ const alias2 = meta.table2.alias ? ` AS ${meta.table2.alias}` : '';
1061
+ const table2 = `${meta.table2.alias || meta.table2.name}`;
1062
+ const table1 = `${meta.table1.alias || meta.table1.name}`;
1063
+ joins.push(`LEFT JOIN ${table2Name}${alias2} ON ${table1}.${meta.table1.fieldAlias} = ${table2}.${meta.table2.fieldAlias}`);
1064
+ if (Array.isArray(item.expressions) && item.expressions.length > 0) {
1065
+ item.expressions.forEach(expression => {
1066
+ let left = '',
1067
+ right = '';
1068
+ if (expression.left_type === 'field') {
1069
+ left = `${table1}.${expression.left_fieldAlias}`;
1070
+ } else {
1071
+ left = expression.left_string;
1072
+ }
1073
+ if (expression.right_type === 'field') {
1074
+ right = `${table2}.${expression.right_fieldAlias}`;
1075
+ } else {
1076
+ right = expression.right_string;
1077
+ }
1078
+ joins.push(`AND ${left} = ${right}`);
1079
+ });
1080
+ }
1081
+ }
1082
+ if (item.type === TypeEnum.filter) {
1083
+ const filterStrings = item.filter.map(f => f.quotes).filter(Boolean);
1084
+ if (filterStrings.length > 0) {
1085
+ wheres.push(...filterStrings);
1086
+ }
1087
+ }
1088
+ });
1089
+ // 构建子查询
1090
+ if (tables.length > 0) {
1091
+ sqlClauses.push(`SELECT 1 FROM ${tables[0]}`);
1092
+ if (joins.length > 0) {
1093
+ sqlClauses.push(joins.join(' '));
1094
+ }
1095
+ if (wheres.length > 0) {
1096
+ sqlClauses.push(`WHERE ${wheres.join(' AND ')}`);
1097
+ }
1098
+ }
1099
+ sqlClauses.push(')');
1100
+ return sqlClauses.join(' ') + ';';
1101
+ };
872
1102
 
873
1103
  let metaKey = 1;
874
1104
  const SummarizeAlias = 'source';
@@ -893,9 +1123,9 @@ const useStore = () => {
893
1123
  list: defaultMetaList
894
1124
  }];
895
1125
  const defaultOperator = {
896
- type: 'group',
897
- name: 'group',
898
- operator: UnionEnum.union,
1126
+ type: 'union',
1127
+ name: 'union',
1128
+ union: UnionEnum.union,
899
1129
  list: []
900
1130
  };
901
1131
  const [showFields, setShowFields] = useState(true); //显示字段
@@ -921,6 +1151,8 @@ const useStore = () => {
921
1151
  }); //弹窗
922
1152
  const [popupClosable, setClosable] = useState(true); //是否可关闭 如果弹框里面再弹框 则不可关闭
923
1153
  const [popupClosable2, setClosable2] = useState(true); //是否可关闭 如果弹框里面再弹框 则不可关闭
1154
+ // 外层ref
1155
+ const popupContainer = useRef();
924
1156
  // const [fetchDatasetFn, setFetchDatasetFn] = useState<(id: string) => Promise<any>>(
925
1157
  // async () => {},
926
1158
  // ); //fn
@@ -938,18 +1170,18 @@ const useStore = () => {
938
1170
  };
939
1171
  // 是否显示主表后面的字段按钮 (如果下面 没有聚合,或者选了聚合但是聚合里面没有选值的时候显示 主表字段按钮)
940
1172
  const showMainColumn = useMemo(() => {
941
- // 先将二维数组拍平为一维数组
942
- const flatMetaList = metaList.flatMap(group => group.list);
943
- // 过滤出所有汇总类型的项
944
- const summarizeItems = flatMetaList.filter(v => v.type === TypeEnum.summarize);
945
- // 如果没有汇总项,默认显示主列
946
- if (summarizeItems.length === 0) {
947
- return true;
948
- }
949
- // 如果只有一个汇总项,并且 group 和 by 都为空,则也显示主列
950
- const onlyItem = summarizeItems[0];
951
- const hasGroupOrBy = Array.isArray(onlyItem.group) && onlyItem.group.length > 0 || Array.isArray(onlyItem.by) && onlyItem.by.length > 0;
952
- return !hasGroupOrBy;
1173
+ return metaList?.map((item, groupIndex) => {
1174
+ // 过滤出所有汇总类型的项
1175
+ const summarizeItems = item.list.filter(v => v.type === TypeEnum.summarize);
1176
+ // 如果没有汇总项,默认显示主列
1177
+ if (summarizeItems.length === 0) {
1178
+ return true;
1179
+ }
1180
+ // 如果只有一个汇总项,并且 group 和 by 都为空,则也显示主列
1181
+ const onlyItem = summarizeItems[0];
1182
+ const hasGroupOrBy = Array.isArray(onlyItem.group) && onlyItem.group.length > 0 || Array.isArray(onlyItem.by) && onlyItem.by.length > 0;
1183
+ return !hasGroupOrBy;
1184
+ });
953
1185
  }, [metaList]);
954
1186
  // const showMainColumn = useMemo(() => {
955
1187
  // let summarizeList = metaList.filter((v) => v.type === TypeEnum.summarize);
@@ -993,7 +1225,7 @@ const useStore = () => {
993
1225
  columns = await fetchColumnsFn.current(extra, datasourceId);
994
1226
  setColumns(tableName, columns);
995
1227
  }
996
- const _columns = columns.map(v => {
1228
+ const _columns = columns?.map(v => {
997
1229
  return {
998
1230
  ...v,
999
1231
  fieldUuid: v.fieldAlias || uuidv4('field')
@@ -1007,21 +1239,56 @@ const useStore = () => {
1007
1239
  _setMeta(newMeta);
1008
1240
  };
1009
1241
  // 回显
1010
- const setPreData = async data => {
1242
+ // 设置column
1243
+ const setQuotes = newMeta => {
1244
+ newMeta.table1 = {
1245
+ ...newMeta.table1,
1246
+ fieldAlias: newMeta.table1.fieldAlias || newMeta.table1.column,
1247
+ fieldUuid: newMeta.table1.fieldUuid || uuidv4('field'),
1248
+ quotes: newMeta.table1.quotes || newMeta.table1.column,
1249
+ tableUuid: newMeta.table1.tableUuid || uuidv4('table')
1250
+ };
1251
+ newMeta.table2 = {
1252
+ ...newMeta.table2,
1253
+ fieldAlias: newMeta.table2.fieldAlias || newMeta.table2.column,
1254
+ fieldUuid: newMeta.table2.fieldUuid || uuidv4('field'),
1255
+ quotes: newMeta.table2.quotes || newMeta.table2.column,
1256
+ tableUuid: newMeta.table2.tableUuid || uuidv4('table')
1257
+ };
1258
+ newMeta.expressions = newMeta.expressions?.map(v => {
1259
+ return {
1260
+ ...v,
1261
+ left_fieldAlias: v.left_fieldAlias || v.left_column,
1262
+ left_fieldUuid: v.left_fieldUuid || uuidv4('field'),
1263
+ left_quotes: v.left_quotes || v.left_column,
1264
+ right_fieldAlias: v.right_fieldAlias || v.right_column,
1265
+ right_fieldUuid: v.right_fieldUuid || uuidv4('field'),
1266
+ right_quotes: v.right_quotes || v.right_column
1267
+ };
1268
+ });
1269
+ return newMeta;
1270
+ };
1271
+ const setPreData = data => {
1011
1272
  if (data.length) {
1012
- let _metaList = data.map((item, groupIndex) => {
1273
+ let _metaList = data?.map((item, groupIndex) => {
1013
1274
  let newList = item.list?.map((v, i) => {
1014
- let newMeta = cloneDeep(item.list);
1275
+ let newMeta = item.list;
1276
+ if (v.table) {
1277
+ v.table.tableUuid = v.table.tableUuid || uuidv4('table');
1278
+ }
1279
+ if (v.type === TypeEnum.joinData) {
1280
+ newMeta[i] = setQuotes(newMeta[i]);
1281
+ }
1015
1282
  // 设置右侧column
1016
1283
  if (v.table2?.datasourceId && v.columns.length < 1) {
1017
- fetchColumns(newMeta[i].table2, newMeta[i].table2.datasourceId, columns => {
1284
+ fetchColumns(newMeta[i].table2, newMeta[i].table2.datasourceId, (columns = []) => {
1018
1285
  if (v.isSubquery) {
1019
1286
  let newColumns = [];
1020
1287
  const items = getSubColumns(v.subquery);
1021
- newColumns = items.flatMap(item => item.columns);
1022
- newMeta[i].columns = newColumns;
1288
+ newColumns = items?.flatMap(item => item.columns);
1289
+ newMeta[i].columns = newColumns || [];
1023
1290
  } else {
1024
- newMeta[i].columns = columns;
1291
+ newMeta[i].columns = columns || [];
1025
1292
  }
1026
1293
  setMeta(newMeta, groupIndex);
1027
1294
  });
@@ -1031,15 +1298,18 @@ const useStore = () => {
1031
1298
  }
1032
1299
  // 设置column
1033
1300
  if (v.table?.datasourceId && v.columns.length < 1) {
1034
- fetchColumns(newMeta[i].table, newMeta[i].table.datasourceId, columns => {
1301
+ fetchColumns(newMeta[i].table, newMeta[i].table.datasourceId, (columns = []) => {
1035
1302
  if (v.isSubquery) {
1036
1303
  let newColumns = [];
1037
1304
  const items = getSubColumns(v.subquery);
1038
1305
  newColumns = items.flatMap(item => item.columns);
1039
- newMeta[i].columns = newColumns;
1306
+ newMeta[i].columns = newColumns || [];
1040
1307
  } else {
1041
- newMeta[i].columns = columns;
1308
+ newMeta[i].columns = columns || [];
1042
1309
  }
1310
+ // if (v.type === TypeEnum.joinData) {
1311
+ // newMeta[i] = setQuotes(newMeta[i]);
1312
+ // }
1043
1313
  setMeta(newMeta, groupIndex);
1044
1314
  });
1045
1315
  return {
@@ -1053,7 +1323,8 @@ const useStore = () => {
1053
1323
  return {
1054
1324
  name: item.name || 'default',
1055
1325
  list: newList.length < 1 ? defaultMetaList : newList,
1056
- type: item.type || 'group'
1326
+ type: item.type || 'group',
1327
+ union: item.union
1057
1328
  };
1058
1329
  });
1059
1330
  const validMetaKeys = _metaList.flatMap(group => group.list).map(v => Number(v.metaKey)).filter(num => !isNaN(num));
@@ -1076,8 +1347,8 @@ const useStore = () => {
1076
1347
  tableUuid: '',
1077
1348
  datasourceId: '',
1078
1349
  datasourceName: '',
1079
- column: '',
1080
- column_id: ''
1350
+ fieldAlias: '',
1351
+ fieldUuid: ''
1081
1352
  };
1082
1353
  if (index === 1) {
1083
1354
  table1 = {
@@ -1086,8 +1357,8 @@ const useStore = () => {
1086
1357
  alias: mainTable.table.alias,
1087
1358
  datasourceId: mainTable.table.datasourceId,
1088
1359
  datasourceName: mainTable.table.datasourceName,
1089
- column: '',
1090
- column_id: ''
1360
+ fieldAlias: '',
1361
+ fieldUuid: ''
1091
1362
  };
1092
1363
  }
1093
1364
  item = {
@@ -1102,8 +1373,8 @@ const useStore = () => {
1102
1373
  tableUuid: '',
1103
1374
  datasourceId: '',
1104
1375
  datasourceName: '',
1105
- column: '',
1106
- column_id: ''
1376
+ fieldAlias: '',
1377
+ fieldUuid: ''
1107
1378
  },
1108
1379
  columns: [],
1109
1380
  expressions: []
@@ -1161,7 +1432,7 @@ const useStore = () => {
1161
1432
  }
1162
1433
  };
1163
1434
  }
1164
- if (type === TypeEnum.group) {
1435
+ if (type === TypeEnum.union) {
1165
1436
  // 添加分组
1166
1437
  let newMetaList = metaList.slice();
1167
1438
  newMetaList.splice(groupIndex + 1, 0, defaultOperator, ...defaultMeta);
@@ -1212,7 +1483,7 @@ const useStore = () => {
1212
1483
  setMeta(_metaList, groupIndex);
1213
1484
  };
1214
1485
  const setColumns = (tableId, columns) => {
1215
- const _columns = columns.map(v => {
1486
+ const _columns = columns?.map(v => {
1216
1487
  return {
1217
1488
  ...v,
1218
1489
  fieldUuid: v.fieldUuid || uuidv4('field')
@@ -1237,46 +1508,10 @@ const useStore = () => {
1237
1508
  const getDataset = datasourceId => {
1238
1509
  return _cacheSource2TableMap[datasourceId] || [];
1239
1510
  };
1240
- const changeAlias = (groupIndex, alias) => {
1241
- let newMetaList = metaList.slice();
1242
- const _list = newMetaList[groupIndex].list;
1243
- if (_list.length > 0) {
1244
- _list.forEach(item => {
1245
- if (item.type === TypeEnum.joinData && item.table2.alias === alias) {
1246
- item.table2.alias = alias;
1247
- } else if (item.type === TypeEnum.data && item.table.alias === alias) {
1248
- item.table.alias = alias;
1249
- } else if (item.type === TypeEnum.filter) {
1250
- //过滤器
1251
- item.filter.forEach(filterItem => {
1252
- if (filterItem.alias === alias) {
1253
- filterItem.alias = alias;
1254
- }
1255
- });
1256
- } else if (item.type === TypeEnum.summarize) {
1257
- // 汇总
1258
- item.alias = alias;
1259
- item.by.forEach(byItem => {
1260
- if (byItem.alias === alias) {
1261
- byItem.alias = alias;
1262
- }
1263
- });
1264
- item.group.forEach(groupItem => {
1265
- if (groupItem.alias === alias) {
1266
- groupItem.alias = alias;
1267
- groupItem.sql = alias;
1268
- }
1269
- });
1270
- }
1271
- });
1272
- newMetaList[groupIndex].list = _list;
1273
- _setMeta(newMetaList);
1274
- }
1275
- };
1276
1511
  const reset = () => {
1277
1512
  // setSourceList([]);
1278
1513
  _setMeta(defaultMeta);
1279
- setToolbar(defaultToolbar);
1514
+ // setToolbar(defaultToolbar);
1280
1515
  set_cacheSource2TableMap({});
1281
1516
  set_cacheColumnsMap({});
1282
1517
  };
@@ -1330,7 +1565,7 @@ const useStore = () => {
1330
1565
  _setShowSubquery,
1331
1566
  constantList,
1332
1567
  setConstantList,
1333
- changeAlias
1568
+ popupContainer
1334
1569
  };
1335
1570
  };
1336
1571
 
@@ -1700,7 +1935,7 @@ const Loading = ({
1700
1935
  });
1701
1936
  };
1702
1937
 
1703
- var css_248z$d = ".mx-4 {\n margin-left: 1rem;\n margin-right: 1rem;\n}\n.m-2 {\n margin: 0.5rem;\n}\n.mx-2 {\n margin-left: 0.5rem;\n margin-right: 0.5rem;\n}\n.ml-2 {\n margin-left: 0.5rem;\n}\n.mt-2 {\n margin-top: 0.5rem;\n}\n.mb-2 {\n margin-bottom: 0.5rem;\n}\n.mt-4 {\n margin-top: 1rem;\n}\n.ml-4 {\n margin-left: 1rem;\n}\n.mr-4 {\n margin-right: 1rem;\n}\n.mr-2 {\n margin-right: 0.5rem;\n}\n.pt-2 {\n padding-top: 0.5rem;\n}\n.pb-2 {\n padding-bottom: 0.5rem;\n}\n.px-2 {\n padding-left: 0.5rem;\n padding-right: 0.5rem;\n}\n.p-4 {\n padding: 1rem;\n}\n.p-2 {\n padding: 0.5rem;\n}\n.px-2 {\n padding-left: 0.5rem;\n padding-right: 0.5rem;\n}\n.pb-4 {\n padding-bottom: 1rem;\n}\n.pt-4 {\n padding-top: 1rem;\n}\n.block {\n display: block;\n}\n.w-full {\n width: 100%;\n}\n.font-bold {\n font-weight: 700;\n}\n.uppercase {\n text-transform: uppercase;\n}\n.tracking-wider {\n letter-spacing: 0.05em;\n}\n.relative {\n position: relative;\n}\n.absolute {\n position: absolute;\n}\n.top-0 {\n top: 0px;\n}\n.left-0 {\n left: 0;\n}\n.rounded-lg {\n border-radius: 0.5rem;\n}\n.text-gray-500 {\n color: #6b7280;\n}\n.flex {\n display: flex;\n}\n.items-center {\n align-items: center;\n}\n.justify-center {\n justify-content: center;\n}\n.visual-box {\n position: relative;\n width: 100%;\n height: 100%;\n overflow-y: scroll;\n overflow-x: hidden;\n transition: all 0.3s;\n z-index: 3;\n background-color: #fff;\n}\n.Sqb {\n padding: 0 20px 50px;\n}\n.Sqb-list {\n padding-top: 1.5rem;\n}\n.Sqb-hover-parent {\n margin-bottom: 16px;\n padding-bottom: 16px;\n}\n.Sqb-item {\n font-size: 14px;\n}\n.Sqb-item--text {\n color: #509ee3;\n width: 66.6667%;\n box-sizing: border-box;\n margin-bottom: 8px;\n display: flex;\n align-items: center;\n font-weight: 600;\n}\n.Sqb-item--text.purple-text {\n color: #7172ad;\n}\n.Sqb-item--text.gray-text {\n color: #93a1ab;\n}\n.Sqb-item--text.green-text {\n color: #88bf4d;\n}\n.Sqb-item-close {\n width: 16px;\n height: 16px;\n color: #b8bbc3;\n margin-left: auto;\n visibility: hidden;\n cursor: pointer;\n}\n.Sqb-item--content {\n width: 66.6667%;\n box-sizing: border-box;\n}\n.Sqb-item--content .Sqb-Filter-item {\n position: relative;\n margin: 0 10px;\n}\n.Sqb-item--content .Sqb-Filter-item .right-arrow,\n.Sqb-item--content .Sqb-Filter-item .left-arrow {\n position: absolute;\n top: 0;\n height: 40px;\n width: 30px;\n display: flex;\n align-items: center;\n justify-content: center;\n opacity: 0.4;\n cursor: pointer;\n transform: scale(0);\n transition: all 0.3s;\n}\n.Sqb-item--content .Sqb-Filter-item .right-arrow img,\n.Sqb-item--content .Sqb-Filter-item .left-arrow img {\n transform: scale(0.8);\n}\n.Sqb-item--content .Sqb-Filter-item .right-arrow:hover,\n.Sqb-item--content .Sqb-Filter-item .left-arrow:hover {\n opacity: 1;\n}\n.Sqb-item--content .Sqb-Filter-item .left-arrow {\n transform: rotate(180deg) scale(0);\n transform-origin: 50% 50%;\n left: -30px;\n}\n.Sqb-item--content .Sqb-Filter-item .right-arrow {\n right: -20px;\n}\n.Sqb-item--content .Sqb-Filter-item.hover .left-arrow {\n transform: rotate(180deg) scale(1);\n}\n.Sqb-item--content .Sqb-Filter-item.hover .right-arrow {\n transform: scale(1);\n}\n.Sqb-item--content .Sqb-NotebookCell {\n box-sizing: border-box;\n padding: 16px 16px 8px;\n color: #509ee3;\n display: flex;\n flex-wrap: wrap;\n -webkit-box-align: center;\n align-items: center;\n border-radius: 8px;\n background-color: rgba(80, 158, 227, 0.1);\n}\n.Sqb-item--content .Sqb-NotebookCell-preview {\n flex-shrink: 0;\n width: 100%;\n}\n.Sqb-item--content .Sqb-NotebookCell.gray-bg {\n background-color: rgba(147, 161, 171, 0.1);\n}\n.Sqb-item--content .Sqb-NotebookCell.green-bg {\n background-color: rgba(136, 191, 77, 0.1);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName {\n position: relative;\n border: 2px solid transparent;\n border-radius: 6px;\n color: white;\n background-color: #509ee3;\n transition: background 300ms linear 0s,\n border 300ms linear 0s;\n box-sizing: border-box;\n margin-bottom: 8px;\n margin-right: 8px;\n padding: 8px;\n display: flex;\n -webkit-box-align: center;\n align-items: center;\n cursor: pointer;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName-as {\n position: absolute;\n right: 0;\n top: 0;\n transform: translate(50%, -50%);\n margin: 0;\n border: none;\n border-radius: 50%;\n width: 20px;\n height: 20px;\n font-size: 12px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName-input {\n margin-bottom: 9px;\n margin-right: 8px;\n padding: 9px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName::selection {\n color: #ffffff;\n background-color: #d489ac;\n text-shadow: none;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName:hover {\n background-color: rgba(80, 158, 227, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.noClick {\n cursor: default;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.noClick:hover {\n background-color: #509ee3;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.notSelected {\n border: 2px solid rgba(80, 158, 227, 0.25);\n color: #509ee3;\n background-color: transparent;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.notSelected:hover {\n border-color: rgba(80, 158, 227, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name {\n color: white;\n background-color: #7172ad;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name:hover {\n background-color: rgba(113, 114, 173, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name svg.closeIcon {\n opacity: 0.6;\n margin-left: 8px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name.notSelected {\n border: 2px solid rgba(113, 114, 173, 0.25);\n color: #7172ad;\n background-color: transparent;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name.notSelected:hover {\n border-color: rgba(113, 114, 173, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.gray-name {\n color: white;\n background-color: #93a1ab;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.gray-name:hover {\n background-color: rgba(147, 161, 171, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.gray-name svg.sort-arrow {\n margin-right: 0.5rem;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.gray-name svg.closeIcon {\n opacity: 0.6;\n margin-left: 8px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name {\n color: white;\n background-color: #88bf4d;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name:hover {\n background-color: rgba(136, 191, 77, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name svg.closeIcon {\n opacity: 0.6;\n margin-left: 8px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name.notSelected {\n border: 2px solid rgba(136, 191, 77, 0.25);\n color: #88bf4d;\n background-color: transparent;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name.notSelected:hover {\n border-color: rgba(136, 191, 77, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .ant-input-number {\n margin-bottom: 0.5rem;\n}\n.Sqb-item--content .Sqb-NotebookCell .ant-input-number .ant-input-number-input {\n height: 32px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-where {\n box-sizing: border-box;\n display: flex;\n -webkit-box-align: center;\n align-items: center;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-where.block {\n width: 100%;\n}\n.Sqb-item--content .Sqb-NotebookCell .operator-icon,\n.Sqb-item--content .Sqb-NotebookCell .operator-icon button {\n font-size: 18px !important;\n border: none !important;\n}\n.Sqb-item--content .Sqb-NotebookCell .subquery-icon {\n color: #93a1ab;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableColumns {\n font-weight: 600;\n margin-bottom: 0.5rem;\n margin-left: auto;\n cursor: pointer;\n}\n.Sqb-item--content .flex-row {\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n align-items: center;\n flex-direction: row;\n}\n.Sqb-item--content .flex-row .Sqb-NotebookCell {\n width: 50%;\n}\n.Sqb-item--content .flex-row .pass {\n color: #88bf4d;\n margin: 4px 16px;\n font-size: 600;\n}\n.Sqb-item--func {\n box-sizing: border-box;\n margin-top: 8px;\n}\n.Sqb-item--func .Sqb-button {\n display: inline-block;\n box-sizing: border-box;\n text-decoration: none;\n cursor: pointer;\n font-weight: bold;\n padding: 12px 16px;\n border-radius: 6px;\n margin-right: 16px;\n margin-top: 16px;\n border: none;\n transition: background 300ms ease 0s;\n flex-shrink: 0;\n color: #93a1ab;\n background-color: #ffffff;\n}\n.Sqb-item--func .Sqb-button:hover {\n color: #7e8f9b;\n background-color: #eceff0;\n}\n.Sqb-item--func .Sqb-button > div {\n min-width: 60px;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n display: flex;\n}\n.Sqb-item--func .Sqb-button > div svg {\n flex-shrink: 0;\n}\n.Sqb-item--func .Sqb-button > div div {\n margin-top: 0.5rem;\n}\n.Sqb-item--func .Sqb-button.filter {\n color: #7172ad;\n background-color: #e0e0ed;\n}\n.Sqb-item--func .Sqb-button.filter:hover {\n color: #5d5ea0;\n background-color: #cccce1;\n}\n.Sqb-item--func .Sqb-button.summarize {\n color: #88bf4d;\n background-color: #d8eac5;\n}\n.Sqb-item--func .Sqb-button.summarize:hover {\n color: #79ae3f;\n background-color: #cae2af;\n}\n.Sqb-item--func .Sqb-button.joinData {\n color: #509ee3;\n background-color: #f1f7fd;\n}\n.Sqb-item--func .Sqb-button.joinData:hover {\n color: #328dde;\n background-color: #d4e7f8;\n}\n.Sqb-item--func .Sqb-button.small {\n margin-right: 8px;\n margin-top: 0;\n padding: 0.5rem;\n}\n.Sqb-item--func .Sqb-button.small > div {\n min-width: 0;\n}\n.Sqb-item--func .Sqb-button.small > div svg {\n width: 14px;\n height: 14px;\n}\n.Sqb-item--func .Sqb-button.small > div div {\n display: none;\n}\n.Sqb-item:hover .Sqb-item-close {\n visibility: visible;\n}\n.Sqb > .Sqb-btn {\n min-width: 220px;\n height: 36px;\n border-radius: 6px;\n color: #ffffff;\n background-color: #509ee3 !important;\n border: 1px solid #509ee3;\n}\n.Sqb > .Sqb-btn:hover {\n background-color: rgba(80, 158, 227, 0.8) !important;\n}\n";
1938
+ var css_248z$d = ".mx-4 {\n margin-left: 1rem;\n margin-right: 1rem;\n}\n.m-2 {\n margin: 0.5rem;\n}\n.mx-2 {\n margin-left: 0.5rem;\n margin-right: 0.5rem;\n}\n.ml-2 {\n margin-left: 0.5rem;\n}\n.mt-2 {\n margin-top: 0.5rem;\n}\n.mb-2 {\n margin-bottom: 0.5rem;\n}\n.mt-4 {\n margin-top: 1rem;\n}\n.ml-4 {\n margin-left: 1rem;\n}\n.mr-4 {\n margin-right: 1rem;\n}\n.mr-2 {\n margin-right: 0.5rem;\n}\n.pt-2 {\n padding-top: 0.5rem;\n}\n.pb-2 {\n padding-bottom: 0.5rem;\n}\n.px-2 {\n padding-left: 0.5rem;\n padding-right: 0.5rem;\n}\n.p-4 {\n padding: 1rem;\n}\n.p-2 {\n padding: 0.5rem;\n}\n.p-1 {\n padding: 0.25rem;\n}\n.px-2 {\n padding-left: 0.5rem;\n padding-right: 0.5rem;\n}\n.pb-4 {\n padding-bottom: 1rem;\n}\n.pt-4 {\n padding-top: 1rem;\n}\n.block {\n display: block;\n}\n.w-full {\n width: 100%;\n}\n.font-bold {\n font-weight: 700;\n}\n.uppercase {\n text-transform: uppercase;\n}\n.tracking-wider {\n letter-spacing: 0.05em;\n}\n.relative {\n position: relative;\n}\n.absolute {\n position: absolute;\n}\n.top-0 {\n top: 0px;\n}\n.left-0 {\n left: 0;\n}\n.rounded-lg {\n border-radius: 0.5rem;\n}\n.text-gray-500 {\n color: #6b7280;\n}\n.flex {\n display: flex;\n}\n.items-center {\n align-items: center;\n}\n.justify-center {\n justify-content: center;\n}\n.visual-box {\n position: relative;\n width: 100%;\n height: 100%;\n overflow-y: scroll;\n overflow-x: hidden;\n transition: all 0.3s;\n z-index: 3;\n background-color: #fff;\n}\n.Sqb {\n padding: 0 20px 50px;\n}\n.Sqb-list {\n padding-top: 1.5rem;\n}\n.Sqb-hover-parent {\n margin-bottom: 16px;\n padding-bottom: 16px;\n}\n.Sqb-item {\n font-size: 14px;\n}\n.Sqb-item--text {\n color: #509ee3;\n width: 66.6667%;\n box-sizing: border-box;\n margin-bottom: 8px;\n display: flex;\n align-items: center;\n font-weight: 600;\n}\n.Sqb-item--text.purple-text {\n color: #7172ad;\n}\n.Sqb-item--text.gray-text {\n color: #93a1ab;\n}\n.Sqb-item--text.green-text {\n color: #88bf4d;\n}\n.Sqb-item-close {\n width: 16px;\n height: 16px;\n color: #b8bbc3;\n margin-left: auto;\n visibility: hidden;\n cursor: pointer;\n}\n.Sqb-item--content {\n width: 66.6667%;\n box-sizing: border-box;\n}\n.Sqb-item--content .Sqb-Filter-item {\n position: relative;\n margin: 0 10px;\n}\n.Sqb-item--content .Sqb-Filter-item .right-arrow,\n.Sqb-item--content .Sqb-Filter-item .left-arrow {\n position: absolute;\n top: 0;\n height: 40px;\n width: 30px;\n display: flex;\n align-items: center;\n justify-content: center;\n opacity: 0.4;\n cursor: pointer;\n transform: scale(0);\n transition: all 0.3s;\n}\n.Sqb-item--content .Sqb-Filter-item .right-arrow img,\n.Sqb-item--content .Sqb-Filter-item .left-arrow img {\n transform: scale(0.8);\n}\n.Sqb-item--content .Sqb-Filter-item .right-arrow:hover,\n.Sqb-item--content .Sqb-Filter-item .left-arrow:hover {\n opacity: 1;\n}\n.Sqb-item--content .Sqb-Filter-item .left-arrow {\n transform: rotate(180deg) scale(0);\n transform-origin: 50% 50%;\n left: -30px;\n}\n.Sqb-item--content .Sqb-Filter-item .right-arrow {\n right: -20px;\n}\n.Sqb-item--content .Sqb-Filter-item.hover .left-arrow {\n transform: rotate(180deg) scale(1);\n}\n.Sqb-item--content .Sqb-Filter-item.hover .right-arrow {\n transform: scale(1);\n}\n.Sqb-item--content .Sqb-NotebookCell {\n box-sizing: border-box;\n padding: 16px 16px 8px;\n color: #509ee3;\n display: flex;\n flex-wrap: wrap;\n -webkit-box-align: center;\n align-items: center;\n border-radius: 8px;\n background-color: rgba(80, 158, 227, 0.1);\n}\n.Sqb-item--content .Sqb-NotebookCell-preview {\n flex-shrink: 0;\n width: 100%;\n}\n.Sqb-item--content .Sqb-NotebookCell.gray-bg {\n background-color: rgba(147, 161, 171, 0.1);\n}\n.Sqb-item--content .Sqb-NotebookCell.green-bg {\n background-color: rgba(136, 191, 77, 0.1);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName {\n position: relative;\n border: 2px solid transparent;\n border-radius: 6px;\n color: white;\n background-color: #509ee3;\n transition: background 300ms linear 0s,\n border 300ms linear 0s;\n box-sizing: border-box;\n margin-bottom: 8px;\n margin-right: 8px;\n padding: 8px;\n display: flex;\n -webkit-box-align: center;\n align-items: center;\n cursor: pointer;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName-as {\n position: absolute;\n right: 0;\n top: 0;\n transform: translate(50%, -50%);\n margin: 0;\n border: none;\n border-radius: 50%;\n width: 20px;\n height: 20px;\n font-size: 12px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName-input {\n margin-bottom: 9px;\n margin-right: 8px;\n padding: 9px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName::selection {\n color: #ffffff;\n background-color: #d489ac;\n text-shadow: none;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName:hover {\n background-color: rgba(80, 158, 227, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.noClick {\n cursor: default;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.noClick:hover {\n background-color: #509ee3;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.notSelected {\n border: 2px solid rgba(80, 158, 227, 0.25);\n color: #509ee3;\n background-color: transparent;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.notSelected:hover {\n border-color: rgba(80, 158, 227, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name {\n color: white;\n background-color: #7172ad;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name:hover {\n background-color: rgba(113, 114, 173, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name svg.closeIcon {\n opacity: 0.6;\n margin-left: 8px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name.notSelected {\n border: 2px solid rgba(113, 114, 173, 0.25);\n color: #7172ad;\n background-color: transparent;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.purple-name.notSelected:hover {\n border-color: rgba(113, 114, 173, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.gray-name {\n color: white;\n background-color: #93a1ab;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.gray-name:hover {\n background-color: rgba(147, 161, 171, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.gray-name svg.sort-arrow {\n margin-right: 0.5rem;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.gray-name svg.closeIcon {\n opacity: 0.6;\n margin-left: 8px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name {\n color: white;\n background-color: #88bf4d;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name:hover {\n background-color: rgba(136, 191, 77, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name svg.closeIcon {\n opacity: 0.6;\n margin-left: 8px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name.notSelected {\n border: 2px solid rgba(136, 191, 77, 0.25);\n color: #88bf4d;\n background-color: transparent;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableName.green-name.notSelected:hover {\n border-color: rgba(136, 191, 77, 0.8);\n}\n.Sqb-item--content .Sqb-NotebookCell .ant-input-number {\n margin-bottom: 0.5rem;\n}\n.Sqb-item--content .Sqb-NotebookCell .ant-input-number .ant-input-number-input {\n height: 32px;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-where {\n box-sizing: border-box;\n display: flex;\n -webkit-box-align: center;\n align-items: center;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-where.block {\n width: 100%;\n}\n.Sqb-item--content .Sqb-NotebookCell .operator-icon,\n.Sqb-item--content .Sqb-NotebookCell .operator-icon button {\n font-size: 18px !important;\n border: none !important;\n}\n.Sqb-item--content .Sqb-NotebookCell .subquery-icon {\n color: #93a1ab;\n}\n.Sqb-item--content .Sqb-NotebookCell .Sqb-TableColumns {\n font-weight: 600;\n margin-bottom: 0.5rem;\n margin-left: auto;\n cursor: pointer;\n}\n.Sqb-item--content .flex-row {\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n align-items: center;\n flex-direction: row;\n}\n.Sqb-item--content .flex-row .Sqb-NotebookCell {\n width: 50%;\n}\n.Sqb-item--content .flex-row .pass {\n color: #88bf4d;\n margin: 4px 16px;\n font-size: 600;\n}\n.Sqb-item--func {\n box-sizing: border-box;\n margin-top: 8px;\n}\n.Sqb-item--func .Sqb-button {\n display: inline-block;\n box-sizing: border-box;\n text-decoration: none;\n cursor: pointer;\n font-weight: bold;\n padding: 12px 16px;\n border-radius: 6px;\n margin-right: 16px;\n margin-top: 16px;\n border: none;\n transition: background 300ms ease 0s;\n flex-shrink: 0;\n color: #93a1ab;\n background-color: #ffffff;\n}\n.Sqb-item--func .Sqb-button:hover {\n color: #7e8f9b;\n background-color: #eceff0;\n}\n.Sqb-item--func .Sqb-button > div {\n min-width: 60px;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n display: flex;\n}\n.Sqb-item--func .Sqb-button > div svg {\n flex-shrink: 0;\n}\n.Sqb-item--func .Sqb-button > div div {\n margin-top: 0.5rem;\n}\n.Sqb-item--func .Sqb-button.filter {\n color: #7172ad;\n background-color: #e0e0ed;\n}\n.Sqb-item--func .Sqb-button.filter:hover {\n color: #5d5ea0;\n background-color: #cccce1;\n}\n.Sqb-item--func .Sqb-button.summarize {\n color: #88bf4d;\n background-color: #d8eac5;\n}\n.Sqb-item--func .Sqb-button.summarize:hover {\n color: #79ae3f;\n background-color: #cae2af;\n}\n.Sqb-item--func .Sqb-button.joinData {\n color: #509ee3;\n background-color: #f1f7fd;\n}\n.Sqb-item--func .Sqb-button.joinData:hover {\n color: #328dde;\n background-color: #d4e7f8;\n}\n.Sqb-item--func .Sqb-button.small {\n margin-right: 8px;\n margin-top: 0;\n padding: 0.5rem;\n}\n.Sqb-item--func .Sqb-button.small > div {\n min-width: 0;\n}\n.Sqb-item--func .Sqb-button.small > div svg {\n width: 14px;\n height: 14px;\n}\n.Sqb-item--func .Sqb-button.small > div div {\n display: none;\n}\n.Sqb-item:hover .Sqb-item-close {\n visibility: visible;\n}\n.Sqb > .Sqb-btn {\n min-width: 220px;\n height: 36px;\n border-radius: 6px;\n color: #ffffff;\n background-color: #509ee3 !important;\n border: 1px solid #509ee3;\n}\n.Sqb > .Sqb-btn:hover {\n background-color: rgba(80, 158, 227, 0.8) !important;\n}\n";
1704
1939
  styleInject(css_248z$d);
1705
1940
 
1706
1941
  // 获取元素translate x y值
@@ -1732,6 +1967,7 @@ const getComputedTranslate = obj => {
1732
1967
  };
1733
1968
  // 获取元素距离浏览器顶部的距离
1734
1969
  const getElementTop = elem => {
1970
+ if (!elem) return 0;
1735
1971
  let elemTop = elem.offsetTop;
1736
1972
  let pElem = elem.offsetParent;
1737
1973
  while (pElem != null) {
@@ -1745,6 +1981,7 @@ const getElementTop = elem => {
1745
1981
  };
1746
1982
  // 获取元素距离浏览器顶部的距离
1747
1983
  const getElementLeft = elem => {
1984
+ if (!elem) return 0;
1748
1985
  let elemLeft = elem.offsetLeft;
1749
1986
  let pElem = elem.offsetParent;
1750
1987
  while (pElem != null) {
@@ -1756,8 +1993,23 @@ const getElementLeft = elem => {
1756
1993
  }
1757
1994
  return elemLeft;
1758
1995
  };
1759
- const getScrollTop = () => {
1760
- return document.documentElement.scrollTop;
1996
+ // 获取元素可见范围内高度
1997
+ const getContainerVisibleHeight = container => {
1998
+ if (!container) return 0;
1999
+ const rect = container.getBoundingClientRect();
2000
+ const windowHeight = window.innerHeight || document.documentElement.clientHeight;
2001
+ // 元素顶部在视口上方 -> 不可见
2002
+ if (rect.bottom < 0) return 0;
2003
+ // 元素底部在视口下方 -> 不可见
2004
+ if (rect.top > windowHeight) return 0;
2005
+ // 可见区域的 top 和 bottom
2006
+ const visibleTop = Math.max(rect.top, 0);
2007
+ const visibleBottom = Math.min(rect.bottom, windowHeight);
2008
+ // 可见高度
2009
+ return visibleBottom - visibleTop;
2010
+ };
2011
+ const getScrollTop = elem => {
2012
+ return elem?.scrollTop || document.documentElement.scrollTop;
1761
2013
  };
1762
2014
  // 浏览器可视宽高
1763
2015
  const getWindowSize = () => {
@@ -2236,7 +2488,7 @@ const List = [{
2236
2488
  const RowLimit$1 = props => {
2237
2489
  const {
2238
2490
  meta,
2239
- operator,
2491
+ union,
2240
2492
  groupIndex
2241
2493
  } = props;
2242
2494
  const store = useStore$1();
@@ -2246,10 +2498,10 @@ const RowLimit$1 = props => {
2246
2498
  node: e.currentTarget,
2247
2499
  content: jsx(SelectList, {
2248
2500
  list: List,
2249
- value: operator,
2501
+ value: union,
2250
2502
  onChange: type => {
2251
2503
  let newMeta = store.metaList.slice();
2252
- newMeta[groupIndex].operator = type;
2504
+ newMeta[groupIndex].union = type;
2253
2505
  store._setMeta(newMeta);
2254
2506
  store.setPopup({
2255
2507
  visible: false
@@ -2272,7 +2524,7 @@ const RowLimit$1 = props => {
2272
2524
  children: jsx("div", {
2273
2525
  className: `Sqb-TableName`,
2274
2526
  onClick: e => selectOperator(e),
2275
- children: operator
2527
+ children: union
2276
2528
  })
2277
2529
  })
2278
2530
  })]
@@ -3328,6 +3580,7 @@ function returnDocument(element) {
3328
3580
  const outSpacing = 10;
3329
3581
  function generateTrigger(PortalComponent) {
3330
3582
  class Trigger extends React.Component {
3583
+ resizeObserver = null; // 显式声明 resizeObserver 属性
3331
3584
  resetId = -1; // 监听窗口改变事件id 用于组件销毁的时候清除事件
3332
3585
  static defaultProps = {
3333
3586
  visible: false,
@@ -3342,11 +3595,39 @@ function generateTrigger(PortalComponent) {
3342
3595
  this.resetId = winResetEvent.addEvent(this.didUpdate, this, 300);
3343
3596
  this.props.container && this.props.container.addEventListener('scroll', this.didUpdate);
3344
3597
  this.bindEvent();
3598
+ // 延迟绑定 ResizeObserver 到 ensure the element is ready
3599
+ this.initResizeObserver();
3600
+ }
3601
+ componentDidUpdate(prevProps) {
3602
+ // 如果 children 发生变化,重新初始化观察器
3603
+ if (prevProps.children !== this.props.children) {
3604
+ this.initResizeObserver();
3605
+ }
3345
3606
  }
3346
3607
  componentWillUnmount() {
3347
3608
  winResetEvent.removeEvent(this.resetId);
3348
3609
  this.props.container && this.props.container.removeEventListener('scroll', this.didUpdate);
3610
+ if (this.resizeObserver) {
3611
+ this.resizeObserver.disconnect();
3612
+ this.resizeObserver = null;
3613
+ }
3349
3614
  }
3615
+ // children高度变化后,从新计算高度
3616
+ initResizeObserver = () => {
3617
+ const targetNode = this.ref.current;
3618
+ if (!targetNode) return;
3619
+ // 如果已经存在 ResizeObserver,先断开连接
3620
+ if (this.resizeObserver) {
3621
+ this.resizeObserver.disconnect();
3622
+ }
3623
+ // 初始化 ResizeObserver 并开始观察目标节点
3624
+ this.resizeObserver = new ResizeObserver(entries => {
3625
+ entries.forEach(entry => {
3626
+ this.didUpdate();
3627
+ });
3628
+ });
3629
+ this.resizeObserver.observe(targetNode);
3630
+ };
3350
3631
  bindEvent = () => {
3351
3632
  let that = this;
3352
3633
  returnDocument().body.addEventListener('click', function (e) {
@@ -3364,7 +3645,7 @@ function generateTrigger(PortalComponent) {
3364
3645
  this.props.visible && this.props.closable && this.props.hideVisible();
3365
3646
  };
3366
3647
  attachParent = popupContainer => {
3367
- let mountNode = returnDocument().body;
3648
+ let mountNode = this.props.container || returnDocument().body;
3368
3649
  mountNode.appendChild(popupContainer);
3369
3650
  };
3370
3651
  getCurrentNodePos = () => {
@@ -3373,8 +3654,9 @@ function generateTrigger(PortalComponent) {
3373
3654
  container
3374
3655
  } = this.props;
3375
3656
  return {
3376
- x: getElementLeft(node),
3377
- y: getElementTop(node) - (container?.scrollTop || 0),
3657
+ x: getElementLeft(node) - getElementLeft(container),
3658
+ y: getElementTop(node) - getElementTop(container),
3659
+ t: getElementTop(container),
3378
3660
  h: node.offsetHeight
3379
3661
  };
3380
3662
  };
@@ -3417,19 +3699,21 @@ function generateTrigger(PortalComponent) {
3417
3699
  didUpdate = () => {
3418
3700
  if (!this.props.node) return false;
3419
3701
  let {
3420
- innerSpacing = 10
3702
+ innerSpacing = 10,
3703
+ container
3421
3704
  } = this.props;
3422
3705
  let pos = this.getCurrentNodePos();
3423
- let posY = pos.y - getScrollTop();
3706
+ let posY = pos.y - getScrollTop(container);
3424
3707
  if (!this.ref) return false;
3425
3708
  let realHeight = this.ref?.current?.childNodes?.[0]?.offsetHeight || 0;
3426
3709
  if (!realHeight) return false;
3427
3710
  let {
3428
3711
  height: winH
3429
3712
  } = getWindowSize();
3430
- let downH = winH - posY - pos.h; // 元素下面可用高度
3713
+ let containerH = getContainerVisibleHeight(container);
3714
+ let downH = (containerH || winH) - posY - pos.h; // 元素下面可用高度
3431
3715
  let maxHeight = 0;
3432
- let topHeight = getScrollTop();
3716
+ let topHeight = getScrollTop(container);
3433
3717
  if (downH >= posY || realHeight <= downH - innerSpacing - outSpacing) {
3434
3718
  // 下面比上面宽敞 或 下面足够放下所有 放下面
3435
3719
  maxHeight = Math.min(realHeight, downH - innerSpacing - outSpacing);
@@ -3465,7 +3749,7 @@ styleInject(css_248z$9);
3465
3749
  var css_248z$8 = ".function-tip__container {\n width: 448px;\n font-size: 14px;\n color: #4c5773;\n}\n.function-tip__container .function-name {\n background: #fffcf2;\n font-weight: 700;\n padding: 1rem;\n font-size: 14px;\n}\n.function-tip__container .function-desc {\n padding: 1rem;\n border-top: 1px solid #f0f0f0;\n}\n.function-tip__container .function-desc .desc {\n font-weight: 700;\n}\n.function-tip__container .function-desc .case {\n font-family: monospace;\n color: #949aab;\n background-color: #edf2f5;\n border-radius: 2px;\n padding: 0.2em 0.4em;\n line-height: 1.4em;\n white-space: pre-wrap;\n}\n.function-tip__container .funciton-parameter {\n padding: 1rem;\n border-top: 1px solid #f0f0f0;\n}\n.function-tip__container .funciton-parameter .key {\n color: #949aab;\n}\n.function-tip__container .funciton-parameter .explain {\n font-weight: 700;\n margin-top: 0.5rem;\n}\n";
3466
3750
  styleInject(css_248z$8);
3467
3751
 
3468
- var css_248z$7 = ".Sqb-SelectColumn--box {\n box-sizing: border-box;\n min-width: 1em;\n max-width: 300px;\n background-color: #ffffff;\n overflow: hidden;\n}\n.Sqb-SelectColumn--box .SelectColumn-border {\n border-bottom: 1px solid #f0f0f0;\n}\n.Sqb-SelectColumn--box .SelectColumn-border.events-none {\n pointer-events: none;\n opacity: 0.4;\n}\n.Sqb-SelectColumn--box > div {\n cursor: pointer;\n color: #4c5773;\n}\n.Sqb-SelectColumn--box > div .selected {\n width: 16px;\n height: 16px;\n background-color: #509ee3;\n border: 2px solid #509ee3;\n border-radius: 4px;\n color: #fff;\n}\n.Sqb-SelectColumn--box > div .no-select {\n width: 16px;\n height: 16px;\n background-color: white;\n border: 2px solid #b8bbc3;\n border-radius: 4px;\n color: #b8bbc3;\n}\n.Sqb-SelectColumn--box > div .Sqb-TableName-as {\n margin-left: auto;\n}\n";
3752
+ var css_248z$7 = ".Sqb-SelectColumn--box {\n box-sizing: border-box;\n min-width: 1em;\n max-width: 300px;\n background-color: #ffffff;\n overflow: hidden;\n}\n.Sqb-SelectColumn--box .SelectColumn-border {\n border-bottom: 1px solid #f0f0f0;\n}\n.Sqb-SelectColumn--box .SelectColumn-border.events-none {\n pointer-events: none;\n opacity: 0.4;\n}\n.Sqb-SelectColumn--box > div {\n cursor: pointer;\n color: #4c5773;\n}\n.Sqb-SelectColumn--box > div .selected {\n width: 16px;\n height: 16px;\n background-color: #509ee3;\n border: 2px solid #509ee3;\n border-radius: 4px;\n color: #fff;\n}\n.Sqb-SelectColumn--box > div .no-select {\n width: 16px;\n height: 16px;\n background-color: white;\n border: 2px solid #b8bbc3;\n border-radius: 4px;\n color: #b8bbc3;\n}\n.Sqb-SelectColumn--box > div .Sqb-TableName-as {\n margin-left: auto;\n}\n.Sqb-SelectColumn--box .Sqb-SelectColumn-search {\n display: flex;\n align-items: center;\n flex: 1 0 auto;\n color: #b8bbc3;\n background-color: #fff;\n border: 1px solid #f0f0f0;\n font-size: 14px;\n}\n.Sqb-SelectColumn--box .Sqb-SelectColumn-search span {\n line-height: 0;\n}\n.Sqb-SelectColumn--box .Sqb-SelectColumn-search input {\n box-shadow: none;\n outline: 0;\n border: none !important;\n background: transparent;\n color: #4c5773;\n font-size: 1em;\n font-weight: 600;\n}\n.Sqb-SelectColumn--box .Sqb-SelectColumn-search input::-webkit-input-placeholder {\n color: #b8bbc3;\n}\n.Sqb-SelectColumn--box .Sqb-SelectColumn-search input::-ms-input-placeholder {\n color: #b8bbc3;\n}\n";
3469
3753
  styleInject(css_248z$7);
3470
3754
 
3471
3755
  // 选择表中参数
@@ -3474,11 +3758,21 @@ const SelectColumn = ({
3474
3758
  groupIndex,
3475
3759
  onChange
3476
3760
  }) => {
3477
- const [columns, setColumns] = useState(_data.slice());
3761
+ const [columns, setColumns] = useState([]);
3762
+ const [originList, setOriginList] = useState(_data.slice());
3478
3763
  const store = useStore$1();
3764
+ const [filterVal, setFilterVal] = useState('');
3765
+ useEffect(() => {
3766
+ let newList = cloneDeep(originList.slice());
3767
+ setColumns(newList.filter(v => ~(v.name + (v.name_zh || '')).toLocaleLowerCase().indexOf(filterVal.toLocaleLowerCase())));
3768
+ }, [filterVal, originList]);
3769
+ function onInput(e) {
3770
+ let val = e.target.value;
3771
+ setFilterVal(val);
3772
+ }
3479
3773
  const isAllSelect = useMemo(() => {
3480
- return columns.filter(v => v.select).length === columns.length;
3481
- }, [columns]);
3774
+ return originList.filter(v => v.select).length === originList.length;
3775
+ }, [originList]);
3482
3776
  const AllSelectElement = useMemo(() => {
3483
3777
  if (isAllSelect) {
3484
3778
  return jsxs(Fragment, {
@@ -3497,8 +3791,14 @@ const SelectColumn = ({
3497
3791
  }
3498
3792
  }, [isAllSelect]);
3499
3793
  function onSelect(columns) {
3794
+ const originalData = cloneDeep(originList); // 原始数据
3795
+ const mergedColumns = originalData.map(item => {
3796
+ const match = columns.find(col => col.fieldUuid === item.fieldUuid);
3797
+ return match ? cloneDeep(match) : item; // 可选:是否需要深拷贝 match
3798
+ });
3500
3799
  setColumns(columns);
3501
- typeof onChange === 'function' && onChange(columns);
3800
+ setOriginList(mergedColumns);
3801
+ typeof onChange === 'function' && onChange(mergedColumns);
3502
3802
  }
3503
3803
  const onChangeFieldAlias = (val, i) => {
3504
3804
  let fieldAlias = val || '';
@@ -3542,6 +3842,18 @@ const SelectColumn = ({
3542
3842
  onSelect(newColumns);
3543
3843
  },
3544
3844
  children: AllSelectElement
3845
+ }), jsxs("div", {
3846
+ className: cx(`Sqb-SelectColumn-search m-2 rounded-lg`),
3847
+ children: [jsx("span", {
3848
+ className: 'px-2',
3849
+ children: jsx(SearchIcon, {})
3850
+ }), jsx("input", {
3851
+ type: 'text',
3852
+ autoFocus: true,
3853
+ className: 'p-1',
3854
+ placeholder: __('data.search'),
3855
+ onInput: onInput
3856
+ })]
3545
3857
  }), Array.isArray(columns) && columns.map((v, i) => {
3546
3858
  return jsxs("div", {
3547
3859
  className: 'pb-2 px-2 flex items-center',
@@ -3579,7 +3891,7 @@ const SelectColumn = ({
3579
3891
  });
3580
3892
  };
3581
3893
 
3582
- var css_248z$6 = ".Sqb-SelectColumns--box {\n box-sizing: border-box;\n min-width: 1em;\n max-width: 500px;\n background-color: #ffffff;\n overflow: hidden;\n}\n.Sqb-SelectColumns--box .Sqb-List-item {\n display: flex;\n border-radius: 4px;\n margin-top: 2px;\n margin-bottom: 2px;\n}\n.Sqb-SelectColumns--box .Sqb-List-item a {\n flex: auto;\n cursor: pointer;\n display: flex;\n align-items: center;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .List-item-icon {\n display: flex;\n align-items: center;\n color: #b8bbc3;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .List-item-title {\n word-break: break-word;\n word-wrap: anywhere;\n color: #4c5773;\n margin-top: 0;\n margin-bottom: 0;\n font-size: 14px;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .Field-extra {\n display: flex;\n align-items: center;\n padding: 0.5rem;\n cursor: pointer;\n border-left: 2px solid rgba(113, 114, 173, 0.1);\n color: rgba(255, 255, 255, 0.5);\n visibility: hidden;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .Field-extra h4 {\n margin-bottom: 0;\n color: inherit;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .Field-extra svg {\n color: #fff;\n margin-left: 0.5rem;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .Field-extra:hover {\n color: #fff;\n}\n.Sqb-SelectColumns--box .Sqb-List-item:not(.disabled):hover,\n.Sqb-SelectColumns--box .Sqb-List-item.active {\n background-color: #509ee3;\n border-color: rgba(169, 137, 197, 0.2);\n}\n.Sqb-SelectColumns--box .Sqb-List-item:not(.disabled):hover .List-item-icon,\n.Sqb-SelectColumns--box .Sqb-List-item.active .List-item-icon {\n color: #fff !important;\n}\n.Sqb-SelectColumns--box .Sqb-List-item:not(.disabled):hover .List-item-title,\n.Sqb-SelectColumns--box .Sqb-List-item.active .List-item-title {\n color: #fff !important;\n}\n.Sqb-SelectColumns--box .Sqb-List-item:not(.disabled):hover .Field-extra,\n.Sqb-SelectColumns--box .Sqb-List-item.active .Field-extra {\n visibility: visible;\n}\n.Sqb-SelectColumns--box .Sqb-List-item.disabled .List-item-title {\n color: #949aab !important;\n}\n.Sqb-SelectColumns--box .Sqb-List-title {\n display: flex;\n border-radius: 4px;\n}\n.Sqb-SelectColumns--box .Sqb-List-title a {\n flex: auto;\n cursor: default;\n display: flex;\n align-items: center;\n color: #4c5773;\n overflow: hidden;\n}\n.Sqb-SelectColumns--box .Sqb-List-title .List-item-icon {\n display: flex;\n align-items: center;\n}\n.Sqb-SelectColumns--box .Sqb-List-title .List-item-title {\n word-break: break-word;\n word-wrap: anywhere;\n margin-top: 0;\n margin-bottom: 0;\n font-size: 16px;\n font-weight: 600;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.Sqb-SelectColumns--box .Sqb-List-title .List-title-arrow {\n margin-left: auto;\n}\n.Sqb-SelectColumns--box .Sqb-List-title.active .List-item-icon {\n color: #509ee3;\n}\n.Sqb-SelectColumns--box .Sqb-List-title.shrink {\n cursor: pointer;\n}\n.Sqb-SelectColumns--box .Sqb-List-title.shrink a {\n cursor: pointer;\n}\n.Sqb-SelectColumns--box .Sqb-List-title.shrink:hover a {\n color: #509ee3;\n}\n.Sqb-SelectColumns--box .Sqb-List-title.shrink:hover a .List-item-title {\n color: #509ee3;\n}\n.Sqb-SelectColumns--box .Sqb-List-search {\n display: flex;\n align-items: center;\n flex: 1 0 auto;\n color: #b8bbc3;\n background-color: #fff;\n border: 1px solid #f0f0f0;\n font-size: 14px;\n}\n.Sqb-SelectColumns--box .Sqb-List-search span {\n line-height: 0;\n}\n.Sqb-SelectColumns--box .Sqb-List-search input {\n box-shadow: none;\n outline: 0;\n border: none !important;\n background: transparent;\n color: #4c5773;\n font-size: 1.12em;\n font-weight: 600;\n}\n.Sqb-SelectColumns--box .Sqb-List-search input::-webkit-input-placeholder {\n color: #b8bbc3;\n}\n.Sqb-SelectColumns--box .Sqb-List-search input::-ms-input-placeholder {\n color: #b8bbc3;\n}\n.Sqb-SelectColumns--box.greenGrass .Sqb-List-item:not(.disabled):hover,\n.Sqb-SelectColumns--box.greenGrass .Sqb-List-item.active {\n background-color: #88bf4d;\n}\n.Sqb-SelectColumns--box.greenGrass .Sqb-List-title.active .List-item-icon {\n color: #88bf4d;\n}\n.Sqb-SelectColumns--box.greenGrass .Sqb-List-title.shrink:hover a {\n color: #88bf4d;\n}\n.Sqb-SelectColumns--box.greenGrass .Sqb-List-title.shrink:hover a .List-item-title {\n color: #88bf4d;\n}\n.Sqb-SelectColumns--box.purple .Sqb-List-item:not(.disabled):hover,\n.Sqb-SelectColumns--box.purple .Sqb-List-item.active {\n background-color: #7172ad;\n}\n.Sqb-SelectColumns--box.purple .Sqb-List-title.active .List-item-icon {\n color: #7172ad;\n}\n.Sqb-SelectColumns--box.purple .Sqb-List-title.shrink:hover a {\n color: #7172ad;\n}\n.Sqb-SelectColumns--box.purple .Sqb-List-title.shrink:hover a .List-item-title {\n color: #7172ad;\n}\n.menu-list {\n border: none !important;\n}\n.menu-list .ant-menu-item:hover {\n color: #88bf4d !important;\n}\n.menu-list .ant-menu-item-selected {\n background-color: #88bf4d !important;\n color: #fff !important;\n border-radius: 4px !important;\n}\n";
3894
+ var css_248z$6 = ".Sqb-SelectColumns--box {\n box-sizing: border-box;\n min-width: 1em;\n max-width: 500px;\n background-color: #ffffff;\n overflow: hidden;\n}\n.Sqb-SelectColumns--box .Sqb-List-item {\n display: flex;\n border-radius: 4px;\n margin-top: 2px;\n margin-bottom: 2px;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .List-item {\n flex: auto;\n cursor: pointer;\n display: flex;\n align-items: center;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .List-item-icon {\n display: flex;\n align-items: center;\n color: #b8bbc3;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .List-item-title {\n word-break: break-word;\n word-wrap: anywhere;\n color: #4c5773;\n margin-top: 0;\n margin-bottom: 0;\n font-size: 14px;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .Field-extra {\n display: flex;\n align-items: center;\n padding: 0.5rem;\n cursor: pointer;\n border-left: 2px solid rgba(113, 114, 173, 0.1);\n color: rgba(255, 255, 255, 0.5);\n visibility: hidden;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .Field-extra h4 {\n margin-bottom: 0;\n color: inherit;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .Field-extra svg {\n color: #fff;\n margin-left: 0.5rem;\n}\n.Sqb-SelectColumns--box .Sqb-List-item .Field-extra:hover {\n color: #fff;\n}\n.Sqb-SelectColumns--box .Sqb-List-item:not(.disabled):hover,\n.Sqb-SelectColumns--box .Sqb-List-item.active {\n background-color: #509ee3;\n border-color: rgba(169, 137, 197, 0.2);\n}\n.Sqb-SelectColumns--box .Sqb-List-item:not(.disabled):hover .List-item-icon,\n.Sqb-SelectColumns--box .Sqb-List-item.active .List-item-icon {\n color: #fff !important;\n}\n.Sqb-SelectColumns--box .Sqb-List-item:not(.disabled):hover .List-item-title,\n.Sqb-SelectColumns--box .Sqb-List-item.active .List-item-title {\n color: #fff !important;\n}\n.Sqb-SelectColumns--box .Sqb-List-item:not(.disabled):hover .Field-extra,\n.Sqb-SelectColumns--box .Sqb-List-item.active .Field-extra {\n visibility: visible;\n}\n.Sqb-SelectColumns--box .Sqb-List-item.disabled .List-item-title {\n color: #949aab !important;\n}\n.Sqb-SelectColumns--box .Sqb-List-title {\n display: flex;\n border-radius: 4px;\n}\n.Sqb-SelectColumns--box .Sqb-List-title .List-item {\n flex: auto;\n cursor: pointer;\n display: flex;\n align-items: center;\n color: #4c5773;\n overflow: hidden;\n}\n.Sqb-SelectColumns--box .Sqb-List-title .List-item-icon {\n display: flex;\n align-items: center;\n}\n.Sqb-SelectColumns--box .Sqb-List-title .List-item-title {\n word-break: break-word;\n word-wrap: anywhere;\n margin-top: 0;\n margin-bottom: 0;\n font-size: 16px;\n font-weight: 600;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.Sqb-SelectColumns--box .Sqb-List-title .List-title-arrow {\n margin-left: auto;\n}\n.Sqb-SelectColumns--box .Sqb-List-title.active .List-item-icon {\n color: #509ee3;\n}\n.Sqb-SelectColumns--box .Sqb-List-title.shrink {\n cursor: pointer;\n}\n.Sqb-SelectColumns--box .Sqb-List-title.shrink .List-item {\n cursor: pointer;\n}\n.Sqb-SelectColumns--box .Sqb-List-title.shrink:hover .List-item {\n color: #509ee3;\n}\n.Sqb-SelectColumns--box .Sqb-List-title.shrink:hover .List-item .List-item-title {\n color: #509ee3;\n}\n.Sqb-SelectColumns--box .Sqb-List-search {\n display: flex;\n align-items: center;\n flex: 1 0 auto;\n color: #b8bbc3;\n background-color: #fff;\n border: 1px solid #f0f0f0;\n font-size: 14px;\n}\n.Sqb-SelectColumns--box .Sqb-List-search span {\n line-height: 0;\n}\n.Sqb-SelectColumns--box .Sqb-List-search input {\n box-shadow: none;\n outline: 0;\n border: none !important;\n background: transparent;\n color: #4c5773;\n font-size: 1.12em;\n font-weight: 600;\n}\n.Sqb-SelectColumns--box .Sqb-List-search input::-webkit-input-placeholder {\n color: #b8bbc3;\n}\n.Sqb-SelectColumns--box .Sqb-List-search input::-ms-input-placeholder {\n color: #b8bbc3;\n}\n.Sqb-SelectColumns--box.greenGrass .Sqb-List-item:not(.disabled):hover,\n.Sqb-SelectColumns--box.greenGrass .Sqb-List-item.active {\n background-color: #88bf4d;\n}\n.Sqb-SelectColumns--box.greenGrass .Sqb-List-title.active .List-item-icon {\n color: #88bf4d;\n}\n.Sqb-SelectColumns--box.greenGrass .Sqb-List-title.shrink:hover a {\n color: #88bf4d;\n}\n.Sqb-SelectColumns--box.greenGrass .Sqb-List-title.shrink:hover a .List-item-title {\n color: #88bf4d;\n}\n.Sqb-SelectColumns--box.purple .Sqb-List-item:not(.disabled):hover,\n.Sqb-SelectColumns--box.purple .Sqb-List-item.active {\n background-color: #7172ad;\n}\n.Sqb-SelectColumns--box.purple .Sqb-List-title.active .List-item-icon {\n color: #7172ad;\n}\n.Sqb-SelectColumns--box.purple .Sqb-List-title.shrink:hover a {\n color: #7172ad;\n}\n.Sqb-SelectColumns--box.purple .Sqb-List-title.shrink:hover a .List-item-title {\n color: #7172ad;\n}\n.menu-list {\n border: none !important;\n}\n.menu-list .ant-menu-item:hover {\n color: #88bf4d !important;\n}\n.menu-list .ant-menu-item-selected {\n background-color: #88bf4d !important;\n color: #fff !important;\n border-radius: 4px !important;\n}\n";
3583
3895
  styleInject(css_248z$6);
3584
3896
 
3585
3897
  const NUMBER_GROUP = [SQL_COLUMN_TYPE.FLOAT, SQL_COLUMN_TYPE.LONG, SQL_COLUMN_TYPE.CURRENCY];
@@ -3697,7 +4009,8 @@ const SelectJoinColumn = ({
3697
4009
  })));
3698
4010
  }
3699
4011
  },
3700
- children: jsxs("a", {
4012
+ children: jsxs("div", {
4013
+ className: 'List-item',
3701
4014
  children: [jsx("span", {
3702
4015
  className: 'List-item-icon',
3703
4016
  children: jsx(TableIcon, {})
@@ -3716,7 +4029,7 @@ const SelectJoinColumn = ({
3716
4029
  })]
3717
4030
  })
3718
4031
  })
3719
- }), open && jsxs(Fragment, {
4032
+ }), (open || isSummarize) && jsxs(Fragment, {
3720
4033
  children: [!isSummarize && jsx("div", {
3721
4034
  className: cx(`Sqb-List-section`),
3722
4035
  children: jsxs("div", {
@@ -3762,7 +4075,7 @@ const SelectJoinColumn = ({
3762
4075
  let quotes = name;
3763
4076
  return onGroup({
3764
4077
  ..._value,
3765
- tableUuid: _value.tableUuid || tableUuid,
4078
+ tableUuid: tableUuid || _value.tableUuid,
3766
4079
  ...v,
3767
4080
  table,
3768
4081
  tableId,
@@ -3776,7 +4089,7 @@ const SelectJoinColumn = ({
3776
4089
  }
3777
4090
  typeof onSelect === 'function' && onSelect({
3778
4091
  ..._value,
3779
- tableUuid: _value.tableUuid || tableUuid,
4092
+ tableUuid: tableUuid || _value.tableUuid,
3780
4093
  ...v,
3781
4094
  table,
3782
4095
  tableId,
@@ -3789,8 +4102,8 @@ const SelectJoinColumn = ({
3789
4102
  realName
3790
4103
  });
3791
4104
  },
3792
- children: [jsxs("a", {
3793
- className: 'p-2',
4105
+ children: [jsxs("div", {
4106
+ className: 'p-2 List-item',
3794
4107
  children: [jsx("span", {
3795
4108
  className: 'List-item-icon',
3796
4109
  children: IconMap[special_type || database_type] || jsx(LetterAaIcon, {})
@@ -3829,7 +4142,8 @@ const SelectFilterColumn = ({
3829
4142
  value,
3830
4143
  onChange,
3831
4144
  didUpdate,
3832
- isCustom: _isCustom = false
4145
+ isCustom: _isCustom = false,
4146
+ container: _container = null
3833
4147
  }) => {
3834
4148
  const [curColumn, setCurColumn] = useState(value);
3835
4149
  const [condition, setCondition] = useState(value.condition);
@@ -4246,6 +4560,7 @@ const SelectFilterColumn = ({
4246
4560
  store.setPopup2({
4247
4561
  visible: true,
4248
4562
  node: e.currentTarget,
4563
+ container: _container,
4249
4564
  content: jsx(SelectList, {
4250
4565
  value: valType,
4251
4566
  list: store.constantList || [],
@@ -4268,6 +4583,7 @@ const SelectFilterColumn = ({
4268
4583
  store.setPopup2({
4269
4584
  visible: true,
4270
4585
  node: e.currentTarget,
4586
+ container: _container,
4271
4587
  content: jsx(SelectList, {
4272
4588
  value: valType,
4273
4589
  list: [{
@@ -4302,6 +4618,7 @@ const SelectFilterColumn = ({
4302
4618
  store.setPopup2({
4303
4619
  visible: true,
4304
4620
  node: e.currentTarget,
4621
+ container: _container,
4305
4622
  content: jsx(SelectJoinColumn, {
4306
4623
  data: [..._data],
4307
4624
  value: value,
@@ -4610,7 +4927,7 @@ const SelectSummarize = ({
4610
4927
  availableData = data.map(v => {
4611
4928
  return {
4612
4929
  ...v,
4613
- columns: v.columns.filter(o => o.database_type && NUMBER_GROUP.includes(o.database_type))
4930
+ columns: v.columns.filter(o => o.database_type && (NUMBER_GROUP.includes(o.database_type) || (condition === '最大值' || condition === '最小值') && DATE_GROUP.includes(o.database_type)))
4614
4931
  };
4615
4932
  }).filter(v => v.columns.length);
4616
4933
  }
@@ -5015,17 +5332,17 @@ const IconTypeMap = new Map([[TypeEnum.filter, {
5015
5332
  name: __('SqlQueryBuilder.rowLimit'),
5016
5333
  icon: jsx(RowLimitIcon, {}),
5017
5334
  className: 'rowLimit'
5018
- }], [TypeEnum.group, {
5335
+ }], [TypeEnum.union, {
5019
5336
  name: __('SqlQueryBuilder.union'),
5020
5337
  icon: jsx(GroupIcon, {}),
5021
5338
  className: 'union'
5022
5339
  }]]);
5023
5340
  // 前端展示的icon顺序 随便改不影响逻辑
5024
- const DisplayOrder = [TypeEnum.filter, TypeEnum.summarize, TypeEnum.joinData, TypeEnum.permissionTable, TypeEnum.customColumn, TypeEnum.sort, TypeEnum.rowLimit, TypeEnum.group];
5341
+ const DisplayOrder = [TypeEnum.filter, TypeEnum.summarize, TypeEnum.joinData, TypeEnum.permissionTable, TypeEnum.customColumn, TypeEnum.sort, TypeEnum.rowLimit, TypeEnum.union];
5025
5342
  // js逻辑顺序 正常顺序
5026
- const OrderType = [TypeEnum.data, TypeEnum.joinData, TypeEnum.permissionTable, TypeEnum.customColumn, TypeEnum.filter, TypeEnum.summarize, TypeEnum.sort, TypeEnum.rowLimit, TypeEnum.group];
5343
+ const OrderType = [TypeEnum.data, TypeEnum.joinData, TypeEnum.permissionTable, TypeEnum.customColumn, TypeEnum.filter, TypeEnum.summarize, TypeEnum.sort, TypeEnum.rowLimit, TypeEnum.union];
5027
5344
  // js逻辑顺序 聚合下面的顺序是这个样子
5028
- const OrderNewType = [TypeEnum.sort, TypeEnum.rowLimit, TypeEnum.joinData, TypeEnum.permissionTable, TypeEnum.customColumn, TypeEnum.filter, TypeEnum.summarize, TypeEnum.group];
5345
+ const OrderNewType = [TypeEnum.sort, TypeEnum.rowLimit, TypeEnum.joinData, TypeEnum.permissionTable, TypeEnum.customColumn, TypeEnum.filter, TypeEnum.summarize, TypeEnum.union];
5029
5346
  const metaIcon = (size, handleClick) => {
5030
5347
  return ({
5031
5348
  type
@@ -5130,7 +5447,7 @@ const findNextIcon = (store, props) => {
5130
5447
  if (meta.table2.name) {
5131
5448
  available = OrderType.slice(curLocation + 1);
5132
5449
  } else {
5133
- available = [TypeEnum.customColumn, TypeEnum.filter, TypeEnum.summarize, TypeEnum.group];
5450
+ available = [TypeEnum.customColumn, TypeEnum.filter, TypeEnum.summarize, TypeEnum.union];
5134
5451
  }
5135
5452
  } else {
5136
5453
  if (isLast) {
@@ -5152,7 +5469,7 @@ const findNextIcon = (store, props) => {
5152
5469
  if (meta.customColumn.length || ~joinIndex && prevList[joinIndex].table2.name) {
5153
5470
  available = OrderType.slice(curLocation + 1);
5154
5471
  } else {
5155
- available = [TypeEnum.filter, TypeEnum.summarize, TypeEnum.group];
5472
+ available = [TypeEnum.filter, TypeEnum.summarize, TypeEnum.union];
5156
5473
  }
5157
5474
  } else {
5158
5475
  if (isLast) {
@@ -5185,7 +5502,7 @@ const findNextIcon = (store, props) => {
5185
5502
  if (isLast) {
5186
5503
  if (!ExistAboveGroupBy) {
5187
5504
  if (meta.group.length && !meta.by.length) ; else if (!meta.group.length && !meta.by.length) {
5188
- available = [TypeEnum.sort, TypeEnum.rowLimit, TypeEnum.group];
5505
+ available = [TypeEnum.sort, TypeEnum.rowLimit, TypeEnum.union];
5189
5506
  } else {
5190
5507
  available = OrderNewType;
5191
5508
  }
@@ -5293,6 +5610,7 @@ const TableData = props => {
5293
5610
  } = props;
5294
5611
  const store = useStore$1();
5295
5612
  let selected = Boolean(meta.table.name);
5613
+ let subQuerySelected = Boolean(meta.subquery?.[0]?.table?.name);
5296
5614
  function selectTable(e) {
5297
5615
  !meta.readonly && store.setPopup({
5298
5616
  visible: true,
@@ -5358,6 +5676,77 @@ const TableData = props => {
5358
5676
  onCancel: () => {}
5359
5677
  });
5360
5678
  };
5679
+ // 子查询弹窗
5680
+ const showSubQuery = (val = []) => {
5681
+ const {
5682
+ subToolbar,
5683
+ toolbar,
5684
+ ...other
5685
+ } = store.preProps;
5686
+ let newMetaList = store.metaList[groupIndex].list.slice()[0];
5687
+ let oldList = cloneDeep(newMetaList.subquery);
5688
+ let _toolbar = subToolbar || toolbar;
5689
+ _toolbar = _toolbar.filter(v => v !== 'group'); // 子查询不需要分组
5690
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : 0;
5691
+ let o = Modal2.openModal({
5692
+ title: __('SqlQueryBuilder.subquery'),
5693
+ transparentMask: true,
5694
+ zIndex: Number(zIndex),
5695
+ content: jsx(Fragment, {
5696
+ children: jsx(SqlVisionBuilder, {
5697
+ ...other,
5698
+ showSubquery: store._showSubquery,
5699
+ toolbar: _toolbar,
5700
+ btnText: __('SqlQueryBuilder.confirm'),
5701
+ value: val,
5702
+ onOk: newList => {
5703
+ try {
5704
+ // 子查询未改变不做操作
5705
+ if (isEqual(newList, oldList)) {
5706
+ o.close();
5707
+ return;
5708
+ }
5709
+ newMetaList.subquery = newList;
5710
+ newMetaList.table = {
5711
+ ...newList[0].table
5712
+ };
5713
+ const items = getSubColumns(newList);
5714
+ const newColumns = items.flatMap(item => item.columns);
5715
+ newMetaList.columns = newColumns;
5716
+ // (newMeta[index] as MetaJoin).expressions = [];
5717
+ store.setMeta([newMetaList], groupIndex);
5718
+ o.close();
5719
+ } catch (e) {
5720
+ console.warn(e);
5721
+ } finally {
5722
+ o.close();
5723
+ }
5724
+ }
5725
+ })
5726
+ }),
5727
+ onClose: () => {}
5728
+ });
5729
+ };
5730
+ // 切换子查询
5731
+ const switchSubQuery = () => {
5732
+ let newMetaList = store.metaList[groupIndex].list.slice()[0];
5733
+ newMetaList.isSubquery = !newMetaList.isSubquery;
5734
+ //重置表数据
5735
+ newMetaList.subquery = [];
5736
+ newMetaList.table = {
5737
+ name: '',
5738
+ // 表名
5739
+ tableUuid: '',
5740
+ id: '',
5741
+ // 表名
5742
+ alias: '',
5743
+ // 表别名
5744
+ datasourceName: '',
5745
+ // 数据源名
5746
+ datasourceId: '' // 数据源id
5747
+ };
5748
+ store.setMeta([newMetaList], groupIndex);
5749
+ };
5361
5750
  return jsx(Wrapper, {
5362
5751
  className: `Sqb-item`,
5363
5752
  children: jsxs("div", {
@@ -5368,7 +5757,29 @@ const TableData = props => {
5368
5757
  className: `Sqb-item--content`,
5369
5758
  children: jsxs("div", {
5370
5759
  className: `Sqb-NotebookCell`,
5371
- children: [jsxs("div", {
5760
+ children: [meta.isSubquery ? jsxs("div", {
5761
+ className: cx(`Sqb-TableName`, {
5762
+ notSelected: !subQuerySelected
5763
+ }),
5764
+ onClick: () => {
5765
+ showSubQuery(meta.subquery);
5766
+ },
5767
+ children: [subQuerySelected && jsx(Tooltip, {
5768
+ title: __('SqlQueryBuilder.alias'),
5769
+ children: jsx(Button, {
5770
+ className: ':Sqb-TableName-as',
5771
+ shape: 'circle',
5772
+ iconOnly: true,
5773
+ primary: true,
5774
+ icon: 'As',
5775
+ size: 'small',
5776
+ onClick: e => {
5777
+ e.stopPropagation();
5778
+ onChangeTableAlias(meta.table?.alias || '');
5779
+ }
5780
+ })
5781
+ }), subQuerySelected ? `${(meta.subquery?.[0]).table.datasourceName}.${(meta.subquery?.[0]).table.name} ${meta.table?.alias ? `as ${meta.table?.alias}` : ''} ` : __('SqlQueryBuilder.setSubQuery')]
5782
+ }) : jsxs("div", {
5372
5783
  className: cx(`Sqb-TableName`, {
5373
5784
  notSelected: !selected
5374
5785
  }),
@@ -5388,7 +5799,19 @@ const TableData = props => {
5388
5799
  }
5389
5800
  })
5390
5801
  }), selected ? `${meta.table.datasourceName}.${meta.table.name} ${meta.table?.alias ? `as ${meta.table?.alias}` : ''}` : __('SqlQueryBuilder.pickTable')]
5391
- }), selected && store.showMainColumn && store.showFields && jsx("div", {
5802
+ }), store.showSubquery && jsx(Tooltip, {
5803
+ title: __('SqlQueryBuilder.switchSubQuery'),
5804
+ children: jsx(Button, {
5805
+ disabled: meta.readonly,
5806
+ primary: meta.isSubquery,
5807
+ ghost: true,
5808
+ className: cx('mr-2 operator-icon', {
5809
+ ['subquery-icon']: !meta.isSubquery
5810
+ }),
5811
+ icon: jsx(RelatedWork, {}),
5812
+ onClick: switchSubQuery
5813
+ })
5814
+ }), selected && store.showFields && jsx("div", {
5392
5815
  className: `Sqb-TableColumns`,
5393
5816
  onClick: selectColumns,
5394
5817
  children: __('SqlQueryBuilder.columns')
@@ -5410,8 +5833,8 @@ var FlagLocation;
5410
5833
  })(FlagLocation || (FlagLocation = {}));
5411
5834
  var ExpressionsEnum;
5412
5835
  (function (ExpressionsEnum) {
5413
- ExpressionsEnum["LEFT"] = "left_column";
5414
- ExpressionsEnum["RIGHT"] = "right_column";
5836
+ ExpressionsEnum["LEFT"] = "left";
5837
+ ExpressionsEnum["RIGHT"] = "right";
5415
5838
  })(ExpressionsEnum || (ExpressionsEnum = {}));
5416
5839
  const JoinData = props => {
5417
5840
  const {
@@ -5426,7 +5849,12 @@ const JoinData = props => {
5426
5849
  let table1Selected = Boolean(meta.table1.name);
5427
5850
  let table2Selected = Boolean(meta.table2.name);
5428
5851
  let subQuerySelected = Boolean(meta.subquery?.[0]?.table?.name);
5429
- let columnsSelected = meta.table1.column && meta.table2.column;
5852
+ let columnsSelected = meta.table1.quotes && meta.table2.quotes;
5853
+ // useEffect(() => {
5854
+ // let newMetaList = store.metaList[groupIndex].list.slice();
5855
+ // newMetaList[index] = setQuotes(meta);
5856
+ // store.setMeta(newMetaList, groupIndex);
5857
+ // }, []);
5430
5858
  function selectColumns(e) {
5431
5859
  let columns = meta.columns;
5432
5860
  !meta.readonly && store.setPopup({
@@ -5495,8 +5923,9 @@ const JoinData = props => {
5495
5923
  name: tableName,
5496
5924
  tableUuid: data.tableUuid || uuidv4('table'),
5497
5925
  alias,
5498
- column: '',
5499
- column_id: '',
5926
+ fieldAlias: '',
5927
+ fieldUuid: '',
5928
+ quotes: '',
5500
5929
  datasourceId: data.datasourceId,
5501
5930
  datasourceName: data.datasourceName
5502
5931
  };
@@ -5539,8 +5968,9 @@ const JoinData = props => {
5539
5968
  let type = node.getAttribute('v-data');
5540
5969
  let data = [];
5541
5970
  let value = {
5542
- name: meta[type].column,
5543
- id: meta[type].column_id,
5971
+ name: meta[type].quotes || meta[type].fieldAlias,
5972
+ quotes: meta[type].quotes,
5973
+ id: meta[type].fieldUuid,
5544
5974
  table: meta[type].name,
5545
5975
  tableId: meta[type].id,
5546
5976
  fieldUuid: meta[type].fieldUuid || uuidv4('field'),
@@ -5658,15 +6088,27 @@ const JoinData = props => {
5658
6088
  sql,
5659
6089
  datasourceId,
5660
6090
  datasourceName,
5661
- id = ''
6091
+ id = '',
6092
+ fieldAlias = '',
6093
+ fieldUuid = '',
6094
+ quotes,
6095
+ tableUuid
5662
6096
  } = record;
5663
6097
  let newMeta = store.metaList[groupIndex].list.slice();
5664
- newMeta[index][type].column = name;
5665
- newMeta[index][type].column_id = id;
6098
+ if (alias === SummarizeAlias$1) {
6099
+ newMeta[index][type].fieldAlias = fieldAlias;
6100
+ newMeta[index][type].fieldUuid = fieldUuid;
6101
+ newMeta[index][type].quotes = quotes;
6102
+ } else {
6103
+ newMeta[index][type].fieldAlias = name;
6104
+ newMeta[index][type].fieldUuid = id;
6105
+ newMeta[index][type].quotes = name;
6106
+ }
5666
6107
  if (type === FlagLocation.TABLE_1) {
5667
6108
  if (newMeta[index][type].alias !== alias) {
5668
6109
  newMeta[index][type].alias = alias;
5669
6110
  newMeta[index][type].name = table;
6111
+ newMeta[index][type].tableUuid = tableUuid;
5670
6112
  newMeta[index][type].datasourceId = datasourceId;
5671
6113
  newMeta[index][type].datasourceName = datasourceName;
5672
6114
  newMeta[index].expressions = [];
@@ -5690,8 +6132,8 @@ const JoinData = props => {
5690
6132
  let index = findIndex(store.metaList[groupIndex].list, meta);
5691
6133
  let table_type = type === ExpressionsEnum.LEFT ? FlagLocation.TABLE_1 : FlagLocation.TABLE_2;
5692
6134
  let value = {
5693
- name: meta.expressions[_ind][type],
5694
- id: meta.expressions[_ind][`${type}_id`],
6135
+ name: meta.expressions[_ind][`${type}_quotes`] || meta.expressions[_ind][`${type}_fieldAlias`],
6136
+ id: meta.expressions[_ind][`${type}_fieldUuid`],
5695
6137
  table: meta[table_type].name,
5696
6138
  fieldUuid: meta[table_type].fieldUuid || uuidv4('field'),
5697
6139
  fieldAlias: meta[table_type].fieldAlias || '',
@@ -5816,11 +6258,23 @@ const JoinData = props => {
5816
6258
  sql,
5817
6259
  datasourceId,
5818
6260
  datasourceName,
5819
- id = ''
6261
+ id = '',
6262
+ fieldAlias,
6263
+ fieldUuid,
6264
+ quotes = ''
5820
6265
  } = record;
5821
6266
  let newMeta = store.metaList[groupIndex].list.slice();
5822
- newMeta[index].expressions[_ind][type] = name;
5823
- newMeta[index].expressions[_ind][`${type}_id`] = id;
6267
+ if (alias === SummarizeAlias$1) {
6268
+ newMeta[index].expressions[_ind][`${type}_fieldAlias`] = fieldAlias;
6269
+ newMeta[index].expressions[_ind][`${type}_fieldUuid`] = fieldUuid;
6270
+ newMeta[index].expressions[_ind][`${type}_quotes`] = quotes;
6271
+ } else {
6272
+ newMeta[index].expressions[_ind][`${type}_fieldAlias`] = name;
6273
+ newMeta[index].expressions[_ind][`${type}_fieldUuid`] = id;
6274
+ newMeta[index].expressions[_ind][`${type}_quotes`] = name;
6275
+ }
6276
+ // (newMeta[index] as MetaJoin).expressions[_ind][type] = name;
6277
+ // (newMeta[index] as MetaJoin).expressions[_ind][`${type}_id`] = id;
5824
6278
  store.setMeta(newMeta, groupIndex);
5825
6279
  store.setPopup({
5826
6280
  visible: false
@@ -5902,10 +6356,11 @@ const JoinData = props => {
5902
6356
  let oldList = cloneDeep(newMeta[index].subquery);
5903
6357
  let _toolbar = subToolbar || toolbar;
5904
6358
  _toolbar = _toolbar.filter(v => v !== 'group'); // 子查询不需要分组
6359
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : 0;
5905
6360
  let o = Modal2.openModal({
5906
6361
  title: __('SqlQueryBuilder.subquery'),
5907
6362
  transparentMask: true,
5908
- zIndex: 200,
6363
+ zIndex: Number(zIndex),
5909
6364
  content: jsx(Fragment, {
5910
6365
  children: jsx(SqlVisionBuilder, {
5911
6366
  ...other,
@@ -5923,8 +6378,8 @@ const JoinData = props => {
5923
6378
  newMeta[index].subquery = newList;
5924
6379
  newMeta[index].table2 = {
5925
6380
  ...newList[0].table,
5926
- column: '',
5927
- column_id: ''
6381
+ fieldAlias: '',
6382
+ fieldUuid: ''
5928
6383
  };
5929
6384
  const items = getSubColumns(newList);
5930
6385
  const newColumns = items.flatMap(item => item.columns);
@@ -5949,8 +6404,9 @@ const JoinData = props => {
5949
6404
  let newMeta = store.metaList[groupIndex].list.slice();
5950
6405
  newMeta[index].isSubquery = !newMeta[index].isSubquery;
5951
6406
  newMeta[index].table2 = {
5952
- column: '',
5953
- column_id: '',
6407
+ quotes: '',
6408
+ fieldAlias: '',
6409
+ fieldUuid: '',
5954
6410
  name: '',
5955
6411
  // 表名
5956
6412
  tableUuid: '',
@@ -6043,7 +6499,7 @@ const JoinData = props => {
6043
6499
  onChangeTableAlias(meta.table2?.alias || '');
6044
6500
  }
6045
6501
  })
6046
- }), subQuerySelected ? `${meta.subquery?.[0].table.datasourceName}.${meta.subquery?.[0].table.name} ${meta.table2?.alias ? `as ${meta.table2?.alias}` : ''} ` : __('SqlQueryBuilder.setSubQuery')]
6502
+ }), subQuerySelected ? `${(meta.subquery?.[0]).table.datasourceName}.${(meta.subquery?.[0]).table.name} ${meta.table2?.alias ? `as ${meta.table2?.alias}` : ''} ` : __('SqlQueryBuilder.setSubQuery')]
6047
6503
  }) : jsxs("div", {
6048
6504
  className: cx(`Sqb-TableName`, {
6049
6505
  notSelected: !table2Selected
@@ -6083,23 +6539,23 @@ const JoinData = props => {
6083
6539
  children: "on"
6084
6540
  }), jsx("div", {
6085
6541
  className: cx(`Sqb-TableName`, {
6086
- notSelected: !meta.table1.column
6542
+ notSelected: !meta.table1.quotes
6087
6543
  }),
6088
6544
  "v-data": FlagLocation.TABLE_1,
6089
6545
  onClick: selectJoinColumn,
6090
- children: meta.table1.column ? meta.table1.column : __('SqlQueryBuilder.pickTable')
6546
+ children: meta.table1.quotes ? meta.table1.quotes : __('SqlQueryBuilder.pickTable')
6091
6547
  }), jsx("span", {
6092
6548
  className: 'mr-2 text-gray-500',
6093
6549
  children: "="
6094
6550
  }), jsx("div", {
6095
6551
  className: cx(`Sqb-TableName`, {
6096
- notSelected: !meta.table2.column
6552
+ notSelected: !meta.table2.quotes
6097
6553
  }),
6098
6554
  "v-data": FlagLocation.TABLE_2,
6099
6555
  onClick: selectJoinColumn,
6100
- children: meta.table2.column ? meta.table2.column : __('SqlQueryBuilder.pickTable')
6556
+ children: meta.table2.quotes ? meta.table2.quotes : __('SqlQueryBuilder.pickTable')
6101
6557
  })]
6102
- }), meta.table1.column_id && meta.table2.column_id && meta.expressions?.map((v, i) => {
6558
+ }), meta.table1.fieldUuid && meta.table2.fieldUuid && meta.expressions?.map((v, i) => {
6103
6559
  return jsxs("div", {
6104
6560
  className: cx(`Sqb-where block`),
6105
6561
  children: [jsx("span", {
@@ -6128,12 +6584,12 @@ const JoinData = props => {
6128
6584
  children: v.left_constant ? v.left_constant : __('SqlQueryBuilder.pickConstant')
6129
6585
  }), (!v.left_type || v.left_type === 'field') && jsx("div", {
6130
6586
  className: cx(`Sqb-TableName`, {
6131
- notSelected: !v.left_column
6587
+ notSelected: !v.left_quotes
6132
6588
  }),
6133
6589
  "v-data": ExpressionsEnum.LEFT,
6134
6590
  "v-index": i,
6135
6591
  onClick: selectMoreJoinColumn,
6136
- children: v.left_column ? v.left_column : __('SqlQueryBuilder.pickTable')
6592
+ children: v.left_quotes ? v.left_quotes : __('SqlQueryBuilder.pickTable')
6137
6593
  }), jsx(Tooltip, {
6138
6594
  title: __('SqlQueryBuilder.switch'),
6139
6595
  children: jsx(Button, {
@@ -6172,12 +6628,12 @@ const JoinData = props => {
6172
6628
  children: v.right_constant ? v.right_constant : __('SqlQueryBuilder.pickConstant')
6173
6629
  }), (!v.right_type || v.right_type === 'field') && jsx("div", {
6174
6630
  className: cx(`Sqb-TableName`, {
6175
- notSelected: !v.right_column
6631
+ notSelected: !v.right_quotes
6176
6632
  }),
6177
6633
  "v-data": ExpressionsEnum.RIGHT,
6178
6634
  "v-index": i,
6179
6635
  onClick: selectMoreJoinColumn,
6180
- children: v.right_column ? v.right_column : __('SqlQueryBuilder.pickTable')
6636
+ children: v.right_quotes ? v.right_quotes : __('SqlQueryBuilder.pickTable')
6181
6637
  }), jsx(Tooltip, {
6182
6638
  title: __('SqlQueryBuilder.switch'),
6183
6639
  children: jsx(Button, {
@@ -6203,16 +6659,17 @@ const JoinData = props => {
6203
6659
  let newMeta = store.metaList[groupIndex].list.slice();
6204
6660
  newMeta[index].expressions.splice(i + 1, 0, {
6205
6661
  operator: 'and',
6206
- left_column: '',
6207
- left_column_id: '',
6662
+ left_fieldAlias: '',
6663
+ left_fieldUuid: '',
6664
+ left_quotes: '',
6208
6665
  left_string: '',
6209
- left_isString: false,
6210
6666
  left_type: 'field',
6211
6667
  left_constant: '',
6212
- right_column: '',
6213
- right_column_id: '',
6668
+ right_fieldAlias: '',
6669
+ right_fieldUuid: '',
6670
+ right_quotes: '',
6214
6671
  right_string: '',
6215
- right_isString: false,
6672
+ // right_isString: false,
6216
6673
  right_type: 'field',
6217
6674
  right_constant: ''
6218
6675
  });
@@ -6235,7 +6692,7 @@ const JoinData = props => {
6235
6692
  })
6236
6693
  })]
6237
6694
  }, i);
6238
- }), meta.table1.column_id && meta.table2.column_id && (meta.expressions?.length || 0) < 1 && jsx(Tooltip, {
6695
+ }), meta.table1.fieldUuid && meta.table2.fieldUuid && (meta.expressions?.length || 0) < 1 && jsx(Tooltip, {
6239
6696
  title: __('SqlQueryBuilder.add'),
6240
6697
  children: jsx(Button, {
6241
6698
  disabled: meta.readonly,
@@ -6248,16 +6705,17 @@ const JoinData = props => {
6248
6705
  let newMeta = store.metaList[groupIndex].list.slice();
6249
6706
  newMeta[index].expressions = [{
6250
6707
  operator: 'and',
6251
- left_column: '',
6252
- left_column_id: '',
6708
+ left_fieldAlias: '',
6709
+ left_fieldUuid: '',
6710
+ left_quotes: '',
6253
6711
  left_string: '',
6254
- left_isString: false,
6255
6712
  left_type: 'field',
6256
6713
  left_constant: '',
6257
- right_column: '',
6258
- right_column_id: '',
6714
+ right_fieldAlias: '',
6715
+ right_fieldUuid: '',
6716
+ right_quotes: '',
6259
6717
  right_string: '',
6260
- right_isString: false,
6718
+ // right_isString: false,
6261
6719
  right_constant: '',
6262
6720
  right_type: 'field'
6263
6721
  }];
@@ -6406,12 +6864,12 @@ const CaseEditor = props => {
6406
6864
  onOk,
6407
6865
  onCancel
6408
6866
  } = props;
6409
- const [popup, setPopup] = useState({
6410
- visible: false
6411
- }); // 弹框信息
6867
+ // const [popup, setPopup] = useState<PopupType>({ visible: false }); // 弹框信息
6412
6868
  const [caseList, setCaseList] = useState(value.formulaList || []);
6413
6869
  const [name, setName] = useState(value?.name || ''); // 表达式名字
6414
6870
  const [ind, setInd] = useState(-1);
6871
+ const ref = useRef(null);
6872
+ const store = useStore$1();
6415
6873
  const filterCase = useMemo(() => {
6416
6874
  const hasCase = caseList.some(item => item.type === OptionsTypeEnum.OTHER && item.operator === 'case');
6417
6875
  if (hasCase) {
@@ -6423,24 +6881,22 @@ const CaseEditor = props => {
6423
6881
  const usable = useMemo(() => {
6424
6882
  return Array.from(caseList).length > 0 && name;
6425
6883
  }, [caseList, name]);
6426
- const popupContent = useMemo(() => {
6427
- let {
6428
- visible,
6429
- content
6430
- } = popup;
6431
- if (!visible) return null;
6432
- return content;
6433
- }, [popup]);
6884
+ // const popupContent = useMemo(() => {
6885
+ // let { visible, content } = popup;
6886
+ // if (!visible) return null;
6887
+ // return content;
6888
+ // }, [popup]);
6434
6889
  function closePopup() {
6435
- setPopup({
6890
+ store.setPopup({
6436
6891
  visible: false
6437
6892
  });
6438
6893
  }
6439
6894
  // 字段
6440
6895
  function handleField(e, i, val) {
6441
- setPopup({
6896
+ store.setPopup({
6442
6897
  visible: true,
6443
6898
  node: e.currentTarget,
6899
+ container: ref.current,
6444
6900
  content: jsx(SelectJoinColumn, {
6445
6901
  data: data,
6446
6902
  value: val,
@@ -6448,8 +6904,13 @@ const CaseEditor = props => {
6448
6904
  isGroup: true,
6449
6905
  // @ts-ignore
6450
6906
  onGroup: data => {
6907
+ let _data = cloneDeep(data);
6908
+ if (_data.alias != SummarizeAlias$1) {
6909
+ _data.fieldAlias = _data.name;
6910
+ _data.fieldUuid = uuidv4('field');
6911
+ }
6451
6912
  const _caseList = caseList.slice();
6452
- _caseList[i].expression = data;
6913
+ _caseList[i].expression = _data;
6453
6914
  setCaseList(_caseList);
6454
6915
  closePopup();
6455
6916
  }
@@ -6465,16 +6926,23 @@ const CaseEditor = props => {
6465
6926
  };
6466
6927
  // 表达式
6467
6928
  function handleExpression(e, i, val) {
6468
- setPopup({
6929
+ store.setPopup({
6469
6930
  visible: true,
6470
6931
  node: e.currentTarget,
6932
+ container: ref.current,
6471
6933
  content: jsx(SelectFilter, {
6472
6934
  isCustom: true,
6935
+ container: ref.current,
6473
6936
  data: data,
6474
6937
  value: val,
6475
6938
  onChange: data => {
6939
+ let _data = cloneDeep(data);
6940
+ if (_data.alias != SummarizeAlias$1) {
6941
+ _data.fieldAlias = _data.name;
6942
+ _data.fieldUuid = uuidv4('field');
6943
+ }
6476
6944
  const _caseList = caseList.slice();
6477
- _caseList[i].expression = data;
6945
+ _caseList[i].expression = _data;
6478
6946
  setCaseList(_caseList);
6479
6947
  closePopup();
6480
6948
  }
@@ -6517,8 +6985,7 @@ const CaseEditor = props => {
6517
6985
  const _onOk = () => {
6518
6986
  typeof onOk === 'function' && onOk?.({
6519
6987
  name,
6520
- formulaList: caseList,
6521
- formula: ''
6988
+ formulaList: caseList
6522
6989
  });
6523
6990
  };
6524
6991
  // 分段
@@ -6666,6 +7133,7 @@ const CaseEditor = props => {
6666
7133
  };
6667
7134
  return jsxs("div", {
6668
7135
  className: 'custom-box',
7136
+ ref: ref,
6669
7137
  children: [jsx(VisualBox$1, {
6670
7138
  children: jsx("div", {
6671
7139
  className: `Sqb-item Sqb-case-editor mb-2 mt-2`,
@@ -6803,13 +7271,6 @@ const CaseEditor = props => {
6803
7271
  })]
6804
7272
  })
6805
7273
  })
6806
- }), jsx(Popup, {
6807
- visible: popup.visible,
6808
- closable: true,
6809
- node: popup.node,
6810
- innerSpacing: popup.innerSpacing,
6811
- hideVisible: closePopup,
6812
- children: popupContent
6813
7274
  }), jsx("div", {
6814
7275
  className: `btns p-4`,
6815
7276
  children: jsxs("div", {
@@ -6941,14 +7402,15 @@ const CustomColumn = props => {
6941
7402
  }
6942
7403
  return data;
6943
7404
  }
6944
- // 子查询弹窗
7405
+ // 自定义弹窗
6945
7406
  const showSubQuery = (e, i) => {
6946
7407
  let newMeta = store.metaList[groupIndex].list.slice();
6947
7408
  const _value = newMeta[index].customColumn[i] || [];
7409
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : 0;
6948
7410
  let o = Modal2.openModal({
6949
7411
  title: __('SqlQueryBuilder.customExpression'),
6950
7412
  transparentMask: true,
6951
- zIndex: 200,
7413
+ zIndex: Number(zIndex),
6952
7414
  content: jsx(Fragment, {
6953
7415
  children: jsx(Provider, {
6954
7416
  value: store,
@@ -7208,7 +7670,7 @@ const Filter = props => {
7208
7670
  let newMeta = store.metaList[groupIndex].list.slice();
7209
7671
  let val = filter[i];
7210
7672
  if (val.type === Filter_TypeEnum.NOT_EXISTS) {
7211
- showSubQuery(i, '');
7673
+ showNotExists(i, '');
7212
7674
  return;
7213
7675
  }
7214
7676
  let data = getColumns();
@@ -7307,10 +7769,10 @@ const Filter = props => {
7307
7769
  newMeta[index].filter = [..._filter];
7308
7770
  setInd(-1);
7309
7771
  };
7310
- // 子查询弹窗
7311
- const showSubQuery = (i, position) => {
7772
+ // NotExists 窗口
7773
+ const showNotExists = (i, position) => {
7312
7774
  const {
7313
- subToolbar,
7775
+ notExistsToolbar,
7314
7776
  toolbar,
7315
7777
  ...other
7316
7778
  } = store.preProps;
@@ -7318,12 +7780,13 @@ const Filter = props => {
7318
7780
  let index = findIndex(store.metaList[groupIndex].list, meta);
7319
7781
  let _value = position ? [] : newMeta[index].filter[i]?.subquery || [];
7320
7782
  let oldList = position ? [] : cloneDeep(newMeta[index].filter[i]?.subquery || []);
7321
- let _toolbar = subToolbar || toolbar;
7783
+ let _toolbar = notExistsToolbar || toolbar;
7322
7784
  _toolbar = _toolbar.filter(v => v !== 'group'); // 子查询不需要分组
7785
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : null;
7323
7786
  let o = Modal2.openModal({
7324
7787
  title: 'NOT EXISTS',
7325
7788
  transparentMask: true,
7326
- zIndex: 200,
7789
+ zIndex: Number(zIndex),
7327
7790
  content: jsx(Fragment, {
7328
7791
  children: jsx(SqlVisionBuilder, {
7329
7792
  ...other,
@@ -7341,7 +7804,7 @@ const Filter = props => {
7341
7804
  }
7342
7805
  const _tem = {
7343
7806
  subquery: newList,
7344
- quotes: `${newList?.[0].table.datasourceName}.${newList?.[0].table.alias || newList?.[0].table.name}`,
7807
+ quotes: buildSqlQuery(newList),
7345
7808
  condition: '',
7346
7809
  table: '',
7347
7810
  tableId: '',
@@ -7416,7 +7879,7 @@ const Filter = props => {
7416
7879
  if (type === Filter_TypeEnum.EXPRESSION) {
7417
7880
  handleAdd(_e);
7418
7881
  } else if (type === Filter_TypeEnum.NOT_EXISTS) {
7419
- showSubQuery(_index, _type);
7882
+ showNotExists(_index, _type);
7420
7883
  }
7421
7884
  }
7422
7885
  })
@@ -7483,7 +7946,7 @@ const Filter = props => {
7483
7946
  }, i) : jsxs("div", {
7484
7947
  className: `Sqb-TableName purple-name`,
7485
7948
  onClick: e => handleUpdate(e, i),
7486
- children: [v.quotes, jsx("span", {
7949
+ children: [v.type === Filter_TypeEnum.NOT_EXISTS ? 'not exitis ( * )' : v.quotes, jsx("span", {
7487
7950
  style: {
7488
7951
  fontSize: 0
7489
7952
  },
@@ -7527,7 +7990,7 @@ const Filter = props => {
7527
7990
  if (typeof v === 'string') {
7528
7991
  return v;
7529
7992
  } else if (v.type === Filter_TypeEnum.NOT_EXISTS) {
7530
- return 'not exitis ( * )';
7993
+ return `${buildSqlQuery(v.subquery)}`;
7531
7994
  } else {
7532
7995
  return v.quotes;
7533
7996
  }
@@ -7659,10 +8122,10 @@ const GroupBy = props => {
7659
8122
  newMeta[index].by.splice(i, 1, data);
7660
8123
  // @ts-ignore
7661
8124
  newMeta[index].by = newMeta[index].by.map(v => {
7662
- const fieldAlias = v.fieldAlias || `${v.alias}__${v.name}`;
8125
+ const fieldAlias = `${v.alias}__${v.name}`;
7663
8126
  return {
7664
8127
  ...v,
7665
- sql: `${v.alias}.${v.realName || v.name} AS ${fieldAlias}`,
8128
+ sql: `${v.alias}.${v.realName || v.name}`,
7666
8129
  fieldAlias: fieldAlias
7667
8130
  };
7668
8131
  });
@@ -7693,8 +8156,8 @@ const GroupBy = props => {
7693
8156
  quotes: '',
7694
8157
  datasourceId: '',
7695
8158
  datasourceName: '',
7696
- column: '',
7697
- column_id: '',
8159
+ // column: '',
8160
+ // column_id: '',
7698
8161
  summarizeType: MetaSummarize_Enum.BY
7699
8162
  };
7700
8163
  store.setPopup({
@@ -7711,10 +8174,10 @@ const GroupBy = props => {
7711
8174
  newMeta[index].by.push(data);
7712
8175
  // @ts-ignore
7713
8176
  newMeta[index].by = newMeta[index].by.map(v => {
7714
- const fieldAlias = v.fieldAlias || `${v.alias}__${v.name}`;
8177
+ const fieldAlias = `${v.alias}__${v.name}`;
7715
8178
  return {
7716
8179
  ...v,
7717
- sql: `${v.alias}.${v.realName || v.name} AS ${fieldAlias}`,
8180
+ sql: `${v.alias}.${v.realName || v.name}`,
7718
8181
  fieldAlias: fieldAlias,
7719
8182
  fieldUuid: uuidv4('field'),
7720
8183
  summarizeType: MetaSummarize_Enum.BY
@@ -7955,8 +8418,8 @@ const SelectIndex = props => {
7955
8418
  quotes: '',
7956
8419
  datasourceId: '',
7957
8420
  datasourceName: '',
7958
- column: '',
7959
- column_id: '',
8421
+ // column: '',
8422
+ // column_id: '',
7960
8423
  summarizeType: MetaSummarize_Enum.GROUP
7961
8424
  };
7962
8425
  store.setPopup({
@@ -8526,7 +8989,8 @@ const Metabase = props => {
8526
8989
  } = props;
8527
8990
  const store = useStore$1();
8528
8991
  const [saveLoading, setSaveLoading] = useState(false);
8529
- const popupContainer = useRef();
8992
+ // const popupContainer = useRef();
8993
+ // store.setPopupContainer(popupContainer);
8530
8994
  const popupContent = useMemo(() => {
8531
8995
  let {
8532
8996
  visible,
@@ -8545,40 +9009,35 @@ const Metabase = props => {
8545
9009
  }, [store.popupData2]);
8546
9010
  const onSave = async () => {
8547
9011
  let intercept = false; // 是否返回
9012
+ const _metaList = splitByUnion(store.metaList);
8548
9013
  store.metaList.map(v => {
8549
- if (v.type !== 'group' && !(v.list?.[0]).table.name) {
9014
+ if (v.type !== 'union' && !(v.list?.[0]).table.name) {
8550
9015
  intercept = true;
8551
9016
  return Toast.warning(__('data.pleaseSelectDataTable'));
8552
9017
  }
8553
9018
  });
8554
9019
  if (saveLoading || intercept) return null;
8555
9020
  setSaveLoading(true);
8556
- if (store.toolbar.includes('group')) {
8557
- // 分组
8558
- await onOk?.(store.metaList);
8559
- } else {
8560
- // 非分组
8561
- await onOk?.(store.metaList[0].list);
8562
- }
9021
+ await onOk?.(_metaList);
8563
9022
  setSaveLoading(false);
8564
9023
  };
8565
- let zIndex = popupContainer.current ? getMaxZIndexInParents(popupContainer.current) : null;
9024
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : null;
8566
9025
  return (
8567
9026
  // @ts-ignore
8568
9027
  jsx(VisualBox, {
8569
- ref: popupContainer,
9028
+ ref: store.popupContainer,
8570
9029
  children: jsxs("div", {
8571
9030
  className: 'Sqb',
8572
9031
  children: [store.metaList.map((v, index) => {
8573
- if (v.type === 'group' && v.operator) {
9032
+ if (v.type === 'union' && v.union) {
8574
9033
  return jsx("div", {
8575
9034
  className: cx(`Sqb-list`),
8576
9035
  children: jsx(RowLimit$1, {
8577
- operator: v.operator,
9036
+ union: v.union,
8578
9037
  meta: v,
8579
9038
  groupIndex: index
8580
9039
  })
8581
- }, 'group' + index);
9040
+ }, 'union' + index);
8582
9041
  }
8583
9042
  return jsx("div", {
8584
9043
  className: cx(`Sqb-list`),
@@ -8603,8 +9062,8 @@ const Metabase = props => {
8603
9062
  disabled: saveLoading,
8604
9063
  onClick: onSave,
8605
9064
  children: btnText || __('SqlQueryBuilder.visualize')
8606
- }) : null, popupContainer.current && jsx(Popup, {
8607
- container: popupContainer.current,
9065
+ }) : null, store.popupContainer.current && jsx(Popup, {
9066
+ container: store.popupData.container || store.popupContainer.current,
8608
9067
  visible: store.popupData.visible,
8609
9068
  node: store.popupData.node,
8610
9069
  closable: store.popupClosable,
@@ -8615,8 +9074,8 @@ const Metabase = props => {
8615
9074
  });
8616
9075
  },
8617
9076
  children: popupContent
8618
- }), popupContainer.current && jsx(Popup, {
8619
- container: popupContainer.current,
9077
+ }), store.popupContainer.current && jsx(Popup, {
9078
+ container: store.popupData2.container || store.popupContainer.current,
8620
9079
  visible: store.popupData2.visible,
8621
9080
  node: store.popupData2.node,
8622
9081
  closable: store.popupClosable2,
@@ -8665,15 +9124,9 @@ const SqlVisionBuilder = /*#__PURE__*/React__default.forwardRef((props, ref) =>
8665
9124
  store.setProps(props);
8666
9125
  }, [props]);
8667
9126
  useEffect(() => {
8668
- if (toolbar.includes('group')) {
8669
- store.setPreData(value);
8670
- } else {
8671
- store.setPreData([{
8672
- name: 'default',
8673
- list: value
8674
- }]);
8675
- }
8676
- }, [value, toolbar]);
9127
+ const _value = reassembleByUnion(value);
9128
+ store.setPreData(_value);
9129
+ }, [value]);
8677
9130
  useEffect(() => {
8678
9131
  store.setSourceList(sourceList);
8679
9132
  }, [sourceList]);