|
@@ -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
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|