@steedos-labs/plugin-workflow 3.0.53 → 3.0.55

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,8 +5,8 @@
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-3PKde6SC.js"></script>
9
- <link rel="stylesheet" crossorigin href="/api/workflow/designer-v2/assets/index-xR8ApdWL.css">
8
+ <script type="module" crossorigin src="/api/workflow/designer-v2/assets/index-CBj3S4BT.js"></script>
9
+ <link rel="stylesheet" crossorigin href="/api/workflow/designer-v2/assets/index-BNulYl_s.css">
10
10
  </head>
11
11
  <body>
12
12
  <div id="root"></div>
@@ -94,7 +94,7 @@ async function upgradeForm(formId, form, currentUserId, spaceId) {
94
94
  pass = recordsCount > 0;
95
95
  }
96
96
 
97
- if (pass === true) {
97
+ if (pass === true || true) {
98
98
  formUpdateObj.$push = { 'historys': ff["current"] };
99
99
  current._id = _makeNewID();
100
100
  current._rev = ff["current"]["_rev"] + 1;
@@ -210,7 +210,7 @@ async function upgradeFlow(flowCome, userId, flowId) {
210
210
  });
211
211
  pass = insCount > 0;
212
212
 
213
- if (pass === true && flow.current.start_date && stepsStr === flowComeStepsStr) {
213
+ if (pass === true && flow.current.start_date && stepsStr === flowComeStepsStr || true) {
214
214
  updateObj.$push = { 'historys': flow.current };
215
215
  current = {
216
216
  '_id': _makeNewID(),
@@ -374,154 +374,134 @@ pushManager.getSmsBody = function (parameters, lang = "zh-CN") {
374
374
  return t('instance.sms.submit_pending_inbox', parameters, lang);
375
375
  };
376
376
 
377
+ const BADGE_SEND_FROM_WHITELIST = new Set([
378
+ 'first_submit_inbox', 'submit_pending_rejected_inbox',
379
+ 'submit_pending_inbox', 'current_user', 'terminate_approval',
380
+ 'reassign_new_inbox_users', 'trace_approve_cc', 'trace_approve_cc_submit',
381
+ 'auto_submit_pending_inbox', 'return_pending_inbox'
382
+ ]);
383
+
377
384
  pushManager.get_badge = async function (send_from, user_id) {
378
- if (!['first_submit_inbox', 'submit_pending_rejected_inbox',
379
- 'submit_pending_inbox', 'current_user', 'terminate_approval',
380
- 'reassign_new_inbox_users', 'trace_approve_cc', 'trace_approve_cc_submit',
381
- 'auto_submit_pending_inbox', 'return_pending_inbox'].includes(send_from)) {
382
- return null;
383
- }
384
- if (!user_id) {
385
+ if (!BADGE_SEND_FROM_WHITELIST.has(send_from) || !user_id) {
385
386
  return null;
386
387
  }
388
+
387
389
  let badge = 0;
388
- const db = {
389
- space_users: await getCollection('space_users'),
390
- categories: await getCollection('categories'),
391
- steedos_keyvalues: await getCollection('steedos_keyvalues')
392
- }
393
- let user_spaces = await db.space_users.find({
394
- user: user_id,
395
- user_accepted: true
396
- }, {
397
- fields: {space: 1}
398
- }).toArray();
390
+ const [spaceUsersCol, categoriesCol, keyvaluesCol] = await Promise.all([
391
+ getCollection('space_users'),
392
+ getCollection('categories'),
393
+ getCollection('steedos_keyvalues')
394
+ ]);
399
395
 
400
- for (const user_space of user_spaces) {
401
- var appCategories, c, categories, ref4, sk, sk_new, spaceId;
402
- spaceId = user_space.space;
396
+ const badgeQuery = { user: user_id, key: 'badge' };
397
+ const badgeFields = { fields: { _id: 1, value: 1 } };
403
398
 
404
- categories = await db.categories.find({
405
- space: spaceId,
406
- app: {
407
- $ne: null
408
- }
409
- }, {
410
- fields: { app: 1 }
411
- }).toArray();
399
+ const userSpaces = await spaceUsersCol.find(
400
+ { user: user_id, user_accepted: true },
401
+ { fields: { space: 1 } }
402
+ ).toArray();
403
+
404
+ for (const userSpace of userSpaces) {
405
+ const spaceId = userSpace.space;
406
+
407
+ // 按 app 分组的 category badge 更新
408
+ const categories = await categoriesCol.find(
409
+ { space: spaceId, app: { $ne: null } },
410
+ { fields: { app: 1 } }
411
+ ).toArray();
412
412
 
413
413
  if (categories.length > 0) {
414
- appCategories = _.groupBy(categories, 'app');
414
+ const appCategories = _.groupBy(categories, 'app');
415
+
415
416
  for (const appName in appCategories) {
416
- const categorys = appCategories[appName]
417
- var _set, appKeyValue, appKeyValueNew, categoryBadge, categorysIds, ref4;
418
- categorysIds = _.pluck(categorys, '_id');
419
- if (appName) {
420
- if (categorysIds.length > 0) {
421
-
422
- categoryBadge = await count_instance_tasks({
423
- filters: [
424
- ['handler', '=', user_id],
425
- ['is_finished', '=', false],
426
- ['space', '=', spaceId],
427
- ['category', 'in', categorysIds],
428
- ]
429
- })
430
-
431
- appKeyValue = await db.steedos_keyvalues.findOne({
432
- user: user_id,
433
- space: user_space.space,
434
- key: 'badge'
435
- }, {
436
- fields: {
437
- _id: 1,
438
- value: 1
439
- }
417
+ if (!appName) continue;
418
+
419
+ const categoryIds = _.pluck(appCategories[appName], '_id');
420
+ if (categoryIds.length === 0) continue;
421
+
422
+ const categoryBadge = await count_instance_tasks({
423
+ filters: [
424
+ ['handler', '=', user_id],
425
+ ['is_finished', '=', false],
426
+ ['space', '=', spaceId],
427
+ ['category', 'in', categoryIds],
428
+ ]
429
+ });
430
+
431
+ const appKeyValue = await keyvaluesCol.findOne(
432
+ { ...badgeQuery, space: spaceId },
433
+ badgeFields
434
+ );
435
+
436
+ if (appKeyValue) {
437
+ if (appKeyValue.value?.[appName] !== categoryBadge) {
438
+ await getObject('steedos_keyvalues').update(appKeyValue._id, {
439
+ [`value.${appName}`]: categoryBadge
440
440
  });
441
- if (appKeyValue) {
442
- if (((ref4 = appKeyValue.value) != null ? ref4[appName] : void 0) !== categoryBadge) {
443
- _set = {};
444
- _set['value.' + appName] = categoryBadge;
445
- await getObject('steedos_keyvalues').update(appKeyValue._id, _set)
446
- continue;
447
- }
448
- } else {
449
- appKeyValueNew = {};
450
- appKeyValueNew.user = user_id;
451
- appKeyValueNew.space = user_space.space;
452
- appKeyValueNew.key = 'badge';
453
- appKeyValueNew.value = {};
454
- appKeyValueNew.value[appName] = categoryBadge;
455
- await getObject('steedos_keyvalues').insert(appKeyValueNew)
456
- continue;
457
- }
458
441
  }
442
+ } else {
443
+ await getObject('steedos_keyvalues').insert({
444
+ user: user_id,
445
+ space: spaceId,
446
+ key: 'badge',
447
+ value: { [appName]: categoryBadge }
448
+ });
459
449
  }
460
450
  }
461
451
  }
462
452
 
463
453
  // workflow 记录所有待办数量
464
- c = await count_instance_tasks({
454
+ const taskCount = await count_instance_tasks({
465
455
  filters: [
466
456
  ['handler', '=', user_id],
467
457
  ['is_finished', '=', false],
468
458
  ['space', '=', spaceId],
469
459
  ]
470
- })
471
- badge += c;
472
- sk = await db.steedos_keyvalues.findOne({
473
- user: user_id,
474
- space: user_space.space,
475
- key: 'badge'
476
- }, {
477
- fields: {
478
- _id: 1,
479
- value: 1
480
- }
481
460
  });
461
+ badge += taskCount;
462
+
463
+ const sk = await keyvaluesCol.findOne(
464
+ { ...badgeQuery, space: spaceId },
465
+ badgeFields
466
+ );
467
+
482
468
  if (sk) {
483
- if (((ref4 = sk.value) != null ? ref4.workflow : void 0) !== c) {
469
+ if (sk.value?.workflow !== taskCount) {
484
470
  await getObject('steedos_keyvalues').update(sk._id, {
485
- 'value.workflow': c
486
- })
471
+ 'value.workflow': taskCount
472
+ });
487
473
  continue;
488
474
  }
489
475
  } else {
490
- sk_new = {};
491
- sk_new.user = user_id;
492
- sk_new.space = user_space.space;
493
- sk_new.key = 'badge';
494
- sk_new.value = {
495
- 'workflow': c
496
- };
497
- await getObject('steedos_keyvalues').insert(sk_new);
476
+ await getObject('steedos_keyvalues').insert({
477
+ user: user_id,
478
+ space: spaceId,
479
+ key: 'badge',
480
+ value: { workflow: taskCount }
481
+ });
498
482
  continue;
499
483
  }
500
484
  }
501
485
 
502
- sk_all = await db.steedos_keyvalues.findOne({
503
- user: user_id,
504
- space: null,
505
- key: 'badge'
506
- }, {
507
- fields: {
508
- _id: 1
509
- }
510
- });
511
- if (sk_all) {
512
- await getObject('steedos_keyvalues').update(sk_all._id, {
486
+ // 更新跨 space 的全局 badge
487
+ const skAll = await keyvaluesCol.findOne(
488
+ { ...badgeQuery, space: null },
489
+ { fields: { _id: 1 } }
490
+ );
491
+
492
+ if (skAll) {
493
+ await getObject('steedos_keyvalues').update(skAll._id, {
513
494
  'value.workflow': badge
514
495
  });
515
496
  } else {
516
- sk_all_new = {};
517
- sk_all_new.user = user_id;
518
- sk_all_new.space = null;
519
- sk_all_new.key = 'badge';
520
- sk_all_new.value = {
521
- 'workflow': badge
522
- };
523
- await getObject('steedos_keyvalues').insert(sk_all_new)
497
+ await getObject('steedos_keyvalues').insert({
498
+ user: user_id,
499
+ space: null,
500
+ key: 'badge',
501
+ value: { workflow: badge }
502
+ });
524
503
  }
504
+
525
505
  return badge;
526
506
  };
527
507
 
@@ -864,7 +864,7 @@ UUFlowManager.initFormulaValues = async function (instance, values) {
864
864
  * @param {Object} values - Form values
865
865
  * @returns {Array} Array of next step IDs
866
866
  */
867
- UUFlowManager.getNextSteps = async function (instance, flow, step, judge, values) {
867
+ UUFlowManager.getNextSteps = async function (instance, flow, step, judge, values, showSkipStep=false) {
868
868
  const step_type = step.step_type;
869
869
  let nextSteps = [];
870
870
 
@@ -1001,7 +1001,7 @@ UUFlowManager.getNextSteps = async function (instance, flow, step, judge, values
1001
1001
  for (const nextStepId of nextSteps) {
1002
1002
  const _step = await UUFlowManager.getStep(instance, flow, nextStepId);
1003
1003
 
1004
- if (isSkipStep(instance, _step)) {
1004
+ if (!showSkipStep && isSkipStep(instance, _step)) {
1005
1005
  if (!judge && _step.step_type === 'sign') {
1006
1006
  judge = 'approved';
1007
1007
  }
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ instance_exportVisible: function (object_name, record_id, record_permissions, data) {
3
+ var box = data.listName;
4
+ var flowId = data.flowId;
5
+ if (box === "monitor" && flowId) {
6
+ return true;
7
+ }
8
+ return false;
9
+ }
10
+ }
@@ -0,0 +1,83 @@
1
+ name: instance_export
2
+ amis_schema: |-
3
+ {
4
+ "type": "service",
5
+ "body": [
6
+ {
7
+ "type": "dropdown-button",
8
+ "label": "导出",
9
+ "id": "u:instance_export",
10
+ "level": "default",
11
+ "icon": "fa fa-download",
12
+ "buttons": [
13
+ {
14
+ "type": "button",
15
+ "label": "本月",
16
+ "onEvent": {
17
+ "click": {
18
+ "actions": [
19
+ {
20
+ "actionType": "custom",
21
+ "script": "var spaceId = event.data.context.tenantId; var flowId = event.data.flowId; if(spaceId && flowId){ var timezoneoffset = new Date().getTimezoneOffset(); var url = Steedos.absoluteUrl('/api/workflow/export/instances?space_id=' + spaceId + '&flow_id=' + flowId + '&type=0&timezoneoffset=' + timezoneoffset); window.open(url, '_blank'); } else { window.toastr && window.toastr.warning('请先选择流程'); }"
22
+ }
23
+ ]
24
+ }
25
+ }
26
+ },
27
+ {
28
+ "type": "button",
29
+ "label": "上月",
30
+ "onEvent": {
31
+ "click": {
32
+ "actions": [
33
+ {
34
+ "actionType": "custom",
35
+ "script": "var spaceId = event.data.context.tenantId; var flowId = event.data.flowId; if(spaceId && flowId){ var timezoneoffset = new Date().getTimezoneOffset(); var url = Steedos.absoluteUrl('/api/workflow/export/instances?space_id=' + spaceId + '&flow_id=' + flowId + '&type=1&timezoneoffset=' + timezoneoffset); window.open(url, '_blank'); } else { window.toastr && window.toastr.warning('请先选择流程'); }"
36
+ }
37
+ ]
38
+ }
39
+ }
40
+ },
41
+ {
42
+ "type": "button",
43
+ "label": "本年度",
44
+ "onEvent": {
45
+ "click": {
46
+ "actions": [
47
+ {
48
+ "actionType": "custom",
49
+ "script": "var spaceId = event.data.context.tenantId; var flowId = event.data.flowId; if(spaceId && flowId){ var timezoneoffset = new Date().getTimezoneOffset(); var url = Steedos.absoluteUrl('/api/workflow/export/instances?space_id=' + spaceId + '&flow_id=' + flowId + '&type=2&timezoneoffset=' + timezoneoffset); window.open(url, '_blank'); } else { window.toastr && window.toastr.warning('请先选择流程'); }"
50
+ }
51
+ ]
52
+ }
53
+ }
54
+ },
55
+ {
56
+ "type": "button",
57
+ "label": "所有",
58
+ "onEvent": {
59
+ "click": {
60
+ "actions": [
61
+ {
62
+ "actionType": "custom",
63
+ "script": "var spaceId = event.data.context.tenantId; var flowId = event.data.flowId; if(spaceId && flowId){ var timezoneoffset = new Date().getTimezoneOffset(); var url = Steedos.absoluteUrl('/api/workflow/export/instances?space_id=' + spaceId + '&flow_id=' + flowId + '&type=3&timezoneoffset=' + timezoneoffset); window.open(url, '_blank'); } else { window.toastr && window.toastr.warning('请先选择流程'); }"
64
+ }
65
+ ]
66
+ }
67
+ }
68
+ }
69
+ ]
70
+ }
71
+ ],
72
+ "regions": [
73
+ "body"
74
+ ],
75
+ "bodyClassName": "p-0",
76
+ "id": "u:instance_export_service"
77
+ }
78
+ is_enable: true
79
+ label: 导出
80
+ 'on': list
81
+ type: amis_button
82
+ visible: true
83
+ sort: 900
@@ -11,8 +11,8 @@ const express = require('express');
11
11
  const router = express.Router();
12
12
  const { requireAuthentication } = require("@steedos/auth");
13
13
  const WorkflowManager = require('../manager/workflow_manager');
14
+ const { getCollection } = require('../utils/collection');
14
15
  const _ = require('underscore');
15
- const Fiber = function(fun){console.log('TODO Fiber...')}
16
16
  const moment = require('moment')
17
17
  const fs = require('fs')
18
18
  const path = require('path')
@@ -35,160 +35,105 @@ const path = require('path')
35
35
  */
36
36
  router.get('/api/workflow/export/instances', requireAuthentication, async function (req, res) {
37
37
  try {
38
- let userSession = req.user;
39
- const spaceId = userSession.spaceId;
38
+ const userSession = req.user;
40
39
  const userId = userSession.userId;
41
- const isSpaceAdmin = userSession.is_space_admin;
42
- Fiber(async function () {
43
- try {
44
- var ejs, end_date, fields, fileName, flow, flow_id, flow_ids, form, form_name, formatDate, ins_to_xls, lang, last_month_date, now, query, ret, selector, space, space_id, start_date, str, table_fields, template, timezoneoffset, type, uid, utcOffset;
45
- query = req.query;
46
- space_id = query.space_id;
47
- flow_id = query.flow_id;
48
- type = parseInt(query.type);
49
- timezoneoffset = parseInt(query.timezoneoffset);
50
- flow = db.flows.findOne({
51
- _id: flow_id
52
- }, {
53
- fields: {
54
- form: 1
55
- }
56
- });
57
- form = db.forms.findOne({
58
- _id: flow.form
59
- }, {
60
- fields: {
61
- name: 1,
62
- 'current.fields': 1
63
- }
64
- });
65
- form_name = form.name;
66
- fields = form.current.fields;
67
- table_fields = new Array;
68
- _.each(form.current.fields, function (field) {
69
- if (field.type === "table") {
70
- return table_fields.push(field);
71
- }
72
- });
73
- ins_to_xls = new Array;
74
- start_date = null;
75
- end_date = null;
76
- now = new Date;
77
- selector = {
78
- space: space_id,
79
- flow: flow_id
80
- };
81
- selector.state = {
82
- $in: ["pending", "completed"]
83
- };
84
- uid = userId;
85
- space = db.spaces.findOne({_id: space_id});
86
- if (!space) {
87
- selector.state = "none";
88
- }
89
- if (!space.admins.includes(uid)) {
90
- flow_ids = WorkflowManager.getMyAdminOrMonitorFlows(space_id, uid);
91
- if (!flow_ids.includes(selector.flow)) {
92
- selector.$or = [
93
- {
94
- submitter: uid
95
- },
96
- {
97
- applicant: uid
98
- },
99
- {
100
- inbox_users: uid
101
- },
102
- {
103
- outbox_users: uid
104
- }
105
- ];
106
- }
107
- }
108
- // 0-本月
109
- if (type === 0) {
110
- start_date = new Date(now.getFullYear(), now.getMonth(), 1);
111
- selector.submit_date = {
112
- $gte: start_date
113
- };
114
- ins_to_xls = db.instances.find(selector, {
115
- sort: {
116
- submit_date: 1
117
- }
118
- }).fetch();
119
- // 1-上月
120
- } else if (type === 1) {
121
- last_month_date = new Date(new Date(now.getFullYear(), now.getMonth(), 1) - 1000 * 60 * 60 * 24);
122
- start_date = new Date(last_month_date.getFullYear(), last_month_date.getMonth(), 1);
123
- end_date = new Date(now.getFullYear(), now.getMonth(), 1);
124
- selector.submit_date = {
125
- $gte: start_date,
126
- $lte: end_date
127
- };
128
- ins_to_xls = db.instances.find(selector, {
129
- sort: {
130
- submit_date: 1
131
- }
132
- }).fetch();
133
- // 2-整个年度
134
- } else if (type === 2) {
135
- start_date = new Date(now.getFullYear(), 0, 1);
136
- selector.submit_date = {
137
- $gte: start_date
138
- };
139
- ins_to_xls = db.instances.find(selector, {
140
- sort: {
141
- submit_date: 1
142
- }
143
- }).fetch();
144
- // 3-所有
145
- } else if (type === 3) {
146
- ins_to_xls = db.instances.find(selector, {
147
- sort: {
148
- submit_date: 1
149
- }
150
- }).fetch();
151
- }
152
- ejs = require('ejs');
153
- str = fs.readFileSync(path.resolve(__dirname, '../server/ejs/export_instances.ejs'), 'utf8');
154
- // 检测是否有语法错误
155
- // ejsLint = require('ejs-lint')
156
- // if ejsLint.lint
157
- // error_obj = ejsLint.lint(str, {})
158
- // else
159
- // error_obj = ejsLint(str, {})
160
- // if error_obj
161
- // console.error "===/api/workflow/export:"
162
- // console.error error_obj
163
- template = ejs.compile(str);
164
- lang = 'en';
165
- if (userSession.locale === 'zh-cn') {
166
- lang = 'zh-CN';
167
- }
168
- utcOffset = timezoneoffset / -60;
169
- formatDate = function (date, formater) {
170
- return moment(date).utcOffset(utcOffset).format(formater);
171
- };
172
- ret = template({
173
- lang: lang,
174
- formatDate: formatDate,
175
- form_name: form_name,
176
- fields: fields,
177
- table_fields: table_fields,
178
- ins_to_xls: ins_to_xls
179
- });
180
- fileName = "SteedOSWorkflow_" + moment().format('YYYYMMDDHHmm') + ".xls";
181
- res.setHeader("Content-type", "application/octet-stream");
182
- res.setHeader("Content-Disposition", "attachment;filename=" + encodeURI(fileName));
183
- return res.end(ret);
184
- } catch (e) {
185
- console.error(e);
186
- res.status(200).send({
187
- errors: [{ errorMessage: e.message }]
188
- });
40
+ const query = req.query;
41
+ const space_id = query.space_id;
42
+ const flow_id = query.flow_id;
43
+ const type = parseInt(query.type);
44
+ const timezoneoffset = parseInt(query.timezoneoffset);
45
+
46
+ const flowsCollection = await getCollection('flows');
47
+ const formsCollection = await getCollection('forms');
48
+ const spacesCollection = await getCollection('spaces');
49
+ const instancesCollection = await getCollection('instances');
50
+
51
+ const flow = await flowsCollection.findOne(
52
+ { _id: flow_id },
53
+ { projection: { form: 1 } }
54
+ );
55
+ const form = await formsCollection.findOne(
56
+ { _id: flow.form },
57
+ { projection: { name: 1, 'current.fields': 1 } }
58
+ );
59
+ const form_name = form.name;
60
+ const fields = form.current.fields;
61
+ const table_fields = [];
62
+ _.each(fields, function (field) {
63
+ if (field.type === "table") {
64
+ table_fields.push(field);
189
65
  }
190
- }).run()
66
+ });
67
+
68
+ let ins_to_xls = [];
69
+ const now = new Date();
70
+ const selector = {
71
+ space: space_id,
72
+ flow: flow_id,
73
+ state: { $in: ["pending", "completed"] }
74
+ };
75
+
76
+ const uid = userId;
77
+ const space = await spacesCollection.findOne({ _id: space_id });
78
+ if (!space) {
79
+ selector.state = "none";
80
+ }
81
+ if (space && !space.admins.includes(uid)) {
82
+ const flow_ids = await WorkflowManager.getMyAdminOrMonitorFlows(space_id, uid);
83
+ if (!flow_ids.includes(flow_id)) {
84
+ selector.$or = [
85
+ { submitter: uid },
86
+ { applicant: uid },
87
+ { inbox_users: uid },
88
+ { outbox_users: uid }
89
+ ];
90
+ }
91
+ }
92
+
93
+ // 0-本月
94
+ if (type === 0) {
95
+ const start_date = new Date(now.getFullYear(), now.getMonth(), 1);
96
+ selector.submit_date = { $gte: start_date };
97
+ // 1-上月
98
+ } else if (type === 1) {
99
+ const last_month_date = new Date(new Date(now.getFullYear(), now.getMonth(), 1) - 1000 * 60 * 60 * 24);
100
+ const start_date = new Date(last_month_date.getFullYear(), last_month_date.getMonth(), 1);
101
+ const end_date = new Date(now.getFullYear(), now.getMonth(), 1);
102
+ selector.submit_date = { $gte: start_date, $lte: end_date };
103
+ // 2-整个年度
104
+ } else if (type === 2) {
105
+ const start_date = new Date(now.getFullYear(), 0, 1);
106
+ selector.submit_date = { $gte: start_date };
107
+ }
108
+ // 3-所有: 不加 submit_date 过滤
109
+
110
+ ins_to_xls = await instancesCollection.find(selector).sort({ submit_date: 1 }).toArray();
111
+
112
+ const ejs = require('ejs');
113
+ const str = fs.readFileSync(path.resolve(__dirname, '../server/ejs/export_instances.ejs'), 'utf8');
114
+ const template = ejs.compile(str);
115
+ let lang = 'en';
116
+ if (userSession.locale === 'zh-cn') {
117
+ lang = 'zh-CN';
118
+ }
119
+ const utcOffset = timezoneoffset / -60;
120
+ const formatDate = function (date, formater) {
121
+ return moment(date).utcOffset(utcOffset).format(formater);
122
+ };
123
+ const ret = template({
124
+ lang: lang,
125
+ formatDate: formatDate,
126
+ form_name: form_name,
127
+ fields: fields,
128
+ table_fields: table_fields,
129
+ ins_to_xls: ins_to_xls
130
+ });
131
+ const fileName = "SteedOSWorkflow_" + moment().format('YYYYMMDDHHmm') + ".xls";
132
+ res.setHeader("Content-type", "application/octet-stream");
133
+ res.setHeader("Content-Disposition", "attachment;filename=" + encodeURI(fileName));
134
+ return res.end(ret);
191
135
  } catch (e) {
136
+ console.error(e);
192
137
  res.status(200).send({
193
138
  errors: [{ errorMessage: e.message }]
194
139
  });