PenDatas.vue 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  1. <template>
  2. <div class="props">
  3. <div
  4. class="real-times"
  5. v-if="props.pen.realTimes && props.pen.realTimes.length"
  6. >
  7. <div class="grid head">
  8. <div class="title">数据名</div>
  9. <div class="title">值</div>
  10. <div class="title">触发器</div>
  11. <div class="actions">
  12. <t-icon name="more" />
  13. </div>
  14. </div>
  15. <div class="grid" v-for="(item, i) in props.pen.realTimes">
  16. <t-tooltip :content="item.key" placement="top">
  17. <label class="label">{{ item.label }}</label>
  18. </t-tooltip>
  19. <div class="value">
  20. <t-input
  21. v-if="item.type === 'integer'"
  22. v-model.number="props.pen[item.key]"
  23. placeholder="整数"
  24. @change="changeValue(item.key)"
  25. />
  26. <t-input-number
  27. v-else-if="item.type === 'float'"
  28. v-model="props.pen[item.key]"
  29. placeholder="浮点数"
  30. theme="normal"
  31. @change="changeValue(item.key)"
  32. />
  33. <t-switch
  34. v-else-if="item.type === 'bool'"
  35. v-model="props.pen[item.key]"
  36. class="ml-8"
  37. size="small"
  38. @change="changeValue(item.key)"
  39. />
  40. <t-button
  41. v-else-if="item.type === 'array' || item.type === 'object'"
  42. variant="outline"
  43. style="padding: 0px 2px 0 4px; margin: 0 4px"
  44. @click="editObject(item)"
  45. >
  46. <t-icon name="ellipsis" />
  47. </t-button>
  48. <t-input
  49. v-else
  50. v-model="props.pen[item.key]"
  51. placeholder="字符串"
  52. @change="changeValue(item.key)"
  53. />
  54. <t-tooltip :content="getBindsDesc(item)" placement="top">
  55. <t-icon
  56. name="link"
  57. class="hover ml-4"
  58. :class="{ primary: item.enableMock || item.bind?.id }"
  59. @click="onBind(item)"
  60. />
  61. </t-tooltip>
  62. </div>
  63. <div>
  64. <t-tooltip :content="item.triggers?.length || '触发器'">
  65. <t-badge
  66. :count="item.triggers?.length"
  67. size="small"
  68. dot
  69. :offset="[0, 5]"
  70. >
  71. <t-icon
  72. name="relativity"
  73. class="hover"
  74. @click="onTrigger(item)"
  75. />
  76. </t-badge>
  77. </t-tooltip>
  78. </div>
  79. <div class="actions">
  80. <t-dropdown
  81. :options="moreOptions"
  82. @click="onMenuMore($event, item, i)"
  83. :minColumnWidth="80"
  84. >
  85. <t-icon name="more" class="more hover" />
  86. </t-dropdown>
  87. </div>
  88. </div>
  89. <div class="mt-8 pb-16">
  90. <t-dropdown
  91. :options="options"
  92. @click="addRealTime"
  93. :minColumnWidth="150"
  94. >
  95. <a class="ml-12"> <t-icon name="add-rectangle" /> 添加动态数据 </a>
  96. </t-dropdown>
  97. </div>
  98. </div>
  99. <div class="flex column center blank" v-else>
  100. <img src="/img/blank.png" />
  101. <div class="gray center">还没有动态数据</div>
  102. <div class="mt-8">
  103. <t-dropdown
  104. :options="options"
  105. @click="addRealTime"
  106. :minColumnWidth="150"
  107. >
  108. <t-button style="height: 30px"> 添加动态数据 </t-button>
  109. </t-dropdown>
  110. </div>
  111. </div>
  112. </div>
  113. <t-dialog
  114. v-if="addDataDialog.show"
  115. :visible="true"
  116. class="data-dialog"
  117. :header="addDataDialog.header"
  118. @close="addDataDialog.show = false"
  119. @confirm="onConfirmData"
  120. >
  121. <div class="form-item mt-16">
  122. <label>数据名</label>
  123. <t-input
  124. v-model="addDataDialog.data.label"
  125. placeholder="简短描述"
  126. :disabled="!!addDataDialog.data.keywords"
  127. @blur="onChangeLabel"
  128. />
  129. </div>
  130. <div class="form-item mt-16">
  131. <label>属性名</label>
  132. <t-input
  133. v-model="addDataDialog.data.key"
  134. placeholder="关键字"
  135. @blur="onKeyBlur"
  136. :disabled="!!addDataDialog.data.keywords"
  137. />
  138. </div>
  139. <div class="form-item mt-16">
  140. <label>类型</label>
  141. <t-select
  142. class="w-full"
  143. :options="typeOptions"
  144. v-model="addDataDialog.data.type"
  145. placeholder="字符串"
  146. :disabled="!!addDataDialog.data.keywords"
  147. @change="onKeyBlur"
  148. />
  149. </div>
  150. </t-dialog>
  151. <t-dialog
  152. v-if="dataBindDialog.show"
  153. :visible="true"
  154. class="data-link-dialog"
  155. header="动态数据设置"
  156. @close="
  157. dataBindDialog.datasetList = undefined;
  158. dataBindDialog.show = false;
  159. "
  160. @confirm="dataBindonConfirm"
  161. :top="70"
  162. :width="700"
  163. >
  164. <t-tabs :defaultValue="1">
  165. <t-tab-panel
  166. :value="1"
  167. label="绑定数据点"
  168. :destroy-on-hide="false"
  169. style="height: 420px"
  170. >
  171. <div class="form-item mt-12">
  172. <label>当前绑定:</label>
  173. <div class="label" v-if="dataBindDialog.data.bind?.id">
  174. <t-tooltip :content="dataBindDialog.data.bind?.id">
  175. <t-tag class="mr-8 mb-8" closable @close="onRemoveBind()">
  176. {{ dataBindDialog.data.bind?.label }}
  177. </t-tag>
  178. </t-tooltip>
  179. </div>
  180. <div class="label gray" v-else>无</div>
  181. </div>
  182. <div class="form-item flex middle mt-8">
  183. <t-input
  184. v-if="dataBindDialog.url"
  185. v-model="dataBindDialog.device"
  186. placeholder="设备"
  187. style="width: 200px"
  188. />
  189. <t-select
  190. v-else
  191. class="mr-16"
  192. style="width: 200px"
  193. v-model="dataBindDialog.device"
  194. clearable
  195. placeholder="设备"
  196. @change="getDataset"
  197. >
  198. <t-option
  199. v-for="(item, i) in dataBindDialog.devices"
  200. :key="item"
  201. :value="item"
  202. :label="item"
  203. />
  204. </t-select>
  205. <t-input
  206. placeholder="搜索"
  207. v-model="dataBindDialog.input"
  208. @change="onSearchDataset"
  209. @enter="onSearchDataset"
  210. >
  211. <template #suffixIcon>
  212. <t-icon name="search" class="hover" @click="onSearchDataset" />
  213. </template>
  214. </t-input>
  215. </div>
  216. <t-table
  217. class="mt-12 data-list"
  218. row-key="id"
  219. :data="dataBindDialog.dataset"
  220. :columns="dataSetColumns"
  221. size="small"
  222. bordered
  223. :loading="dataBindDialog.loading"
  224. :pagination="query"
  225. @page-change="onChangePagination"
  226. :selected-row-keys="dataBindDialog.selectedIds"
  227. @select-change="onSelectBindsChange"
  228. :max-height="270"
  229. >
  230. </t-table>
  231. </t-tab-panel>
  232. <t-tab-panel
  233. :value="2"
  234. label="数据模拟"
  235. :destroy-on-hide="false"
  236. style="height: 420px"
  237. >
  238. <div class="form-item mt-20">
  239. <label>模拟值:</label>
  240. <t-input v-model="dataBindDialog.data.mock" />
  241. </div>
  242. <div class="form-item mt-12">
  243. <label>开启:</label>
  244. <t-switch
  245. class="mt-8"
  246. size="small"
  247. v-model="dataBindDialog.data.enableMock"
  248. />
  249. </div>
  250. <h6 class="desc mt-20">模拟值说明</h6>
  251. <ul class="desc mt-4">
  252. <li class="mt-4">
  253. <label class="inline" style="width: 80px">固定值:</label>
  254. 直接填写,例如:10
  255. </li>
  256. <li class="mt-4">
  257. <label class="inline" style="width: 80px">随机值:</label>
  258. 值1,值2,...。例如:1,2,3,4,5
  259. </li>
  260. <li class="mt-4">
  261. <label class="inline" style="width: 80px">范围数字:</label>
  262. 最小值-最大值。例如:0-1.0 或 0-100
  263. </li>
  264. <li class="mt-4">
  265. <label class="inline" style="width: 80px">随机字符串:</label>
  266. [长度]。例如:[8]
  267. </li>
  268. </ul>
  269. </t-tab-panel>
  270. </t-tabs>
  271. </t-dialog>
  272. <t-dialog
  273. v-if="triggersDialog.show"
  274. :visible="true"
  275. class="data-events-dialog"
  276. header="数据触发器"
  277. @confirm="triggersDialog.show = false"
  278. @close="triggersDialog.show = false"
  279. :width="700"
  280. >
  281. <div class="body">
  282. <t-collapse
  283. v-model="triggersDialog.openedCollapses"
  284. :borderless="true"
  285. :expand-on-row-click="false"
  286. >
  287. <t-collapse-panel
  288. v-for="(trigger, i) in triggersDialog.data.triggers"
  289. :value="i"
  290. >
  291. <template #header>
  292. <t-input v-model="trigger.name" class="mr-12" />
  293. </template>
  294. <template #headerRightContent>
  295. <t-popconfirm
  296. content="确认删除该触发器吗?"
  297. @confirm="triggersDialog.data.triggers.splice(i, 1)"
  298. >
  299. <t-icon name="delete" class="hover" />
  300. </t-popconfirm>
  301. </template>
  302. <section>
  303. <div class="form-item banner">
  304. <label>触发条件</label>
  305. <div class="w-full flex middle between">
  306. <div></div>
  307. <t-radio-group v-model="trigger.conditionType">
  308. <t-radio value="and"> 满足全部条件 </t-radio>
  309. <t-radio value="or"> 满足任意条件 </t-radio>
  310. </t-radio-group>
  311. </div>
  312. </div>
  313. <div v-for="(c, index) in trigger.conditions" class="mb-12">
  314. <div class="flex middle between head">
  315. <div class="flex middle">
  316. <t-icon name="arrow-right" class="mr-4" />
  317. 条件{{ index + 1 }}
  318. </div>
  319. <t-icon
  320. name="close"
  321. class="hover"
  322. @click="trigger.conditions.splice(index, 1)"
  323. />
  324. </div>
  325. <div class="px-16 py-4">
  326. <div class="form-item mt-4">
  327. <label>条件类型</label>
  328. <t-radio-group v-model="c.type">
  329. <t-radio value=""> 关系条件 </t-radio>
  330. <t-radio value="fn"> 高级条件 </t-radio>
  331. </t-radio-group>
  332. </div>
  333. <template v-if="!c.type">
  334. <div class="form-item mt-8">
  335. <label>比较条件</label>
  336. <div class="flex middle">
  337. <label class="shrink-0 mr-8">数据</label>
  338. <t-select
  339. v-model="c.operator"
  340. placeholder="关系运算"
  341. :options="operatorOptions"
  342. class="shrink-0 mr-8"
  343. style="width: 80px"
  344. />
  345. <t-select
  346. v-model="c.valueType"
  347. class="shrink-0 mr-8"
  348. style="width: 110px"
  349. placeholder="固定值"
  350. >
  351. <t-option key="" value="" label="固定值">
  352. 固定值
  353. </t-option>
  354. <t-option key="prop" value="prop" label="对象属性值">
  355. 对象属性值
  356. </t-option>
  357. </t-select>
  358. <template v-if="!c.valueType">
  359. <t-input
  360. v-model="c.value"
  361. class="shrink-0"
  362. style="width: 320px"
  363. />
  364. </template>
  365. <template v-else>
  366. <t-tree-select
  367. v-model="c.target"
  368. :data="penTree"
  369. filterable
  370. placeholder="对象"
  371. class="shrink-0 mr-8"
  372. style="width: 160px"
  373. @change="onChangeTriggerTarget(c)"
  374. />
  375. <t-select-input
  376. v-model:inputValue="c.value"
  377. :value="c.label"
  378. v-model:popupVisible="c.popupVisible"
  379. allow-input
  380. clearable
  381. @clear="c.label = undefined"
  382. @focus="c.popupVisible = true"
  383. @blur="c.popupVisible = undefined"
  384. @input-change="onInput(c)"
  385. class="shrink-0"
  386. style="width: 152px"
  387. >
  388. <template #panel>
  389. <ul style="padding: 8px 12px">
  390. <li
  391. v-for="item in c.targetProps"
  392. :key="item.value"
  393. @click="
  394. c.value = item.value;
  395. c.label = item.label;
  396. "
  397. >
  398. {{ item.label }}
  399. </li>
  400. </ul>
  401. </template>
  402. </t-select-input>
  403. </template>
  404. </div>
  405. </div>
  406. </template>
  407. <template v-else>
  408. <div>function condition(pen) {</div>
  409. <CodeEditor class="mt-4" v-model="c.fnJs" />
  410. <div class="mt-4">}</div>
  411. </template>
  412. </div>
  413. </div>
  414. <div class="mt-8">
  415. <a @click="addTriggerCondition(trigger)"> + 添加条件 </a>
  416. </div>
  417. <div class="form-item banner mt-16">
  418. <label>执行动作</label>
  419. </div>
  420. <Actions class="mt-8" :data="trigger" />
  421. </section>
  422. </t-collapse-panel>
  423. </t-collapse>
  424. <div class="mt-8">
  425. <a @click="onAddTrigger"> + 添加触发器 </a>
  426. </div>
  427. </div>
  428. </t-dialog>
  429. <t-dialog
  430. v-if="ojbectDialog.show"
  431. :visible="true"
  432. header="数据编辑"
  433. @confirm="onOkEditOjbect"
  434. @close="ojbectDialog.show = false"
  435. :width="700"
  436. >
  437. <div class="py-8">
  438. <CodeEditor
  439. :json="true"
  440. v-model="ojbectDialog.data"
  441. style="height: 300px"
  442. />
  443. </div>
  444. </t-dialog>
  445. </template>
  446. <script lang="ts" setup>
  447. import {
  448. getCurrentInstance,
  449. onBeforeMount,
  450. onUnmounted,
  451. reactive,
  452. ref,
  453. toRaw,
  454. } from 'vue';
  455. import { useRoute, useRouter } from 'vue-router';
  456. import { MessagePlugin } from 'tdesign-vue-next';
  457. import axios from 'axios';
  458. import { getter, setter } from '@meta2d/core/src/utils/object';
  459. import { debounce } from '@/services/debouce';
  460. import { getPenTree, typeOptions } from '@/services/common';
  461. import { searchPinyin } from '@/services/pinyin';
  462. import { updatePen } from './pen';
  463. import CodeEditor from '@/views/components/common/CodeEditor.vue';
  464. import Actions from './Actions.vue';
  465. const route = useRoute();
  466. const router = useRouter();
  467. const {
  468. proxy: { $forceUpdate },
  469. }: any = getCurrentInstance();
  470. const props = defineProps<{
  471. pen: any;
  472. }>();
  473. const options = ref<any>([
  474. {
  475. value: '',
  476. content: '自定义',
  477. divider: true,
  478. },
  479. {
  480. value: 'x',
  481. content: 'X',
  482. type: 'float',
  483. keywords: true,
  484. },
  485. {
  486. value: 'y',
  487. content: 'Y',
  488. type: 'float',
  489. keywords: true,
  490. },
  491. {
  492. value: 'width',
  493. content: '宽',
  494. type: 'float',
  495. keywords: true,
  496. },
  497. {
  498. value: 'height',
  499. content: '高',
  500. type: 'float',
  501. keywords: true,
  502. },
  503. {
  504. value: 'visible',
  505. content: '显示',
  506. type: 'bool',
  507. keywords: true,
  508. },
  509. {
  510. value: 'text',
  511. content: '文字',
  512. // keywords: true,
  513. },
  514. {
  515. value: 'progress',
  516. content: '进度',
  517. type: 'float',
  518. keywords: true,
  519. },
  520. {
  521. value: 'showChild',
  522. content: '状态',
  523. type: 'integer',
  524. keywords: true,
  525. },
  526. {
  527. value: 'rotate',
  528. content: '旋转',
  529. type: 'integer',
  530. keywords: true,
  531. },
  532. ]);
  533. const moreOptions = ref<any>([
  534. {
  535. value: 'edit',
  536. content: '编辑',
  537. },
  538. {
  539. value: 'delete',
  540. content: '移除',
  541. },
  542. ]);
  543. const addDataDialog = reactive<any>({
  544. show: false,
  545. data: undefined,
  546. });
  547. const dataBindDialog = reactive<any>({
  548. show: false,
  549. data: undefined,
  550. });
  551. const ojbectDialog = reactive<any>({
  552. show: false,
  553. data: undefined,
  554. });
  555. const dataSetColumns = [
  556. {
  557. colKey: 'row-select',
  558. type: 'single',
  559. width: 50,
  560. },
  561. {
  562. colKey: 'device',
  563. title: '设备',
  564. ellipsis: { theme: 'light', trigger: 'context-menu' },
  565. },
  566. {
  567. colKey: 'label',
  568. title: '数据点名称',
  569. ellipsis: { theme: 'light', trigger: 'context-menu' },
  570. },
  571. {
  572. colKey: 'id',
  573. title: '数据点ID',
  574. ellipsis: { theme: 'light', trigger: 'context-menu' },
  575. },
  576. {
  577. colKey: 'type',
  578. title: '类型',
  579. width: 100,
  580. },
  581. {
  582. colKey: 'mock',
  583. title: '值范围',
  584. ellipsis: true,
  585. },
  586. ];
  587. const operatorOptions = ref<any>([
  588. { label: '=', value: '=' },
  589. { label: '!=', value: '!=' },
  590. { label: '>', value: '>' },
  591. { label: '<', value: '<' },
  592. { label: '>=', value: '>=' },
  593. { label: '<=', value: '<=' },
  594. { label: '包含', value: '[)' },
  595. { label: '不包含', value: '![)' },
  596. ]);
  597. const query = reactive<{
  598. current: number;
  599. pageSize: number;
  600. total: number;
  601. range: any[];
  602. }>({
  603. current: 1,
  604. pageSize: 10,
  605. total: 0,
  606. range: [],
  607. });
  608. const triggersDialog = reactive<any>({
  609. show: false,
  610. data: undefined,
  611. });
  612. const penTree: any = ref([]);
  613. let timer: any;
  614. onBeforeMount(() => {
  615. // realTimesOptions - 扩展的动态数据下拉列表
  616. if (props.pen.realTimesOptions) {
  617. options.value[options.value.length - 1].divider = true;
  618. options.value.push(...props.pen.realTimesOptions);
  619. }
  620. timer = setInterval($forceUpdate, 1000);
  621. });
  622. const addRealTime = (e: any) => {
  623. if (e.keywords || e.value === 'text') {
  624. if (!props.pen.realTimes) {
  625. props.pen.realTimes = [];
  626. }
  627. props.pen.realTimes.push({
  628. label: e.content,
  629. key: e.value,
  630. type: e.type,
  631. keywords: e.keywords,
  632. });
  633. return;
  634. }
  635. addDataDialog.header = '添加动态数据';
  636. addDataDialog.data = {
  637. label: e.content,
  638. key: e.value,
  639. type: e.type,
  640. keywords: e.keywords,
  641. };
  642. if (e.keywords) {
  643. addDataDialog.data.label = '';
  644. }
  645. addDataDialog.show = true;
  646. };
  647. const onKeyBlur = () => {
  648. if (addDataDialog.data) {
  649. let value = getter(props.pen, addDataDialog.data.key);
  650. if (value) {
  651. setter(addDataDialog.data, 'value', value);
  652. } else {
  653. addDataDialog.data.value = null;
  654. }
  655. }
  656. };
  657. const onChangeLabel = () => {
  658. if (!addDataDialog.data.key) {
  659. addDataDialog.data.key = addDataDialog.data.label;
  660. }
  661. };
  662. const onConfirmData = () => {
  663. if (!props.pen.realTimes) {
  664. props.pen.realTimes = [];
  665. }
  666. if (!addDataDialog.data.label || !addDataDialog.data.key) {
  667. MessagePlugin.error('数据名或属性名不能为空!');
  668. return;
  669. }
  670. if (addDataDialog.header === '添加动态数据') {
  671. const found = props.pen.realTimes.findIndex((item: any) => {
  672. return item.key === addDataDialog.data.key;
  673. });
  674. if (found > -1) {
  675. MessagePlugin.error('已经存在相同属性数据!');
  676. return;
  677. }
  678. props.pen.realTimes.push(addDataDialog.data);
  679. }
  680. addDataDialog.show = false;
  681. };
  682. const onMenuMore = (e: any, item: any, i: number) => {
  683. switch (e.value) {
  684. case 'edit':
  685. addDataDialog.header = '编辑动态数据';
  686. setter(item, 'value', getter(props.pen, item.key));
  687. addDataDialog.data = item;
  688. addDataDialog.show = true;
  689. break;
  690. case 'delete':
  691. props.pen.realTimes.splice(i, 1);
  692. break;
  693. default:
  694. break;
  695. }
  696. };
  697. const onBind = (item: any) => {
  698. dataBindDialog.data = item;
  699. dataBindDialog.input = '';
  700. dataBindDialog.selectedIds = [];
  701. if (item.bind && item.bind.id) {
  702. dataBindDialog.selectedIds.push(item.bind.id);
  703. }
  704. dataBindDialog.show = true;
  705. getDataset();
  706. };
  707. const onSearchDataset = () => {
  708. debounce(getDataset, 300);
  709. };
  710. const getDataset = async () => {
  711. // @ts-ignore
  712. const data: Meta2dBackData = meta2d.data();
  713. if (!data.dataset) {
  714. return;
  715. }
  716. dataBindDialog.loading = true;
  717. if (data.dataset.url) {
  718. const ret: any = await axios.get(data.dataset.url, {
  719. params: {
  720. device: dataBindDialog.device || '',
  721. q: dataBindDialog.input,
  722. current: query.current,
  723. pageSize: query.pageSize,
  724. },
  725. });
  726. dataBindDialog.dataset = ret;
  727. dataBindDialog.url = true;
  728. query.total = ret.total;
  729. } else {
  730. dataBindDialog.url = false;
  731. if (!dataBindDialog.datasetList) {
  732. const ret = await axios.post(`/api/data/datasources/get`, {
  733. id: data.dataset.id,
  734. });
  735. if (ret?.data) {
  736. data.dataset.data = ret.data;
  737. dataBindDialog.datasetList = data.dataset.data;
  738. const set = new Set<string>();
  739. for (const item of dataBindDialog.datasetList) {
  740. set.add(item.device);
  741. }
  742. dataBindDialog.devices = Array.from(set);
  743. } else {
  744. dataBindDialog.dataset = [];
  745. dataBindDialog.devices = [];
  746. return;
  747. }
  748. }
  749. if (dataBindDialog.device || dataBindDialog.input) {
  750. dataBindDialog.dataset = dataBindDialog.datasetList.filter(
  751. (item: any) => {
  752. if (dataBindDialog.device && item.device !== dataBindDialog.device) {
  753. return;
  754. }
  755. return (
  756. searchPinyin(item.label, dataBindDialog.input) ||
  757. item.id.indexOf(dataBindDialog.input) > -1
  758. );
  759. }
  760. );
  761. query.total = dataBindDialog.datasetList.length;
  762. } else {
  763. dataBindDialog.dataset = [...dataBindDialog.datasetList];
  764. query.total = dataBindDialog.datasetList.length;
  765. }
  766. }
  767. dataBindDialog.loading = false;
  768. };
  769. const onChangePagination = (pageInfo: any) => {
  770. router.push({
  771. path: route.path,
  772. query: { current: pageInfo.current, pageSize: pageInfo.pageSize },
  773. });
  774. query.current = pageInfo.current;
  775. query.pageSize = pageInfo.pageSize;
  776. getDataset();
  777. };
  778. const onSelectBindsChange = (value: string[], options: any) => {
  779. if (options.type === 'check') {
  780. dataBindDialog.selectedIds = value;
  781. dataBindDialog.data.bind = toRaw(options.selectedRowData[0]);
  782. dataBindDialog.data.mock = dataBindDialog.data.bind.mock;
  783. dataBindDialog.data.type = dataBindDialog.data.bind.type;
  784. doBindInit();
  785. } else if (options.type === 'uncheck') {
  786. dataBindDialog.selectedIds = [];
  787. dataBindDialog.data.bind = {};
  788. }
  789. };
  790. const doBindInit = () => {
  791. let { id } = dataBindDialog.data;
  792. if (props.pen.name === 'echarts' && id.includes('echarts.option.series')) {
  793. const { replaceMode } = props.pen.echarts;
  794. const { xAxis } = props.pen.echarts.option;
  795. let beforeV = getter(props.pen, id);
  796. if (Array.isArray(beforeV) && replaceMode === 0) {
  797. //追加
  798. setter(props.pen, id, []);
  799. let _key = 'echarts.option.xAxis.data';
  800. if (Array.isArray(xAxis) && xAxis.length) {
  801. _key = 'echarts.option.xAxis.0.data';
  802. }
  803. setter(props.pen, _key, []);
  804. }
  805. }
  806. };
  807. const dataBindonConfirm = () => {
  808. dataBindDialog.show = false;
  809. dataBindDialog.datasetList = undefined;
  810. meta2d.initBinds();
  811. };
  812. const onRemoveBind = () => {
  813. dataBindDialog.selectedIds = [];
  814. dataBindDialog.data.bind = undefined;
  815. };
  816. const getBindsDesc = (item: any) => {
  817. if (item.bind?.label) {
  818. return item.bind.label;
  819. }
  820. if (item.enableMock && item.mock) {
  821. return item.mock;
  822. }
  823. return '动态数据';
  824. };
  825. const changeValue = (prop: string) => {
  826. updatePen(props.pen, prop);
  827. };
  828. const onTrigger = (item: any) => {
  829. if (!item.triggers) {
  830. item.triggers = [];
  831. }
  832. triggersDialog.openedCollapses = [0];
  833. triggersDialog.data = item;
  834. triggersDialog.show = true;
  835. penTree.value = getPenTree();
  836. };
  837. const onAddTrigger = () => {
  838. const i = triggersDialog.data.triggers.length;
  839. triggersDialog.data.triggers.push({
  840. name: `触发器${i + 1}`,
  841. conditionType: 'and',
  842. conditions: [],
  843. actions: [],
  844. });
  845. triggersDialog.openedCollapses.push(i);
  846. };
  847. const addTriggerCondition = (trigger: any) => {
  848. trigger.conditions.push({
  849. type: '',
  850. operator: '=',
  851. valueType: '',
  852. });
  853. };
  854. const onChangeTriggerTarget = (c: any) => {
  855. c.targetProps = [
  856. {
  857. value: 'x',
  858. label: 'X',
  859. },
  860. {
  861. value: 'y',
  862. label: 'Y',
  863. },
  864. {
  865. value: 'width',
  866. label: '宽',
  867. },
  868. {
  869. value: 'height',
  870. label: '高',
  871. },
  872. {
  873. value: 'visible',
  874. label: '显示',
  875. },
  876. {
  877. value: 'text',
  878. label: '文字',
  879. },
  880. {
  881. value: 'progress',
  882. label: '进度',
  883. },
  884. {
  885. value: 'showChild',
  886. label: '状态',
  887. },
  888. {
  889. value: 'rotate',
  890. label: '旋转',
  891. },
  892. ];
  893. const target: any = meta2d.findOne(c.target);
  894. if (target) {
  895. for (const item of target.realTimes) {
  896. const found = c.targetProps.findIndex(
  897. (elem: any) => elem.value === item.key
  898. );
  899. if (found < 0) {
  900. c.targetProps.push({
  901. value: item.key,
  902. label: item.label,
  903. });
  904. }
  905. }
  906. }
  907. };
  908. const onInput = (item: any) => {
  909. item.label = item.value;
  910. };
  911. const editObject = (item: any) => {
  912. ojbectDialog.data = props.pen[item.key];
  913. ojbectDialog.item = item;
  914. ojbectDialog.show = true;
  915. };
  916. const onOkEditOjbect = () => {
  917. if (ojbectDialog.data) {
  918. if (
  919. ojbectDialog.item.type === 'array' &&
  920. !Array.isArray(ojbectDialog.data)
  921. ) {
  922. MessagePlugin.error('请输入数组格式数据');
  923. return;
  924. }
  925. props.pen[ojbectDialog.item.key] = ojbectDialog.data;
  926. props.pen[ojbectDialog.item.key] = updatePen(
  927. props.pen,
  928. ojbectDialog.item.key
  929. );
  930. ojbectDialog.show = false;
  931. } else {
  932. MessagePlugin.error('请输入严格的JSON格式数据');
  933. }
  934. };
  935. onUnmounted(() => {
  936. clearInterval(timer);
  937. });
  938. </script>
  939. <style lang="postcss" scoped>
  940. .props {
  941. height: 100%;
  942. .grid {
  943. grid-template-columns: 80px 120px 54px 30px;
  944. padding: 0 12px;
  945. &.head {
  946. background: var(--color-background-input);
  947. line-height: 36px;
  948. margin-bottom: 6px;
  949. .title {
  950. line-height: 36px;
  951. }
  952. }
  953. }
  954. .blank {
  955. height: 70%;
  956. img {
  957. padding: 16px;
  958. opacity: 0.9;
  959. }
  960. }
  961. .label {
  962. width: fix-content;
  963. font-size: 10px;
  964. line-height: 28px;
  965. color: var(--color-desc);
  966. }
  967. .value {
  968. padding-right: 8px;
  969. display: flex;
  970. align-items: center;
  971. justify-content: space-between;
  972. svg {
  973. flex-shrink: 0;
  974. margin-right: 4px;
  975. }
  976. & > div {
  977. width: 90px;
  978. &.t-switch {
  979. width: fit-content;
  980. margin-left: 4px;
  981. }
  982. }
  983. :deep(.t-input) {
  984. padding-left: 4px;
  985. height: 26px;
  986. border-color: transparent;
  987. &:hover {
  988. border-color: var(--color-primary);
  989. }
  990. }
  991. }
  992. .actions {
  993. text-align: right;
  994. padding-right: 2px;
  995. }
  996. .data-list {
  997. :deep(.t-table__header--fixed:not(.t-table__header--multiple) > tr > th) {
  998. background: none;
  999. }
  1000. :deep(.t-table__pagination) {
  1001. padding-bottom: 0;
  1002. }
  1003. }
  1004. }
  1005. .body {
  1006. :deep(.t-collapse.t--border-less) {
  1007. .t-collapse-panel__header {
  1008. border-top: none;
  1009. border-bottom: 1px solid var(--td-border-level-1-color);
  1010. padding: 8px 0;
  1011. .t-input {
  1012. border: none;
  1013. padding-left: 0;
  1014. font-size: 14px;
  1015. }
  1016. }
  1017. .t-collapse-panel__content {
  1018. padding: 8px 0;
  1019. }
  1020. }
  1021. .title {
  1022. position: relative;
  1023. margin: 8px 0;
  1024. :deep(.t-input) {
  1025. border-color: var(--color-background-input);
  1026. border-radius: 0;
  1027. border-left: none;
  1028. border-top: none;
  1029. border-right: none;
  1030. padding-left: 0;
  1031. padding-bottom: 8px;
  1032. font-size: 14px;
  1033. &:hover {
  1034. border-color: var(--color-border-input);
  1035. }
  1036. }
  1037. }
  1038. .head {
  1039. margin-top: 10px;
  1040. }
  1041. .banner {
  1042. background-color: var(--color-background-input);
  1043. padding: 0 12px;
  1044. }
  1045. }
  1046. </style>