mp_addChk.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta
  6. name="viewport"
  7. content="width=device-width, initial-scale=1.0, user-scalable=no"
  8. />
  9. <title>审核</title>
  10. <script src="/js/mp_base/base.js"></script>
  11. <style>
  12. [v-cloak] {
  13. display: none !important;
  14. }
  15. #app {
  16. background: #f5f5f5;
  17. height: 100vh;
  18. display: flex;
  19. flex-direction: column;
  20. overflow: hidden;
  21. box-sizing: border-box;
  22. }
  23. .frame-wrap {
  24. flex: 1;
  25. display: flex;
  26. flex-direction: column;
  27. overflow: hidden;
  28. }
  29. .top-iframe,
  30. .bottom-iframe {
  31. width: 100%;
  32. border: none;
  33. display: block;
  34. background: #fff;
  35. }
  36. .top-iframe {
  37. flex: none;
  38. height: 60%;
  39. }
  40. .bottom-iframe {
  41. flex: none;
  42. height: 40%;
  43. }
  44. .status-wrap {
  45. flex: 1;
  46. display: flex;
  47. align-items: center;
  48. justify-content: center;
  49. padding: 16px;
  50. box-sizing: border-box;
  51. }
  52. .status-card {
  53. width: 100%;
  54. max-width: 520px;
  55. background: #fff;
  56. border-radius: 8px;
  57. padding: 16px;
  58. box-sizing: border-box;
  59. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  60. }
  61. .status-title {
  62. font-size: 15px;
  63. font-weight: 600;
  64. color: #2d3748;
  65. }
  66. .status-text {
  67. margin-top: 8px;
  68. line-height: 1.6;
  69. color: #4a5568;
  70. font-size: 13px;
  71. word-break: break-all;
  72. }
  73. .status-retry {
  74. margin-top: 12px;
  75. height: 34px;
  76. padding: 0 14px;
  77. border: none;
  78. border-radius: 4px;
  79. background: #4a5568;
  80. color: #fff;
  81. font-size: 13px;
  82. }
  83. .url-log-fab {
  84. position: fixed;
  85. right: 12px;
  86. bottom: 72px;
  87. z-index: 1200;
  88. border: none;
  89. border-radius: 16px;
  90. background: rgba(36, 40, 53, 0.88);
  91. color: #fff;
  92. font-size: 12px;
  93. line-height: 1;
  94. padding: 8px 10px;
  95. display: none;
  96. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  97. }
  98. .url-log-panel {
  99. position: fixed;
  100. left: 12px;
  101. right: 12px;
  102. bottom: 116px;
  103. z-index: 1200;
  104. background: rgba(36, 40, 53, 0.96);
  105. color: #fff;
  106. border-radius: 8px;
  107. padding: 10px;
  108. max-height: 42vh;
  109. overflow: auto;
  110. box-sizing: border-box;
  111. }
  112. .url-log-panel__head {
  113. display: flex;
  114. align-items: center;
  115. justify-content: space-between;
  116. margin-bottom: 8px;
  117. font-size: 12px;
  118. }
  119. .url-log-panel__close {
  120. border: none;
  121. background: transparent;
  122. color: #fff;
  123. font-size: 14px;
  124. line-height: 1;
  125. }
  126. .url-log-panel__body {
  127. margin: 0;
  128. white-space: pre-wrap;
  129. word-break: break-all;
  130. font-size: 12px;
  131. line-height: 1.5;
  132. }
  133. </style>
  134. </head>
  135. <body>
  136. <div id="app" v-cloak>
  137. <div class="frame-wrap" v-if="initStatus === 'ready'">
  138. <iframe
  139. ref="topIframe"
  140. class="top-iframe"
  141. :src="topIframeSrc"
  142. frameborder="0"
  143. :style="topIframeHeight > 0 ? { height: `${topIframeHeight}px` } : null"
  144. ></iframe>
  145. <iframe
  146. ref="bottomIframe"
  147. class="bottom-iframe"
  148. :src="bottomIframeSrc"
  149. frameborder="0"
  150. :style="bottomIframeHeight > 0 ? { height: `${bottomIframeHeight}px` } : null"
  151. ></iframe>
  152. </div>
  153. <div class="status-wrap" v-else>
  154. <div class="status-card">
  155. <div class="status-title">{{ initStatusTitle }}</div>
  156. <div class="status-text">{{ initStatusMessage }}</div>
  157. <div class="status-text" v-if="missingParams.length > 0">
  158. 缺少参数:{{ missingParams.join('、') }}
  159. </div>
  160. <button class="status-retry" type="button" @click="callApi">
  161. 重新加载
  162. </button>
  163. </div>
  164. </div>
  165. <ss-bottom
  166. :buttons="bottomButtons"
  167. :show-shyj="true"
  168. @button-click="handleBottomAction"
  169. :disabled="submitting"
  170. v-if="initStatus === 'ready' && bottomButtons.length > 0"
  171. ></ss-bottom>
  172. <button class="url-log-fab" type="button" @click="showCurrentUrls">
  173. URL
  174. </button>
  175. <div class="url-log-panel" v-if="urlLogVisible">
  176. <div class="url-log-panel__head">
  177. <span>当前 URL</span>
  178. <button
  179. class="url-log-panel__close"
  180. type="button"
  181. @click="urlLogVisible = false"
  182. >
  183. ×
  184. </button>
  185. </div>
  186. <pre class="url-log-panel__body">{{ urlLogText }}</pre>
  187. </div>
  188. </div>
  189. <script>
  190. window.SS.ready(function () {
  191. window.SS.dom.initializeFormApp({
  192. el: "#app",
  193. data() {
  194. return {
  195. pageParams: {},
  196. loading: false,
  197. submitting: false,
  198. jdmc: "",
  199. sqid: "",
  200. shid: "",
  201. ssObjName: "",
  202. ssObjId: "",
  203. initStatus: "loading",
  204. initStatusTitle: "页面初始化中",
  205. initStatusMessage: "正在加载审核数据,请稍候...",
  206. missingParams: [],
  207. topIframeSrc: "",
  208. bottomIframeSrc: "",
  209. infoData: null,
  210. agrAddData: null,
  211. rejAddData: null,
  212. bottomButtons: [],
  213. layoutCalculated: false,
  214. headerSectionHeight: 0,
  215. availableHeight: 0,
  216. topIframeHeight: 0,
  217. bottomIframeHeight: 0,
  218. bottomIframeMinHeight: 0,
  219. isExpanded: false,
  220. isDragging: false,
  221. dragStartY: 0,
  222. dragStartBottomHeight: 0,
  223. bottomBarHeight: 0,
  224. layoutObserver: null,
  225. bottomResizeObserver: null,
  226. dragRafId: 0,
  227. pendingDeltaY: 0,
  228. lastDragEndAt: 0,
  229. urlLogVisible: false,
  230. urlLogText: "",
  231. };
  232. },
  233. mounted() {
  234. this.pageParams = this.getUrlParams();
  235. window.addEventListener("message", this.handleIframeMessage);
  236. this.callApi();
  237. },
  238. beforeDestroy() {
  239. window.removeEventListener("message", this.handleIframeMessage);
  240. this.unbindLayoutObserver();
  241. if (this.dragRafId) {
  242. cancelAnimationFrame(this.dragRafId);
  243. this.dragRafId = 0;
  244. }
  245. },
  246. methods: {
  247. normalizeError(error) {
  248. return {
  249. message: (error && error.message) || String(error),
  250. stack: (error && error.stack) || "",
  251. response: (error && error.response) || null,
  252. data: (error && error.data) || null,
  253. };
  254. },
  255. getUrlParams() {
  256. const params = {};
  257. const aliasMap = {
  258. ssobjname: "ssObjName",
  259. ssobjid: "ssObjId",
  260. sqid: "sqid",
  261. shid: "shid",
  262. };
  263. const urlSearchParams = new URLSearchParams(
  264. window.location.search
  265. );
  266. for (const [rawKey, rawValue] of urlSearchParams) {
  267. const decodedValue = this.safeDecode(rawValue);
  268. params[rawKey] = decodedValue;
  269. const normalizedKey = aliasMap[String(rawKey).toLowerCase()];
  270. if (normalizedKey) {
  271. params[normalizedKey] = decodedValue;
  272. }
  273. }
  274. return params;
  275. },
  276. setInitStatus(status, title, message) {
  277. this.initStatus = status;
  278. this.initStatusTitle = title || "";
  279. this.initStatusMessage = message || "";
  280. },
  281. safeDecode(text) {
  282. if (text === undefined || text === null || text === "") return "";
  283. try {
  284. return decodeURIComponent(String(text));
  285. } catch (_) {
  286. return String(text);
  287. }
  288. },
  289. pickFirstValue(sources, keys) {
  290. const srcArr = Array.isArray(sources) ? sources : [];
  291. const keyArr = Array.isArray(keys) ? keys : [];
  292. for (let i = 0; i < srcArr.length; i += 1) {
  293. const src = srcArr[i];
  294. if (!src || typeof src !== "object") continue;
  295. for (let j = 0; j < keyArr.length; j += 1) {
  296. const key = keyArr[j];
  297. const value = src[key];
  298. if (value !== undefined && value !== null && value !== "") {
  299. return value;
  300. }
  301. }
  302. }
  303. return "";
  304. },
  305. extractTokenData(apiResponse) {
  306. const wantedKeys = [
  307. "sqid",
  308. "shid",
  309. "ssObjName",
  310. "ssObjId",
  311. "jdmc",
  312. ];
  313. const candidates = [
  314. apiResponse && apiResponse.data && apiResponse.data.ssData,
  315. apiResponse && apiResponse.ssData,
  316. apiResponse && apiResponse.data,
  317. apiResponse,
  318. ];
  319. let best = {};
  320. let bestScore = -1;
  321. candidates.forEach((item) => {
  322. if (!item || typeof item !== "object") return;
  323. let score = 0;
  324. wantedKeys.forEach((key) => {
  325. if (
  326. item[key] !== undefined &&
  327. item[key] !== null &&
  328. item[key] !== ""
  329. ) {
  330. score += 1;
  331. }
  332. });
  333. if (score > bestScore) {
  334. best = item;
  335. bestScore = score;
  336. }
  337. });
  338. return best;
  339. },
  340. resolveBusinessContext(apiResponse) {
  341. const tokenData = this.extractTokenData(apiResponse);
  342. const sources = [tokenData, this.pageParams];
  343. const resolvedObjId = String(
  344. this.pickFirstValue(sources, ["ssObjId", "ssobjid"]) || ""
  345. );
  346. return {
  347. sqid: String(this.pickFirstValue(sources, ["sqid"]) || ""),
  348. shid: String(this.pickFirstValue(sources, ["shid"]) || ""),
  349. ssObjName: String(
  350. this.pickFirstValue(sources, ["ssObjName", "ssobjname"]) || ""
  351. ),
  352. ssObjId: resolvedObjId,
  353. jdmc: this.safeDecode(
  354. this.pickFirstValue(sources, ["jdmc"]) || ""
  355. ),
  356. };
  357. },
  358. parseInfoParm(rawParm) {
  359. if (!rawParm) return {};
  360. if (typeof rawParm === "object") return rawParm;
  361. const text = String(rawParm).trim();
  362. if (!text) return {};
  363. try {
  364. return JSON.parse(text);
  365. } catch (_) {}
  366. try {
  367. const normalized = text
  368. .replace(/([{,]\s*)([A-Za-z0-9_]+)\s*:/g, '$1"$2":')
  369. .replace(/'/g, '"');
  370. return JSON.parse(normalized);
  371. } catch (_) {
  372. return {};
  373. }
  374. },
  375. resolveInfoDestPath(destName) {
  376. const raw = String(destName || "").trim();
  377. if (!raw) return "";
  378. if (/^https?:\/\//i.test(raw)) return raw;
  379. if (raw.startsWith("/")) return raw;
  380. if (raw.endsWith(".html")) return `/page/${raw}`;
  381. if (raw.startsWith("mp_")) return `/page/${raw}.html`;
  382. return `/page/mp_${raw}.html`;
  383. },
  384. buildInfoIframeSrc(infoData, fallbackQuery) {
  385. const conf =
  386. infoData && typeof infoData === "object" ? infoData : {};
  387. const serviceName = conf.service || conf.servName || "";
  388. const destName = conf.dest || "";
  389. const parmObj = this.parseInfoParm(conf.parm);
  390. const mergedQuery = {
  391. ...(fallbackQuery || {}),
  392. ...(parmObj || {}),
  393. };
  394. if (!serviceName || !destName) {
  395. return this.buildIframeSrc(
  396. "/page/mp_objInfo.html",
  397. mergedQuery
  398. );
  399. }
  400. const pagePath = this.resolveInfoDestPath(destName);
  401. if (!pagePath) {
  402. return this.buildIframeSrc(
  403. "/page/mp_objInfo.html",
  404. mergedQuery
  405. );
  406. }
  407. const paramText =
  408. typeof conf.parm === "string"
  409. ? conf.parm
  410. : JSON.stringify(parmObj || {});
  411. const iframeQuery = {
  412. ...mergedQuery,
  413. ssServ: serviceName,
  414. ssDest: destName,
  415. service: serviceName,
  416. dest: destName,
  417. param: paramText,
  418. };
  419. return this.buildIframeSrc(pagePath, iframeQuery);
  420. },
  421. buildIframeSrc(path, queryObj) {
  422. const search = new URLSearchParams(queryObj);
  423. return `${path}?${search.toString()}`;
  424. },
  425. buildCommonQuery() {
  426. return {
  427. sqid: this.sqid,
  428. shid: this.shid,
  429. ssObjName: this.ssObjName,
  430. ssObjId: this.ssObjId,
  431. };
  432. },
  433. initializeLayout() {
  434. this.$nextTick(() => {
  435. const bottomIframe = this.$refs.bottomIframe;
  436. if (!bottomIframe || !bottomIframe.contentWindow) return;
  437. const waitForHeaderSection = () => {
  438. try {
  439. const iframeDoc = bottomIframe.contentWindow.document;
  440. const headerSection =
  441. iframeDoc.querySelector(".header-section");
  442. if (!headerSection) {
  443. setTimeout(waitForHeaderSection, 120);
  444. return;
  445. }
  446. const headerHeight = headerSection.offsetHeight || 0;
  447. this.headerSectionHeight = headerHeight;
  448. this.bottomIframeMinHeight = Math.max(44, headerHeight);
  449. this.recalculateLayoutMetrics();
  450. if (!this.layoutCalculated) {
  451. this.bottomIframeHeight = this.bottomIframeMinHeight;
  452. this.topIframeHeight = Math.max(
  453. 0,
  454. this.availableHeight - this.bottomIframeHeight
  455. );
  456. } else {
  457. const currentBottom =
  458. this.bottomIframeHeight || this.bottomIframeMinHeight;
  459. this.bottomIframeHeight = Math.max(
  460. this.bottomIframeMinHeight,
  461. Math.min(currentBottom, this.availableHeight)
  462. );
  463. this.topIframeHeight = Math.max(
  464. 0,
  465. this.availableHeight - this.bottomIframeHeight
  466. );
  467. }
  468. this.layoutCalculated = true;
  469. this.applyIframeHeights();
  470. this.bindLayoutObserver();
  471. } catch (error) {
  472. setTimeout(waitForHeaderSection, 180);
  473. }
  474. };
  475. setTimeout(waitForHeaderSection, 80);
  476. });
  477. },
  478. recalculateLayoutMetrics() {
  479. const viewportHeight = window.innerHeight || 0;
  480. const bottomBar = document.querySelector("#app .ss-bottom");
  481. this.bottomBarHeight = bottomBar ? bottomBar.offsetHeight : 0;
  482. this.availableHeight = Math.max(
  483. 0,
  484. viewportHeight - this.bottomBarHeight
  485. );
  486. },
  487. handleLayoutResize() {
  488. if (!this.layoutCalculated) return;
  489. this.recalculateLayoutMetrics();
  490. const bottomActualHeight = Math.max(
  491. this.bottomIframeMinHeight,
  492. Math.min(
  493. this.bottomIframeHeight || this.bottomIframeMinHeight,
  494. this.availableHeight
  495. )
  496. );
  497. this.bottomIframeHeight = bottomActualHeight;
  498. this.topIframeHeight = Math.max(
  499. 0,
  500. this.availableHeight - bottomActualHeight
  501. );
  502. this.applyIframeHeights();
  503. },
  504. bindLayoutObserver() {
  505. if (!this.layoutObserver) {
  506. this.layoutObserver = () => this.handleLayoutResize();
  507. window.addEventListener("resize", this.layoutObserver);
  508. }
  509. if (
  510. !this.bottomResizeObserver &&
  511. typeof window.ResizeObserver === "function"
  512. ) {
  513. const bottomBar = document.querySelector("#app .ss-bottom");
  514. if (bottomBar) {
  515. this.bottomResizeObserver = new ResizeObserver(() => {
  516. this.handleLayoutResize();
  517. });
  518. this.bottomResizeObserver.observe(bottomBar);
  519. }
  520. }
  521. },
  522. unbindLayoutObserver() {
  523. if (this.layoutObserver) {
  524. window.removeEventListener("resize", this.layoutObserver);
  525. this.layoutObserver = null;
  526. }
  527. if (this.bottomResizeObserver) {
  528. this.bottomResizeObserver.disconnect();
  529. this.bottomResizeObserver = null;
  530. }
  531. },
  532. applyIframeHeights() {
  533. const topIframe = this.$refs.topIframe;
  534. const bottomIframe = this.$refs.bottomIframe;
  535. if (!topIframe || !bottomIframe) return;
  536. topIframe.style.height = `${this.topIframeHeight}px`;
  537. bottomIframe.style.height = `${this.bottomIframeHeight}px`;
  538. },
  539. applyIframeHeightsFast() {
  540. const topIframe = this.$refs.topIframe;
  541. const bottomIframe = this.$refs.bottomIframe;
  542. if (!topIframe || !bottomIframe) return;
  543. topIframe.style.height = `${this.topIframeHeight}px`;
  544. bottomIframe.style.height = `${this.bottomIframeHeight}px`;
  545. },
  546. calculateHeights(bottomHeight) {
  547. const bottomActualHeight = Math.max(
  548. this.bottomIframeMinHeight,
  549. Math.min(bottomHeight, this.availableHeight)
  550. );
  551. this.bottomIframeHeight = bottomActualHeight;
  552. this.topIframeHeight = Math.max(
  553. 0,
  554. this.availableHeight - bottomActualHeight
  555. );
  556. this.applyIframeHeights();
  557. },
  558. toggleExpand() {
  559. if (!this.layoutCalculated || this.isDragging) return;
  560. if (Date.now() - this.lastDragEndAt < 180) return;
  561. this.isExpanded = !this.isExpanded;
  562. if (this.isExpanded) {
  563. this.calculateHeights(this.availableHeight);
  564. } else {
  565. this.calculateHeights(this.bottomIframeMinHeight);
  566. }
  567. },
  568. handleIframeMessage(event) {
  569. if (event.origin !== window.location.origin) return;
  570. const payload = event.data || {};
  571. const { type, data } = payload;
  572. if (type === "header-section-click") {
  573. this.toggleExpand();
  574. return;
  575. }
  576. if (type === "header-section-drag-start") {
  577. this.handleDragStart(data || {});
  578. return;
  579. }
  580. if (type === "header-section-drag-move") {
  581. this.handleDragMove((data && data.deltaY) || 0);
  582. return;
  583. }
  584. if (type === "header-section-drag-end") {
  585. this.handleDragEnd();
  586. }
  587. },
  588. handleDragStart(data) {
  589. if (!this.layoutCalculated) return;
  590. this.isDragging = true;
  591. this.dragStartY = Number(data && data.startY) || 0;
  592. this.dragStartBottomHeight = this.bottomIframeHeight;
  593. this.pendingDeltaY = 0;
  594. if (this.dragRafId) {
  595. cancelAnimationFrame(this.dragRafId);
  596. this.dragRafId = 0;
  597. }
  598. },
  599. handleDragMove(deltaY) {
  600. if (!this.isDragging || !this.layoutCalculated) return;
  601. this.pendingDeltaY = Number(deltaY || 0);
  602. if (this.dragRafId) return;
  603. this.dragRafId = requestAnimationFrame(() => {
  604. this.dragRafId = 0;
  605. const nextBottomHeight =
  606. this.dragStartBottomHeight - this.pendingDeltaY;
  607. const bottomActualHeight = Math.max(
  608. this.bottomIframeMinHeight,
  609. Math.min(nextBottomHeight, this.availableHeight)
  610. );
  611. this.bottomIframeHeight = bottomActualHeight;
  612. this.topIframeHeight = Math.max(
  613. 0,
  614. this.availableHeight - bottomActualHeight
  615. );
  616. this.applyIframeHeightsFast();
  617. });
  618. },
  619. handleDragEnd() {
  620. this.isDragging = false;
  621. this.dragStartY = 0;
  622. this.dragStartBottomHeight = 0;
  623. this.pendingDeltaY = 0;
  624. this.lastDragEndAt = Date.now();
  625. if (this.dragRafId) {
  626. cancelAnimationFrame(this.dragRafId);
  627. this.dragRafId = 0;
  628. }
  629. this.applyIframeHeights();
  630. },
  631. async callApi() {
  632. this.loading = true;
  633. this.infoData = null;
  634. this.agrAddData = null;
  635. this.rejAddData = null;
  636. this.bottomButtons = [];
  637. this.topIframeSrc = "";
  638. this.bottomIframeSrc = "";
  639. this.missingParams = [];
  640. this.setInitStatus(
  641. "loading",
  642. "页面初始化中",
  643. "正在加载审核数据,请稍候..."
  644. );
  645. let apiResponse = null;
  646. try {
  647. if (this.pageParams.ssToken) {
  648. const tokenUrl = `/service?ssToken=${this.pageParams.ssToken}`;
  649. apiResponse = await request.post(
  650. tokenUrl,
  651. {},
  652. { loading: false }
  653. );
  654. }
  655. const context = this.resolveBusinessContext(apiResponse);
  656. this.sqid = context.sqid;
  657. this.shid = context.shid;
  658. this.ssObjName = context.ssObjName;
  659. this.ssObjId = context.ssObjId;
  660. this.jdmc = context.jdmc || "";
  661. const requiredKeys = ["sqid", "shid", "ssObjId"];
  662. this.missingParams = requiredKeys.filter((key) => !this[key]);
  663. const query = this.buildCommonQuery();
  664. const infoUrl = `/service?ssServ=dataTag&ssDest=data&name=info&ssObjName=${encodeURIComponent(
  665. this.ssObjName
  666. )}&ssObjId=${encodeURIComponent(
  667. this.ssObjId
  668. )}&sqid=${encodeURIComponent(
  669. this.sqid
  670. )}&shid=${encodeURIComponent(this.shid)}`;
  671. const infoRes = await request.post(
  672. infoUrl,
  673. {},
  674. { loading: false, formData: true }
  675. );
  676. this.infoData =
  677. infoRes && infoRes.data ? infoRes.data.info : null;
  678. this.topIframeSrc = this.buildInfoIframeSrc(
  679. this.infoData,
  680. query
  681. );
  682. this.bottomIframeSrc = this.buildIframeSrc(
  683. "/page/mp_shList.html",
  684. query
  685. );
  686. this.setInitStatus("ready", "页面已就绪", "审核数据加载完成");
  687. this.$nextTick(() => {
  688. this.initializeLayout();
  689. });
  690. const agrUrl = `/service?ssServ=dataTag&ssDest=data&name=agrAdd&ssObjName=${encodeURIComponent(
  691. this.ssObjName
  692. )}&ssObjId=${encodeURIComponent(
  693. this.ssObjId
  694. )}&sqid=${encodeURIComponent(
  695. this.sqid
  696. )}&shid=${encodeURIComponent(this.shid)}`;
  697. const dataTagRes = await request.post(
  698. agrUrl,
  699. {},
  700. { loading: false, formData: true }
  701. );
  702. const rejUrl = `/service?ssServ=dataTag&ssDest=data&name=rejAdd&ssObjName=${encodeURIComponent(
  703. this.ssObjName
  704. )}&ssObjId=${encodeURIComponent(
  705. this.ssObjId
  706. )}&sqid=${encodeURIComponent(
  707. this.sqid
  708. )}&shid=${encodeURIComponent(this.shid)}`;
  709. const dataTagResRej = await request.post(
  710. rejUrl,
  711. {},
  712. { loading: false, formData: true }
  713. );
  714. this.agrAddData =
  715. dataTagRes && dataTagRes.data ? dataTagRes.data.agrAdd : null;
  716. this.rejAddData =
  717. dataTagResRej && dataTagResRej.data
  718. ? dataTagResRej.data.rejAdd
  719. : null;
  720. if (
  721. this.agrAddData &&
  722. !this.agrAddData.service &&
  723. this.agrAddData.servName
  724. ) {
  725. this.agrAddData.service = this.agrAddData.servName;
  726. }
  727. if (
  728. this.rejAddData &&
  729. !this.rejAddData.service &&
  730. this.rejAddData.servName
  731. ) {
  732. this.rejAddData.service = this.rejAddData.servName;
  733. }
  734. const btns = [];
  735. if (
  736. this.rejAddData &&
  737. this.rejAddData.service &&
  738. this.rejAddData.dest
  739. ) {
  740. btns.push({ text: "退回", action: "reject" });
  741. }
  742. if (
  743. this.agrAddData &&
  744. this.agrAddData.service &&
  745. this.agrAddData.dest
  746. ) {
  747. btns.push({ text: "同意", action: "agree" });
  748. }
  749. this.bottomButtons = btns;
  750. this.$nextTick(() => {
  751. this.initializeLayout();
  752. });
  753. } catch (error) {
  754. const normalized = this.normalizeError(error);
  755. this.setInitStatus(
  756. "error",
  757. "页面初始化失败",
  758. normalized.message || "页面初始化失败,请稍后重试"
  759. );
  760. console.error("[mp_addChk] 初始化失败", error);
  761. if (typeof showToastEffect === "function") {
  762. showToastEffect("页面初始化失败,请稍后重试", 2200, "error");
  763. }
  764. } finally {
  765. this.loading = false;
  766. }
  767. },
  768. buildSubmitPayload(actionPayload) {
  769. const submitPayload = {};
  770. if (this.shid) {
  771. submitPayload.shid = this.shid;
  772. }
  773. if (this.sqid) {
  774. submitPayload.sqid = this.sqid;
  775. }
  776. if (this.ssObjName) {
  777. submitPayload.ssObjName = this.ssObjName;
  778. }
  779. if (this.ssObjId) {
  780. submitPayload.ssObjId = this.ssObjId;
  781. }
  782. const payloadObj =
  783. actionPayload && typeof actionPayload === "object"
  784. ? actionPayload
  785. : {};
  786. const reviewValue = this.pickFirstValue(
  787. [payloadObj],
  788. [
  789. "shsm",
  790. "shyjValue",
  791. "shyj",
  792. "spyj",
  793. "opinion",
  794. "comment",
  795. "remark",
  796. "reason",
  797. "yj",
  798. ]
  799. );
  800. if (
  801. reviewValue !== undefined &&
  802. reviewValue !== null &&
  803. reviewValue !== ""
  804. ) {
  805. submitPayload.shsm = String(reviewValue);
  806. }
  807. return submitPayload;
  808. },
  809. navigateToMiniProgramHome() {
  810. const homePath = "/pages/main/index";
  811. const wxObj =
  812. typeof wx !== "undefined" ? wx : window.wx ? window.wx : null;
  813. const fallbackBack = () => {
  814. if (
  815. window.NavigationManager &&
  816. typeof window.NavigationManager.goBack === "function"
  817. ) {
  818. window.NavigationManager.goBack({ refreshParent: true });
  819. } else {
  820. window.history.back();
  821. }
  822. };
  823. if (!wxObj || !wxObj.miniProgram) {
  824. fallbackBack();
  825. return;
  826. }
  827. if (typeof wxObj.miniProgram.switchTab === "function") {
  828. wxObj.miniProgram.switchTab({
  829. url: homePath,
  830. fail: () => {
  831. if (typeof wxObj.miniProgram.reLaunch === "function") {
  832. wxObj.miniProgram.reLaunch({
  833. url: homePath,
  834. fail: fallbackBack,
  835. });
  836. return;
  837. }
  838. fallbackBack();
  839. },
  840. });
  841. return;
  842. }
  843. if (typeof wxObj.miniProgram.reLaunch === "function") {
  844. wxObj.miniProgram.reLaunch({
  845. url: homePath,
  846. fail: fallbackBack,
  847. });
  848. return;
  849. }
  850. fallbackBack();
  851. },
  852. async submitByConfig(conf, actionPayload) {
  853. const serviceName = conf && (conf.service || conf.servName);
  854. const destName = conf && conf.dest;
  855. if (!conf || !serviceName || !destName) {
  856. if (typeof showToastEffect === "function") {
  857. showToastEffect("缺少提交配置", 2200, "error");
  858. }
  859. return;
  860. }
  861. if (this.submitting) return;
  862. try {
  863. this.submitting = true;
  864. const submitUrl = `/service?ssServ=${encodeURIComponent(
  865. serviceName
  866. )}&ssDest=${encodeURIComponent(destName)}`;
  867. const submitPayload = this.buildSubmitPayload(actionPayload);
  868. await request.post(submitUrl, submitPayload, {
  869. loading: true,
  870. formData: true,
  871. });
  872. if (typeof showToastEffect === "function") {
  873. showToastEffect("提交成功", 1200, "success");
  874. }
  875. setTimeout(() => {
  876. this.navigateToMiniProgramHome();
  877. }, 300);
  878. } catch (error) {
  879. console.error("[mp_addChk] 提交失败", error);
  880. if (typeof showToastEffect === "function") {
  881. showToastEffect("提交失败,请稍后重试", 2200, "error");
  882. }
  883. } finally {
  884. this.submitting = false;
  885. }
  886. },
  887. showCurrentUrls() {
  888. const topIframe = this.$refs.topIframe;
  889. const bottomIframe = this.$refs.bottomIframe;
  890. const lines = [
  891. `page: ${window.location.href}`,
  892. `top: ${
  893. (topIframe && topIframe.src) || this.topIframeSrc || "(empty)"
  894. }`,
  895. `bottom: ${
  896. (bottomIframe && bottomIframe.src) ||
  897. this.bottomIframeSrc ||
  898. "(empty)"
  899. }`,
  900. ];
  901. this.urlLogText = lines.join("\n");
  902. this.urlLogVisible = true;
  903. },
  904. handleBottomAction(payload) {
  905. if (!payload || !payload.action) return;
  906. if (payload.action === "agree") {
  907. this.submitByConfig(this.agrAddData, payload);
  908. return;
  909. }
  910. if (payload.action === "reject") {
  911. this.submitByConfig(this.rejAddData, payload);
  912. }
  913. },
  914. },
  915. });
  916. });
  917. </script>
  918. </body>
  919. </html>