| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
- <title>公共录入</title>
- <script src="/js/mp_base/base.js"></script>
- <style>
- body {
- margin: 0;
- background: #f5f5f5;
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
- }
- #app {
- min-height: 100vh;
- background: #f5f5f5;
- overflow: hidden;
- }
- .content {
- width: 100%;
- height: 100vh;
- min-height: 0;
- }
- .form-frame {
- width: 100%;
- height: 100%;
- border: 0;
- display: block;
- background: #fff;
- }
- .placeholder {
- padding: 28px 16px;
- color: #666;
- font-size: 14px;
- text-align: center;
- }
- </style>
- </head>
- <body>
- <div id="app">
- <div class="content" id="contentWrap">
- <iframe
- v-if="iframeSrc"
- id="objInpFrame"
- class="form-frame"
- :src="iframeSrc"
- @load="handleFrameLoad"
- ></iframe>
- <div v-else class="placeholder" id="placeholder">{{ placeholderText }}</div>
- </div>
- <ss-bottom
- v-if="showBottom"
- :buttons="bottomButtons"
- @button-click="handleBottomAction"
- >
- </ss-bottom>
- </div>
- <script>
- // 功能说明:公共录入壳页(先调业务接口+dataTag,再按 include_input 装载 mp_ 表单页) by xu 2026-02-28
- (function () {
- const boot = function () {
- const setStatus = (text) => {
- if (state.vm) {
- state.vm.placeholderText = text;
- return;
- }
- const placeholder = document.getElementById('placeholder');
- if (placeholder) placeholder.textContent = text;
- };
- const state = {
- pageParams: {},
- service: '',
- initPayload: {},
- dataTagPayload: {},
- ssObjName: '',
- ssObjId: '',
- iframe: null,
- submitEnabled: false,
- vm: null,
- };
- const getUrlParams = () => {
- const params = {};
- const search = new URLSearchParams(window.location.search || '');
- for (const [key, value] of search.entries()) {
- params[key] = decodeURIComponent(value || '');
- }
- return params;
- };
- const unwrapData = (data) => {
- if (!data || typeof data !== 'object') return {};
- if (data.ssData && typeof data.ssData === 'object') return data.ssData;
- return data;
- };
- const parseJsonString = (text) => {
- if (!text || typeof text !== 'string') return {};
- try {
- const obj = JSON.parse(text);
- return obj && typeof obj === 'object' ? obj : {};
- } catch (_) {
- return {};
- }
- };
- const pruneParams = (obj) => {
- const out = {};
- Object.entries(obj || {}).forEach(([key, value]) => {
- if (value === undefined || value === null || value === '') return;
- out[key] = value;
- });
- return out;
- };
- // 功能说明:新增场景 id=0 统一按空处理,和你要求保持一致 by xu 2026-02-28
- const resolveObjIdFromInit = (payload, ssObjName, urlParams) => {
- const fromUrl = String(urlParams.ssObjId || '').trim();
- if (fromUrl) return fromUrl;
- if (!payload || typeof payload !== 'object') return '';
- const objName = String(ssObjName || '').trim();
- if (!objName) return '';
- const objData = payload[objName];
- if (!objData || typeof objData !== 'object') return '';
- const idField = String(payload.ssObjIdName || objData.idName || '').trim();
- if (!idField) return '';
- const rawId = objData[idField];
- if (rawId === undefined || rawId === null || rawId === '' || Number(rawId) === 0) return '';
- return String(rawId);
- };
- // 功能说明:/page/xyqj_inp.jsp -> /page/mp_xyqj_inp.html by xu 2026-02-28
- const includeToMpFormPath = (includeInput) => {
- const raw = String(includeInput || '').trim();
- if (!raw) return '';
- const noPrefix = raw.replace(/^\/page\//i, '');
- const base = noPrefix.replace(/\.ss\.jsp$/i, '').replace(/\.jsp$/i, '');
- if (!base) return '';
- return `/page/mp_${base}.html`;
- };
- const goBack = (refreshParent) => {
- if (window.NavigationManager && typeof window.NavigationManager.goBack === 'function') {
- window.NavigationManager.goBack({ refreshParent: !!refreshParent });
- } else {
- window.history.back();
- }
- };
- const ensureRequest = () => {
- if (!window.request || typeof window.request.post !== 'function') {
- throw new Error('request 未就绪');
- }
- return window.request;
- };
- // 功能说明:内容区高度按 100vh 减去 ss-bottom 实际高度计算 by xu 2026-02-28
- const updateContentHeight = () => {
- const contentWrap = document.getElementById('contentWrap');
- if (!contentWrap) return;
- const bottom = document.querySelector('#app .ss-bottom');
- const bottomHeight = bottom ? bottom.offsetHeight : 0;
- contentWrap.style.height = `calc(100vh - ${bottomHeight}px)`;
- };
- const updateBottomButtons = (submitTitle) => {
- if (!state.vm) return;
- state.vm.bottomButtons = [
- { text: '关闭', action: 'close' },
- {
- text: submitTitle || '保存并提交',
- action: 'saveSubmit',
- backgroundColor: '#575d6d',
- color: '#fff'
- }
- ];
- setTimeout(updateContentHeight, 0);
- };
- // 功能说明:供 iframe 子页调用,控制父页底部按钮显隐(解决日期弹层被底部按钮遮挡) by xu 2026-02-28
- const setBottomVisible = (visible) => {
- if (!state.vm) return;
- state.vm.showBottom = visible !== false;
- setTimeout(updateContentHeight, 0);
- };
- const getFrameFormData = () => {
- const frame = document.getElementById('objInpFrame');
- const frameWindow = frame ? frame.contentWindow : null;
- if (!frameWindow) return { valid: false, message: '表单页面未加载完成', data: {} };
- // 功能说明:优先走子页面暴露方法,尽量减少表单页工作量 by xu 2026-02-28
- if (typeof frameWindow.__mpObjInpGetFormData === 'function') {
- const result = frameWindow.__mpObjInpGetFormData();
- if (result && typeof result === 'object') {
- return {
- valid: result.valid !== false,
- message: result.message || '',
- data: result.data && typeof result.data === 'object' ? result.data : {},
- };
- }
- }
- const doc = frameWindow.document;
- const data = {};
- const nodes = doc.querySelectorAll('input[name],select[name],textarea[name]');
- nodes.forEach((node) => {
- const name = node.getAttribute('name');
- if (!name || node.disabled) return;
- const type = (node.getAttribute('type') || '').toLowerCase();
- if ((type === 'checkbox' || type === 'radio') && !node.checked) return;
- data[name] = node.value;
- });
- return { valid: true, message: '', data };
- };
- const getSubmitConfig = () => {
- const p = state.initPayload || {};
- // 功能说明:移动端只保留“保存并提交”,按钮可见性按第一接口 saveAndCommitDest 判断 by xu 2026-02-28
- const enabled = !!String(p.saveAndCommitDest || '').trim();
- return {
- enabled,
- serviceName: String(p.saveAndCommit || '').trim(),
- dest: String(p.saveAndCommitDest || '').trim(),
- title: String(p.saveAndCommitButtonValue || '保存并提交'),
- paramObj: parseJsonString(p.saveAndCommitParam),
- };
- };
- const renderFormFrame = () => {
- const includeInput = (state.dataTagPayload && state.dataTagPayload.include_input) || '';
- const formPath = includeToMpFormPath(includeInput);
- console.log('[mp_objInp][renderFormFrame] include_input =', includeInput);
- console.log('[mp_objInp][renderFormFrame] formPath =', formPath);
- if (!formPath) {
- if (state.vm) {
- state.vm.iframeSrc = '';
- state.vm.placeholderText = '未获取到 include_input,无法加载表单页';
- }
- state.submitEnabled = false;
- console.warn('[mp_objInp][renderFormFrame] formPath为空,终止渲染iframe');
- return;
- }
- const childParams = new URLSearchParams();
- Object.entries(state.pageParams || {}).forEach(([key, value]) => {
- if (value === undefined || value === null || value === '') return;
- childParams.set(key, value);
- });
- childParams.set('embed', '1');
- childParams.set('ssObjName', state.ssObjName || '');
- childParams.set('ssObjId', state.ssObjId || '');
- const iframeSrc = `${formPath}?${childParams.toString()}`;
- console.log('[mp_objInp][renderFormFrame] iframe src =', iframeSrc);
- if (state.vm) {
- state.vm.iframeSrc = iframeSrc;
- }
- const submitCfg = getSubmitConfig();
- state.submitEnabled = !!submitCfg.enabled;
- updateBottomButtons(submitCfg.title);
- setTimeout(updateContentHeight, 0);
- };
- const loadInitPayload = async () => {
- const req = ensureRequest();
- const postData = {
- ...state.pageParams,
- management: state.pageParams.management || '1',
- isReady: '1',
- };
- const res = await req.post(
- `/service?ssServ=${state.service}&management=1&isReady=1`,
- postData,
- { loading: false, formData: true }
- );
- state.initPayload = unwrapData(res ? res.data : null);
- state.ssObjName = String(state.initPayload.ssObjName || state.pageParams.ssObjName || '').trim();
- state.ssObjId = resolveObjIdFromInit(state.initPayload, state.ssObjName, state.pageParams);
- console.log('[mp_objInp] init响应', state.initPayload);
- };
- const loadDataTagPayload = async () => {
- const req = ensureRequest();
- const dataTagParams = {
- ...state.pageParams,
- ssObjName: state.ssObjName,
- ssObjId: state.ssObjId,
- };
- const res = await req.post(
- `/service?ssServ=dataTag&ssDest=data&name=inp&ssObjName=${encodeURIComponent(state.ssObjName)}&ssObjId=${encodeURIComponent(state.ssObjId)}`,
- dataTagParams,
- { loading: false, formData: true }
- );
- state.dataTagPayload = unwrapData(res ? res.data : null);
- console.log('[mp_objInp] dataTag响应', state.dataTagPayload);
- console.log('[mp_objInp] dataTag include_input =', (state.dataTagPayload && state.dataTagPayload.include_input) || '');
- };
- const submitSaveAndCommit = async () => {
- try {
- const cfg = getSubmitConfig();
- if (!state.submitEnabled || !cfg.enabled) {
- if (typeof showToastEffect === 'function') showToastEffect('当前页面不支持保存并提交', 1800, 'warning');
- return;
- }
- if (!cfg.serviceName || !cfg.dest) {
- if (typeof showToastEffect === 'function') showToastEffect('提交配置缺失', 1800, 'error');
- return;
- }
- const formResult = getFrameFormData();
- if (!formResult.valid) {
- if (typeof showToastEffect === 'function') showToastEffect(formResult.message || '表单校验未通过', 2000, 'warning');
- return;
- }
- const req = ensureRequest();
- const payload = pruneParams({
- ...(cfg.paramObj || {}),
- ...(formResult.data || {}),
- ssObjName: state.ssObjName || undefined,
- ssObjId: state.ssObjId || undefined,
- [((state.initPayload && state.initPayload.ssObjIdName) || 'ssObjId')]: state.ssObjId || undefined,
- });
- const res = await req.post(
- `/service?ssServ=${cfg.serviceName}&ssDest=${encodeURIComponent(cfg.dest)}`,
- payload,
- { loading: true, formData: true }
- );
- console.log('[mp_objInp] saveAndCommit响应', res);
- const submitResp = unwrapData(res ? res.data : null);
- // 功能说明:对齐PC流程,保存并提交后若目标为 addSure,则进入 mp_addSure 进行二次确认 by xu 2026-02-28
- if (String(cfg.dest || '').trim().toLowerCase() === 'addsure') {
- // 功能说明:addSure 跳转参数改为白名单,避免将复杂对象/超长字段带入 URL 导致后端解析异常 by xu 2026-03-01
- const allowedKeys = [
- 'msg',
- 'ms',
- 'print',
- 'dataType',
- 'ssServ',
- 'thisViewObject',
- 'wdclosewindowparam',
- ];
- const safeRespParams = {};
- const respObj = submitResp && typeof submitResp === 'object' ? submitResp : {};
- Object.keys(respObj).forEach((key) => {
- if (!allowedKeys.includes(key)) return;
- const value = respObj[key];
- if (value === undefined || value === null) return;
- const valueType = typeof value;
- if (valueType === 'string' || valueType === 'number' || valueType === 'boolean') {
- safeRespParams[key] = value;
- }
- });
- const nextParams = pruneParams({
- ssObjName: submitResp.ssObjName || state.ssObjName,
- ssObjId: submitResp.ssObjId || state.ssObjId,
- ssObjIdName: submitResp.ssObjIdName || (state.initPayload && state.initPayload.ssObjIdName) || 'ssObjId',
- fromObjInp: '1',
- ...safeRespParams,
- });
- if (window.NavigationManager && typeof window.NavigationManager.goTo === 'function') {
- window.NavigationManager.goTo('mp_addSure', nextParams, { needRefresh: true });
- } else {
- const qp = new URLSearchParams();
- Object.keys(nextParams).forEach((k) => qp.set(k, nextParams[k]));
- window.location.href = `/page/mp_addSure.html?${qp.toString()}`;
- }
- return;
- }
- if (typeof showToastEffect === 'function') showToastEffect('提交成功', 1400, 'success');
- setTimeout(() => goBack(true), 600);
- } catch (err) {
- console.error('[mp_objInp] 提交失败', err);
- if (typeof showToastEffect === 'function') showToastEffect('提交失败,请稍后重试', 2200, 'error');
- }
- };
- const init = async () => {
- try {
- setStatus('正在初始化录入页...');
- state.pageParams = getUrlParams();
- state.service = String(state.pageParams.service || '').trim();
- if (!state.service) throw new Error('缺少 service 参数');
- setStatus('正在加载业务配置...');
- await loadInitPayload();
- if (!state.ssObjName) throw new Error('第一接口未返回 ssObjName');
- setStatus('正在加载 dataTag...');
- await loadDataTagPayload();
- setStatus('正在加载表单页面...');
- renderFormFrame();
- setTimeout(updateContentHeight, 0);
- } catch (err) {
- console.error('[mp_objInp] 初始化失败', err);
- setStatus(`初始化失败:${err && err.message ? err.message : err}`);
- state.submitEnabled = false;
- }
- };
- window.addEventListener('resize', updateContentHeight);
- // 功能说明:使用 ss-bottom 统一底部样式与交互 by xu 2026-02-28
- window.SS.dom.initializeFormApp({
- el: '#app',
- data() {
- return {
- iframeSrc: '',
- placeholderText: '正在加载录入页面...',
- showBottom: true,
- bottomButtons: [
- { text: '关闭', action: 'close' },
- {
- text: '保存并提交',
- action: 'saveSubmit',
- backgroundColor: '#575d6d',
- color: '#fff'
- }
- ]
- }
- },
- methods: {
- handleFrameLoad() {
- console.log('[mp_objInp][renderFormFrame] iframe onload');
- setTimeout(updateContentHeight, 0);
- },
- handleBottomAction(payload) {
- if (payload && payload.action === 'close') {
- goBack(false);
- return;
- }
- if (payload && payload.action === 'saveSubmit') {
- submitSaveAndCommit();
- }
- }
- },
- mounted() {
- state.vm = this;
- window.__mpObjInpSetBottomVisible = setBottomVisible;
- init();
- },
- beforeUnmount() {
- window.removeEventListener('resize', updateContentHeight);
- try {
- if (window.__mpObjInpSetBottomVisible === setBottomVisible) {
- delete window.__mpObjInpSetBottomVisible;
- }
- } catch (_) {}
- }
- });
- };
- // 功能说明:SS.ready 某些场景可能不触发,增加超时兜底启动 by xu 2026-02-28
- let booted = false;
- let tries = 0;
- const maxTries = 20;
- const safeBoot = function () {
- if (booted) return;
- const ready = !!(window.SS && window.SS.dom && typeof window.SS.dom.initializeFormApp === 'function');
- if (!ready) {
- tries += 1;
- if (tries >= maxTries) {
- const ph = document.getElementById('placeholder');
- if (ph) ph.textContent = '初始化失败:ss 组件未就绪';
- return;
- }
- setTimeout(safeBoot, 200);
- return;
- }
- booted = true;
- boot();
- };
- if (window.SS && typeof window.SS.ready === 'function') {
- window.SS.ready(safeBoot);
- setTimeout(safeBoot, 1600);
- } else {
- setTimeout(safeBoot, 0);
- }
- })();
- </script>
- </body>
- </html>
|