打印日志 - davy-gan/web GitHub Wiki

/* eslint-disable react/no-array-index-key */
/* eslint-disable react/no-danger */
import React, { useEffect, useState } from 'react';
import { unescape } from 'lodash';
import { Spin } from 'antd';

export default function Log(props) {
  const { logs, logLoading } = props;
  const [data, setData] = useState([]);

  useEffect(() => {
    const newLogs = unescape(logs)
      .replace(/\\n/g, '<br/>')
      .replace(/\\\\/g, '')
      .replace(/\\t/g, '&emsp;&emsp;&emsp;&emsp;');
    const newData = [...newLogs.split(',')];
    setData(newData);
  }, [logs]);
  return (
    <Spin spinning={logLoading}>
      {data.map((item, index) => {
        const text = unescape(item)
          .replace(/\\n/g, '<br/>')
          .replace(/\\t/g, '&emsp;&emsp;&emsp;&emsp;')
          .replace(/\["/g, '')
          // eslint-disable-next-line no-useless-escape
          .replace(/\"]/g, '')
          .replace(/"/g, '')
          .replace(/\\/g, '');
        return (
          <div
            style={{ width: '100%', wordBreak: 'break-all', overflow: scroll }}
            // eslint-disable-next-line react/no-danger
            dangerouslySetInnerHTML={{ __html: text }}
            key={`${text}${index}`}
          />
        );
      })}
    </Spin>
  );
}

//换行操作
export function transferSql(sql = '') {
  return unescape(sql).replace(/\\n/g, '\n');
}
⚠️ **GitHub.com Fallback** ⚠️