midway-fatcms 0.0.1-beta.47 → 0.0.1-beta.49

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.
@@ -20,11 +20,19 @@ const SystemTables_1 = require("../../models/SystemTables");
20
20
  const exceptions_1 = require("../../libs/crud-pro/exceptions");
21
21
  const DatabaseName_1 = require("../../libs/crud-pro/utils/DatabaseName");
22
22
  const common_dto_1 = require("../../libs/utils/common-dto");
23
+ function getObjectKeysWithValue(obj) {
24
+ const keys = Object.keys(obj || {});
25
+ return keys.filter((key) => {
26
+ const valueObj = obj[key];
27
+ const valueKeys = Object.keys(valueObj || {});
28
+ return valueKeys.length > 0;
29
+ });
30
+ }
23
31
  let CrudStandardDesignApi = class CrudStandardDesignApi extends BaseApiController_1.BaseApiController {
24
32
  async getDataBaseList() {
25
- const mysqlList = Object.keys(this.mysql2Config || {});
26
- const postgresList = Object.keys(this.postgres2Config || {});
27
- const sqlServerList = Object.keys(this.sqlserver2Config || {});
33
+ const mysqlList = getObjectKeysWithValue(this.mysql2Config);
34
+ const postgresList = getObjectKeysWithValue(this.postgres2Config);
35
+ const sqlServerList = getObjectKeysWithValue(this.sqlserver2Config);
28
36
  const toSelectList = (dbCfgNameList, dbType) => {
29
37
  return dbCfgNameList.map(dbName => {
30
38
  const value = (0, DatabaseName_1.toDatabaseNameStr)(dbType, dbName);
@@ -48,7 +48,7 @@ let UserAccountManageApi = class UserAccountManageApi extends BaseApiController_
48
48
  'data.nick_name': [keys_1.KeysOfValidators.STRING, 'length:3,20', checkAccountCreateBlacklist],
49
49
  },
50
50
  allowCfg: {
51
- data: ['login_name', 'nick_name', 'avatar', 'status'],
51
+ data: ['login_name', 'nick_name', 'avatar', 'status', 'modified_at', 'created_at'],
52
52
  },
53
53
  });
54
54
  }
@@ -79,10 +79,12 @@ class ExportExcelByStdCrudHandler {
79
79
  return selectedRowKeys.length;
80
80
  }
81
81
  const lastQueryParams = (_b = this.inputParams) === null || _b === void 0 ? void 0 : _b.lastQueryParams;
82
+ const filterValue = _.get(lastQueryParams, 'filterValue');
82
83
  const crudStdService = await this.getCrudStdService();
83
84
  const appCode = this.appCode;
84
85
  const params = {
85
86
  condition: (lastQueryParams === null || lastQueryParams === void 0 ? void 0 : lastQueryParams.condition) || {},
87
+ filterValue,
86
88
  pageSize: 1,
87
89
  pageNo: 1,
88
90
  };
@@ -107,10 +109,12 @@ class ExportExcelByStdCrudHandler {
107
109
  const selectedRowKeys = this.inputParams.selectedRowKeys || [];
108
110
  const primaryKey = this.inputParams.primaryKey || 'id';
109
111
  const lastQueryParams = this.inputParams.lastQueryParams;
112
+ const filterValue = _.get(lastQueryParams, 'filterValue');
110
113
  const crudStdService = await this.getCrudStdService();
111
114
  const appCode = this.appCode;
112
115
  const params = {
113
116
  condition: (lastQueryParams === null || lastQueryParams === void 0 ? void 0 : lastQueryParams.condition) || {},
117
+ filterValue: filterValue,
114
118
  pageSize: pageSize,
115
119
  pageNo: pageNo,
116
120
  orderBy: lastQueryParams === null || lastQueryParams === void 0 ? void 0 : lastQueryParams.orderBy,
@@ -10,62 +10,89 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CrudStdRelationService = void 0;
13
+ /* eslint-disable prettier/prettier */
13
14
  const core_1 = require("@midwayjs/core");
14
15
  const _ = require("lodash");
15
16
  const CurdMixService_1 = require("../curd/CurdMixService");
16
17
  const BaseService_1 = require("../base/BaseService");
17
18
  const CrudStdConstant_1 = require("./CrudStdConstant");
18
19
  const CurdMixUtils_1 = require("../curd/CurdMixUtils");
20
+ class ColumnsRelationMaker {
21
+ constructor(cfgModel, appInfo) {
22
+ cfgModel.columnsRelation = [];
23
+ this.cfgModel = cfgModel;
24
+ this.appInfo = appInfo;
25
+ }
26
+ addColumnRelationByAccount(dataIndex) {
27
+ const columnsRelation = this.cfgModel.columnsRelation;
28
+ columnsRelation.push({
29
+ relatedType: CurdMixUtils_1.RelatedType.accountBasic,
30
+ sourceColumn: dataIndex,
31
+ targetColumns: [], // 使用默认
32
+ });
33
+ }
34
+ addColumnRelationByDictEnumStatus(dataIndex) {
35
+ var _a;
36
+ const appInfo = this.appInfo;
37
+ const tableFields = ((_a = appInfo === null || appInfo === void 0 ? void 0 : appInfo.stdCrudCfgObj) === null || _a === void 0 ? void 0 : _a.tableFields) || [];
38
+ const columnsRelation = this.cfgModel.columnsRelation;
39
+ const fieldCfg = tableFields.find(f => {
40
+ return f.fieldIndex === dataIndex;
41
+ });
42
+ if (fieldCfg && fieldCfg.linkToType === CrudStdConstant_1.fieldLinkToTypes.linkToCustom) {
43
+ columnsRelation.push({
44
+ relatedType: CurdMixUtils_1.RelatedType.linkToCustom,
45
+ relatedCode: fieldCfg.linkToCustom,
46
+ sourceColumn: dataIndex,
47
+ targetColumns: [], // 使用默认
48
+ });
49
+ }
50
+ if (fieldCfg && fieldCfg.linkToType === CrudStdConstant_1.fieldLinkToTypes.linkToSysCfgEnum) {
51
+ columnsRelation.push({
52
+ relatedType: CurdMixUtils_1.RelatedType.sysCfgEnum,
53
+ relatedCode: fieldCfg.linkToSysCfgEnumCode,
54
+ sourceColumn: dataIndex,
55
+ targetColumns: [], // 使用默认
56
+ });
57
+ }
58
+ if (fieldCfg && fieldCfg.linkToType === CrudStdConstant_1.fieldLinkToTypes.linkToDict) {
59
+ columnsRelation.push({
60
+ relatedType: CurdMixUtils_1.RelatedType.dict,
61
+ relatedCode: fieldCfg.linkToDictCode,
62
+ sourceColumn: dataIndex,
63
+ targetColumns: [], // 使用默认
64
+ });
65
+ }
66
+ }
67
+ }
19
68
  let CrudStdRelationService = class CrudStdRelationService extends BaseService_1.BaseService {
20
69
  async addCfgModelColumnsRelation(cfgModel, appInfo) {
21
- var _a, _b;
70
+ var _a;
22
71
  const tableColumns = (_a = appInfo === null || appInfo === void 0 ? void 0 : appInfo.stdCrudCfgObj) === null || _a === void 0 ? void 0 : _a.tableColumns;
23
- const tableFields = ((_b = appInfo === null || appInfo === void 0 ? void 0 : appInfo.stdCrudCfgObj) === null || _b === void 0 ? void 0 : _b.tableFields) || [];
24
- if (!Array.isArray(tableColumns)) {
72
+ if (!Array.isArray(tableColumns) || tableColumns.length === 0) {
25
73
  return;
26
74
  }
27
- const columnsRelation = [];
28
- cfgModel.columnsRelation = columnsRelation;
75
+ const maker = new ColumnsRelationMaker(cfgModel, appInfo);
29
76
  for (let i = 0; i < tableColumns.length; i++) {
30
77
  const tableColumn = tableColumns[i];
31
78
  const dataIndex = _.get(tableColumn, 'dataIndex');
32
79
  const componentName = _.get(tableColumn, 'component.componentName');
33
80
  // 关联用户信息
34
81
  if (componentName === CrudStdConstant_1.tableColumnRenders.RenderUserInfo) {
35
- columnsRelation.push({
36
- relatedType: CurdMixUtils_1.RelatedType.accountBasic,
37
- sourceColumn: dataIndex,
38
- targetColumns: [], // 使用默认
39
- });
82
+ maker.addColumnRelationByAccount(dataIndex);
40
83
  }
41
84
  // 关联枚举文案/状态标签颜色
42
85
  if (componentName === CrudStdConstant_1.tableColumnRenders.RenderDictEnumText || componentName === CrudStdConstant_1.tableColumnRenders.RenderDictEnumStatus) {
43
- const fieldCfg = tableFields.find(f => {
44
- return f.fieldIndex === dataIndex;
45
- });
46
- if (fieldCfg && fieldCfg.linkToType === CrudStdConstant_1.fieldLinkToTypes.linkToCustom) {
47
- columnsRelation.push({
48
- relatedType: CurdMixUtils_1.RelatedType.linkToCustom,
49
- relatedCode: fieldCfg.linkToCustom,
50
- sourceColumn: dataIndex,
51
- targetColumns: [], // 使用默认
52
- });
53
- }
54
- if (fieldCfg && fieldCfg.linkToType === CrudStdConstant_1.fieldLinkToTypes.linkToSysCfgEnum) {
55
- columnsRelation.push({
56
- relatedType: CurdMixUtils_1.RelatedType.sysCfgEnum,
57
- relatedCode: fieldCfg.linkToSysCfgEnumCode,
58
- sourceColumn: dataIndex,
59
- targetColumns: [], // 使用默认
60
- });
61
- }
62
- if (fieldCfg && fieldCfg.linkToType === CrudStdConstant_1.fieldLinkToTypes.linkToDict) {
63
- columnsRelation.push({
64
- relatedType: CurdMixUtils_1.RelatedType.dict,
65
- relatedCode: fieldCfg.linkToDictCode,
66
- sourceColumn: dataIndex,
67
- targetColumns: [], // 使用默认
68
- });
86
+ maker.addColumnRelationByDictEnumStatus(dataIndex);
87
+ }
88
+ // 子属性的配置
89
+ const balloonTipFields = _.get(tableColumn, 'component.props.balloonTipFields');
90
+ if (Array.isArray(balloonTipFields) && balloonTipFields.length > 0) {
91
+ for (let j = 0; j < balloonTipFields.length; j++) {
92
+ const { component, name } = balloonTipFields[j] || {};
93
+ if (component === CrudStdConstant_1.tableColumnRenders.RenderUserInfo) {
94
+ maker.addColumnRelationByAccount(name);
95
+ }
69
96
  }
70
97
  }
71
98
  }
@@ -16,6 +16,9 @@ export interface ICrudStdActionParams {
16
16
  settingKey?: string;
17
17
  buttonSettingKey?: string;
18
18
  }
19
+ export interface IRequestModelCrudProExt extends IRequestModel {
20
+ filterValue: string | number;
21
+ }
19
22
  export declare class CrudStdService extends ApiBaseService {
20
23
  protected ctx: Context;
21
24
  protected curdMixService: CurdMixService;
@@ -24,7 +27,7 @@ export declare class CrudStdService extends ApiBaseService {
24
27
  /**
25
28
  * 执行普通CRUD
26
29
  */
27
- executeStdQuery(stdAction: ICrudStdActionParams, params: IRequestModel, sqlSimpleName: KeysOfSimpleSQL): Promise<ExecuteContext>;
30
+ executeStdQuery(stdAction: ICrudStdActionParams, params: IRequestModelCrudProExt, sqlSimpleName: KeysOfSimpleSQL): Promise<ExecuteContext>;
28
31
  /**
29
32
  * 获取appInfo 并且拿到当前settingKey相关的信息
30
33
  * @param appCode
@@ -37,7 +40,7 @@ export declare class CrudStdService extends ApiBaseService {
37
40
  * @param stdAction
38
41
  * @param params
39
42
  */
40
- executeStdActionByReq(stdAction: ICrudStdActionParams, params: IRequestModel): Promise<ExecuteContext>;
43
+ executeStdActionByReq(stdAction: ICrudStdActionParams, params: IRequestModelCrudProExt): Promise<ExecuteContext>;
41
44
  /**
42
45
  * 查询APP信息
43
46
  * @param appCode
@@ -57,6 +60,7 @@ export declare class CrudStdService extends ApiBaseService {
57
60
  */
58
61
  private getParsedCrudStdAppInfoPrivate;
59
62
  private hasOperationPerm;
63
+ private fixCfgModelByFilterValue;
60
64
  private fixSubmitDataByKeepSubmitData;
61
65
  private fixDataFieldTypeBySqlTableField;
62
66
  }
@@ -59,6 +59,7 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
59
59
  sqlDbType: dbType,
60
60
  sqlTable: getExecuteTableNameBySettingKey(appInfo, stdAction),
61
61
  sqlSimpleName,
62
+ updateCfg: {}
62
63
  };
63
64
  // 接口返回最大值
64
65
  const maxLimit = _.get(stdCrudCfgObj, 'othersSetting.values.maxLimit');
@@ -70,6 +71,8 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
70
71
  }
71
72
  // 根据用户配置,设置关联查询的数据信息。
72
73
  await this.crudStdRelationService.addCfgModelColumnsRelation(cfgModel, appInfo);
74
+ // 根据FilterValue参数,设置updateCfg
75
+ await this.fixCfgModelByFilterValue(params, cfgModel, appInfo, { dbType, dbName });
73
76
  // 根据用户配置的keepSubmitData字段修改提交的数据
74
77
  await this.fixSubmitDataByKeepSubmitData(params, cfgModel, appInfo, { dbType, dbName });
75
78
  // 根据表结构的数据类型,修正数据类型
@@ -208,6 +211,28 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
208
211
  }
209
212
  return true; // 无需鉴权
210
213
  }
214
+ async fixCfgModelByFilterValue(params, cfgModel, appInfo, arg3) {
215
+ const { filterValue } = params || {};
216
+ if (!filterValue && filterValue !== 0) {
217
+ return;
218
+ }
219
+ const filterList = _.get(appInfo, 'stdCrudCfgObj.filterList');
220
+ if (!Array.isArray(filterList) || filterList.length === 0) {
221
+ this.logWarn('filterValue存在,但是filterList没有设置');
222
+ return;
223
+ }
224
+ const filterItem = filterList.find(item => item.value === filterValue);
225
+ if (!filterItem) {
226
+ this.logWarn('filterValue存在,但是filterList中没有找到此配置项');
227
+ return;
228
+ }
229
+ const partialCondition = _.get(filterItem, 'partialCondition');
230
+ if (!partialCondition) {
231
+ this.logWarn('filterValue存在,但是filterList中的配置项没有设置partialCondition');
232
+ return;
233
+ }
234
+ Object.assign(cfgModel.updateCfg, partialCondition);
235
+ }
211
236
  async fixSubmitDataByKeepSubmitData(params, cfgModel, appInfo, arg3) {
212
237
  if (cfgModel.sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT || cfgModel.sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE) {
213
238
  const submitData = params.data || {};
@@ -1,3 +1,3 @@
1
- import { IRequestCfgModel2 } from "../../models/bizmodels";
1
+ import { IRequestCfgModel2 } from '../../models/bizmodels';
2
2
  declare function fixCfgModel(cfgModel: IRequestCfgModel2): void;
3
3
  export { fixCfgModel };
@@ -4,10 +4,7 @@ exports.fixCfgModel = void 0;
4
4
  const bizmodels_1 = require("../../models/bizmodels");
5
5
  const keys_1 = require("../../libs/crud-pro/models/keys");
6
6
  function isSimpleQuery(sqlSimpleName) {
7
- return sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY ||
8
- sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_COUNT ||
9
- sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE ||
10
- sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE;
7
+ return sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY || sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_COUNT || sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE || sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE;
11
8
  }
12
9
  function fixCfgModel(cfgModel) {
13
10
  if (!cfgModel.method) {
@@ -94,8 +91,7 @@ function fixCfgModel(cfgModel) {
94
91
  Object.assign(cfgModel.updateCfg, updateCfgObj2);
95
92
  }
96
93
  // 插入或更新
97
- if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT_OR_UPDATE ||
98
- sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT_ON_DUPLICATE_UPDATE) {
94
+ if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT_OR_UPDATE || sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT_ON_DUPLICATE_UPDATE) {
99
95
  const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.created');
100
96
  const updateCfgObj2 = buildUpdateCfgBy(dataCfgArray, 'data.modified');
101
97
  const updateCfgObj3 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midway-fatcms",
3
- "version": "0.0.1-beta.47",
3
+ "version": "0.0.1-beta.49",
4
4
  "description": "This is a midway component sample",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",