PenEvents.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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">
  13. <t-select v-model="item.name" :options="options" autoWidth />
  14. </div>
  15. </template>
  16. <template #headerRightContent>
  17. <t-space size="small" @click.stop>
  18. <t-popconfirm
  19. content="确认删除该交互事件吗"
  20. placement="left"
  21. @confirm="props.pen.events.splice(i, 1)"
  22. >
  23. <t-icon name="delete" class="hover" />
  24. </t-popconfirm>
  25. </t-space>
  26. </template>
  27. <Actions :data="props.pen.events[i]" />
  28. </t-collapse-panel>
  29. </t-collapse>
  30. <t-divider />
  31. <div class="p-16">
  32. <t-dropdown
  33. :options="options"
  34. @click="addEvent"
  35. :minColumnWidth="254"
  36. :maxHeight="360"
  37. >
  38. <t-button class="w-full" style="height: 30px">
  39. 添加交互事件
  40. </t-button>
  41. </t-dropdown>
  42. </div>
  43. </div>
  44. <div class="flex column center blank" v-else>
  45. <img src="/img/blank.png" />
  46. <div class="gray center">还没有交互事件</div>
  47. <div class="mt-8">
  48. <t-dropdown
  49. :options="options"
  50. @click="addEvent"
  51. :minColumnWidth="150"
  52. :maxHeight="360"
  53. >
  54. <t-button style="height: 30px"> 添加交互事件 </t-button>
  55. </t-dropdown>
  56. </div>
  57. </div>
  58. </div>
  59. </template>
  60. <script lang="ts" setup>
  61. import { onBeforeMount, onUnmounted, ref } from 'vue';
  62. import Actions from './Actions.vue';
  63. const props = defineProps<{
  64. pen: any;
  65. }>();
  66. const options = ref<any>([
  67. {
  68. value: 'click',
  69. content: '单击',
  70. },
  71. {
  72. value: 'dblclick',
  73. content: '双击',
  74. divider: true,
  75. },
  76. {
  77. value: 'enter',
  78. content: '鼠标移入',
  79. },
  80. {
  81. value: 'leave',
  82. content: '鼠标移出',
  83. divider: true,
  84. },
  85. {
  86. value: 'active',
  87. content: '获得焦点',
  88. },
  89. {
  90. value: 'inactive',
  91. content: '失去焦点',
  92. divider: true,
  93. },
  94. {
  95. value: 'mousedown',
  96. content: '鼠标按下',
  97. },
  98. {
  99. value: 'mouseup',
  100. content: '鼠标抬起',
  101. divider: true,
  102. },
  103. {
  104. value: 'message',
  105. content: '监听消息',
  106. },
  107. ]);
  108. const openedCollapses = ref([0]);
  109. onBeforeMount(() => {
  110. if (!props.pen.events) {
  111. props.pen.events = [];
  112. }
  113. for (const item of options.value) {
  114. item.label = item.content;
  115. }
  116. });
  117. const addEvent = (e: any) => {
  118. props.pen.events.push({ name: e.value });
  119. };
  120. onUnmounted(() => {});
  121. </script>
  122. <style lang="postcss" scoped>
  123. .props {
  124. height: 100%;
  125. .blank {
  126. height: 70%;
  127. img {
  128. padding: 16px;
  129. opacity: 0.9;
  130. }
  131. }
  132. .head {
  133. :deep(.t-select) {
  134. width: fit-content;
  135. .t-input {
  136. border-color: transparent;
  137. }
  138. }
  139. }
  140. .banner {
  141. background-color: var(--color-background-input);
  142. padding: 0 12px;
  143. }
  144. }
  145. </style>