Преглед изворни кода

feat: 新增批量打回功能

cuiyalong пре 9 месеци
родитељ
комит
08e5b0fb1f
2 измењених фајлова са 115 додато и 44 уклоњено
  1. 19 3
      frontend/src/views/CodeList.vue
  2. 96 41
      frontend/src/views/ReviewList.vue

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

@@ -135,7 +135,7 @@ import { useRouter } from 'vue-router';
 import { useStore } from 'vuex';
 import { ElMessage, ElMessageBox } from 'element-plus'
 import { BrowserOpenURL, EventsOn } from "../../wailsjs/runtime"
-import { VerifySpiderConfig, ServerActionUpdateCodeState, ServerActionCurrentOpenTab, ServerActionCopyCode } from "../../wailsjs/go/main/App"
+import { KillAllChrome, VerifySpiderConfig, ServerActionUpdateCodeState, ServerActionCurrentOpenTab, ServerActionCopyCode } from "../../wailsjs/go/main/App"
 import Breadcrumb from "../components/Breadcrumb.vue"
 import EditSpider from "../components/spider/EditSpider.vue"
 import RunSpiderDialog from "../components/spider/RunSpiderDialog.vue"
@@ -260,6 +260,14 @@ const editSpiderDialog = ref(null)
 const runSpiderDialog = ref(null)
 const verifySpiderDialog = ref(null)
 
