@gingkoo/pandora-metabase 1.0.0-alpha.3 → 1.0.0-alpha.30

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.3
2
+ * @gingkoo/pandora-metabase v1.0.0-alpha.30
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({});
@@ -154,6 +154,36 @@ var EleComponentEnum;
154
154
  EleComponentEnum["select"] = "select";
155
155
  })(EleComponentEnum || (EleComponentEnum = {}));
156
156
 
157
+ //获取指定名称的cookie值
158
+ function getCookie(name) {
159
+ // (^| )name=([^;]*)(;|$),match[0]为与整个正则表达式匹配的字符串,match[i]为正则表达式捕获数组相匹配的数组;
160
+ var arr = document.cookie.match(new RegExp('(^| )' + name + '=([^;]*)(;|$)'));
161
+ if (arr != null) {
162
+ console.log(arr);
163
+ return arr[2];
164
+ }
165
+ return null;
166
+ }
167
+
168
+ const locales = {};
169
+ const activeLocale = getCookie('LOCALE') || 'zh';
170
+ const isEn = activeLocale === 'en';
171
+ const register = (name, data) => {
172
+ if (name in locales) {
173
+ console.warn(`[i18n] ${name} has been registered`);
174
+ } else {
175
+ locales[name] = data;
176
+ }
177
+ };
178
+ const __ = name => {
179
+ if (activeLocale in locales) {
180
+ return locales[activeLocale][name] || '';
181
+ } else {
182
+ console.warn(`[i18n] locale not found`);
183
+ return '';
184
+ }
185
+ };
186
+
157
187
  // import { SummarizeAlias } from './index';
158
188
  const SummarizeAlias$1 = 'source';
159
189
  const NUMBER_GROUP$1 = [SQL_COLUMN_TYPE.FLOAT, SQL_COLUMN_TYPE.LONG, SQL_COLUMN_TYPE.CURRENCY];
@@ -278,7 +308,6 @@ const summarizeToSql = (arr, record) => {
278
308
  condition,
279
309
  alias,
280
310
  name,
281
- fieldAlias,
282
311
  realName = ''
283
312
  } = record;
284
313
  let index = arr.indexOf(record);
@@ -339,9 +368,10 @@ const summarizeToSql = (arr, record) => {
339
368
  count++;
340
369
  }
341
370
  });
342
- as = fieldAlias || as + (count ? '_' + (count + 1) : '');
371
+ as = as + (count ? '_' + (count + 1) : '');
343
372
  return {
344
- sql: sql + ' AS ' + as,
373
+ sql: sql,
374
+ // + ' AS ' + as,
345
375
  fieldAlias: as
346
376
  };
347
377
  };
@@ -467,15 +497,15 @@ const handleNesting = data => {
467
497
  if (customColumn && customColumn.customColumn.length) {
468
498
  obj.customColumns = customColumn.customColumn.map(v => {
469
499
  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
- })
500
+ alias: v.name
501
+ // formula: v.formula.replace(/\[.*?\]/g, (column: string): string => {
502
+ // let str = column.substr(1, column.length - 2);
503
+ // if (~str.indexOf('->')) {
504
+ // let _str = str.replace(/ /g, '').split('->');
505
+ // return `${_str[0]}.${_str[1]}`;
506
+ // }
507
+ // return str;
508
+ // }),
479
509
  };
480
510
  });
481
511
  }
@@ -626,9 +656,8 @@ const getSubColumns = metaList => {
626
656
  metaKey: -1,
627
657
  type: TypeEnum.customColumn,
628
658
  customColumn: [{
629
- name: '',
630
- // 用户起的别名
631
- formula: '' // 公式}];
659
+ name: '' // 用户起的别名
660
+ // formula: '', // 公式}];
632
661
  }]
633
662
  };
