Просмотр исходного кода

feat: export report with fetch

ryanemax 7 месяцев назад
Родитель
Сommit
2889a5d237

+ 29 - 4
projects/textbook/src/services/textbook.ts

@@ -9,7 +9,9 @@ export class textbookServer {
   company: string = localStorage.getItem('company')!;
   theme: boolean = false; //深色主题模式
   profile: any = JSON.parse(localStorage.getItem('profile')!);
-  constructor() {}
+  constructor(
+    private http:HttpClient
+  ) {}
   authMobile(mobile: string): boolean {
     let a = /^1[3456789]\d{9}$/;
     if (!String(mobile).match(a)) {
@@ -160,10 +162,33 @@ export class textbookServer {
   //     }
   //   }
 }
-tbookExportReport(options:{processId?:string,bookList?:any[]}){
+async tbookExportReport(options:{processId?:string,bookList?:any[]}){
 
-
-  // return
+  let url = Parse.serverURL + "/api/tbook/export"
+  // console.log(url)
+  let response = await fetch(url, {
+    method: 'POST',
+    headers: {
+        'Content-Type': 'application/json',
+        'X-Parse-Application-Id': 'edu-textbook'
+    },
+    body: JSON.stringify(options)
+  })
+  let result = await response.json()
+  let zipUrl = result?.result?.zipUrl;
+  if(result?.code==200){
+    zipUrl = zipUrl.replaceAll("http://","https://");
+    const a = document.createElement('a'); // 创建一个<a>元素
+    a.href = zipUrl; // 设置链接的href属性为要下载的文件的URL
+    a.download = '报送流程'; // 设置下载文件的名称
+    document.body.appendChild(a); // 将<a>元素添加到文档中
+    a.click(); // 模拟点击<a>元素
+    document.body.removeChild(a); // 下载后移除<a>元素
+  }
+  // console.log(result)
+  return result
+ 
+  
   Parse.Cloud.run('tbookExportReport', options).then(
     (data) => {
       console.log(data);

+ 1 - 0
server/cloud/tbook/func-tbook-export.js

@@ -15,6 +15,7 @@ if(!fs.existsSync(TemplateDocxPath)){
  curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "processId": "FR7KZtefyR" }' http://127.0.0.1:61337/parse/functions/tbookExportReport
  curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "processId": "FR7KZtefyR" }' http://8.140.98.43/parse/functions/tbookExportReport
  curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "processId": "FR7KZtefyR" }' http://8.140.98.43/parse/api/tbook/export
+ curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "processId": "FR7KZtefyR" }' https://145.tbook.com.cn/parse/api/tbook/export
  导出教材列表
  curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "bookList": ["9V575dapEM","2YBKitpCJL","xLdiEaHGrX"] }' http://8.140.98.43/parse/functions/tbookExportReport
  */