owl-cli 6.54.0 → 6.55.0

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.
@@ -32,9 +32,6 @@ var spec = @spec;
32
32
  var exportKey = params.exportKey;
33
33
  env.exportKey = exportKey;
34
34
 
35
-
36
-
37
-
38
35
  function getKeywordQuery(){
39
36
  if(keyword && trim(keyword).length>0){
40
37
  return "\"" + trim(keyword) + "\""
@@ -0,0 +1,51 @@
1
+ //#import Util.js
2
+ //#import session.js
3
+ //#import $@projectCode:services/modelService.jsx
4
+ //#import jobs.js
5
+ //#import @handlers/include/checklogin.jsx
6
+ //#import $owl_task_info:services/modelService.jsx
7
+
8
+ function main(){
9
+ var env = checklogin();
10
+ if(!env){
11
+ return;
12
+ }
13
+ if(!env.loginId){
14
+ //没有登录
15
+ return;
16
+ }
17
+ var shopId = env.shopId;
18
+
19
+
20
+ var params = JSON.parse($body);
21
+ var ids = params.ids;
22
+ var templateId = params.templateId;
23
+
24
+ var now = new Date().getTime();
25
+
26
+ var taskInfo = {
27
+ submitDate: now,
28
+ appId:'@projectCode',
29
+ pageId:'tasks/exportWithTemplateTask.jsx',
30
+ state:'notstart',
31
+ params:JSON.stringify({
32
+ ids:ids,
33
+ templateId:templateId
34
+ })
35
+ };
36
+ var taskInfoId = owl_task_infoService.add(taskInfo);
37
+ var taskId = JobsService.submitExportTask('@projectCode', 'tasks/exportWithTemplateTask.jsx',{
38
+ ids:ids,
39
+ templateId:templateId,
40
+ taskInfoId:taskInfoId,
41
+ taskId:taskId
42
+ },now);
43
+
44
+ var ret = {
45
+ state:'ok',
46
+ taskInfoId : taskId
47
+ }
48
+
49
+ out.print(JSON.stringify(ret));
50
+ }
51
+ main();
@@ -0,0 +1,110 @@
1
+ //#import $@projectCode:services/modelService.jsx
2
+ //#import moment.min.js
3
+ //#import excel.js
4
+ //#import $owl_excel_templates:services/modelService.jsx
5
+ //#import $owl_task_info:services/modelService.jsx
6
+ //#import file.js
7
+
8
+ var formSpecs = @formSpecs;
9
+
10
+ function tranverseFields(formSpec, callback, ctx){
11
+ formSpec.fields.forEach( function(field){
12
+ if (field[ '_ft' ] == 'field') {
13
+ callback( field, ctx );
14
+ }
15
+ else if (field[ '_ft' ] == 'subform') {
16
+ var context = { parentField: field }
17
+ tranverseFields( field, callback, context );
18
+ }
19
+ else if (field[ '_ft' ] == 'array') {
20
+ var context = { parentField: field }
21
+ tranverseFields( field, callback, context )
22
+ }
23
+ } );
24
+ }
25
+
26
+ function normalizeValue(value,spec){
27
+ if(value == null){
28
+ return null;
29
+ }
30
+ switch (spec.fieldType){
31
+ case 'string':
32
+ return 's'+value;
33
+ case 'number':
34
+ return 'n' + value;
35
+ case 'date':
36
+ return 'd'+ moment(value).toDate().getTime();
37
+ case 'choice':
38
+ for(var i=0; i<spec.options.length; i++){
39
+ var option = spec.options[i];
40
+ if(option[0]==value){
41
+ return 's'+option[1];
42
+ }
43
+ }
44
+ return 's'+value;
45
+ default:
46
+ return "s"+value;
47
+ }
48
+ }
49
+
50
+ function getExportDoc(obj){
51
+ tranverseFields(formSpecs,function(f,ctx){
52
+ if (ctx.parentField && ctx.parentField._ft == 'array') {
53
+ var items = @projectCodeService.getValue( ctx.parentField.key, obj )
54
+ if(items){
55
+ for(var i=0; i<items.length; i++){
56
+ var item = items[i];
57
+ var value = item[f.origKey];
58
+ value = normalizeValue(value,f);
59
+ item[f.origKey] = value;
60
+ }
61
+ }
62
+ }
63
+ else{
64
+ var value = @projectCodeService.getValue( f.key, obj );
65
+ value = normalizeValue(value,f);
66
+ @projectCodeService.setValue(f.key,value,obj);
67
+ }
68
+ },{});
69
+ return obj;
70
+ }
71
+
72
+
73
+ (function(){
74
+ var template = owl_excel_templatesService.get(templateId);
75
+ if(!template || template.template && template.template.length>0){
76
+ $.log("没有配置模版")
77
+ return null;
78
+ }
79
+ var taskInfo = owl_task_infoService.get(taskInfoId);
80
+ taskInfo.state = "running";
81
+ taskInfo.beginDate = new Date().getTime();
82
+ taskInfo.taskId = taskId;
83
+ owl_task_infoService.update(taskInfo);
84
+ var doc = @projectCodeService.get(id);
85
+ var exportDoc = getExportDoc(doc);
86
+ // var templateExcelUrl = "@{@projectCode.xlsx}@";
87
+ var templateUrl = template.template[0].url;
88
+ var fileId = Excel.generateExcelFromTemplate( templateUrl, exportDoc );
89
+ if(template.toField){
90
+ var doc = @projectCodeService.get(id);
91
+ var url = FileService.getFullPath(fileId);
92
+ doc[template.toField] = {
93
+ url:url,
94
+ fileId:fileId
95
+ }
96
+ @projectCodeService.update(doc);
97
+ }
98
+
99
+ var taskInfo = owl_task_infoService.get(taskInfoId);
100
+ taskInfo.state = "success";
101
+ taskInfo.percent = 100;
102
+ taskInfo.fileId = fileId;
103
+ taskInfo.endDate = new Date().getTime();
104
+ taskInfo.state = "succeeded";
105
+ taskInfo.msg = "生成Excel文件成功";
106
+ taskInfo.fileId = fileId;
107
+
108
+ owl_task_infoService.update(taskInfo);
109
+ })();
110
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owl-cli",
3
- "version": "6.54.0",
3
+ "version": "6.55.0",
4
4
  "main": "index.js",
5
5
  "preferGlobal": true,
6
6
  "bin": {