+const tryToKillChrome = () => {
+    try {
+        KillAllChrome()
+    } catch (error) {
+        console.error(error)
+    }
+}
+
 // 取消prevClicked的高亮
 const cancelOtherHighlight = () => {
     for (const key in prevClickedRow.value) {
@@ -661,8 +669,11 @@ const tableEvents = {
     },
     confirmSubmit(row) {
         const lua = getLuaParams(row)
+        const param = {
+            stype: '提交'
+        }
         lua.state = 1
-        ServerActionUpdateCodeState({ lua: lua }).then(r => {
+        ServerActionUpdateCodeState({ lua: [lua], param }).then(r => {
             if (r.err === 1) {
                 ElMessage({
                     message: '提交成功',
@@ -670,6 +681,8 @@ const tableEvents = {
                     duration: 3000,
                 })
                 getTableList()
+                // 尝试kill chrome
+                tryToKillChrome()
             } else {
                 return ElMessage({
                     message: r.msg || '提交失败',
@@ -704,8 +717,11 @@ const tableEvents = {
     },
     confirmRollback(row) {
         const lua = getLuaParams(row)
+        const param = {
+            stype: '退回'
+        }
         lua.state = 12
-        ServerActionUpdateCodeState({ lua: lua }).then(r => {
+        ServerActionUpdateCodeState({ lua: [lua], param }).then(r => {
             if (r.err === 1) {
                 ElMessage({
                     message: '退回成功',

+ 96 - 41
frontend/src/views/ReviewList.vue

@@ -6,7 +6,8 @@
             <div class="action-bar-container">
                 <el-space class="action-bar-item-container action-bar-action-left">
                     <el-button-group class="ml-4">
-                        <el-button type="primary" :icon="Refresh" @click="resetFilterAndRefreshTableList">刷新</el-button>
+                        <!-- <el-button type="primary" :icon="Refresh" @click="resetFilterAndRefreshTableList">刷新</el-button> -->
+                        <el-button type="primary" :icon="Box" @click="doBatchRollback" v-if="showBatchListing">批量打回</el-button>
                         <el-button type="primary" :icon="Box" @click="doBatchListing" v-if="showBatchListing">批量上线</el-button>
                         <el-button type="primary" :icon="Box" @click="doUnBatchListing" v-if="showBatchListing">批量下线</el-button>
                     </el-button-group>
@@ -91,9 +92,8 @@
                 </el-table-column>
                 <el-table-column label="功能" width="120" align="center">
                     <template #default="scope">
-                    <!-- 审核人员:打回和通过 -->
-                    <div v-if="tableActionShow.reviewerGroup(scope.row)">
-                        <el-tooltip content="通过" placement="top">
+                        <!-- 审核人员:通过和打回,管理员也有此功能 -->
+                        <el-tooltip content="通过" placement="top" v-if="tableActionShow.reviewerGroup(scope.row)">
                             <el-button size="small" :class="{ active: scope.row._action_clicked_submit }" :disabled="actionButtonDisabled.reviewerSubmit(scope.row)" @click="tableEvents.reviewerSubmit(scope.$index, scope.row)">
                                 <el-icon><CircleCheck /></el-icon>
                             </el-button>
@@ -103,25 +103,24 @@
                                 <el-icon><CircleClose /></el-icon>
                             </el-button>
                         </el-tooltip>
-                    </div>
-                    <!-- 管理员:上线和退回 -->
-                    <div v-if="tableActionShow.adminGroup(scope.row)">
-                        <el-tooltip content="下线" placement="top" v-if="tableActionShow.downCode(scope.row)">
-                            <el-button size="small" :class="{ active: scope.row._action_clicked_down_code }" :disabled="actionButtonDisabled.adminDownCode(scope.row)" @click="tableEvents.adminDownCode(scope.$index, scope.row)">
-                                <el-icon><Download /></el-icon>
-                            </el-button>
-                        </el-tooltip>
-                        <el-tooltip content="上线" placement="top" v-if="tableActionShow.adminSubmit(scope.row)">
-                            <el-button size="small" :class="{ active: scope.row._action_clicked_submit }" :disabled="actionButtonDisabled.adminSubmit(scope.row)" @click="tableEvents.adminSubmit(scope.$index, scope.row)">
-                                <el-icon><UploadFilled /></el-icon>
-                            </el-button>
-                        </el-tooltip>
-                        <el-tooltip content="退回" placement="top" v-if="tableActionShow.adminRollback(scope.row)">
-                            <el-button size="small" :class="{ active: scope.row._action_clicked_rollback }" @click="tableEvents.adminRollback(scope.$index, scope.row)">
-                                <el-icon><DArrowLeft /></el-icon>
-                            </el-button>
-                        </el-tooltip>
-                    </div>
+                        <!-- 管理员:上线和退回 -->
+                        <template v-if="tableActionShow.adminGroup(scope.row)">
+                            <el-tooltip content="下线" placement="top" v-if="tableActionShow.downCode(scope.row)">
+                                <el-button size="small" :class="{ active: scope.row._action_clicked_down_code }" :disabled="actionButtonDisabled.adminDownCode(scope.row)" @click="tableEvents.adminDownCode(scope.$index, scope.row)">
+                                    <el-icon><Download /></el-icon>
+                                </el-button>
+                            </el-tooltip>
+                            <el-tooltip content="上线" placement="top" v-if="tableActionShow.adminSubmit(scope.row)">
+                                <el-button size="small" :class="{ active: scope.row._action_clicked_submit }" :disabled="actionButtonDisabled.adminSubmit(scope.row)" @click="tableEvents.adminSubmit(scope.$index, scope.row)">
+                                    <el-icon><UploadFilled /></el-icon>
+                                </el-button>
+                            </el-tooltip>
+                            <el-tooltip content="退回" placement="top" v-if="tableActionShow.adminRollback(scope.row)">
+                                <el-button size="small" :class="{ active: scope.row._action_clicked_rollback }" @click="tableEvents.adminRollback(scope.$index, scope.row)">
+                                    <el-icon><DArrowLeft /></el-icon>
+                                </el-button>
+                            </el-tooltip>
+                        </template>
                     </template>
                 </el-table-column>
             </el-table>
@@ -492,7 +491,13 @@ const tableActionShow = {
 const actionButtonDisabled = {
     reviewerSubmit(row) {
         // 只有待审核的才能点击
-        const canClick = row.state === 1
+        let canClick = false
+        if (isAdmin.value) {
+            canClick = row.state === 1 || row.state === 3
+        } else {
+            canClick = row.state === 1
+        }
+
         return !canClick
     },
     reviewerRollback(row) {
@@ -655,11 +660,25 @@ const tableEvents = {
         })
     },
     // 操作按钮-----
-    updateCodeStateAction(row, info) {
-        const lua = getLuaParams(row)
+    updateCodeStateAction(rowArr, info) {
+        const luaArr = []
+        if (Array.isArray(rowArr) && rowArr.length > 0) {
+            rowArr.forEach(row => {
+                const lua = getLuaParams(row)
+                luaArr.push(lua)
+            })
+        } else {
+            return console.error('至少选中1个操作内容')
+        }
+        if (!info.stype) {
+            return console.error('没有找到关键参数stype')
+        }
+        const param = {
+            stype: info.stype,
+        }
         lua.state = info.state
         lua.reason = info.reason
-        ServerActionUpdateCodeState({ lua: lua }).then(r => {
+        ServerActionUpdateCodeState({ lua: luaArr, param }).then(r => {
             if (r.err === 1) {
                 ElMessage({
                     message: r.msg || info.successTip,
@@ -698,18 +717,24 @@ const tableEvents = {
             errorTip: `${stateInfo.text}失败`,
         }
         if (!Array.isArray(list)) return
+        if (list.length <= 0) {
+            return console.error('至少选中一个可操作对象')
+        }
         if (list.length > 1) {
             info = {
                 successTip: `批量${stateInfo.text}成功`,
                 errorTip: `批量${stateInfo.text}失败`,
             }
         }
-        const codeList = list.map(r => `${r.code}_${r.state}`)
-        const lua = {
-            code: codeList.join(','),
-            state: stateInfo.code,
+        const luaArr = list.map(r => {
+            const lua = getLuaParams(r)
+            lua.state = r.state
+            return lua
+        })
+        const param = {
+            stype: stateInfo.text
         }
-        ServerActionUpdateCodeState({ lua: lua }).then(r => {
+        ServerActionUpdateCodeState({ lua: luaArr, param }).then(r => {
             if (r.err === 1) {
                 ElMessage({
                     message: r.msg || info.successTip,
@@ -728,7 +753,6 @@ const tableEvents = {
     },
     // 审核打回
     reviewerRollback(_, row) {
-        console.log('审核打回', row)
         onlyClickHighlight(row, '_action_clicked_rollback')
         ElMessageBox.prompt('请输入打回原因', '审核打回', {
             confirmButtonText: '确认打回',
@@ -737,15 +761,16 @@ const tableEvents = {
             inputErrorMessage: '不能为空',
         })
         .then(({ value }) => {
-            this.updateCodeStateAction(row, {
+            this.updateCodeStateAction([row], {
                 reason: value,
+                stype: '打回',
                 state: 2,
                 successTip: '打回成功',
                 errorTip: '打回失败',
             })
         })
     },
-    // 审核提交
+    // 审核通过
     reviewerSubmit(_, row) {
         onlyClickHighlight(row, '_action_clicked_submit')
         ElMessageBox.confirm('确认通过?', '提示',
@@ -757,8 +782,9 @@ const tableEvents = {
                 showCancelButton: false,
             }
         ).then(() => {
-            this.updateCodeStateAction(row, {
+            this.updateCodeStateAction([row], {
                 state: 3,
+                stype: '通过',
                 successTip: '通过成功',
                 errorTip: '通过失败',
             })
@@ -807,8 +833,9 @@ const tableEvents = {
                 showCancelButton: false,
             }
         ).then(() => {
-            this.updateCodeStateAction(row, {
+            this.updateCodeStateAction([row], {
                 state: 12,
+                stype: '退回',
                 successTip: '退回成功',
                 errorTip: '退回失败',
             })
@@ -828,10 +855,40 @@ const toggleRow = (rowList = []) => {
 }
 
 const tableRowSelectable = (row) => {
-    // 审核通过或者已上线的才能选
-    return row.state === 3 || row.state === 11
+    // 审核(管理员的批量打回)、已通过(管理员的批量上线)或者已上线(管理员的批量下线)的才能选
+    return row.state === 1 || row.state === 3 || row.state === 11
 }
 
+// 批量打回
+const doBatchRollback = () => {
+    // 过滤一下,找到已上线爬虫,仅提交此类爬虫(因为能选中的只有3和11,所以直接过滤获取2组)
+    let list = []
+    let dropList = []
+    if (isAdmin.value) {
+        // 管理员可以打回待审核和已通过爬虫
+        list = listState.selected.filter(v => v.state === 1 || v.state === 3)
+        dropList = listState.selected.filter(v => !(v.state === 1 || v.state === 3))
+    } else {
+        // 审核员只能打回待审核爬虫
+        list = listState.selected.filter(v => v.state === 1)
+        dropList = listState.selected.filter(v => v.state !== 1)
+    }
+    toggleRow(dropList)
+    if (list.length <= 0) {
+        return ElMessage({
+            message: '至少要选中1条有效数据: 当前未选中待审核爬虫',
+            type: 'error',
+            duration: 3000,
+        })
+    }
+    tableEvents.updateCodeStateAction([row], {
+        reason: value,
+        stype: '打回',
+        state: 2,
+        successTip: '批量打回成功',
+        errorTip: '批量打回失败',
+    })
+}
 // 执行批量上线
 const doBatchListing = () => {
     // 过滤一下,找到已通过爬虫,仅提交此类爬虫(因为能选中的只有3和11,所以直接过滤获取2组)
@@ -846,8 +903,6 @@ const doBatchListing = () => {
         })
     }
     // 判断爬虫中是否有其他类型,如果有,将其他类型爬虫取消选中
-
-
     tableEvents.batchListing(list, 'up')
 }
 // 执行批量下线操作