1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236 |
- <template>
- <div class="props">
- <t-collapse
- :defaultValue="['1', '2', '3']"
- expandIconPlacement="right"
- :borderless="true"
- >
- <!-- <t-collapse-panel value="1" header="通信">
- <t-space direction="vertical" size="small" class="w-full">
- <div class="form-item">
- <label title="http地址">http地址 </label>
- <t-input
- class="w-full"
- v-model="props.pen.apiUrl"
- @change="changeValue('apiUrl')"
- />
- </div>
- <div class="form-item">
- <label title="请求方式">请求方式</label>
- <t-select
- v-model="props.pen.apiMethod"
- @change="changeValue('apiMethod')"
- >
- <t-option key="GET" value="GET" label="GET" />
- <t-option key="POST" value="POST" label="POST" />
- </t-select>
- </div>
- <div class="form-item">
- <label title="请求头">请求头</label>
- <t-button
- class="ml-8"
- shape="square"
- variant="outline"
- style="width: 24px"
- @click="preShowPropsEdit('apiHeaders')"
- >
- <ellipsis-icon slot="icon"/>
- </t-button>
- </div>
- <div class="form-item" v-if="props.pen.apiMethod === 'POST'">
- <label title="请求体">请求体</label>
- <t-button
- class="ml-8"
- shape="square"
- variant="outline"
- style="width: 24px"
- @click="preShowPropsEdit('apiBody')"
- >
- <ellipsis-icon slot="icon"/>
- </t-button>
- </div>
- <div class="form-item">
- <label title="开启轮询">开启轮询</label>
- <t-switch
- class="mt-8 ml-8"
- v-model="props.pen.apiEnable"
- size="small"
- @change="changeValue('apiEnable')"
- />
- </div>
- </t-space>
- </t-collapse-panel> -->
- <!-- <t-collapse-panel v-if="props.pen.props.custom" value="2" header="属性">
- <t-space direction="vertical" size="small" class="w-full">
- <div v-for="item in props.pen.props.custom" class="form-item">
- <label :title="item.label">{{ item.label }}</label>
- <t-checkbox
- class="ml-8"
- v-if="item.type === 'bool'"
- v-model="props.pen[item.key]"
- @change="changeValue(item.key)"
- />
- <t-input-number
- class="w-full"
- v-else-if="item.type === 'number'"
- v-model.number="props.pen[item.key]"
- theme="column"
- :max="item.max"
- :min="item.min"
- @change="changeValue(item.key)"
- :placeholder="item.placeholder"
- :allowInputOverLimit="false"
- :decimalPlaces="2"
- />
- <t-color-picker
- class="w-full"
- v-else-if="item.type === 'color'"
- :enable-alpha="true"
- :recent-colors="null"
- format="CSS"
- :swatch-colors="defaultPureColor"
- :color-modes="['monochrome']"
- :show-primary-color-preview="false"
- v-model="props.pen[item.key]"
- @change="changeValue(item.key)"
- :placeholder="item.placeholder"
- />
- <t-select
- class="w-full"
- v-else-if="item.type === 'select'"
- size="small"
- :options="item.options"
- v-model="props.pen[item.key]"
- @change="changeValue(item.key)"
- :placeholder="item.placeholder"
- />
- <t-button
- class="ml-8"
- v-else-if="item.type === 'code'"
- shape="square"
- variant="outline"
- style="width: 24px"
- @click="showDrawer(item)"
- >
- <ChevronLeftDoubleIcon slot="icon"/>
- </t-button>
- <t-slider
- v-else-if="item.type === 'slider'"
- v-model="props.pen[item.key]"
- :min="0"
- :max="1"
- :step="0.01"
- @change="changeValue(item.key)"
- />
- <t-switch
- size="small"
- class="mt-8 ml-8"
- v-else-if="item.type === 'switch'"
- v-model="props.pen[item.key]"
- @change="changeValue(item.key)"
- />
- <t-input
- class="w-full"
- v-else
- v-model="props.pen[item.key]"
- @change="changeValue(item.key)"
- :placeholder="item.placeholder"
- />
- </div>
- </t-space>
- </t-collapse-panel> -->
- <t-collapse-panel value="3" header="数据">
- <div class="form-item" v-if="props.pen.name==='tablePlus'">
- <label class="label">数据源</label>
- <t-select
- v-model="dataSource"
- placeholder="请选择"
- @change="getDataSource"
- >
- <t-option key="api" value="api" label="API接口"/>
- <t-option key="csv" value="csv" label="CSV文件"/>
- <t-option key="excel" value="excel" label="从Excel导入"/>
- </t-select>
- </div>
- <div class="t-space-item" v-if="props.pen.name==='tablePlus'">
- <div v-if="cell.row!==undefined" class="flex between form-item py-12">
- <div v-if="cell.col!==undefined" style="line-height: 30px">
- 当前选中单元格 (第{{ cell.row }}行,第{{ cell.col}}列)
- </div>
- <div v-else style="line-height: 30px">
- 当前选中行 (第{{ cell.row }}行)
- </div>
- <div>
- <t-tooltip content="快捷绑定" placement="top">
- <link-icon style="width: 13px;margin-right: 26px"class="hover ml-4" @click="onQuickBind()"/>
- </t-tooltip>
- </div>
- </div>
- </div>
- <div class="t-space-item">
- <div class="form-item py-12">
- <label style="width: 76px">关联设备</label>
- <t-input
- class="w-full"
- placeholder="设备ID"
- v-model="props.pen.deviceId"
- @change="changeValue('deviceId')"
- />
- </div>
- </div>
- <div
- class="real-times"
- v-if="props.pen.realTimes && props.pen.realTimes.length||pen.children?.length"
- >
- <div class="grid head">
- <div class="title">数据名</div>
- <div class="title">值</div>
- <div class="title" style="text-align: center;">绑定</div>
- <div class="title" style="text-align: center;">操作</div>
- <!-- <div class="actions">
- <more-icon />
- </div> -->
- </div>
- <div class="grid" v-for="(item, i) in props.pen.realTimes">
- <t-tooltip :content="item.key" placement="top">
- <label class="label">{{ item.label }}</label>
- </t-tooltip>
- <div class="value">
- <t-input
- v-if="item.type === 'integer'"
- v-model.number="props.pen[item.key]"
- placeholder="整数"
- @change="changeValue(item.key)"
- />
- <t-input-number
- v-else-if="item.type === 'float'"
- v-model="props.pen[item.key]"
- placeholder="浮点数"
- theme="normal"
- @change="changeValue(item.key)"
- />
- <t-switch
- v-else-if="item.type === 'bool'"
- v-model="props.pen[item.key]"
- class="ml-8"
- size="small"
- @change="changeValue(item.key)"
- />
- <t-button
- v-else-if="item.type === 'array' || item.type === 'object'"
- variant="outline"
- style="padding: 0px 2px 0 4px; margin: 0 4px"
- @click="editObject(item)"
- >
- <ellipsis-icon />
- <!-- <t-icon name="ellipsis" /> -->
- </t-button>
- <t-input
- v-else
- v-model="props.pen[item.key]"
- placeholder="字符串"
- @change="changeValue(item.key)"
- />
-
- </div>
- <div style="text-align: center;">
- <t-tooltip :content="getBindsDesc(item)" placement="top">
- <link-icon class="hover ml-4"
- :class="{ primary: item.enableMock || item.bind?.id }"
- @click="onBind(item)"/>
- </t-tooltip>
- </div>
- <div style="text-align: center;">
- <!-- <t-tooltip :content="item.triggers?.length || '状态'">
- <t-badge
- :count="item.triggers?.length"
- size="small"
- dot
- :offset="[0, 5]"
- >
- <relativity-icon class="hover"
- @click="onTrigger(item)"/>
- </t-badge>
- </t-tooltip> -->
- <t-dropdown
- :options="triggerOptions"
- @click="addTrigger(item, $event, i)"
- :minColumnWidth="120"
- >
- <ViewListIcon class="hover"/>
- </t-dropdown>
- </div>
- <!-- <div class="actions">
- <t-dropdown
- :options="moreOptions"
- @click="onMenuMore($event, item, i)"
- :minColumnWidth="80"
- >
- <more-icon class="more hover" />
- </t-dropdown>
- </div> -->
- </div>
- <div class="mt-8 pb-16">
- <t-dropdown
- :options="options"
- @click="addRealTime"
- :minColumnWidth="150"
- >
- <a class="ml-12">
- <add-rectangle-icon />
- <!-- <t-icon name="add-rectangle" /> -->
- 添加动态数据
- </a>
- </t-dropdown>
- </div>
- </div>
- <div class="flex column center blank" v-else>
- <img src="/img/blank.png" />
- <div class="gray center">还没有动态数据</div>
- <div class="mt-8">
- <t-dropdown
- :options="options"
- @click="addRealTime"
- :minColumnWidth="150"
- >
- <t-button style="height: 30px"> 添加动态数据 </t-button>
- </t-dropdown>
- </div>
- </div>
- <div v-if="props.pen.children?.length" class="c-titile">
- <t-tooltip content="ctrl+shift+点击,可选中子图元">
- 子节点数据
- </t-tooltip>
- </div>
- <template v-for="(cPen) in childrenPens">
- <div
- class="real-times"
- >
- <t-divider align="left c-head"> {{ cPen.description||cPen.name }}</t-divider>
- <div class="grid" v-for="(item, i) in cPen.realTimes">
- <t-tooltip :content="item.key" placement="top">
- <label class="label">{{ item.label }}</label>
- </t-tooltip>
- <div class="value">
- <t-input
- v-if="item.type === 'integer'"
- v-model.number="cPen[item.key]"
- placeholder="整数"
- @change="changeCValue(item.key,cPen)"
- />
- <t-input-number
- v-else-if="item.type === 'float'"
- v-model="cPen[item.key]"
- placeholder="浮点数"
- theme="normal"
- @change="changeCValue(item.key,cPen)"
- />
- <t-switch
- v-else-if="item.type === 'bool'"
- v-model="cPen[item.key]"
- class="ml-8"
- size="small"
- @change="changeCValue(item.key,cPen)"
- />
- <t-button
- v-else-if="item.type === 'array' || item.type === 'object'"
- variant="outline"
- style="padding: 0px 2px 0 4px; margin: 0 4px"
- @click="editCObject(item,cPen)"
- >
- <ellipsis-icon />
- </t-button>
- <t-input
- v-else
- v-model="cPen[item.key]"
- placeholder="字符串"
- @change="changeCValue(item.key,cPen)"
- />
- </div>
- <div style="text-align: center;">
- <t-tooltip :content="getBindsDesc(item)" placement="top">
- <link-icon class="hover ml-4"
- :class="{ primary: item.enableMock || item.bind?.id }"
- @click="onBind(item)"/>
- </t-tooltip>
- </div>
- <!-- <div>
- <t-tooltip :content="item.triggers?.length || '状态'">
- <t-badge
- :count="item.triggers?.length"
- size="small"
- dot
- :offset="[0, 5]"
- >
- <relativity-icon class="hover"
- @click="onTrigger(item)"/>
- </t-badge>
- </t-tooltip>
- </div> -->
- <div class="actions" style="text-align: center;">
- <t-dropdown
- :options="moreOptions"
- @click="onCMenuMore($event, item, i, cPen)"
- :minColumnWidth="80"
- >
- <ViewListIcon class="hover"/>
- </t-dropdown>
- </div>
- </div>
- <div class="mt-8 pb-16">
- <t-dropdown
- :options="options"
- @click="addCRealTime($event,cPen)"
- :minColumnWidth="150"
- >
- <a class="ml-12">
- <add-rectangle-icon />
- 添加动态数据
- </a>
- </t-dropdown>
- </div>
- </div>
- </template>
- </t-collapse-panel>
- </t-collapse>
- </div>
- <!-- <t-drawer
- v-model:visible="drawer.visible"
- :header="drawer.header"
- cancelBtn="关闭"
- confirmBtn="运行"
- @confirm="onConfirmDrawer"
- :closeOnOverlayClick="false"
- :sizeDraggable="true"
- >
- <div style="height:100%">
- <CodeEditor
- style="height: 100%"
- :key="drawer.randomkey"
- :json="true"
- :language="'json'"
- v-model="drawer.value"
- />
- </div>
- <div class="gray" style="font-size: 12px">
- {{ drawer.placeholder }}
- </div>
- </t-drawer> -->
- <t-dialog
- v-if="addDataDialog.show"
- :visible="true"
- class="data-dialog"
- :header="addDataDialog.header"
- @close="addDataDialog.show = false"
- @confirm="onConfirmData"
- >
- <div class="form-item mt-16">
- <label>数据名</label>
- <t-input
- v-model="addDataDialog.data.label"
- placeholder="简短描述"
- :disabled="!!addDataDialog.data.keywords"
- @blur="onChangeLabel"
- />
- </div>
- <div class="form-item mt-16">
- <label>属性名</label>
- <t-input
- v-model="addDataDialog.data.key"
- placeholder="关键字"
- @blur="onKeyBlur"
- :disabled="!!addDataDialog.data.keywords"
- />
- </div>
- <div class="form-item mt-16">
- <label>类型</label>
- <t-select
- class="w-full"
- :options="typeOptions"
- v-model="addDataDialog.data.type"
- placeholder="字符串"
- :disabled="!!addDataDialog.data.keywords"
- @change="onKeyBlur"
- />
- </div>
- </t-dialog>
- <t-dialog
- v-if="dataBindDialog.show"
- :visible="true"
- class="data-link-dialog"
- header="动态数据设置"
- @close="
- dataBindDialog.datasetList = undefined;
- dataBindDialog.show = false;
- "
- @confirm="dataBindonConfirm"
- :top="70"
- :width="700"
- >
- <t-tabs :defaultValue="1">
- <t-tab-panel
- :value="1"
- label="绑定变量"
- :destroy-on-hide="false"
- style="height: 420px"
- >
- <div class="form-item mt-12">
- <label>当前绑定:</label>
- <div class="label" v-if="dataBindDialog.data.bind?.id">
- <t-tooltip :content="dataBindDialog.data.bind?.id">
- <t-tag class="mr-8 mb-8" closable @close="onRemoveBind()">
- {{ dataBindDialog.data.bind?.label }}
- </t-tag>
- </t-tooltip>
- </div>
- <div class="label gray" v-else>无</div>
- </div>
- <div class="form-item flex middle mt-8">
- <!-- <t-input
- v-if="dataBindDialog.url"
- v-model="dataBindDialog.device"
- placeholder="设备"
- style="width: 200px"
- />
- <t-select
- v-else
- class="mr-16"
- style="width: 200px"
- v-model="dataBindDialog.device"
- clearable
- placeholder="设备"
- @change="getDataset"
- >
- <t-option
- v-for="(item, i) in dataBindDialog.devices"
- :key="item"
- :value="item"
- :label="item"
- />
- </t-select> -->
- <t-input
- style="width:250px;"
- placeholder="搜索"
- v-model="dataBindDialog.input"
- @change="onSearchDataset"
- @enter="onSearchDataset"
- >
- <template #suffixIcon>
- <search-icon class="hover" @click="onSearchDataset"/>
- <!-- <t-icon name="search" class="hover" @click="onSearchDataset" /> -->
- </template>
- </t-input>
- </div>
- <t-table
- class="mt-12 data-list"
- row-key="id"
- :data="dataBindDialog.dataset"
- :columns="dataSetColumns"
- size="small"
- bordered
- rowSelectionAllowUncheck
- :loading="dataBindDialog.loading"
- :pagination="query"
- @page-change="onChangePagination"
- :selected-row-keys="dataBindDialog.selectedIds"
- @select-change="onSelectBindsChange"
- :max-height="270"
- >
- </t-table>
- </t-tab-panel>
- <t-tab-panel
- :value="2"
- label="本地调试"
- :destroy-on-hide="false"
- style="height: 420px"
- >
- <div class="form-item mt-20">
- <label>模拟值:</label>
- <t-input v-model="dataBindDialog.data.mock" />
- </div>
- <div class="form-item mt-20">
- <label>类型:</label>
- <t-select
- class="w-full"
- :options="typeOptions"
- v-model="dataBindDialog.data.type"
- placeholder="字符串"
- />
- </div>
- <div class="form-item mt-12">
- <label>开启:</label>
- <t-switch
- class="mt-8"
- size="small"
- v-model="dataBindDialog.data.enableMock"
- />
- </div>
- <h6 class="desc mt-20">模拟值说明</h6>
- <ul class="desc mt-4">
- <li class="mt-4">
- <label class="inline" style="width: 80px">固定值:</label>
- 直接填写,例如:10
- </li>
- <li class="mt-4">
- <label class="inline" style="width: 80px">随机值:</label>
- 值1,值2,...。例如:1,2,3,4,5
- </li>
- <li class="mt-4">
- <label class="inline" style="width: 80px">范围数字:</label>
- 最小值-最大值。例如:0-1.0 或 0-100
- </li>
- <li class="mt-4">
- <label class="inline" style="width: 80px">随机字符串:</label>
- [长度]。例如:[8]
- </li>
- </ul>
- </t-tab-panel>
- </t-tabs>
- </t-dialog>
- <t-dialog
- v-if="triggersDialog.show"
- :visible="true"
- class="data-events-dialog"
- header="数据状态"
- @confirm="triggersDialog.show = false"
- @close="triggersDialog.show = false"
- :width="700"
- >
- <div class="body">
- <t-collapse
- v-model="triggersDialog.openedCollapses"
- :borderless="true"
- :expand-on-row-click="false"
- >
- <t-collapse-panel
- v-for="(trigger, i) in triggersDialog.data.triggers"
- :value="i"
- >
- <template #header>
- <t-input v-model="trigger.name" class="mr-12" />
- </template>
- <template #headerRightContent>
- <t-popconfirm
- content="确认删除该状态吗?"
- @confirm="triggersDialog.data.triggers.splice(i, 1)"
- >
- <delete-icon class="hover"/>
- <!-- <t-icon name="delete" class="hover" /> -->
- </t-popconfirm>
- </template>
- <section>
- <div class="form-item banner">
- <label>满足条件</label>
- <div class="w-full flex middle between">
- <div></div>
- <t-radio-group v-model="trigger.conditionType">
- <t-radio value="and"> 所有 </t-radio>
- <t-radio value="or"> 任意 </t-radio>
- </t-radio-group>
- </div>
- </div>
- <div v-for="(c, index) in trigger.conditions" class="mb-12">
- <div class="flex middle between head">
- <div class="flex middle">
- <arrow-right-icon class="mr-4"/>
- <!-- <t-icon name="arrow-right" class="mr-4" /> -->
- 条件{{ index + 1 }}
- </div>
- <close-icon class="hover"
- @click="trigger.conditions.splice(index, 1)"/>
- <!-- <t-icon
- name="close"
- class="hover"
- @click="trigger.conditions.splice(index, 1)"
- /> -->
- </div>
- <div class="px-16 py-4">
- <div class="form-item mt-4">
- <label>条件类型</label>
- <t-radio-group v-model="c.type">
- <t-radio value=""> 关系条件 </t-radio>
- <t-radio value="fn"> 高级条件 </t-radio>
- </t-radio-group>
- </div>
- <template v-if="!c.type">
- <div class="form-item mt-8">
- <label>比较条件</label>
- <div class="flex middle">
- <label class="shrink-0 mr-8">数据</label>
- <t-select
- v-model="c.operator"
- placeholder="关系运算"
- :options="operatorOptions"
- class="shrink-0 mr-8"
- style="width: 80px"
- />
- <t-select
- v-model="c.valueType"
- class="shrink-0 mr-8"
- style="width: 110px"
- placeholder="固定值"
- >
- <t-option key="" value="" label="固定值">
- 固定值
- </t-option>
- <t-option key="prop" value="prop" label="对象属性值">
- 对象属性值
- </t-option>
- </t-select>
- <template v-if="!c.valueType">
- <t-input
- @change="valueChange($event,c)"
- v-model="c.value"
- class="shrink-0"
- style="width: 320px"
- />
- </template>
- <template v-else>
- <t-tree-select
- v-model="c.target"
- :data="penTree"
- filterable
- placeholder="对象"
- class="shrink-0 mr-8"
- style="width: 160px"
- @change="onChangeTriggerTarget(c)"
- />
- <t-select-input
- v-model:inputValue="c.value"
- :value="c.label"
- v-model:popupVisible="c.popupVisible"
- allow-input
- clearable
- @clear="c.label = undefined"
- @focus="c.popupVisible = true"
- @blur="c.popupVisible = false"
- @input-change="onInput(c)"
- class="shrink-0"
- style="width: 152px"
- >
- <template #panel>
- <ul style="padding: 8px 12px">
- <li
- v-for="item in cProps"
- :key="item.value"
- @click="
- c.value = item.value;
- c.label = item.label;
- c.popupVisible = false;
- "
- >
- {{ item.label }}
- </li>
- </ul>
- </template>
- </t-select-input>
- </template>
- </div>
- </div>
- </template>
- <template v-else>
- <div>function condition(pen) {</div>
- <CodeEditor class="mt-4" @change="codeChange($event,c)" v-model="c.fnJs" />
- <div class="mt-4">}</div>
- </template>
- </div>
- </div>
- <div class="mt-8">
- <a @click="addTriggerCondition(trigger)"> + 添加条件 </a>
- </div>
- <div class="form-item banner mt-16">
- <label>执行动作</label>
- </div>
- <Actions class="mt-8" :data="trigger" />
- </section>
- </t-collapse-panel>
- </t-collapse>
- <div class="mt-8">
- <!-- <a @click="onAddTrigger"> + 添加状态 </a> -->
- <t-button @click="onAddTrigger" style="width: 100%;" variant="outline">
- <template #icon><add-icon /></template>
- 添加状态
- </t-button>
- </div>
- </div>
- </t-dialog>
- <t-dialog
- v-if="ojbectDialog.show"
- :visible="true"
- header="数据编辑"
- @confirm="onOkEditOjbect"
- @close="ojbectDialog.show = false"
- :width="700"
- >
- <div class="py-8">
- <CodeEditor
- :json="true"
- v-model="ojbectDialog.data"
- style="height: 300px"
- />
- </div>
- </t-dialog>
- <t-dialog
- v-if="propsDialog.show"
- :visible="true"
- :header="propsDialog.header"
- @confirm="onOkPropsEdit"
- @close="propsDialog.show = false"
- :width="700"
- >
- <div class="py-8">
- <CodeEditor
- :json="true"
- :language="'json'"
- v-model="propsDialog.value"
- style="height: 300px"
- />
- </div>
- <div class="gray" style="font-size: 12px">
- {{ propsDialog.placeholder }}
- </div>
- </t-dialog>
- <t-dialog
- v-if="apiDialog.show"
- :visible="true"
- class="data-dialog"
- header="API接口"
- @close="apiDialog.show = false"
- @confirm="onConfirmAPI"
- >
- <div class="form-item mt-8">
- <label>http地址</label>
- <t-input
- placeholder="请输入(临时请求,不会保存)"
- v-model="apiDialog.url"
- />
- </div>
- <div class="form-item mt-8">
- <label>请求方式</label>
- <t-select v-model="apiDialog.method">
- <t-option key="GET" value="GET" label="GET" />
- <t-option key="POST" value="POST" label="POST" />
- </t-select>
- </div>
- <div class="form-item mt-8">
- <label>请求头</label>
- <CodeEditor
- :json="true"
- :language="'json'"
- v-model="apiDialog.headers"
- class="mt-4"
- style="height: 50px"
- />
- </div>
- <div v-if="apiDialog.method === 'POST'" class="form-item mt-8">
- <label>请求体</label>
- <CodeEditor
- :json="true"
- :language="'json'"
- v-model="apiDialog.body"
- class="mt-4"
- style="height: 50px"
- />
- </div>
- </t-dialog>
- </template>
- <script lang="ts" setup>
- import {
- getCurrentInstance,
- onBeforeMount,
- onUnmounted,
- reactive,
- ref,
- toRaw,
- watch,
- onMounted,
- computed
- } from 'vue';
- import { useRoute, useRouter } from 'vue-router';
- import { MessagePlugin } from 'tdesign-vue-next';
- import axios from 'axios';
- import { debounce } from '@/services/debouce';
- import { getPenTree, typeOptions, changeType } from '@/services/common';
- import { searchPinyin } from '@/services/pinyin';
- import { updatePen } from './pen';
- import { getter, setter, queryURLParams, deepClone, getAllChildren, Pen } from '@meta2d/core';
- import CodeEditor from '@/views/components/common/CodeEditor.vue';
- import Actions from './Actions.vue';
- import { useSelection } from '@/services/selections';
- import { defaultGradientColor, defaultPureColor } from '@/services/defaults';
- import { getLe5le3d, getLe5leV, getLe5le2d } from '@/services/api';
- import { EllipsisIcon, MoreIcon, LinkIcon, RelativityIcon, AddRectangleIcon, SearchIcon ,DeleteIcon, ArrowRightIcon, CloseIcon, ChevronLeftDoubleIcon, AddIcon, ViewListIcon } from 'tdesign-icons-vue-next';
- import { s8 } from '@/services/random';
- import { importExcel } from '@/services/excel';
- import { importCSV } from '@/services/file';
- const route = useRoute();
- const router = useRouter();
- const {
- proxy: { $forceUpdate },
- }: any = getCurrentInstance();
- const props = defineProps<{
- pen: any;
- }>();
- const options = ref<any>([
- {
- value: '',
- content: '自定义',
- divider: true,
- },
- {
- value: 'x',
- content: 'X',
- type: 'float',
- keywords: true,
- },
- {
- value: 'y',
- content: 'Y',
- type: 'float',
- keywords: true,
- },
- {
- value: 'width',
- content: '宽',
- type: 'float',
- keywords: true,
- },
- {
- value: 'height',
- content: '高',
- type: 'float',
- keywords: true,
- },
- {
- value: 'visible',
- content: '显示',
- type: 'bool',
- keywords: true,
- },
- {
- value: 'text',
- content: '文字',
- // keywords: true,
- },
- {
- value: 'progress',
- content: '进度',
- type: 'float',
- keywords: true,
- },
- {
- value: 'showChild',
- content: '状态',
- type: 'integer',
- keywords: true,
- },
- {
- value: 'rotate',
- content: '旋转',
- type: 'integer',
- keywords: true,
- },
- ]);
- const moreOptions = ref<any>([
- {
- value: 'view',
- content: '查看状态',
- },
- {
- value: 'custom',
- content: '自定义状态',
- divider: true
- },
- {
- value: 'edit',
- content: '编辑',
- },
- {
- value: 'delete',
- content: '移除',
- },
- ]);
- const addDataDialog = reactive<any>({
- show: false,
- data: undefined,
- });
- const dataBindDialog = reactive<any>({
- show: false,
- data: undefined,
- });
- const ojbectDialog = reactive<any>({
- show: false,
- data: undefined,
- });
- const dataSetColumns = [
- {
- colKey: 'row-select',
- type: 'single',
- width: 50,
- },
- // {
- // colKey: 'device',
- // title: '设备',
- // ellipsis: { theme: 'light', trigger: 'context-menu' },
- // },
- {
- colKey: 'label',
- title: '显示名称',
- ellipsis: { theme: 'light', trigger: 'context-menu' },
- },
- {
- colKey: 'id',
- title: '变量名',
- ellipsis: { theme: 'light', trigger: 'context-menu' },
- },
- {
- colKey: 'type',
- title: '类型',
- width: 100,
- },
- {
- colKey: 'mock',
- title: '值范围',
- ellipsis: true,
- },
- ];
- const operatorOptions = ref<any>([
- { label: '=', value: '=' },
- { label: '!=', value: '!=' },
- { label: '>', value: '>' },
- { label: '<', value: '<' },
- { label: '>=', value: '>=' },
- { label: '<=', value: '<=' },
- { label: '包含', value: '[)' },
- { label: '不包含', value: '![)' },
- ]);
- const cProps = [
- {
- value: 'x',
- label: 'X',
- },
- {
- value: 'y',
- label: 'Y',
- },
- {
- value: 'width',
- label: '宽',
- },
- {
- value: 'height',
- label: '高',
- },
- {
- value: 'visible',
- label: '显示',
- },
- {
- value: 'text',
- label: '文字',
- },
- {
- value: 'color',
- label: '颜色',
- },
- {
- value: 'background',
- label: '背景颜色',
- },
- {
- value: 'progress',
- label: '进度',
- },
- {
- value: 'progressColor',
- label: '进度颜色',
- },
- {
- value: 'showChild',
- label: '状态',
- },
- {
- value: 'rotate',
- label: '旋转',
- },
- {
- value: 'disabled',
- label: '禁用',
- },
- {
- value: 'selectedKey',
- label: '单选选中值',
- }
- ];
- const query = reactive<{
- current: number;
- pageSize: number;
- total: number;
- range: any[];
- }>({
- current: 1,
- pageSize: 10,
- total: 0,
- range: [],
- });
- const triggersDialog = reactive<any>({
- show: false,
- data: undefined,
- });
- const penTree: any = ref([]);
- let timer: any;
- onBeforeMount(() => {
- // realTimesOptions - 扩展的动态数据下拉列表
- if (props.pen.realTimesOptions) {
- options.value[options.value.length - 1].divider = true;
- options.value.push(...props.pen.realTimesOptions);
- }
- timer = setInterval($forceUpdate, 1000);
- });
- const addRealTime = (e: any) => {
- if (e.keywords || e.value === 'text') {
- if (!props.pen.realTimes) {
- props.pen.realTimes = [];
- }
- props.pen.realTimes.push({
- label: e.content,
- key: e.value,
- type: e.type,
- keywords: e.keywords,
- });
- return;
- }
- addDataDialog.header = '添加动态数据';
- addDataDialog.data = {
- label: e.content,
- key: e.value,
- type: e.type,
- keywords: e.keywords,
- };
- addDataDialog.data.pen = undefined;
- if (e.keywords) {
- addDataDialog.data.label = '';
- }
- addDataDialog.show = true;
- };
- const onKeyBlur = () => {
- if (addDataDialog.data) {
- let value = getter(props.pen, addDataDialog.data.key);
- if (value) {
- setter(addDataDialog.data, 'value', value);
- } else {
- addDataDialog.data.value = null;
- }
- }
- };
- const onChangeLabel = () => {
- if (!addDataDialog.data.key) {
- addDataDialog.data.key = addDataDialog.data.label;
- }
- };
- const onConfirmData = () => {
- const pen = addDataDialog.data.pen || props.pen;
- if (!pen.realTimes) {
- pen.realTimes = [];
- }
- if (!addDataDialog.data.label || !addDataDialog.data.key) {
- MessagePlugin.error('数据名或属性名不能为空!');
- return;
- }
- delete addDataDialog.data.pen;
- if (addDataDialog.header === '添加动态数据') {
- const found = pen.realTimes.findIndex((item: any) => {
- return item.key === addDataDialog.data.key;
- });
- if (found > -1) {
- MessagePlugin.error('已经存在相同属性数据!');
- return;
- }
- if(pen[addDataDialog.data.key] === undefined && addDataDialog.data.key.indexOf('.') !== -1){
- pen[addDataDialog.data.key] = getter(pen, addDataDialog.data.key);
- }
- pen.realTimes.push(addDataDialog.data);
- }
- addDataDialog.show = false;
- };
- const onMenuMore = (e: any, item: any, i: number) => {
- switch (e.value) {
- case 'edit':
- addDataDialog.header = '编辑动态数据';
- setter(item, 'value', getter(props.pen, item.key));
- addDataDialog.data = item;
- addDataDialog.show = true;
- break;
- case 'delete':
- props.pen.realTimes.splice(i, 1);
- meta2d.initBinds();
- break;
- default:
- break;
- }
- };
- const onBind = (item: any) => {
- dataBindDialog.data = item;
- dataBindDialog.input = '';
- dataBindDialog.selectedIds = [];
- if (item.bind && item.bind.id) {
- dataBindDialog.selectedIds.push(item.bind.id);
- }
- dataBindDialog.show = true;
- getDataset();
- };
- const onSearchDataset = () => {
- debounce(getDataset, 300);
- };
- const getDataset = async () => {
- // @ts-ignore
- const data: Meta2dBackData = meta2d.data();
- if (!data.dataset) {
- return;
- }
- dataBindDialog.dataset = data.dataset.devices;
- dataBindDialog.datasetList = data.dataset.devices;
- if(dataBindDialog.device || dataBindDialog.input){
- dataBindDialog.dataset = dataBindDialog.datasetList.filter(
- (item: any) => {
- if (dataBindDialog.device && item.device !== dataBindDialog.device) {
- return;
- }
- return (
- searchPinyin(item.label, dataBindDialog.input) ||
- item.id.indexOf(dataBindDialog.input) > -1
- );
- }
- );
- }
- query.total = dataBindDialog.dataset.length;
- return;
- dataBindDialog.loading = true;
- if (data.dataset.url) {
- const ret: any = await axios.get(data.dataset.url, {
- params: {
- device: dataBindDialog.device || '',
- q: dataBindDialog.input,
- current: query.current,
- pageSize: query.pageSize,
- },
- });
- dataBindDialog.dataset = ret;
- dataBindDialog.url = true;
- query.total = ret.total;
- console.log( dataBindDialog.dataset,
- query.total);
- } else {
- dataBindDialog.url = false;
- if (!dataBindDialog.datasetList) {
- const ret:any = await axios.post(`/api/data/datasource/get`, {
- id: data.dataset.id,
- });
- if (ret?.data?.devices) {
- data.dataset.data = ret.data.devices;
- dataBindDialog.datasetList = data.dataset.data;
- const set = new Set<string>();
- for (const item of dataBindDialog.datasetList) {
- set.add(item.device);
- }
- dataBindDialog.devices = Array.from(set);
- } else {
- dataBindDialog.dataset = [];
- dataBindDialog.devices = [];
- return;
- }
- }
- if (dataBindDialog.device || dataBindDialog.input) {
- dataBindDialog.dataset = dataBindDialog.datasetList.filter(
- (item: any) => {
- if (dataBindDialog.device && item.device !== dataBindDialog.device) {
- return;
- }
- return (
- searchPinyin(item.label, dataBindDialog.input) ||
- item.id.indexOf(dataBindDialog.input) > -1
- );
- }
- );
- query.total = dataBindDialog.datasetList.length;
- } else {
- dataBindDialog.dataset = [...dataBindDialog.datasetList];
- query.total = dataBindDialog.datasetList.length;
- }
- console.log("dataBindDialog",dataBindDialog,dataBindDialog);
- }
- dataBindDialog.loading = false;
- };
- const onChangePagination = (pageInfo: any) => {
- // router.push({
- // path: route.path,
- // query: { current: pageInfo.current, pageSize: pageInfo.pageSize },
- // });
- query.current = pageInfo.current;
- query.pageSize = pageInfo.pageSize;
- getDataset();
- };
- const onSelectBindsChange = (value: string[], options: any) => {
- if (options.type === 'check') {
- dataBindDialog.selectedIds = value;
- dataBindDialog.data.bind = toRaw(options.selectedRowData[0]);
- if(dataBindDialog.data.bind.id){
- dataBindDialog.data.enableMock = false;
- }
- dataBindDialog.data.mock = dataBindDialog.data.bind.mock;
- dataBindDialog.data.type = dataBindDialog.data.bind.type;
- doBindInit();
- } else if (options.type === 'uncheck') {
- dataBindDialog.selectedIds = [];
- dataBindDialog.data.bind = {};
- }
- };
- const doBindInit = () => {
- let { id } = dataBindDialog.data;
- if (props.pen.name === 'echarts' && id?.includes('echarts.option.series')) {
- const { replaceMode } = props.pen.echarts;
- const { xAxis } = props.pen.echarts.option;
- let beforeV = getter(props.pen, id);
- if (Array.isArray(beforeV) && replaceMode === 0) {
- //追加
- setter(props.pen, id, []);
- let _key = 'echarts.option.xAxis.data';
- if (Array.isArray(xAxis) && xAxis.length) {
- _key = 'echarts.option.xAxis.0.data';
- }
- setter(props.pen, _key, []);
- }
- }
- };
- const dataBindonConfirm = () => {
- dataBindDialog.show = false;
- dataBindDialog.datasetList = undefined;
- meta2d.initBinds();
- };
- const onRemoveBind = () => {
- dataBindDialog.selectedIds = [];
- dataBindDialog.data.bind = undefined;
- };
- const getBindsDesc = (item: any) => {
- if (item.bind?.label) {
- return item.bind.label;
- }
- if (item.enableMock && item.mock) {
- return item.mock;
- }
- return '绑定变量';
- };
- const { selections } = useSelection();
- const changeValue = (prop: string) => {
- updatePen(props.pen, prop);
- selections.pen[prop] = getter(props.pen, prop);
- if (prop === 'iframe') {
- getThumbImg();
- }
- if(prop === 'apiEnable'){
- meta2d.penNetwork(props.pen);
- meta2d.connectNetwork();
- }
- };
- const onTrigger = (item: any) => {
- if (!item.triggers) {
- item.triggers = [];
- }
- triggersDialog.openedCollapses = [0];
- triggersDialog.data = item;
- triggersDialog.show = true;
- penTree.value = getPenTree();
- };
- const onAddTrigger = () => {
- const i = triggersDialog.data.triggers.length;
- triggersDialog.data.triggers.push({
- name: `状态${i + 1}`,
- conditionType: 'and',
- conditions: [],
- actions: [],
- });
- triggersDialog.openedCollapses.push(i);
- };
- const addTriggerCondition = (trigger: any) => {
- trigger.conditions.push({
- type: '',
- operator: '=',
- valueType: '',
- });
- };
- const onChangeTriggerTarget = (c: any) => {
- /*
- c.targetProps = [
- {
- value: 'x',
- label: 'X',
- },
- {
- value: 'y',
- label: 'Y',
- },
- {
- value: 'width',
- label: '宽',
- },
- {
- value: 'height',
- label: '高',
- },
- {
- value: 'visible',
- label: '显示',
- },
- {
- value: 'text',
- label: '文字',
- },
- {
- value: 'progress',
- label: '进度',
- },
- {
- value: 'showChild',
- label: '状态',
- },
- {
- value: 'rotate',
- label: '旋转',
- },
- ];*/
- const target: any = meta2d.findOne(c.target);
- if (target && target.realTimes) {
- for (const item of target.realTimes) {
- const found = cProps.findIndex((elem: any) => elem.value === item.key);
- if (found < 0) {
- cProps.push({
- value: item.key,
- label: item.label,
- });
- }
- }
- }
- };
- const onInput = (item: any) => {
- item.label = item.value;
- };
- const editObject = (item: any) => {
- ojbectDialog.data = props.pen[item.key];
- ojbectDialog.item = item;
- ojbectDialog.pen = undefined;
- ojbectDialog.show = true;
- };
- const onOkEditOjbect = () => {
- if (ojbectDialog.data) {
- if (
- ojbectDialog.item.type === 'array' &&
- !Array.isArray(ojbectDialog.data)
- ) {
- MessagePlugin.error('请输入数组格式数据');
- return;
- }
- const pen = ojbectDialog.pen || props.pen;
- pen[ojbectDialog.item.key] = deepClone(ojbectDialog.data);
- updatePen(
- pen,
- ojbectDialog.item.key
- );
- ojbectDialog.show = false;
- } else {
- MessagePlugin.error('请输入严格的JSON格式数据');
- }
- };
- const propsDialog = reactive<any>({
- show: false,
- });
- // const changeValue = (prop: string) => {
- // updatePen(props.pen, prop);
- // selections.pen[prop] = getter(props.pen, prop);
- // if (prop === 'iframe') {
- // getThumbImg();
- // }
- // };
- const getThumbImg = async () => {
- //改iframe地址后
- let arr = props.pen.iframe.split('?');
- let id = queryURLParams(arr[1]).id;
- if (!id) {
- return;
- }
- // let projection = {
- // image: 1,
- // _id: 1,
- // name: 1,
- // };
- let projection = 'image,id,name';
- let res: any;
- if (arr[0].indexOf('2d.le5le') !== -1||arr[0].indexOf('le5le.com/2d') !== -1) {
- res = await getLe5le2d(id, projection);
- } else if (arr[0].indexOf('v.le5le') !== -1||arr[0].indexOf('le5le.com/v') !== -1) {
- res = await getLe5leV(id, projection);
- } else if (arr[0].indexOf('3d.le5le') !== -1||arr[0].indexOf('le5le.com/3d') !== -1) {
- res = await getLe5le3d(id, projection);
- }
- if (res) {
- props.pen.thumbImg = res.image;
- props.pen.calculative&&(props.pen.calculative.img = null);
- }
- props.pen.onRenderPenRaw?.(props.pen);
- };
- const preShowPropsEdit = (key: string) => {
- showPropsEdit({
- key,
- // item: {
- // key,
- type: 'code',
- label: key,
- placeholder: '支持设置动态参数,例如:{"Authorization": "Bearer ${token}"}',
- // },
- });
- };
- const showPropsEdit = (item: any) => {
- propsDialog.key = item.key;
- propsDialog.header = `${item.label}(${item.key})`;
- propsDialog.value = props.pen[item.key];
- propsDialog.placeholder = item.placeholder;
- propsDialog.show = true;
- };
- const onOkPropsEdit = () => {
- if (!propsDialog.value) {
- MessagePlugin.error('数据不满足json格式');
- return;
- }
- props.pen[propsDialog.key] = propsDialog.value;
- updatePen(props.pen, propsDialog.key);
- propsDialog.show = false;
- };
- const codeChange = (e:any,a:any)=>{
- a.fn = null;
- }
- const valueChange = (e,c:any)=>{
- c.value= changeType(e);
- }
- const drawer = reactive<any>({
- visible: false,
- });
- const showDrawer = (item:any)=>{
- drawer.key = item.key;
- drawer.header = `${item.label}(${item.key})`;
- drawer.value = deepClone(props.pen[item.key]);
- drawer.placeholder = item.placeholder;
- drawer.randomkey = s8();//props.pen.id;
- drawer.visible = true;
- }
- const onConfirmDrawer = () => {
- if (!drawer.value) {
- MessagePlugin.error('数据不满足json格式');
- return;
- }
- props.pen[drawer.key] = drawer.value;
- updatePen(props.pen, drawer.key);
- };
- const childrenPens = ref([]);
- watch(
- () => props.pen.id,
- (newValue) => {
- childrenPens.value = [];
- // childrenKey.value = s8();
- if(props.pen.children?.length){
- childrenPens.value = getAllChildren(meta2d.store.pens[props.pen.id],meta2d.store);
- }
- }
- );
- onMounted(() => {
- childrenPens.value = [];
- if(props.pen.children?.length){
- childrenPens.value = getAllChildren(meta2d.store.pens[props.pen.id],meta2d.store);
- }
- });
- const changeCValue = (prop: string, pen:Pen)=>{
- updatePen(pen, prop);
- selections.pen[prop] = getter(pen, prop);
- if (prop === 'iframe') {
- getThumbImg();
- }
- if(prop === 'apiEnable'){
- meta2d.penNetwork(pen);
- meta2d.connectNetwork();
- }
- }
- const editCObject = (item: any, pen:Pen) => {
- ojbectDialog.data = pen[item.key];
- ojbectDialog.pen = pen;
- ojbectDialog.item = item;
- ojbectDialog.show = true;
- };
- const addCRealTime = (e: any, pen:Pen) => {
- if (e.keywords || e.value === 'text') {
- if (!pen.realTimes) {
- pen.realTimes = [];
- }
- pen.realTimes.push({
- label: e.content,
- key: e.value,
- type: e.type,
- keywords: e.keywords,
- });
- return;
- }
- addDataDialog.header = '添加动态数据';
-
- addDataDialog.data = {
- label: e.content,
- key: e.value,
- type: e.type,
- keywords: e.keywords,
- };
- addDataDialog.data.pen = pen;
- if (e.keywords) {
- addDataDialog.data.label = '';
- }
- addDataDialog.show = true;
- };
- const onCMenuMore = (e: any, item: any, i: number, pen:any)=>{
- switch (e.value) {
- case 'edit':
- addDataDialog.header = '编辑动态数据';
- setter(item, 'value', getter(pen, item.key));
- addDataDialog.data = item;
- addDataDialog.data.pen = pen;
- addDataDialog.show = true;
- break;
- case 'delete':
- pen.realTimes.splice(i, 1);
- meta2d.initBinds();
- break;
- case 'custom':
- if(!pen.triggers){
- pen.triggers = [];
- }
- pen.triggers.push({
- name: `状态场景${pen.triggers.length + 1}`,
- status:[
- {
- name:'状态1',
- conditionType: 'and',
- conditions: [{
- type:'',
- operator: "=",
- key: item.key,//"text",
- keyLabel: item.label,
- value: undefined
- }],
- actions: [],
- },
- {
- name:'状态2',
- conditionType: 'and',
- conditions: [],
- actions: [],
- }
- ],
- });
- meta2d.active(meta2d.find(pen.id));
- emit('tabchange',pen.triggers.length-1);
- break;
- case 'view':
- meta2d.active(meta2d.find(pen.id));
- emit('tabchange',-1);
- default:
- break;
- }
- }
- const emit = defineEmits(['tabchange']);
- const triggerOptions = computed(() => {
- const options = [
- {
- value: 'custom',
- content: '自定义状态',
- divider: true
- },
- {
- value: 'warning',
- content: '条件告警',
- },
- {
- value: 'warningAnimate',
- content: '条件动画',
- divider: true
- },
- {
- value: 'edit',
- content: '编辑',
- },
- {
- value: 'delete',
- content: '移除',
- },
- ]
- if( props.pen.name === "combine"&& props.pen.showChild !== undefined){
- options.splice(1,0,
- {
- value: 'switch',
- content: '状态切换',
- });
- }
-
- return options
- });
- const addTrigger = (item:any, e:any, i:any) => {
- if(!['edit', 'delete'].includes(e.value)){
- if(!props.pen.triggers){
- props.pen.triggers = [];
- }
- }
- switch (e.value) {
- case 'edit':
- addDataDialog.header = '编辑动态数据';
- setter(item, 'value', getter(props.pen, item.key));
- addDataDialog.data = item;
- addDataDialog.show = true;
- break;
- case 'delete':
- props.pen.realTimes.splice(i, 1);
- meta2d.initBinds();
- break;
- case 'switch':
- props.pen.triggers.push({
- "name": e.content,
- "status": [
- {
- "name": "满足条件,切换到状态1",
- "conditionType": "and",
- "conditions": [
- {
- "type": "",
- "operator": ">=",
- "key": item.key,
- "keyLabel": item.label,
- "valueType": ""
- }
- ],
- "actions": [
- {
- "action": 1,
- "params": "",
- "value": {
- "showChild": 1
- },
- "targetType": "id"
- }
- ]
- },
- {
- "name": "默认显示状态",
- "conditionType": "and",
- "conditions": [],
- "actions": [
- {
- "action": 1,
- "params": "",
- "value": {
- "showChild": 0
- },
- "targetType": "id"
- }
- ]
- }
- ]
- });
- break;
- case 'warning':
- props.pen.triggers.push({
- "name": e.content,
- "status": [
- {
- "name": "满足条件,触发告警",
- "conditions": [
- {
- "type": "",
- "operator": ">=",
- "valueType": "",
- "key": item.key,
- "keyLabel":item.label,
- "value": undefined
- }
- ],
- "actions": [
- {
- "action": 1,
- "params": "",
- "value": {
- "background": "red",
- },
- "targetType": "id"
- }
- ],
- "conditionType": "and"
- },
- {
- "name": "恢复默认",
- "conditionType": "and",
- "conditions": [],
- "actions": [
- {
- "action": 1,
- "params": "",
- "value": {
- "background": "#0000",
- },
- "targetType": "id"
- }
- ]
- }
- ]
- });
- break;
- case 'warningAnimate':
- props.pen.triggers.push({
- "name": e.content,
- "status": [
- {
- "name": "满足条件,触发动画执行",
- "conditions": [
- {
- "type": "",
- "operator": ">=",
- "valueType": "",
- "key": item.key,
- "keyLabel":item.label,
- "value": undefined
- }
- ],
- "actions": [
- {
- "action": 2,
- "params": "",
- "value": "",
- "targetType": "id",
- }
- ],
- "conditionType": "and"
- },
- {
- "name": "恢复默认状态",
- "conditionType": "and",
- "conditions": [],
- "actions": [
- {
- "action": 4,
- "params": "",
- "value": "",
- "targetType": "id"
- }
- ]
- }
- ]
- });
- break;
- case 'custom':
- props.pen.triggers.push({
- name: `状态场景${props.pen.triggers.length + 1}`,
- status:[
- {
- name:'状态1',
- conditionType: 'and',
- conditions: [{
- type:'',
- operator: "=",
- key: item.key,//"text",
- keyLabel: item.label,
- value: undefined
- }],
- actions: [],
- },
- {
- name:'状态2',
- conditionType: 'and',
- conditions: [],
- actions: [],
- }
- ],
- });
- break;
- }
- if(!['edit', 'delete'].includes(e.value)){
- emit('tabchange',props.pen.triggers.length-1);
- }
- }
- const cell = ref({
- col:undefined,
- row:undefined
- });
- const getPenData = (e)=>{
- if(props.pen.name === 'tablePlus'){
- if(props.pen.calculative.activeRow !== undefined){
- cell.value.row = props.pen.calculative.activeRow;
- cell.value.col = undefined;
- }else if(props.pen.calculative.activeCell){
- cell.value.col = props.pen.calculative.activeCell.col;
- cell.value.row = props.pen.calculative.activeCell.row;
- }else{
- cell.value.col = undefined;
- cell.value.row = undefined;
- }
- }
- }
- const onQuickBind = ()=>{
- if(cell.value.row !== undefined){
- if(!props.pen.realTimes){
- props.pen.realTimes = [];
- }
- if(cell.value.col !== undefined){
- let found = props.pen.realTimes.findIndex((item:any)=>{
- return item.key === `data.${cell.value.row}.${cell.value.col}`;
- });
- if(found === -1){
- props.pen.realTimes.push({
- label: `第${cell.value.row}行,第${cell.value.col}列`,
- key: `data.${cell.value.row}.${cell.value.col}`,
- type: 'float',
- });
- onBind(props.pen.realTimes[props.pen.realTimes.length-1]);
- }else{
- onBind(props.pen.realTimes[found]);
- }
- }else{
- let found = props.pen.realTimes.findIndex((item:any)=>{
- return item.key === `data.${cell.value.row}`;
- });
- if(found === -1){
- props.pen.realTimes.push({
- label: `第${cell.value.row}行`,
- key: `data.${cell.value.row}`,
- type: 'array',
- });
- onBind(props.pen.realTimes[props.pen.realTimes.length-1]);
- }else{
- onBind(props.pen.realTimes[found]);
- }
- }
- }
- }
- const dataSource = ref('');
- const getDataSource = async (e) => {
- dataSource.value = '';
- if (e === 'excel') {
- let data = await importExcel();
- if (Array.isArray(data) && Array.isArray(data[0])) {
- meta2d.setValue({ id: props.pen.id, data: data, styles: [], mergeCells: [], colHeaders: false }, { doEvent: false });
- } else {
- MessagePlugin.warning("数据格式必需是二维数组");
- }
- } else if (e === 'csv') {
- let data = await importCSV();
- if (Array.isArray(data) && Array.isArray(data[0])) {
- meta2d.setValue({ id: props.pen.id, data: data, styles: [], mergeCells: [], colHeaders: false }, { doEvent: false });
- } else {
- MessagePlugin.warning("数据格式必需是二维数组");
- }
- } else if (e === 'api') {
- apiDialog.show = true;
- }
- }
- const apiDialog = reactive<any>({
- show: false,
- });
- const onConfirmAPI = async () => {
- if (!apiDialog.url) {
- MessagePlugin.warning('请输入API地址');
- return;
- }
- const res: Response = await fetch(apiDialog.url, {
- headers: apiDialog.headers,
- method: apiDialog.method || 'GET',
- body: apiDialog.method === 'GET' ? undefined : JSON.stringify(apiDialog.body),
- });
- let data: any = JSON.parse(await res.text());
- if (data.data) {
- data = data.data;
- }
- if (data.list) {
- data = data.list;
- }
- if (Array.isArray(data)) {
- if (Array.isArray(data[0])) {
- } else {
- let _data = [];
- data.forEach((item) => {
- _data.push(Object.values(item));
- })
- data = _data;
- }
- if (Array.isArray(data) && Array.isArray(data[0])) {
- meta2d.setValue({ id: props.pen.id, data: data, styles: [], mergeCells: [], colHeaders: false }, { doEvent: false });
- MessagePlugin.success("导入成功");
- } else {
- MessagePlugin.warning("数据格式必需是二维数组");
- }
- apiDialog.show = false;
- } else {
- MessagePlugin.warning("数据格式必需是数组类型");
- }
- };
- onMounted(() => {
- meta2d.on('click',getPenData);
- getPenData({});
- });
- onUnmounted(() => {
- meta2d.off('click',getPenData);
- clearInterval(timer);
- });
- </script>
- <style lang="postcss" scoped>
- .props {
- height: 100%;
- .grid {
- grid-template-columns: 70px 70px 50px 65px;
- padding: 0 12px;
- &.head {
- background: var(--color-background-input);
- line-height: 36px;
- margin-bottom: 6px;
- .title {
- line-height: 36px;
- }
- }
- }
- .blank {
- height: 70%;
- img {
- padding: 16px;
- opacity: 0.9;
- }
- }
- .c-titile{
- margin-top: 12px;
- color: var(--color-title);
- font-size: 12px;
- font-weight: 700;
- }
- .c-head{
- &::before{
- width: 0%;
- }
- color: var(--color);
- font-weight: 700;
- }
- .real-times{
- .label {
- width: fix-content;
- font-size: 10px;
- line-height: 28px;
- color: var(--color-desc);
- }
- }
- .value {
- padding-right: 8px;
- display: flex;
- align-items: center;
- justify-content: space-between;
- svg {
- flex-shrink: 0;
- margin-right: 4px;
- }
- & > div {
- width: 72px;
- &.t-switch {
- width: fit-content;
- margin-left: 4px;
- }
- }
- :deep(.t-input) {
- padding-left: 4px;
- height: 26px;
- border-color: transparent;
- &:hover {
- border-color: var(--color-primary);
- }
- }
- }
- .actions {
- text-align: right;
- padding-right: 2px;
- }
- .data-list {
- :deep(.t-table__header--fixed:not(.t-table__header--multiple) > tr > th) {
- background: none;
- }
- :deep(.t-table__pagination) {
- padding-bottom: 0;
- }
- }
- }
- .body {
- :deep(.t-collapse.t--border-less) {
- .t-collapse-panel__header {
- border-top: none;
- /* border-bottom: 1px solid var(--td-border-level-1-color); */
- padding: 8px 0;
- .t-input {
- border: none;
- padding-left: 0;
- font-size: 14px;
- }
- }
- .t-collapse-panel__content {
- padding: 8px 0;
- }
- }
- .title {
- position: relative;
- margin: 8px 0;
- :deep(.t-input) {
- border-color: var(--color-background-input);
- border-radius: 0;
- border-left: none;
- border-top: none;
- border-right: none;
- padding-left: 0;
- padding-bottom: 8px;
- font-size: 14px;
- &:hover {
- border-color: var(--color-border-input);
- }
- }
- }
- .head {
- margin-top: 10px;
- }
- .banner {
- background-color: var(--color-background-input);
- padding: 0 12px;
- }
- }
- </style>
- <style lang="postcss">
- .t-drawer__mask{
- /* background-color: #fff0; */
- }
- .t-drawer__body{
- padding:0px;
- }
- </style>
|