mirror of
https://github.com/palxiao/poster-design.git
synced 2025-07-15 16:02:19 +08:00
feat: convert create-cover component to vue3
This commit is contained in:
parent
12d27d7f41
commit
a9f594fb1c
@ -15,7 +15,7 @@ interface Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
upload: async (file: File, options: Options, cb?: IQiniuSubscribeCb) => {
|
upload: async (file: File | Blob, options: Options, cb?: IQiniuSubscribeCb) => {
|
||||||
const win = window
|
const win = window
|
||||||
let name = ''
|
let name = ''
|
||||||
const suffix = file.type.split('/')[1] || 'png' // 文件后缀
|
const suffix = file.type.split('/')[1] || 'png' // 文件后缀
|
||||||
|
@ -2,66 +2,63 @@
|
|||||||
* @Author: ShawnPhang
|
* @Author: ShawnPhang
|
||||||
* @Date: 2021-08-01 11:12:17
|
* @Date: 2021-08-01 11:12:17
|
||||||
* @Description: 前端出图 - 用于封面
|
* @Description: 前端出图 - 用于封面
|
||||||
* @LastEditors: ShawnPhang <https://m.palxp.cn>
|
* @LastEditors: ShawnPhang <https://m.palxp.cn>, Jeremy Yu <https://github.com/JeremyYu-cn>
|
||||||
* @LastEditTime: 2023-09-13 17:36:36
|
* @Date: 2024-03-04 18:50:00
|
||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
<div id="cover-wrap"></div>
|
<div id="cover-wrap"></div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent, reactive, toRefs, watch, getCurrentInstance, ComponentInternalInstance } from 'vue'
|
import { useStore } from 'vuex'
|
||||||
import { mapGetters, mapActions } from 'vuex'
|
|
||||||
import html2canvas from 'html2canvas'
|
import html2canvas from 'html2canvas'
|
||||||
import api from '@/api'
|
|
||||||
import Qiniu from '@/common/methods/QiNiu'
|
import Qiniu from '@/common/methods/QiNiu'
|
||||||
|
import { useSetupMapGetters } from '@/common/hooks/mapGetters'
|
||||||
|
|
||||||
export default defineComponent({
|
const store = useStore();
|
||||||
props: ['modelValue'],
|
|
||||||
emits: ['update:modelValue'],
|
|
||||||
setup(props, context) {
|
|
||||||
const { proxy }: any = getCurrentInstance() as ComponentInternalInstance
|
|
||||||
|
|
||||||
async function createCover(cb: any) {
|
const { dZoom } = useSetupMapGetters(['dZoom'])
|
||||||
const nowZoom = proxy?.dZoom
|
|
||||||
// 取消选中元素
|
|
||||||
proxy?.selectWidget({
|
|
||||||
uuid: '-1',
|
|
||||||
})
|
|
||||||
proxy?.updateZoom(100)
|
|
||||||
const opts = {
|
|
||||||
useCORS: true, // 跨域图片
|
|
||||||
scale: 0.2,
|
|
||||||
}
|
|
||||||
setTimeout(async () => {
|
|
||||||
const clonePage: HTMLElement = document.getElementById('page-design-canvas').cloneNode(true)
|
|
||||||
clonePage.setAttribute('id', 'clone-page')
|
|
||||||
document.body.appendChild(clonePage)
|
|
||||||
html2canvas(document.getElementById('clone-page'), opts).then((canvas: any) => {
|
|
||||||
canvas.toBlob(
|
|
||||||
async (blobObj: Blob) => {
|
|
||||||
const result: any = await Qiniu.upload(blobObj, { bucket: 'xp-design', prePath: 'cover/user' })
|
|
||||||
cb(result)
|
|
||||||
},
|
|
||||||
'image/jpeg',
|
|
||||||
0.15,
|
|
||||||
)
|
|
||||||
proxy?.updateZoom(nowZoom)
|
|
||||||
clonePage.remove()
|
|
||||||
})
|
|
||||||
}, 10)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
createCover,
|
// props: ['modelValue'],
|
||||||
}
|
// emits: ['update:modelValue'],
|
||||||
},
|
|
||||||
computed: {
|
async function createCover(cb: any) {
|
||||||
...mapGetters(['dZoom']),
|
const nowZoom = dZoom.value
|
||||||
},
|
// 取消选中元素
|
||||||
methods: {
|
store.dispatch('selectWidget', {
|
||||||
...mapActions(['selectWidget', 'updateZoom']),
|
uuid: '-1',
|
||||||
},
|
})
|
||||||
|
store.dispatch('updateZoom', 100)
|
||||||
|
|
||||||
|
const opts = {
|
||||||
|
useCORS: true, // 跨域图片
|
||||||
|
scale: 0.2,
|
||||||
|
}
|
||||||
|
setTimeout(async () => {
|
||||||
|
const clonePage = document.getElementById('page-design-canvas')?.cloneNode(true) as HTMLElement
|
||||||
|
if (!clonePage) return
|
||||||
|
clonePage.setAttribute('id', 'clone-page')
|
||||||
|
document.body.appendChild(clonePage)
|
||||||
|
html2canvas(clonePage, opts).then((canvas) => {
|
||||||
|
canvas.toBlob(
|
||||||
|
async (blobObj) => {
|
||||||
|
if (blobObj) {
|
||||||
|
const result = await Qiniu.upload(blobObj, { bucket: 'xp-design', prePath: 'cover/user' })
|
||||||
|
cb(result)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'image/jpeg',
|
||||||
|
0.15,
|
||||||
|
)
|
||||||
|
store.dispatch('updateZoom', nowZoom)
|
||||||
|
clonePage.remove()
|
||||||
|
})
|
||||||
|
}, 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
createCover
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
2
src/types/global.d.ts
vendored
2
src/types/global.d.ts
vendored
@ -40,7 +40,7 @@ interface IQiniuSubscribeCb {
|
|||||||
interface Window {
|
interface Window {
|
||||||
qiniu: {
|
qiniu: {
|
||||||
upload: (
|
upload: (
|
||||||
file: File,
|
file: File | Blob,
|
||||||
name: string,
|
name: string,
|
||||||
token: string,
|
token: string,
|
||||||
exObj: Record<string, any>,
|
exObj: Record<string, any>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user