PenEvents.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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> {{$t('二次确认')}}</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>{{$t('确认文本')}}</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(['datePickerDom','dateRangePickerDom','treeFilterDom','cascadeFilterDom'].includes(props.pen.name)){
  164. options.push({
  165. value: 'change',
  166. content: '选择完成',
  167. divider: true,
  168. });
  169. }else if (props.pen.input) {
  170. options.push(
  171. ...[
  172. {
  173. value: 'change',
  174. content: $t('输入完成'),
  175. },
  176. {
  177. value: 'input',
  178. content: $t('输入'),
  179. divider: true,
  180. },
  181. ]
  182. );
  183. }else if(props.pen.name=='form'){
  184. //表单组件
  185. options.push(
  186. ...[
  187. {
  188. value: 'submit',
  189. content: '表单提交',
  190. },
  191. {
  192. value: 'reset',
  193. content: '表单重置',
  194. divider: true,
  195. },
  196. ]
  197. );
  198. }
  199. options.push(
  200. ...[
  201. {
  202. value: 'contextmenu',
  203. content: $t('鼠标右键'),
  204. },
  205. {
  206. value: 'enter',
  207. content: $t('鼠标移入'),
  208. },
  209. {
  210. value: 'leave',
  211. content: $t('鼠标移出'),
  212. divider: true,
  213. },
  214. {
  215. value: 'active',
  216. content: $t('获得焦点'),
  217. },
  218. {
  219. value: 'inactive',
  220. content: $t('失去焦点'),
  221. divider: true,
  222. },
  223. {
  224. value: 'mousedown',
  225. content: $t('鼠标按下'),
  226. },
  227. {
  228. value: 'mouseup',
  229. content: $t('鼠标抬起'),
  230. divider: true,
  231. },
  232. {
  233. value: 'message',
  234. content: $t('监听全局消息'),
  235. },
  236. ]
  237. );
  238. return options;
  239. });
  240. const openedCollapses = ref([0]);
  241. onBeforeMount(() => {
  242. if (!props.pen.events) {
  243. props.pen.events = [];
  244. }
  245. for (const item of options.value) {
  246. item.label = item.content;
  247. }
  248. });
  249. const addEvent = (e: any) => {
  250. if (!props.pen.events) {
  251. props.pen.events = [];
  252. }
  253. props.pen.events.push({ name: e.value });
  254. if(props.pen.name === 'echarts'){
  255. initEvent(props.pen);
  256. }
  257. };
  258. const eventNameChange = ()=>{
  259. if(props.pen.name === 'echarts'){
  260. initEvent(props.pen);
  261. }
  262. }
  263. onUnmounted(() => {});
  264. </script>
  265. <style lang="postcss" scoped>
  266. .props {
  267. height: 100%;
  268. .blank {
  269. height: 70%;
  270. img {
  271. padding: 16px;
  272. opacity: 0.9;
  273. }
  274. }
  275. .head {
  276. :deep(.t-select) {
  277. width: fit-content;
  278. .t-input {
  279. border-color: transparent;
  280. }
  281. }
  282. }
  283. .banner {
  284. background-color: var(--color-background-input);
  285. padding: 0 12px;
  286. }
  287. :deep(.value-input) {
  288. max-width: 95px;
  289. }
  290. :deep(.value-label){
  291. width: 50px;
  292. overflow: hidden;
  293. text-overflow:ellipsis;
  294. white-space: nowrap;
  295. }
  296. }
  297. </style>