@steedos-labs/plugin-workflow 3.0.52 → 3.0.53

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.
@@ -5,7 +5,7 @@
5
5
  <link rel="shortcut icon" type="image/svg+xml" href="/images/logo.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>designer</title>
8
- <script type="module" crossorigin src="/api/workflow/designer-v2/assets/index-BkLrUP0o.js"></script>
8
+ <script type="module" crossorigin src="/api/workflow/designer-v2/assets/index-3PKde6SC.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/api/workflow/designer-v2/assets/index-xR8ApdWL.css">
10
10
  </head>
11
11
  <body>
@@ -304,15 +304,16 @@ getHandlersManager.getHandlers = async function (instance_id, step_id, login_use
304
304
  }
305
305
 
306
306
  for (const org of org_ids_names) {
307
+ const org_id_val = _.isString(org) ? org : org["id"];
307
308
  const check_org_count = await organizationsCollection.find({
308
- _id: org["id"]
309
+ _id: org_id_val
309
310
  }).count();
310
311
 
311
312
  if (check_org_count === 0) {
312
313
  throw new Error('error! 组织ID不合法');
313
314
  }
314
315
 
315
- org_ids.push(org["id"]);
316
+ org_ids.push(org_id_val);
316
317
  }
317
318
 
318
319
  if (current_step.approver_roles && current_step.approver_roles.length > 0) {
@@ -380,15 +381,16 @@ getHandlersManager.getHandlers = async function (instance_id, step_id, login_use
380
381
  }
381
382
 
382
383
  for (const org of org_ids_names) {
384
+ const org_id_val = _.isString(org) ? org : org["id"];
383
385
  const check_org_count = await organizationsCollection.find({
384
- _id: org["id"]
386
+ _id: org_id_val
385
387
  }).count();
386
388
 
387
389
  if (check_org_count === 0) {
388
390
  throw new Error('error! 组织ID不合法');
389
391
  }
390
392
 
391
- org_ids.push(org["id"]);
393
+ org_ids.push(org_id_val);
392
394
  }
393
395
 
394
396
  let user_ids = [];
@@ -81,7 +81,7 @@ async function upgradeForm(formId, form, currentUserId, spaceId) {
81
81
  const insCount = await instancesCollection.countDocuments({
82
82
  space: spaceId,
83
83
  form: formId,
84
- 'form_version': form['current']['id']
84
+ 'form_version': form['current']['id'] || form['current']['_id']
85
85
  });
86
86
  pass = insCount > 0;
87
87
  } else if (ff.app === 'creator') {
@@ -89,7 +89,7 @@ async function upgradeForm(formId, form, currentUserId, spaceId) {
89
89
  const recordsCount = await recordsCollection.countDocuments({
90
90
  space: spaceId,
91
91
  form: formId,
92
- 'form_version': form['current']['id']
92
+ 'form_version': form['current']['id'] || form['current']['_id']
93
93
  });
94
94
  pass = recordsCount > 0;
95
95
  }
@@ -165,7 +165,7 @@ async function upgradeFlow(flowCome, userId, flowId) {
165
165
 
166
166
  // Process steps
167
167
  const clientStepIds = [];
168
- _.each(flowCome['current']['steps'], (step) => clientStepIds.push(step['id']));
168
+ _.each(flowCome['current']['steps'], (step) => clientStepIds.push(step['_id'] || step['id']));
169
169
  _.each(flowCome['current']['steps'], (step) => {
170
170
  if (step['approver_step'] && !clientStepIds.includes(step['approver_step'])) {
171
171
  step['approver_step'] = '';
@@ -1240,7 +1240,27 @@ UUFlowManager.getInstanceName = async function (instance, vals) {
1240
1240
  // Remove special characters from the name
1241
1241
  rev = rev.replace(/\?|\*|\:|\"|\<|\>|\\|\/|\|/g, "");
1242
1242
  } catch (error) {
1243
- console.error('Error evaluating instance name formula:', error);
1243
+ // JS expression failed retry as template format
1244
+ // e.g. "新闻上报-{title}" or "News Report-{title}"
1245
+ try {
1246
+ let templateScript = form_v.name_forumla;
1247
+ templateScript = templateScript.split(/(\{[^{}]+\})/).map(part => {
1248
+ if (/^\{[^{}]+\}$/.test(part)) return part;
1249
+ return part ? JSON.stringify(part) : '';
1250
+ }).filter(Boolean).join('+');
1251
+
1252
+ if (templateScript.includes("{applicant.")) {
1253
+ templateScript = templateScript.replace(/\{applicant./g, "(applicant.").replace(/\}/g, " || '')");
1254
+ }
1255
+ templateScript = templateScript.replace(/\{/g, "(values.").replace(/\}/g, " || '')");
1256
+
1257
+ const script = `module.exports = function (applicant, values, flow, form) { return ${templateScript} }`;
1258
+ const func = _eval(script, "getInstanceName");
1259
+ rev = func(applicant, values, null, form) || default_value;
1260
+ rev = rev.replace(/\?|\*|\:|\"|\<|\>|\\|\/|\|/g, "");
1261
+ } catch (e) {
1262
+ console.error('Error evaluating instance name formula:', e);
1263
+ }
1244
1264
  }
1245
1265
  }
1246
1266
 
@@ -183,7 +183,7 @@ router.post('/am/forms', async function (req, res) {
183
183
  });
184
184
  let companyId = currentSpaceUser.company_id;
185
185
  let newForm = {
186
- _id: form["id"],
186
+ _id: form["id"] || form["_id"],
187
187
  name: form["name"],
188
188
  state: "disabled",
189
189
  is_deleted: false,
@@ -204,7 +204,7 @@ router.post('/am/forms', async function (req, res) {
204
204
  newForm.company_id = companyId;
205
205
  }
206
206
  let current = {
207
- _id: form["current"]["id"],
207
+ _id: form["current"]["id"] || form["current"]["_id"],
208
208
  name_forumla: name_forumla,
209
209
  form: newForm._id,
210
210
  _rev: 1,
@@ -274,7 +274,7 @@ router.post('/am/forms', async function (req, res) {
274
274
  let flow = {
275
275
  _id: _makeNewID(),
276
276
  space: form["space"],
277
- form: form["id"],
277
+ form: form["id"] || form["_id"],
278
278
  name_formula: "",
279
279
  code_formula: "",
280
280
  is_valid: true,
@@ -323,7 +323,7 @@ router.post('/am/forms', async function (req, res) {
323
323
  steps: await designerManager.makeSteps(userId, newForm.current.fields, language),
324
324
  _rev: 1,
325
325
  flow: flow._id,
326
- form_version: form["current"]["id"],
326
+ form_version: form["current"]["id"] || form["current"]["_id"],
327
327
  created: now,
328
328
  created_by: userId,
329
329
  modified: now,
@@ -359,7 +359,7 @@ router.put('/am/forms', async function (req, res) {
359
359
  // 执行者的身份校验
360
360
  await designerManager.checkSpaceUserBeforeUpdate(form['space'], userId, req.user.roles)
361
361
  // 更新表单
362
- await designerManager.updateForm(form["id"], form, updatedForms, updatedFlows, userId)
362
+ await designerManager.updateForm(form["id"] || form["_id"], form, updatedForms, updatedFlows, userId)
363
363
  }
364
364
  res.send({
365
365
  "ChangeSet": {
@@ -395,7 +395,7 @@ router.delete('/am/forms', async function (req, res) {
395
395
  let now = new Date();
396
396
  for (let i = 0; i < data['Forms'].length; i++) {
397
397
  let form = data['Forms'][i];
398
- let f = await formCollection.findOne({_id: form["id"]});
398
+ let f = await formCollection.findOne({_id: form["id"] || form["_id"]});
399
399
  // 执行者的身份校验
400
400
  await designerManager.checkSpaceUserBeforeUpdate(f.space, userId, req.user.roles)
401
401
 
@@ -405,7 +405,7 @@ router.delete('/am/forms', async function (req, res) {
405
405
  // 删除表单对应流程
406
406
  let flows = await flowCollection.find({
407
407
  space: spaceId,
408
- form: form["id"]
408
+ form: form["id"] || form["_id"]
409
409
  }).toArray();
410
410
  for (let flow_fd of flows) {
411
411
  let deleted_flow = Object.assign({}, flow_fd);
@@ -420,7 +420,7 @@ router.delete('/am/forms', async function (req, res) {
420
420
  if (recordCollection) {
421
421
  let records = await recordCollection.find({
422
422
  space: spaceId,
423
- form: form["id"]
423
+ form: form["id"] || form["_id"]
424
424
  }).toArray();
425
425
  for (let record_fd of records) {
426
426
  let deleted_record = Object.assign({}, record_fd);
@@ -435,7 +435,7 @@ router.delete('/am/forms', async function (req, res) {
435
435
  // 删除表单对应申请单
436
436
  let instances = await instanceCollection.find({
437
437
  space: spaceId,
438
- form: form["id"]
438
+ form: form["id"] || form["_id"]
439
439
  }).toArray();
440
440
  for (let instance_fd of instances) {
441
441
  let deleted_instance = Object.assign({}, instance_fd);
@@ -447,7 +447,7 @@ router.delete('/am/forms', async function (req, res) {
447
447
  }
448
448
 
449
449
  // 删除instance_tasks
450
- await instanceCollection.deleteMany({ form: form["id"] })
450
+ await instanceCollection.deleteMany({ form: form["id"] || form["_id"] })
451
451
 
452
452
  // 删除表单
453
453
  let deleted_form = Object.assign({}, f);
@@ -455,7 +455,7 @@ router.delete('/am/forms', async function (req, res) {
455
455
  deleted_form['deleted_by'] = userId;
456
456
  await dFormsCollection.insert(deleted_form);
457
457
  deletedForms.push(deleted_form);
458
- await formCollection.deleteOne({_id: form["id"]})
458
+ await formCollection.deleteOne({_id: form["id"] || form["_id"]})
459
459
  }
460
460
 
461
461
  res.send({
@@ -484,7 +484,7 @@ router.put('/am/flows', async function (req, res) {
484
484
  let flowCome = data['Flows'][i];
485
485
  let spaceId = flowCome["space"];
486
486
  let formId = flowCome["form"];
487
- let flowId = flowCome["id"];
487
+ let flowId = flowCome["id"] || flowCome["_id"];
488
488
  let upgraded = flowCome['upgraded'];
489
489
  delete flowCome['decription'];
490
490
  let now = new Date();
@@ -502,7 +502,7 @@ router.put('/am/flows', async function (req, res) {
502
502
  // 某步骤被删除后,删除同流程的“指定历史步骤”属性中被引用的步骤id(仅限于流程的最新版)
503
503
  let clientStepIds = []
504
504
  _.each(flowCome['current']['steps'], function (step) {
505
- clientStepIds.push(step['id']);
505
+ clientStepIds.push(step['_id'] || step['id']);
506
506
  })
507
507
 
508
508
  _.each(flowCome['current']['steps'], function (step) {
@@ -525,12 +525,16 @@ router.put('/am/flows', async function (req, res) {
525
525
 
526
526
  // 由于前台传的是id而非_id,故比较时将id转为_id
527
527
  _.each(flowCome['current']['steps'], function (step) {
528
- step['_id'] = step['id'];
529
- delete step['id'];
528
+ if (step['id']) {
529
+ step['_id'] = step['id'];
530
+ delete step['id'];
531
+ }
530
532
  if (step['lines']) {
531
533
  _.each(step['lines'], function (line) {
532
- line['_id'] = line['id'];
533
- delete line['id'];
534
+ if (line['id']) {
535
+ line['_id'] = line['id'];
536
+ delete line['id'];
537
+ }
534
538
  })
535
539
  }
536
540
  })
@@ -666,7 +670,7 @@ router.put('/am/flows/state', async function (req, res) {
666
670
  let flowCome = data['Flows'][i];
667
671
  let spaceId = flowCome["space"];
668
672
  let formId = flowCome["form"];
669
- let flowId = flowCome["id"];
673
+ let flowId = flowCome["id"] || flowCome["_id"];
670
674
  let now = new Date();
671
675
  let flowUpdateObj = {
672
676
  $set: {}
@@ -416,6 +416,15 @@ if (field.name === 'quantity' || field.name === 'unit_price') {
416
416
  - 示例:旧版 \`{项目名称}({申请日期})\` → 新版 \`{project_name}({apply_date})\`(注意中文括号必须保留)
417
417
  - 如果用户未提供旧版标题公式,则 nameFormula 字段可省略或返回空字符串
418
418
 
419
+ #### name_forumla 运行时格式规范
420
+ nameFormula 是一个 JS 表达式,运行时被包装为 \`return <nameFormula>\`,其中 \`{fieldCode}\` 会被替换为 \`(values.fieldCode || '')\`,\`{applicant.xxx}\` 会被替换为 \`(applicant.xxx || '')\`。
421
+ **规则:所有非 {xxx} 的文本(包括中文、符号、空格)必须用引号包裹,多段用 + 拼接。**
422
+ - 正确:\`"合同名称" + {project_name}\`
423
+ - 正确:\`{applicant_name} + "-" + {project_name}\`
424
+ - 错误:\`合同名称{project_name}\` — JS 语法错误
425
+ - 错误:\`合同名称 + {project_name}\` — JS 语法错误
426
+ - 错误:\`{project_name} 审批单\` — JS 语法错误
427
+
419
428
  ### migrationLog(迁移记录)
420
429
  当用户提供了 flow_events、form_script、instance_template 中包含业务逻辑(如校验、赋值、显隐控制等脚本代码)时,必须在 migrationLog 数组中为每条被迁移的逻辑记录一条说明,格式:
421
430
  "<来源>: <原逻辑简述> → <迁移到的具体位置>"
@@ -787,6 +787,15 @@ if (field.name === 'quantity' || field.name === 'unit_price') {
787
787
  - 示例:旧版 \`{项目名称}({申请日期})\` → 新版 \`{project_name}({apply_date})\`(注意中文括号必须保留)
788
788
  - 如果用户未提供旧版标题公式,则 nameFormula 字段可省略或返回空字符串
789
789
 
790
+ #### name_forumla 运行时格式规范
791
+ nameFormula 是一个 JS 表达式,运行时被包装为 \`return <nameFormula>\`,其中 \`{fieldCode}\` 会被替换为 \`(values.fieldCode || '')\`,\`{applicant.xxx}\` 会被替换为 \`(applicant.xxx || '')\`。
792
+ **规则:所有非 {xxx} 的文本(包括中文、符号、空格)必须用引号包裹,多段用 + 拼接。**
793
+ - 正确:\`"合同名称" + {project_name}\`
794
+ - 正确:\`{applicant_name} + "-" + {project_name}\`
795
+ - 错误:\`合同名称{project_name}\` — JS 语法错误
796
+ - 错误:\`合同名称 + {project_name}\` — JS 语法错误
797
+ - 错误:\`{project_name} 审批单\` — JS 语法错误
798
+
790
799
  ### migrationLog(迁移记录)
791
800
  当用户提供了 flow_events、form_script、instance_template 中包含业务逻辑(如校验、赋值、显隐控制等脚本代码)时,必须在 migrationLog 数组中为每条被迁移的逻辑记录一条说明,格式:
792
801
  "<来源>: <原逻辑简述> → <迁移到的具体位置>"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos-labs/plugin-workflow",
3
- "version": "3.0.52",
3
+ "version": "3.0.53",
4
4
  "main": "package.service.js",
5
5
  "license": "MIT",
6
6
  "files": [