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

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,19 +1,19 @@
1
1
  /**
2
- * @gingkoo/pandora-metabase v1.0.0-alpha.3
2
+ * @gingkoo/pandora-metabase v1.0.0-alpha.31
3
3
  */
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import * as React from 'react';
6
6
  import React__default, { useContext, createContext, useState, useRef, useMemo, useEffect, forwardRef, useImperativeHandle } from 'react';
7
7
  import cloneDeep from 'lodash/cloneDeep';
8
8
  import cx from 'classnames';
9
- import { Tooltip, Button, Modal, Input, DatePicker, Dropdown, InputNumber, Select, Modal2, Toast } from '@gingkoo/pandora';
9
+ import { Tooltip, Button, Modal, Input, DatePicker, Dropdown, InputNumber, Select, Toast, Modal2 } 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';
@@ -986,6 +1224,7 @@ const useStore = () => {
986
1224
  const [tableNameTpl, setTableNameTpl] = useState('${name}'); //显示字段
987
1225
  const [sourceList, setSourceList] = useState([]); //数据源列表
988
1226
  const [constantList, setConstantList] = useState([]); //常量列表
1227
+ const [ignoreGroupByType, setIgnoreGroupByType] = useState(false); // 忽略groupBy类型
989
1228
  const [_cacheSource2TableMap, set_cacheSource2TableMap] = useState({}); //数据源id 对应数据集列表
990
1229
  const [_cacheColumnsMap, set_cacheColumnsMap] = useState({}); //数据源id 对应数据集列表
991
1230
  const [metaList, _setMeta] = useState(defaultMeta); //数据源id 对应数据集列表
@@ -1001,6 +1240,8 @@ const useStore = () => {
1001
1240
  }); //弹窗
1002
1241
  const [popupClosable, setClosable] = useState(true); //是否可关闭 如果弹框里面再弹框 则不可关闭
1003
1242
  const [popupClosable2, setClosable2] = useState(true); //是否可关闭 如果弹框里面再弹框 则不可关闭
1243
+ // 外层ref
1244
+ const popupContainer = useRef();
1004
1245
  // const [fetchDatasetFn, setFetchDatasetFn] = useState<(id: string) => Promise<any>>(
1005
1246
  // async () => {},
1006
1247
  // ); //fn
@@ -1018,18 +1259,18 @@ const useStore = () => {
1018
1259
  };
1019
1260
  // 是否显示主表后面的字段按钮 (如果下面 没有聚合,或者选了聚合但是聚合里面没有选值的时候显示 主表字段按钮)
1020
1261
  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;
1262
+ return metaList?.map((item, groupIndex) => {
1263
+ // 过滤出所有汇总类型的项
1264
+ const summarizeItems = item.list.filter(v => v.type === TypeEnum.summarize);
1265
+ // 如果没有汇总项,默认显示主列
1266
+ if (summarizeItems.length === 0) {
1267
+ return true;
1268
+ }
1269
+ // 如果只有一个汇总项,并且 group 和 by 都为空,则也显示主列
1270
+ const onlyItem = summarizeItems[0];
1271
+ const hasGroupOrBy = Array.isArray(onlyItem.group) && onlyItem.group.length > 0 || Array.isArray(onlyItem.by) && onlyItem.by.length > 0;
1272
+ return !hasGroupOrBy;
1273
+ });
1033
1274
  }, [metaList]);
1034
1275
  // const showMainColumn = useMemo(() => {
1035
1276
  // let summarizeList = metaList.filter((v) => v.type === TypeEnum.summarize);
@@ -1073,7 +1314,7 @@ const useStore = () => {
1073
1314
  columns = await fetchColumnsFn.current(extra, datasourceId);
1074
1315
  setColumns(tableName, columns);
1075
1316
  }
