| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <template>
- <div class="element-outline">
- <div class="row" v-if="!fixed">
- <div style="flex: 2;">启用边框:</div>
- <div class="switch-wrapper" style="flex: 3;">
- <Switch
- :checked="hasOutline"
- @change="checked => toggleOutline(checked)"
- />
- </div>
- </div>
- <template v-if="hasOutline">
- <div class="row">
- <div style="flex: 2;">边框样式:</div>
- <Select
- style="flex: 3;"
- :value="outline.style"
- @change="value => updateOutline({ style: value })"
- >
- <SelectOption value="solid">实线边框</SelectOption>
- <SelectOption value="dashed">虚线边框</SelectOption>
- </Select>
- </div>
- <div class="row">
- <div style="flex: 2;">边框颜色:</div>
- <Popover trigger="click">
- <template #content>
- <ColorPicker
- :modelValue="outline.color"
- @update:modelValue="value => updateOutline({ color: value })"
- />
- </template>
- <ColorButton :color="outline.color" style="flex: 3;" />
- </Popover>
- </div>
- <div class="row">
- <div style="flex: 2;">边框粗细:</div>
- <InputNumber
- :value="outline.width"
- @change="value => updateOutline({ width: value })"
- style="flex: 3;"
- />
- </div>
- </template>
- </div>
- </template>
- <script lang="ts">
- import { computed, defineComponent, ref, watch } from 'vue'
- import { MutationTypes, useStore } from '@/store'
- import { PPTElement, PPTElementOutline } from '@/types/slides'
- import useHistorySnapshot from '@/hooks/useHistorySnapshot'
- import ColorButton from './ColorButton.vue'
- export default defineComponent({
- name: 'element-outline',
- components: {
- ColorButton,
- },
- props: {
- fixed: {
- type: Boolean,
- default: false,
- },
- },
- setup() {
- const store = useStore()
- const handleElement = computed<PPTElement>(() => store.getters.handleElement)
- const outline = ref<PPTElementOutline>()
- const hasOutline = ref(false)
- watch(handleElement, () => {
- if (!handleElement.value) return
- outline.value = 'outline' in handleElement.value ? handleElement.value.outline : undefined
- hasOutline.value = !!outline.value
- }, { deep: true, immediate: true })
- const { addHistorySnapshot } = useHistorySnapshot()
- const updateOutline = (outlineProps: Partial<PPTElementOutline>) => {
- const props = { outline: { ...outline.value, ...outlineProps } }
- store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })
- addHistorySnapshot()
- }
- const toggleOutline = (checked: boolean) => {
- if (checked) {
- const props = { outline: { width: 2, color: '#000', style: 'solid' } }
- store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })
- }
- else {
- store.commit(MutationTypes.REMOVE_ELEMENT_PROPS, { id: handleElement.value.id, propName: 'outline' })
- }
- addHistorySnapshot()
- }
- return {
- outline,
- hasOutline,
- toggleOutline,
- updateOutline,
- }
- },
- })
- </script>
- <style lang="scss" scoped>
- .row {
- width: 100%;
- display: flex;
- align-items: center;
- margin-bottom: 10px;
- }
- .switch-wrapper {
- text-align: right;
- }
- </style>
|