123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995 |
- <template>
- <div class="project-info">
- <div class="header">
- <div class="go-back" @click="router.replace({ name: 'Automate' })">
- <van-button size="small"><van-icon name="arrow-left" />返回</van-button>
- </div>
- <div class="project-name">
- <div class="name">
- {{ crtProject!.name }}
- </div>
- <van-tag type="primary" v-show="crtProject?.isCompiled" size="medium">已编译</van-tag>
- <van-tag type="warning" v-show="!crtProject?.isCompiled" size="medium">未编译</van-tag>
- </div>
- <div class="more"><van-button type="primary" size="small" @click="showMorePopup = true">更多</van-button></div>
- </div>
- <div class="command-container">
- <van-swipe-cell v-for="item in crtProject!.commandList" :key="item.id">
- <van-cell
- clickable
- :border="false"
- :title="item.name"
- :label="item.time"
- @click="router.push(`/command-info/${crtProject!.id}/${item.id}`)"
- >
- <template #right-icon>
- <i class="iconfont icon-copy" @click.stop="copyCommand(item)"></i>
- </template>
- </van-cell>
- <template #right>
- <van-button square type="danger" text="删除" class="del-button" @click="handleDelete(item.id)" />
- </template>
- </van-swipe-cell>
- </div>
- <div class="add-btn">
- <van-button type="primary" block @click="handleAddCommond">添加任务</van-button>
- </div>
- <van-popup v-model:show="showMorePopup" position="right" :style="{ width: '50%', height: '100%' }">
- <template v-if="showMorePopup">
- <van-cell-group :style="{ marginTop: '16px' }">
- <van-cell title="编辑工程名称" clickable @click="handleEditName" :title-style="{ color: '#07c160' }" />
- <van-cell title="编译文件" @click="get_c_code('wx')" clickable :title-style="{ color: '#1989fa' }" />
- <van-cell clickable v-show="crtProject?.isCompiled">
- <template #title>
- <div v-html="wxtag" class="wx-tag"></div>
- </template>
- </van-cell>
- <van-cell title="仿真模拟" @click="get_c_code('wxsimu')" clickable :title-style="{ color: '#1989fa' }" />
- <van-cell title="删除工程" @click="delProject" clickable :title-style="{ color: '#fd5632' }" />
- <van-cell clickable v-if="isInWx">
- <template #title>
- <div v-html="wxShareTag" class="wx-tag"></div>
- </template>
- </van-cell>
- <!-- <van-cell title="分享" @click="shareProject" clickable /> -->
- </van-cell-group>
- </template>
- </van-popup>
- <van-popup v-model:show="showEditPopup" round :style="{ width: '80%' }">
- <div class="label" style="margin: 16px">编辑工程名称</div>
- <van-form @submit="onSubmit">
- <van-cell-group inset>
- <van-field
- border
- v-model="newProjectName"
- name="newProjectName"
- placeholder="工程名称"
- maxlength="20"
- :rules="[{ required: true, message: '请填写工程名称' }]"
- />
- </van-cell-group>
- <div class="van-button-group">
- <van-button @click="handleCancel" size="small">取消</van-button>
- <van-button type="primary" native-type="submit" size="small">确定</van-button>
- </div>
- </van-form>
- </van-popup>
- <van-popup v-model:show="showSharePopup" round :style="{ width: '80%' }">
- <div class="share-container">
- <!-- <canvas ref="qrcodeCanvas"></canvas> -->
- <img :src="shareImg" alt="" width="100%" />
- <div class="tip">长按图片进行分享</div>
- </div>
- </van-popup>
- </div>
- </template>
- <script setup lang="ts">
- import { useGlobalStore } from '@/stores/global'
- import type { CommandType, ProjectType } from '@/types/global'
- import { formatDateTime, deepEqual, deepClone } from '@/utils/tools'
- import { storeToRefs } from 'pinia'
- import { v4 as uuid4 } from 'uuid'
- import { showConfirmDialog, showLoadingToast, showFailToast } from 'vant'
- import qrcode from 'qrcode'
- const route = useRoute()
- const router = useRouter()
- const { projectList } = storeToRefs(useGlobalStore())
- const crtProject = ref<ProjectType>()
- const wxtag = ref('')
- const wxShareTag = ref('')
- const isInWx = window.isInWx
- let wx = window.wx
- // fetch('https://plceditor.worldflying.cn/api/build/getjsconfig', {
- // method: 'POST',
- // body: JSON.stringify({ url: location.origin + location.pathname + location.search })
- // })
- // .then((res) => res.json())
- // .then((res) => {
- // wx.config(res.data)
- // wx.ready(function () {
- // console.log('微信初始化成功')
- // showWxAppBtn.value = true
- // })
- // wx.error(function (res: any) {
- // console.log('微信初始化失败', res)
- // })
- // })
- const initWxEnv = () => {
- if (!window.isInWx) return showFailToast('请在微信中打开')
- const url = location.origin + location.pathname + location.search
- const wxConfigStr = localStorage.getItem(url)
- if (!wxConfigStr) showFailToast('初始化失败')
- else {
- const wxConfig = JSON.parse(wxConfigStr)
- wx.config(wxConfig)
- wx.ready(function () {
- console.log('微信初始化成功')
- })
- wx.error(function (res: any) {
- console.log('微信初始化失败', res)
- })
- }
- }
- initWxEnv()
- watch(
- () => route,
- () => {
- crtProject.value = projectList.value.find((item) => item.id === route.params.id)
- // console.log(JSON.stringify(crtProject.value))
- wxShareTag.value = `<wx-open-launch-weapp appid="wx4c5a777c71f2981c" style="width: 100%;" path="pages/sharefile/index?content=${encodeURIComponent(JSON.stringify({ ...crtProject.value, qrcodeType: 'worldflying_plc_editor' }))}&filename=${crtProject.value?.name}.jmpec"><template><text style="color: #896ef4;">分享</text></template></wx-open-launch-weapp>`
- let imgobjStr = localStorage.getItem('imgobj' + crtProject.value!.id)
- if (imgobjStr) {
- try {
- let imgobj = JSON.parse(imgobjStr)
- let now = new Date().getTime() // 当前时间戳
- if (now < imgobj.deadline) {
- crtProject.value!.isCompiled = true
- wxtag.value = `<wx-open-launch-weapp appid="wx4c5a777c71f2981c" style="width: 100%;" path="pages/index/rj45cfgbybt/plc/index?imgurl=${imgobj.url}"><template><text style="color: #7232dd;">烧录设备</text></template></wx-open-launch-weapp>`
- } else {
- crtProject.value!.isCompiled = false
- localStorage.removeItem('imgobj' + crtProject.value!.id)
- }
- } catch (e) {
- console.log(e)
- }
- }
- },
- {
- deep: true,
- immediate: true,
- once: true
- }
- )
- const showMorePopup = ref(false)
- const handleEditName = () => {
- showEditPopup.value = true
- showMorePopup.value = false
- newProjectName.value = crtProject.value!.name
- }
- const showEditPopup = ref(false)
- const newProjectName = ref('')
- const onSubmit = (values: Record<string, string>) => {
- console.log(values)
- const isExist = projectList.value.some(
- (item) => item.name === values.newProjectName && item.id !== crtProject.value?.id
- )
- if (isExist) {
- showFailToast('工程名称已存在')
- return
- } else {
- crtProject.value!.name = values.newProjectName
- wxShareTag.value = `<wx-open-launch-weapp appid="wx4c5a777c71f2981c" style="width: 100%;" path="pages/sharefile/index?content=${encodeURIComponent(JSON.stringify({ ...crtProject.value, qrcodeType: 'worldflying_plc_editor' }))}&filename=${crtProject.value?.name}.jmpec"><template><text style="color: #896ef4;">分享</text></template></wx-open-launch-weapp>`
- console.log(wxShareTag.value)
- handleCancel()
- }
- }
- const handleCancel = async () => {
- showEditPopup.value = false
- await nextTick()
- newProjectName.value = ''
- }
- const handleDelete = (val: string) => {
- if (val) {
- const project = projectList.value.find((item) => (item.id = crtProject.value!.id))
- if (project) {
- if (project.commandList.length === 1) return showFailToast('请至少保留一个任务!')
- project.commandList = project.commandList.filter((item) => item.id !== val)
- crtProject.value!.commandList = crtProject.value!.commandList.filter((item) => item.id !== val)
- if (crtProject.value?.isCompiled) {
- crtProject.value.isCompiled = false
- localStorage.removeItem('imgobj' + crtProject.value!.id)
- }
- }
- }
- }
- let flag = false
- let timer: any
- const handleAddCommond = () => {
- if (flag) return
- if (timer) clearTimeout(timer)
- flag = true
- // const lastCmdName = crtProject.value?.commandList[0].name || '任务'
- // const baseName = lastCmdName.replace(/\s*\-\d+/, '')
- let maxSuffix = 0
- // 遍历任务列表,找到与基础名称匹配的最大编号
- crtProject.value?.commandList.forEach((item) => {
- if (item.name.startsWith('任务')) {
- const match = item.name.match(/\-(\d+)/) // 匹配末尾的 "(数字)"
- if (match) {
- const suffix = parseInt(match[1], 10)
- if (suffix > maxSuffix) {
- maxSuffix = suffix
- }
- }
- }
- })
- // 生成新的任务名称
- const newSuffix = maxSuffix + 1
- const name = `任务-${newSuffix}`
- // let name = `任务${Math.floor(Date.now())}`
- crtProject.value!.commandList.unshift({
- id: '' + Date.now(),
- name,
- time: new Date().toLocaleString(),
- stepList: [],
- // x: 100,
- // y: 100 + crtProject.value!.commandList.length * 2000,
- parentId: crtProject.value!.id
- })
- if (crtProject.value?.isCompiled) {
- crtProject.value.isCompiled = false
- localStorage.removeItem('imgobj' + crtProject.value!.id)
- }
- timer = setTimeout(() => {
- flag = false
- }, 500)
- }
- // 文件编译
- // 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('任务内容为空!')
- // }
- // if (crtProject.value.isCompiled) {
- // return showFailToast('工程已编译!')
- // }
- // const isExistExec = crtProject.value.commandList.some((item) =>
- // item.stepList.some((cItem) => cItem.type === 'exec' && cItem.list?.length !== 0)
- // )
- // if (!isExistExec) return showFailToast('请先添加执行任务!')
- // const loading = showLoadingToast({
- // message: '正在编译中...',
- // forbidClick: true,
- // duration: 0
- // })
- // let xml = ''
- // // 头部
- // xml += `<?xml version="1.0" encoding="UTF-8"?>
- // <project xmlns="http://www.plcopen.org/xml/tc6_0201" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:ns1="http://www.plcopen.org/xml/tc6.xsd">
- // <fileHeader companyName="${'未知'}" productName="${'未命名'}" productVersion="1.0" creationDateTime="${formatDateTime(new Date(), 'T')}" />
- // <contentHeader name="${crtProject.value.name}" modificationDateTime="${formatDateTime(new Date(), 'T')}">
- // <coordinateInfo>
- // <fbd>
- // <scaling x="10" y="10"/>
- // </fbd>
- // <ld>
- // <scaling x="10" y="10"/>
- // </ld>
- // <sfc>
- // <scaling x="10" y="10"/>
- // </sfc>
- // </coordinateInfo>
- // </contentHeader>
- // <types>
- // <dataTypes/>
- // <pous>
- // `
- // // <pou name="proogram0" pouType="program">
- // // <interface>
- // // <localVars>
- // const commandVarMap: Record<string, string> = {}
- // const weekMap: Record<string, number> = {
- // 周一: 4,
- // 周二: 5,
- // 周三: 6,
- // 周四: 0,
- // 周五: 1,
- // 周六: 2,
- // 周日: 3
- // }
- // const globalVarList = [
- // 'DI0',
- // 'DI1',
- // 'DI2',
- // 'DI3',
- // 'DI4',
- // 'DI5',
- // 'DI6',
- // 'DI7',
- // 'DI8',
- // 'DI9',
- // 'AI0',
- // 'AI1',
- // 'AI2',
- // 'AI3',
- // 'DO0',
- // 'DO1',
- // 'DO2',
- // 'DO3',
- // 'DO4',
- // 'DO5',
- // 'DO6',
- // 'DO7',
- // 'DO8',
- // 'DO9',
- // 'AO0',
- // 'AO1'
- // ]
- // let instanceXml = ''
- // let globalVarsXml = ''
- // globalVarList.forEach((item) => {
- // globalVarsXml += `<variable name="${item}">
- // <type><${item.includes('A') ? 'UINT' : 'BOOL'} /></type>
- // </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>
- // <externalVars>
- // ${globalVarsXml}
- // <variable name="CRT_DATA">
- // <type><DT /></type>
- // </variable>
- // </externalVars>
- // <localVars>
- // <variable name="MOD_HOUR">
- // <type><ULINT /></type>
- // <initialValue>
- // <simpleValue value="24" />
- // </initialValue>
- // </variable>
- // <variable name="HOURS">
- // <type><ULINT /></type>
- // <initialValue>
- // <simpleValue value="3600" />
- // </initialValue>
- // </variable>
- // <variable name="DAYS">
- // <type><ULINT /></type>
- // <initialValue>
- // <simpleValue value="86400" />
- // </initialValue>
- // </variable>
- // <variable name="MOD_WEEK">
- // <type><ULINT /></type>
- // <initialValue>
- // <simpleValue value="7" />
- // </initialValue>
- // </variable>
- // <variable name="MINUTE">
- // <type><ULINT /></type>
- // <initialValue>
- // <simpleValue value="60" />
- // </initialValue>
- // </variable>
- // <variable name="MUL_NUM">
- // <type><INT /></type>
- // <initialValue>
- // <simpleValue value="1" />
- // </initialValue>
- // </variable>
- // `
- // // 临时变量
- // // const tempVarNum = item.stepList.filter((cItem) => cItem.type === 'condition').length
- // const tempVarNum = item.stepList.length
- // for (let i = 1; i <= tempVarNum; i++) {
- // xml += `<variable name="temp${i - 1}">
- // <type><BOOL /></type>
- // </variable>`
- // }
- // // 定义所需变量
- // item.stepList.forEach((item, index) => {
- // if (item.type === 'delay') {
- // // RTC 数量
- // xml += `<variable name="TON${index}">
- // <type>
- // <derived name="TON" />
- // </type>
- // </variable>
- // <variable name="PT${index}">
- // <type>
- // <TIME />
- // </type>
- // <initialValue>
- // <simpleValue value="T#${item.value}s" />
- // </initialValue>
- // </variable>`
- // } else {
- // item.list?.forEach((cItem, cIndex) => {
- // // PT 数量
- // if (cItem.type === 'time') {
- // xml += `<variable name="RTC${index}_${cIndex}">
- // <type>
- // <derived name="RTC" />
- // </type>
- // </variable>`
- // const timeArr = cItem.value.split(':')
- // xml += `<variable name="HOUR${index}_${cIndex}">
- // <type><ULINT /></type>
- // <initialValue>
- // <simpleValue value="${+timeArr[0]}" />
- // </initialValue>
- // </variable>`
- // xml += `<variable name="MIN${index}_${cIndex}">
- // <type><ULINT /></type>
- // <initialValue>
- // <simpleValue value="${+timeArr[1]}" />
- // </initialValue>
- // </variable>`
- // if (Object.keys(weekMap).includes(cItem.label)) {
- // xml += `<variable name="RTC${index}_${cIndex}_WEEK">
- // <type><ULINT /></type>
- // <initialValue>
- // <simpleValue value="${weekMap[cItem.label]}" />
- // </initialValue>
- // </variable>`
- // } else if (cItem.label !== '每天') {
- // const timeArr = cItem.value.split('-')
- // xml += `<variable name="RTC${index}_${cIndex}_START">
- // <type><ULINT /></type>
- // <initialValue>
- // <simpleValue value="${new Date(timeArr[0] + '').getTime() / 1000}" />
- // </initialValue>
- // </variable>`
- // xml += `<variable name="RTC${index}_${cIndex}_END">
- // <type><ULINT /></type>
- // <initialValue>
- // <simpleValue value="${new Date(timeArr[2] + '').getTime() / 1000}" />
- // </initialValue>
- // </variable>`
- // }
- // } else if (cItem.type === 'input' && cItem.label.includes('AI')) {
- // // 判断AI变量
- // xml += `<variable name="COMPARE_AI${index}_${cIndex}">
- // <type><UINT /></type>
- // <initialValue>
- // <simpleValue value="${+cItem.value * 100}" />
- // </initialValue>
- // </variable>`
- // } else if (cItem.type === 'output' && cItem.label.includes('AO')) {
- // // 赋值AO变量
- // xml += `<variable name="SET_AI${index}_${cIndex}">
- // <type><UINT /></type>
- // <initialValue>
- // <simpleValue value="${+cItem.value * 100}" />
- // </initialValue>
- // </variable>`
- // }
- // })
- // }
- // })
- // xml += `</localVars></interface>`
- // xml += `<body><LD>`
- // // 左侧电源导轨
- // const firstStep = item.stepList[0]
- // // const powerRailH = firstStep.type === 'delay' ? 40 : 40 + 20 * firstStep.list!.length
- // xml += `<leftPowerRail localId="${item.id}" width="20" height="40">
- // <position x="${item.x}" y="${item.y}"/>`
- // // if (firstStep.type === 'delay') {
- // xml += `<connectionPointOut formalParameter="">`
- // xml += `<relPosition x="40" y="20"/>`
- // xml += `</connectionPointOut>`
- // // } else {
- // // for (let i = 1; i <= firstStep.list!.length; i++) {
- // // xml += `<connectionPointOut formalParameter="">`
- // // xml += `<relPosition x="20" y="${20 * i}"/>`
- // // xml += `</connectionPointOut>`
- // // }
- // // }
- // xml += `</leftPowerRail>`
- // let tempVarId = `99${index}`
- // item.stepList.forEach((sItem, sIndex) => {
- // let tempXML = ''
- // let tempConnectXML = ''
- // if (sItem.type === 'condition' || sItem.type === 'exec') {
- // for (let i = 0; i < sItem.list!.length; i++) {
- // const cItem = sItem.list![i]
- // if (cItem.label.includes('DI') || cItem.label.includes('DO')) {
- // xml += `<${cItem.label.includes('DI') ? 'contact' : 'coil'} localId="${cItem.id}" negated="${cItem.value === '打开'}" width="40" height="40">`
- // xml += `<position x="${cItem.x}" y="${cItem.y}" />
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${sIndex === 0 ? item.id : tempVarId}">
- // <position x="${sIndex === 0 ? item.x + 40 : sItem.x - 40}" y="${sItem.y + 20}" />
- // <position x="${cItem.x - 20}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // <connectionPointOut>
- // <relPosition x="60" y="20"/>
- // </connectionPointOut>
- // <variable>${cItem.label}</variable>
- // `
- // xml += `</${cItem.label.includes('DI') ? 'contact' : 'coil'}>`
- // tempConnectXML += `
- // <connection refLocalId="${cItem.id}" >
- // <position x="${cItem.x + 60}" y="${cItem.y + 20}" />
- // <position x="${sItem.x - 120}" y="${sItem.y + 20}" />
- // </connection>`
- // } else if (cItem.type === 'time') {
- // let setTimeVarID = `${index + 1}${sIndex}${i}11`
- // // 赋值当前时间
- // xml += `
- // <inVariable localId="${setTimeVarID}" width="40" height="40" negated="false">
- // <position x="${cItem.x - 100}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>CRT_DATA</expression>
- // </inVariable>`
- // let RTCID1 = `${index + 1}${sIndex}${i}12`
- // // 定义RTC变量
- // xml += `
- // <block
- // localId="${RTCID1}"
- // typeName="RTC"
- // instanceName="RTC${sIndex}_${i}"
- // width="80"
- // height="80"
- // >
- // <position x="${cItem.x}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="IN">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${sIndex === 0 ? item.id : tempVarId}">
- // <position x="${sIndex === 0 ? item.x + 40 : sItem.x - 40}" y="${sItem.y + 20}" />
- // <position x="${cItem.x - 20}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="PDT">
- // <connectionPointIn>
- // <relPosition x="-20" y="60" />
- // <connection refLocalId="${setTimeVarID}">
- // <position x="${cItem.x - 40}" y="${cItem.y + 220}" />
- // <position x="${cItem.x - 20}" y="${cItem.y + 60}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="Q">
- // <connectionPointOut>
- // <relPosition x="100" y="20" />
- // </connectionPointOut>
- // </variable>
- // <variable formalParameter="CDT">
- // <connectionPointOut>
- // <relPosition x="100" y="60" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // // DT TO ULINGT
- // let dtToULIntId1 = `${index + 1}${sIndex}${i}13`
- // xml += `
- // <block localId="${dtToULIntId1}" typeName="DT_TO_ULINT" width="100" height="40">
- // <position x="${cItem.x + 200}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="IN">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${RTCID1}" formalParameter="CDT">
- // <position x="${cItem.x + 100}" y="${cItem.y + 60}" />
- // <position x="${cItem.x + 180}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="120" y="20" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>`
- // let joinXML = ''
- // let isJoin = false
- // if (Object.keys(weekMap).includes(cItem.label)) {
- // isJoin = true
- // let varId6 = `${index + 1}${sIndex}${i}14`
- // // 天被除数变量
- // xml += `
- // <inVariable localId="${varId6}" width="40" height="40" negated="false">
- // <position x="${cItem.x + 300}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>DAYS</expression>
- // </inVariable>`
- // let DIVID3 = `${index + 1}${sIndex}${i}15`
- // // 计算天数
- // xml += `
- // <block localId="${DIVID3}" typeName="DIV" width="70" height="60">
- // <position x="${cItem.x + 400}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${dtToULIntId1}" formalParameter="OUT">
- // <position x="${cItem.x + 320}" y="${cItem.y + 20}" />
- // <position x="${cItem.x + 380}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${varId6}">
- // <position x="${cItem.x + 360}" y="${cItem.y + 220}" />
- // <position x="${cItem.x + 380}" y="${cItem.y + 40}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="20" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // let varId7 = `${index + 1}${sIndex}${i}16`
- // // 取模变量
- // xml += `
- // <inVariable localId="${varId7}" width="40" height="40" negated="false">
- // <position x="${cItem.x + 500}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>MOD_WEEK</expression>
- // </inVariable>`
- // let MODID4 = `${index + 1}${sIndex}${i}17`
- // // 计算当前为周几 0为周四
- // xml += `
- // <block localId="${MODID4}" typeName="MOD" width="70" height="60">
- // <position x="${cItem.x + 600}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${DIVID3}" formalParameter="OUT">
- // <position x="${cItem.x + 490}" y="${cItem.y + 20}" />
- // <position x="${cItem.x + 580}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${varId7}">
- // <position x="${cItem.x + 560}" y="${cItem.y + 220}" />
- // <position x="${cItem.x + 580}" y="${cItem.y + 40}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="20" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // // 设置的周几变量
- // let weekVarId = `${index + 1}${sIndex}${i}18`
- // xml += `
- // <inVariable localId="${weekVarId}" width="40" height="40" negated="false">
- // <position x="${cItem.x + 700}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>RTC${sIndex}_${i}_WEEK</expression>
- // </inVariable>`
- // let GTID3 = `${index + 1}${sIndex}${i}19`
- // // 判断是否为指定的周几(等于)
- // xml += `
- // <block localId="${GTID3}" typeName="EQ" width="70" height="60">
- // <position x="${cItem.x + 800}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${MODID4}" formalParameter="OUT">
- // <position x="${cItem.x + 690}" y="${cItem.y + 20}" />
- // <position x="${cItem.x + 780}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${weekVarId}">
- // <position x="${cItem.x + 760}" y="${cItem.y + 20}" />
- // <position x="${cItem.x + 780}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="20" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // joinXML += `
- // <variable formalParameter="EN">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${GTID3}" formalParameter="OUT">
- // <position x="${cItem.x + 890}" y="${cItem.y + 20}" />
- // <position x="${cItem.x + 980}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // `
- // } else if (cItem.label !== '每天') {
- // isJoin = true
- // // 判断是否再日期范围内
- // let startTimeID = `${index + 1}${sIndex}37`
- // let endTimeID = `${index + 1}${sIndex}36`
- // // 开始时间变量
- // xml += `
- // <inVariable localId="${startTimeID}" width="40" height="40" negated="false">
- // <position x="${cItem.x + 300}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>RTC${sIndex}_${i}_START</expression>
- // </inVariable>`
- // // 大于等于最小值
- // let GEID1 = `${index + 1}${sIndex}35`
- // xml += `
- // <block localId="${GEID1}" typeName="GE" width="70" height="60">
- // <position x="${cItem.x + 400}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${dtToULIntId1}" formalParameter="OUT">
- // <position x="${cItem.x + 320}" y="${cItem.y + 20}" />
- // <position x="${cItem.x + 380}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${startTimeID}">
- // <position x="${cItem.x + 360}" y="${cItem.y + 220}" />
- // <position x="${cItem.x + 380}" y="${cItem.y + 40}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="30" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // // 结束时间变量
- // xml += `
- // <inVariable localId="${endTimeID}" width="40" height="40" negated="false">
- // <position x="${cItem.x + 500}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>RTC${sIndex}_${i}_END</expression>
- // </inVariable>`
- // // 小于等于最大值
- // let LEID1 = `${index + 1}${sIndex}34`
- // xml += `
- // <block localId="${LEID1}" typeName="LE" width="70" height="60">
- // <position x="${cItem.x + 600}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="EN">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${GEID1}" formalParameter="OUT">
- // <position x="${cItem.x + 490}" y="${cItem.y + 30}" />
- // <position x="${cItem.x + 580}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${dtToULIntId1}" formalParameter="OUT">
- // <position x="${cItem.x + 320}" y="${cItem.y + 20}" />
- // <position x="${cItem.x + 580}" y="${cItem.y + 40}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="60" />
- // <connection refLocalId="${endTimeID}" formalParameter="OUT">
- // <position x="${cItem.x + 560}" y="${cItem.y + 220}" />
- // <position x="${cItem.x + 580}" y="${cItem.y + 60}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="ENO">
- // <connectionPointOut>
- // <relPosition x="90" y="20" />
- // </connectionPointOut>
- // </variable>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="40" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // joinXML += `
- // <variable formalParameter="EN">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${LEID1}" formalParameter="OUT">
- // <position x="${cItem.x + 690}" y="${cItem.y + 40}" />
- // <position x="${cItem.x + 980}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // `
- // }
- // let varId2 = `${index + 1}${sIndex}${i}20`
- // // 小时被除数
- // xml += `
- // <inVariable localId="${varId2}" width="40" height="40" negated="false">
- // <position x="${cItem.x + 900}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>HOURS</expression>
- // </inVariable>`
- // let DIVID1 = `${index + 1}${sIndex}${i}21`
- // // 计算小时
- // xml += `
- // <block localId="${DIVID1}" typeName="DIV" width="70" height="60">
- // <position x="${cItem.x + 1000}" y="${cItem.y}" />
- // <inputVariables>
- // ${joinXML}
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="${isJoin ? 40 : 20}" />
- // <connection refLocalId="${dtToULIntId1}" formalParameter="OUT">
- // <position x="${cItem.x + 320}" y="${cItem.y + 20}" />
- // <position x="${cItem.x + 980}" y="${cItem.y + (isJoin ? 40 : 20)}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="${isJoin ? 60 : 40}" />
- // <connection refLocalId="${varId2}">
- // <position x="${cItem.x + 960}" y="${cItem.y + 220}" />
- // <position x="${cItem.x + 980}" y="${cItem.y + (isJoin ? 60 : 40)}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // ${
- // isJoin
- // ? `<variable formalParameter="ENO">
- // <connectionPointOut>
- // <relPosition x="90" y="20" />
- // </connectionPointOut>
- // </variable>`
- // : ''
- // }
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="40" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // let varId3 = `${index + 1}${sIndex}${i}22`
- // // 小时取模变量
- // xml += `
- // <inVariable localId="${varId3}" width="40" height="40" negated="false">
- // <position x="${cItem.x + 1100}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>MOD_HOUR</expression>
- // </inVariable>`
- // let MODID1 = `${index + 1}${sIndex}${i}23`
- // // 计算当前时间为几点
- // xml += `
- // <block localId="${MODID1}" typeName="MOD" width="70" height="60">
- // <position x="${cItem.x + 1200}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${DIVID1}" formalParameter="OUT">
- // <position x="${cItem.x + 1090}" y="${cItem.y + 40}" />
- // <position x="${cItem.x + 1180}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${varId3}">
- // <position x="${cItem.x + 1160}" y="${cItem.y + 220}" />
- // <position x="${cItem.x + 1180}" y="${cItem.y + 40}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="20" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // // 设置的小时数变量
- // let hourVarId = `${index + 1}${sIndex}${i}24`
- // xml += `
- // <inVariable localId="${hourVarId}" width="40" height="40" negated="false">
- // <position x="${cItem.x + 1300}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>HOUR${sIndex}_${i}</expression>
- // </inVariable>`
- // let GTID1 = `${index + 1}${sIndex}${i}25`
- // // 判断小时数是否相等
- // xml += `
- // <block localId="${GTID1}" typeName="EQ" width="70" height="60">
- // <position x="${cItem.x + 1400}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${MODID1}" formalParameter="OUT">
- // <position x="${cItem.x + 1290}" y="${cItem.y + 20}" />
- // <position x="${cItem.x + 1380}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${hourVarId}" formalParameter="OUT">
- // <position x="${cItem.x + 1360}" y="${cItem.y + 220}" />
- // <position x="${cItem.x + 1380}" y="${cItem.y + 40}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="20" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // let varId4 = `${index + 1}${sIndex}${i}26`
- // // 分钟被除数
- // xml += `
- // <inVariable localId="${varId4}" width="40" height="40" negated="false">
- // <position x="${cItem.x + 1500}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>MINUTE</expression>
- // </inVariable>`
- // let DIVID2 = `${index + 1}${sIndex}${i}27`
- // // 计算分钟
- // xml += `
- // <block localId="${DIVID2}" typeName="DIV" width="70" height="60">
- // <position x="${cItem.x + 1600}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="EN">
- // <connectionPointIn>
- // <relPosition x="-20" y="20"/>
- // <connection refLocalId="${GTID1}" formalParameter="OUT">
- // <position x="${cItem.x + 1490}" y="${cItem.y + 20}"/>
- // <position x="${cItem.x + 1580}" y="${cItem.y + 20}"/>
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${dtToULIntId1}" formalParameter="OUT">
- // <position x="${cItem.x + 320}" y="${cItem.y + 20}" />
- // <position x="${cItem.x + 1580}" y="${cItem.y + 40}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="60" />
- // <connection refLocalId="${varId4}">
- // <position x="${cItem.x + 1560}" y="${cItem.y + 220}" />
- // <position x="${cItem.x + 1580}" y="${cItem.y + 60}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="ENO">
- // <connectionPointOut>
- // <relPosition x="90" y="20"/>
- // </connectionPointOut>
- // </variable>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="40" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // let varId5 = `${index + 1}${sIndex}${i}28`
- // // 取模变量
- // xml += `
- // <inVariable localId="${varId5}" width="40" height="40" negated="false">
- // <position x="${cItem.x + 1700}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>MINUTE</expression>
- // </inVariable>`
- // let MODID2 = `${index + 1}${sIndex}${i}29`
- // // 计算当前时间为几分
- // xml += `
- // <block localId="${MODID2}" typeName="MOD" width="70" height="60">
- // <position x="${cItem.x + 1800}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${DIVID2}" formalParameter="OUT">
- // <position x="${cItem.x + 1690}" y="${cItem.y + 40}" />
- // <position x="${cItem.x + 1780}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${varId5}">
- // <position x="${cItem.x + 1760}" y="${cItem.y + 220}" />
- // <position x="${cItem.x + 1780}" y="${cItem.y + 40}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="20" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // // 设置的分钟数变量
- // let minVarId = `${index + 1}${sIndex}${i}30`
- // xml += `
- // <inVariable localId="${minVarId}" width="40" height="40" negated="false">
- // <position x="${cItem.x + 1900}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>MIN${sIndex}_${i}</expression>
- // </inVariable>`
- // let GTID2 = `${index + 1}${sIndex}${i}31`
- // // 判断分钟数是否相等
- // xml += `
- // <block localId="${GTID2}" typeName="EQ" width="70" height="60">
- // <position x="${cItem.x + 2000}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${MODID2}" formalParameter="OUT">
- // <position x="${cItem.x + 1990}" y="${cItem.y + 20}" />
- // <position x="${cItem.x + 1980}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${minVarId}">
- // <position x="${cItem.x + 1960}" y="${cItem.y + 220}" />
- // <position x="${cItem.x + 1980}" y="${cItem.y + 40}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="20" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // tempConnectXML += `
- // <connection refLocalId="${GTID2}" formalParameter="OUT">
- // <position x="${cItem.x + 2090}" y="${cItem.y + 20}" />
- // <position x="${sItem.x - 120}" y="${sItem.y + 20}" />
- // </connection>`
- // } else if (cItem.label.includes('AI')) {
- // let compareVarID = `${index + 1}${sIndex}${i}33`
- // // 对AI进行比较的变量
- // xml += `
- // <inVariable localId="${compareVarID}" width="40" height="40" negated="false">
- // <position x="${cItem.x - 100}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>COMPARE_AI${sIndex}_${i}</expression>
- // </inVariable>`
- // // AI变量
- // let AIID = `${index + 1}${sIndex}${i}34`
- // xml += `
- // <inVariable localId="${AIID}" width="40" height="40" negated="false">
- // <position x="${cItem.x - 100}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>${cItem.label}</expression>
- // </inVariable>`
- // let compareBlockID = `${index + 1}${sIndex}${i}35`
- // let operationMap: Record<string, string> = {
- // '≥': 'GE',
- // '≤': 'LE',
- // '>': 'GT',
- // '<': 'LT',
- // '=': 'EQ',
- // '≠': 'NE'
- // }
- // xml += `<block localId="${compareBlockID}" typeName="${operationMap[cItem.operation!]}" width="70" height="60">
- // <position x="${cItem.x}" y="${cItem.y + 200}" />
- // <inputVariables>
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${compareVarID}" formalParameter="OUT">
- // <position x="${cItem.x - 40}" y="${cItem.y + 220}" />
- // <position x="${cItem.x - 20}" y="${cItem.y + 240}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="60" />
- // <connection refLocalId="${AIID}" formalParameter="OUT">
- // <position x="${cItem.x - 40}" y="${cItem.y + 220}" />
- // <position x="${cItem.x - 20}" y="${cItem.y + 260}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="20" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>`
- // tempConnectXML += `
- // <connection refLocalId="${compareBlockID}" formalParameter="OUT">
- // <position x="${cItem.x + 690}" y="${cItem.y + 20}" />
- // <position x="${sItem.x - 120}" y="${sItem.y + 20}" />
- // </connection>`
- // } else if (cItem.label.includes('AO')) {
- // // 乘数id
- // let mulID = `${index + 1}${sIndex}${i}36`
- // xml += `
- // <inVariable localId="${mulID}" width="40" height="40" negated="false">
- // <position x="${cItem.x - 100}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>MUL_NUM</expression>
- // </inVariable>`
- // // 赋值id
- // let setID = `${index + 1}${sIndex}${i}37`
- // xml += `
- // <inVariable localId="${setID}" width="40" height="40" negated="false">
- // <position x="${cItem.x - 100}" y="${cItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>SET_AI${sIndex}_${i}</expression>
- // </inVariable>`
- // let mulBlockId = `${index + 1}${sIndex}${i}38`
- // xml += `
- // <block localId="${mulBlockId}" typeName="DIV" width="70" height="60">
- // <position x="${cItem.x}" y="${cItem.y}" />
- // <inputVariables>
- // <variable formalParameter="EN">
- // <connectionPointIn>
- // <relPosition x="-20" y="20"/>
- // <connection refLocalId="${sIndex === 0 ? item.id : tempVarId}" formalParameter="OUT">
- // <position x="${sIndex === 0 ? item.x + 40 : sItem.x - 40}" y="${sItem.y + 20}"/>
- // <position x="${cItem.x - 20}" y="${cItem.y + 20}"/>
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN1">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${mulID}" formalParameter="OUT">
- // <position x="${cItem.x - 40}" y="${cItem.y + 220}" />
- // <position x="${cItem.x - 20}" y="${cItem.y + 40}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="IN2">
- // <connectionPointIn>
- // <relPosition x="-20" y="60" />
- // <connection refLocalId="${setID}">
- // <position x="${cItem.x - 40}" y="${cItem.y + 220}" />
- // <position x="${cItem.x - 20}" y="${cItem.y + 60}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="ENO">
- // <connectionPointOut>
- // <relPosition x="90" y="20"/>
- // </connectionPointOut>
- // </variable>
- // <variable formalParameter="OUT">
- // <connectionPointOut>
- // <relPosition x="90" y="40" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // // 赋值AO变量
- // let AOID = `${index + 1}${sIndex}${i}38`
- // xml += `
- // <outVariable localId="${AOID}" width="40" height="40" negated="false">
- // <position x="${cItem.x - 400}" y="${cItem.y + 200}" />
- // <connectionPointIn>
- // <relPosition x="60" y="20" />
- // <connection refLocalId="${mulBlockId}" formalParameter="OUT">
- // <position x="${cItem.x + 90}" y="${cItem.y + 4}" />
- // <position x="${cItem.x - 340}" y="${cItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // <expression>${cItem.label}</expression>
- // </outVariable>`
- // }
- // }
- // } else if (sItem.type === 'delay') {
- // // 延时时间变量
- // let delayVarId = `${index + 1}${sIndex}32`
- // xml += `
- // <inVariable localId="${delayVarId}" width="40" height="40" negated="false">
- // <position x="${sItem.x - 100}" y="${sItem.y + 200}" />
- // <connectionPointOut>
- // <relPosition x="60" y="20" />
- // </connectionPointOut>
- // <expression>PT${sIndex}</expression>
- // </inVariable>
- // `
- // xml += `
- // <block
- // localId="${sItem.id}"
- // typeName="TON"
- // instanceName="TON${sIndex}"
- // width="50"
- // height="60"
- // >
- // <position x="${sItem.x}" y="${sItem.y}" />
- // <inputVariables>
- // <variable formalParameter="IN">
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // <connection refLocalId="${sIndex === 0 ? item.id : tempVarId}">
- // <position x="${sIndex === 0 ? item.x + 40 : sItem.x - 40}" y="${sItem.y + 20}" />
- // <position x="${sItem.x - 20}" y="${sItem.y + 20}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // <variable formalParameter="PT">
- // <connectionPointIn>
- // <relPosition x="-20" y="40" />
- // <connection refLocalId="${delayVarId}">
- // <position x="${sItem.x - 40}" y="${sItem.y + 220}" />
- // <position x="${sItem.x - 20}" y="${sItem.y + 40}" />
- // </connection>
- // </connectionPointIn>
- // </variable>
- // </inputVariables>
- // <inOutVariables />
- // <outputVariables>
- // <variable formalParameter="Q">
- // <connectionPointOut>
- // <relPosition x="70" y="20" />
- // </connectionPointOut>
- // </variable>
- // <variable formalParameter="ET">
- // <connectionPointOut>
- // <relPosition x="70" y="40" />
- // </connectionPointOut>
- // </variable>
- // </outputVariables>
- // </block>
- // `
- // tempConnectXML += `
- // <connection refLocalId="${sItem.id}" formalParameter="Q">
- // <position x="${sItem.x + 70}" y="${sItem.y + 20}" />
- // <position x="${sItem.x - 120}" y="${sItem.y + 20}" />
- // </connection>`
- // }
- // if (sIndex !== 0) {
- // tempVarId = `${index + 1}${sIndex}33`
- // }
- // tempXML += `<inOutVariable localId="${tempVarId}" width="40" height="40" negatedOut="false" negatedIn="false">
- // <position x="${sItem.x - 100}" y="${sItem.y}" />
- // <connectionPointIn>
- // <relPosition x="-20" y="20" />
- // `
- // tempXML += tempConnectXML
- // tempXML += `
- // </connectionPointIn>
- // <connectionPointOut>
- // <relPosition x="60" y="20"/>
- // </connectionPointOut>
- // <expression>temp${sIndex}</expression></inOutVariable>`
- // if (sIndex !== item.stepList.length - 1) {
- // xml += tempXML
- // }
- // })
- // xml += `
- // </LD>
- // </body>
- // </pou>
- // `
- // })
- // // 尾部
- // xml += `
- // </pous>
- // </types>
- // <instances>
- // <configurations>
- // <configuration name="Config0">
- // <resource name="Res0">
- // <task name="task0" priority="0" interval="T#20ms">
- // ${instanceXml}
- // </task>
- // </resource>
- // <globalVars>
- // ${globalVarsXml}
- // <variable name="CRT_DATA">
- // <type><DT /></type>
- // <initialValue>
- // <simpleValue value="DT#${formatDateTime(new Date(), '-')}" />
- // </initialValue>
- // </variable>
- // </globalVars>
- // </configuration>
- // </configurations>
- // </instances>
- // </project>`
- // // console.log(xml)
- // // 生成文件下载
- // // 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: JSON.stringify(params),
- // headers: {
- // 'Content-Type': 'application/x-www-form-urlencoded',
- // 'Content-Length': xml.length + ''
- // }
- // })
- // .then((res) => res.json())
- // .then((res) => {
- // console.log(res)
- // // 关闭loading
- // loading.close()
- // if (res.errcode === 3000) {
- // showFailToast('编译失败!')
- // } else if (res.errcode === 0) {
- // localStorage.setItem(
- // 'imgobj' + crtProject.value!.id,
- // JSON.stringify({
- // url: res.url,
- // deadline: new Date().getTime() + 30 * 60 * 1000
- // })
- // )
- // crtProject.value!.isCompiled = true
- // crtProject.value!.CompileTime = formatDateTime(new Date())!
- // wxtag.value = `<wx-open-launch-weapp appid="wx4c5a777c71f2981c" path="pages/index/rj45cfgbybt/plc/index?imgurl=${res.url}"><template><text style="color: #7232dd">烧录设备</text></template></wx-open-launch-weapp>`
- // console.log('本地存储成功')
- // showSuccessToast('编译成功!')
- // }
- // })
- // // const link = document.createElement('a')
- // // link.href = URL.createObjectURL(blob)
- // // link.download = 'project.xml'
- // // link.click()
- // // URL.revokeObjectURL(link.href)
- // // link.remove()
- // }
- const get_c_code = (codetype: string) => {
- 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('任务内容为空!')
- }
- if (crtProject.value.isCompiled && codetype === 'wx') {
- return showFailToast('工程已编译!')
- }
- const isExistExec = crtProject.value.commandList.some((item) =>
- item.stepList.some((cItem) => cItem.type === 'exec' && cItem.list?.length !== 0)
- )
- if (!isExistExec) return showFailToast('请先添加执行任务!')
- const loading = showLoadingToast({
- message: '正在编译中...',
- forbidClick: true,
- duration: 0
- })
- const valMap: Record<string, number> = {
- 闭合: 1,
- 断开: 0,
- 打开: 0,
- }
- const weekMap: Record<string, number> = {
- 每天: 0,
- 周一: 1,
- 周二: 2,
- 周三: 3,
- 周四: 4,
- 周五: 5,
- 周六: 6,
- 周日: 7,
- 仅一次: 8
- }
- const operationMap: Record<string, string> = {
- '=': '==',
- '<': '<',
- '>': '>',
- '≤': '<=',
- '≥': '>=',
- '≠': '!='
- }
- const timeOperationMap: Record<string, number> = {
- 等于: 0,
- 早于: 1,
- 晚于: 2
- }
- let c_code = ''
- if (crtProject.value) {
- c_code = `#include "iec_def.h"
- extern uint8_t coil[20];
- extern uint16_t ai[4];
- extern uint16_t ao[2];`
- let call_code = ''
- crtProject.value.commandList.forEach((item, index) => {
- if (!item.stepList.some((cItem) => cItem.type === 'exec' && cItem.list?.length !== 0)) return
- call_code += `
- PROGRAM${index}_body(&p${index}, &p${index}_delay);`
- let body_code = `
- static struct pt p${index};
- static TIME p${index}_delay;
- static PT_THREAD(PROGRAM${index}_body(struct pt *pt, TIME *pt_delay))
- {
- PT_BEGIN(pt);`
- item.stepList.forEach((sItem, sIndex) => {
- if (sItem.type === 'delay') {
- body_code += `
- delay_set(pt_delay, ${+sItem.value! * 1000});
- PT_WAIT_UNTIL(pt, delay_expired(pt_delay));`
- } else {
- let condition_code = ''
- sItem.list!.forEach((cItem, cIndex) => {
- const linkStr = cIndex === sItem.list!.length - 1 ? '' : ' || '
- if (sItem.type === 'condition') {
- if (cItem.label.includes('DI')) {
- const idx = cItem.label.slice(2)
- condition_code += `GET_DI(${idx}) == ${valMap[cItem.value]}${linkStr}`
- }
- if (cItem.label.includes('DO')) {
- const idx = cItem.label.slice(2)
- condition_code += `GET_DO(${idx}) == ${valMap[cItem.value]}${linkStr}`
- }
- if (cItem.label.includes('AI')) {
- const idx = cItem.label.slice(2)
- condition_code += `GET_AI(${idx}) ${operationMap[cItem.operation!]} ${+cItem.value * 1000}${linkStr}`
- }
- if (cItem.label.includes('AO')) {
- const idx = cItem.label.slice(2)
- condition_code += `GET_AO(${idx}) ${operationMap[cItem.operation!]} ${+cItem.value * 1000}${linkStr}`
- }
- if (cItem.type === 'time') {
- const timeArr = cItem.value.split(':')
- const sec = Math.floor(
- (new Date(new Date().setHours(+timeArr[0], +timeArr[1], 0, 0)).getTime() -
- new Date(new Date().setHours(0, 0, 0, 0)).getTime()) /
- 1000
- )
- const operation = weekMap[cItem.label!]
- const timeOperation = timeOperationMap[cItem.operation!]
- if ((operation || operation === 0) && operation !== 8) {
- condition_code += `time_compare(${sec},${timeOperation}, 0, 0, ${operation})${linkStr}`
- } else if (cItem.label.includes('-')) {
- // 自定义时间
- const dateArr = cItem.label!.split('-')
- const start = Math.floor(new Date(dateArr[0]).getTime() / 1000)
- const end = Math.floor(new Date(dateArr[1]).getTime() / 1000)
- condition_code += `time_compare(${sec},${timeOperation}, ${start}, ${end}, 8)${linkStr}`
- console.log(condition_code)
- } else {
- // 特定某一天
- const start = Math.floor(new Date(cItem.label).getTime() / 1000)
- condition_code += `time_compare(${sec},${timeOperation}, ${start}, ${start + 24 * 60 * 60}, 8)${linkStr}`
- }
- }
- } else if (sItem.type === 'exec') {
- if (cItem.label.includes('DO')) {
- const idx = cItem.label.slice(2)
- body_code += `
- SET_DO(${idx}, ${valMap[cItem.value]});`
- }
- if (cItem.label.includes('AO')) {
- const idx = cItem.label.slice(2)
- body_code += `
- SET_AO(${idx}, ${+cItem.value * 1000});`
- }
- }
- })
- if (condition_code !== '') {
- body_code += `
- PT_WAIT_UNTIL(pt, ${condition_code});`
- }
- }
- })
- body_code += `
- PT_END(pt);
- }`
- c_code += body_code
- })
- c_code += `
- void IEC_run(void)
- {${call_code}
- }`
- }
- console.log(c_code)
- const params = {
- devicetype: 'PLC101',
- xml: c_code,
- codetype,
- getlog: true
- }
- fetch('https://plceditor.worldflying.cn/api/build/buildcode', {
- method: 'POST',
- body: JSON.stringify(params),
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded'
- }
- })
- .then((res) => res.json())
- .then((res) => {
- console.log(res)
- // 关闭loading
- loading.close()
- if (res.errcode === 3000) {
- showFailToast('操作失败!')
- } else if (res.errcode === 0) {
- if (codetype === 'wx') {
- localStorage.setItem(
- 'imgobj' + crtProject.value!.id,
- JSON.stringify({
- url: res.url,
- deadline: new Date().getTime() + 30 * 60 * 1000
- })
- )
- crtProject.value!.isCompiled = true
- crtProject.value!.CompileTime = formatDateTime(new Date())!
- wxtag.value = `<wx-open-launch-weapp appid="wx4c5a777c71f2981c" style="width: 100%;" path="pages/index/rj45cfgbybt/plc/index?imgurl=${res.url}"><template><text style="color: #7232dd;">烧录设备</text></template></wx-open-launch-weapp>`
- console.log('本地存储成功')
- showSuccessToast('编译成功!')
- } else {
- router.push({
- name: 'runtime',
- query: {
- id: crtProject.value!.id,
- url: res.url
- }
- })
- }
- }
- })
- }
- // 删除工程
- const delProject = () => {
- if (crtProject.value) {
- showConfirmDialog({
- title: '提示',
- message: '确定要删除这个工程吗'
- })
- .then(() => {
- // on confirm
- console.log(projectList.value)
- localStorage.removeItem('imgobj' + crtProject.value!.id)
- projectList.value = projectList.value.filter((item) => crtProject.value?.id !== item.id)
- router.replace({ name: 'Automate' })
- })
- .catch(() => {
- // on cancel
- })
- }
- }
- const showSharePopup = ref(false)
- const shareImg = ref('')
- const qrcodeCanvas = ref<HTMLCanvasElement>()
- const shareProject = async () => {
- if (!window.isInWx) return
- showSharePopup.value = true
- await nextTick()
- // const canvasEl = document.createElement('canvas')
- // const ratio = window.devicePixelRatio
- // const windowWidth = window.innerWidth
- // const windowHeight = window.innerHeight
- // const minWindowSize = Math.floor(Math.min(windowWidth, windowHeight) * 0.7)
- // canvasEl!.style.width = `${minWindowSize}px`
- // canvasEl!.style.height = `${minWindowSize}px`
- // canvasEl!.width = minWindowSize * ratio
- // canvasEl!.height = minWindowSize * ratio
- // qrcode.toCanvas(canvasEl!, JSON.stringify({ ...crtProject.value, qrcodeType: 'worldflying_plc_editor' }), {
- // width: minWindowSize * 2
- // })
- // const canvasEl1 = document.createElement('canvas')
- // canvasEl1.style.width = `${minWindowSize}px`
- // canvasEl1.style.height = `${minWindowSize + 50}px`
- // canvasEl1.width = minWindowSize * ratio
- // canvasEl1.height = (minWindowSize + 50) * ratio
- // const ctx = canvasEl1?.getContext('2d')
- // if (ctx) {
- // ctx.imageSmoothingEnabled = false
- // const fontSize = 16 * ratio
- // ctx.font = `${fontSize}px Arial`
- // ctx.fillText(`工程名称:${crtProject.value?.name}`, 20 * ratio, 35 * ratio)
- // ctx.drawImage(canvasEl, 0, 50 * ratio, minWindowSize * ratio, minWindowSize * ratio)
- // // shareImg.value = canvasEl1.toDataURL('image/png', 1)
- // canvasEl1.toBlob((blob) => {
- // if (!blob) return
- // shareImg.value = URL.createObjectURL(blob)
- // }, 'image/png', 1)
- // }
- qrcode.toDataURL(
- JSON.stringify({ ...crtProject.value, qrcodeType: 'worldflying_plc_editor' }),
- function (error, url) {
- if (error) console.error(error)
- // console.log(url)
- const ratio = devicePixelRatio
- const canvasEl = document.createElement('canvas')
- const windowWidth = window.innerWidth
- const windowHeight = window.innerHeight
- const minWindowSize = Math.floor(Math.min(windowWidth, windowHeight) * 0.7)
- canvasEl.style.width = `${minWindowSize}px`
- canvasEl.style.height = `${minWindowSize + 120}px`
- canvasEl.width = minWindowSize * ratio
- canvasEl.height = (minWindowSize + 120) * ratio
- const ctx = canvasEl?.getContext('2d')
- if (ctx) {
- const fontSize = 12 * ratio
- ctx.font = `${fontSize}px Arial`
- ctx.fillText(`工程名称:${crtProject.value?.name}`, 5 * ratio, 35 * ratio)
- const img = new Image()
- img.src = url
- img.onload = function () {
- ctx.imageSmoothingEnabled = false
- ctx.drawImage(img, 0, 40 * ratio, minWindowSize * ratio, minWindowSize * ratio)
- const tipText = '请打开沃航PLC手机编辑器,通过编辑页面导入该图片'
- const arr = []
- for (let i = 1; i <= tipText.length; i++) {
- const tipMsg = ctx.measureText(tipText.slice(0, i))
- if (Math.ceil(tipMsg.width / ratio) > minWindowSize) {
- arr.push(tipText.slice(0, i - 1))
- arr.push(tipText.slice(i - 1))
- break
- }
- if (i === tipText.length) {
- arr.push(tipText)
- }
- }
- arr.forEach((item, index) => {
- ctx.fillText(item, 5 * ratio, (minWindowSize + 55 + index * 15) * ratio)
- })
- const companyText = '沃航科技有限公司'
- const companyMsg = ctx.measureText(companyText)
- ctx.fillText(companyText, (minWindowSize - 10) * ratio - companyMsg.width, (minWindowSize + 100) * ratio)
- shareImg.value = canvasEl.toDataURL('image/png', 1)
- // canvasEl.toBlob(
- // (blob) => {
- // if (!blob) return
- // shareImg.value = URL.createObjectURL(blob)
- // },
- // 'image/png',
- // )
- }
- }
- canvasEl.remove()
- }
- )
- }
- const getSTFile = () => {
- if (!crtProject.value) return
- let st = ''
- crtProject.value.commandList.forEach((item, index) => {
- st += `
- PROGRAM program${index}
- VAR
- DI0: BOOL
- DI1: BOOL
- AI0: INT
- AI1: INT
- DO0: BOOL
- DO1: BOOL
- AO0: INT
- AO1: INT
- `
- const tempVarNum = item.stepList.length
- for (let i = 1; i <= tempVarNum; i++) {
- st += `TEMP${i}: BOOL`
- }
- })
- }
- let copyStatus = false
- let copyTimer: any
- // 复制任务
- const copyCommand = (cmd: CommandType) => {
- console.log(copyStatus)
- if (copyStatus) return
- if (copyTimer) clearTimeout(copyTimer)
- copyStatus = true
- // 提取基础名称和编号
- const baseName = cmd.name.replace(/\s*\(\d+\)/, '') // 去掉末尾的 "(数字)"
- let maxSuffix = 0
- // 遍历任务列表,找到与基础名称匹配的最大编号
- crtProject.value?.commandList.forEach((item) => {
- if (item.name.startsWith(baseName)) {
- const match = item.name.match(/\((\d+)\)/) // 匹配末尾的 "(数字)"
- if (match) {
- const suffix = parseInt(match[1], 10)
- if (suffix > maxSuffix) {
- maxSuffix = suffix
- }
- }
- }
- })
- // 生成新的任务名称
- const newSuffix = maxSuffix + 1
- const name = `${baseName}(${newSuffix})`
- const id = '' + Date.now()
- const time = new Date().toLocaleString()
- crtProject.value?.commandList.unshift({
- ...deepClone(cmd),
- name,
- id,
- time
- })
- copyTimer = setTimeout(() => {
- copyStatus = false
- }, 500)
- }
- </script>
- <style scoped>
- .project-info {
- padding: 16px 0 0;
- height: 100%;
- overflow: hidden;
- }
- .van-button {
- padding: 2px 8px;
- }
- .more .van-button {
- padding: 2px 16px;
- }
- .header {
- padding: 0 16px 16px;
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .header .project-name {
- height: 100%;
- max-width: 70%;
- display: flex;
- gap: 4px;
- align-items: center;
- justify-content: center;
- }
- .header .project-name .name {
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- max-width: 70%;
- }
- .command-container {
- height: calc(100% - 65px);
- padding-bottom: 16px;
- overflow: auto;
- }
- .command-container :deep(.van-cell__value) {
- width: 32px;
- flex: none;
- }
- .command-container :deep(.van-cell__title) {
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- .command-container :deep(.van-swipe-cell__right) {
- }
- .del-button {
- width: 64px;
- height: 100%;
- }
- .van-cell {
- justify-content: space-between;
- align-items: center;
- margin-bottom: 2px;
- gap: 16px;
- }
- .add-btn {
- position: fixed;
- bottom: 64px;
- left: 50%;
- transform: translateX(-50%);
- width: 70%;
- }
- .van-button-group {
- margin: 16px;
- display: flex;
- justify-content: flex-end;
- gap: 8px;
- }
- .share-container {
- padding: 16px;
- display: flex;
- justify-content: center;
- flex-direction: column;
- align-items: center;
- }
- .share-container .tip {
- margin: 16px 0;
- font-size: 18px;
- }
- .iconfont {
- font-size: 24px;
- }
- .wx-tag {
- display: flex;
- width: 100%;
- }
- </style>
|