Skip to content

Commit

Permalink
更新上传pdf加载样式
Browse files Browse the repository at this point in the history
  • Loading branch information
more-strive committed Dec 6, 2023
1 parent 549f059 commit ef03001
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
9 changes: 4 additions & 5 deletions src/components/FileUpload/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import { computed, ref, watch } from 'vue'
import { UploadFilled } from '@element-plus/icons-vue'
import { ElMessage, genFileId, UploadInstance, UploadProps, UploadRawFile } from "element-plus"
import { storeToRefs } from 'pinia'
import { loadSVGFromString } from 'fabric'
import { uploadFile } from '@/api/file'
import { useTemplatesStore } from '@/store'
import useCanvas from '@/views/Canvas/useCanvas'
import useCanvasScale from '@/hooks/useCanvasScale'
const templatesStore = useTemplatesStore()
const { setCanvasTransform } = useCanvasScale()
const dialogVisible = ref(false)
const fileAccept = ref('.pdf,.psd,.cdr,.svg,.jpg,.jpeg,.png')
const uploadRef = ref<UploadInstance>()
Expand Down Expand Up @@ -58,7 +56,8 @@ const uploadHandle = async (option: any) => {
if (res && res.data.code === 200) {
const template = res.data.data
if (!template) return
templatesStore.addTemplate(template)
await templatesStore.addTemplate(template)
setCanvasTransform()
emit('close')
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ImageHit } from "@/api/image/types"
export const enum ElementNames {
TEXTBOX = 'textbox',
TEXT = 'text',
ITEXT = 'i-text',
IMAGE = 'image',
CROPIMAGE = 'cropimage',
MASK = 'mask',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import { ImageElement } from '@/types/canvas'
import { ratioClipOptions } from '@/configs/images'
import { getImageDataURL } from '@/utils/image'
import { propertiesToInclude } from '@/configs/canvas'
import { Image } from 'fabric'
import ElementPosition from '../Components/ElementPosition.vue'
import ElementOutline from '../Components/ElementOutline.vue'
import ElementShadow from '../Components/ElementShadow.vue'
Expand All @@ -91,7 +92,7 @@ const mainStore = useMainStore()
const templatesStore = useTemplatesStore()
const [ canvas ] = useCanvas()
const { canvasObject } = storeToRefs(mainStore)
const handleElement = computed(() => canvasObject.value as ImageElement)
const handleElement = computed(() => canvasObject.value as Image)
// 打开自由裁剪
Expand Down Expand Up @@ -147,7 +148,6 @@ const replaceImage = (files: FileList) => {
getImageDataURL(imageFile).then(dataURL => {
const props = { src: dataURL }
handleElement.value.setSrc(dataURL)
// @ts-ignore
templatesStore.updateElement({ id: handleElement.value.id, props })
})
Expand Down
2 changes: 2 additions & 0 deletions src/views/Editor/CanvasRight/ElementStylePanel/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import GroupStylePanel from './GroupStylePanel.vue'
const panelMap = {
[ElementNames.TEXTBOX]: TextboxStylePanel,
[ElementNames.TEXT]: TextboxStylePanel,
[ElementNames.ITEXT]: TextboxStylePanel,
[ElementNames.IMAGE]: ImageStylePanel,
[ElementNames.CROPIMAGE]: ImageStylePanel,
[ElementNames.PATH]: PathStylePanel,
Expand All @@ -39,6 +40,7 @@ const { canvasObject } = storeToRefs(useMainStore())
const currentPanelComponent = computed(() => {
if (!canvasObject.value) return null
console.log('canvasObject:', canvasObject.value.name)
const canvasType = canvasObject.value.name ? canvasObject.value.name : canvasObject.value.type
return panelMap[canvasType.toLowerCase() as ElementNames.TEXT]
})
Expand Down
18 changes: 14 additions & 4 deletions src/views/Editor/CanvasThumb/ThumbnailTemplate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

<script lang="ts" setup>
import { computed, onMounted, PropType, ref, watch } from 'vue'
import { StaticCanvas } from 'fabric'
import { StaticCanvas, Group } from 'fabric'
import { Template, CanvasElement } from '@/types/canvas'
import { WorkSpaceThumbType, WorkSpaceDrawType } from '@/configs/canvas'
import { el } from 'element-plus/es/locale';
const props = defineProps({
template: {
Expand Down Expand Up @@ -66,11 +67,20 @@ const setThumbnailElement = async () => {
})
thumbCanvas.value.setZoom(thumbZoom)
const thumbViewportTransform = thumbCanvas.value.viewportTransform
const objects = thumbCanvas.value.getObjects().filter(ele => !WorkSpaceThumbType.includes(ele.id))
const boundingBox = Group.prototype.getObjectsBoundingBox(objects)
let left = 0, top = 0
if (thumbWorkSpaceDraw) {
thumbViewportTransform[4] = -thumbWorkSpaceDraw.left * thumbZoom
thumbViewportTransform[5] = -thumbWorkSpaceDraw.top * thumbZoom
thumbCanvas.value.setViewportTransform(thumbViewportTransform)
left = thumbWorkSpaceDraw.left
top = thumbWorkSpaceDraw.top
}
else if (boundingBox) {
left = boundingBox.centerX - boundingBox.width / 2
top = boundingBox.centerY - boundingBox.height / 2
}
thumbViewportTransform[4] = -left * thumbZoom
thumbViewportTransform[5] = -top * thumbZoom
thumbCanvas.value.setViewportTransform(thumbViewportTransform)
thumbCanvas.value.renderAll()
}
</script>
Expand Down

0 comments on commit ef03001

Please sign in to comment.