PenDatas.vue 27 KB

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