PenEvents.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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" :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">
  38. <label>二次确认</label>
  39. <t-switch class="mt-8 ml-8" v-if="['click','dblclick'].includes(item.name)" 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. }
  178. options.push(
  179. ...[
  180. {
  181. value: 'contextmenu',
  182. content: $t('鼠标右键'),
  183. },
  184. {
  185. value: 'enter',
  186. content: $t('鼠标移入'),
  187. },
  188. {
  189. value: 'leave',
  190. content: $t('鼠标移出'),
  191. divider: true,
  192. },
  193. {
  194. value: 'active',
  195. content: $t('获得焦点'),
  196. },
  197. {
  198. value: 'inactive',
  199. content: $t('失去焦点'),
  200. divider: true,
  201. },
  202. {
  203. value: 'mousedown',
  204. content: $t('鼠标按下'),
  205. },
  206. {
  207. value: 'mouseup',
  208. content: $t('鼠标抬起'),
  209. divider: true,
  210. },
  211. {
  212. value: 'message',
  213. content: $t('监听全局消息'),
  214. },
  215. ]
  216. );
  217. return options;
  218. });
  219. const openedCollapses = ref([0]);
  220. onBeforeMount(() => {
  221. if (!props.pen.events) {
  222. props.pen.events = [];
  223. }
  224. for (const item of options.value) {
  225. item.label = item.content;
  226. }
  227. });
  228. const addEvent = (e: any) => {
  229. if (!props.pen.events) {
  230. props.pen.events = [];
  231. }
  232. props.pen.events.push({ name: e.value });
  233. if(props.pen.name === 'echarts'){
  234. initEvent(props.pen);
  235. }
  236. };
  237. const eventNameChange = ()=>{
  238. if(props.pen.name === 'echarts'){
  239. initEvent(props.pen);
  240. }
  241. }
  242. onUnmounted(() => {});
  243. </script>
  244. <style lang="postcss" scoped>
  245. .props {
  246. height: 100%;
  247. .blank {
  248. height: 70%;
  249. img {
  250. padding: 16px;
  251. opacity: 0.9;
  252. }
  253. }
  254. .head {
  255. :deep(.t-select) {
  256. width: fit-content;
  257. .t-input {
  258. border-color: transparent;
  259. }
  260. }
  261. }
  262. .banner {
  263. background-color: var(--color-background-input);
  264. padding: 0 12px;
  265. }
  266. :deep(.value-input) {
  267. max-width: 95px;
  268. }
  269. :deep(.value-label){
  270. width: 50px;
  271. overflow: hidden;
  272. text-overflow:ellipsis;
  273. white-space: nowrap;
  274. }
  275. }
  276. </style>