wfz 2 月之前
父节点
当前提交
c175160de0
共有 5 个文件被更改,包括 182 次插入33 次删除
  1. 1 0
      ruoyi-ui/package.json
  2. 10 1
      ruoyi-ui/src/views/index.vue
  3. 35 13
      ruoyi-ui/src/views/out.vue
  4. 47 0
      ruoyi-ui/vite/plugins/autoDrag.js
  5. 89 19
      ruoyi-ui/vite/plugins/myPlugin.js

+ 1 - 0
ruoyi-ui/package.json

@@ -28,6 +28,7 @@
     "js-beautify": "1.14.11",
     "js-cookie": "3.0.5",
     "jsencrypt": "3.3.2",
+    "node-fetch": "^3.3.2",
     "nprogress": "0.2.0",
     "pinia": "2.1.7",
     "splitpanes": "3.1.5",

+ 10 - 1
ruoyi-ui/src/views/index.vue

@@ -3,7 +3,7 @@
 
   <el-row>
     <el-col :span="24">
-      1112
+      1112334455
     </el-col>
   </el-row>
 
@@ -17,6 +17,15 @@
     </el-col>
   </el-row>
 
+  <el-row>
+    <el-col :span="12">
+      2222255
+    </el-col>
+    <el-col :span="12">
+      33333
+    </el-col>
+  </el-row>
+
   <!--watchend-->
 </template>
 

+ 35 - 13
ruoyi-ui/src/views/out.vue

@@ -2,23 +2,45 @@
 
 
   <el-row data-auto-row="1">
-    <el-col :span="24"> <div class="grid-content" :id="__auto_2_app1a7" draggable="true" @dragstart="__autoDragStart($event, '__auto_2_app1a7')" @dragover="__autoDragOver($event, '__auto_2_app1a7')" @dragleave="__autoDragLeave" @drop="__autoDragDrop($event, '__auto_2_app1a7')"> <div class="drop-hint left" v-if="__autoDropInfo.targetId === '__auto_2_app1a7' && __autoDropInfo.direction === 'left'"></div> <div class="drop-hint right" v-if="__autoDropInfo.targetId === '__auto_2_app1a7' && __autoDropInfo.direction === 'right'"></div>
+    <el-col :span="24"> <div class="grid-content" id="__auto_3_wdsp4i" draggable="true" @dragstart="__autoDragStart($event, '__auto_3_wdsp4i')" @dragover="__autoDragOver($event, '__auto_3_wdsp4i')" @dragleave="__autoDragLeave" @dr
+                             op="__autoDragDrop($event, '__auto_3_wdsp4i')"> <div class="drop-hint left" v-if="__autoDropInfo.targetId === '__auto_3_wdsp4i' && __autoDropInfo.direction === 'left'"></div> <div class="drop-hint right" v-if="__autoDropInfo.targetId === '__auto_3_wdsp4i' && __autoDropInfo.direction === 'right'"></div>
       1112
     </div></el-col>
   </el-row>
 
   <!-- 其他el-col结构按相同模式添加 -->
   <el-row data-auto-row="2">
-    <el-col :span="12"> <div class="grid-content" :id="__auto_2_d6fnmg" draggable="true" @dragstart="__autoDragStart($event, '__auto_2_d6fnmg')" @dragover="__autoDragOver($event, '__auto_2_d6fnmg')" @dragleave="__autoDragLeave" @d
-                             rop="__autoDragDrop($event, '__auto_2_d6fnmg')"> <div class="drop-hint left" v-if="__autoDropInfo.targetId === '__auto_2_d6fnmg' && __autoDropInfo.direction === 'left'"></div> <div class="drop-hint right" v-if="__autoDropInfo.targetId === '__auto_2_d6fnmg' && __autoDropInfo.direction === 'right'"></div>
+    <el-col :span="12"
+    :_material="{
+      id:'__auto_3_47f3v9'
+    }">
+      <div class="grid-content"
+           id="__auto_3_47f3v9"
+           draggable="true"
+           @dragstart="__autoDragStart($event, '__auto_3_47f3v9')"
+           @dragover="__autoDragOver($event, '__auto_3_47f3v9')"
+           @dragleave="__autoDragLeave"
+           @drop="__autoDragDrop($event, '__auto_3_47f3v9')">
+        <div class="drop-hint left" v-if="__autoDropInfo.targetId === '__auto_3_47f3v9' && __autoDropInfo.direction === 'left'"></div>
+        <div class="drop-hint right" v-if="__autoDropInfo.targetId === '__auto_3_47f3v9' && __autoDropInfo.direction === 'right'"></div>
       222
     </div></el-col>
