SOURCE

console 命令行工具 X clear

                    
>
console
<!DOCTYPE html>
<html>

<head>
  <title>分类展开代码转换</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta http-equiv="Access-Control-Allow-Origin" content="*" />
  <meta name="format-detection" content="telephone=no" />
  <meta http-equiv="pragma" content="no-cache" />
  <script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.5.0/jquery.min.js"></script>
  <script>
    var w = document.documentElement.clientWidth;
    if (w <= 640) {
      document.documentElement.style.fontSize = Math.floor(w * 100 / 640) + "px";
    }
    else {
      document.documentElement.style.fontSize = 640 * 100 / 640 + "px";
    }
  </script>

  <style>
    #from {
      position: absolute;
      width: 800px;
      height: 300px
    }

    #from .area {
      transform: translateX(25px);
      text-align: left;
      width: 750px;
      height: 250px;
      display: block;
    }

    #from h6 {
      position: relative;
      display: block;
      height: 50px;
      line-height: 50px;
      font-size: 26px;
      margin: 0;
      padding: auto;
    }



    .el-button {
      position: absolute;
      right: 50px;
      display: line-block;
      line-height: 1;
      white-space: nowrap;
      cursor: pointer;
      background: #fff;
      border: 1px solid #dcdfe6;
      color: #606266;
      -webkit-appearance: none;
      text-align: center;
      box-sizing: border-box;
      outline: none;
      transition: .1s;
      font-weight: 500;
      -moz-user-select: none;
      -webkit-user-select: none;
      -ms-user-select: none;
      padding: 12px 20px;
      font-size: 14px;
      border-radius: 4px;
    }

    .el-button--primary {
      color: #fff;
      background-color: #409eff;
      border-color: #409eff;
    }
  </style>
</head>

<body>
  <div id="from">
    <h6>原代码:<button id="changebtn" class="el-button el-button--primary">转换</button></h6>
    <textarea id="zhq" class="area" value=""></textarea>
    <h6>输出结果</h6>
    <textarea id="zhh" class="area" value=""></textarea>
  </div>
  <!-- <div id="rk">请输入口令<input id="ri" /><button id="rb">确认</button></div> -->

</body>
<script>
  let defutRes = {
    "moduleType": "lynflzk",
    "show": true,
    "tab1": {
      "lb_tl": "0|200",
      "pop_wh": "150|110",
      "pop_mbr": "4",
      "pop_tl": "0",
      "classImage": "https://img.alicdn.com/imgextra/i3/907349826/O1CN01JZRYKT2MSMF5HTkfo_!!907349826.jpg",
      "classActiveImage": "https://img.alicdn.com/imgextra/i2/907349826/O1CN01E8izwp2MSMF5Zenyf_!!907349826.jpg",
      "mr_fc": "30|#999",
      "act_fc": "30|#000",
      "auto": "2",
      "auto1": {
        "autot": "3"
      },
      "lbtype": "7",
      "topcontent": ""
    },
    "tab2": {
      "jsonarray": []
    },
    "tab4": {
      "zkT": "0.3",
      "list": []
    },
    "tab3": {
      "xfshow": "2",
      "xfshow1": {
        "xfani": "1",
        "xfshowone": "2"
      }
    }
  };

  $("#changebtn").click(() => {
    let mock = $("#zhq").val();

    try {
      mock = JSON.parse(mock);
    } catch (err) {
      mock = {};
    }

    if (mock.module) {
      mock = mock.module;
      let moduleList = mock.moduleList || [];
      mock = moduleList.filter(item => {
        return item.moduleInstantsName == "展开分类" && item.moduleData && item.moduleData.jsonarray
      })[0]
    }

    if (!mock.moduleData) {
      mock = { err: "参数错误" };
      mock = JSON.stringify(mock)
      $("#zhh").val(mock)
      return;
    }
    mock = mock.moduleData;

    mock.tab1 = mock.tab1 || {};

    let isall = false;


    let res = JSON.parse(JSON.stringify(defutRes));


    res.tab2.jsonarray = mock.jsonarray || []; // 数组内容基本适配
    res.tab2.jsonarray = res.tab2.jsonarray.map((item, index) => {
      item = item || {}; // 避免报错
      // delete item.tit; // 新版不支持标题自定义
      let res = {
        title: item.title || item.name,
        content: item.content,
        flname: `name_${index + 1}`
      };
      if (item.classImage || item.popImg) res.classImage = item.classImage || item.popImg;
      if (item.classActiveImage || item.popAct) res.classActiveImage = item.classActiveImage || item.popAct;
      if (item.popurl) res.popurl = item.popurl;
      if (item.interval) res.interval = item.interval;
      if (item.it_h) res.it_h = item.it_h;
      return res;
    });

    mock.zkArray = mock.zkArray || [];
    res.tab4.list = mock.zkArray.map(item => {
      let res = {}

      if (item.index) res.belong = `name_${item.index}`;


      if (item.pop && checkBg(item.pop) == "pic") res.pop1 = {
        width: item.width,
        height: item.height,
        pop1: item.pop
      };
      if (item.act && checkBg(item.act) == "pic") res.pop2 = {
        width: item.width,
        height: item.height,
        pop2: item.act
      };
      if (item.pop && checkBg(item.pop) == "diy") res.pop1diy = item.pop;
      if (item.act && checkBg(item.act) == "diy") res.pop2diy = item.act;


      if (item.btmContent) res.content = item.btmContent;
      return res;
    });

    // res.tab1.mr_fc = mock.size_color || res.tab1.mr_fc; // 默认导航字体
    // res.tab1.act_fc = mock.a_size_color || res.tab1.act_fc; // 高亮导航字体
    // res.tab1.classImage = mock.classImage; // 默认背景图
    // res.tab1.classActiveImage = mock.classActiveImage; // 高亮背景图

    // res.tab1.topcontent = mock.topcontent; // 顶部自定义

    res.tab1.pop_wh = mock.tab1.tabWH || `200|120`; // 单个导航宽高

    res.tab1.mindex = mock.tab1.showIndex || "";

    res.tab1.popanisel = "0";
    // if (res.tab1.popanisel == "2") res.tab1.popanisel = "3"
    // else if (res.tab1.popanisel == "3") res.tab1.popanisel = "4"
    // else res.tab1.popanisel = "0"

    res = JSON.stringify(res)
    $("#zhh").val(res)
  });



  // 判断背景
  function checkBg(bg) {
    let type = ""
    if (bg) {
      if (typeof (bg) == "string") {
        if (bg.indexOf("diyM") > -1) {
          type = "diy"
        } else if (bg.indexOf("//") > -1) {
          type = "pic"
        } else { type = "color" }
      } else { type = "diy" }
    }
    return type
  }

</script>

</html>