LineStylePanel.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="line-style-panel">
  3. <div class="row">
  4. <div style="width: 40%;">线条样式:</div>
  5. <SelectCustom style="width: 60%;">
  6. <template #options>
  7. <div class="option" v-for="item in lineStyleOptions" :key="item" @click="updateLine({ style: item })">
  8. <SVGLine :type="item" />
  9. </div>
  10. </template>
  11. <template #label>
  12. <SVGLine :type="handleLineElement.style" />
  13. </template>
  14. </SelectCustom>
  15. </div>
  16. <div class="row">
  17. <div style="width: 40%;">线条颜色:</div>
  18. <Popover trigger="click" style="width: 60%;">
  19. <template #content>
  20. <ColorPicker
  21. :modelValue="handleLineElement.color"
  22. @update:modelValue="value => updateLine({ color: value })"
  23. />
  24. </template>
  25. <ColorButton :color="handleLineElement.color" />
  26. </Popover>
  27. </div>
  28. <div class="row">
  29. <div style="width: 40%;">线条宽度:</div>
  30. <NumberInput
  31. :value="handleLineElement.width"
  32. @update:value="value => updateLine({ width: value })"
  33. style="width: 60%;"
  34. />
  35. </div>
  36. <div class="row">
  37. <div style="width: 40%;">起点样式:</div>
  38. <SelectCustom style="width: 60%;">
  39. <template #options>
  40. <div class="option" v-for="item in lineMarkerOptions" :key="item" @click="updateLine({ points: [item, handleLineElement.points[1]] })">
  41. <SVGLine :padding="5" :markers="[item, '']" />
  42. </div>
  43. </template>
  44. <template #label>
  45. <SVGLine :padding="5" :markers="[handleLineElement.points[0], '']" />
  46. </template>
  47. </SelectCustom>
  48. </div>
  49. <div class="row">
  50. <div style="width: 40%;">终点样式:</div>
  51. <SelectCustom style="width: 60%;">
  52. <template #options>
  53. <div class="option" v-for="item in lineMarkerOptions" :key="item" @click="updateLine({ points: [handleLineElement.points[0], item] })">
  54. <SVGLine :padding="5" :markers="['', item]" />
  55. </div>
  56. </template>
  57. <template #label>
  58. <SVGLine :padding="5" :markers="['', handleLineElement.points[1]]" />
  59. </template>
  60. </SelectCustom>
  61. </div>
  62. <Divider />
  63. <div class="row">
  64. <Button style="flex: 1;" @click="updateLine({ start: handleLineElement.end, end: handleLineElement.start })"><IconSwitch /> 交换方向</Button>
  65. </div>
  66. <Divider />
  67. <ElementShadow />
  68. </div>
  69. </template>
  70. <script lang="ts" setup>
  71. import { type Ref, ref } from 'vue'
  72. import { storeToRefs } from 'pinia'
  73. import { useMainStore, useSlidesStore } from '@/store'
  74. import type { LinePoint, LineStyleType, PPTLineElement } from '@/types/slides'
  75. import useHistorySnapshot from '@/hooks/useHistorySnapshot'
  76. import ElementShadow from '../common/ElementShadow.vue'
  77. import SVGLine from '../common/SVGLine.vue'
  78. import Button from '@/components/Button.vue'
  79. import ColorButton from '@/components/ColorButton.vue'
  80. import ColorPicker from '@/components/ColorPicker/index.vue'
  81. import Divider from '@/components/Divider.vue'
  82. import NumberInput from '@/components/NumberInput.vue'
  83. import SelectCustom from '@/components/SelectCustom.vue'
  84. import Popover from '@/components/Popover.vue'
  85. const slidesStore = useSlidesStore()
  86. const { handleElement } = storeToRefs(useMainStore())
  87. const handleLineElement = handleElement as Ref<PPTLineElement>
  88. const { addHistorySnapshot } = useHistorySnapshot()
  89. const lineStyleOptions = ref<LineStyleType[]>(['solid', 'dashed', 'dotted'])
  90. const lineMarkerOptions = ref<LinePoint[]>(['', 'arrow', 'dot'])
  91. const updateLine = (props: Partial<PPTLineElement>) => {
  92. if (!handleElement.value) return
  93. slidesStore.updateElement({ id: handleElement.value.id, props })
  94. addHistorySnapshot()
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .row {
  99. width: 100%;
  100. display: flex;
  101. align-items: center;
  102. margin-bottom: 10px;
  103. }
  104. .line-btn {
  105. display: flex;
  106. align-items: center;
  107. justify-content: space-between;
  108. padding: 0 !important;
  109. .line-wrapper {
  110. margin-left: 8px;
  111. }
  112. }
  113. .line-wrapper {
  114. overflow: visible;
  115. }
  116. .line-btn-icon {
  117. width: 30px;
  118. font-size: 12px;
  119. margin-top: 2px;
  120. color: #bfbfbf;
  121. }
  122. .preset-point-style {
  123. padding: 0 10px;
  124. & + .preset-point-style {
  125. margin-top: 10px;
  126. }
  127. }
  128. .option {
  129. height: 32px;
  130. padding: 0 5px;
  131. border-radius: $borderRadius;
  132. &:not(.selected):hover {
  133. background-color: rgba($color: $themeColor, $alpha: .05);
  134. cursor: pointer;
  135. }
  136. &.selected {
  137. color: $themeColor;
  138. font-weight: 700;
  139. }
  140. }
  141. </style>