PenEvents.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <div class="props">
  3. <div v-if="props.pen.events && props.pen.events.length">
  4. <t-collapse
  5. v-model="openedCollapses"
  6. :borderless="true"
  7. :expand-on-row-click="true"
  8. expand-icon-placement="left"
  9. >
  10. <t-collapse-panel v-for="(item, i) in props.pen.events" v-show="!item.hideInPanel" :value="i">
  11. <template #header>
  12. <div @click.stop class="head flex">
  13. <t-select
  14. v-model="item.name"
  15. style="width: 40%"
  16. @change="eventNameChange"
  17. :options="options"
  18. autoWidth
  19. />
  20. <t-input
  21. v-if="item.name === 'message'"
  22. style="width: 93px;margin-left: 20px;"
  23. v-model="item.message"
  24. :placeholder="$t('消息名')"
  25. />
  26. </div>
  27. </template>
  28. <template #headerRightContent>
  29. <t-space size="small" @click.stop>
  30. <t-popconfirm placement="left" @confirm="props.pen.events.splice(i, 1)" :content="$t('确认删除该交互事件吗?')">
  31. <!-- <t-icon name="delete" class="hover" /> -->
  32. <delete-icon class="hover"/>
  33. </t-popconfirm>
  34. </t-space>
  35. </template>
  36. <Conditions :data="props.pen.events[i]" />
  37. <div class="form-item mt-16" v-if="['click','dblclick'].includes(item.name)||item.confirm">
  38. <label>二次确认</label>
  39. <t-switch size="small" class="mt-8 ml-8" v-model="item.confirm" />
  40. </div>
  41. <div v-if="item.confirm" class="form-item mt-8 mb-16">
  42. <label>确认文本</label>
  43. <t-input v-model="item.confirmTitle" />
  44. </div>
  45. <Actions :data="props.pen.events[i]" />
  46. </t-collapse-panel>
  47. </t-collapse>
  48. <t-divider />
  49. <div class="p-16">
  50. <t-dropdown
  51. :options="options"
  52. @click="addEvent"
  53. :minColumnWidth="254"
  54. :maxHeight="360"
  55. >
  56. <t-button class="w-full" style="height: 30px">
  57. {{$t('添加交互事件')}}
  58. </t-button>
  59. </t-dropdown>
  60. </div>
  61. </div>
  62. <div class="flex column center blank" v-else>
  63. <img src="/img/blank.png">
  64. <div class="gray center">{{$t('还没有交互事件')}}</div>
  65. <div class="mt-8">
  66. <t-dropdown :options="options" @click="addEvent" :minColumnWidth="150" :maxHeight="360">
  67. <t-button style="height: 30px"> {{$t('添加交互事件')}} </t-button>
  68. </t-dropdown>
  69. </div>
  70. </div>
  71. </div>
  72. </template>
  73. <script lang="ts" setup>
  74. import { onBeforeMount, onUnmounted, ref, computed, getCurrentInstance } from 'vue';
  75. import Actions from './Actions.vue';
  76. import Conditions from './Conditions.vue';
  77. import { DeleteIcon } from 'tdesign-icons-vue-next';
  78. import { initEvent } from '@meta2d/chart-diagram';
  79. const { proxy } = getCurrentInstance();
  80. const $t = proxy.$t
  81. const props = defineProps<{
  82. pen: any;
  83. }>();
  84. // const options = ref<any>([
  85. // {
  86. // value: 'click',
  87. // content: $t('单击'),
  88. // },
  89. // {
  90. // value: 'dblclick',
  91. // content: $t('双击'),
  92. // divider: true,
  93. // },
  94. // {
  95. // value: 'change',
  96. // content: $t('输入完成'),
  97. // },
  98. // {
  99. // value: 'input',
  100. // content: $t('输入'),
  101. // divider: true,
  102. // },
  103. // {
  104. // value: 'contextmenu',
  105. // content: $t('鼠标右键'),
  106. // },
  107. // {
  108. // value: 'enter',
  109. // content: $t('鼠标移入'),
  110. // },
  111. // {
  112. // value: 'leave',
  113. // content: $t('鼠标移出'),
  114. // divider: true,
  115. // },
  116. // {
  117. // value: 'active',
  118. // content: $t('获得焦点'),
  119. // },
  120. // {
  121. // value: 'inactive',
  122. // content: $t('失去焦点'),
  123. // divider: true,
  124. // },
  125. // {
  126. // value: 'mousedown',
  127. // content: $t('鼠标按下'),
  128. // },
  129. // {
  130. // value: 'mouseup',
  131. // content: $t('鼠标抬起'),
  132. // divider: true,
  133. // },
  134. // {
  135. // value: 'message',
  136. // content: $t('监听全局消息'),
  137. // },
  138. // ]);
  139. const options: any = computed(() => {
  140. const options = [
  141. {
  142. value: 'click',
  143. content: $t('单击'),
  144. },
  145. {
  146. value: 'dblclick',
  147. content: $t('双击'),
  148. divider: true,
  149. },
  150. ];
  151. if (props.pen.dropdownList) {
  152. options.push({
  153. value: 'change',
  154. content: $t('选择完成'),
  155. divider: true,
  156. });
  157. } else if (props.pen.name === 'inputDom') {
  158. options.push({
  159. value: 'input',
  160. content: $t('输入'),
  161. divider: true,
  162. });
  163. } else if (props.pen.input) {
  164. options.push(
  165. ...[
  166. {
  167. value: 'change',
  168. content: $t('输入完成'),
  169. },
  170. {
  171. value: 'input',
  172. content: $t('输入'),
  173. divider: true,
  174. },
  175. ]
  176. );
  177. }else if(props.pen.name=='form'){
  178. //表单组件
  179. options.push(
  180. ...[
  181. {
  182. value: 'submit',
  183. content: '表单提交',
  184. },
  185. {
  186. value: 'reset',
  187. content: '表单重置',
  188. divider: true,
  189. },
  190. ]
  191. );
  192. }
  193. options.push(
  194. ...[
  195. {
  196. value: 'contextmenu',
  197. content: $t('鼠标右键'),
  198. },
  199. {
  200. value: 'enter',
  201. content: $t('鼠标移入'),
  202. },
  203. {
  204. value: 'leave',
  205. content: $t('鼠标移出'),
  206. divider: true,
  207. },
  208. {
  209. value: 'active',
  210. content: $t('获得焦点'),
  211. },
  212. {
  213. value: 'inactive',
  214. content: $t('失去焦点'),
  215. divider: true,
  216. },
  217. {
  218. value: 'mousedown',
  219. content: $t('鼠标按下'),
  220. },
  221. {
  222. value: 'mouseup',
  223. content: $t('鼠标抬起'),
  224. divider: true,
  225. },
  226. {
  227. value: 'message',
  228. content: $t('监听全局消息'),
  229. },
  230. ]
  231. );
  232. return options;
  233. });
  234. const openedCollapses = ref([0]);
  235. onBeforeMount(() => {
  236. if (!props.pen.events) {
  237. props.pen.events = [];
  238. }
  239. for (const item of options.value) {
  240. item.label = item.content;
  241. }
  242. });
  243. const addEvent = (e: any) => {
  244. if (!props.pen.events) {
  245. props.pen.events = [];
  246. }
  247. props.pen.events.push({ name: e.value });
  248. if(props.pen.name === 'echarts'){
  249. initEvent(props.pen);
  250. }
  251. };
  252. const eventNameChange = ()=>{
  253. if(props.pen.name === 'echarts'){
  254. initEvent(props.pen);
  255. }
  256. }
  257. onUnmounted(() => {});
  258. </script>
  259. <style lang="postcss" scoped>
  260. .props {
  261. height: 100%;
  262. .blank {
  263. height: 70%;
  264. img {
  265. padding: 16px;
  266. opacity: 0.9;
  267. }
  268. }
  269. .head {
  270. :deep(.t-select) {
  271. width: fit-content;
  272. .t-input {
  273. border-color: transparent;
  274. }
  275. }
  276. }
  277. .banner {
  278. background-color: var(--color-background-input);
  279. padding: 0 12px;
  280. }
  281. :deep(.value-input) {
  282. max-width: 95px;
  283. }
  284. :deep(.value-label){
  285. width: 50px;
  286. overflow: hidden;
  287. text-overflow:ellipsis;
  288. white-space: nowrap;
  289. }
  290. }
  291. </style>