634
663
  let {
@@ -650,7 +679,9 @@ const getSubColumns = metaList => {
650
679
  return {
651
680
  name_zh: v.quotes,
652
681
  ...v,
653
- name: v.quotes,
682
+ name: v.fieldAlias || v.name,
683
+ fieldAlias: '',
684
+ // fieldUuid: uuidv4('field'),
654
685
  realName: v.sql?.split(' AS ')?.[1] || '',
655
686
  // name_zh: '',
656
687
  database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
@@ -664,7 +695,9 @@ const getSubColumns = metaList => {
664
695
  return {
665
696
  name_zh: v.quotes,
666
697
  ...v,
667
- name: v.quotes,
698
+ name: v.fieldAlias || v.name,
699
+ fieldAlias: '',
700
+ // fieldUuid: uuidv4('field'),
668
701
  realName: v.sql?.split(' AS ')?.[1] || '',
669
702
  // name_zh: '',
670
703
  database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
@@ -681,10 +714,18 @@ const getSubColumns = metaList => {
681
714
  data = data.concat(
682
715
  // @ts-ignore
683
716
  joinData.map(v => {
717
+ const columns = v.columns.map(column => {
718
+ return {
719
+ ...column,
720
+ name: column.fieldAlias || column.name,
721
+ fieldAlias: ''
722
+ // fieldUuid: uuidv4('field'),
723
+ };
724
+ });
684
725
  return {
685
726
  alias: v.table2.alias,
686
727
  table: v.table2.name,
687
- columns: v.columns
728
+ columns: columns
688
729
  };
689
730
  }));
690
731
  }
@@ -692,16 +733,51 @@ const getSubColumns = metaList => {
692
733
  // @ts-ignore
693
734
  data = metaList.slice().map(v => {
694
735
  if (v.type === TypeEnum.data) {
736
+ const columns = v.columns.map(column => {
737
+ return {
738
+ ...column,
739
+ name: column.fieldAlias || column.name,
740
+ fieldAlias: ''
741
+ // fieldUuid: uuidv4('field'),
742
+ };
743
+ }).filter(item => item.select);
695
744
  return {
696
745
  alias: v.table.alias,
697
746
  table: v.table.name,
698
- columns: v.columns
747
+ columns: columns
699
748
  };
700
749
  } else if (v.type === TypeEnum.joinData) {
750
+ const columns = v.columns.map(column => {
751
+ return {
752
+ ...column,
753
+ name: column.fieldAlias || column.name,
754
+ fieldAlias: ''
755
+ // fieldUuid: uuidv4('field'),
756
+ };
757
+ }).filter(item => item.select);
701
758
  return {
702
759
  alias: v.table2.alias,
703
760
  table: v.table2.name,
704
- columns: v.columns
761
+ columns: columns
762
+ };
763
+ } else if (v.type === TypeEnum.customColumn) {
764
+ const {
765
+ customColumn
766
+ } = v;
767
+ const columns = customColumn.map(v => {
768
+ return {
769
+ database_type: SQL_COLUMN_TYPE.STRING,
770
+ name_zh: v.name,
771
+ name: v.name,
772
+ select: true,
773
+ fieldAlias: ''
774
+ // fieldUuid: uuidv4('field'),
775
+ };
776
+ });
777
+ return {
778
+ columns: columns,
779
+ alias: '',
780
+ table: __('SqlQueryBuilder.customColumn')
705
781
  };
706
782
  } else {
707
783
  return {
@@ -726,18 +802,25 @@ const changeTableAlias = (list, curObj) => {
726
802
  alias
727
803
  } = cloneDeep(curObj);
728
804
  const newList = cloneDeep(list);
729
- newList.map(v => {
730
- if (v.type === TypeEnum.data) ;
805
+ return newList?.map(v => {
806
+ if (v.type === TypeEnum.data) {
807
+ if (v.table.tableUuid === tableUuid) {
808
+ v.table.alias = alias;
809
+ }
810
+ }
731
811
  if (v.type === TypeEnum.joinData) {
732
812
  if (v.table1.tableUuid === tableUuid) {
733
813
  v.table1.alias = alias;
734
814
  }
815
+ if (v.table2.tableUuid === tableUuid) {
816
+ v.table2.alias = alias;
817
+ }
735
818
  }
736
819
  if (v.type === TypeEnum.customColumn) {
737
820
  v.customColumn.map(item => {
738
821
  item.formulaList?.map(formula => {
739
- if (formula.tableUuid === tableUuid) {
740
- formula.alias = alias;
822
+ if (formula.expression && formula.expression.tableUuid === tableUuid) {
823
+ formula.expression.alias = alias;
741
824
  }
742
825
  });
743
826
  });
@@ -768,34 +851,61 @@ const changeTableAlias = (list, curObj) => {
768
851
  v.by.map(by => {
769
852
  if (by.tableUuid === tableUuid) {
770
853
  by.alias = alias;
771
- by.sql = `${by.alias}.${by.realName || by.name} AS ${by.fieldAlias}`;
854
+ by.sql = `${by.alias}.${by.realName || by.name}`;
772
855
  }
773
856
  });
774
857
  }
775
858
  if (v.type === TypeEnum.filter) {
776
859
  v.filter.map(item => {
777
860
  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
- }
861
+ // if (item.alias === SummarizeAlias) {
862
+ // //有groupBy 特殊处理
863
+ // const { prevGroupBy } = getHelper(list, v);
864
+ // let groupBy: any =
865
+ // prevGroupBy?.by.filter((v) => v.fieldUuid === item.fieldUuid)[0] ||
866
+ // prevGroupBy?.group.filter((v) => v.fieldUuid === item.fieldUuid)[0] ||
867
+ // null;
868
+ // groupBy.alias = alias;
869
+ // const sql = groupBy.sql;
870
+ // if (groupBy) {
871
+ // item.sql = sql;
872
+ // item.groupSql = sql;
873
+ // }
874
+ // }
875
+ item.alias = alias;
876
+ item.sql = '';
877
+ }
878
+ if (item.table2 && item.table2.tableUuid === tableUuid) {
879
+ // if (item.table2.alias === SummarizeAlias) {
880
+ // //有groupBy 特殊处理
881
+ // const { prevGroupBy } = getHelper(list, v);
882
+ // let groupBy: any =
883
+ // prevGroupBy?.by.filter((v) => v.fieldUuid === item.table2?.fieldUuid)[0] ||
884
+ // prevGroupBy?.group.filter((v) => v.fieldUuid === item.table2?.fieldUuid)[0] ||
885
+ // null;
886
+ // groupBy.alias = alias;
887
+ // const sql = groupBy.sql;
888
+ // if (groupBy) {
889
+ // item.table2.sql = sql;
890
+ // item.table2.groupSql = sql;
891
+ // }
892
+ // }
893
+ item.table2.alias = alias;
894
+ // item.table2.sql = '';
794
895
  }
896
+ // if (item.subquery) {
897
+ // item.subquery = changeTableAlias(item.subquery || [], curObj);
898
+ // }
795
899
  });
796
900
  }
797
- });
798
- return newList;
901
+ // if ((v as MetaData | MetaJoin).subquery) {
902
+ // (v as MetaData | MetaJoin).subquery = changeTableAlias(
903
+ // (v as MetaData | MetaJoin).subquery || [],
904
+ // curObj,
905
+ // );
906
+ // }
907
+ return v;
908
+ }) || [];
799
909
  };
800
910
  const changeFieldAlias = (list, curObj) => {
801
911
  const {
@@ -803,14 +913,32 @@ const changeFieldAlias = (list, curObj) => {
803
913
  fieldAlias
804
914
  } = cloneDeep(curObj);
805
915
  const newList = cloneDeep(list);
806
- newList.map(v => {
916
+ return newList?.map(v => {
807
917
  if (v.type === TypeEnum.data) ;
808
- if (v.type === TypeEnum.joinData) ;
918
+ if (v.type === TypeEnum.joinData) {
919
+ if (v.table1.fieldUuid === fieldUuid) {
920
+ v.table1.fieldAlias = fieldAlias;
921
+ }
922
+ if (v.table2.fieldUuid === fieldUuid) {
923
+ v.table2.fieldAlias = fieldAlias;
924
+ }
925
+ v.expressions.map(column => {
926
+ if (column.left_fieldUuid === fieldUuid) {
927
+ column.left_fieldAlias = fieldAlias;
928
+ }
929
+ if (column.right_fieldUuid === fieldUuid) {
930
+ column.right_fieldAlias = fieldAlias;
931
+ }
932
+ });
933
+ // if (v.table1.tableUuid === tableUuid) {
934
+ // v.table1.alias = alias;
935
+ // }
936
+ }
809
937
  if (v.type === TypeEnum.customColumn) {
810
938
  v.customColumn.map(item => {
811
939
  item.formulaList?.map(formula => {
812
- if (formula.fieldUuid === fieldUuid) {
813
- formula.fieldAlias = fieldAlias;
940
+ if (formula.expression && formula.expression.fieldUuid === fieldUuid) {
941
+ formula.expression.fieldAlias = fieldAlias;
814
942
  }
815
943
  });
816
944
  });
@@ -842,7 +970,7 @@ const changeFieldAlias = (list, curObj) => {
842
970
  v.by.map(by => {
843
971
  if (by.fieldUuid === fieldUuid) {
844
972
  by.fieldAlias = fieldAlias;
845
- by.sql = `${by.alias}.${by.realName || by.name} AS ${by.fieldAlias}`;
973
+ by.sql = `${by.alias}.${by.realName || by.name}`;
846
974
  }
847
975
  });
848
976
  }
@@ -856,20 +984,43 @@ const changeFieldAlias = (list, curObj) => {
856
984
  prevGroupBy
857
985
  } = getHelper(list, v);
858
986
  let groupBy = prevGroupBy?.by.filter(v => v.fieldUuid === item.fieldUuid)[0] || prevGroupBy?.group.filter(v => v.fieldUuid === item.fieldUuid)[0] || null;
859
- groupBy.fieldAlias = fieldAlias;
860
- const sql = groupBy.sql;
861
987
  if (groupBy) {
988
+ groupBy.fieldAlias = fieldAlias;
989
+ const sql = groupBy.sql;
862
990
  item.sql = sql;
863
991
  item.groupSql = sql;
864
992
  }
865
993
  }
866
994
  }
995
+ if (item.table2 && item.table2.fieldUuid === fieldUuid) {
996
+ item.table2.fieldAlias = fieldAlias;
997
+ // if (item.table2.alias === SummarizeAlias) {
998
+ // //有groupBy 特殊处理
999
+ // const { prevGroupBy } = getHelper(list, v);
1000
+ // let groupBy: any =
1001
+ // prevGroupBy?.by.filter((v) => v.fieldUuid === item.table2?.fieldUuid)[0] ||
1002
+ // prevGroupBy?.group.filter((v) => v.fieldUuid === item.table2?.fieldUuid)[0] ||
1003
+ // null;
1004
+ // groupBy.fieldAlias = fieldAlias;
1005
+ // const sql = groupBy.sql;
1006
+ // if (groupBy) {
1007
+ // item.table2.sql = sql;
1008
+ // item.table2.groupSql = sql;
1009
+ // }
1010
+ // }
1011
+ }
1012
+ if (item.notExists) {
1013
+ item.notExists = changeFieldAlias(item.notExists || [], curObj);
1014
+ }
867
1015
  });
868
1016
  }
869
- });
870
- return newList;
1017
+ return {
1018
+ ...v
1019
+ };
1020
+ }) || [];
871
1021
  };
872
1022
  function splitByUnion(data) {
1023
+ if (!data) return [];
873
1024
  const original = cloneDeep(data);
874
1025
  const result = [];
875
1026
  let i = 0;
@@ -905,7 +1056,8 @@ function splitByUnion(data) {
905
1056
  }
906
1057
  return result;
907
1058
  }
908
- function reassembleByUnion(target) {
1059
+ function reassembleByUnion(target = []) {
1060
+ if (!target) return [];
909
1061
  const result = [];
910
1062
  let i = 0;
911
1063
  const len = target.length;
@@ -949,6 +1101,92 @@ function reassembleByUnion(target) {
949
1101
  }
950
1102
  return result;
951
1103
  }
1104
+ // export const buildSqlQuery = (data?: MetaListType[]): string => {
1105
+ // if (!data || data.length === 0) return '';
1106
+ // let sqlClauses: string[] = ['not exitis ( '];
1107
+ // data.forEach((item) => {
1108
+ // if (item.type === TypeEnum.data) {
1109
+ // const meta = item as MetaData;
1110
+ // const tableName = meta.table.name;
1111
+ // const alias = meta.table.alias ? `AS ${meta.table.alias}` : '';
1112
+ // const dataSource = meta.table.datasourceName;
1113
+ // sqlClauses.push(`SELECT 1 FROM ${dataSource}.${tableName} ${alias}`);
1114
+ // }
1115
+ // if (item.type === TypeEnum.joinData) {
1116
+ // const meta = item as MetaJoin;
1117
+ // const table1 = meta.table1.alias ? meta.table1.alias : meta.table1.name;
1118
+ // const table2 = `${meta.table2.datasourceName}.${meta.table2.name}`;
1119
+ // const alias2 = meta.table2.alias ? meta.table2.alias : '';
1120
+ // joins.push(`LEFT JOIN ${table2} ${alias2} ON ${table1}.${meta.columns[0]?.name} = ${alias2}.${meta.columns[0]?.name}`);
1121
+ // }
1122
+ // if (item.type === TypeEnum.filter) {
1123
+ // const filterStrings = (item as MetaFilter).filter.map((f) => f.quotes).filter(Boolean); // 排除空条件
1124
+ // if (filterStrings.length > 0) {
1125
+ // sqlClauses.push(`WHERE ${filterStrings.join(' AND ')}`);
1126
+ // }
1127
+ // }
1128
+ // });
1129
+ // // 简单拼接 SQL 片段
1130
+ // return sqlClauses.join(' ') + ' )' + ';';
1131
+ // };
1132
+ const buildSqlQuery = data => {
1133
+ if (!data || data.length === 0) return '';
1134
+ let sqlClauses = ['NOT EXISTS ('];
1135
+ let tables = [];
1136
+ let joins = [];
1137
+ let wheres = [];
1138
+ data.forEach(item => {
1139
+ if (item.type === TypeEnum.data) {
1140
+ const meta = item;
1141
+ const tableName = `${meta.table.name}`;
1142
+ const alias = meta.table.alias ? ` AS ${meta.table.alias}` : '';
1143
+ tables.push(`${tableName}${alias}`);
1144
+ }
1145
+ if (item.type === TypeEnum.joinData) {
1146
+ const meta = item;
1147
+ const table2Name = `${meta.table2.name}`;
1148
+ const alias2 = meta.table2.alias ? ` AS ${meta.table2.alias}` : '';
1149
+ const table2 = `${meta.table2.alias || meta.table2.name}`;
1150
+ const table1 = `${meta.table1.alias || meta.table1.name}`;
1151
+ joins.push(`LEFT JOIN ${table2Name}${alias2} ON ${table1}.${meta.table1.fieldAlias} = ${table2}.${meta.table2.fieldAlias}`);
1152
+ if (Array.isArray(item.expressions) && item.expressions.length > 0) {
1153
+ item.expressions.forEach(expression => {
1154
+ let left = '',
1155
+ right = '';
1156
+ if (expression.left_type === 'field') {
1157
+ left = `${table1}.${expression.left_fieldAlias}`;
1158
+ } else {
1159
+ left = expression.left_string;
1160
+ }
1161
+ if (expression.right_type === 'field') {
1162
+ right = `${table2}.${expression.right_fieldAlias}`;
1163
+ } else {
1164
+ right = expression.right_string;
1165
+ }
1166
+ joins.push(`AND ${left} = ${right}`);
1167
+ });
1168
+ }
1169
+ }
1170
+ if (item.type === TypeEnum.filter) {
1171
+ const filterStrings = item.filter.map(f => f.quotes).filter(Boolean);
1172
+ if (filterStrings.length > 0) {
1173
+ wheres.push(...filterStrings);
1174
+ }
1175
+ }
1176
+ });
1177
+ // 构建子查询
1178
+ if (tables.length > 0) {
1179
+ sqlClauses.push(`SELECT 1 FROM ${tables[0]}`);
1180
+ if (joins.length > 0) {
1181
+ sqlClauses.push(joins.join(' '));
1182
+ }
1183
+ if (wheres.length > 0) {
1184
+ sqlClauses.push(`WHERE ${wheres.join(' AND ')}`);
1185
+ }
1186
+ }
1187
+ sqlClauses.push(')');
1188
+ return sqlClauses.join(' ') + ';';
1189
+ };
952
1190
 
953
1191
  let metaKey = 1;
954
1192
  const SummarizeAlias = 'source';
@@ -1001,6 +1239,8 @@ const useStore = () => {
1001
1239
  }); //弹窗
1002
1240
  const [popupClosable, setClosable] = useState(true); //是否可关闭 如果弹框里面再弹框 则不可关闭
1003
1241
  const [popupClosable2, setClosable2] = useState(true); //是否可关闭 如果弹框里面再弹框 则不可关闭
1242
+ // 外层ref
1243
+ const popupContainer = useRef();
1004
1244
  // const [fetchDatasetFn, setFetchDatasetFn] = useState<(id: string) => Promise<any>>(
1005
1245
  // async () => {},
1006
1246
  // ); //fn
@@ -1018,18 +1258,18 @@ const useStore = () => {
1018
1258
  };
1019
1259
  // 是否显示主表后面的字段按钮 (如果下面 没有聚合,或者选了聚合但是聚合里面没有选值的时候显示 主表字段按钮)
1020
1260
  const showMainColumn = useMemo(() => {
1021
- // 先将二维数组拍平为一维数组
1022
- const flatMetaList = metaList.flatMap(group => group.list);
1023
- // 过滤出所有汇总类型的项
1024
- const summarizeItems = flatMetaList.filter(v => v.type === TypeEnum.summarize);
1025
- // 如果没有汇总项,默认显示主列
1026
- if (summarizeItems.length === 0) {
1027
- return true;
1028
- }
1029
- // 如果只有一个汇总项,并且 group 和 by 都为空,则也显示主列
1030
- const onlyItem = summarizeItems[0];
1031
- const hasGroupOrBy = Array.isArray(onlyItem.group) && onlyItem.group.length > 0 || Array.isArray(onlyItem.by) && onlyItem.by.length > 0;
1032
- return !hasGroupOrBy;
1261
+ return metaList?.map((item, groupIndex) => {
1262
+ // 过滤出所有汇总类型的项
1263
+ const summarizeItems = item.list.filter(v => v.type === TypeEnum.summarize);
1264
+ // 如果没有汇总项,默认显示主列
1265
+ if (summarizeItems.length === 0) {
1266
+ return true;
1267
+ }
1268
+ // 如果只有一个汇总项,并且 group 和 by 都为空,则也显示主列
1269
+ const onlyItem = summarizeItems[0];
1270
+ const hasGroupOrBy = Array.isArray(onlyItem.group) && onlyItem.group.length > 0 || Array.isArray(onlyItem.by) && onlyItem.by.length > 0;
1271
+ return !hasGroupOrBy;
1272
+ });
1033
1273
  }, [metaList]);
1034
1274
  // const showMainColumn = useMemo(() => {
1035
1275
  // let summarizeList = metaList.filter((v) => v.type === TypeEnum.summarize);
@@ -1073,7 +1313,7 @@ const useStore = () => {
1073
1313
  columns = await fetchColumnsFn.current(extra, datasourceId);
1074
1314
  setColumns(tableName, columns);
1075
1315
  }
1076
- const _columns = columns.map(v => {
1316
+ const _columns = columns?.map(v => {
1077
1317
  return {
1078
1318
  ...v,
1079
1319
  fieldUuid: v.fieldAlias || uuidv4('field')
@@ -1087,21 +1327,56 @@ const useStore = () => {
1087
1327
  _setMeta(newMeta);
1088
1328
  };
1089
1329
  // 回显
1090
- const setPreData = async data => {
1330
+ // 设置column
1331
+ const setQuotes = newMeta => {
1332
+ newMeta.table1 = {
1333
+ ...newMeta.table1,
1334
+ fieldAlias: newMeta.table1.fieldAlias || newMeta.table1.column,
1335
+ fieldUuid: newMeta.table1.fieldUuid || uuidv4('field'),
1336
+ quotes: newMeta.table1.quotes || newMeta.table1.column,
1337
+ tableUuid: newMeta.table1.tableUuid || uuidv4('table')
1338
+ };
1339
+ newMeta.table2 = {
1340
+ ...newMeta.table2,
1341
+ fieldAlias: newMeta.table2.fieldAlias || newMeta.table2.column,
1342
+ fieldUuid: newMeta.table2.fieldUuid || uuidv4('field'),
1343
+ quotes: newMeta.table2.quotes || newMeta.table2.column,
1344
+ tableUuid: newMeta.table2.tableUuid || uuidv4('table')
1345
+ };
1346
+ newMeta.expressions = newMeta.expressions?.map(v => {
1347
+ return {
1348
+ ...v,
1349
+ left_fieldAlias: v.left_fieldAlias || v.left_column,
1350
+ left_fieldUuid: v.left_fieldUuid || uuidv4('field'),
1351
+ left_quotes: v.left_quotes || v.left_column,
1352
+ right_fieldAlias: v.right_fieldAlias || v.right_column,
1353
+ right_fieldUuid: v.right_fieldUuid || uuidv4('field'),
1354
+ right_quotes: v.right_quotes || v.right_column
1355
+ };
1356
+ });
1357
+ return newMeta;
1358
+ };
1359
+ const setPreData = data => {
1091
1360
  if (data.length) {
1092
- let _metaList = data.map((item, groupIndex) => {
1361
+ let _metaList = data?.map((item, groupIndex) => {
1093
1362
  let newList = item.list?.map((v, i) => {
1094
- let newMeta = cloneDeep(item.list);
1363
+ let newMeta = item.list;
1364
+ if (v.table) {
1365
+ v.table.tableUuid = v.table.tableUuid || uuidv4('table');
1366
+ }
1367
+ if (v.type === TypeEnum.joinData) {
1368
+ newMeta[i] = setQuotes(newMeta[i]);
1369
+ }
1095
1370
  // 设置右侧column
1096
1371
  if (v.table2?.datasourceId && v.columns.length < 1) {
1097
- fetchColumns(newMeta[i].table2, newMeta[i].table2.datasourceId, columns => {
1372
+ fetchColumns(newMeta[i].table2, newMeta[i].table2.datasourceId, (columns = []) => {
1098
1373
  if (v.isSubquery) {
1099
1374
  let newColumns = [];
1100
1375
  const items = getSubColumns(v.subquery);
1101
- newColumns = items.flatMap(item => item.columns);
1102
- newMeta[i].columns = newColumns;
1376
+ newColumns = items?.flatMap(item => item.columns);
1377
+ newMeta[i].columns = newColumns || [];
1103
1378
  } else {
1104
- newMeta[i].columns = columns;
1379
+ newMeta[i].columns = columns || [];
1105
1380
  }
1106
1381
  setMeta(newMeta, groupIndex);
1107
1382
  });
@@ -1111,15 +1386,18 @@ const useStore = () => {
1111
1386
  }
1112
1387
  // 设置column
1113
1388
  if (v.table?.datasourceId && v.columns.length < 1) {
1114
- fetchColumns(newMeta[i].table, newMeta[i].table.datasourceId, columns => {
1389
+ fetchColumns(newMeta[i].table, newMeta[i].table.datasourceId, (columns = []) => {
1115
1390
  if (v.isSubquery) {
1116
1391
  let newColumns = [];
1117
1392
  const items = getSubColumns(v.subquery);
1118
1393
  newColumns = items.flatMap(item => item.columns);
1119
- newMeta[i].columns = newColumns;
1394
+ newMeta[i].columns = newColumns || [];
1120
1395
  } else {
1121
- newMeta[i].columns = columns;
1396
+ newMeta[i].columns = columns || [];
1122
1397
  }
1398
+ // if (v.type === TypeEnum.joinData) {
1399
+ // newMeta[i] = setQuotes(newMeta[i]);
1400
+ // }
1123
1401
  setMeta(newMeta, groupIndex);
1124
1402
  });
1125
1403
  return {
@@ -1157,8 +1435,8 @@ const useStore = () => {
1157
1435
  tableUuid: '',
1158
1436
  datasourceId: '',
1159
1437
  datasourceName: '',
1160
- column: '',
1161
- column_id: ''
1438
+ fieldAlias: '',
1439
+ fieldUuid: ''
1162
1440
  };
1163
1441
  if (index === 1) {
1164
1442
  table1 = {
@@ -1167,8 +1445,8 @@ const useStore = () => {
1167
1445
  alias: mainTable.table.alias,
1168
1446
  datasourceId: mainTable.table.datasourceId,
1169
1447
  datasourceName: mainTable.table.datasourceName,
1170
- column: '',
1171
- column_id: ''
1448
+ fieldAlias: '',
1449
+ fieldUuid: ''
1172
1450
  };
1173
1451
  }
1174
1452
  item = {
@@ -1183,8 +1461,8 @@ const useStore = () => {
1183
1461
  tableUuid: '',
1184
1462
  datasourceId: '',
1185
1463
  datasourceName: '',
1186
- column: '',
1187
- column_id: ''
1464
+ fieldAlias: '',
1465
+ fieldUuid: ''
1188
1466
  },
1189
1467
  columns: [],
1190
1468
  expressions: []
@@ -1293,7 +1571,7 @@ const useStore = () => {
1293
1571
  setMeta(_metaList, groupIndex);
1294
1572
  };
1295
1573
  const setColumns = (tableId, columns) => {
1296
- const _columns = columns.map(v => {
1574
+ const _columns = columns?.map(v => {
1297
1575
  return {
1298
1576
  ...v,
1299
1577
  fieldUuid: v.fieldUuid || uuidv4('field')
@@ -1318,46 +1596,10 @@ const useStore = () => {
1318
1596
  const getDataset = datasourceId => {
1319
1597
  return _cacheSource2TableMap[datasourceId] || [];
1320
1598
  };
1321
- const changeAlias = (groupIndex, alias) => {
1322
- let newMetaList = metaList.slice();
1323
- const _list = newMetaList[groupIndex].list;
1324
- if (_list.length > 0) {
1325
- _list.forEach(item => {
1326
- if (item.type === TypeEnum.joinData && item.table2.alias === alias) {
1327
- item.table2.alias = alias;
1328
- } else if (item.type === TypeEnum.data && item.table.alias === alias) {
1329
- item.table.alias = alias;
1330
- } else if (item.type === TypeEnum.filter) {
1331
- //过滤器
1332
- item.filter.forEach(filterItem => {
1333
- if (filterItem.alias === alias) {
1334
- filterItem.alias = alias;
1335
- }
1336
- });
1337
- } else if (item.type === TypeEnum.summarize) {
1338
- // 汇总
1339
- item.alias = alias;
1340
- item.by.forEach(byItem => {
1341
- if (byItem.alias === alias) {
1342
- byItem.alias = alias;
1343
- }
1344
- });
1345
- item.group.forEach(groupItem => {
1346
- if (groupItem.alias === alias) {
1347
- groupItem.alias = alias;
1348
- groupItem.sql = alias;
1349
- }
1350
- });
1351
- }
1352
- });
1353
- newMetaList[groupIndex].list = _list;
1354
- _setMeta(newMetaList);
1355
- }
1356
- };
1357
1599
  const reset = () => {
1358
1600
  // setSourceList([]);
1359
1601
  _setMeta(defaultMeta);
1360
- setToolbar(defaultToolbar);
1602
+ // setToolbar(defaultToolbar);
1361
1603
  set_cacheSource2TableMap({});
1362
1604
  set_cacheColumnsMap({});
1363
1605
  };
@@ -1411,40 +1653,10 @@ const useStore = () => {
1411
1653
  _setShowSubquery,
1412
1654
  constantList,
1413
1655
  setConstantList,
1414
- changeAlias
1656
+ popupContainer
1415
1657
  };
1416
1658
  };
1417
1659
 
1418
- //获取指定名称的cookie值
1419
- function getCookie(name) {
1420
- // (^| )name=([^;]*)(;|$),match[0]为与整个正则表达式匹配的字符串,match[i]为正则表达式捕获数组相匹配的数组;
1421
- var arr = document.cookie.match(new RegExp('(^| )' + name + '=([^;]*)(;|$)'));
1422
- if (arr != null) {
1423
- console.log(arr);
1424
- return arr[2];
1425
- }
1426
- return null;
1427
- }
1428
-
1429
- const locales = {};
1430
- const activeLocale = getCookie('LOCALE') || 'zh';
1431
- const isEn = activeLocale === 'en';
1432
- const register = (name, data) => {
1433
- if (name in locales) {
1434
- console.warn(`[i18n] ${name} has been registered`);
1435
- } else {
1436
- locales[name] = data;
1437
- }
1438
- };
1439
- const __ = name => {
1440
- if (activeLocale in locales) {
1441
- return locales[activeLocale][name] || '';
1442
- } else {
1443
- console.warn(`[i18n] locale not found`);
1444
- return '';
1445
- }
1446
- };
1447
-
1448
1660
  register('en', {
1449
1661
  'data.pleaseSelectDataTable': 'please select data table',
1450
1662
  'data.calculatingNow': 'calculating now...',
@@ -1781,7 +1993,7 @@ const Loading = ({
1781
1993
  });
1782
1994
  };
1783
1995
 
1784
- 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";
1996
+ 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";
1785
1997
  styleInject(css_248z$d);
1786
1998
 
1787
1999
  // 获取元素translate x y值
@@ -1813,6 +2025,7 @@ const getComputedTranslate = obj => {
1813
2025
  };
1814
2026
  // 获取元素距离浏览器顶部的距离
1815
2027
  const getElementTop = elem => {
2028
+ if (!elem) return 0;
1816
2029
  let elemTop = elem.offsetTop;
1817
2030
  let pElem = elem.offsetParent;
1818
2031
  while (pElem != null) {
@@ -1826,6 +2039,7 @@ const getElementTop = elem => {
1826
2039
  };
1827
2040
  // 获取元素距离浏览器顶部的距离
1828
2041
  const getElementLeft = elem => {
2042
+ if (!elem) return 0;
1829
2043
  let elemLeft = elem.offsetLeft;
1830
2044
  let pElem = elem.offsetParent;
1831
2045
  while (pElem != null) {
@@ -1837,8 +2051,23 @@ const getElementLeft = elem => {
1837
2051
  }
1838
2052
  return elemLeft;
1839
2053
  };
1840
- const getScrollTop = () => {
1841
- return document.documentElement.scrollTop;
2054
+ // 获取元素可见范围内高度
2055
+ const getContainerVisibleHeight = container => {
2056
+ if (!container) return 0;
2057
+ const rect = container.getBoundingClientRect();
2058
+ const windowHeight = window.innerHeight || document.documentElement.clientHeight;
2059
+ // 元素顶部在视口上方 -> 不可见
2060
+ if (rect.bottom < 0) return 0;
2061
+ // 元素底部在视口下方 -> 不可见
2062
+ if (rect.top > windowHeight) return 0;
2063
+ // 可见区域的 top 和 bottom
2064
+ const visibleTop = Math.max(rect.top, 0);
2065
+ const visibleBottom = Math.min(rect.bottom, windowHeight);
2066
+ // 可见高度
2067
+ return visibleBottom - visibleTop;
2068
+ };
2069
+ const getScrollTop = elem => {
2070
+ return elem?.scrollTop || document.documentElement.scrollTop;
1842
2071
  };
1843
2072
  // 浏览器可视宽高
1844
2073
  const getWindowSize = () => {
@@ -3393,7 +3622,9 @@ const Portal = /*#__PURE__*/forwardRef((props, ref) => {
3393
3622
  initRef.current = true;
3394
3623
  }
3395
3624
  useEffect(() => {
3396
- didUpdate?.(props, containerRef.current);
3625
+ setTimeout(() => {
3626
+ didUpdate?.(props, containerRef.current);
3627
+ }, 0);
3397
3628
  });
3398
3629
  useEffect(() => {
3399
3630
  return () => {
@@ -3409,6 +3640,7 @@ function returnDocument(element) {
3409
3640
  const outSpacing = 10;
3410
3641
  function generateTrigger(PortalComponent) {
3411
3642
  class Trigger extends React.Component {
3643
+ resizeObserver = null; // 显式声明 resizeObserver 属性
3412
3644
  resetId = -1; // 监听窗口改变事件id 用于组件销毁的时候清除事件
3413
3645
  static defaultProps = {
3414
3646
  visible: false,
@@ -3423,11 +3655,39 @@ function generateTrigger(PortalComponent) {
3423
3655
  this.resetId = winResetEvent.addEvent(this.didUpdate, this, 300);
3424
3656
  this.props.container && this.props.container.addEventListener('scroll', this.didUpdate);
3425
3657
  this.bindEvent();
3658
+ // 延迟绑定 ResizeObserver 到 ensure the element is ready
3659
+ this.initResizeObserver();
3660
+ }
3661
+ componentDidUpdate(prevProps) {
3662
+ // 如果 children 发生变化,重新初始化观察器
3663
+ if (prevProps.children !== this.props.children) {
3664
+ this.initResizeObserver();
3665
+ }
3426
3666
  }
3427
3667
  componentWillUnmount() {
3428
3668
  winResetEvent.removeEvent(this.resetId);
3429
3669
  this.props.container && this.props.container.removeEventListener('scroll', this.didUpdate);
3670
+ if (this.resizeObserver) {
3671
+ this.resizeObserver.disconnect();
3672
+ this.resizeObserver = null;
3673
+ }
3430
3674
  }
3675
+ // children高度变化后,从新计算高度
3676
+ initResizeObserver = () => {
3677
+ const targetNode = this.ref.current;
3678
+ if (!targetNode) return;
3679
+ // 如果已经存在 ResizeObserver,先断开连接
3680
+ if (this.resizeObserver) {
3681
+ this.resizeObserver.disconnect();
3682
+ }
3683
+ // 初始化 ResizeObserver 并开始观察目标节点
3684
+ this.resizeObserver = new ResizeObserver(entries => {
3685
+ entries.forEach(entry => {
3686
+ this.didUpdate();
3687
+ });
3688
+ });
3689
+ this.resizeObserver.observe(targetNode);
3690
+ };
3431
3691
  bindEvent = () => {
3432
3692
  let that = this;
3433
3693
  returnDocument().body.addEventListener('click', function (e) {
@@ -3445,7 +3705,7 @@ function generateTrigger(PortalComponent) {
3445
3705
  this.props.visible && this.props.closable && this.props.hideVisible();
3446
3706
  };
3447
3707
  attachParent = popupContainer => {
3448
- let mountNode = returnDocument().body;
3708
+ let mountNode = this.props.container || returnDocument().body;
3449
3709
  mountNode.appendChild(popupContainer);
3450
3710
  };
3451
3711
  getCurrentNodePos = () => {
@@ -3454,8 +3714,9 @@ function generateTrigger(PortalComponent) {
3454
3714
  container
3455
3715
  } = this.props;
3456
3716
  return {
3457
- x: getElementLeft(node),
3458
- y: getElementTop(node) - (container?.scrollTop || 0),
3717
+ x: getElementLeft(node) - getElementLeft(container),
3718
+ y: getElementTop(node) - getElementTop(container),
3719
+ t: getElementTop(container),
3459
3720
  h: node.offsetHeight
3460
3721
  };
3461
3722
  };
@@ -3489,6 +3750,7 @@ function generateTrigger(PortalComponent) {
3489
3750
  borderRadius: 6
3490
3751
  },
3491
3752
  onClick: e => this.props.closable && e.stopPropagation(),
3753
+ onMouseDown: e => e.stopPropagation(),
3492
3754
  children: /*#__PURE__*/React.cloneElement(this.props.children, {
3493
3755
  key: posKey,
3494
3756
  didUpdate: this.didUpdate
@@ -3498,19 +3760,21 @@ function generateTrigger(PortalComponent) {
3498
3760
  didUpdate = () => {
3499
3761
  if (!this.props.node) return false;
3500
3762
  let {
3501
- innerSpacing = 10
3763
+ innerSpacing = 10,
3764
+ container
3502
3765
  } = this.props;
3503
3766
  let pos = this.getCurrentNodePos();
3504
- let posY = pos.y - getScrollTop();
3767
+ let posY = pos.y - getScrollTop(container);
3505
3768
  if (!this.ref) return false;
3506
3769
  let realHeight = this.ref?.current?.childNodes?.[0]?.offsetHeight || 0;
3507
3770
  if (!realHeight) return false;
3508
3771
  let {
3509
3772
  height: winH
3510
3773
  } = getWindowSize();
3511
- let downH = winH - posY - pos.h; // 元素下面可用高度
3774
+ let containerH = getContainerVisibleHeight(container);
3775
+ let downH = (containerH || winH) - posY - pos.h; // 元素下面可用高度
3512
3776
  let maxHeight = 0;
3513
- let topHeight = getScrollTop();
3777
+ let topHeight = getScrollTop(container);
3514
3778
  if (downH >= posY || realHeight <= downH - innerSpacing - outSpacing) {
3515
3779
  // 下面比上面宽敞 或 下面足够放下所有 放下面
3516
3780
  maxHeight = Math.min(realHeight, downH - innerSpacing - outSpacing);
@@ -3546,7 +3810,7 @@ styleInject(css_248z$9);
3546
3810
  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";
3547
3811
  styleInject(css_248z$8);
3548
3812
 
3549
- 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";
3813
+ 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";
3550
3814
  styleInject(css_248z$7);
3551
3815
 
3552
3816
  // 选择表中参数
@@ -3555,11 +3819,21 @@ const SelectColumn = ({
3555
3819
  groupIndex,
3556
3820
  onChange
3557
3821
  }) => {
3558
- const [columns, setColumns] = useState(_data.slice());
3822
+ const [columns, setColumns] = useState([]);
3823
+ const [originList, setOriginList] = useState(_data.slice());
3559
3824
  const store = useStore$1();
3825
+ const [filterVal, setFilterVal] = useState('');
3826
+ useEffect(() => {
3827
+ let newList = cloneDeep(originList.slice());
3828
+ setColumns(newList.filter(v => ~(v.name + (v.name_zh || '')).toLocaleLowerCase().indexOf(filterVal.toLocaleLowerCase())));
3829
+ }, [filterVal, originList]);
3830
+ function onInput(e) {
3831
+ let val = e.target.value;
3832
+ setFilterVal(val);
3833
+ }
3560
3834
  const isAllSelect = useMemo(() => {
3561
- return columns.filter(v => v.select).length === columns.length;
3562
- }, [columns]);
3835
+ return originList.filter(v => v.select).length === originList.length;
3836
+ }, [originList]);
3563
3837
  const AllSelectElement = useMemo(() => {
3564
3838
  if (isAllSelect) {
3565
3839
  return jsxs(Fragment, {
@@ -3578,8 +3852,14 @@ const SelectColumn = ({
3578
3852
  }
3579
3853
  }, [isAllSelect]);
3580
3854
  function onSelect(columns) {
3855
+ const originalData = cloneDeep(originList); // 原始数据
3856
+ const mergedColumns = originalData.map(item => {
3857
+ const match = columns.find(col => col.fieldUuid === item.fieldUuid);
3858
+ return match ? cloneDeep(match) : item; // 可选:是否需要深拷贝 match
3859
+ });
3581
3860
  setColumns(columns);
3582
- typeof onChange === 'function' && onChange(columns);
3861
+ setOriginList(mergedColumns);
3862
+ typeof onChange === 'function' && onChange(mergedColumns);
3583
3863
  }
3584
3864
  const onChangeFieldAlias = (val, i) => {
3585
3865
  let fieldAlias = val || '';
@@ -3600,10 +3880,14 @@ const SelectColumn = ({
3600
3880
  newMetaList = changeFieldAlias(newMetaList, newColumns[i]);
3601
3881
  store.setMeta(newMetaList, groupIndex);
3602
3882
  onSelect(newColumns);
3603
- store.setClosable(true);
3883
+ setTimeout(() => {
3884
+ store.setClosable(true);
3885
+ }, 0);
3604
3886
  },
3605
3887
  onCancel: () => {
3606
- store.setClosable(true);
3888
+ setTimeout(() => {
3889
+ store.setClosable(true);
3890
+ }, 0);
3607
3891
  }
3608
3892
  });
3609
3893
  };
@@ -3623,6 +3907,18 @@ const SelectColumn = ({
3623
3907
  onSelect(newColumns);
3624
3908
  },
3625
3909
  children: AllSelectElement
3910
+ }), jsxs("div", {
3911
+ className: cx(`Sqb-SelectColumn-search m-2 rounded-lg`),
3912
+ children: [jsx("span", {
3913
+ className: 'px-2',
3914
+ children: jsx(SearchIcon, {})
3915
+ }), jsx("input", {
3916
+ type: 'text',
3917
+ autoFocus: true,
3918
+ className: 'p-1',
3919
+ placeholder: __('data.search'),
3920
+ onInput: onInput
3921
+ })]
3626
3922
  }), Array.isArray(columns) && columns.map((v, i) => {
3627
3923
  return jsxs("div", {
3628
3924
  className: 'pb-2 px-2 flex items-center',
@@ -3660,7 +3956,7 @@ const SelectColumn = ({
3660
3956
  });
3661
3957
  };
3662
3958
 
3663
- 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";
3959
+ 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";
3664
3960
  styleInject(css_248z$6);
3665
3961
 
3666
3962
  const NUMBER_GROUP = [SQL_COLUMN_TYPE.FLOAT, SQL_COLUMN_TYPE.LONG, SQL_COLUMN_TYPE.CURRENCY];
@@ -3691,10 +3987,10 @@ const SelectJoinColumn = ({
3691
3987
  }) => {
3692
3988
  const store = useStore$1();
3693
3989
  const [value, setValue] = useState(_value); // 当前选择的字段
3694
- const [curTable, setCurTable] = useState(_value.alias); // 当前选择的表
3990
+ const [curTable, setCurTable] = useState(_value.tableUuid); // 当前选择的表
3695
3991
  const [curColumn, setCurColumn] = useState(_value.name); // 当前选择的字段
3696
3992
  const [tableList, setTableList] = useState(_data.map((v, i) => {
3697
- let open = !i && !_value.alias ? true : v.alias === _value.alias; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
3993
+ let open = !i && !_value.tableUuid ? true : v.tableUuid === _value.tableUuid; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
3698
3994
  return {
3699
3995
  ...v,
3700
3996
  open,
@@ -3704,12 +4000,12 @@ const SelectJoinColumn = ({
3704
4000
  }));
3705
4001
  useEffect(() => {
3706
4002
  setValue(_value);
3707
- setCurTable(_value.alias);
4003
+ setCurTable(_value.tableUuid);
3708
4004
  setCurColumn(_value.name);
3709
4005
  }, [_value]);
3710
4006
  useEffect(() => {
3711
4007
  setTableList(_data.map((v, i) => {
3712
- let open = !i && !_value.alias ? true : v.alias === _value.alias; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
4008
+ let open = !i && !_value.tableUuid ? true : v.tableUuid === _value.tableUuid; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
3713
4009
  return {
3714
4010
  ...v,
3715
4011
  open,
@@ -3769,16 +4065,17 @@ const SelectJoinColumn = ({
3769
4065
  if (open) {
3770
4066
  setTableList(newTables.map(v => ({
3771
4067
  ...v,
3772
- open: tableAlias === v.alias ? false : v.open
4068
+ open: tableUuid === v.tableUuid ? false : v.open
3773
4069
  })));
3774
4070
  } else {
3775
4071
  setTableList(newTables.map(v => ({
3776
4072
  ...v,
3777
- open: tableAlias === v.alias || v.alias === SummarizeAlias$1
4073
+ open: tableUuid === v.tableUuid || v.alias === SummarizeAlias$1
3778
4074
  })));
3779
4075
  }
3780
4076
  },
3781
- children: jsxs("a", {
4077
+ children: jsxs("div", {
4078
+ className: 'List-item',
3782
4079
  children: [jsx("span", {
3783
4080
  className: 'List-item-icon',
3784
4081
  children: jsx(TableIcon, {})
@@ -3797,7 +4094,7 @@ const SelectJoinColumn = ({
3797
4094
  })]
3798
4095
  })
3799
4096
  })
3800
- }), open && jsxs(Fragment, {
4097
+ }), (open || isSummarize) && jsxs(Fragment, {
3801
4098
  children: [!isSummarize && jsx("div", {
3802
4099
  className: cx(`Sqb-List-section`),
3803
4100
  children: jsxs("div", {
@@ -3835,7 +4132,7 @@ const SelectJoinColumn = ({
3835
4132
  className: cx(`Sqb-List-section`),
3836
4133
  children: jsxs("div", {
3837
4134
  className: cx(`Sqb-List-item mx-2`, {
3838
- active: curColumn === name && curTable === tableAlias
4135
+ active: curColumn === name && curTable === tableUuid
3839
4136
  }),
3840
4137
  onClick: () => {
3841
4138
  if (isGroup && typeof onGroup === 'function') {
@@ -3843,7 +4140,7 @@ const SelectJoinColumn = ({
3843
4140
  let quotes = name;
3844
4141
  return onGroup({
3845
4142
  ..._value,
3846
- tableUuid: _value.tableUuid || tableUuid,
4143
+ tableUuid: tableUuid || _value.tableUuid,
3847
4144
  ...v,
3848
4145
  table,
3849
4146
  tableId,
@@ -3857,7 +4154,7 @@ const SelectJoinColumn = ({
3857
4154
  }
3858
4155
  typeof onSelect === 'function' && onSelect({
3859
4156
  ..._value,
3860
- tableUuid: _value.tableUuid || tableUuid,
4157
+ tableUuid: tableUuid || _value.tableUuid,
3861
4158
  ...v,
3862
4159
  table,
3863
4160
  tableId,
@@ -3870,8 +4167,8 @@ const SelectJoinColumn = ({
3870
4167
  realName
3871
4168
  });
3872
4169
  },
3873
- children: [jsxs("a", {
3874
- className: 'p-2',
4170
+ children: [jsxs("div", {
4171
+ className: 'p-2 List-item',
3875
4172
  children: [jsx("span", {
3876
4173
  className: 'List-item-icon',
3877
4174
  children: IconMap[special_type || database_type] || jsx(LetterAaIcon, {})
@@ -3910,7 +4207,8 @@ const SelectFilterColumn = ({
3910
4207
  value,
3911
4208
  onChange,
3912
4209
  didUpdate,
3913
- isCustom: _isCustom = false
4210
+ isCustom: _isCustom = false,
4211
+ container: _container = null
3914
4212
  }) => {
3915
4213
  const [curColumn, setCurColumn] = useState(value);
3916
4214
  const [condition, setCondition] = useState(value.condition);
@@ -4327,6 +4625,7 @@ const SelectFilterColumn = ({
4327
4625
  store.setPopup2({
4328
4626
  visible: true,
4329
4627
  node: e.currentTarget,
4628
+ container: _container,
4330
4629
  content: jsx(SelectList, {
4331
4630
  value: valType,
4332
4631
  list: store.constantList || [],
@@ -4349,6 +4648,7 @@ const SelectFilterColumn = ({
4349
4648
  store.setPopup2({
4350
4649
  visible: true,
4351
4650
  node: e.currentTarget,
4651
+ container: _container,
4352
4652
  content: jsx(SelectList, {
4353
4653
  value: valType,
4354
4654
  list: [{
@@ -4383,6 +4683,7 @@ const SelectFilterColumn = ({
4383
4683
  store.setPopup2({
4384
4684
  visible: true,
4385
4685
  node: e.currentTarget,
4686
+ container: _container,
4386
4687
  content: jsx(SelectJoinColumn, {
4387
4688
  data: [..._data],
4388
4689
  value: value,
@@ -4691,7 +4992,7 @@ const SelectSummarize = ({
4691
4992
  availableData = data.map(v => {
4692
4993
  return {
4693
4994
  ...v,
4694
- columns: v.columns.filter(o => o.database_type && NUMBER_GROUP.includes(o.database_type))
4995
+ columns: v.columns.filter(o => o.database_type && (NUMBER_GROUP.includes(o.database_type) || (condition === '最大值' || condition === '最小值') && DATE_GROUP.includes(o.database_type)))
4695
4996
  };
4696
4997
  }).filter(v => v.columns.length);
4697
4998
  }
@@ -5374,6 +5675,7 @@ const TableData = props => {
5374
5675
  } = props;
5375
5676
  const store = useStore$1();
5376
5677
  let selected = Boolean(meta.table.name);
5678
+ let subQuerySelected = Boolean(meta.subquery?.[0]?.table?.name);
5377
5679
  function selectTable(e) {
5378
5680
  !meta.readonly && store.setPopup({
5379
5681
  visible: true,
@@ -5439,6 +5741,79 @@ const TableData = props => {
5439
5741
  onCancel: () => {}
5440
5742
  });
5441
5743
  };
5744
+ // 子查询弹窗
5745
+ const showSubQuery = (val = []) => {
5746
+ const {
5747
+ subToolbar,
5748
+ toolbar,
5749
+ ...other
5750
+ } = store.preProps;
5751
+ let newMetaList = store.metaList[groupIndex].list.slice()[0];
5752
+ let oldList = cloneDeep(newMetaList.subquery);
5753
+ let _toolbar = subToolbar || toolbar;
5754
+ _toolbar = _toolbar.filter(v => v !== 'group'); // 子查询不需要分组
5755
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : 0;
5756
+ let o = Modal2.openModal({
5757
+ title: __('SqlQueryBuilder.subquery'),
5758
+ transparentMask: true,
5759
+ zIndex: Number(zIndex),
5760
+ content: jsx(Fragment, {
5761
+ children: jsx(SqlVisionBuilder, {
5762
+ ...other,
5763
+ showSubquery: store._showSubquery,
5764
+ toolbar: _toolbar,
5765
+ btnText: __('SqlQueryBuilder.confirm'),
5766
+ value: val,
5767
+ onOk: newList => {
5768
+ try {
5769
+ // 子查询未改变不做操作
5770
+ if (isEqual(newList, oldList)) {
5771
+ o.close();
5772
+ return;
5773
+ }
5774
+ newMetaList.subquery = newList;
5775
+ newMetaList.table = {
5776
+ ...newList[0].table,
5777
+ alias: newMetaList.table.alias || '',
5778
+ tableUuid: uuidv4('table')
5779
+ };
5780
+ const items = getSubColumns(newList);
5781
+ const newColumns = items.flatMap(item => item.columns);
5782
+ newMetaList.columns = newColumns;
5783
+ // (newMeta[index] as MetaJoin).expressions = [];
5784
+ store.setMeta([newMetaList], groupIndex);
5785
+ o.close();
5786
+ } catch (e) {
5787
+ console.warn(e);
5788
+ } finally {
5789
+ o.close();
5790
+ }
5791
+ }
5792
+ })
5793
+ }),
5794
+ onClose: () => {}
5795
+ });
5796
+ };
5797
+ // 切换子查询
5798
+ const switchSubQuery = () => {
5799
+ let newMetaList = store.metaList[groupIndex].list.slice()[0];
5800
+ newMetaList.isSubquery = !newMetaList.isSubquery;
5801
+ //重置表数据
5802
+ newMetaList.subquery = [];
5803
+ newMetaList.table = {
5804
+ name: '',
5805
+ // 表名
5806
+ tableUuid: '',
5807
+ id: '',
5808
+ // 表名
5809
+ alias: '',
5810
+ // 表别名
5811
+ datasourceName: '',
5812
+ // 数据源名
5813
+ datasourceId: '' // 数据源id
5814
+ };
5815
+ store.setMeta([newMetaList], groupIndex);
5816
+ };
5442
5817
  return jsx(Wrapper, {
5443
5818
  className: `Sqb-item`,
5444
5819
  children: jsxs("div", {
@@ -5449,7 +5824,29 @@ const TableData = props => {
5449
5824
  className: `Sqb-item--content`,
5450
5825
  children: jsxs("div", {
5451
5826
  className: `Sqb-NotebookCell`,
5452
- children: [jsxs("div", {
5827
+ children: [meta.isSubquery ? jsxs("div", {
5828
+ className: cx(`Sqb-TableName`, {
5829
+ notSelected: !subQuerySelected
5830
+ }),
5831
+ onClick: () => {
5832
+ showSubQuery(meta.subquery);
5833
+ },
5834
+ children: [subQuerySelected && jsx(Tooltip, {
5835
+ title: __('SqlQueryBuilder.alias'),
5836
+ children: jsx(Button, {
5837
+ className: ':Sqb-TableName-as',
5838
+ shape: 'circle',
5839
+ iconOnly: true,
5840
+ primary: true,
5841
+ icon: 'As',
5842
+ size: 'small',
5843
+ onClick: e => {
5844
+ e.stopPropagation();
5845
+ onChangeTableAlias(meta.table?.alias || '');
5846
+ }
5847
+ })
5848
+ }), subQuerySelected ? `${(meta.subquery?.[0]).table.datasourceName}.${(meta.subquery?.[0]).table.name} ${meta.table?.alias ? `as ${meta.table?.alias}` : ''} ` : __('SqlQueryBuilder.setSubQuery')]
5849
+ }) : jsxs("div", {
5453
5850
  className: cx(`Sqb-TableName`, {
5454
5851
  notSelected: !selected
5455
5852
  }),
@@ -5469,7 +5866,19 @@ const TableData = props => {
5469
5866
  }
5470
5867
  })
5471
5868
  }), selected ? `${meta.table.datasourceName}.${meta.table.name} ${meta.table?.alias ? `as ${meta.table?.alias}` : ''}` : __('SqlQueryBuilder.pickTable')]
5472
- }), selected && store.showMainColumn && store.showFields && jsx("div", {
5869
+ }), store.showSubquery && jsx(Tooltip, {
5870
+ title: __('SqlQueryBuilder.switchSubQuery'),
5871
+ children: jsx(Button, {
5872
+ disabled: meta.readonly,
5873
+ primary: meta.isSubquery,
5874
+ ghost: true,
5875
+ className: cx('mr-2 operator-icon', {
5876
+ ['subquery-icon']: !meta.isSubquery
5877
+ }),
5878
+ icon: jsx(RelatedWork, {}),
5879
+ onClick: switchSubQuery
5880
+ })
5881
+ }), selected && store.showFields && jsx("div", {
5473
5882
  className: `Sqb-TableColumns`,
5474
5883
  onClick: selectColumns,
5475
5884
  children: __('SqlQueryBuilder.columns')
@@ -5491,8 +5900,8 @@ var FlagLocation;
5491
5900
  })(FlagLocation || (FlagLocation = {}));
5492
5901
  var ExpressionsEnum;
5493
5902
  (function (ExpressionsEnum) {
5494
- ExpressionsEnum["LEFT"] = "left_column";
5495
- ExpressionsEnum["RIGHT"] = "right_column";
5903
+ ExpressionsEnum["LEFT"] = "left";
5904
+ ExpressionsEnum["RIGHT"] = "right";
5496
5905
  })(ExpressionsEnum || (ExpressionsEnum = {}));
5497
5906
  const JoinData = props => {
5498
5907
  const {
@@ -5507,7 +5916,12 @@ const JoinData = props => {
5507
5916
  let table1Selected = Boolean(meta.table1.name);
5508
5917
  let table2Selected = Boolean(meta.table2.name);
5509
5918
  let subQuerySelected = Boolean(meta.subquery?.[0]?.table?.name);
5510
- let columnsSelected = meta.table1.column && meta.table2.column;
5919
+ let columnsSelected = meta.table1.quotes && meta.table2.quotes;
5920
+ // useEffect(() => {
5921
+ // let newMetaList = store.metaList[groupIndex].list.slice();
5922
+ // newMetaList[index] = setQuotes(meta);
5923
+ // store.setMeta(newMetaList, groupIndex);
5924
+ // }, []);
5511
5925
  function selectColumns(e) {
5512
5926
  let columns = meta.columns;
5513
5927
  !meta.readonly && store.setPopup({
@@ -5576,8 +5990,9 @@ const JoinData = props => {
5576
5990
  name: tableName,
5577
5991
  tableUuid: data.tableUuid || uuidv4('table'),
5578
5992
  alias,
5579
- column: '',
5580
- column_id: '',
5993
+ fieldAlias: '',
5994
+ fieldUuid: '',
5995
+ quotes: '',
5581
5996
  datasourceId: data.datasourceId,
5582
5997
  datasourceName: data.datasourceName
5583
5998
  };
@@ -5620,8 +6035,9 @@ const JoinData = props => {
5620
6035
  let type = node.getAttribute('v-data');
5621
6036
  let data = [];
5622
6037
  let value = {
5623
- name: meta[type].column,
5624
- id: meta[type].column_id,
6038
+ name: meta[type].quotes || meta[type].fieldAlias,
6039
+ quotes: meta[type].quotes,
6040
+ id: meta[type].fieldUuid,
5625
6041
  table: meta[type].name,
5626
6042
  tableId: meta[type].id,
5627
6043
  fieldUuid: meta[type].fieldUuid || uuidv4('field'),
@@ -5739,15 +6155,27 @@ const JoinData = props => {
5739
6155
  sql,
5740
6156
  datasourceId,
5741
6157
  datasourceName,
5742
- id = ''
6158
+ id = '',
6159
+ fieldAlias = '',
6160
+ fieldUuid = '',
6161
+ quotes,
6162
+ tableUuid
5743
6163
  } = record;
5744
6164
  let newMeta = store.metaList[groupIndex].list.slice();
5745
- newMeta[index][type].column = name;
5746
- newMeta[index][type].column_id = id;
6165
+ if (alias === SummarizeAlias$1) {
6166
+ newMeta[index][type].fieldAlias = fieldAlias;
6167
+ newMeta[index][type].fieldUuid = fieldUuid;
6168
+ newMeta[index][type].quotes = quotes;
6169
+ } else {
6170
+ newMeta[index][type].fieldAlias = name;
6171
+ newMeta[index][type].fieldUuid = id;
6172
+ newMeta[index][type].quotes = name;
6173
+ }
5747
6174
  if (type === FlagLocation.TABLE_1) {
5748
6175
  if (newMeta[index][type].alias !== alias) {
5749
6176
  newMeta[index][type].alias = alias;
5750
6177
  newMeta[index][type].name = table;
6178
+ newMeta[index][type].tableUuid = tableUuid;
5751
6179
  newMeta[index][type].datasourceId = datasourceId;
5752
6180
  newMeta[index][type].datasourceName = datasourceName;
5753
6181
  newMeta[index].expressions = [];
@@ -5771,8 +6199,8 @@ const JoinData = props => {
5771
6199
  let index = findIndex(store.metaList[groupIndex].list, meta);
5772
6200
  let table_type = type === ExpressionsEnum.LEFT ? FlagLocation.TABLE_1 : FlagLocation.TABLE_2;
5773
6201
  let value = {
5774
- name: meta.expressions[_ind][type],
5775
- id: meta.expressions[_ind][`${type}_id`],
6202
+ name: meta.expressions[_ind][`${type}_quotes`] || meta.expressions[_ind][`${type}_fieldAlias`],
6203
+ id: meta.expressions[_ind][`${type}_fieldUuid`],
5776
6204
  table: meta[table_type].name,
5777
6205
  fieldUuid: meta[table_type].fieldUuid || uuidv4('field'),
5778
6206
  fieldAlias: meta[table_type].fieldAlias || '',
@@ -5897,11 +6325,23 @@ const JoinData = props => {
5897
6325
  sql,
5898
6326
  datasourceId,
5899
6327
  datasourceName,
5900
- id = ''
6328
+ id = '',
6329
+ fieldAlias,
6330
+ fieldUuid,
6331
+ quotes = ''
5901
6332
  } = record;
5902
6333
  let newMeta = store.metaList[groupIndex].list.slice();
5903
- newMeta[index].expressions[_ind][type] = name;
5904
- newMeta[index].expressions[_ind][`${type}_id`] = id;
6334
+ if (alias === SummarizeAlias$1) {
6335
+ newMeta[index].expressions[_ind][`${type}_fieldAlias`] = fieldAlias;
6336
+ newMeta[index].expressions[_ind][`${type}_fieldUuid`] = fieldUuid;
6337
+ newMeta[index].expressions[_ind][`${type}_quotes`] = quotes;
6338
+ } else {
6339
+ newMeta[index].expressions[_ind][`${type}_fieldAlias`] = name;
6340
+ newMeta[index].expressions[_ind][`${type}_fieldUuid`] = id;
6341
+ newMeta[index].expressions[_ind][`${type}_quotes`] = name;
6342
+ }
6343
+ // (newMeta[index] as MetaJoin).expressions[_ind][type] = name;
6344
+ // (newMeta[index] as MetaJoin).expressions[_ind][`${type}_id`] = id;
5905
6345
  store.setMeta(newMeta, groupIndex);
5906
6346
  store.setPopup({
5907
6347
  visible: false
@@ -5983,10 +6423,11 @@ const JoinData = props => {
5983
6423
  let oldList = cloneDeep(newMeta[index].subquery);
5984
6424
  let _toolbar = subToolbar || toolbar;
5985
6425
  _toolbar = _toolbar.filter(v => v !== 'group'); // 子查询不需要分组
6426
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : 0;
5986
6427
  let o = Modal2.openModal({
5987
6428
  title: __('SqlQueryBuilder.subquery'),
5988
6429
  transparentMask: true,
5989
- zIndex: 200,
6430
+ zIndex: Number(zIndex),
5990
6431
  content: jsx(Fragment, {
5991
6432
  children: jsx(SqlVisionBuilder, {
5992
6433
  ...other,
@@ -6003,14 +6444,14 @@ const JoinData = props => {
6003
6444
  }
6004
6445
  newMeta[index].subquery = newList;
6005
6446
  newMeta[index].table2 = {
6006
- ...newList[0].table,
6007
- column: '',
6008
- column_id: ''
6447
+ ...newList[0].table
6009
6448
  };
6010
6449
  const items = getSubColumns(newList);
6011
6450
  const newColumns = items.flatMap(item => item.columns);
6012
6451
  newMeta[index].columns = newColumns;
6013
6452
  newMeta[index].expressions = [];
6453
+ // 关联表变了 下面模块全部删除
6454
+ newMeta = newMeta.filter((v, i) => i <= index);
6014
6455
  store.setMeta(newMeta, groupIndex);
6015
6456
  o.close();
6016
6457
  } catch (e) {
@@ -6030,8 +6471,9 @@ const JoinData = props => {
6030
6471
  let newMeta = store.metaList[groupIndex].list.slice();
6031
6472
  newMeta[index].isSubquery = !newMeta[index].isSubquery;
6032
6473
  newMeta[index].table2 = {
6033
- column: '',
6034
- column_id: '',
6474
+ quotes: '',
6475
+ fieldAlias: '',
6476
+ fieldUuid: '',
6035
6477
  name: '',
6036
6478
  // 表名
6037
6479
  tableUuid: '',
@@ -6124,7 +6566,7 @@ const JoinData = props => {
6124
6566
  onChangeTableAlias(meta.table2?.alias || '');
6125
6567
  }
6126
6568
  })
6127
- }), subQuerySelected ? `${meta.subquery?.[0].table.datasourceName}.${meta.subquery?.[0].table.name} ${meta.table2?.alias ? `as ${meta.table2?.alias}` : ''} ` : __('SqlQueryBuilder.setSubQuery')]
6569
+ }), subQuerySelected ? `${(meta.subquery?.[0]).table.datasourceName}.${(meta.subquery?.[0]).table.name} ${meta.table2?.alias ? `as ${meta.table2?.alias}` : ''} ` : __('SqlQueryBuilder.setSubQuery')]
6128
6570
  }) : jsxs("div", {
6129
6571
  className: cx(`Sqb-TableName`, {
6130
6572
  notSelected: !table2Selected
@@ -6164,23 +6606,23 @@ const JoinData = props => {
6164
6606
  children: "on"
6165
6607
  }), jsx("div", {
6166
6608
  className: cx(`Sqb-TableName`, {
6167
- notSelected: !meta.table1.column
6609
+ notSelected: !meta.table1.quotes
6168
6610
  }),
6169
6611
  "v-data": FlagLocation.TABLE_1,
6170
6612
  onClick: selectJoinColumn,
6171
- children: meta.table1.column ? meta.table1.column : __('SqlQueryBuilder.pickTable')
6613
+ children: meta.table1.quotes ? meta.table1.quotes : __('SqlQueryBuilder.pickTable')
6172
6614
  }), jsx("span", {
6173
6615
  className: 'mr-2 text-gray-500',
6174
6616
  children: "="
6175
6617
  }), jsx("div", {
6176
6618
  className: cx(`Sqb-TableName`, {
6177
- notSelected: !meta.table2.column
6619
+ notSelected: !meta.table2.quotes
6178
6620
  }),
6179
6621
  "v-data": FlagLocation.TABLE_2,
6180
6622
  onClick: selectJoinColumn,
6181
- children: meta.table2.column ? meta.table2.column : __('SqlQueryBuilder.pickTable')
6623
+ children: meta.table2.quotes ? meta.table2.quotes : __('SqlQueryBuilder.pickTable')
6182
6624
  })]
6183
- }), meta.table1.column_id && meta.table2.column_id && meta.expressions?.map((v, i) => {
6625
+ }), meta.table1.fieldUuid && meta.table2.fieldUuid && meta.expressions?.map((v, i) => {
6184
6626
  return jsxs("div", {
6185
6627
  className: cx(`Sqb-where block`),
6186
6628
  children: [jsx("span", {
@@ -6209,12 +6651,12 @@ const JoinData = props => {
6209
6651
  children: v.left_constant ? v.left_constant : __('SqlQueryBuilder.pickConstant')
6210
6652
  }), (!v.left_type || v.left_type === 'field') && jsx("div", {
6211
6653
  className: cx(`Sqb-TableName`, {
6212
- notSelected: !v.left_column
6654
+ notSelected: !v.left_quotes
6213
6655
  }),
6214
6656
  "v-data": ExpressionsEnum.LEFT,
6215
6657
  "v-index": i,
6216
6658
  onClick: selectMoreJoinColumn,
6217
- children: v.left_column ? v.left_column : __('SqlQueryBuilder.pickTable')
6659
+ children: v.left_quotes ? v.left_quotes : __('SqlQueryBuilder.pickTable')
6218
6660
  }), jsx(Tooltip, {
6219
6661
  title: __('SqlQueryBuilder.switch'),
6220
6662
  children: jsx(Button, {
@@ -6253,12 +6695,12 @@ const JoinData = props => {
6253
6695
  children: v.right_constant ? v.right_constant : __('SqlQueryBuilder.pickConstant')
6254
6696
  }), (!v.right_type || v.right_type === 'field') && jsx("div", {
6255
6697
  className: cx(`Sqb-TableName`, {
6256
- notSelected: !v.right_column
6698
+ notSelected: !v.right_quotes
6257
6699
  }),
6258
6700
  "v-data": ExpressionsEnum.RIGHT,
6259
6701
  "v-index": i,
6260
6702
  onClick: selectMoreJoinColumn,
6261
- children: v.right_column ? v.right_column : __('SqlQueryBuilder.pickTable')
6703
+ children: v.right_quotes ? v.right_quotes : __('SqlQueryBuilder.pickTable')
6262
6704
  }), jsx(Tooltip, {
6263
6705
  title: __('SqlQueryBuilder.switch'),
6264
6706
  children: jsx(Button, {
@@ -6284,16 +6726,17 @@ const JoinData = props => {
6284
6726
  let newMeta = store.metaList[groupIndex].list.slice();
6285
6727
  newMeta[index].expressions.splice(i + 1, 0, {
6286
6728
  operator: 'and',
6287
- left_column: '',
6288
- left_column_id: '',
6729
+ left_fieldAlias: '',
6730
+ left_fieldUuid: '',
6731
+ left_quotes: '',
6289
6732
  left_string: '',
6290
- left_isString: false,
6291
6733
  left_type: 'field',
6292
6734
  left_constant: '',
6293
- right_column: '',
6294
- right_column_id: '',
6735
+ right_fieldAlias: '',
6736
+ right_fieldUuid: '',
6737
+ right_quotes: '',
6295
6738
  right_string: '',
6296
- right_isString: false,
6739
+ // right_isString: false,
6297
6740
  right_type: 'field',
6298
6741
  right_constant: ''
6299
6742
  });
@@ -6316,7 +6759,7 @@ const JoinData = props => {
6316
6759
  })
6317
6760
  })]
6318
6761
  }, i);
6319
- }), meta.table1.column_id && meta.table2.column_id && (meta.expressions?.length || 0) < 1 && jsx(Tooltip, {
6762
+ }), meta.table1.fieldUuid && meta.table2.fieldUuid && (meta.expressions?.length || 0) < 1 && jsx(Tooltip, {
6320
6763
  title: __('SqlQueryBuilder.add'),
6321
6764
  children: jsx(Button, {
6322
6765
  disabled: meta.readonly,
@@ -6329,16 +6772,17 @@ const JoinData = props => {
6329
6772
  let newMeta = store.metaList[groupIndex].list.slice();
6330
6773
  newMeta[index].expressions = [{
6331
6774
  operator: 'and',
6332
- left_column: '',
6333
- left_column_id: '',
6775
+ left_fieldAlias: '',
6776
+ left_fieldUuid: '',
6777
+ left_quotes: '',
6334
6778
  left_string: '',
6335
- left_isString: false,
6336
6779
  left_type: 'field',
6337
6780
  left_constant: '',
6338
- right_column: '',
6339
- right_column_id: '',
6781
+ right_fieldAlias: '',
6782
+ right_fieldUuid: '',
6783
+ right_quotes: '',
6340
6784
  right_string: '',
6341
- right_isString: false,
6785
+ // right_isString: false,
6342
6786
  right_constant: '',
6343
6787
  right_type: 'field'
6344
6788
  }];
@@ -6487,12 +6931,12 @@ const CaseEditor = props => {
6487
6931
  onOk,
6488
6932
  onCancel
6489
6933
  } = props;
6490
- const [popup, setPopup] = useState({
6491
- visible: false
6492
- }); // 弹框信息
6934
+ // const [popup, setPopup] = useState<PopupType>({ visible: false }); // 弹框信息
6493
6935
  const [caseList, setCaseList] = useState(value.formulaList || []);
6494
6936
  const [name, setName] = useState(value?.name || ''); // 表达式名字
6495
6937
  const [ind, setInd] = useState(-1);
6938
+ const ref = useRef(null);
6939
+ const store = useStore$1();
6496
6940
  const filterCase = useMemo(() => {
6497
6941
  const hasCase = caseList.some(item => item.type === OptionsTypeEnum.OTHER && item.operator === 'case');
6498
6942
  if (hasCase) {
@@ -6504,24 +6948,22 @@ const CaseEditor = props => {
6504
6948
  const usable = useMemo(() => {
6505
6949
  return Array.from(caseList).length > 0 && name;
6506
6950
  }, [caseList, name]);
6507
- const popupContent = useMemo(() => {
6508
- let {
6509
- visible,
6510
- content
6511
- } = popup;
6512
- if (!visible) return null;
6513
- return content;
6514
- }, [popup]);
6951
+ // const popupContent = useMemo(() => {
6952
+ // let { visible, content } = popup;
6953
+ // if (!visible) return null;
6954
+ // return content;
6955
+ // }, [popup]);
6515
6956
  function closePopup() {
6516
- setPopup({
6957
+ store.setPopup({
6517
6958
  visible: false
6518
6959
  });
6519
6960
  }
6520
6961
  // 字段
6521
6962
  function handleField(e, i, val) {
6522
- setPopup({
6963
+ store.setPopup({
6523
6964
  visible: true,
6524
6965
  node: e.currentTarget,
6966
+ container: ref.current,
6525
6967
  content: jsx(SelectJoinColumn, {
6526
6968
  data: data,
6527
6969
  value: val,
@@ -6529,8 +6971,13 @@ const CaseEditor = props => {
6529
6971
  isGroup: true,
6530
6972
  // @ts-ignore
6531
6973
  onGroup: data => {
6974
+ let _data = cloneDeep(data);
6975
+ if (_data.alias != SummarizeAlias$1) {
6976
+ _data.fieldAlias = _data.name;
6977
+ _data.fieldUuid = uuidv4('field');
6978
+ }
6532
6979
  const _caseList = caseList.slice();
6533
- _caseList[i].expression = data;
6980
+ _caseList[i].expression = _data;
6534
6981
  setCaseList(_caseList);
6535
6982
  closePopup();
6536
6983
  }
@@ -6546,16 +6993,23 @@ const CaseEditor = props => {
6546
6993
  };
6547
6994
  // 表达式
6548
6995
  function handleExpression(e, i, val) {
6549
- setPopup({
6996
+ store.setPopup({
6550
6997
  visible: true,
6551
6998
  node: e.currentTarget,
6999
+ container: ref.current,
6552
7000
  content: jsx(SelectFilter, {
6553
7001
  isCustom: true,
7002
+ container: ref.current,
6554
7003
  data: data,
6555
7004
  value: val,
6556
7005
  onChange: data => {
7006
+ let _data = cloneDeep(data);
7007
+ if (_data.alias != SummarizeAlias$1) {
7008
+ _data.fieldAlias = _data.name;
7009
+ _data.fieldUuid = uuidv4('field');
7010
+ }
6557
7011
  const _caseList = caseList.slice();
6558
- _caseList[i].expression = data;
7012
+ _caseList[i].expression = _data;
6559
7013
  setCaseList(_caseList);
6560
7014
  closePopup();
6561
7015
  }
@@ -6598,8 +7052,7 @@ const CaseEditor = props => {
6598
7052
  const _onOk = () => {
6599
7053
  typeof onOk === 'function' && onOk?.({
6600
7054
  name,
6601
- formulaList: caseList,
6602
- formula: ''
7055
+ formulaList: caseList
6603
7056
  });
6604
7057
  };
6605
7058
  // 分段
@@ -6747,6 +7200,7 @@ const CaseEditor = props => {
6747
7200
  };
6748
7201
  return jsxs("div", {
6749
7202
  className: 'custom-box',
7203
+ ref: ref,
6750
7204
  children: [jsx(VisualBox$1, {
6751
7205
  children: jsx("div", {
6752
7206
  className: `Sqb-item Sqb-case-editor mb-2 mt-2`,
@@ -6884,13 +7338,6 @@ const CaseEditor = props => {
6884
7338
  })]
6885
7339
  })
6886
7340
  })
6887
- }), jsx(Popup, {
6888
- visible: popup.visible,
6889
- closable: true,
6890
- node: popup.node,
6891
- innerSpacing: popup.innerSpacing,
6892
- hideVisible: closePopup,
6893
- children: popupContent
6894
7341
  }), jsx("div", {
6895
7342
  className: `btns p-4`,
6896
7343
  children: jsxs("div", {
@@ -7022,14 +7469,15 @@ const CustomColumn = props => {
7022
7469
  }
7023
7470
  return data;
7024
7471
  }
7025
- // 子查询弹窗
7472
+ // 自定义弹窗
7026
7473
  const showSubQuery = (e, i) => {
7027
7474
  let newMeta = store.metaList[groupIndex].list.slice();
7028
7475
  const _value = newMeta[index].customColumn[i] || [];
7476
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : 0;
7029
7477
  let o = Modal2.openModal({
7030
7478
  title: __('SqlQueryBuilder.customExpression'),
7031
7479
  transparentMask: true,
7032
- zIndex: 200,
7480
+ zIndex: Number(zIndex),
7033
7481
  content: jsx(Fragment, {
7034
7482
  children: jsx(Provider, {
7035
7483
  value: store,
@@ -7183,6 +7631,9 @@ const Filter = props => {
7183
7631
  let {
7184
7632
  filter
7185
7633
  } = meta;
7634
+ const {
7635
+ notExistsColumns
7636
+ } = store.preProps;
7186
7637
  React__default.useRef(null);
7187
7638
  let index = findIndex(store.metaList[groupIndex].list, meta);
7188
7639
  let notSelected = !meta.filter.length;
@@ -7289,10 +7740,10 @@ const Filter = props => {
7289
7740
  let newMeta = store.metaList[groupIndex].list.slice();
7290
7741
  let val = filter[i];
7291
7742
  if (val.type === Filter_TypeEnum.NOT_EXISTS) {
7292
- showSubQuery(i, '');
7743
+ showNotExists(i, '');
7293
7744
  return;
7294
7745
  }
7295
- let data = getColumns();
7746
+ let data = [...getColumns(), ...cloneDeep(notExistsColumns || [])];
7296
7747
  store.setPopup({
7297
7748
  visible: true,
7298
7749
  node: e.currentTarget,
@@ -7310,8 +7761,8 @@ const Filter = props => {
7310
7761
  function handleAdd(e) {
7311
7762
  let node = e.currentTarget;
7312
7763
  let newMeta = store.metaList[groupIndex].list.slice();
7313
- let data = getColumns();
7314
- let _index = node.getAttribute('v-index');
7764
+ let data = [...getColumns(), ...cloneDeep(notExistsColumns || [])];
7765
+ let _index = Number(node.getAttribute('v-index'));
7315
7766
  let _type = node.getAttribute('v-type');
7316
7767
  let value = {
7317
7768
  table: '',
@@ -7347,15 +7798,16 @@ const Filter = props => {
7347
7798
  content: jsx(SelectFilter, {
7348
7799
  data: data,
7349
7800
  value: value,
7350
- onChange: data => {
7801
+ onChange: val => {
7351
7802
  if (_type) {
7352
7803
  if (_type === 'before') {
7353
- newMeta[index].filter.splice(_index, 0, data);
7804
+ newMeta[index].filter.splice(_index, 0, val);
7354
7805
  } else {
7355
- newMeta[index].filter.splice(_index + 1, 0, data);
7806
+ console.log('🚀 ~ ', newMeta[index].filter);
7807
+ newMeta[index].filter.splice(_index + 1, 0, val);
7356
7808
  }
7357
7809
  } else {
7358
- newMeta[index].filter.push(data);
7810
+ newMeta[index].filter.push(val);
7359
7811
  }
7360
7812
  store.setMeta(newMeta, groupIndex);
7361
7813
  closePopup();
@@ -7388,26 +7840,29 @@ const Filter = props => {
7388
7840
  newMeta[index].filter = [..._filter];
7389
7841
  setInd(-1);
7390
7842
  };
7391
- // 子查询弹窗
7392
- const showSubQuery = (i, position) => {
7843
+ // NotExists 窗口
7844
+ const showNotExists = (i, position) => {
7393
7845
  const {
7394
- subToolbar,
7846
+ notExistsToolbar,
7395
7847
  toolbar,
7396
7848
  ...other
7397
7849
  } = store.preProps;
7398
7850
  let newMeta = store.metaList[groupIndex].list.slice();
7399
7851
  let index = findIndex(store.metaList[groupIndex].list, meta);
7400
- let _value = position ? [] : newMeta[index].filter[i]?.subquery || [];
7401
- let oldList = position ? [] : cloneDeep(newMeta[index].filter[i]?.subquery || []);
7402
- let _toolbar = subToolbar || toolbar;
7852
+ let _value = position ? [] : newMeta[index].filter[i]?.notExists || [];
7853
+ let oldList = position ? [] : cloneDeep(newMeta[index].filter[i]?.notExists || []);
7854
+ let _toolbar = notExistsToolbar || toolbar;
7403
7855
  _toolbar = _toolbar.filter(v => v !== 'group'); // 子查询不需要分组
7856
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : null;
7857
+ let notExistsColumns = getColumns();
7404
7858
  let o = Modal2.openModal({
7405
7859
  title: 'NOT EXISTS',
7406
7860
  transparentMask: true,
7407
- zIndex: 200,
7861
+ zIndex: Number(zIndex),
7408
7862
  content: jsx(Fragment, {
7409
7863
  children: jsx(SqlVisionBuilder, {
7410
7864
  ...other,
7865
+ notExistsColumns: notExistsColumns,
7411
7866
  showFields: false,
7412
7867
  showSubquery: false,
7413
7868
  toolbar: _toolbar,
@@ -7421,8 +7876,8 @@ const Filter = props => {
7421
7876
  return;
7422
7877
  }
7423
7878
  const _tem = {
7424
- subquery: newList,
7425
- quotes: `${newList?.[0].table.datasourceName}.${newList?.[0].table.alias || newList?.[0].table.name}`,
7879
+ notExists: newList,
7880
+ quotes: buildSqlQuery(newList),
7426
7881
  condition: '',
7427
7882
  table: '',
7428
7883
  tableId: '',
@@ -7497,7 +7952,7 @@ const Filter = props => {
7497
7952
  if (type === Filter_TypeEnum.EXPRESSION) {
7498
7953
  handleAdd(_e);
7499
7954
  } else if (type === Filter_TypeEnum.NOT_EXISTS) {
7500
- showSubQuery(_index, _type);
7955
+ showNotExists(_index, _type);
7501
7956
  }
7502
7957
  }
7503
7958
  })
@@ -7564,7 +8019,7 @@ const Filter = props => {
7564
8019
  }, i) : jsxs("div", {
7565
8020
  className: `Sqb-TableName purple-name`,
7566
8021
  onClick: e => handleUpdate(e, i),
7567
- children: [v.quotes, jsx("span", {
8022
+ children: [v.type === Filter_TypeEnum.NOT_EXISTS ? 'not exitis ( * )' : v.quotes, jsx("span", {
7568
8023
  style: {
7569
8024
  fontSize: 0
7570
8025
  },
@@ -7608,7 +8063,7 @@ const Filter = props => {
7608
8063
  if (typeof v === 'string') {
7609
8064
  return v;
7610
8065
  } else if (v.type === Filter_TypeEnum.NOT_EXISTS) {
7611
- return 'not exitis ( * )';
8066
+ return `${buildSqlQuery(v.notExists)}`;
7612
8067
  } else {
7613
8068
  return v.quotes;
7614
8069
  }
@@ -7740,10 +8195,10 @@ const GroupBy = props => {
7740
8195
  newMeta[index].by.splice(i, 1, data);
7741
8196
  // @ts-ignore
7742
8197
  newMeta[index].by = newMeta[index].by.map(v => {
7743
- const fieldAlias = v.fieldAlias || `${v.alias}__${v.name}`;
8198
+ const fieldAlias = `${v.alias}__${v.name}`;
7744
8199
  return {
7745
8200
  ...v,
7746
- sql: `${v.alias}.${v.realName || v.name} AS ${fieldAlias}`,
8201
+ sql: `${v.alias}.${v.realName || v.name}`,
7747
8202
  fieldAlias: fieldAlias
7748
8203
  };
7749
8204
  });
@@ -7774,8 +8229,8 @@ const GroupBy = props => {
7774
8229
  quotes: '',
7775
8230
  datasourceId: '',
7776
8231
  datasourceName: '',
7777
- column: '',
7778
- column_id: '',
8232
+ // column: '',
8233
+ // column_id: '',
7779
8234
  summarizeType: MetaSummarize_Enum.BY
7780
8235
  };
7781
8236
  store.setPopup({
@@ -7792,10 +8247,10 @@ const GroupBy = props => {
7792
8247
  newMeta[index].by.push(data);
7793
8248
  // @ts-ignore
7794
8249
  newMeta[index].by = newMeta[index].by.map(v => {
7795
- const fieldAlias = v.fieldAlias || `${v.alias}__${v.name}`;
8250
+ const fieldAlias = `${v.alias}__${v.name}`;
7796
8251
  return {
7797
8252
  ...v,
7798
- sql: `${v.alias}.${v.realName || v.name} AS ${fieldAlias}`,
8253
+ sql: `${v.alias}.${v.realName || v.name}`,
7799
8254
  fieldAlias: fieldAlias,
7800
8255
  fieldUuid: uuidv4('field'),
7801
8256
  summarizeType: MetaSummarize_Enum.BY
@@ -8036,8 +8491,8 @@ const SelectIndex = props => {
8036
8491
  quotes: '',
8037
8492
  datasourceId: '',
8038
8493
  datasourceName: '',
8039
- column: '',
8040
- column_id: '',
8494
+ // column: '',
8495
+ // column_id: '',
8041
8496
  summarizeType: MetaSummarize_Enum.GROUP
8042
8497
  };
8043
8498
  store.setPopup({
@@ -8279,8 +8734,8 @@ const Sort = props => {
8279
8734
  let value = {
8280
8735
  table: '',
8281
8736
  tableId: '',
8282
- tableUuid: uuidv4('table'),
8283
- fieldUuid: uuidv4('field'),
8737
+ tableUuid: '',
8738
+ fieldUuid: '',
8284
8739
  fieldAlias: '',
8285
8740
  alias: '',
8286
8741
  name: '',
@@ -8607,7 +9062,8 @@ const Metabase = props => {
8607
9062
  } = props;
8608
9063
  const store = useStore$1();
8609
9064
  const [saveLoading, setSaveLoading] = useState(false);
8610
- const popupContainer = useRef();
9065
+ // const popupContainer = useRef();
9066
+ // store.setPopupContainer(popupContainer);
8611
9067
  const popupContent = useMemo(() => {
8612
9068
  let {
8613
9069
  visible,
@@ -8638,11 +9094,11 @@ const Metabase = props => {
8638
9094
  await onOk?.(_metaList);
8639
9095
  setSaveLoading(false);
8640
9096
  };
8641
- let zIndex = popupContainer.current ? getMaxZIndexInParents(popupContainer.current) : null;
9097
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : null;
8642
9098
  return (
8643
9099
  // @ts-ignore
8644
9100
  jsx(VisualBox, {
8645
- ref: popupContainer,
9101
+ ref: store.popupContainer,
8646
9102
  children: jsxs("div", {
8647
9103
  className: 'Sqb',
8648
9104
  children: [store.metaList.map((v, index) => {
@@ -8679,8 +9135,8 @@ const Metabase = props => {
8679
9135
  disabled: saveLoading,
8680
9136
  onClick: onSave,
8681
9137
  children: btnText || __('SqlQueryBuilder.visualize')
8682
- }) : null, popupContainer.current && jsx(Popup, {
8683
- container: popupContainer.current,
9138
+ }) : null, store.popupContainer.current && jsx(Popup, {
9139
+ container: store.popupData.container || store.popupContainer.current,
8684
9140
  visible: store.popupData.visible,
8685
9141
  node: store.popupData.node,
8686
9142
  closable: store.popupClosable,
@@ -8691,8 +9147,8 @@ const Metabase = props => {
8691
9147
  });
8692
9148
  },
8693
9149
  children: popupContent
8694
- }), popupContainer.current && jsx(Popup, {
8695
- container: popupContainer.current,
9150
+ }), store.popupContainer.current && jsx(Popup, {
9151
+ container: store.popupData2.container || store.popupContainer.current,
8696
9152
  visible: store.popupData2.visible,
8697
9153
  node: store.popupData2.node,
8698
9154
  closable: store.popupClosable2,