ElementOutline.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div class="element-outline">
  3. <div class="row" v-if="!fixed">
  4. <div style="flex: 2;">启用边框:</div>
  5. <div class="switch-wrapper" style="flex: 3;">
  6. <Switch
  7. :checked="hasOutline"
  8. @change="checked => toggleOutline(checked)"
  9. />
  10. </div>
  11. </div>
  12. <template v-if="hasOutline">
  13. <div class="row">
  14. <div style="flex: 2;">边框样式:</div>
  15. <Select
  16. style="flex: 3;"
  17. :value="outline.style"
  18. @change="value => updateOutline({ style: value })"
  19. >
  20. <SelectOption value="solid">实线边框</SelectOption>
  21. <SelectOption value="dashed">虚线边框</SelectOption>
  22. </Select>
  23. </div>
  24. <div class="row">
  25. <div style="flex: 2;">边框颜色:</div>
  26. <Popover trigger="click">
  27. <template #content>
  28. <ColorPicker
  29. :modelValue="outline.color"
  30. @update:modelValue="value => updateOutline({ color: value })"
  31. />
  32. </template>
  33. <ColorButton :color="outline.color" style="flex: 3;" />
  34. </Popover>
  35. </div>
  36. <div class="row">
  37. <div style="flex: 2;">边框粗细:</div>
  38. <InputNumber
  39. :value="outline.width"
  40. @change="value => updateOutline({ width: value })"
  41. style="flex: 3;"
  42. />
  43. </div>
  44. </template>
  45. </div>
  46. </template>
  47. <script lang="ts">
  48. import { computed, defineComponent, ref, watch } from 'vue'
  49. import { MutationTypes, useStore } from '@/store'
  50. import { PPTElement, PPTElementOutline } from '@/types/slides'
  51. import useHistorySnapshot from '@/hooks/useHistorySnapshot'
  52. import ColorButton from './ColorButton.vue'
  53. export default defineComponent({
  54. name: 'element-outline',
  55. components: {
  56. ColorButton,
  57. },
  58. props: {
  59. fixed: {
  60. type: Boolean,
  61. default: false,
  62. },
  63. },
  64. setup() {
  65. const store = useStore()
  66. const handleElement = computed<PPTElement>(() => store.getters.handleElement)
  67. const outline = ref<PPTElementOutline>()
  68. const hasOutline = ref(false)
  69. watch(handleElement, () => {
  70. if (!handleElement.value) return
  71. outline.value = 'outline' in handleElement.value ? handleElement.value.outline : undefined
  72. hasOutline.value = !!outline.value
  73. }, { deep: true, immediate: true })
  74. const { addHistorySnapshot } = useHistorySnapshot()
  75. const updateOutline = (outlineProps: Partial<PPTElementOutline>) => {
  76. const props = { outline: { ...outline.value, ...outlineProps } }
  77. store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })
  78. addHistorySnapshot()
  79. }
  80. const toggleOutline = (checked: boolean) => {
  81. if (checked) {
  82. const props = { outline: { width: 2, color: '#000', style: 'solid' } }
  83. store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })
  84. }
  85. else {
  86. store.commit(MutationTypes.REMOVE_ELEMENT_PROPS, { id: handleElement.value.id, propName: 'outline' })
  87. }
  88. addHistorySnapshot()
  89. }
  90. return {
  91. outline,
  92. hasOutline,
  93. toggleOutline,
  94. updateOutline,
  95. }
  96. },
  97. })
  98. </script>
  99. <style lang="scss" scoped>
  100. .row {
  101. width: 100%;
  102. display: flex;
  103. align-items: center;
  104. margin-bottom: 10px;
  105. }
  106. .switch-wrapper {
  107. text-align: right;
  108. }
  109. </style>