From 015f92abba32cc7036ab02316631790498addb6a Mon Sep 17 00:00:00 2001 From: Youngster_yj <907985037@qq.com> Date: Mon, 2 Dec 2024 17:58:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86\=E4=BB=A3=E7=A0=81=E5=AE=A1=E8=AE=A1-?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../YakitVirtualList/YakitVirtualList.tsx | 9 +- .../YakRunnerProjectManager.tsx | 2 +- .../risks/YakitRiskTable/YakitRiskTable.tsx | 2 +- .../AuditCode/AuditCode.tsx | 215 +++++++++++++++--- .../AuditCode/AuditCodeType.d.ts | 9 + .../RunnerFileTree/RunnerFileTree.module.scss | 2 +- .../RunnerFileTree/RunnerFileTree.tsx | 29 ++- 7 files changed, 229 insertions(+), 39 deletions(-) diff --git a/app/renderer/src/main/src/components/yakitUI/YakitVirtualList/YakitVirtualList.tsx b/app/renderer/src/main/src/components/yakitUI/YakitVirtualList/YakitVirtualList.tsx index 0683a62bbb..efc93973b7 100644 --- a/app/renderer/src/main/src/components/yakitUI/YakitVirtualList/YakitVirtualList.tsx +++ b/app/renderer/src/main/src/components/yakitUI/YakitVirtualList/YakitVirtualList.tsx @@ -7,6 +7,7 @@ import { useDebounceEffect, useMemoizedFn, useThrottleFn, + useUpdateEffect, useVirtualList } from "ahooks" import {useRef, useState} from "react" @@ -46,7 +47,7 @@ export const YakitVirtualList = (props: YakitVirtualListProps) const containerRef = useRef(null) const wrapperRef = useRef(null) - const [list] = useVirtualList(data, { + const [list, scrollTo] = useVirtualList(data, { containerTarget: containerRef, wrapperTarget: wrapperRef, itemHeight: 48, @@ -68,10 +69,14 @@ export const YakitVirtualList = (props: YakitVirtualListProps) setScroll(true) } }, - [vlistHeigth, wrapperRef.current?.clientHeight, refresh, hasMore], + [vlistHeigth, wrapperRef.current?.clientHeight, hasMore], {wait: 200} ) + useUpdateEffect(() => { + scrollTo(0) + }, [refresh]) + const onScrollCapture = useThrottleFn( () => { if (wrapperRef && containerRef && !loading && hasMore) { diff --git a/app/renderer/src/main/src/pages/YakRunnerProjectManager/YakRunnerProjectManager.tsx b/app/renderer/src/main/src/pages/YakRunnerProjectManager/YakRunnerProjectManager.tsx index 4388465e4b..4a802cca50 100644 --- a/app/renderer/src/main/src/pages/YakRunnerProjectManager/YakRunnerProjectManager.tsx +++ b/app/renderer/src/main/src/pages/YakRunnerProjectManager/YakRunnerProjectManager.tsx @@ -40,7 +40,7 @@ export const YakRunnerProjectManager: React.FC = (
{ setShowCompileModal(true) }} diff --git a/app/renderer/src/main/src/pages/risks/YakitRiskTable/YakitRiskTable.tsx b/app/renderer/src/main/src/pages/risks/YakitRiskTable/YakitRiskTable.tsx index eda452a172..7cfd2e8a9d 100644 --- a/app/renderer/src/main/src/pages/risks/YakitRiskTable/YakitRiskTable.tsx +++ b/app/renderer/src/main/src/pages/risks/YakitRiskTable/YakitRiskTable.tsx @@ -1230,7 +1230,7 @@ export const YakitRiskTable: React.FC = React.memo((props)
Total - {response.Total} + {allTotal}
diff --git a/app/renderer/src/main/src/pages/yakRunnerAuditCode/AuditCode/AuditCode.tsx b/app/renderer/src/main/src/pages/yakRunnerAuditCode/AuditCode/AuditCode.tsx index d3dca2a63d..d27cd2573e 100644 --- a/app/renderer/src/main/src/pages/yakRunnerAuditCode/AuditCode/AuditCode.tsx +++ b/app/renderer/src/main/src/pages/yakRunnerAuditCode/AuditCode/AuditCode.tsx @@ -1,5 +1,6 @@ import React, {memo, useEffect, useMemo, useRef, useState} from "react" import { + AfreshAuditModalProps, AuditCodeProps, AuditHistoryTableProps, AuditMainItemFormProps, @@ -17,7 +18,7 @@ import { import classNames from "classnames" import styles from "./AuditCode.module.scss" import {genDefaultPagination, QueryGeneralResponse, YakScript} from "@/pages/invoker/schema" -import {Divider, Form, FormInstance, Input, Progress, Tooltip, Tree} from "antd" +import {Badge, Divider, Form, FormInstance, Input, Progress, Tooltip, Tree} from "antd" import {YakitSpin} from "@/components/yakitUI/YakitSpin/YakitSpin" import {ExtraParamsNodeByType} from "@/pages/plugins/operator/localPluginExecuteDetailHeard/PluginExecuteExtraParams" import {ExecuteEnterNodeByPluginParams} from "@/pages/plugins/operator/localPluginExecuteDetailHeard/LocalPluginExecuteDetailHeard" @@ -29,6 +30,7 @@ import { ParamsToGroupByGroupName } from "@/pages/plugins/editDetails/utils" import { + useControllableValue, useDebounceFn, useInterval, useInViewport, @@ -50,13 +52,13 @@ import useStore from "../hooks/useStore" import {getNameByPath, grpcFetchAuditTree, grpcFetchDeleteAudit, loadAuditFromYakURLRaw} from "../utils" import {YakitEmpty} from "@/components/yakitUI/YakitEmpty/YakitEmpty" import { - OutlinCompileIcon, OutlineArrowcirclerightIcon, OutlineBugIcon, OutlineChevronrightIcon, OutlineDeprecatedIcon, OutlineDocumentduplicateIcon, OutlinePencilaltIcon, + OutlineReloadScanIcon, OutlineScanIcon, OutlineSearchIcon, OutlineTrashIcon, @@ -100,7 +102,7 @@ import {Paging} from "@/utils/yakQueryHTTPFlow" import {YakitTag} from "@/components/yakitUI/YakitTag/YakitTag" import {showYakitModal} from "@/components/yakitUI/YakitModal/YakitModalConfirm" import {setClipboardText} from "@/utils/clipboard" -import { getJsonSchemaListResult } from "@/components/JsonFormWrapper/JsonFormWrapper" +import {getJsonSchemaListResult} from "@/components/JsonFormWrapper/JsonFormWrapper" const {ipcRenderer} = window.require("electron") @@ -1015,17 +1017,17 @@ export const AuditModalForm: React.FC = (props) => { } const result = getJsonSchemaListResult(jsonSchemaListRef.current) - if(result.jsonSchemaError.length>0) { + if (result.jsonSchemaError.length > 0) { failed(`jsonSchema校验失败`) return } - result.jsonSchemaSuccess.forEach((item)=>{ + result.jsonSchemaSuccess.forEach((item) => { requestParams.ExecParams.push({ - Key:item.key, - Value:JSON.stringify(item.value) + Key: item.key, + Value: JSON.stringify(item.value) }) }) - console.log("requestParams---",requestParams); + console.log("requestParams---", requestParams) onStartAudit(value["programName"], requestParams) }) .catch(() => {}) @@ -1046,7 +1048,7 @@ export const AuditModalForm: React.FC = (props) => { /* eslint-disable no-template-curly-in-string */ required: "${label} 是必填字段" }} - className={styles['audit-modal-form']} + className={styles["audit-modal-form"]} > {/* */}
@@ -1081,7 +1083,7 @@ export const AuditModalForm: React.FC = (props) => { ) } -// 公共封装组件用于新建项目 +// 公共封装组件用于编译项目 export const AuditModalFormModal: React.FC = (props) => { const {onCancel, onSuccee, isInitDefault, title, warrpId} = props const [isShowCompileModal, setShowCompileModal] = useState(true) @@ -1153,7 +1155,7 @@ export const AuditModalFormModal: React.FC = (props) = Progress: progress }) }, [streamInfo]) - + return ( <> = (props) = ) } +// 公共封装组件用于重新编译 +export const AfreshAuditModal: React.FC = (props) => { + const {afreshName, setAfreshName, onSuccee, warrpId} = props + const tokenRef = useRef(randomString(40)) + /** 是否在执行中 */ + const [isExecuting, setIsExecuting] = useState(false) + const [runtimeId, setRuntimeId] = useState("") + const [streamInfo, debugPluginStreamEvent] = useHoldGRPCStream({ + taskName: "debug-plugin", + apiKey: "DebugPlugin", + token: tokenRef.current, + onEnd: () => { + debugPluginStreamEvent.stop() + setTimeout(() => { + setIsExecuting(false) + }, 300) + }, + onError: () => {}, + setRuntimeId: (rId) => { + yakitNotify("info", `调试任务启动成功,运行时 ID: ${rId}`) + setRuntimeId(rId) + } + }) + // export-show + const [exportStreamData, setExportStreamData] = useState({ + Progress: 0, + Message: "", + CostDurationVerbose: "", + RestDurationVerbose: "", + Speed: "0" + }) + const logInfoRef = useRef([]) + + useEffect(() => { + // 初次打开时带参执行 + if (afreshName) { + const requestParams: DebugPluginRequest = { + Code: "", + PluginType: "yak", + Input: "", + HTTPRequestTemplate: {} as HTTPRequestBuilderParams, + ExecParams: [ + { + Key: "programName", + Value: afreshName + } + ], + PluginName: "SSA 项目重编译" + } + + debugPluginStreamEvent.reset() + setRuntimeId("") + apiDebugPlugin({params: requestParams, token: tokenRef.current}).then(() => { + setIsExecuting(true) + debugPluginStreamEvent.start() + }) + } + }, [afreshName]) + + const onCancelAudit = () => { + logInfoRef.current = [] + debugPluginStreamEvent.cancel() + debugPluginStreamEvent.reset() + setAfreshName(undefined) + } + + useEffect(() => { + const progress = Math.floor((streamInfo.progressState.map((item) => item.progress)[0] || 0) * 100) / 100 + // 当任务结束时 跳转打开编译列表 + if (progress === 1) { + setTimeout(() => { + logInfoRef.current = [] + onCancelAudit() + onSuccee() + }, 300) + } + logInfoRef.current = streamInfo.logState.slice(0, 8) + setExportStreamData({ + ...exportStreamData, + Progress: progress + }) + }, [streamInfo]) + + return ( + <> + {/* 重新编译项目进度条弹窗 */} + + { + onCancelAudit() + }} + logInfo={logInfoRef.current} + showDownloadDetail={false} + /> + + + ) +} + export const ProjectManagerEditForm: React.FC = memo((props) => { const {onClose, record, setData} = props const {Name, Description} = record @@ -1266,8 +1380,10 @@ export const ProjectManagerEditForm: React.FC = mem }) export const AuditHistoryTable: React.FC = memo((props) => { - const {pageType, onClose, onExecuteAudit, refresh} = props + const {pageType, onClose, onExecuteAudit, warrpId} = props const {projectName} = useStore() + const [afreshName, setAfreshName] = useState() + const [refresh, setRefresh] = useControllableValue(props) const [params, setParams] = useState({ Keyword: "" }) @@ -1316,26 +1432,27 @@ export const AuditHistoryTable: React.FC = memo((props) if (reload) { afterId.current = undefined setLoading(true) - } - - if (afterId.current) { - params.AfterID = parseInt(afterId.current + "") + setRefresh(!refresh) } ipcRenderer .invoke("QuerySSAPrograms", { - Filter: params, + Filter: {...params, AfterID: reload ? undefined : parseInt(afterId.current + "")}, Pagination: paginationProps }) .then((item: QueryGeneralResponse) => { - const newData = Number(item.Pagination.Page) === 1 ? item.Data : data.concat(item.Data) + const newData = reload ? item.Data : data.concat(item.Data) const isMore = item.Data.length < item.Pagination.Limit || newData.length === total setHasMore(!isMore) if (isAllSelect) setSelectedRowKeys(newData.map((item) => item.Id)) setData(newData) setPagination(item.Pagination || genDefaultPagination(200)) - setTotal(item.Total) + if (reload) { + setTotal(item.Total) + } else { + getTotalFun() + } }) .catch((e) => { yakitNotify("error", "获取列表数据失败:" + e) @@ -1348,6 +1465,21 @@ export const AuditHistoryTable: React.FC = memo((props) ) }) + const getTotalFun = useMemoizedFn(() => { + const paginationProps = { + Page: 1, + Limit: pagination.Limit + } + ipcRenderer + .invoke("QuerySSAPrograms", { + Filter: params, + Pagination: paginationProps + }) + .then((item: QueryGeneralResponse) => { + setTotal(item.Total) + }) + }) + const onDelete = useMemoizedFn(async (params: {DeleteAll?: boolean; Filter?: QuerySSAProgramsProps}) => { try { setLoading(true) @@ -1415,7 +1547,11 @@ export const AuditHistoryTable: React.FC = memo((props) dataIndex: "LowRiskNumber", render: (text, record) => { const {CriticalRiskNumber, HighRiskNumber, WarnRiskNumber, LowRiskNumber} = record - const countNum = CriticalRiskNumber + HighRiskNumber + WarnRiskNumber + LowRiskNumber + const countNum = + parseInt(CriticalRiskNumber + "") + + parseInt(HighRiskNumber + "") + + parseInt(WarnRiskNumber + "") + + parseInt(LowRiskNumber + "") return <>{countNum !== 0 ? {countNum} : "-"} }, width: 120 @@ -1431,16 +1567,31 @@ export const AuditHistoryTable: React.FC = memo((props) { title: "操作", dataIndex: "action", - width: 160, + width: 200, render: (text, record) => { return (
+ + + } + onClick={() => { + setAfreshName(record.Name) + }} + /> + + + } + icon={} onClick={() => { - // addToTab(YakitRoute.YakRunner_Code_Scan) emiter.emit( "openPage", JSON.stringify({ @@ -1461,7 +1612,7 @@ export const AuditHistoryTable: React.FC = memo((props) } + icon={} onClick={() => { if (pageType === "projectManager") { // 跳转到审计页面的参数 @@ -1487,7 +1638,7 @@ export const AuditHistoryTable: React.FC = memo((props) } + icon={} onClick={() => { const m = showYakitModal({ title: "编辑", @@ -1533,7 +1684,11 @@ export const AuditHistoryTable: React.FC = memo((props) }) return ( -
event.stopPropagation()}> +
event.stopPropagation()} + >
已编译项目
@@ -1601,6 +1756,7 @@ export const AuditHistoryTable: React.FC = memo((props) className={styles["audit-virtual-list"]} loading={loading} + refresh={refresh} hasMore={hasMore} columns={columns} data={data} @@ -1616,6 +1772,13 @@ export const AuditHistoryTable: React.FC = memo((props) }} />
+ + update(true)} + warrpId={warrpId || document.getElementById("audit-history-table")} + />
) }) diff --git a/app/renderer/src/main/src/pages/yakRunnerAuditCode/AuditCode/AuditCodeType.d.ts b/app/renderer/src/main/src/pages/yakRunnerAuditCode/AuditCode/AuditCodeType.d.ts index a0ea9052ae..cbf949c298 100644 --- a/app/renderer/src/main/src/pages/yakRunnerAuditCode/AuditCode/AuditCodeType.d.ts +++ b/app/renderer/src/main/src/pages/yakRunnerAuditCode/AuditCode/AuditCodeType.d.ts @@ -110,6 +110,14 @@ export interface AuditModalFormModalProps { warrpId?: HTMLElement | null } +export interface AfreshAuditModalProps { + afreshName?: string + setAfreshName: (v?: string) => void + onSuccee: () => void + // 绑定容器 + warrpId?: HTMLElement | null +} + export interface QuerySSAProgramsProps { ProgramNames?: string[] Languages?: string[] @@ -142,6 +150,7 @@ export interface AuditHistoryTableProps { onClose?: () => void onExecuteAudit?: () => void refresh?: boolean + warrpId?: HTMLElement | null } export interface ProjectManagerEditFormProps { diff --git a/app/renderer/src/main/src/pages/yakRunnerAuditCode/RunnerFileTree/RunnerFileTree.module.scss b/app/renderer/src/main/src/pages/yakRunnerAuditCode/RunnerFileTree/RunnerFileTree.module.scss index d0fb6bb525..d221358c94 100644 --- a/app/renderer/src/main/src/pages/yakRunnerAuditCode/RunnerFileTree/RunnerFileTree.module.scss +++ b/app/renderer/src/main/src/pages/yakRunnerAuditCode/RunnerFileTree/RunnerFileTree.module.scss @@ -144,4 +144,4 @@ } } } -} +} \ No newline at end of file diff --git a/app/renderer/src/main/src/pages/yakRunnerAuditCode/RunnerFileTree/RunnerFileTree.tsx b/app/renderer/src/main/src/pages/yakRunnerAuditCode/RunnerFileTree/RunnerFileTree.tsx index 44b527eb1f..955319d406 100644 --- a/app/renderer/src/main/src/pages/yakRunnerAuditCode/RunnerFileTree/RunnerFileTree.tsx +++ b/app/renderer/src/main/src/pages/yakRunnerAuditCode/RunnerFileTree/RunnerFileTree.tsx @@ -49,7 +49,7 @@ import {failed, success} from "@/utils/notification" import {FileMonitorItemProps, FileMonitorProps} from "@/utils/duplex/duplex" import {Tooltip} from "antd" import {YakitDrawer} from "@/components/yakitUI/YakitDrawer/YakitDrawer" -import {AuditHistoryTable} from "../AuditCode/AuditCode" +import {AfreshAuditModal, AuditHistoryTable} from "../AuditCode/AuditCode" import {KeyToIcon} from "@/pages/yakRunner/FileTree/icon" import {OpenFileByPathProps} from "../YakRunnerAuditCodeType" @@ -64,9 +64,10 @@ import {FileNodeProps, FileTreeListProps} from "../FileTree/FileTreeType" const {ipcRenderer} = window.require("electron") export const RunnerFileTree: React.FC = memo((props) => { - const {fileTreeLoad,boxHeight} = props + const {fileTreeLoad, boxHeight} = props const {fileTree, activeFile, projectName} = useStore() const {handleFileLoadData} = useDispatcher() + const [afreshName, setAfreshName] = useState() const [visible, setVisible] = useState(false) const [aduitList, setAduitList] = useState<{path: string; name: string}[]>([]) // 选中的文件或文件夹 @@ -261,15 +262,13 @@ export const RunnerFileTree: React.FC = memo((props) => { } }) - - // 关闭抽屉 const onCloseDrawer = useMemoizedFn(() => { setVisible(false) }) return ( -
+
@@ -294,7 +293,9 @@ export const RunnerFileTree: React.FC = memo((props) => { disabled={fileTree.length === 0} type='text2' icon={} - onClick={() => {}} + onClick={() => { + setAfreshName(projectName) + }} /> @@ -340,7 +341,7 @@ export const RunnerFileTree: React.FC = memo((props) => {
= memo((props) => { className={classNames(styles["audit-history-drawer"])} onClose={onCloseDrawer} > - setVisible(false)} /> + setVisible(false)} + warrpId={document.getElementById("audit-code")} + /> + + { + emiter.emit("onCodeAuditRefreshTree") + }} + />
) })