diff --git a/src/components/Upload/index.vue b/src/components/Upload/index.vue index 71bb0015a856ef68f945cba1d383cdd9a36d6f7a..00fafe68ab40c4a0b2f495003fad386a18a86481 100644 --- a/src/components/Upload/index.vue +++ b/src/components/Upload/index.vue @@ -6,18 +6,22 @@ import { IconUpload, IconVisible, IconDelete, IconCaretRight } from '@computing/ import type { UploadFile, ElUploadProgressEvent, ElFile } from 'element-plus/es/components/upload/src/upload.type'; import { Codemirror } from 'vue-codemirror'; import { api } from 'src/apis'; -import { successMsg } from 'src/components/Message'; +import { errorMsg, successMsg } from 'src/components/Message'; -const handleCreateapi = () => { - api - .createOrUpdateApi({ - serviceId: props.serviceId||'', - data:yamlToJsonContent.value, - }) - .then(res => { +const handleCreateapi = async () => { + const [_, res] = await api.createOrUpdateApi({ + serviceId: props.serviceId || '', + data: yamlToJsonContent.value, + }); + if (!_ && res) { + if (res.code === 200) { getServiceJson.value = res[1]?.result?.apis; uploadtype.value = 'get'; - }); + successMsg('创建成功'); + } else { + errorMsg('创建失败'); + } + } }; const props = defineProps({ @@ -58,24 +62,11 @@ const handleClose = () => { emits('closeDrawer'); }; -const handleEditClose = () => { - //清空数据 - // getServiceYaml.value = ''; - // yamlToJsonContent.value = ''; - // getServiceJson.value = ''; - emits('closeDrawer'); -}; - const handleEdit = () => { //edit数据 successMsg('可编辑'); editable.value = true; }; -const data = [ - {path:'212121',description:"23213123"}, - {path:'ndie',description:"23213123"}, - {path:'nidanide1',description:"23213123"}, -] const uploadtype = ref(props.type); const getServiceYaml = ref(''); @@ -88,7 +79,11 @@ const uploadDone = ref(false); const editable = ref(false); // 上传前检查 const beforeUpload = async (file: ElFile) => { - const isYaml = file.type === 'application/x-yaml' || file.type === 'text/yaml' || file.name.indexOf('.yaml') > -1 || file.name.indexOf('.yml') > -1; // 也可能遇到 text/yaml 类型 + const isYaml = + file.type === 'application/x-yaml' || + file.type === 'text/yaml' || + file.name.indexOf('.yaml') > -1 || + file.name.indexOf('.yml') > -1; // 也可能遇到 text/yaml 类型 const isLt2M = file.size / 1024 / 1024 < 2; if (!isYaml) { ElMessage({ @@ -165,13 +160,13 @@ const doPreview = (e: Event) => { }; const getServiceYamlFun = async (id: string) => { - await api.querySingleApiData({serviceId:id,edit:true}).then((res) => { - if(res) { - getServiceYaml.value = jsYaml.dump(res[1]?.result.data); - } - }) -} -const handleChange = (payload) => { + await api.querySingleApiData({ serviceId: id, edit: true }).then(res => { + if (res) { + getServiceYaml.value = jsYaml.dump(res[1]?.result.data); + } + }); +}; +const handleChange = payload => { yamlToJsonContent.value = jsYaml.load(payload); setTimeout(() => { payload.view.scrollDOM.scrollTop = 0; @@ -182,7 +177,7 @@ watch( () => { getServiceJson.value = props.getServiceJson; getServiceYaml.value = props.getServiceYaml; - console.log(props, 'props---result') + console.log(props, 'props---result'); if (getServiceJson.value?.length) { activeServiceNameList.value = [getServiceJson.value?.[0]?.name]; } @@ -197,8 +192,8 @@ watch( () => getServiceYaml, () => { yamlToJsonContent.value = jsYaml.load(getServiceYaml.value); - } -) + }, +);