From 125d52f863133b2b9dd8a25c6ebd8c50b6370431 Mon Sep 17 00:00:00 2001 From: ShawnPhang Date: Sun, 17 Mar 2024 20:56:04 +0800 Subject: [PATCH] fix: copy&paste --- package-lock.json | 6 ++++++ package.json | 1 + src/common/methods/DesignFeatures/setWidgetData.ts | 5 +++-- src/components/modules/panel/wrap/UserWrap.vue | 6 ++++++ src/mixins/methods/handlePaste.ts | 11 +++++++++-- src/store/modules/base/index.ts | 3 +++ src/store/modules/base/mutations.ts | 2 +- src/store/modules/design/actions.ts | 1 + src/utils/plugins/eventBus.ts | 9 +++++++++ src/views/Draw.vue | 2 +- src/views/Index.vue | 2 +- src/views/components/HeaderOptions.vue | 2 +- 12 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 src/utils/plugins/eventBus.ts diff --git a/package-lock.json b/package-lock.json index 9ff4481..2bc5483 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "element-plus": "^2.3.7", "fontfaceobserver": "^2.1.0", "html2canvas": "^1.4.1", + "mitt": "^3.0.1", "moveable": "^0.26.0", "moveable-helper": "^0.4.0", "nanoid": "^3.1.23", @@ -3013,6 +3014,11 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/mitt": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz", + "integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==" + }, "node_modules/moveable": { "version": "0.26.0", "resolved": "https://registry.npmjs.org/moveable/-/moveable-0.26.0.tgz", diff --git a/package.json b/package.json index 6d7970f..84195af 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "element-plus": "^2.3.7", "fontfaceobserver": "^2.1.0", "html2canvas": "^1.4.1", + "mitt": "^3.0.1", "moveable": "^0.26.0", "moveable-helper": "^0.4.0", "nanoid": "^3.1.23", diff --git a/src/common/methods/DesignFeatures/setWidgetData.ts b/src/common/methods/DesignFeatures/setWidgetData.ts index c3fc7a9..49182fa 100644 --- a/src/common/methods/DesignFeatures/setWidgetData.ts +++ b/src/common/methods/DesignFeatures/setWidgetData.ts @@ -8,14 +8,15 @@ // import store from '@/store' // import { getImage } from '../getImgDetail' import setImageData from '@/common/methods/DesignFeatures/setImage' -import wText from '@/components/modules/widgets/wText/wText.vue' +// import wText from '@/components/modules/widgets/wText/wText.vue' +import { wTextSetting } from '@/components/modules/widgets/wText/wTextSetting' import wImage from '@/components/modules/widgets/wImage/wImage.vue' import wSvg from '@/components/modules/widgets/wSvg/wSvg.vue' export default async function(type: string, item: TCommonItemData, data: Record) { let setting = data if (type === 'text') { - !item.fontFamily && !item.color ? (setting = JSON.parse(JSON.stringify(wText.setting))) : (setting = item) + !item.fontFamily && !item.color ? (setting = JSON.parse(JSON.stringify(wTextSetting))) : (setting = item) !setting.text ? (setting.text = '双击编辑文字') : (setting.text = decodeURIComponent(setting.text)) // item.text setting.fontSize = item.fontSize setting.width = item.width || item.fontSize * setting.text.length diff --git a/src/components/modules/panel/wrap/UserWrap.vue b/src/components/modules/panel/wrap/UserWrap.vue index 196d815..4a3c981 100644 --- a/src/components/modules/panel/wrap/UserWrap.vue +++ b/src/components/modules/panel/wrap/UserWrap.vue @@ -50,6 +50,7 @@ import photoList from './components/photoList.vue' import imgWaterFall from './components/imgWaterFall.vue' import { TUploadDoneData } from '@/components/common/Uploader/index.vue' import { IGetTempListData } from '@/api/home' +import eventBus from '@/utils/plugins/eventBus' type TProps = { active?: number @@ -238,6 +239,11 @@ const openPSD = () => { window.open(router.resolve('/psd').href, '_blank') } +eventBus.on('refreshUserImages', () => { + state.imgList = [] + load(true) +}) + defineExpose({ selectDesign, loadDesign, diff --git a/src/mixins/methods/handlePaste.ts b/src/mixins/methods/handlePaste.ts index a5821f5..6964524 100644 --- a/src/mixins/methods/handlePaste.ts +++ b/src/mixins/methods/handlePaste.ts @@ -17,7 +17,8 @@ import Qiniu from '@/common/methods/QiNiu' import _config from '@/config' import { getImage } from '@/common/methods/getImgDetail' import wImage from '@/components/modules/widgets/wImage/wImage.vue' -import wText from '@/components/modules/widgets/wText/wText.vue' +import { wTextSetting } from '@/components/modules/widgets/wText/wTextSetting' +import eventBus from '@/utils/plugins/eventBus' export default () => { return new Promise((resolve) => { @@ -38,6 +39,8 @@ export default () => { const { width, height }: any = await getImage(file) const url = _config.IMG_URL + result.key await api.material.addMyPhoto({ width, height, url }) + // 刷新用户列表 + eventBus.emit('refreshUserImages') // 添加图片到画布中 store.commit('setShowMoveable', false) // 清理掉上一次的选择 const setting = JSON.parse(JSON.stringify(wImage.setting)) @@ -54,10 +57,14 @@ export default () => { 'text/plain': new Blob([''], {type: 'text/plain'}) }) ]) + // 最后尝试复制,将图片替换为图片组件 + setTimeout(() => { + store.dispatch('copyWidget') + }, 100) break } else if (item.types.toString().indexOf('text') !== -1) { store.commit('setShowMoveable', false) // 清理掉上一次的选择 - const setting = JSON.parse(JSON.stringify(wText.setting)) + const setting = JSON.parse(JSON.stringify(wTextSetting)) setting.text = await navigator.clipboard.readText() store.dispatch('addWidget', setting) break diff --git a/src/store/modules/base/index.ts b/src/store/modules/base/index.ts index 4a1e8c7..1d7bd60 100644 --- a/src/store/modules/base/index.ts +++ b/src/store/modules/base/index.ts @@ -38,6 +38,9 @@ const all = { fonts: (state: Type.Object) => { return state.fonts }, + app: (state: Type.Object) => { + return state.app + } }, mutations: { ...mutations, diff --git a/src/store/modules/base/mutations.ts b/src/store/modules/base/mutations.ts index f506b49..88bd32a 100644 --- a/src/store/modules/base/mutations.ts +++ b/src/store/modules/base/mutations.ts @@ -38,5 +38,5 @@ export default { }, managerEdit(state: Type.Object, status: string) { state.tempEditing = status - }, + } } diff --git a/src/store/modules/design/actions.ts b/src/store/modules/design/actions.ts index 8c215a5..f267e7c 100644 --- a/src/store/modules/design/actions.ts +++ b/src/store/modules/design/actions.ts @@ -291,6 +291,7 @@ export default { } store.dispatch('pushHistory', 'pasteWidget') + store.dispatch('copyWidget') store.dispatch('reChangeCanvas') }, // TODO: 选中元件与取消选中 diff --git a/src/utils/plugins/eventBus.ts b/src/utils/plugins/eventBus.ts new file mode 100644 index 0000000..4368337 --- /dev/null +++ b/src/utils/plugins/eventBus.ts @@ -0,0 +1,9 @@ +import mitt from 'mitt'; + +type Events = { + refreshUserImages: any; +}; + +const emitter = mitt(); + +export default emitter; \ No newline at end of file diff --git a/src/views/Draw.vue b/src/views/Draw.vue index d5c95ee..7eec640 100644 --- a/src/views/Draw.vue +++ b/src/views/Draw.vue @@ -12,7 +12,7 @@ import { StyleValue, onMounted, reactive, nextTick } from 'vue' import { useStore } from 'vuex' import api from '@/api' -import wGroup from '@/components/modules/widgets/wGroup/wGroup.vue' +// import wGroup from '@/components/modules/widgets/wGroup/wGroup.vue' import Preload from '@/utils/plugins/preload' import FontFaceObserver from 'fontfaceobserver' import { fontWithDraw, font2style } from '@/utils/widgets/loadFontRule' diff --git a/src/views/Index.vue b/src/views/Index.vue index 0aa2576..64ee6e1 100644 --- a/src/views/Index.vue +++ b/src/views/Index.vue @@ -67,7 +67,7 @@ import zoomControl from '@/components/modules/layout/zoomControl/index.vue' import lineGuides from '@/components/modules/layout/lineGuides.vue' import shortcuts from '@/mixins/shortcuts' -import wGroup from '@/components/modules/widgets/wGroup/wGroup.vue' +// import wGroup from '@/components/modules/widgets/wGroup/wGroup.vue' import HeaderOptions from './components/HeaderOptions.vue' import ProgressLoading from '@/components/common/ProgressLoading/index.vue' import { useSetupMapGetters } from '@/common/hooks/mapGetters' diff --git a/src/views/components/HeaderOptions.vue b/src/views/components/HeaderOptions.vue index 7f7d5ea..3d276cc 100644 --- a/src/views/components/HeaderOptions.vue +++ b/src/views/components/HeaderOptions.vue @@ -37,7 +37,7 @@ import { useFontStore } from '@/common/methods/fonts' import copyRight from './CopyRight.vue' import _config from '@/config' import useConfirm from '@/common/methods/confirm' -import wGroup from '@/components/modules/widgets/wGroup/wGroup.vue' +// import wGroup from '@/components/modules/widgets/wGroup/wGroup.vue' import { useSetupMapGetters } from '@/common/hooks/mapGetters' type TProps = {