Browse Source

fix(mkl): parse successful preview response correctly

malk 3 weeks ago
parent
commit
724e51ac2e
1 changed files with 20 additions and 1 deletions
  1. 20 1
      src/sample/mkl.js

+ 20 - 1
src/sample/mkl.js

@@ -66,6 +66,25 @@ async function _postRaw (url, params = {}, body = {}) {
   return response && response.data;
 }
 
+/**
+ * 调用宜搭图片生成接口并保留 ApiResponse 外层结构。
+ * 该接口返回 success/message/data,不使用合同确认接口的 code/data 结构。
+ * @param {string} url 请求地址
+ * @param {Object} body 请求参数
+ * @returns {Promise<Object>} 宜搭图片生成响应
+ */
+async function _postYidaEnvelope (url, body = {}) {
+  const response = await mjs.request.xhr.doPost(url, {}, body, {
+    ..._requestConfig(),
+    ignoreResponse: true,
+  });
+  const result = response && response.data;
+  if (!result || result.success !== true) {
+    throw new Error(result && (result.message || result.msg) || "合同生成接口调用失败");
+  }
+  return result;
+}
+
 function _componentValue (componentId) {
   if (!componentId) return "";
   const component = _page().$(componentId);
@@ -194,7 +213,7 @@ export default {
       dingUid: options.dingUid || page.utils.getLoginUserId(),
       corpId: options.corpId || "",
     };
-    const result = await _post("/api/yida/subform-to-image", body);
+    const result = await _postYidaEnvelope("/api/yida/subform-to-image", body);
     const fileUrl = result && (result.message || result.downloadUrl || result.fileUrl || result.url);
     if (fileUrl && ids.previewFrame) _page().$(ids.previewFrame).set("src", fileUrl);
     if (fileUrl && ids.previewSection) _page().$(ids.previewSection).setBehavior("NORMAL");