|
@@ -9,7 +9,7 @@
|
|
|
</div>
|
|
|
|
|
|
<div class="command-container">
|
|
|
- <van-swipe-cell v-for="item in commandList" :key="item.id" :disabled="touchStatus">
|
|
|
+ <van-swipe-cell v-for="item in crtProject!.commandList" :key="item.id" :disabled="touchStatus">
|
|
|
<van-cell
|
|
|
clickable
|
|
|
:border="false"
|
|
@@ -79,13 +79,12 @@ const router = useRouter()
|
|
|
|
|
|
const { projectList } = storeToRefs(useGlobalStore())
|
|
|
const crtProject = ref<ProjectType>()
|
|
|
-const commandList = ref<CommandType[]>([])
|
|
|
|
|
|
watch(
|
|
|
() => route,
|
|
|
() => {
|
|
|
crtProject.value = projectList.value.find((item) => item.id === route.params.id)
|
|
|
- commandList.value = crtProject.value!.commandList
|
|
|
+ // commandList.value = crtProject.value!.commandList
|
|
|
},
|
|
|
{
|
|
|
deep: true,
|
|
@@ -141,21 +140,22 @@ const handleCancel = async () => {
|
|
|
}
|
|
|
|
|
|
const handleDelete = (val: string) => {
|
|
|
- console.log(val)
|
|
|
- console.log(commandList.value)
|
|
|
if (val) {
|
|
|
- commandList.value = commandList.value.filter((item) => item.id !== val)
|
|
|
+ const project = projectList.value.find((item) => (item.id = crtProject.value!.id))
|
|
|
+ if (project) {
|
|
|
+ project.commandList = project.commandList.filter((item) => item.id !== val)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const handleAddCommond = () => {
|
|
|
- let name = `任务${commandList.value.length + 1}`
|
|
|
- if (commandList.value.length) {
|
|
|
- const beforeName = commandList.value[commandList.value.length - 1].name
|
|
|
+ let name = `任务${crtProject.value!.commandList.length + 1}`
|
|
|
+ if (crtProject.value!.commandList.length) {
|
|
|
+ const beforeName = crtProject.value!.commandList[crtProject.value!.commandList.length - 1].name
|
|
|
const index = beforeName.split('任务')[1]
|
|
|
name = `任务${+index + 1}`
|
|
|
}
|
|
|
- commandList.value.push({
|
|
|
+ crtProject.value!.commandList.push({
|
|
|
id: '' + Date.now(),
|
|
|
name,
|
|
|
time: new Date().toLocaleString(),
|
|
@@ -169,6 +169,12 @@ const handleAddCommond = () => {
|
|
|
// 文件编译
|
|
|
const getXMLFile = () => {
|
|
|
if (!crtProject.value) return
|
|
|
+ if (crtProject.value.commandList.length === 0) return showFailToast('请先添加任务')
|
|
|
+ if (crtProject.value.commandList.length === 1 && crtProject.value.commandList[0].stepList.length === 0) {
|
|
|
+ return showFailToast('任务内容为空')
|
|
|
+ }
|
|
|
+ const isExistExec = crtProject.value.commandList.some((item) => item.stepList.some((cItem) => cItem.type === 'exec' && cItem.list?.length !== 0))
|
|
|
+ if (!isExistExec) return showFailToast('请先添加执行任务')
|
|
|
let xml = ''
|
|
|
// 头部
|
|
|
xml += `<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -244,6 +250,7 @@ const getXMLFile = () => {
|
|
|
</variable>`
|
|
|
})
|
|
|
crtProject.value.commandList.forEach((item, index) => {
|
|
|
+ if (!item.stepList.some(cItem => cItem.type === 'exec' && cItem.list?.length !== 0)) return
|
|
|
instanceXml += `<pouInstance name="instance${index}" typeName="program${index}"/>`
|
|
|
xml += `<pou name="program${index}" pouType="program">
|
|
|
<interface>
|
|
@@ -1360,15 +1367,25 @@ const getXMLFile = () => {
|
|
|
|
|
|
console.log(xml)
|
|
|
// 生成文件下载
|
|
|
- const blob = new Blob([xml], { type: 'text/plain;charset=utf-8' })
|
|
|
- const formdata = new FormData()
|
|
|
- formdata.append('file', blob, 'project.xml')
|
|
|
- fetch('http://192.168.88.1:8080/api/upload', {
|
|
|
+ // const blob = new Blob([xml], { type: 'text/plain;charset=utf-8' })
|
|
|
+ // const formdata = new FormData()
|
|
|
+ // formdata.append('file', blob, 'project.xml')
|
|
|
+ const params = {
|
|
|
+ devicetype: 'PLC101',
|
|
|
+ xml
|
|
|
+ }
|
|
|
+ fetch('https://plceditor.worldflying.cn/api/build/buildcode', {
|
|
|
method: 'POST',
|
|
|
- body: formdata
|
|
|
- }).then((res) => res.json()).then((res) => {
|
|
|
- console.log(res)
|
|
|
+ body: JSON.stringify(params),
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
+ 'Content-Length': xml.length + ''
|
|
|
+ }
|
|
|
})
|
|
|
+ .then((res) => res.json())
|
|
|
+ .then((res) => {
|
|
|
+ console.log(res)
|
|
|
+ })
|
|
|
|
|
|
// const link = document.createElement('a')
|
|
|
// link.href = URL.createObjectURL(blob)
|