wanshenmean
11 小时以前 1515ffa15c11e106f35e1447bc990b7867c449bb
Code/WMS/WIDESEA_WMSClient/src/extension/system/Mes_Log.jsx
@@ -1,5 +1,7 @@
import { h, createApp } from 'vue';
import { ElDrawer, ElIcon } from 'element-plus';
import { createApp } from 'vue';
import { ElDrawer } from 'element-plus';
import { JsonViewer } from 'vue3-json-viewer';
import 'vue3-json-viewer/dist/vue3-json-viewer.css';
let extension = {
  components: {
@@ -54,13 +56,12 @@
      const jsonContent = type === 'request' ? row.requestJson : row.responseJson;
      const title = type === 'request' ? '📋 请求 JSON' : '📥 响应 JSON';
      // 格式化 JSON
      let formattedJson = '';
      // 解析 JSON 对象,解析失败则保留原始字符串
      let jsonData;
      try {
        const obj = typeof jsonContent === 'string' ? JSON.parse(jsonContent) : jsonContent;
        formattedJson = JSON.stringify(obj, null, 2);
        jsonData = typeof jsonContent === 'string' ? JSON.parse(jsonContent) : jsonContent;
      } catch (e) {
        formattedJson = String(jsonContent);
        jsonData = String(jsonContent);
      }
      // 创建临时容器渲染抽屉
@@ -69,45 +70,38 @@
      const app = createApp({
        render() {
          return h('div', [
            h(ElDrawer, {
              modelValue: true,
              'onUpdate:modelValue': (val) => {
                if (!val) {
                  app.unmount();
                  document.body.removeChild(container);
                }
              },
              title: title,
              size: '30%',
              destroyOnClose: true,
              closeOnClickModal: true
            }, {
              default: () => h('div', {
                style: {
                  height: '100%',
                  backgroundColor: '#f5f5f5',
                  padding: '16px',
                  borderRadius: '4px'
                }
              }, [
                h('pre', {
                  style: {
                    margin: '0',
                    fontSize: '14px',
                    lineHeight: '1.5',
                    fontFamily: 'Consolas, Monaco, "Courier New", monospace',
                    whiteSpace: 'pre-wrap',
                    wordBreak: 'break-all'
                  }
                }, formattedJson)
              ])
            })
          ]);
          const onClose = (val) => {
            if (!val) {
              app.unmount();
              document.body.removeChild(container);
            }
          };
          return (
            <div>
              <ElDrawer
                modelValue={true}
                onUpdate:modelValue={onClose}
                title={title}
                size="30%"
                destroyOnClose={true}
                closeOnClickModal={true}
              >
                <JsonViewer
                  value={jsonData}
                  expanded={true}
                  expandDepth={5}
                  copyable={true}
                  sort={false}
                  theme="light"
                />
              </ElDrawer>
            </div>
          );
        }
      });
      app.use(window.ElementPlus);
      app.component('JsonViewer', JsonViewer);
      app.mount(container);
    },
  }