فهرست منبع

打印框架加载数据集

zhoucg 1 سال پیش
والد
کامیت
502388d83e
1فایلهای تغییر یافته به همراه53 افزوده شده و 0 حذف شده
  1. 53 0
      src/api/CommonApi.ts

+ 53 - 0
src/api/CommonApi.ts

@@ -0,0 +1,53 @@
+import {request} from "@/utils/request";
+import ApiUrlConstant from "@/api/ApiUrlConstant";
+
+export default class CommonApi {
+
+    private static getContextPath() {
+        return '';
+    }
+
+    public static request<T = any>(url: string, args: any = {}): Promise<T> {
+        return request.invoke(CommonApi.getContextPath() + url, [args], {
+            headers: {
+                'Accept': 'application/json, */*',
+                'Content-Type': 'application/json',
+                'cache': 'default',
+                'x-ajax': 'true'
+            }
+        })
+    }
+
+    public static invoke<T = any>(url: string, args: any = {}, config?: any): Promise<T> {
+        return request.invoke(CommonApi.getContextPath() + url, [args], config)
+    }
+
+    /**
+     * 获取资源信息
+     * @param resourceId
+     */
+    public static async getResourceById(resourceId) {
+        const params = {pageCode: resourceId};
+        return CommonApi.request(ApiUrlConstant.getResourceByIdUrl, params);
+    }
+
+    /**
+     * 预览模板
+     * @param templateJson
+     * @param templateParams
+     * @param callback
+     */
+    public static async previewTemplate(templateJson, templateParams, callback) {
+        const params = {templateJson, ...templateParams}
+        return CommonApi.invoke(ApiUrlConstant.previewTemplateUrl, params, {
+            headers: {
+                'Accept': 'application/json, */*',
+                'Content-Type': 'application/json',
+                'cache': 'default',
+                'x-ajax': 'true'
+            },
+            'responseType': 'blob',
+            afterResponse: callback
+        });
+    }
+}