midway-fatcms 0.0.1-beta.45 → 0.0.1-beta.46

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.
@@ -33,52 +33,44 @@ let CrudStdGatewayController = class CrudStdGatewayController extends BaseApiCon
33
33
  */
34
34
  async getObjectList() {
35
35
  const { stdAction, ...otherParams } = this.ctx.request.body;
36
- const appCode = stdAction.appCode;
37
- return this.crudStdService.executeStdQuery(appCode, CrudStdService_1.SPECIAL_SETTING_KEY.QUERY_LIST, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
36
+ stdAction.settingKey = CrudStdService_1.SPECIAL_SETTING_KEY.QUERY_LIST;
37
+ return this.crudStdService.executeStdQuery(stdAction, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
38
38
  }
39
39
  /**
40
40
  * 单个查询
41
41
  */
42
42
  async getObjectOne() {
43
43
  const { stdAction, ...otherParams } = this.ctx.request.body;
44
- const appCode = stdAction.appCode;
45
- return this.crudStdService.executeStdQuery(appCode, CrudStdService_1.SPECIAL_SETTING_KEY.QUERY_ONE, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE);
44
+ stdAction.settingKey = CrudStdService_1.SPECIAL_SETTING_KEY.QUERY_ONE;
45
+ return this.crudStdService.executeStdQuery(stdAction, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE);
46
46
  }
47
47
  /**
48
48
  * 单个删除
49
49
  */
50
50
  async deleteObject() {
51
51
  const { stdAction, ...otherParams } = this.ctx.request.body;
52
- const appCode = stdAction.appCode;
53
- const settingKey = stdAction.settingKey;
54
- return this.crudStdService.executeStdQuery(appCode, settingKey, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_DELETE);
52
+ return this.crudStdService.executeStdQuery(stdAction, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_DELETE);
55
53
  }
56
54
  /**
57
55
  * 单个创建
58
56
  */
59
57
  async createObject() {
60
58
  const { stdAction, ...otherParams } = this.ctx.request.body;
61
- const appCode = stdAction.appCode;
62
- const settingKey = stdAction.settingKey;
63
- return this.crudStdService.executeStdQuery(appCode, settingKey, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_INSERT);
59
+ return this.crudStdService.executeStdQuery(stdAction, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_INSERT);
64
60
  }
65
61
  /**
66
62
  * 单个更新
67
63
  */
68
64
  async updateObject() {
69
65
  const { stdAction, ...otherParams } = this.ctx.request.body;
70
- const appCode = stdAction.appCode;
71
- const settingKey = stdAction.settingKey;
72
- return this.crudStdService.executeStdQuery(appCode, settingKey, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE);
66
+ return this.crudStdService.executeStdQuery(stdAction, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE);
73
67
  }
74
68
  /**
75
69
  * 执行操作
76
70
  */
77
71
  async executeStdAction() {
78
72
  const { stdAction, ...otherParams } = this.ctx.request.body;
79
- const appCode = stdAction.appCode;
80
- const settingKey = stdAction.settingKey;
81
- return await this.crudStdService.executeStdActionByReq(appCode, settingKey, otherParams);
73
+ return await this.crudStdService.executeStdActionByReq(stdAction, otherParams);
82
74
  }
83
75
  };
84
76
  __decorate([
@@ -12,10 +12,14 @@ function createUniqueId() {
12
12
  }
13
13
  exports.createUniqueId = createUniqueId;
14
14
  function parseJsonObject(str) {
15
- if (typeof str === 'object') {
15
+ const typeofStr = typeof str;
16
+ if (str === null || typeofStr === 'undefined') {
17
+ return null;
18
+ }
19
+ if (typeofStr === 'object') {
16
20
  return str;
17
21
  }
18
- if (typeof str === 'string') {
22
+ if (typeofStr === 'string') {
19
23
  str = str.trim();
20
24
  if (str.startsWith('{') || str.startsWith('[')) {
21
25
  try {
@@ -31,6 +31,7 @@ export interface ICrudStdAppInfo {
31
31
  }
32
32
  export interface ICrudStdAppInfoForSettingKey extends ICrudStdAppInfo {
33
33
  settingKeyActionCfg?: any;
34
+ buttonSettingKeyActionCfg?: any;
34
35
  authConfig?: string[];
35
36
  authType?: string;
36
37
  }
@@ -90,7 +90,11 @@ class ExportExcelByStdCrudHandler {
90
90
  this.ctx.innerHeaders = {};
91
91
  }
92
92
  Object.assign(this.ctx.innerHeaders, this.inputParams.headers || {});
93
- const a = await crudStdService.executeStdQuery(appCode, CrudStdService_1.SPECIAL_SETTING_KEY.QUERY_LIST, params, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
93
+ const stdAction = {
94
+ appCode: appCode,
95
+ settingKey: CrudStdService_1.SPECIAL_SETTING_KEY.QUERY_LIST,
96
+ };
97
+ const a = await crudStdService.executeStdQuery(stdAction, params, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
94
98
  return pickData(a, 'total_count');
95
99
  }
96
100
  /**
@@ -116,7 +120,11 @@ class ExportExcelByStdCrudHandler {
116
120
  $in: selectedRowKeys,
117
121
  };
118
122
  }
119
- const a = await crudStdService.executeStdQuery(appCode, CrudStdService_1.SPECIAL_SETTING_KEY.QUERY_LIST, params, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
123
+ const stdAction = {
124
+ appCode: appCode,
125
+ settingKey: CrudStdService_1.SPECIAL_SETTING_KEY.QUERY_LIST,
126
+ };
127
+ const a = await crudStdService.executeStdQuery(stdAction, params, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
120
128
  return pickData(a, 'rows');
121
129
  }
122
130
  }
@@ -11,6 +11,11 @@ export declare const SPECIAL_SETTING_KEY: {
11
11
  QUERY_LIST: string;
12
12
  QUERY_ONE: string;
13
13
  };
14
+ export interface ICrudStdActionParams {
15
+ appCode: string;
16
+ settingKey?: string;
17
+ buttonSettingKey?: string;
18
+ }
14
19
  export declare class CrudStdService extends ApiBaseService {
15
20
  protected ctx: Context;
16
21
  protected curdMixService: CurdMixService;
@@ -19,7 +24,7 @@ export declare class CrudStdService extends ApiBaseService {
19
24
  /**
20
25
  * 执行普通CRUD
21
26
  */
22
- executeStdQuery(appCode: string, settingKey: string, params: IRequestModel, sqlSimpleName: KeysOfSimpleSQL): Promise<ExecuteContext>;
27
+ executeStdQuery(stdAction: ICrudStdActionParams, params: IRequestModel, sqlSimpleName: KeysOfSimpleSQL): Promise<ExecuteContext>;
23
28
  /**
24
29
  * 获取appInfo 并且拿到当前settingKey相关的信息
25
30
  * @param appCode
@@ -29,11 +34,10 @@ export declare class CrudStdService extends ApiBaseService {
29
34
  private getParsedCrudStdAppForSettingKey;
30
35
  /**
31
36
  * 执行动作
32
- * @param appCode
33
- * @param settingKey
37
+ * @param stdAction
34
38
  * @param params
35
39
  */
36
- executeStdActionByReq(appCode: string, settingKey: string, params: IRequestModel): Promise<ExecuteContext>;
40
+ executeStdActionByReq(stdAction: ICrudStdActionParams, params: IRequestModel): Promise<ExecuteContext>;
37
41
  /**
38
42
  * 查询APP信息
39
43
  * @param appCode
@@ -53,5 +57,6 @@ export declare class CrudStdService extends ApiBaseService {
53
57
  */
54
58
  private getParsedCrudStdAppInfoPrivate;
55
59
  private hasOperationPerm;
60
+ private fixSubmitDataByKeepSubmitData;
56
61
  private fixDataFieldTypeBySqlTableField;
57
62
  }
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CrudStdService = exports.SPECIAL_SETTING_KEY = void 0;
13
+ /* eslint-disable prettier/prettier */
13
14
  const _ = require("lodash");
14
15
  const core_1 = require("@midwayjs/core");
15
16
  const CurdMixService_1 = require("../curd/CurdMixService");
@@ -27,7 +28,8 @@ exports.SPECIAL_SETTING_KEY = {
27
28
  QUERY_LIST: 'QUERY_LIST',
28
29
  QUERY_ONE: 'QUERY_ONE',
29
30
  };
30
- function getExecuteTableNameBySettingKey(appInfo, settingKey) {
31
+ function getExecuteTableNameBySettingKey(appInfo, stdAction) {
32
+ const { settingKey } = stdAction || {};
31
33
  const stdCrudCfgObj = appInfo.stdCrudCfgObj;
32
34
  const actionsMap = appInfo.actionsMap || {};
33
35
  const actionCfg = actionsMap[settingKey];
@@ -43,8 +45,9 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
43
45
  /**
44
46
  * 执行普通CRUD
45
47
  */
46
- async executeStdQuery(appCode, settingKey, params, sqlSimpleName) {
47
- const appInfo = await this.getParsedCrudStdAppForSettingKey(appCode, settingKey);
48
+ async executeStdQuery(stdAction, params, sqlSimpleName) {
49
+ const appCode = stdAction.appCode;
50
+ const appInfo = await this.getParsedCrudStdAppForSettingKey(stdAction);
48
51
  const stdCrudCfgObj = appInfo.stdCrudCfgObj;
49
52
  if (!appInfo || appInfo.status !== 1) {
50
53
  throw new devops_1.BizException('应用不存在或已下线:' + appCode);
@@ -54,7 +57,7 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
54
57
  const cfgModel = {
55
58
  sqlDatabase: dbName,
56
59
  sqlDbType: dbType,
57
- sqlTable: getExecuteTableNameBySettingKey(appInfo, settingKey),
60
+ sqlTable: getExecuteTableNameBySettingKey(appInfo, stdAction),
58
61
  sqlSimpleName,
59
62
  };
60
63
  // 接口返回最大值
@@ -67,6 +70,8 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
67
70
  }
68
71
  // 根据用户配置,设置关联查询的数据信息。
69
72
  await this.crudStdRelationService.addCfgModelColumnsRelation(cfgModel, appInfo);
73
+ // 根据用户配置的keepSubmitData字段修改提交的数据
74
+ await this.fixSubmitDataByKeepSubmitData(params, cfgModel, appInfo, { dbType, dbName });
70
75
  // 根据表结构的数据类型,修正数据类型
71
76
  await this.fixDataFieldTypeBySqlTableField(params, cfgModel, appInfo, { dbType, dbName });
72
77
  // 业务系统自定义的修改:查询前的查询条件:cfgModel
@@ -82,7 +87,8 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
82
87
  * @param settingKey
83
88
  * @private
84
89
  */
85
- async getParsedCrudStdAppForSettingKey(appCode, settingKey) {
90
+ async getParsedCrudStdAppForSettingKey(stdAction) {
91
+ const { appCode, settingKey, buttonSettingKey } = stdAction || {};
86
92
  if (!appCode) {
87
93
  throw new devops_1.BizException('缺少参数:curdStdAppCode');
88
94
  }
@@ -110,18 +116,20 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
110
116
  }
111
117
  appInfo.settingKeyActionCfg = actionCfg;
112
118
  }
119
+ if (buttonSettingKey) {
120
+ appInfo.buttonSettingKeyActionCfg = actionsMap[buttonSettingKey];
121
+ }
113
122
  return appInfo;
114
123
  }
115
124
  /**
116
125
  * 执行动作
117
- * @param appCode
118
- * @param settingKey
126
+ * @param stdAction
119
127
  * @param params
120
128
  */
121
- async executeStdActionByReq(appCode, settingKey, params) {
122
- const appInfo = await this.getParsedCrudStdAppForSettingKey(appCode, settingKey);
129
+ async executeStdActionByReq(stdAction, params) {
130
+ const appInfo = await this.getParsedCrudStdAppForSettingKey(stdAction);
123
131
  if (!appInfo || appInfo.status !== 1) {
124
- throw new devops_1.BizException('应用不存在或已下线:' + appCode);
132
+ throw new devops_1.BizException('应用不存在或已下线:' + stdAction.appCode);
125
133
  }
126
134
  const actionsMap = appInfo.actionsMap;
127
135
  const actionCfg = appInfo.settingKeyActionCfg;
@@ -170,12 +178,7 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
170
178
  }
171
179
  const { app_schema, ...others } = row;
172
180
  const stdCrudCfgObj = (0, functions_1.parseJsonObject)(app_schema);
173
- // 为了方便查找到action对象
174
- const actionsMap = {};
175
- const keys = Object.keys(stdCrudCfgObj);
176
- for (let i = 0; i < keys.length; i++) {
177
- const key = keys[i];
178
- const arrayCfg = stdCrudCfgObj[key];
181
+ const handleArrayCfg = (arrayCfg) => {
179
182
  if (Array.isArray(arrayCfg)) {
180
183
  for (let j = 0; j < arrayCfg.length; j++) {
181
184
  const actionCfg = arrayCfg[j];
@@ -183,8 +186,18 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
183
186
  if (actionCfg.settingKey) {
184
187
  actionsMap[actionCfg.settingKey] = actionCfg;
185
188
  }
189
+ const submitButtonCfg = _.get(actionCfg, 'component.props.submitButtonCfg');
190
+ handleArrayCfg(submitButtonCfg);
186
191
  }
187
192
  }
193
+ };
194
+ // 为了方便查找到action对象
195
+ const actionsMap = {};
196
+ const keys = Object.keys(stdCrudCfgObj);
197
+ for (let i = 0; i < keys.length; i++) {
198
+ const key = keys[i];
199
+ const arrayCfg = stdCrudCfgObj[key];
200
+ handleArrayCfg(arrayCfg);
188
201
  }
189
202
  return { ...others, stdCrudCfgObj, actionsMap };
190
203
  }
@@ -195,6 +208,21 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
195
208
  }
196
209
  return true; // 无需鉴权
197
210
  }
211
+ async fixSubmitDataByKeepSubmitData(params, cfgModel, appInfo, arg3) {
212
+ if (cfgModel.sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT || cfgModel.sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE) {
213
+ const submitData = params.data || {};
214
+ //1. 按钮中配置的keepSubmitData
215
+ const buttonActionCfg = appInfo.buttonSettingKeyActionCfg || {};
216
+ const keepSubmitDataByButtonStr = _.get(buttonActionCfg, 'keepSubmitData');
217
+ const keepSubmitDataByButton = (0, functions_1.parseJsonObject)(keepSubmitDataByButtonStr);
218
+ //2. 全局配置的keepSubmitData
219
+ const keepSubmitDataByGlobalStr = _.get(appInfo, 'stdCrudCfgObj.othersSetting.values.keepSubmitData');
220
+ const keepSubmitDataByGlobal = (0, functions_1.parseJsonObject)(keepSubmitDataByGlobalStr);
221
+ //3. 合并
222
+ Object.assign(submitData, keepSubmitDataByButton);
223
+ Object.assign(submitData, keepSubmitDataByGlobal);
224
+ }
225
+ }
198
226
  async fixDataFieldTypeBySqlTableField(params, cfgModel, appInfo, arg3) {
199
227
  const tableFields = _.get(appInfo, 'stdCrudCfgObj.tableFields');
200
228
  const tableFieldMap = MixinUtils_1.MixinUtils.toMap(tableFields, (e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midway-fatcms",
3
- "version": "0.0.1-beta.45",
3
+ "version": "0.0.1-beta.46",
4
4
  "description": "This is a midway component sample",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",