PenProps.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="props">
  3. <t-tabs v-model="data.tab">
  4. <t-tab-panel :value="1" label="外观">
  5. <t-space direction="vertical" class="panel">
  6. <div class="form-item">
  7. <t-input-number
  8. label="X"
  9. v-model="data.rect.x"
  10. placeholder="x"
  11. theme="normal"
  12. style="width: 80px"
  13. @change="changeRect"
  14. />
  15. <t-icon name="link" class="hidden ml-4" />
  16. <t-input-number
  17. class="ml-8"
  18. label="Y"
  19. placeholder="y"
  20. theme="normal"
  21. v-model="data.rect.y"
  22. style="width: 80px"
  23. @change="changeRect"
  24. />
  25. <t-input
  26. class="ml-8"
  27. v-model="data.pen.rotate"
  28. placeholder="旋转"
  29. style="width: 72px"
  30. @change="changeValue"
  31. >
  32. <template #prefix-icon>
  33. <svg class="l-icon" aria-hidden="true">
  34. <use xlink:href="#l-rotate"></use>
  35. </svg>
  36. </template>
  37. </t-input>
  38. </div>
  39. <div class="form-item hover-icons" style="margin-top: -12px">
  40. <t-input-number
  41. label="W"
  42. v-model="data.rect.width"
  43. placeholder="宽"
  44. theme="normal"
  45. min="1"
  46. style="width: 80px"
  47. @change="changeRect(1)"
  48. />
  49. <t-tooltip v-if="data.pen.ratio" content="固定比例" placement="top">
  50. <t-icon
  51. name="link"
  52. class="ml-4 hover"
  53. @click="data.pen.ratio = !data.pen.ratio"
  54. />
  55. </t-tooltip>
  56. <t-tooltip v-else content="不固定比例" placement="top">
  57. <t-icon
  58. name="link-unlink"
  59. class="ml-4 hover icon"
  60. @click="data.pen.ratio = !data.pen.ratio"
  61. />
  62. </t-tooltip>
  63. <t-input-number
  64. class="ml-8"
  65. label="H"
  66. placeholder="高"
  67. theme="normal"
  68. min="1"
  69. v-model="data.rect.height"
  70. style="width: 80px"
  71. @change="changeRect(2)"
  72. />
  73. <t-input
  74. class="ml-8"
  75. v-model.number="data.pen.borderRadius"
  76. placeholder="圆角"
  77. style="width: 72px"
  78. @change="changeValue"
  79. >
  80. <template #prefix-icon>
  81. <svg class="l-icon" aria-hidden="true">
  82. <use xlink:href="#l-border-radius"></use>
  83. </svg>
  84. </template>
  85. </t-input>
  86. </div>
  87. <t-divider style="margin: -8px 0" />
  88. <div class="form-item" style="margin-top: -12px">
  89. <label>不透明度</label>
  90. <t-slider
  91. v-model="data.pen.globalAlpha"
  92. :min="0"
  93. :max="1"
  94. :step="0.01"
  95. @change="changeValue"
  96. />
  97. <span class="ml-16" style="width: 50px; line-height: 30px">
  98. {{ data.pen.globalAlpha }}
  99. </span>
  100. </div>
  101. <div class="form-item" style="margin-top: -12px">
  102. <label>不透明度</label>
  103. <t-slider
  104. v-model="data.pen.globalAlpha"
  105. :min="0"
  106. :max="1"
  107. :step="0.01"
  108. @change="changeValue"
  109. />
  110. <span class="ml-16" style="width: 50px; line-height: 30px">
  111. {{ data.pen.globalAlpha }}
  112. </span>
  113. </div>
  114. </t-space>
  115. </t-tab-panel>
  116. <t-tab-panel :value="2" label="事件"> </t-tab-panel>
  117. <t-tab-panel :value="3" label="动画"> </t-tab-panel>
  118. <t-tab-panel :value="4" label="数据"> </t-tab-panel>
  119. </t-tabs>
  120. </div>
  121. </template>
  122. <script lang="ts" setup>
  123. import { onBeforeMount, onUnmounted, reactive } from 'vue';
  124. import { getCookie } from '@/services/cookie';
  125. import { useSelection } from '@/services/selections';
  126. const headers = {
  127. Authorization: 'Bearer ' + (localStorage.token || getCookie('token') || ''),
  128. };
  129. const updataData = { directory: '/项目' };
  130. const data = reactive<any>({
  131. tab: 1,
  132. pen: {},
  133. rect: {},
  134. });
  135. const { selections } = useSelection();
  136. onBeforeMount(() => {
  137. data.pen = selections.pen;
  138. getRect();
  139. meta2d.on('translatePens', getRect);
  140. meta2d.on('resizePens', getRect);
  141. meta2d.on('rotatePens', getRect);
  142. });
  143. const getRect = () => {
  144. data.rect = meta2d.getPenRect(data.pen);
  145. };
  146. const changeRect = (mode?: number) => {
  147. //宽高比锁定
  148. if (data.pen.ratio) {
  149. if (mode === 1) {
  150. data.rect.height = (data.rect.width / data.pen.width) * data.pen.height;
  151. } else if (mode === 2) {
  152. data.rect.width = (data.rect.height / data.pen.height) * data.pen.width;
  153. }
  154. }
  155. meta2d.setPenRect(data.pen, data.rect, true);
  156. };
  157. const changeValue = (mode?: number) => {
  158. switch (mode) {
  159. case 1:
  160. break;
  161. }
  162. meta2d.render();
  163. };
  164. onUnmounted(() => {
  165. meta2d.off('translatePens', getRect);
  166. meta2d.off('resizePens', getRect);
  167. meta2d.off('rotatePens', getRect);
  168. });
  169. </script>
  170. <style lang="postcss" scoped>
  171. .props {
  172. }
  173. </style>