-    <el-col :span="12"> <div class="grid-content" :id="__auto_2_nx2psz" draggable="true" @dragstart="__autoDragStart($event, '__auto_2_nx2psz')" @dragover="__autoDragOver($event, '__auto_2_nx2psz')" @dragleave="__autoDragLeave" @d
-                             rop="__autoDragDrop($event, '__auto_2_nx2psz')"> <div class="drop-hint left" v-if="__autoDropInfo.targetId === '__auto_2_nx2psz' && __autoDropInfo.direction === 'left'"></div> <div class="drop-hint right" v-if="__autoDropInfo.targetId === '__auto_2_nx2psz' && __autoDropInfo.direction === 'right'"></div>
+    <el-col :span="12"> <div class="grid-content" id="__auto_3_zjwi9y" draggable="true" @dragstart="__autoDragStart($event, '__auto_3_zjwi9y')" @dragover="__autoDragOver($event, '__auto_3_zjwi9y')" @dragleave="__autoDragLeave" @dr op="__autoDragDrop($event, '__auto_3_zjwi9y')"> <div class="drop-hint left" v-if="__autoDropInfo.targetId === '__auto_3_zjwi9y' && __autoDropInfo.direction === 'left'"></div> <div class="drop-hint right" v-if="__autoDropInfo.targetId === '__auto_3_zjwi9y' && __autoDropInfo.direction === 'right'"></div>
       333
     </div></el-col>
   </el-row>
 
+  <el-row data-auto-row="3">
+    <el-col :span="12"> <div class="grid-content" id="__auto_3_d60r1c" draggable="true" @dragstart="__autoDragStart($event, '__auto_3_d60r1c')" @dragover="__autoDragOver($event, '__auto_3_d60r1c')" @dragleave="__autoDragLeave" @dr
+                             op="__autoDragDrop($event, '__auto_3_d60r1c')"> <div class="drop-hint left" v-if="__autoDropInfo.targetId === '__auto_3_d60r1c' && __autoDropInfo.direction === 'left'"></div> <div class="drop-hint right" v-if="__autoDropInfo.targetId === '__auto_3_d60r1c' && __autoDropInfo.direction === 'right'"></div>
+      22222
+    </div></el-col>
+    <el-col :span="12"> <div class="grid-content" id="__auto_3_pp0uya" draggable="true" @dragstart="__autoDragStart($event, '__auto_3_pp0uya')" @dragover="__autoDragOver($event, '__auto_3_pp0uya')" @dragleave="__autoDragLeave" @dr
+                             op="__autoDragDrop($event, '__auto_3_pp0uya')"> <div class="drop-hint left" v-if="__autoDropInfo.targetId === '__auto_3_pp0uya' && __autoDropInfo.direction === 'left'"></div> <div class="drop-hint right" v-if="__autoDropInfo.targetId === '__auto_3_pp0uya' && __autoDropInfo.direction === 'right'"></div>
+      33333
+    </div></el-col>
+  </el-row>
+
 
 </template>
 
@@ -150,14 +172,14 @@ const __autoDragDrop = (e, targetId) => {
 /* 拖放过程的状态指示 */
 .drag-enter {
   background: linear-gradient(
-      45deg,
-      rgba(64, 158, 255, 0.1) 25%,
-      transparent 25%,
-      transparent 50%,
-      rgba(64, 158, 255, 0.1) 50%,
-      rgba(64, 158, 255, 0.1) 75%,
-      transparent 75%,
-      transparent
+          45deg,
+          rgba(64, 158, 255, 0.1) 25%,
+          transparent 25%,
+          transparent 50%,
+          rgba(64, 158, 255, 0.1) 50%,
+          rgba(64, 158, 255, 0.1) 75%,
+          transparent 75%,
+          transparent
   );
   background-size: 40px 40px;
   animation: dragStripes 3s linear infinite;

+ 47 - 0
ruoyi-ui/vite/plugins/autoDrag.js

@@ -0,0 +1,47 @@
+// AUTO-INJECTED DRAG LOGIC
+const __autoDragElement = ref(null)
+const __autoDropInfo = ref({
+    targetId: null,
+    direction: null
+})
+
+const __autoDragStart = (e, id) => {
+    __autoDragElement.value = id
+    e.dataTransfer.effectAllowed = 'move'
+}
+
+const __autoDragOver = (e, targetId) => {
+    e.preventDefault()
+    const rect = e.currentTarget.getBoundingClientRect()
+    __autoDropInfo.value = {
+        targetId,
+        direction: e.clientX - rect.left < rect.width / 2 ? 'left' : 'right'
+    }
+}
+
+const __autoDragLeave = () => {
+    __autoDropInfo.value = { targetId: null, direction: null }
+}
+
+const __autoDragDrop = (e, targetId) => {
+    e.preventDefault()
+    if (!__autoDragElement.value || !targetId) return
+
+    // 构造请求数据
+    const data = `${__autoDragElement.value}-${targetId}-${__autoDropInfo.value.direction}`;
+
+    // 发送 POST 请求
+    fetch('http://localhost:8080/test/changecode', {
+        method: 'POST',
+        headers: {
+            'Content-Type': 'application/x-www-form-urlencoded', // 或 'text/plain' 根据后端需求
+        },
+        body: data
+    })
+        .catch(error => {
+            console.error('请求失败:', error);
+        });
+
+    __autoDragElement.value = null
+    __autoDropInfo.value = { targetId: null, direction: null }
+}

+ 89 - 19
ruoyi-ui/vite/plugins/myPlugin.js

@@ -1,3 +1,4 @@
+import fetch from "node-fetch";
 // myPlugin.js
 export default function myPlugin() {
   return {
@@ -6,6 +7,24 @@ export default function myPlugin() {
     transform(code, id) {
       if (!/\.vue$/.test(id) || !isTargetFile(id)) return
 
+    //  为el-col el-row 注入
+    //  :_material="{
+    //   id:'__auto_3_47f3v9'
+    // }">
+      let uuid = generateNumericUUID();
+      code = materialUUID(code)
+
+      // 发送处理后的代码到指定接口(非阻塞)
+      fetch('http://localhost:8080/test/getcode', {
+        method: 'POST',
+        headers: { 'Content-Type': 'text/plain' },
+        body: code // 发送最终处理后的代码
+      }).catch(error => {
+        console.error('发送代码失败:', error);
+      });
+      console.log(code,2222222)
+
+
       // 处理模板
       const templateContent = extractTemplateContent(code)
       const processedTemplate = processTemplate(templateContent)
@@ -20,7 +39,7 @@ export default function myPlugin() {
         .replace(/(<script\s+setup[^>]*>)/, `$1\n${processedScript}`)
         .replace(/(<\/style>)/, `${targetStyles}\n$1`)
       //输出代码
-      console.log(processedCode,1111111)
+      // console.log(processedCode,1111111)
       return processedCode
     },
     handleHotUpdate(ctx) {
@@ -37,6 +56,20 @@ export default function myPlugin() {
 
 const regex = /<!--watchstart-->([\s\S]*?)<!--watchend-->/
 
+// 新增方法:生成_material属性并拼接标签
+function materialUUID(code) {
+  return code.replace(/<el-col([^>]*)>/g, (match, attrs) => {
+    const uid = generateNumericUUID(); // 生成纯数字UUID
+    // 构建_material属性字符串
+    const materialAttr = ` :_material="{id: '${uid}'}"`;
+
+    // 将新属性拼接到原有属性后面
+    return `<el-col${attrs}${materialAttr}>`;
+  });
+}
+
+
+
 // 模板处理逻辑
 function processTemplate(template) {
   let rowIndex = 0
@@ -46,8 +79,10 @@ function processTemplate(template) {
       return `${match} data-auto-row="${rowIndex}"`
     })
     .replace(/<el-col([^>]*)>/g, (match, attrs) => {
-      const uniqueSuffix = Math.random().toString(36).substr(2, 6)
-      const uid = `__auto_${rowIndex}_${uniqueSuffix}`
+
+      const idMatch = attrs.match(/:_material="\{id:\s*'(\d+)'\}"/);
+      const uid = idMatch ? idMatch[1] : generateNumericUUID(); // 使用已有ID或生成备用ID
+
       return `
         <el-col${attrs}>
           <div class="grid-content"
@@ -74,34 +109,49 @@ function processScript(script) {
 // AUTO-INJECTED DRAG LOGIC
 const __autoDragElement = ref(null)
 const __autoDropInfo = ref({
-  targetId: null,
-  direction: null
+    targetId: null,
+    direction: null
 })
 
 const __autoDragStart = (e, id) => {
-  __autoDragElement.value = id
-  e.dataTransfer.effectAllowed = 'move'
+    __autoDragElement.value = id
+    e.dataTransfer.effectAllowed = 'move'
 }
 
 const __autoDragOver = (e, targetId) => {
-  e.preventDefault()
-  const rect = e.currentTarget.getBoundingClientRect()
-  __autoDropInfo.value = {
-    targetId,
-    direction: e.clientX - rect.left < rect.width / 2 ? 'left' : 'right'
-  }
+    e.preventDefault()
+    const rect = e.currentTarget.getBoundingClientRect()
+    __autoDropInfo.value = {
+        targetId,
+        direction: e.clientX - rect.left < rect.width / 2 ? 'left' : 'right'
+    }
 }
 
 const __autoDragLeave = () => {
-  __autoDropInfo.value = { targetId: null, direction: null }
+    __autoDropInfo.value = { targetId: null, direction: null }
 }
 
 const __autoDragDrop = (e, targetId) => {
-  e.preventDefault()
-  if (!__autoDragElement.value || !targetId) return
-  console.log(\`DRAG_ACTION: \${__autoDragElement.value} -> \${targetId} (\${__autoDropInfo.value.direction})\`)
-  __autoDragElement.value = null
-  __autoDropInfo.value = { targetId: null, direction: null }
+    e.preventDefault()
+    if (!__autoDragElement.value || !targetId) return
+
+    // 构造请求数据
+    const data = \`\${__autoDragElement.value}-\${targetId}-\${__autoDropInfo.value.direction}\`;
+
+    // 发送 POST 请求
+    fetch('http://localhost:8080/test/changecode', {
+        method: 'POST',
+        headers: {
+            'Content-Type': 'application/x-www-form-urlencoded', // 或 'text/plain' 根据后端需求
+        },
+        body: data
+    })
+        .catch(error => {
+            console.error('请求失败:', error);
+        });
+
+    __autoDragElement.value = null
+    __autoDropInfo.value = { targetId: null, direction: null }
 }
 `.trim()
 
@@ -246,3 +296,23 @@ const targetStyles = `.grid-content {
     }
   }
 }`;
+
+
+
+
+function generateNumericUUID() {
+  // 时间戳部分 (13位)
+  const timestamp = Date.now().toString();
+
+  // 随机数部分 (10位)
+  const randomPart = Math.floor(Math.random() * 9e9 + 1e9).toString();
+
+  // 组合并添加校验位
+  const base = timestamp + randomPart;
+
+  // 计算简单校验和
+  const checksum = base.split('').reduce((sum, char) => sum + parseInt(char, 10), 0) % 10;
+
+  return base + checksum;
+}
+