-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jasonczc
committed
Nov 3, 2021
1 parent
fc861b3
commit fbce248
Showing
8 changed files
with
233 additions
and
107 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
frontend/src/components/Plugin/EditForm/EditPluginInfoForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import ProForm, {ProFormText} from "@ant-design/pro-form"; | ||
import axios from "axios"; | ||
import {Button, message} from "antd"; | ||
import ProCard from "@ant-design/pro-card"; | ||
import React, {useState} from "react"; | ||
import {useHistory} from "react-router"; | ||
import {PluginInfoFormParams} from "../EditPluginForm"; | ||
type LayoutType = Parameters<typeof ProForm>[0]['layout']; | ||
|
||
export default function(props:PluginInfoFormParams) { | ||
const {id} = props.info | ||
const [formLayout ] = useState<LayoutType>('horizontal'); | ||
const history = useHistory() | ||
const formItemLayout = | ||
formLayout === 'horizontal' | ||
? { | ||
labelCol: { span: 4 }, | ||
wrapperCol: { span: 14 }, | ||
} | ||
: null; | ||
const setStatus = async () =>{ | ||
try{ | ||
await axios.patch('/v1/admin/setstate',{ | ||
pluginId:props.info.id, | ||
state:2 | ||
}) | ||
message.success('切换状态成功'); | ||
}catch (err) { | ||
message.error(err.response.data.message) | ||
} | ||
} | ||
return <ProCard style={{ marginTop: 8 }} loading={props.loading}> | ||
<ProForm<{ | ||
name: string; | ||
id: string; | ||
info: string; | ||
}> | ||
{...formItemLayout} | ||
layout={formLayout} | ||
request={async () => { | ||
return props.info | ||
}} | ||
onFinish={async (values) => { | ||
try{ | ||
await axios.put('/v1/plugins/'+values.id,{ | ||
name:values.name, | ||
info:values.info | ||
}) | ||
message.success('提交成功'); | ||
}catch (err) { | ||
message.error(err.response.data.message) | ||
} | ||
}} | ||
submitter={{ | ||
render: (props, doms) => { | ||
return [ | ||
<Button key={"status"} htmlType="button" onClick={() => setStatus()}> | ||
设置状态为启用(admin) | ||
</Button>, | ||
<Button key={"preview"} htmlType="button" onClick={() => history.push('/app/info/'+id)}> | ||
查看该插件信息 | ||
</Button>, | ||
...doms, | ||
]; | ||
}, | ||
}} | ||
> | ||
<div> | ||
<ProFormText | ||
width="md" | ||
disabled={true} | ||
name="id" | ||
label="包名" | ||
tooltip="例如org.example.mirai.test-plugin" | ||
placeholder="请输入包名" | ||
/> | ||
<ProFormText | ||
width="md" | ||
name="name" | ||
label="插件名称" | ||
tooltip="例如Mirai Not Core" | ||
placeholder="请输入插件名称" | ||
/> | ||
<ProFormText | ||
width="md" | ||
name="info" | ||
label="插件信息" | ||
tooltip="填写一些描述信息" | ||
placeholder="请输入插件信息" | ||
/> | ||
</div> | ||
</ProForm> | ||
</ProCard> | ||
} |
42 changes: 42 additions & 0 deletions
42
frontend/src/components/Plugin/EditForm/PluginVersionControlForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {Button, Form, Input, message, Upload} from "antd"; | ||
import ProCard from "@ant-design/pro-card"; | ||
import React, {useState} from "react"; | ||
import {PluginInfoFormParams} from "../EditPluginForm"; | ||
import {UploadOutlined} from "@ant-design/icons"; | ||
import axios from "axios"; | ||
import VersionList from "./VersionControl/VersionList"; | ||
|
||
export default function(props:PluginInfoFormParams) { | ||
const {id} = props.info | ||
const [hasPluginVersion, setHasPluginVersion] = useState(false) | ||
const [form] = Form.useForm(); | ||
const [version, setVersion] = useState("") | ||
const onFinish = async (values: any) => { | ||
try{ | ||
await axios.put("/v1/plugins/"+id+"/"+values.version) | ||
setVersion(values.version) | ||
setHasPluginVersion(true) | ||
}catch (e) { | ||
message.error(e.response.data.message) | ||
} | ||
}; | ||
|
||
return <ProCard style={{ marginTop: 8 }} loading={props.loading}> | ||
<VersionList {...props}/> | ||
<Form form={form} onFinish={onFinish}> | ||
<Form.Item | ||
label="版本号" | ||
name="version" | ||
rules={[{ required: true, message: '请输入版本号!' }]}> | ||
<Input disabled={hasPluginVersion} placeholder="输入版本号" /> | ||
</Form.Item> | ||
{hasPluginVersion? | ||
<Upload | ||
action={"/v1/plugins/"+id+"/"+version+"/test.zip"} | ||
method={"put"} | ||
> | ||
<Button icon={<UploadOutlined />}>点击上传</Button> | ||
</Upload>:<Button htmlType="submit">确定</Button>} | ||
</Form> | ||
</ProCard> | ||
} |
19 changes: 19 additions & 0 deletions
19
frontend/src/components/Plugin/EditForm/VersionControl/FileList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {useEffect, useState} from "react"; | ||
import axios from "axios"; | ||
|
||
export interface VersionFilesProps{ | ||
id:string, | ||
version:string | ||
} | ||
export default function(props:VersionFilesProps){ | ||
const [fileList, setFileList] = useState(Array<string>()) | ||
useEffect( ()=>{ | ||
axios.get("/v1/plugins/"+props.id+"/"+props.version+"/").then(res=>setFileList(res.data.response)) | ||
},[]) | ||
return ( | ||
<> | ||
<h5>共{fileList.length}个附件</h5> | ||
{fileList.map((item,index)=><h5 key={index}>{item}</h5>)} | ||
</> | ||
) | ||
} |
27 changes: 27 additions & 0 deletions
27
frontend/src/components/Plugin/EditForm/VersionControl/VersionList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {PluginInfoFormParams} from "../../EditPluginForm"; | ||
import {useEffect, useState} from "react"; | ||
import axios from "axios"; | ||
import {Collapse} from "antd"; | ||
import CollapsePanel from "antd/es/collapse/CollapsePanel"; | ||
import FileList from "./FileList"; | ||
|
||
export default function(props:PluginInfoFormParams){ | ||
const [versionList,setVersionList] = useState(Array<string>()) | ||
useEffect( ()=>{ | ||
axios.get("/v1/plugins/"+props.info.id+"/versionList").then(res=>setVersionList(res.data.response)) | ||
},[]) | ||
|
||
function callback(key:any) { | ||
console.log(key); | ||
} | ||
|
||
return( | ||
<Collapse defaultActiveKey={[]} onChange={callback}> | ||
{versionList.map((item,index)=>{ | ||
return <CollapsePanel header={item} key={index}> | ||
<FileList id={props.info.id} version={item}/> | ||
</CollapsePanel> | ||
})} | ||
</Collapse> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from "react"; | ||
import {BasicPluginInfo} from "../../models/Plugin"; | ||
import EditPluginInfoForm from "./EditForm/EditPluginInfoForm"; | ||
import PluginVersionControlForm from "./EditForm/PluginVersionControlForm"; | ||
|
||
export interface PluginInfoFormParams { | ||
loading:boolean | ||
info:BasicPluginInfo | ||
} | ||
|
||
export default function(props:PluginInfoFormParams) { | ||
return <> | ||
<EditPluginInfoForm {...props}/> | ||
<PluginVersionControlForm {...props}/> | ||
</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {Button, Result} from "antd"; | ||
import React from "react"; | ||
import {useHistory} from "react-router"; | ||
|
||
export default function (){ | ||
const history = useHistory() | ||
return ( | ||
|
||
<div | ||
style={{ | ||
height: '40vh', | ||
}} | ||
> | ||
<Result | ||
style={{ | ||
height: '100%', | ||
background: '#fff', | ||
}} | ||
status="warning" | ||
title="错误" | ||
subTitle="您查找的ID并不存在" | ||
extra={<Button onClick={()=>history.push("")}>返回主页</Button>} | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters