ElementOutline.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class="element-outline">
  3. <div class="row">
  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 { useStore } from 'vuex'
  50. import { MutationTypes, State } from '@/store'
  51. import { PPTElement, PPTElementOutline } from '@/types/slides'
  52. import useHistorySnapshot from '@/hooks/useHistorySnapshot'
  53. import ColorButton from './ColorButton.vue'
  54. export default defineComponent({
  55. name: 'element-outline',
  56. components: {
  57. ColorButton,
  58. },
  59. setup() {
  60. const store = useStore<State>()
  61. const handleElement = computed<PPTElement>(() => store.getters.handleElement)
  62. const outline = ref<PPTElementOutline>()
  63. const hasOutline = ref(false)
  64. watch(handleElement, () => {
  65. if(!handleElement.value) return
  66. outline.value = 'outline' in handleElement.value ? handleElement.value.outline : undefined
  67. hasOutline.value = !!outline.value
  68. }, { deep: true, immediate: true })
  69. const { addHistorySnapshot } = useHistorySnapshot()
  70. const updateOutline = (outlineProps: Partial<PPTElementOutline>) => {
  71. const props = { outline: { ...outline.value, ...outlineProps } }
  72. store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })
  73. addHistorySnapshot()
  74. }
  75. const toggleOutline = (checked: boolean) => {
  76. let props: { outline?: PPTElementOutline } = { outline: undefined }
  77. if(checked) {
  78. props = { outline: { width: 2, color: '#000', style: 'solid' } }
  79. }
  80. store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })
  81. addHistorySnapshot()
  82. }
  83. return {
  84. outline,
  85. hasOutline,
  86. toggleOutline,
  87. updateOutline,
  88. }
  89. },
  90. })
  91. </script>
  92. <style lang="scss" scoped>
  93. .row {
  94. width: 100%;
  95. display: flex;
  96. align-items: center;
  97. margin-bottom: 10px;
  98. }
  99. .switch-wrapper {
  100. text-align: right;
  101. }
  102. </style>