|
| 1 | +import React from 'react'; |
| 2 | +import {ModalForm, ProFormSelect, ProFormText, ProFormTextArea} from '@ant-design/pro-components'; |
| 3 | +import defaultData from "@/utils/defaultData.json"; |
| 4 | +import {Button, message} from "antd"; |
| 5 | +import _ from "lodash"; |
| 6 | +import {addProject} from "@/services/project"; |
| 7 | +import {addGroupProject} from "@/services/group-project"; |
| 8 | +import {CopyOutlined} from "@ant-design/icons"; |
| 9 | +import useProjectStore from "@/store/project/useProjectStore"; |
| 10 | +import shallow from "zustand/shallow"; |
| 11 | + |
| 12 | +export type CopyProjectProps = { |
| 13 | + projectJSON: any; |
| 14 | +}; |
| 15 | + |
| 16 | +const CopyProject: React.FC<CopyProjectProps> = (props) => { |
| 17 | + const {profile, dataTypeDomains} = useProjectStore(state => ({ |
| 18 | + profile: state.project?.projectJSON?.profile, |
| 19 | + dataTypeDomains: state.project?.projectJSON?.dataTypeDomains, |
| 20 | + }), shallow); |
| 21 | + const emptyProject = { |
| 22 | + "projectName": "", |
| 23 | + "description": "", |
| 24 | + "tags": "", |
| 25 | + "projectJSON": { |
| 26 | + ...defaultData |
| 27 | + }, |
| 28 | + "configJSON": {synchronous: {upgradeType: "increment"}}, |
| 29 | + } |
| 30 | + |
| 31 | + |
| 32 | + return (<> |
| 33 | + <ModalForm |
| 34 | + title="复刻为新项目(从当前版本创建新项目)" |
| 35 | + trigger={ |
| 36 | + <Button key="copy" size={"small"} type={"link"} icon={<CopyOutlined/>}>复刻</Button> |
| 37 | + } |
| 38 | + onFinish={async (values: any) => { |
| 39 | + |
| 40 | + console.log(39, values); |
| 41 | + console.log(39, props.projectJSON); |
| 42 | + if (values.type.value === 1) { |
| 43 | + addProject({ |
| 44 | + ...emptyProject, |
| 45 | + projectJSON: { |
| 46 | + profile, |
| 47 | + dataTypeDomains, |
| 48 | + modules: props.projectJSON?.modules || emptyProject.projectJSON.modules |
| 49 | + }, |
| 50 | + projectName: values.projectName, |
| 51 | + description: values.description, |
| 52 | + tags: _.join(values.tags, ',') |
| 53 | + }).then((r) => { |
| 54 | + console.log(54, r); |
| 55 | + if (r.code === 200) { |
| 56 | + message.success( |
| 57 | + <> |
| 58 | + 复刻成功, |
| 59 | + <a href="/project/recent">立即打开</a> |
| 60 | + </>, 5 |
| 61 | + ); |
| 62 | + } |
| 63 | + }); |
| 64 | + } else { |
| 65 | + addGroupProject({ |
| 66 | + ...emptyProject, |
| 67 | + projectJSON: { |
| 68 | + profile, |
| 69 | + dataTypeDomains, |
| 70 | + modules: props.projectJSON?.modules || emptyProject.projectJSON.modules |
| 71 | + }, |
| 72 | + projectName: values.projectName, |
| 73 | + description: values.description, |
| 74 | + tags: _.join(values.tags, ',') |
| 75 | + }).then((r) => { |
| 76 | + console.log(54, r); |
| 77 | + if (r.code === 200) { |
| 78 | + message.success( |
| 79 | + <> |
| 80 | + 复刻成功, |
| 81 | + <a href="/project/recent">立即打开</a> |
| 82 | + </>, 5 |
| 83 | + ); |
| 84 | + } |
| 85 | + }); |
| 86 | + } |
| 87 | + }} |
| 88 | + > |
| 89 | + <ProFormText |
| 90 | + width="md" |
| 91 | + name="projectName" |
| 92 | + label="项目名" |
| 93 | + placeholder="请输入项目名" |
| 94 | + formItemProps={{ |
| 95 | + rules: [ |
| 96 | + { |
| 97 | + required: true, |
| 98 | + message: '不能为空', |
| 99 | + }, |
| 100 | + { |
| 101 | + max: 100, |
| 102 | + message: '不能大于 100 个字符', |
| 103 | + }, |
| 104 | + ], |
| 105 | + }} |
| 106 | + /> |
| 107 | + <ProFormSelect |
| 108 | + name="type" |
| 109 | + width="md" |
| 110 | + label="项目类型" |
| 111 | + fieldProps={{ |
| 112 | + labelInValue: true, |
| 113 | + }} |
| 114 | + options={[ |
| 115 | + {label: '个人项目', value: 1}, |
| 116 | + {label: '团队项目', value: 2}, |
| 117 | + ]} |
| 118 | + /> |
| 119 | + <ProFormSelect |
| 120 | + width="md" |
| 121 | + name="tags" |
| 122 | + label="标签" |
| 123 | + placeholder="请输入项目标签,按回车分割" |
| 124 | + formItemProps={{ |
| 125 | + rules: [ |
| 126 | + { |
| 127 | + required: true, |
| 128 | + message: '不能为空', |
| 129 | + }, |
| 130 | + ], |
| 131 | + }} |
| 132 | + fieldProps={{ |
| 133 | + mode: "tags", |
| 134 | + tokenSeparators: [','] |
| 135 | + }} |
| 136 | + /> |
| 137 | + |
| 138 | + <ProFormTextArea |
| 139 | + width="md" |
| 140 | + name="description" |
| 141 | + label="项目描述" |
| 142 | + placeholder="请输入项目描述" |
| 143 | + formItemProps={{ |
| 144 | + rules: [ |
| 145 | + { |
| 146 | + required: true, |
| 147 | + message: '不能为空', |
| 148 | + }, |
| 149 | + { |
| 150 | + max: 100, |
| 151 | + message: '不能大于 100 个字符', |
| 152 | + }, |
| 153 | + ], |
| 154 | + }} |
| 155 | + /> |
| 156 | + </ModalForm> |
| 157 | + </>); |
| 158 | +} |
| 159 | + |
| 160 | +export default React.memo(CopyProject) |
0 commit comments