Sfoglia il codice sorgente

feat: 新增调试保存功能

cuiyalong 9 mesi fa
parent
commit
72586b7641

+ 11 - 1
frontend/src/components/spider/EditSpider.vue

@@ -523,8 +523,12 @@ defineExpose({
     .el-input__wrapper {
         background-color: transparent;
     }
+    
+}
+.header-left {
+    display: flex;
+    align-items: center;
 }
-
 .codeEditor {
     width: 100%;
     font-size: 12pt;
@@ -546,6 +550,12 @@ defineExpose({
     align-items: center;
     flex: 1;
     margin-left: 10px;
+    :deep(.el-tag) {
+        padding-top: 2px;
+        padding-bottom: 2px;
+        height: unset;
+        min-height: 24px;
+    }
 }
 .mark-buttons {
     margin: 0 10px;

+ 34 - 0
frontend/src/components/spider/RunSpider.vue

@@ -106,6 +106,8 @@ import {ViewCurrentSpiderConfig, DebugSpider, StopDebugSpider, ExportJsonFile} f
 import { ViewResultItemAll, SelectSaveFilePath, ExportEpubFile, ExportExcelFile, CountYestodayArts } from "../../../wailsjs/go/main/App"
 import { EventsOn, EventsOff } from "../../../wailsjs/runtime"
 
+const emit = defineEmits(['save'])
+
 let originData = {}
 const defaultFormValue = {
     maxPages: 1,
@@ -324,6 +326,37 @@ const handleCountYestday = () => {
         });
     }
 }
+
+
+const doSaveInfo = () => {
+  const payload = {
+    _originData: JSON.parse(JSON.stringify(originData)),
+    value: {}
+  }
+  const cssMark = originData.cssmark
+  const formDataVal = formData.value
+  const listDelayTime = formDataVal.listDelay ? parseInt(formDataVal.listDelay) : 0
+  const listTurnDelayTime = formDataVal.trunPageDelay ? parseInt(formDataVal.trunPageDelay) : 0
+  const contentDelayTime = formDataVal.contentDelay ? parseInt(formDataVal.contentDelay) : 0
+  if (cssMark) {
+    // 替换
+    cssMark.listDelayTime = listDelayTime
+    cssMark.listTurnDelayTime = listTurnDelayTime
+    cssMark.contentDelayTime = contentDelayTime
+  } else {
+    // 初始化
+    payload.value = {
+      listDelayTime,
+      listTurnDelayTime,
+      contentDelayTime,
+    }
+  }
+  console.log(payload)
+  setTimeout(() => {
+    emit('save', payload)
+  }, 1000)
+}
+
 //Wails事件绑定
 EventsOff('debug_event')
 EventsOn("debug_event", data => {
@@ -342,6 +375,7 @@ EventsOn("debug_event", data => {
 
 defineExpose({
     setPageData,
+    doSaveInfo,
 })
 </script>
 <style lang="scss" scoped>

+ 34 - 4
frontend/src/components/spider/RunSpiderDialog.vue

@@ -1,14 +1,29 @@
 <template>
-    <el-dialog title="调试/运行" v-model="dialogVisible" :close-on-click-modal="false" destroy-on-close width="80%">
-        <RunSpiderContent ref="runSpiderContent" />
+    <el-dialog :title="dialogTitle" v-model="dialogVisible" :close-on-click-modal="false" destroy-on-close width="80%">
+        <template #header="{ titleId, titleClass }">
+            <div class="run-spider-css-header">
+                <div class="header-left">
+                    <span :id="titleId" :class="titleClass">{{ dialogTitle }}</span>
+                </div>
+                <div class="mark-container">
+                    <el-button-group class="mark-buttons">
+                        <el-button type="primary" :icon="Link" @click="handleSave">保存</el-button>
+                    </el-button-group>
+                </div>
+            </div>
+        </template>
+        <RunSpiderContent ref="runSpiderContent" @save="onContentSave" />
     </el-dialog>
 </template>
 <script setup>
 import { ref, nextTick } from 'vue';
 import RunSpiderContent from "./RunSpider.vue"
 
+const emit = defineEmits(['save'])
+
 const dialogVisible = ref(false)
 const runSpiderContent = ref({})
+const dialogTitle = ref('调试/运行')
 
 const setPageData = (e) => {
     nextTick(() => {
@@ -19,12 +34,27 @@ const getPageData = () => {
     return runSpiderContent.value.getPageData()
 }
 
+const handleSave = () => {
+    runSpiderContent.value.doSaveInfo()
+}
+
+const onContentSave = (e) => {
+    emit('save', e)
+}
+
 defineExpose({
     dialogVisible,
     setPageData,
     getPageData,
 })
 </script>
-<style scoped>
-
+<style scoped lang="scss">
+.run-spider-css-header {
+    display: flex;
+}
+.header-left {
+    margin-right: 12px;
+    display: flex;
+    align-items: center;
+}
 </style>

+ 31 - 3
frontend/src/views/CodeList.vue

@@ -123,7 +123,9 @@
         @custom-event="dialogEvents.editSpiderConfigSaveEvent"
         @data-tag="editDialogMarkClick($event)"
     />
-    <RunSpiderDialog ref="runSpiderDialog" />
+    <RunSpiderDialog ref="runSpiderDialog"
+        @save="dialogEvents.runSpiderConfigSave"
+    />
     <VerifySpider ref="verifySpiderDialog" />
 </template>
 
@@ -491,6 +493,20 @@ const dialogEvents = {
         const rowData = data._originData
         const payload = data.value
         const code = rowData.code
+        // 保存逻辑
+        console.log(data, payload, code)
+        dialogEvents.saveRequest(code, payload)
+    },
+    runSpiderConfigSave(data) {
+        console.log(data)
+        const rowData = data._originData
+        const payload = data.value
+        const code = rowData.code
+        // 保存逻辑
+        console.log(data, payload, code)
+        dialogEvents.saveRequest(code, payload)
+    },
+    async saveRequest(code, payload) {
         const updateRule = [
             {
                 query: { code: code },
@@ -503,7 +519,6 @@ const dialogEvents = {
             stype: 'save',
             update: updateRule
         }
-        console.log("change data:", data, params)
         try {
             const r = await store.dispatch('rulesList/editCodeItem', params)
             const { msg, err } = r
@@ -529,7 +544,7 @@ const dialogEvents = {
                 duration: 3000,
             })
         }
-    },
+    }
 }
 
 const getMarkWithRow = row => {
@@ -632,6 +647,19 @@ const tableEvents = {
     },
     handleSubmit(index, row) {
         onlyClickHighlight(row, '_action_clicked_submit')
+        ElMessageBox.confirm('确定提交?', '提示',
+            {
+                customClass: 'j-confirm-message-box',
+                type: 'warning',
+                confirmButtonText: '确定',
+                cancelButtonText: '取消',
+                showCancelButton: false,
+            }
+        ).then(() => {
+            this.confirmSubmit(row)
+        })
+    },
+    confirmSubmit(row) {
         const lua = getLuaParams(row)
         lua.state = 1
         ServerActionUpdateCodeState({ lua: lua }).then(r => {