@cloudbase/weda-ui-mp 3.8.2 → 3.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { getWhereList, getParseValue } from './platform';
2
+ import { getDataSourceByName } from './tcb';
2
3
  import { isNil } from './lodash';
3
4
 
4
5
  /**
@@ -13,23 +14,96 @@ export const convertWhere = (props) => {
13
14
  return Array.isArray(where) ? where : [];
14
15
  };
15
16
 
17
+ /**
18
+ * 拼接filter参数
19
+ */
20
+ const getFilter = (wList) => {
21
+ let where = [];
22
+ let filter = { where: {} };
23
+ if (wList?.where?.$or) {
24
+ const wListWhere = wList?.where?.$or || [];
25
+ if (wList?.constructor === Object) {
26
+ where = [...wListWhere];
27
+ filter = {
28
+ ...wList,
29
+ where: {
30
+ $or: where,
31
+ },
32
+ };
33
+ }
34
+ } else {
35
+ const wListWhere = wList?.where?.$and || [];
36
+ if (wList?.constructor === Object) {
37
+ where = [...wListWhere];
38
+ filter = {
39
+ ...wList,
40
+ where: {
41
+ $and: where,
42
+ },
43
+ };
44
+ }
45
+ }
46
+
47
+ if (Array.isArray(wList)) {
48
+ where = [...wList];
49
+ filter = {
50
+ where: {
51
+ $and: where,
52
+ },
53
+ };
54
+ }
55
+ return getParseValue(filter);
56
+ };
57
+ const getSelectFields = async (props) => {
58
+ let select = {};
59
+ // 支持自定义查询字段
60
+ if (props.selectFieldType === 'all' && props.datasource?.name) {
61
+ // V2 查询方法中,要显式传入所有应该展示的字段
62
+
63
+ const datasource = await getDataSourceByName(props.datasource.name);
64
+ const authFields = Object.keys(datasource?.schema?.properties || {});
65
+ authFields.forEach((name) => {
66
+ select[name] = true;
67
+ });
68
+ } else if (props.selectFieldType === 'custom') {
69
+ const _selectFields = Array.isArray(props.selectFields)
70
+ ? props.selectFields
71
+ : [];
72
+ _selectFields.forEach((name) => {
73
+ select[name] = true;
74
+ });
75
+ } else {
76
+ select = { $master: true };
77
+ }
78
+ return select;
79
+ };
16
80
  /**
17
81
  * 获取tcb查询条件
18
82
  */
19
- export const getModelParams = (props) => {
83
+ export const getModelParams = async (props) => {
20
84
  const params = {};
21
85
  try {
22
- const where = convertWhere(props);
23
86
  const { orderBy, orderType } = props || {};
24
87
 
25
88
  if (orderBy && ['asc', 'desc'].includes(orderType)) {
26
89
  params['orderBy'] = orderBy;
27
90
  params['orderType'] = orderType;
28
91
  }
29
- if (Array.isArray(where) && where.length > 0) {
30
- params['where'] = where;
92
+ if (props.supportManyRelated) {
93
+ // 支持多关联查询,需要将查询条件转换为filter
94
+ if (props?.queryCondition?.constructor === Object) {
95
+ params['filter'] = getFilter(props.queryCondition);
96
+ }
97
+ params.select = await getSelectFields(props);
98
+ } else {
99
+ const where = convertWhere(props);
100
+ if (Array.isArray(where) && where.length > 0) {
101
+ params['where'] = where;
102
+ }
31
103
  }
32
- } catch (e) {}
104
+ } catch (e) {
105
+ console.error('getModelParams error', e);
106
+ }
33
107
  return params;
34
108
  };
35
109