tianyunperfect 2 éve
szülő
commit
2a864cced5
3 módosított fájl, 235 hozzáadás és 0 törlés
  1. 57 0
      tmp/convert-tmp.html
  2. 136 0
      tmp/div-drag.html
  3. 42 0
      tmp/tmp.js

+ 57 - 0
tmp/convert-tmp.html

@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="UTF-8">
+  <title>文本转换器</title>
+</head>
+<body>
+<div>
+  <textarea id="input" rows="10" cols="50"></textarea>
+  <button id="convert">转换</button>
+  <textarea id="output" rows="10" cols="50"></textarea>
+</div>
+<script>
+  const input = document.getElementById('input');
+  const convertButton = document.getElementById('convert');
+  const output = document.getElementById('output');
+
+  function convert() {
+    // 获取输入文本域的值
+    const inputText = input.value.trim();
+    // 对输入文本进行转换
+    const convertedText = convertInput(inputText);
+    // 将转换后的结果显示在输出文本域中
+    output.value = convertedText;
+  }
+  function convertInput(inputText) {
+    const input = JSON.parse(inputText);
+
+    function convertNode(node) {
+      if (node.conjunction) {
+        return {
+          relationship: node.conjunction,
+          list: node.children.map(child => convertNode(child))
+        };
+      } else {
+        return {
+          key: node.left.field,
+          op: node.op,
+          value: node.right
+        };
+      }
+    }
+
+    let newVar = {
+      relationship: input.conjunction,
+      list: input.children.map(child => convertNode(child))
+    };
+    return JSON.stringify(newVar, null, 4);
+  }
+
+
+
+  // 绑定转换按钮的点击事件
+  convertButton.addEventListener('click', convert);
+</script>
+</body>
+</html>

+ 136 - 0
tmp/div-drag.html

@@ -0,0 +1,136 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+    <style>
+        .item {
+            width: 100px;
+            height: 100px;
+            border: 1px solid black;
+            display: inline-block;
+            margin-right: 10px;
+            text-align: center;
+            line-height: 100px;
+
+        }
+
+    </style>
+</head>
+<body>
+<div class="sortable">
+    <a class="item">Item 1</a>
+    <div class="item">Item 2</div>
+    <div class="item">Item 3</div>
+    <a class="item">Item 4</a>
+    <div class="item">Item 5</div>
+</div>
+
+
+<script>
+
+    function setDrag(cssSelector) {
+        function addNewStyle(newStyle) {
+            let elementId = 'styles_js______';
+            let styleElement = document.getElementById(elementId);
+            if (!styleElement) {
+                styleElement = document.createElement('style');
+                styleElement.type = 'text/css';
+                styleElement.id = elementId;
+                document.getElementsByTagName('head')[0].appendChild(styleElement);
+            }
+            styleElement.appendChild(document.createTextNode(newStyle));
+        }
+
+        // 调用方式
+        addNewStyle('.dragging { opacity: 0.5; } .over,.over * { background-color: red; }');
+
+
+        let elements = document.querySelectorAll(cssSelector);
+        for (let i = 0; i < elements.length; i++) {
+            elements[i].setAttribute('draggable', 'true');
+        }
+
+        let draggingItem = null;
+        let draggingIndex = -1;
+
+        function handleDragStart(e) {
+            draggingItem = this;
+            draggingIndex = getIndex(this);
+            e.dataTransfer.effectAllowed = 'move';
+            e.dataTransfer.setData('text/html', this.innerHTML);
+            this.classList.add('dragging');
+        }
+
+        function handleDragOver(e) {
+            if (e.preventDefault) {
+                e.preventDefault();
+            }
+            e.dataTransfer.dropEffect = 'move';
+            return false;
+        }
+
+        function handleDragEnter(e) {
+            this.classList.add('over');
+        }
+
+        function handleDragLeave(e) {
+            this.classList.remove('over');
+        }
+
+        function handleDrop(e) {
+            if (e.stopPropagation) {
+                e.stopPropagation();
+            }
+            if (draggingItem !== this) {
+                let dropIndex = getIndex(this);
+                let parent = this.parentNode;
+                if (draggingIndex < dropIndex) {
+                    parent.insertBefore(draggingItem, this.nextSibling);
+                } else {
+                    parent.insertBefore(draggingItem, this);
+                }
+                items = document.querySelectorAll(cssSelector);
+                [].forEach.call(items, function (item, index) {
+                    item.setAttribute('data-index', index);
+                });
+            }
+            return false;
+        }
+
+        function handleDragEnd(e) {
+            this.classList.remove('dragging');
+            let items = document.querySelectorAll(cssSelector);
+            [].forEach.call(items, function (item) {
+                item.classList.remove('over');
+            });
+        }
+
+        function getIndex(el) {
+            let index = 0;
+            let sibling = el;
+            while (sibling != null) {
+                sibling = sibling.previousElementSibling;
+                index++;
+            }
+            return index - 1;
+        }
+
+        let items = document.querySelectorAll(cssSelector);
+        [].forEach.call(items, function (item) {
+            item.addEventListener('dragstart', handleDragStart, false);
+            item.addEventListener('dragover', handleDragOver, false);
+            item.addEventListener('dragenter', handleDragEnter, false);
+            item.addEventListener('dragleave', handleDragLeave, false);
+            item.addEventListener('drop', handleDrop, false);
+            item.addEventListener('dragend', handleDragEnd, false);
+        });
+    }
+
+
+    setDrag(".item")
+
+    // notion-page-mention-token notion-text-mention-token
+</script>
+</body>
+</html>

+ 42 - 0
tmp/tmp.js

@@ -0,0 +1,42 @@
+const input = {
+    "code": 10000200,
+    "data": {
+        "headers": [
+            "日期",
+            "card_test1_1.0",
+            "card_test1_1.1"
+        ],
+        "countList": [
+            {
+                "日期": "2023-03-02",
+                "card_test1_1.1": "0",
+                "card_test1_1.0": "0",
+            },
+            {
+                "日期": "2023-03-07",
+                "card_test1_1.1": "8",
+                "card_test1_1.0": "0",
+            },
+            {
+                "日期": "2023-03-08",
+                "card_test1_1.1": "9",
+                "card_test1_1.0": "0",
+            }
+        ]
+    },
+    "message": "操作成功!",
+    "meta": {
+        "pagination": null,
+        "traceId": "b045c90a895740708923783c6e557cba"
+    }
+};
+
+const { headers, countList } = input.data;
+
+const output = countList.map((item) => {
+    const name = item["日期"];
+    const data = headers.slice(1).map((key) => item[key]);
+    return { name, data };
+});
+
+console.log(output);