From 3f05d860e82bab8f3aa8bda74fa283a090fda51a Mon Sep 17 00:00:00 2001 From: luoluo <1425735414@qq.com> Date: Tue, 5 Mar 2024 10:57:29 +0800 Subject: [PATCH 01/48] =?UTF-8?q?del:=E5=88=A0=E9=99=A4=E6=97=A7=E7=89=88?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E9=A1=B5=E9=9D=A2=E3=80=8BPluginOperator?= =?UTF-8?q?=E3=80=81LocalPluginExecutor,=E4=BB=A5=E5=8F=8APluginOperator.t?= =?UTF-8?q?sx=E9=A1=B5=E9=9D=A2=E4=B8=AD=E6=9C=AA=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/local/PluginsLocalDetail.tsx | 2 +- .../src/pages/yakitStore/PluginOperator.tsx | 858 +----------------- .../src/pages/yakitStore/YakitStorePage.tsx | 1 - app/renderer/src/main/src/routes/newRoute.tsx | 6 +- 4 files changed, 8 insertions(+), 859 deletions(-) diff --git a/app/renderer/src/main/src/pages/plugins/local/PluginsLocalDetail.tsx b/app/renderer/src/main/src/pages/plugins/local/PluginsLocalDetail.tsx index 49de38714b..e9afac61c1 100644 --- a/app/renderer/src/main/src/pages/plugins/local/PluginsLocalDetail.tsx +++ b/app/renderer/src/main/src/pages/plugins/local/PluginsLocalDetail.tsx @@ -24,7 +24,7 @@ import {yakitNotify} from "@/utils/notification" import {YakitPluginOnlineJournal} from "@/pages/yakitStore/YakitPluginOnlineJournal/YakitPluginOnlineJournal" import {executeYakScriptByParams} from "@/pages/invoker/YakScriptCreator" import {showYakitModal} from "@/components/yakitUI/YakitModal/YakitModalConfirm" -import {AddToMenuActionForm, LocalPluginExecutor} from "@/pages/yakitStore/PluginOperator" +import {AddToMenuActionForm} from "@/pages/yakitStore/PluginOperator" import {isCommunityEdition} from "@/utils/envfile" import {CodeGV} from "@/yakitGV" import {getRemoteValue} from "@/utils/kv" diff --git a/app/renderer/src/main/src/pages/yakitStore/PluginOperator.tsx b/app/renderer/src/main/src/pages/yakitStore/PluginOperator.tsx index 86ac147020..9976eb5359 100644 --- a/app/renderer/src/main/src/pages/yakitStore/PluginOperator.tsx +++ b/app/renderer/src/main/src/pages/yakitStore/PluginOperator.tsx @@ -1,523 +1,19 @@ -import React, {useEffect, useRef, useState} from "react" -import { - Button, - Upload, - Empty, - Form, - PageHeader, - Popconfirm, - Popover, - Row, - Space, - Tabs, - Tag, - Tooltip, - Card, - Badge, - MenuItemProps -} from "antd" -import {QueryYakScriptRequest, YakScript} from "../invoker/schema" +import React, {useEffect, useState} from "react" +import {Form} from "antd" +import {YakScript} from "../invoker/schema" import {failed, success, yakitNotify} from "../../utils/notification" -import {formatTimestamp} from "../../utils/timeUtil" -import {CopyableField, InputItem} from "../../utils/inputUtil" -import {YakEditor} from "../../utils/editors" -import {showDrawer, showModal} from "../../utils/showModal" -import {PluginExecutor} from "./PluginExecutor" -import {DocumentEditor} from "./DocumentEditor" -import MDEditor from "@uiw/react-md-editor" -import {PluginHistoryTable} from "./PluginHistory" -import {openABSFile} from "../../utils/openWebsite" -import {BUILDIN_PARAM_NAME_YAKIT_PLUGIN_NAMES, YakScriptCreatorForm} from "../invoker/YakScriptCreator" -import {EditOutlined, QuestionOutlined, SettingOutlined, CloudUploadOutlined, CloseOutlined} from "@ant-design/icons" -import {YakScriptExecResultTable} from "../../components/YakScriptExecResultTable" -import {getLocalValue, setLocalValue} from "../../utils/kv" -import {useDebounceEffect, useGetState, useHover, useMemoizedFn} from "ahooks" -import {YakitPluginInfoOnline} from "./YakitPluginInfoOnline/YakitPluginInfoOnline" +import {useMemoizedFn} from "ahooks" import "./PluginOperator.scss" -import {ResizeBox} from "../../components/ResizeBox" -import {SimplePluginList} from "../../components/SimplePluginList" -import {YakExecutorParam} from "../invoker/YakExecutorParams" -import {API} from "@/services/swagger/resposeType" -import {GetYakScriptByOnlineIDRequest} from "./YakitStorePage" -import {YakitPluginOnlineJournal} from "./YakitPluginOnlineJournal/YakitPluginOnlineJournal" -import {UserInfoProps} from "@/store" -import {NetWorkApi} from "@/services/fetch" import {getRemoteValue} from "@/utils/kv" import {YakitAutoComplete} from "@/components/yakitUI/YakitAutoComplete/YakitAutoComplete" import {YakitInput} from "@/components/yakitUI/YakitInput/YakitInput" import {YakitButton} from "@/components/yakitUI/YakitButton/YakitButton" -import {YakitModal} from "@/components/yakitUI/YakitModal/YakitModal" -import {RemoveIcon} from "@/assets/newIcon" import {isCommunityEdition} from "@/utils/envfile" import {CodeGV} from "@/yakitGV" import {DatabaseFirstMenuProps, YakitRoute} from "@/routes/newRoute" -import emiter from "@/utils/eventBus/eventBus" -import { onToEditPlugin } from "../plugins/utils" - -export interface YakScriptOperatorProp { - yakScriptId: number - yakScriptName: string - yakScriptIdOnlineId?: number - yakScriptUUIdOnlineUUId?: string - size?: "big" | "small" - fromMenu?: boolean - - setTrigger?: () => void - setScript?: (item?: any) => any - deletePluginLocal?: (i: YakScript) => void - - deletePluginOnline?: (p: API.YakitPluginDetail) => void - updatePluginOnline?: (p: API.YakitPluginDetail) => void - - userInfo?: UserInfoProps - plugSource?: string - setMonitorEdit?: (v: boolean) => void -} - -interface PromptRequest { - id: number -} const {ipcRenderer} = window.require("electron") -export const PluginOperator: React.FC = (props) => { - const {userInfo, plugSource, setMonitorEdit} = props - const [script, setScript, getScript] = useGetState() - const [error, setError] = useState("") - const [loading, setLoading] = useState(false) - const [groups, setGroups] = useState([]) - const [markdown, setMarkdown] = useState("") - const [trigger, setTrigger] = useState(false) - const [extraParams, setExtraParams] = useState() - const [isShowJournalDot, setIsShowJournalDot] = useState(false) - const [isEdit, setIsEdit] = useState(false) - - const [settingShow, setSettingShow] = useState(false) - // 是否展示(根据插件url与私有域比较) - const [isShowPrivateDom, setIsShowPrivateDom] = useState(true) - const [patternMenu, setPatternMenu] = useState<"expert" | "new">("expert") - - const updateGroups = () => { - getRemoteValue("PatternMenu").then((patternMenu) => { - const menuMode = patternMenu || "expert" - setPatternMenu(menuMode) - if (!props.yakScriptName) return - ipcRenderer - .invoke("QueryNavigationGroups", { - YakScriptName: props.yakScriptName, - Mode: isCommunityEdition() ? CodeGV.PublicMenuModeValue : menuMode - }) - .then((data: {Groups: string[]}) => { - setGroups(data.Groups) - }) - .catch((e: any) => { - console.info(e) - }) - .finally() - }) - } - - const update = () => { - if (props.yakScriptId <= 0) { - return - } - getYakScriptById(props.yakScriptId) - } - - const getYakScriptById = useMemoizedFn((yakScriptId: number) => { - updateGroups() - setLoading(true) - ipcRenderer - .invoke("GetYakScriptById", {Id: yakScriptId}) - .then((e: YakScript) => { - getLocalScriptAfter(e) - }) - .catch((e: any) => { - failed("Query YakScript By ID failed") - }) - .finally(() => - setTimeout(() => { - setTrigger(!trigger) - setLoading(false) - }, 300) - ) - }) - - const getLocalScriptAfter = useMemoizedFn((e: YakScript) => { - setScript(e) - ipcRenderer - .invoke("GetMarkdownDocument", { - YakScriptId: e?.Id, - YakScriptName: e?.ScriptName - }) - .then((data: {Markdown: string}) => { - setMarkdown(data.Markdown) - }) - .catch((e: any) => { - setMarkdown("") - }) - }) - useEffect(() => { - update() - }, [props.yakScriptId]) - - // 来源于菜单进入以及开启了插件选择的话,就打开 - const enablePluginSelector = !!script?.EnablePluginSelector && props.fromMenu - - // OnlineBaseUrl与私有域不匹配则屏蔽云端/修改按钮并不可点击线上与日志 - useEffect(() => { - if (getScript()?.OnlineBaseUrl && plugSource === "local") { - getRemoteValue("httpSetting").then((value) => { - if (getScript()?.OnlineBaseUrl && getScript()?.OnlineBaseUrl !== JSON.parse(value)?.BaseUrl) { - setIsShowPrivateDom(false) - } else { - setIsShowPrivateDom(true) - } - }) - } - }, [script]) - - const executor = useMemoizedFn(() => { - return ( - script && ( - - ) - ) - }) - const [isDisabledLocal, setIsDisabledLocal] = useState(false) - const [isDisabledOnline, setIsDisabledOnline] = useState(false) - const [activeKey, setActiveKey] = useState("runner") - const [pluginIdOnlineId, setPluginIdOnlineId, getPluginIdOnlineId] = useGetState() - const [pluginUUIdOnlineUUId, setPluginUUIdOnlineUUId] = useState() - const refTabsAndOnlinePlugin = useMemoizedFn(() => { - if (script) { - setIsDisabledLocal(false) - setActiveKey("runner") - } else { - setIsDisabledLocal(true) - setActiveKey("online") - } - if (script && script.OnlineId == 0) { - setIsDisabledOnline(true) - } else { - setIsDisabledOnline(false) - } - if (script && script.OnlineId > 0) { - // 有本地走本地 - setPluginIdOnlineId(script?.OnlineId) - setPluginUUIdOnlineUUId(script?.UUID) - } else { - // 没本地走线上 - setPluginIdOnlineId(props.yakScriptIdOnlineId) - setPluginUUIdOnlineUUId(props.yakScriptUUIdOnlineUUId) - } - }) - const getYakScriptLocal = useMemoizedFn((id, uuid) => { - setLoading(true) - ipcRenderer - .invoke("GetYakScriptByOnlineID", { - OnlineID: id, - UUID: uuid - } as GetYakScriptByOnlineIDRequest) - .then((newSrcipt: YakScript) => { - setIsDisabledLocal(false) - setActiveKey("runner") - setPluginIdOnlineId(0) - if (props.setScript) props.setScript(newSrcipt) - getLocalScriptAfter(newSrcipt) - }) - .catch((e) => {}) - .finally(() => { - setTimeout(() => { - setTrigger(!trigger) - setLoading(false) - }, 300) - }) - }) - useDebounceEffect( - () => { - refTabsAndOnlinePlugin() - }, - [script?.OnlineId, props.yakScriptIdOnlineId], - {wait: 200} - ) - - useEffect(() => { - // 下载插件后,刷新 - ipcRenderer.on("ref-plugin-operator", async (e: any, data: any) => { - const {pluginOnlineId, pluginUUID} = data - if (getScript()?.OnlineId == pluginOnlineId || getPluginIdOnlineId() === pluginOnlineId) { - getYakScriptLocal(pluginOnlineId, pluginUUID) - } - }) - return () => { - ipcRenderer.removeAllListeners("ref-plugin-operator") - } - }, []) - useEffect(() => { - if (userInfo?.isLogin) getJournalDot() - }, [userInfo?.isLogin, pluginIdOnlineId, activeKey]) - - const getJournalDot = useMemoizedFn(() => { - if (!pluginIdOnlineId) return - NetWorkApi({ - method: "get", - url: "apply/prompt", - params: { - id: pluginIdOnlineId - } - }) - .then((res) => { - setIsShowJournalDot(res) - }) - .catch((err) => { - // failed("获取日志红点失败:" + err) - }) - }) - - const defaultContent = () => { - return ( - - - {!enablePluginSelector && executor()} - {enablePluginSelector && ( - { - setExtraParams([ - {Key: BUILDIN_PARAM_NAME_YAKIT_PLUGIN_NAMES, Value: names.join("|")} - ]) - }} - sourceType='PLUGIN_OPERATOR' - /> - } - firstMinSize={"300px"} - firstRatio={"320px"} - secondNode={executor()} - /> - )} - {/* {script && ( - - - - - - {script.Help && ( - - - - - - - - ) - } - script={script} - size={props.size} - settingShow={settingShow} - settingNode={ - { - setTimeout(() => props.setTrigger!(), 300) - }} - updateGroups={updateGroups} - setScript={props.setScript} - /> - } - /> - )} */} - - - {script && ( -
- -
- )} - {markdown ? ( -
- -
- ) : ( - - )} -
- -
- -
-
- - {script && } - {/**/} - - - {script && } - - - {pluginIdOnlineId && pluginIdOnlineId > 0 && activeKey === "online" && ( - { - if (props.deletePluginOnline) props.deletePluginOnline(p) - }} - updatePlugin={(p) => { - if (props.updatePluginOnline) props.updatePluginOnline(p) - }} - deletePluginLocal={(s) => { - if (props.deletePluginLocal) props.deletePluginLocal(s) - }} - /> - )} - - - 日志 - - ) : ( - "日志" - ) - } - key={"journal"} - disabled={!isShowPrivateDom || isDisabledOnline} - > - {pluginIdOnlineId && pluginIdOnlineId > 0 && activeKey === "journal" && ( - - )} - -
- ) - } - - const showContent = (module: YakScript): JSX.Element => { - if (!module) return <> - - const key = module.GeneralModuleKey - - switch (key) { - default: - return defaultContent() - } - } - return ( -
- {!!script && !!props.fromMenu ? showContent(script) : defaultContent()} -
- ) -} - export interface AddToMenuActionFormProp { script: YakScript visible: boolean @@ -530,14 +26,6 @@ interface OptionsProps { value: string } -interface AddToMenuRequest { - YakScriptId: number - Group: string - Verbose: string - MenuSort: number - GroupSort: number -} - export const AddToMenuActionForm: React.FC = (props) => { const [form] = Form.useForm() const {script, visible, setVisible} = props @@ -676,341 +164,3 @@ export const AddToMenuActionForm: React.FC = (props) => ) } - -interface PluginManagementProps { - script: YakScript - vertical?: boolean - update?: () => any - groups?: string[] - updateGroups?: () => any - style?: React.CSSProperties - patternMenu: "expert" | "new" - setScript?: (item: any) => any - deletePluginLocal?: (i: YakScript) => void -} - -export const PluginManagement: React.FC = React.memo((props) => { - const {script, groups, style, patternMenu} = props - const [visibleRemove, setVisibleRemove] = useState(false) - const [visibleAdd, setVisibleAdd] = useState(false) - const update = props?.update ? props.update : () => {} - const updateGroups = props?.updateGroups ? props.updateGroups : () => {} - return ( - - - {script && ( - - )} - - } - trigger={["click"]} - visible={visibleAdd} - onVisibleChange={(visible) => { - setVisibleAdd(visible) - }} - > - - - - {script?.IsIgnore ? ( - <> - { - ipcRenderer - .invoke("UnIgnoreYakScript", { - Id: script?.Id - }) - .then((e) => { - success("显示该模块") - }) - .catch((e: any) => {}) - .finally(() => {}) - }} - > - - - - ) : ( - { - ipcRenderer - .invoke("IgnoreYakScript", {Id: script?.Id}) - .then((e) => { - success("忽略该模块") - }) - .catch((e: any) => {}) - .finally(() => {}) - }} - > - - - )} - - - { - ipcRenderer.invoke("delete-yak-script", script.Id).then(() => { - ipcRenderer.invoke("change-main-menu") - if (props.deletePluginLocal) props.deletePluginLocal(script) - if (props.setScript) props.setScript(undefined) - update() - }) - }} - > - - - setVisibleRemove(false)} - footer={null} - closable={true} - closeIcon={} - bodyStyle={{padding: 0}} - > - - {(groups && - groups.length > 0 && - groups.map((element) => { - return ( - - ) - })) || - "暂无数据"} - - - - ) -}) - -interface LocalPluginExecutorProps { - script: YakScript - isEdit: boolean - setIsEdit: (v: boolean) => void - setMonitorEdit?: (v: boolean) => void - setScript?: (item?: any) => void - setTrigger?: () => void - isShowPrivateDom: boolean - fromMenu?: boolean - settingShow: boolean - setSettingShow: (v: boolean) => void - size?: "big" | "small" - extraParams?: YakExecutorParam[] - setExtraParams: (y: YakExecutorParam[]) => void - groups: string[] - updateGroups: () => void - deletePluginLocal?: (i: YakScript) => void - patternMenu: "expert" | "new" -} -export const LocalPluginExecutor: React.FC = React.memo((props) => { - const { - script, - isEdit, - setIsEdit, - setMonitorEdit, - setScript, - setTrigger, - isShowPrivateDom, - fromMenu, - setSettingShow, - settingShow, - size, - extraParams, - groups, - updateGroups, - deletePluginLocal, - patternMenu - } = props - return ( - <> - {(isEdit && ( -
-
-
修改插件:{script.ScriptName}
-
- { - setMonitorEdit && setMonitorEdit(false) - setIsEdit(false) - if (setScript) setScript(script) - if (setTrigger) setTrigger() - }} - /> -
-
-
- { - if (props.setScript) props.setScript(i) - if (props.setTrigger) props.setTrigger() - }} - fromLayout={{ - labelCol: {span: 4}, - wrapperCol: {span: 18} - }} - /> -
-
- )) || ( - - {script.Help && ( - -