1076
- const _columns = columns.map(v => {
1317
+ const _columns = columns?.map(v => {
1077
1318
  return {
1078
1319
  ...v,
1079
1320
  fieldUuid: v.fieldAlias || uuidv4('field')
@@ -1087,21 +1328,56 @@ const useStore = () => {
1087
1328
  _setMeta(newMeta);
1088
1329
  };
1089
1330
  // 回显
1090
- const setPreData = async data => {
1331
+ // 设置column
1332
+ const setQuotes = newMeta => {
1333
+ newMeta.table1 = {
1334
+ ...newMeta.table1,
1335
+ fieldAlias: newMeta.table1.fieldAlias || newMeta.table1.column,
1336
+ fieldUuid: newMeta.table1.fieldUuid || uuidv4('field'),
1337
+ quotes: newMeta.table1.quotes || newMeta.table1.column,
1338
+ tableUuid: newMeta.table1.tableUuid || uuidv4('table')
1339
+ };
1340
+ newMeta.table2 = {
1341
+ ...newMeta.table2,
1342
+ fieldAlias: newMeta.table2.fieldAlias || newMeta.table2.column,
1343
+ fieldUuid: newMeta.table2.fieldUuid || uuidv4('field'),
1344
+ quotes: newMeta.table2.quotes || newMeta.table2.column,
1345
+ tableUuid: newMeta.table2.tableUuid || uuidv4('table')
1346
+ };
1347
+ newMeta.expressions = newMeta.expressions?.map(v => {
1348
+ return {
1349
+ ...v,
1350
+ left_fieldAlias: v.left_fieldAlias || v.left_column,
1351
+ left_fieldUuid: v.left_fieldUuid || uuidv4('field'),
1352
+ left_quotes: v.left_quotes || v.left_column,
1353
+ right_fieldAlias: v.right_fieldAlias || v.right_column,
1354
+ right_fieldUuid: v.right_fieldUuid || uuidv4('field'),
1355
+ right_quotes: v.right_quotes || v.right_column
1356
+ };
1357
+ });
1358
+ return newMeta;
1359
+ };
1360
+ const setPreData = data => {
1091
1361
  if (data.length) {
1092
- let _metaList = data.map((item, groupIndex) => {
1362
+ let _metaList = data?.map((item, groupIndex) => {
1093
1363
  let newList = item.list?.map((v, i) => {
1094
- let newMeta = cloneDeep(item.list);
1364
+ let newMeta = item.list;
1365
+ if (v.table) {
1366
+ v.table.tableUuid = v.table.tableUuid || uuidv4('table');
1367
+ }
1368
+ if (v.type === TypeEnum.joinData) {
1369
+ newMeta[i] = setQuotes(newMeta[i]);
1370
+ }
1095
1371
  // 设置右侧column
1096
1372
  if (v.table2?.datasourceId && v.columns.length < 1) {
1097
- fetchColumns(newMeta[i].table2, newMeta[i].table2.datasourceId, columns => {
1373
+ fetchColumns(newMeta[i].table2, newMeta[i].table2.datasourceId, (columns = []) => {
1098
1374
  if (v.isSubquery) {
1099
1375
  let newColumns = [];
1100
1376
  const items = getSubColumns(v.subquery);
1101
- newColumns = items.flatMap(item => item.columns);
1102
- newMeta[i].columns = newColumns;
1377
+ newColumns = items?.flatMap(item => item.columns);
1378
+ newMeta[i].columns = newColumns || [];
1103
1379
  } else {
1104
- newMeta[i].columns = columns;
1380
+ newMeta[i].columns = columns || [];
1105
1381
  }
1106
1382
  setMeta(newMeta, groupIndex);
1107
1383
  });
@@ -1111,15 +1387,18 @@ const useStore = () => {
1111
1387
  }
1112
1388
  // 设置column
1113
1389
  if (v.table?.datasourceId && v.columns.length < 1) {
1114
- fetchColumns(newMeta[i].table, newMeta[i].table.datasourceId, columns => {
1390
+ fetchColumns(newMeta[i].table, newMeta[i].table.datasourceId, (columns = []) => {
1115
1391
  if (v.isSubquery) {
1116
1392
  let newColumns = [];
1117
1393
  const items = getSubColumns(v.subquery);
1118
1394
  newColumns = items.flatMap(item => item.columns);
1119
- newMeta[i].columns = newColumns;
1395
+ newMeta[i].columns = newColumns || [];
1120
1396
  } else {
1121
- newMeta[i].columns = columns;
1397
+ newMeta[i].columns = columns || [];
1122
1398
  }
1399
+ // if (v.type === TypeEnum.joinData) {
1400
+ // newMeta[i] = setQuotes(newMeta[i]);
1401
+ // }
1123
1402
  setMeta(newMeta, groupIndex);
1124
1403
  });
1125
1404
  return {
@@ -1157,8 +1436,8 @@ const useStore = () => {
1157
1436
  tableUuid: '',
1158
1437
  datasourceId: '',
1159
1438
  datasourceName: '',
1160
- column: '',
1161
- column_id: ''
1439
+ fieldAlias: '',
1440
+ fieldUuid: ''
1162
1441
  };
1163
1442
  if (index === 1) {
1164
1443
  table1 = {
@@ -1167,8 +1446,8 @@ const useStore = () => {
1167
1446
  alias: mainTable.table.alias,
1168
1447
  datasourceId: mainTable.table.datasourceId,
1169
1448
  datasourceName: mainTable.table.datasourceName,
1170
- column: '',
1171
- column_id: ''
1449
+ fieldAlias: '',
1450
+ fieldUuid: ''
1172
1451
  };
1173
1452
  }
1174
1453
  item = {
@@ -1183,8 +1462,8 @@ const useStore = () => {
1183
1462
  tableUuid: '',
1184
1463
  datasourceId: '',
1185
1464
  datasourceName: '',
1186
- column: '',
1187
- column_id: ''
1465
+ fieldAlias: '',
1466
+ fieldUuid: ''
1188
1467
  },
1189
1468
  columns: [],
1190
1469
  expressions: []
@@ -1293,7 +1572,7 @@ const useStore = () => {
1293
1572
  setMeta(_metaList, groupIndex);
1294
1573
  };
1295
1574
  const setColumns = (tableId, columns) => {
1296
- const _columns = columns.map(v => {
1575
+ const _columns = columns?.map(v => {
1297
1576
  return {
1298
1577
  ...v,
1299
1578
  fieldUuid: v.fieldUuid || uuidv4('field')
@@ -1318,46 +1597,10 @@ const useStore = () => {
1318
1597
  const getDataset = datasourceId => {
1319
1598
  return _cacheSource2TableMap[datasourceId] || [];
1320
1599
  };
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
1600
  const reset = () => {
1358
1601
  // setSourceList([]);
1359
1602
  _setMeta(defaultMeta);
1360
- setToolbar(defaultToolbar);
1603
+ // setToolbar(defaultToolbar);
1361
1604
  set_cacheSource2TableMap({});
1362
1605
  set_cacheColumnsMap({});
1363
1606
  };
@@ -1411,40 +1654,12 @@ const useStore = () => {
1411
1654
  _setShowSubquery,
1412
1655
  constantList,
1413
1656
  setConstantList,
1414
- changeAlias
1657
+ popupContainer,
1658
+ ignoreGroupByType,
1659
+ setIgnoreGroupByType
1415
1660
  };
1416
1661
  };
1417
1662
 
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
1663
  register('en', {
1449
1664
  'data.pleaseSelectDataTable': 'please select data table',
1450
1665
  'data.calculatingNow': 'calculating now...',
@@ -1492,6 +1707,7 @@ register('en', {
1492
1707
  'SqlQueryBuilder.visualize': 'visualize',
1493
1708
  'SqlQueryBuilder.selectColumnAll': 'select all',
1494
1709
  'SqlQueryBuilder.alias': 'alias',
1710
+ 'SqlQueryBuilder.aliasCannotEmpty': 'Alias cannot be empty',
1495
1711
  'customColumn.operator': 'operator',
1496
1712
  'customColumn.field': 'field',
1497
1713
  'customColumn.constant': 'constant',
@@ -1636,6 +1852,7 @@ register('zh', {
1636
1852
  'SqlQueryBuilder.visualize': '可视化',
1637
1853
  'SqlQueryBuilder.selectColumnAll': '全选',
1638
1854
  'SqlQueryBuilder.alias': '别名',
1855
+ 'SqlQueryBuilder.aliasCannotEmpty': '别名不能为空',
1639
1856
  'customColumn.operator': '运算符',
1640
1857
  'customColumn.field': '字段',
1641
1858
  'customColumn.constant': '常量',
@@ -1781,7 +1998,7 @@ const Loading = ({
1781
1998
  });
1782
1999
  };
1783
2000
 
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";
2001
+ 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
2002
  styleInject(css_248z$d);
1786
2003
 
1787
2004
  // 获取元素translate x y值
@@ -1813,6 +2030,7 @@ const getComputedTranslate = obj => {
1813
2030
  };
1814
2031
  // 获取元素距离浏览器顶部的距离
1815
2032
  const getElementTop = elem => {
2033
+ if (!elem) return 0;
1816
2034
  let elemTop = elem.offsetTop;
1817
2035
  let pElem = elem.offsetParent;
1818
2036
  while (pElem != null) {
@@ -1826,6 +2044,7 @@ const getElementTop = elem => {
1826
2044
  };
1827
2045
  // 获取元素距离浏览器顶部的距离
1828
2046
  const getElementLeft = elem => {
2047
+ if (!elem) return 0;
1829
2048
  let elemLeft = elem.offsetLeft;
1830
2049
  let pElem = elem.offsetParent;
1831
2050
  while (pElem != null) {
@@ -1837,8 +2056,23 @@ const getElementLeft = elem => {
1837
2056
  }
1838
2057
  return elemLeft;
1839
2058
  };
1840
- const getScrollTop = () => {
1841
- return document.documentElement.scrollTop;
2059
+ // 获取元素可见范围内高度
2060
+ const getContainerVisibleHeight = container => {
2061
+ if (!container) return 0;
2062
+ const rect = container.getBoundingClientRect();
2063
+ const windowHeight = window.innerHeight || document.documentElement.clientHeight;
2064
+ // 元素顶部在视口上方 -> 不可见
2065
+ if (rect.bottom < 0) return 0;
2066
+ // 元素底部在视口下方 -> 不可见
2067
+ if (rect.top > windowHeight) return 0;
2068
+ // 可见区域的 top 和 bottom
2069
+ const visibleTop = Math.max(rect.top, 0);
2070
+ const visibleBottom = Math.min(rect.bottom, windowHeight);
2071
+ // 可见高度
2072
+ return visibleBottom - visibleTop;
2073
+ };
2074
+ const getScrollTop = elem => {
2075
+ return elem?.scrollTop || document.documentElement.scrollTop;
1842
2076
  };
1843
2077
  // 浏览器可视宽高
1844
2078
  const getWindowSize = () => {
@@ -3393,7 +3627,9 @@ const Portal = /*#__PURE__*/forwardRef((props, ref) => {
3393
3627
  initRef.current = true;
3394
3628
  }
3395
3629
  useEffect(() => {
3396
- didUpdate?.(props, containerRef.current);
3630
+ setTimeout(() => {
3631
+ didUpdate?.(props, containerRef.current);
3632
+ }, 0);
3397
3633
  });
3398
3634
  useEffect(() => {
3399
3635
  return () => {
@@ -3409,6 +3645,7 @@ function returnDocument(element) {
3409
3645
  const outSpacing = 10;
3410
3646
  function generateTrigger(PortalComponent) {
3411
3647
  class Trigger extends React.Component {
3648
+ resizeObserver = null; // 显式声明 resizeObserver 属性
3412
3649
  resetId = -1; // 监听窗口改变事件id 用于组件销毁的时候清除事件
3413
3650
  static defaultProps = {
3414
3651
  visible: false,
@@ -3423,11 +3660,39 @@ function generateTrigger(PortalComponent) {
3423
3660
  this.resetId = winResetEvent.addEvent(this.didUpdate, this, 300);
3424
3661
  this.props.container && this.props.container.addEventListener('scroll', this.didUpdate);
3425
3662
  this.bindEvent();
3663
+ // 延迟绑定 ResizeObserver 到 ensure the element is ready
3664
+ this.initResizeObserver();
3665
+ }
3666
+ componentDidUpdate(prevProps) {
3667
+ // 如果 children 发生变化,重新初始化观察器
3668
+ if (prevProps.children !== this.props.children) {
3669
+ this.initResizeObserver();
3670
+ }
3426
3671
  }
3427
3672
  componentWillUnmount() {
3428
3673
  winResetEvent.removeEvent(this.resetId);
3429
3674
  this.props.container && this.props.container.removeEventListener('scroll', this.didUpdate);
3675
+ if (this.resizeObserver) {
3676
+ this.resizeObserver.disconnect();
3677
+ this.resizeObserver = null;
3678
+ }
3430
3679
  }
3680
+ // children高度变化后,从新计算高度
3681
+ initResizeObserver = () => {
3682
+ const targetNode = this.ref.current;
3683
+ if (!targetNode) return;
3684
+ // 如果已经存在 ResizeObserver,先断开连接
3685
+ if (this.resizeObserver) {
3686
+ this.resizeObserver.disconnect();
3687
+ }
3688
+ // 初始化 ResizeObserver 并开始观察目标节点
3689
+ this.resizeObserver = new ResizeObserver(entries => {
3690
+ entries.forEach(entry => {
3691
+ this.didUpdate();
3692
+ });
3693
+ });
3694
+ this.resizeObserver.observe(targetNode);
3695
+ };
3431
3696
  bindEvent = () => {
3432
3697
  let that = this;
3433
3698
  returnDocument().body.addEventListener('click', function (e) {
@@ -3445,7 +3710,7 @@ function generateTrigger(PortalComponent) {
3445
3710
  this.props.visible && this.props.closable && this.props.hideVisible();
3446
3711
  };
3447
3712
  attachParent = popupContainer => {
3448
- let mountNode = returnDocument().body;
3713
+ let mountNode = this.props.container || returnDocument().body;
3449
3714
  mountNode.appendChild(popupContainer);
3450
3715
  };
3451
3716
  getCurrentNodePos = () => {
@@ -3454,8 +3719,9 @@ function generateTrigger(PortalComponent) {
3454
3719
  container
3455
3720
  } = this.props;
3456
3721
  return {
3457
- x: getElementLeft(node),
3458
- y: getElementTop(node) - (container?.scrollTop || 0),
3722
+ x: getElementLeft(node) - getElementLeft(container),
3723
+ y: getElementTop(node) - getElementTop(container),
3724
+ t: getElementTop(container),
3459
3725
  h: node.offsetHeight
3460
3726
  };
3461
3727
  };
@@ -3489,6 +3755,7 @@ function generateTrigger(PortalComponent) {
3489
3755
  borderRadius: 6
3490
3756
  },
3491
3757
  onClick: e => this.props.closable && e.stopPropagation(),
3758
+ onMouseDown: e => e.stopPropagation(),
3492
3759
  children: /*#__PURE__*/React.cloneElement(this.props.children, {
3493
3760
  key: posKey,
3494
3761
  didUpdate: this.didUpdate
@@ -3498,19 +3765,21 @@ function generateTrigger(PortalComponent) {
3498
3765
  didUpdate = () => {
3499
3766
  if (!this.props.node) return false;
3500
3767
  let {
3501
- innerSpacing = 10
3768
+ innerSpacing = 10,
3769
+ container
3502
3770
  } = this.props;
3503
3771
  let pos = this.getCurrentNodePos();
3504
- let posY = pos.y - getScrollTop();
3772
+ let posY = pos.y - getScrollTop(container);
3505
3773
  if (!this.ref) return false;
3506
3774
  let realHeight = this.ref?.current?.childNodes?.[0]?.offsetHeight || 0;
3507
3775
  if (!realHeight) return false;
3508
3776
  let {
3509
3777
  height: winH
3510
3778
  } = getWindowSize();
3511
- let downH = winH - posY - pos.h; // 元素下面可用高度
3779
+ let containerH = getContainerVisibleHeight(container);
3780
+ let downH = (containerH || winH) - posY - pos.h; // 元素下面可用高度
3512
3781
  let maxHeight = 0;
3513
- let topHeight = getScrollTop();
3782
+ let topHeight = getScrollTop(container);
3514
3783
  if (downH >= posY || realHeight <= downH - innerSpacing - outSpacing) {
3515
3784
  // 下面比上面宽敞 或 下面足够放下所有 放下面
3516
3785
  maxHeight = Math.min(realHeight, downH - innerSpacing - outSpacing);
@@ -3546,7 +3815,7 @@ styleInject(css_248z$9);
3546
3815
  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
3816
  styleInject(css_248z$8);
3548
3817
 
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";
3818
+ 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
3819
  styleInject(css_248z$7);
3551
3820
 
3552
3821
  // 选择表中参数
@@ -3555,11 +3824,21 @@ const SelectColumn = ({
3555
3824
  groupIndex,
3556
3825
  onChange
3557
3826
  }) => {
3558
- const [columns, setColumns] = useState(_data.slice());
3827
+ const [columns, setColumns] = useState([]);
3828
+ const [originList, setOriginList] = useState(_data.slice());
3559
3829
  const store = useStore$1();
3830
+ const [filterVal, setFilterVal] = useState('');
3831
+ useEffect(() => {
3832
+ let newList = cloneDeep(originList.slice());
3833
+ setColumns(newList.filter(v => ~(v.name + (v.name_zh || '')).toLocaleLowerCase().indexOf(filterVal.toLocaleLowerCase())));
3834
+ }, [filterVal, originList]);
3835
+ function onInput(e) {
3836
+ let val = e.target.value;
3837
+ setFilterVal(val);
3838
+ }
3560
3839
  const isAllSelect = useMemo(() => {
3561
- return columns.filter(v => v.select).length === columns.length;
3562
- }, [columns]);
3840
+ return originList.filter(v => v.select).length === originList.length;
3841
+ }, [originList]);
3563
3842
  const AllSelectElement = useMemo(() => {
3564
3843
  if (isAllSelect) {
3565
3844
  return jsxs(Fragment, {
@@ -3578,8 +3857,14 @@ const SelectColumn = ({
3578
3857
  }
3579
3858
  }, [isAllSelect]);
3580
3859
  function onSelect(columns) {
3860
+ const originalData = cloneDeep(originList); // 原始数据
3861
+ const mergedColumns = originalData.map(item => {
3862
+ const match = columns.find(col => col.fieldUuid === item.fieldUuid);
3863
+ return match ? cloneDeep(match) : item; // 可选:是否需要深拷贝 match
3864
+ });
3581
3865
  setColumns(columns);
3582
- typeof onChange === 'function' && onChange(columns);
3866
+ setOriginList(mergedColumns);
3867
+ typeof onChange === 'function' && onChange(mergedColumns);
3583
3868
  }
3584
3869
  const onChangeFieldAlias = (val, i) => {
3585
3870
  let fieldAlias = val || '';
@@ -3600,10 +3885,14 @@ const SelectColumn = ({
3600
3885
  newMetaList = changeFieldAlias(newMetaList, newColumns[i]);
3601
3886
  store.setMeta(newMetaList, groupIndex);
3602
3887
  onSelect(newColumns);
3603
- store.setClosable(true);
3888
+ setTimeout(() => {
3889
+ store.setClosable(true);
3890
+ }, 0);
3604
3891
  },
3605
3892
  onCancel: () => {
3606
- store.setClosable(true);
3893
+ setTimeout(() => {
3894
+ store.setClosable(true);
3895
+ }, 0);
3607
3896
  }
3608
3897
  });
3609
3898
  };
@@ -3623,6 +3912,18 @@ const SelectColumn = ({
3623
3912
  onSelect(newColumns);
3624
3913
  },
3625
3914
  children: AllSelectElement
3915
+ }), jsxs("div", {
3916
+ className: cx(`Sqb-SelectColumn-search m-2 rounded-lg`),
3917
+ children: [jsx("span", {
3918
+ className: 'px-2',
3919
+ children: jsx(SearchIcon, {})
3920
+ }), jsx("input", {
3921
+ type: 'text',
3922
+ autoFocus: true,
3923
+ className: 'p-1',
3924
+ placeholder: __('data.search'),
3925
+ onInput: onInput
3926
+ })]
3626
3927
  }), Array.isArray(columns) && columns.map((v, i) => {
3627
3928
  return jsxs("div", {
3628
3929
  className: 'pb-2 px-2 flex items-center',
@@ -3660,7 +3961,7 @@ const SelectColumn = ({
3660
3961
  });
3661
3962
  };
3662
3963
 
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";
3964
+ 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
3965
  styleInject(css_248z$6);
3665
3966
 
3666
3967
  const NUMBER_GROUP = [SQL_COLUMN_TYPE.FLOAT, SQL_COLUMN_TYPE.LONG, SQL_COLUMN_TYPE.CURRENCY];
@@ -3691,10 +3992,10 @@ const SelectJoinColumn = ({
3691
3992
  }) => {
3692
3993
  const store = useStore$1();
3693
3994
  const [value, setValue] = useState(_value); // 当前选择的字段
3694
- const [curTable, setCurTable] = useState(_value.alias); // 当前选择的表
3995
+ const [curTable, setCurTable] = useState(_value.tableUuid); // 当前选择的表
3695
3996
  const [curColumn, setCurColumn] = useState(_value.name); // 当前选择的字段
3696
3997
  const [tableList, setTableList] = useState(_data.map((v, i) => {
3697
- let open = !i && !_value.alias ? true : v.alias === _value.alias; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
3998
+ let open = !i && !_value.tableUuid ? true : v.tableUuid === _value.tableUuid; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
3698
3999
  return {
3699
4000
  ...v,
3700
4001
  open,
@@ -3704,12 +4005,12 @@ const SelectJoinColumn = ({
3704
4005
  }));
3705
4006
  useEffect(() => {
3706
4007
  setValue(_value);
3707
- setCurTable(_value.alias);
4008
+ setCurTable(_value.tableUuid);
3708
4009
  setCurColumn(_value.name);
3709
4010
  }, [_value]);
3710
4011
  useEffect(() => {
3711
4012
  setTableList(_data.map((v, i) => {
3712
- let open = !i && !_value.alias ? true : v.alias === _value.alias; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
4013
+ let open = !i && !_value.tableUuid ? true : v.tableUuid === _value.tableUuid; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
3713
4014
  return {
3714
4015
  ...v,
3715
4016
  open,
@@ -3769,16 +4070,17 @@ const SelectJoinColumn = ({
3769
4070
  if (open) {
3770
4071
  setTableList(newTables.map(v => ({
3771
4072
  ...v,
3772
- open: tableAlias === v.alias ? false : v.open
4073
+ open: tableUuid === v.tableUuid ? false : v.open
3773
4074
  })));
3774
4075
  } else {
3775
4076
  setTableList(newTables.map(v => ({
3776
4077
  ...v,
3777
- open: tableAlias === v.alias || v.alias === SummarizeAlias$1
4078
+ open: tableUuid === v.tableUuid || v.alias === SummarizeAlias$1
3778
4079
  })));
3779
4080
  }
3780
4081
  },
3781
- children: jsxs("a", {
4082
+ children: jsxs("div", {
4083
+ className: 'List-item',
3782
4084
  children: [jsx("span", {
3783
4085
  className: 'List-item-icon',
3784
4086
  children: jsx(TableIcon, {})
@@ -3797,7 +4099,7 @@ const SelectJoinColumn = ({
3797
4099
  })]
3798
4100
  })
3799
4101
  })
3800
- }), open && jsxs(Fragment, {
4102
+ }), (open || isSummarize) && jsxs(Fragment, {
3801
4103
  children: [!isSummarize && jsx("div", {
3802
4104
  className: cx(`Sqb-List-section`),
3803
4105
  children: jsxs("div", {
@@ -3835,7 +4137,7 @@ const SelectJoinColumn = ({
3835
4137
  className: cx(`Sqb-List-section`),
3836
4138
  children: jsxs("div", {
3837
4139
  className: cx(`Sqb-List-item mx-2`, {
3838
- active: curColumn === name && curTable === tableAlias
4140
+ active: curColumn === name && curTable === tableUuid
3839
4141
  }),
3840
4142
  onClick: () => {
3841
4143
  if (isGroup && typeof onGroup === 'function') {
@@ -3843,7 +4145,7 @@ const SelectJoinColumn = ({
3843
4145
  let quotes = name;
3844
4146
  return onGroup({
3845
4147
  ..._value,
3846
- tableUuid: _value.tableUuid || tableUuid,
4148
+ tableUuid: tableUuid || _value.tableUuid,
3847
4149
  ...v,
3848
4150
  table,
3849
4151
  tableId,
@@ -3857,7 +4159,7 @@ const SelectJoinColumn = ({
3857
4159
  }
3858
4160
  typeof onSelect === 'function' && onSelect({
3859
4161
  ..._value,
3860
- tableUuid: _value.tableUuid || tableUuid,
4162
+ tableUuid: tableUuid || _value.tableUuid,
3861
4163
  ...v,
3862
4164
  table,
3863
4165
  tableId,
@@ -3870,8 +4172,8 @@ const SelectJoinColumn = ({
3870
4172
  realName
3871
4173
  });
3872
4174
  },
3873
- children: [jsxs("a", {
3874
- className: 'p-2',
4175
+ children: [jsxs("div", {
4176
+ className: 'p-2 List-item',
3875
4177
  children: [jsx("span", {
3876
4178
  className: 'List-item-icon',
3877
4179
  children: IconMap[special_type || database_type] || jsx(LetterAaIcon, {})
@@ -3910,7 +4212,8 @@ const SelectFilterColumn = ({
3910
4212
  value,
3911
4213
  onChange,
3912
4214
  didUpdate,
3913
- isCustom: _isCustom = false
4215
+ isCustom: _isCustom = false,
4216
+ container: _container = null
3914
4217
  }) => {
3915
4218
  const [curColumn, setCurColumn] = useState(value);
3916
4219
  const [condition, setCondition] = useState(value.condition);
@@ -4272,7 +4575,7 @@ const SelectFilterColumn = ({
4272
4575
  },
4273
4576
  format: 'YYYY-MM-DD HH:mm',
4274
4577
  className: 'w_300',
4275
- value: moment(firstVal ?? undefined),
4578
+ value: firstVal ? moment(firstVal) : '',
4276
4579
  onChange: val => {
4277
4580
  if (val) {
4278
4581
  setVal([moment(val).format('YYYY-MM-DD HH:mm')]);
@@ -4327,6 +4630,7 @@ const SelectFilterColumn = ({
4327
4630
  store.setPopup2({
4328
4631
  visible: true,
4329
4632
  node: e.currentTarget,
4633
+ container: _container,
4330
4634
  content: jsx(SelectList, {
4331
4635
  value: valType,
4332
4636
  list: store.constantList || [],
@@ -4349,6 +4653,7 @@ const SelectFilterColumn = ({
4349
4653
  store.setPopup2({
4350
4654
  visible: true,
4351
4655
  node: e.currentTarget,
4656
+ container: _container,
4352
4657
  content: jsx(SelectList, {
4353
4658
  value: valType,
4354
4659
  list: [{
@@ -4383,6 +4688,7 @@ const SelectFilterColumn = ({
4383
4688
  store.setPopup2({
4384
4689
  visible: true,
4385
4690
  node: e.currentTarget,
4691
+ container: _container,
4386
4692
  content: jsx(SelectJoinColumn, {
4387
4693
  data: [..._data],
4388
4694
  value: value,
@@ -4670,7 +4976,8 @@ const SelectSummarize = ({
4670
4976
  data,
4671
4977
  value,
4672
4978
  onChange,
4673
- didUpdate
4979
+ didUpdate,
4980
+ ignoreGroupByType
4674
4981
  }) => {
4675
4982
  const [condition, setCondition] = useState(value.condition);
4676
4983
  function goPrevPage() {
@@ -4686,12 +4993,12 @@ const SelectSummarize = ({
4686
4993
  }
4687
4994
  if (condition && !~Special.indexOf(condition)) {
4688
4995
  let availableData = data.slice();
4689
- if (condition !== '不重复值的总数') {
4996
+ if (condition !== '不重复值的总数' && !ignoreGroupByType) {
4690
4997
  // 只能用数字类型做聚合
4691
4998
  availableData = data.map(v => {
4692
4999
  return {
4693
5000
  ...v,
4694
- columns: v.columns.filter(o => o.database_type && NUMBER_GROUP.includes(o.database_type))
5001
+ columns: v.columns.filter(o => o.database_type && (NUMBER_GROUP.includes(o.database_type) || (condition === '最大值' || condition === '最小值') && DATE_GROUP.includes(o.database_type)))
4695
5002
  };
4696
5003
  }).filter(v => v.columns.length);
4697
5004
  }
@@ -5374,6 +5681,7 @@ const TableData = props => {
5374
5681
  } = props;
5375
5682
  const store = useStore$1();
5376
5683
  let selected = Boolean(meta.table.name);
5684
+ let subQuerySelected = Boolean(meta.subquery?.[0]?.table?.name);
5377
5685
  function selectTable(e) {
5378
5686
  !meta.readonly && store.setPopup({
5379
5687
  visible: true,
@@ -5429,16 +5737,94 @@ const TableData = props => {
5429
5737
  alias = val;
5430
5738
  }
5431
5739
  }),
5432
- onOk: () => {
5433
- let newMetaList = store.metaList[groupIndex].list.slice();
5434
- // @ts-ignore
5435
- newMetaList[0].table.alias = alias;
5436
- newMetaList = changeTableAlias(newMetaList, newMetaList[0].table);
5437
- store.setMeta(newMetaList, groupIndex);
5740
+ onOk: async () => {
5741
+ if (!alias) {
5742
+ Toast.warning(__('SqlQueryBuilder.aliasCannotEmpty'));
5743
+ return false;
5744
+ } else {
5745
+ let newMetaList = store.metaList[groupIndex].list.slice();
5746
+ // @ts-ignore
5747
+ newMetaList[0].table.alias = alias;
5748
+ newMetaList = changeTableAlias(newMetaList, newMetaList[0].table);
5749
+ store.setMeta(newMetaList, groupIndex);
5750
+ }
5438
5751
  },
5439
5752
  onCancel: () => {}
5440
5753
  });
5441
5754
  };
5755
+ // 子查询弹窗
5756
+ const showSubQuery = (val = []) => {
5757
+ const {
5758
+ subToolbar,
5759
+ toolbar,
5760
+ ...other
5761
+ } = store.preProps;
5762
+ let newMetaList = store.metaList[groupIndex].list.slice()[0];
5763
+ let oldList = cloneDeep(newMetaList.subquery);
5764
+ let _toolbar = subToolbar || toolbar;
5765
+ _toolbar = _toolbar.filter(v => v !== 'group'); // 子查询不需要分组
5766
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : 0;
5767
+ let o = Modal2.openModal({
5768
+ title: __('SqlQueryBuilder.subquery'),
5769
+ transparentMask: true,
5770
+ zIndex: Number(zIndex),
5771
+ content: jsx(Fragment, {
5772
+ children: jsx(SqlVisionBuilder, {
5773
+ ...other,
5774
+ showSubquery: store._showSubquery,
5775
+ toolbar: _toolbar,
5776
+ btnText: __('SqlQueryBuilder.confirm'),
5777
+ value: val,
5778
+ onOk: newList => {
5779
+ try {
5780
+ // 子查询未改变不做操作
5781
+ if (isEqual(newList, oldList)) {
5782
+ o.close();
5783
+ return;
5784
+ }
5785
+ newMetaList.subquery = newList;
5786
+ newMetaList.table = {
5787
+ ...newList[0].table,
5788
+ alias: newMetaList.table.alias || newList[0].table.name + '_' + groupIndex + '_' + 0,
5789
+ tableUuid: uuidv4('table')
5790
+ };
5791
+ const items = getSubColumns(newList);
5792
+ const newColumns = items.flatMap(item => item.columns);
5793
+ newMetaList.columns = newColumns;
5794
+ // (newMeta[index] as MetaJoin).expressions = [];
5795
+ store.setMeta([newMetaList], groupIndex);
5796
+ o.close();
5797
+ } catch (e) {
5798
+ console.warn(e);
5799
+ } finally {
5800
+ o.close();
5801
+ }
5802
+ }
5803
+ })
5804
+ }),
5805
+ onClose: () => {}
5806
+ });
5807
+ };
5808
+ // 切换子查询
5809
+ const switchSubQuery = () => {
5810
+ let newMetaList = store.metaList[groupIndex].list.slice()[0];
5811
+ newMetaList.isSubquery = !newMetaList.isSubquery;
5812
+ //重置表数据
5813
+ newMetaList.subquery = [];
5814
+ newMetaList.table = {
5815
+ name: '',
5816
+ // 表名
5817
+ tableUuid: '',
5818
+ id: '',
5819
+ // 表名
5820
+ alias: '',
5821
+ // 表别名
5822
+ datasourceName: '',
5823
+ // 数据源名
5824
+ datasourceId: '' // 数据源id
5825
+ };
5826
+ store.setMeta([newMetaList], groupIndex);
5827
+ };
5442
5828
  return jsx(Wrapper, {
5443
5829
  className: `Sqb-item`,
5444
5830
  children: jsxs("div", {
@@ -5449,7 +5835,29 @@ const TableData = props => {
5449
5835
  className: `Sqb-item--content`,
5450
5836
  children: jsxs("div", {
5451
5837
  className: `Sqb-NotebookCell`,
5452
- children: [jsxs("div", {
5838
+ children: [meta.isSubquery ? jsxs("div", {
5839
+ className: cx(`Sqb-TableName`, {
5840
+ notSelected: !subQuerySelected
5841
+ }),
5842
+ onClick: () => {
5843
+ showSubQuery(meta.subquery);
5844
+ },
5845
+ children: [subQuerySelected && jsx(Tooltip, {
5846
+ title: __('SqlQueryBuilder.alias'),
5847
+ children: jsx(Button, {
5848
+ className: ':Sqb-TableName-as',
5849
+ shape: 'circle',
5850
+ iconOnly: true,
5851
+ primary: true,
5852
+ icon: 'As',
5853
+ size: 'small',
5854
+ onClick: e => {
5855
+ e.stopPropagation();
5856
+ onChangeTableAlias(meta.table?.alias || '');
5857
+ }
5858
+ })
5859
+ }), subQuerySelected ? `${(meta.subquery?.[0]).table.datasourceName}.${(meta.subquery?.[0]).table.name} ${meta.table?.alias ? `as ${meta.table?.alias}` : ''} ` : __('SqlQueryBuilder.setSubQuery')]
5860
+ }) : jsxs("div", {
5453
5861
  className: cx(`Sqb-TableName`, {
5454
5862
  notSelected: !selected
5455
5863
  }),
@@ -5469,7 +5877,19 @@ const TableData = props => {
5469
5877
  }
5470
5878
  })
5471
5879
  }), selected ? `${meta.table.datasourceName}.${meta.table.name} ${meta.table?.alias ? `as ${meta.table?.alias}` : ''}` : __('SqlQueryBuilder.pickTable')]
5472
- }), selected && store.showMainColumn && store.showFields && jsx("div", {
5880
+ }), store.showSubquery && jsx(Tooltip, {
5881
+ title: __('SqlQueryBuilder.switchSubQuery'),
5882
+ children: jsx(Button, {
5883
+ disabled: meta.readonly,
5884
+ primary: meta.isSubquery,
5885
+ ghost: true,
5886
+ className: cx('mr-2 operator-icon', {
5887
+ ['subquery-icon']: !meta.isSubquery
5888
+ }),
5889
+ icon: jsx(RelatedWork, {}),
5890
+ onClick: switchSubQuery
5891
+ })
5892
+ }), selected && store.showFields && jsx("div", {
5473
5893
  className: `Sqb-TableColumns`,
5474
5894
  onClick: selectColumns,
5475
5895
  children: __('SqlQueryBuilder.columns')
@@ -5491,8 +5911,8 @@ var FlagLocation;
5491
5911
  })(FlagLocation || (FlagLocation = {}));
5492
5912
  var ExpressionsEnum;
5493
5913
  (function (ExpressionsEnum) {
5494
- ExpressionsEnum["LEFT"] = "left_column";
5495
- ExpressionsEnum["RIGHT"] = "right_column";
5914
+ ExpressionsEnum["LEFT"] = "left";
5915
+ ExpressionsEnum["RIGHT"] = "right";
5496
5916
  })(ExpressionsEnum || (ExpressionsEnum = {}));
5497
5917
  const JoinData = props => {
5498
5918
  const {
@@ -5507,7 +5927,12 @@ const JoinData = props => {
5507
5927
  let table1Selected = Boolean(meta.table1.name);
5508
5928
  let table2Selected = Boolean(meta.table2.name);
5509
5929
  let subQuerySelected = Boolean(meta.subquery?.[0]?.table?.name);
5510
- let columnsSelected = meta.table1.column && meta.table2.column;
5930
+ let columnsSelected = meta.table1.quotes && meta.table2.quotes;
5931
+ // useEffect(() => {
5932
+ // let newMetaList = store.metaList[groupIndex].list.slice();
5933
+ // newMetaList[index] = setQuotes(meta);
5934
+ // store.setMeta(newMetaList, groupIndex);
5935
+ // }, []);
5511
5936
  function selectColumns(e) {
5512
5937
  let columns = meta.columns;
5513
5938
  !meta.readonly && store.setPopup({
@@ -5576,8 +6001,9 @@ const JoinData = props => {
5576
6001
  name: tableName,
5577
6002
  tableUuid: data.tableUuid || uuidv4('table'),
5578
6003
  alias,
5579
- column: '',
5580
- column_id: '',
6004
+ fieldAlias: '',
6005
+ fieldUuid: '',
6006
+ quotes: '',
5581
6007
  datasourceId: data.datasourceId,
5582
6008
  datasourceName: data.datasourceName
5583
6009
  };
@@ -5620,8 +6046,9 @@ const JoinData = props => {
5620
6046
  let type = node.getAttribute('v-data');
5621
6047
  let data = [];
5622
6048
  let value = {
5623
- name: meta[type].column,
5624
- id: meta[type].column_id,
6049
+ name: meta[type].quotes || meta[type].fieldAlias,
6050
+ quotes: meta[type].quotes,
6051
+ id: meta[type].fieldUuid,
5625
6052
  table: meta[type].name,
5626
6053
  tableId: meta[type].id,
5627
6054
  fieldUuid: meta[type].fieldUuid || uuidv4('field'),
@@ -5739,15 +6166,27 @@ const JoinData = props => {
5739
6166
  sql,
5740
6167
  datasourceId,
5741
6168
  datasourceName,
5742
- id = ''
6169
+ id = '',
6170
+ fieldAlias = '',
6171
+ fieldUuid = '',
6172
+ quotes,
6173
+ tableUuid
5743
6174
  } = record;
5744
6175
  let newMeta = store.metaList[groupIndex].list.slice();
5745
- newMeta[index][type].column = name;
5746
- newMeta[index][type].column_id = id;
6176
+ if (alias === SummarizeAlias$1) {
6177
+ newMeta[index][type].fieldAlias = fieldAlias;
6178
+ newMeta[index][type].fieldUuid = fieldUuid;
6179
+ newMeta[index][type].quotes = quotes;
6180
+ } else {
6181
+ newMeta[index][type].fieldAlias = name;
6182
+ newMeta[index][type].fieldUuid = id;
6183
+ newMeta[index][type].quotes = name;
6184
+ }
5747
6185
  if (type === FlagLocation.TABLE_1) {
5748
6186
  if (newMeta[index][type].alias !== alias) {
5749
6187
  newMeta[index][type].alias = alias;
5750
6188
  newMeta[index][type].name = table;
6189
+ newMeta[index][type].tableUuid = tableUuid;
5751
6190
  newMeta[index][type].datasourceId = datasourceId;
5752
6191
  newMeta[index][type].datasourceName = datasourceName;
5753
6192
  newMeta[index].expressions = [];
@@ -5771,8 +6210,8 @@ const JoinData = props => {
5771
6210
  let index = findIndex(store.metaList[groupIndex].list, meta);
5772
6211
  let table_type = type === ExpressionsEnum.LEFT ? FlagLocation.TABLE_1 : FlagLocation.TABLE_2;
5773
6212
  let value = {
5774
- name: meta.expressions[_ind][type],
5775
- id: meta.expressions[_ind][`${type}_id`],
6213
+ name: meta.expressions[_ind][`${type}_quotes`] || meta.expressions[_ind][`${type}_fieldAlias`],
6214
+ id: meta.expressions[_ind][`${type}_fieldUuid`],
5776
6215
  table: meta[table_type].name,
5777
6216
  fieldUuid: meta[table_type].fieldUuid || uuidv4('field'),
5778
6217
  fieldAlias: meta[table_type].fieldAlias || '',
@@ -5897,11 +6336,23 @@ const JoinData = props => {
5897
6336
  sql,
5898
6337
  datasourceId,
5899
6338
  datasourceName,
5900
- id = ''
6339
+ id = '',
6340
+ fieldAlias,
6341
+ fieldUuid,
6342
+ quotes = ''
5901
6343
  } = record;
5902
6344
  let newMeta = store.metaList[groupIndex].list.slice();
5903
- newMeta[index].expressions[_ind][type] = name;
5904
- newMeta[index].expressions[_ind][`${type}_id`] = id;
6345
+ if (alias === SummarizeAlias$1) {
6346
+ newMeta[index].expressions[_ind][`${type}_fieldAlias`] = fieldAlias;
6347
+ newMeta[index].expressions[_ind][`${type}_fieldUuid`] = fieldUuid;
6348
+ newMeta[index].expressions[_ind][`${type}_quotes`] = quotes;
6349
+ } else {
6350
+ newMeta[index].expressions[_ind][`${type}_fieldAlias`] = name;
6351
+ newMeta[index].expressions[_ind][`${type}_fieldUuid`] = id;
6352
+ newMeta[index].expressions[_ind][`${type}_quotes`] = name;
6353
+ }
6354
+ // (newMeta[index] as MetaJoin).expressions[_ind][type] = name;
6355
+ // (newMeta[index] as MetaJoin).expressions[_ind][`${type}_id`] = id;
5905
6356
  store.setMeta(newMeta, groupIndex);
5906
6357
  store.setPopup({
5907
6358
  visible: false
@@ -5983,10 +6434,11 @@ const JoinData = props => {
5983
6434
  let oldList = cloneDeep(newMeta[index].subquery);
5984
6435
  let _toolbar = subToolbar || toolbar;
5985
6436
  _toolbar = _toolbar.filter(v => v !== 'group'); // 子查询不需要分组
6437
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : 0;
5986
6438
  let o = Modal2.openModal({
5987
6439
  title: __('SqlQueryBuilder.subquery'),
5988
6440
  transparentMask: true,
5989
- zIndex: 200,
6441
+ zIndex: Number(zIndex),
5990
6442
  content: jsx(Fragment, {
5991
6443
  children: jsx(SqlVisionBuilder, {
5992
6444
  ...other,
@@ -6004,13 +6456,14 @@ const JoinData = props => {
6004
6456
  newMeta[index].subquery = newList;
6005
6457
  newMeta[index].table2 = {
6006
6458
  ...newList[0].table,
6007
- column: '',
6008
- column_id: ''
6459
+ alias: newMeta[index].table2.alias || newList[0].table.name + '_' + groupIndex + '_' + index
6009
6460
  };
6010
6461
  const items = getSubColumns(newList);
6011
6462
  const newColumns = items.flatMap(item => item.columns);
6012
6463
  newMeta[index].columns = newColumns;
6013
6464
  newMeta[index].expressions = [];
6465
+ // 关联表变了 下面模块全部删除
6466
+ newMeta = newMeta.filter((v, i) => i <= index);
6014
6467
  store.setMeta(newMeta, groupIndex);
6015
6468
  o.close();
6016
6469
  } catch (e) {
@@ -6030,8 +6483,9 @@ const JoinData = props => {
6030
6483
  let newMeta = store.metaList[groupIndex].list.slice();
6031
6484
  newMeta[index].isSubquery = !newMeta[index].isSubquery;
6032
6485
  newMeta[index].table2 = {
6033
- column: '',
6034
- column_id: '',
6486
+ quotes: '',
6487
+ fieldAlias: '',
6488
+ fieldUuid: '',
6035
6489
  name: '',
6036
6490
  // 表名
6037
6491
  tableUuid: '',
@@ -6060,12 +6514,17 @@ const JoinData = props => {
6060
6514
  alias = val;
6061
6515
  }
6062
6516
  }),
6063
- onOk: () => {
6064
- let index = findIndex(store.metaList[groupIndex].list, meta);
6065
- let newMeta = store.metaList[groupIndex].list.slice();
6066
- newMeta[index].table2.alias = alias;
6067
- newMeta = changeTableAlias(newMeta, newMeta[index].table2);
6068
- store.setMeta(newMeta, groupIndex);
6517
+ onOk: async () => {
6518
+ if (!alias) {
6519
+ Toast.warning(__('SqlQueryBuilder.aliasCannotEmpty'));
6520
+ return false;
6521
+ } else {
6522
+ let index = findIndex(store.metaList[groupIndex].list, meta);
6523
+ let newMeta = store.metaList[groupIndex].list.slice();
6524
+ newMeta[index].table2.alias = alias;
6525
+ newMeta = changeTableAlias(newMeta, newMeta[index].table2);
6526
+ store.setMeta(newMeta, groupIndex);
6527
+ }
6069
6528
  },
6070
6529
  onCancel: () => {}
6071
6530
  });
@@ -6124,7 +6583,7 @@ const JoinData = props => {
6124
6583
  onChangeTableAlias(meta.table2?.alias || '');
6125
6584
  }
6126
6585
  })
6127
- }), subQuerySelected ? `${meta.subquery?.[0].table.datasourceName}.${meta.subquery?.[0].table.name} ${meta.table2?.alias ? `as ${meta.table2?.alias}` : ''} ` : __('SqlQueryBuilder.setSubQuery')]
6586
+ }), subQuerySelected ? `${(meta.subquery?.[0]).table.datasourceName}.${(meta.subquery?.[0]).table.name} ${meta.table2?.alias ? `as ${meta.table2?.alias}` : ''} ` : __('SqlQueryBuilder.setSubQuery')]
6128
6587
  }) : jsxs("div", {
6129
6588
  className: cx(`Sqb-TableName`, {
6130
6589
  notSelected: !table2Selected
@@ -6164,23 +6623,23 @@ const JoinData = props => {
6164
6623
  children: "on"
6165
6624
  }), jsx("div", {
6166
6625
  className: cx(`Sqb-TableName`, {
6167
- notSelected: !meta.table1.column
6626
+ notSelected: !meta.table1.quotes
6168
6627
  }),
6169
6628
  "v-data": FlagLocation.TABLE_1,
6170
6629
  onClick: selectJoinColumn,
6171
- children: meta.table1.column ? meta.table1.column : __('SqlQueryBuilder.pickTable')
6630
+ children: meta.table1.quotes ? meta.table1.quotes : __('SqlQueryBuilder.pickTable')
6172
6631
  }), jsx("span", {
6173
6632
  className: 'mr-2 text-gray-500',
6174
6633
  children: "="
6175
6634
  }), jsx("div", {
6176
6635
  className: cx(`Sqb-TableName`, {
6177
- notSelected: !meta.table2.column
6636
+ notSelected: !meta.table2.quotes
6178
6637
  }),
6179
6638
  "v-data": FlagLocation.TABLE_2,
6180
6639
  onClick: selectJoinColumn,
6181
- children: meta.table2.column ? meta.table2.column : __('SqlQueryBuilder.pickTable')
6640
+ children: meta.table2.quotes ? meta.table2.quotes : __('SqlQueryBuilder.pickTable')
6182
6641
  })]
6183
- }), meta.table1.column_id && meta.table2.column_id && meta.expressions?.map((v, i) => {
6642
+ }), meta.table1.fieldUuid && meta.table2.fieldUuid && meta.expressions?.map((v, i) => {
6184
6643
  return jsxs("div", {
6185
6644
  className: cx(`Sqb-where block`),
6186
6645
  children: [jsx("span", {
@@ -6209,12 +6668,12 @@ const JoinData = props => {
6209
6668
  children: v.left_constant ? v.left_constant : __('SqlQueryBuilder.pickConstant')
6210
6669
  }), (!v.left_type || v.left_type === 'field') && jsx("div", {
6211
6670
  className: cx(`Sqb-TableName`, {
6212
- notSelected: !v.left_column
6671
+ notSelected: !v.left_quotes
6213
6672
  }),
6214
6673
  "v-data": ExpressionsEnum.LEFT,
6215
6674
  "v-index": i,
6216
6675
  onClick: selectMoreJoinColumn,
6217
- children: v.left_column ? v.left_column : __('SqlQueryBuilder.pickTable')
6676
+ children: v.left_quotes ? v.left_quotes : __('SqlQueryBuilder.pickTable')
6218
6677
  }), jsx(Tooltip, {
6219
6678
  title: __('SqlQueryBuilder.switch'),
6220
6679
  children: jsx(Button, {
@@ -6253,12 +6712,12 @@ const JoinData = props => {
6253
6712
  children: v.right_constant ? v.right_constant : __('SqlQueryBuilder.pickConstant')
6254
6713
  }), (!v.right_type || v.right_type === 'field') && jsx("div", {
6255
6714
  className: cx(`Sqb-TableName`, {
6256
- notSelected: !v.right_column
6715
+ notSelected: !v.right_quotes
6257
6716
  }),
6258
6717
  "v-data": ExpressionsEnum.RIGHT,
6259
6718
  "v-index": i,
6260
6719
  onClick: selectMoreJoinColumn,
6261
- children: v.right_column ? v.right_column : __('SqlQueryBuilder.pickTable')
6720
+ children: v.right_quotes ? v.right_quotes : __('SqlQueryBuilder.pickTable')
6262
6721
  }), jsx(Tooltip, {
6263
6722
  title: __('SqlQueryBuilder.switch'),
6264
6723
  children: jsx(Button, {
@@ -6284,16 +6743,17 @@ const JoinData = props => {
6284
6743
  let newMeta = store.metaList[groupIndex].list.slice();
6285
6744
  newMeta[index].expressions.splice(i + 1, 0, {
6286
6745
  operator: 'and',
6287
- left_column: '',
6288
- left_column_id: '',
6746
+ left_fieldAlias: '',
6747
+ left_fieldUuid: '',
6748
+ left_quotes: '',
6289
6749
  left_string: '',
6290
- left_isString: false,
6291
6750
  left_type: 'field',
6292
6751
  left_constant: '',
6293
- right_column: '',
6294
- right_column_id: '',
6752
+ right_fieldAlias: '',
6753
+ right_fieldUuid: '',
6754
+ right_quotes: '',
6295
6755
  right_string: '',
6296
- right_isString: false,
6756
+ // right_isString: false,
6297
6757
  right_type: 'field',
6298
6758
  right_constant: ''
6299
6759
  });
@@ -6316,7 +6776,7 @@ const JoinData = props => {
6316
6776
  })
6317
6777
  })]
6318
6778
  }, i);
6319
- }), meta.table1.column_id && meta.table2.column_id && (meta.expressions?.length || 0) < 1 && jsx(Tooltip, {
6779
+ }), meta.table1.fieldUuid && meta.table2.fieldUuid && (meta.expressions?.length || 0) < 1 && jsx(Tooltip, {
6320
6780
  title: __('SqlQueryBuilder.add'),
6321
6781
  children: jsx(Button, {
6322
6782
  disabled: meta.readonly,
@@ -6329,16 +6789,17 @@ const JoinData = props => {
6329
6789
  let newMeta = store.metaList[groupIndex].list.slice();
6330
6790
  newMeta[index].expressions = [{
6331
6791
  operator: 'and',
6332
- left_column: '',
6333
- left_column_id: '',
6792
+ left_fieldAlias: '',
6793
+ left_fieldUuid: '',
6794
+ left_quotes: '',
6334
6795
  left_string: '',
6335
- left_isString: false,
6336
6796
  left_type: 'field',
6337
6797
  left_constant: '',
6338
- right_column: '',
6339
- right_column_id: '',
6798
+ right_fieldAlias: '',
6799
+ right_fieldUuid: '',
6800
+ right_quotes: '',
6340
6801
  right_string: '',
6341
- right_isString: false,
6802
+ // right_isString: false,
6342
6803
  right_constant: '',
6343
6804
  right_type: 'field'
6344
6805
  }];
@@ -6487,12 +6948,12 @@ const CaseEditor = props => {
6487
6948
  onOk,
6488
6949
  onCancel
6489
6950
  } = props;
6490
- const [popup, setPopup] = useState({
6491
- visible: false
6492
- }); // 弹框信息
6951
+ // const [popup, setPopup] = useState<PopupType>({ visible: false }); // 弹框信息
6493
6952
  const [caseList, setCaseList] = useState(value.formulaList || []);
6494
6953
  const [name, setName] = useState(value?.name || ''); // 表达式名字
6495
6954
  const [ind, setInd] = useState(-1);
6955
+ const ref = useRef(null);
6956
+ const store = useStore$1();
6496
6957
  const filterCase = useMemo(() => {
6497
6958
  const hasCase = caseList.some(item => item.type === OptionsTypeEnum.OTHER && item.operator === 'case');
6498
6959
  if (hasCase) {
@@ -6504,24 +6965,22 @@ const CaseEditor = props => {
6504
6965
  const usable = useMemo(() => {
6505
6966
  return Array.from(caseList).length > 0 && name;
6506
6967
  }, [caseList, name]);
6507
- const popupContent = useMemo(() => {
6508
- let {
6509
- visible,
6510
- content
6511
- } = popup;
6512
- if (!visible) return null;
6513
- return content;
6514
- }, [popup]);
6968
+ // const popupContent = useMemo(() => {
6969
+ // let { visible, content } = popup;
6970
+ // if (!visible) return null;
6971
+ // return content;
6972
+ // }, [popup]);
6515
6973
  function closePopup() {
6516
- setPopup({
6974
+ store.setPopup({
6517
6975
  visible: false
6518
6976
  });
6519
6977
  }
6520
6978
  // 字段
6521
6979
  function handleField(e, i, val) {
6522
- setPopup({
6980
+ store.setPopup({
6523
6981
  visible: true,
6524
6982
  node: e.currentTarget,
6983
+ container: ref.current,
6525
6984
  content: jsx(SelectJoinColumn, {
6526
6985
  data: data,
6527
6986
  value: val,
@@ -6529,8 +6988,13 @@ const CaseEditor = props => {
6529
6988
  isGroup: true,
6530
6989
  // @ts-ignore
6531
6990
  onGroup: data => {
6991
+ let _data = cloneDeep(data);
6992
+ if (_data.alias != SummarizeAlias$1) {
6993
+ _data.fieldAlias = _data.name;
6994
+ _data.fieldUuid = uuidv4('field');
6995
+ }
6532
6996
  const _caseList = caseList.slice();
6533
- _caseList[i].expression = data;
6997
+ _caseList[i].expression = _data;
6534
6998
  setCaseList(_caseList);
6535
6999
  closePopup();
6536
7000
  }
@@ -6546,16 +7010,23 @@ const CaseEditor = props => {
6546
7010
  };
6547
7011
  // 表达式
6548
7012
  function handleExpression(e, i, val) {
6549
- setPopup({
7013
+ store.setPopup({
6550
7014
  visible: true,
6551
7015
  node: e.currentTarget,
7016
+ container: ref.current,
6552
7017
  content: jsx(SelectFilter, {
6553
7018
  isCustom: true,
7019
+ container: ref.current,
6554
7020
  data: data,
6555
7021
  value: val,
6556
7022
  onChange: data => {
7023
+ let _data = cloneDeep(data);
7024
+ if (_data.alias != SummarizeAlias$1) {
7025
+ _data.fieldAlias = _data.name;
7026
+ _data.fieldUuid = uuidv4('field');
7027
+ }
6557
7028
  const _caseList = caseList.slice();
6558
- _caseList[i].expression = data;
7029
+ _caseList[i].expression = _data;
6559
7030
  setCaseList(_caseList);
6560
7031
  closePopup();
6561
7032
  }
@@ -6598,8 +7069,7 @@ const CaseEditor = props => {
6598
7069
  const _onOk = () => {
6599
7070
  typeof onOk === 'function' && onOk?.({
6600
7071
  name,
6601
- formulaList: caseList,
6602
- formula: ''
7072
+ formulaList: caseList
6603
7073
  });
6604
7074
  };
6605
7075
  // 分段
@@ -6747,6 +7217,7 @@ const CaseEditor = props => {
6747
7217
  };
6748
7218
  return jsxs("div", {
6749
7219
  className: 'custom-box',
7220
+ ref: ref,
6750
7221
  children: [jsx(VisualBox$1, {
6751
7222
  children: jsx("div", {
6752
7223
  className: `Sqb-item Sqb-case-editor mb-2 mt-2`,
@@ -6884,13 +7355,6 @@ const CaseEditor = props => {
6884
7355
  })]
6885
7356
  })
6886
7357
  })
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
7358
  }), jsx("div", {
6895
7359
  className: `btns p-4`,
6896
7360
  children: jsxs("div", {
@@ -7022,14 +7486,15 @@ const CustomColumn = props => {
7022
7486
  }
7023
7487
  return data;
7024
7488
  }
7025
- // 子查询弹窗
7489
+ // 自定义弹窗
7026
7490
  const showSubQuery = (e, i) => {
7027
7491
  let newMeta = store.metaList[groupIndex].list.slice();
7028
7492
  const _value = newMeta[index].customColumn[i] || [];
7493
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : 0;
7029
7494
  let o = Modal2.openModal({
7030
7495
  title: __('SqlQueryBuilder.customExpression'),
7031
7496
  transparentMask: true,
7032
- zIndex: 200,
7497
+ zIndex: Number(zIndex),
7033
7498
  content: jsx(Fragment, {
7034
7499
  children: jsx(Provider, {
7035
7500
  value: store,
@@ -7183,6 +7648,9 @@ const Filter = props => {
7183
7648
  let {
7184
7649
  filter
7185
7650
  } = meta;
7651
+ const {
7652
+ notExistsColumns
7653
+ } = store.preProps;
7186
7654
  React__default.useRef(null);
7187
7655
  let index = findIndex(store.metaList[groupIndex].list, meta);
7188
7656
  let notSelected = !meta.filter.length;
@@ -7289,10 +7757,10 @@ const Filter = props => {
7289
7757
  let newMeta = store.metaList[groupIndex].list.slice();
7290
7758
  let val = filter[i];
7291
7759
  if (val.type === Filter_TypeEnum.NOT_EXISTS) {
7292
- showSubQuery(i, '');
7760
+ showNotExists(i, '');
7293
7761
  return;
7294
7762
  }
7295
- let data = getColumns();
7763
+ let data = [...getColumns(), ...cloneDeep(notExistsColumns || [])];
7296
7764
  store.setPopup({
7297
7765
  visible: true,
7298
7766
  node: e.currentTarget,
@@ -7310,8 +7778,8 @@ const Filter = props => {
7310
7778
  function handleAdd(e) {
7311
7779
  let node = e.currentTarget;
7312
7780
  let newMeta = store.metaList[groupIndex].list.slice();
7313
- let data = getColumns();
7314
- let _index = node.getAttribute('v-index');
7781
+ let data = [...getColumns(), ...cloneDeep(notExistsColumns || [])];
7782
+ let _index = Number(node.getAttribute('v-index'));
7315
7783
  let _type = node.getAttribute('v-type');
7316
7784
  let value = {
7317
7785
  table: '',
@@ -7347,15 +7815,16 @@ const Filter = props => {
7347
7815
  content: jsx(SelectFilter, {
7348
7816
  data: data,
7349
7817
  value: value,
7350
- onChange: data => {
7818
+ onChange: val => {
7351
7819
  if (_type) {
7352
7820
  if (_type === 'before') {
7353
- newMeta[index].filter.splice(_index, 0, data);
7821
+ newMeta[index].filter.splice(_index, 0, val);
7354
7822
  } else {
7355
- newMeta[index].filter.splice(_index + 1, 0, data);
7823
+ console.log('🚀 ~ ', newMeta[index].filter);
7824
+ newMeta[index].filter.splice(_index + 1, 0, val);
7356
7825
  }
7357
7826
  } else {
7358
- newMeta[index].filter.push(data);
7827
+ newMeta[index].filter.push(val);
7359
7828
  }
7360
7829
  store.setMeta(newMeta, groupIndex);
7361
7830
  closePopup();
@@ -7388,26 +7857,29 @@ const Filter = props => {
7388
7857
  newMeta[index].filter = [..._filter];
7389
7858
  setInd(-1);
7390
7859
  };
7391
- // 子查询弹窗
7392
- const showSubQuery = (i, position) => {
7860
+ // NotExists 窗口
7861
+ const showNotExists = (i, position) => {
7393
7862
  const {
7394
- subToolbar,
7863
+ notExistsToolbar,
7395
7864
  toolbar,
7396
7865
  ...other
7397
7866
  } = store.preProps;
7398
7867
  let newMeta = store.metaList[groupIndex].list.slice();
7399
7868
  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;
7869
+ let _value = position ? [] : newMeta[index].filter[i]?.notExists || [];
7870
+ let oldList = position ? [] : cloneDeep(newMeta[index].filter[i]?.notExists || []);
7871
+ let _toolbar = notExistsToolbar || toolbar;
7403
7872
  _toolbar = _toolbar.filter(v => v !== 'group'); // 子查询不需要分组
7873
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : null;
7874
+ let notExistsColumns = getColumns();
7404
7875
  let o = Modal2.openModal({
7405
7876
  title: 'NOT EXISTS',
7406
7877
  transparentMask: true,
7407
- zIndex: 200,
7878
+ zIndex: Number(zIndex),
7408
7879
  content: jsx(Fragment, {
7409
7880
  children: jsx(SqlVisionBuilder, {
7410
7881
  ...other,
7882
+ notExistsColumns: notExistsColumns,
7411
7883
  showFields: false,
7412
7884
  showSubquery: false,
7413
7885
  toolbar: _toolbar,
@@ -7421,8 +7893,8 @@ const Filter = props => {
7421
7893
  return;
7422
7894
  }
7423
7895
  const _tem = {
7424
- subquery: newList,
7425
- quotes: `${newList?.[0].table.datasourceName}.${newList?.[0].table.alias || newList?.[0].table.name}`,
7896
+ notExists: newList,
7897
+ quotes: buildSqlQuery(newList),
7426
7898
  condition: '',
7427
7899
  table: '',
7428
7900
  tableId: '',
@@ -7497,7 +7969,7 @@ const Filter = props => {
7497
7969
  if (type === Filter_TypeEnum.EXPRESSION) {
7498
7970
  handleAdd(_e);
7499
7971
  } else if (type === Filter_TypeEnum.NOT_EXISTS) {
7500
- showSubQuery(_index, _type);
7972
+ showNotExists(_index, _type);
7501
7973
  }
7502
7974
  }
7503
7975
  })
@@ -7564,7 +8036,7 @@ const Filter = props => {
7564
8036
  }, i) : jsxs("div", {
7565
8037
  className: `Sqb-TableName purple-name`,
7566
8038
  onClick: e => handleUpdate(e, i),
7567
- children: [v.quotes, jsx("span", {
8039
+ children: [v.type === Filter_TypeEnum.NOT_EXISTS ? 'not exitis ( * )' : v.quotes, jsx("span", {
7568
8040
  style: {
7569
8041
  fontSize: 0
7570
8042
  },
@@ -7608,7 +8080,7 @@ const Filter = props => {
7608
8080
  if (typeof v === 'string') {
7609
8081
  return v;
7610
8082
  } else if (v.type === Filter_TypeEnum.NOT_EXISTS) {
7611
- return 'not exitis ( * )';
8083
+ return `${buildSqlQuery(v.notExists)}`;
7612
8084
  } else {
7613
8085
  return v.quotes;
7614
8086
  }
@@ -7740,10 +8212,10 @@ const GroupBy = props => {
7740
8212
  newMeta[index].by.splice(i, 1, data);
7741
8213
  // @ts-ignore
7742
8214
  newMeta[index].by = newMeta[index].by.map(v => {
7743
- const fieldAlias = v.fieldAlias || `${v.alias}__${v.name}`;
8215
+ const fieldAlias = `${v.alias}__${v.name}`;
7744
8216
  return {
7745
8217
  ...v,
7746
- sql: `${v.alias}.${v.realName || v.name} AS ${fieldAlias}`,
8218
+ sql: `${v.alias}.${v.realName || v.name}`,
7747
8219
  fieldAlias: fieldAlias
7748
8220
  };
7749
8221
  });
@@ -7774,8 +8246,8 @@ const GroupBy = props => {
7774
8246
  quotes: '',
7775
8247
  datasourceId: '',
7776
8248
  datasourceName: '',
7777
- column: '',
7778
- column_id: '',
8249
+ // column: '',
8250
+ // column_id: '',
7779
8251
  summarizeType: MetaSummarize_Enum.BY
7780
8252
  };
7781
8253
  store.setPopup({
@@ -7792,10 +8264,10 @@ const GroupBy = props => {
7792
8264
  newMeta[index].by.push(data);
7793
8265
  // @ts-ignore
7794
8266
  newMeta[index].by = newMeta[index].by.map(v => {
7795
- const fieldAlias = v.fieldAlias || `${v.alias}__${v.name}`;
8267
+ const fieldAlias = `${v.alias}__${v.name}`;
7796
8268
  return {
7797
8269
  ...v,
7798
- sql: `${v.alias}.${v.realName || v.name} AS ${fieldAlias}`,
8270
+ sql: `${v.alias}.${v.realName || v.name}`,
7799
8271
  fieldAlias: fieldAlias,
7800
8272
  fieldUuid: uuidv4('field'),
7801
8273
  summarizeType: MetaSummarize_Enum.BY
@@ -7993,6 +8465,7 @@ const SelectIndex = props => {
7993
8465
  content: jsx(SelectSummarize, {
7994
8466
  data: data,
7995
8467
  value: value,
8468
+ ignoreGroupByType: store.ignoreGroupByType,
7996
8469
  onChange: data => {
7997
8470
  //@ts-ignore
7998
8471
  newMeta[index].group.splice(i, 1, data);
@@ -8036,8 +8509,8 @@ const SelectIndex = props => {
8036
8509
  quotes: '',
8037
8510
  datasourceId: '',
8038
8511
  datasourceName: '',
8039
- column: '',
8040
- column_id: '',
8512
+ // column: '',
8513
+ // column_id: '',
8041
8514
  summarizeType: MetaSummarize_Enum.GROUP
8042
8515
  };
8043
8516
  store.setPopup({
@@ -8046,6 +8519,7 @@ const SelectIndex = props => {
8046
8519
  content: jsx(SelectSummarize, {
8047
8520
  data: data,
8048
8521
  value: value,
8522
+ ignoreGroupByType: store.ignoreGroupByType,
8049
8523
  onChange: data => {
8050
8524
  // @ts-ignore
8051
8525
  newMeta[index].group.push(data);
@@ -8279,8 +8753,8 @@ const Sort = props => {
8279
8753
  let value = {
8280
8754
  table: '',
8281
8755
  tableId: '',
8282
- tableUuid: uuidv4('table'),
8283
- fieldUuid: uuidv4('field'),
8756
+ tableUuid: '',
8757
+ fieldUuid: '',
8284
8758
  fieldAlias: '',
8285
8759
  alias: '',
8286
8760
  name: '',
@@ -8607,7 +9081,8 @@ const Metabase = props => {
8607
9081
  } = props;
8608
9082
  const store = useStore$1();
8609
9083
  const [saveLoading, setSaveLoading] = useState(false);
8610
- const popupContainer = useRef();
9084
+ // const popupContainer = useRef();
9085
+ // store.setPopupContainer(popupContainer);
8611
9086
  const popupContent = useMemo(() => {
8612
9087
  let {
8613
9088
  visible,
@@ -8638,11 +9113,11 @@ const Metabase = props => {
8638
9113
  await onOk?.(_metaList);
8639
9114
  setSaveLoading(false);
8640
9115
  };
8641
- let zIndex = popupContainer.current ? getMaxZIndexInParents(popupContainer.current) : null;
9116
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : null;
8642
9117
  return (
8643
9118
  // @ts-ignore
8644
9119
  jsx(VisualBox, {
8645
- ref: popupContainer,
9120
+ ref: store.popupContainer,
8646
9121
  children: jsxs("div", {
8647
9122
  className: 'Sqb',
8648
9123
  children: [store.metaList.map((v, index) => {
@@ -8679,8 +9154,8 @@ const Metabase = props => {
8679
9154
  disabled: saveLoading,
8680
9155
  onClick: onSave,
8681
9156
  children: btnText || __('SqlQueryBuilder.visualize')
8682
- }) : null, popupContainer.current && jsx(Popup, {
8683
- container: popupContainer.current,
9157
+ }) : null, store.popupContainer.current && jsx(Popup, {
9158
+ container: store.popupData.container || store.popupContainer.current,
8684
9159
  visible: store.popupData.visible,
8685
9160
  node: store.popupData.node,
8686
9161
  closable: store.popupClosable,
@@ -8691,8 +9166,8 @@ const Metabase = props => {
8691
9166
  });
8692
9167
  },
8693
9168
  children: popupContent
8694
- }), popupContainer.current && jsx(Popup, {
8695
- container: popupContainer.current,
9169
+ }), store.popupContainer.current && jsx(Popup, {
9170
+ container: store.popupData2.container || store.popupContainer.current,
8696
9171
  visible: store.popupData2.visible,
8697
9172
  node: store.popupData2.node,
8698
9173
  closable: store.popupClosable2,
@@ -8730,7 +9205,8 @@ const SqlVisionBuilder = /*#__PURE__*/React__default.forwardRef((props, ref) =>
8730
9205
  showSubquery = true,
8731
9206
  // 是否展示子查询
8732
9207
  subShowSubquery = false,
8733
- constantList
9208
+ constantList,
9209
+ ignoreGroupByType = false
8734
9210
  } = props;
8735
9211
  const store = useStore();
8736
9212
  useEffect(() => {
@@ -8755,7 +9231,8 @@ const SqlVisionBuilder = /*#__PURE__*/React__default.forwardRef((props, ref) =>
8755
9231
  store.setShowSubquery(showSubquery);
8756
9232
  store._setShowSubquery(subShowSubquery);
8757
9233
  store.setConstantList(constantList || []);
8758
- }, [showFields, fieldNameTpl, tableNameTpl, toolbar, showSubquery, subShowSubquery, constantList]);
9234
+ store.setIgnoreGroupByType(ignoreGroupByType);
9235
+ }, [showFields, fieldNameTpl, tableNameTpl, toolbar, showSubquery, subShowSubquery, constantList, ignoreGroupByType]);
8759
9236
  React__default.useImperativeHandle(ref, () => ({
8760
9237
  // setDatasource: (list) => {
8761
9238
  // store.setSourceList(list);