fix: paste history lost bug

This commit is contained in:
ShawnPhang 2024-05-22 20:22:18 +08:00
parent dcacc3e5e4
commit 3bf285085d
4 changed files with 14 additions and 18 deletions

View File

@ -9,5 +9,8 @@
},
"css.validate": false,
"less.validate": false,
"scss.validate": false
"scss.validate": false,
"i18n-ally.localesPaths": [
"src/languages"
]
}

View File

@ -6,7 +6,7 @@
*
* left 12.6262638 input 12.63
* @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2024-05-18 01:51:34
* @LastEditTime: 2024-05-22 19:33:04
*/
import { onMounted } from 'vue'
// import WebWorker from '@/utils/plugins/webWorker'
@ -14,7 +14,7 @@ import historyFactory from '@/utils/widgets/diffLayouts'
import { useHistoryStore, useWidgetStore } from '@/store'
const blackClass: string[] = ['operation-item', 'icon-undo', 'icon-redo']
const whiteKey: string[] = ['ArrowLeft', 'ArrowDown', 'ArrowRight', 'ArrowUp', 'Backspace', 'Delete']
const whiteKey: string[] = ['ArrowLeft', 'ArrowDown', 'ArrowRight', 'ArrowUp', 'Backspace', 'Delete', 'v']
const historyStore = useHistoryStore()
const widgetStore = useWidgetStore()

View File

@ -3,7 +3,7 @@
* @Date: 2024-04-10 23:02:46
* @Description: 主画布
* @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2024-04-16 11:34:08
* @LastEditTime: 2024-05-22 19:29:51
-->
<template>
<div id="main">
@ -273,8 +273,6 @@ async function drop(e: MouseEvent) {
const widget = dWidgets.value.find((item: { uuid: string }) => item.uuid == dropIn)
if (!widget) return
widget.imgUrl = item.value.url
console.log('加入+', widget)
// store.commit('setShowMoveable', true) //
controlStore.setShowMoveable(true) //
} else {
@ -285,7 +283,6 @@ async function drop(e: MouseEvent) {
} else if (type === 'bg') {
console.log('背景图片放置')
} else if (type !== 'group') {
console.log(setting)
widgetStore.addWidget(setting as Required<TPageState>)
// store.dispatch('addWidget', setting) //
}

View File

@ -2,12 +2,13 @@
* @Author: Jeremy Yu
* @Date: 2024-03-28 14:00:00
* @Description:
* @LastEditors: Jeremy Yu <https://github.com/JeremyYu-cn>
* @LastEditTime: 2024-03-28 14:00:00
* @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2024-05-22 19:32:24
*/
import { useCanvasStore, useHistoryStore } from "@/store"
import { TWidgetStore, TdWidgetData } from ".."
import { useWidgetStore } from "@/store"
import { customAlphabet } from 'nanoid/non-secure'
const nanoid = customAlphabet('1234567890abcdef', 12)
@ -50,8 +51,7 @@ export function copyWidget(store: TWidgetStore) {
/** 粘贴组件 */
export function pasteWidget(store: TWidgetStore) {
const historyStore = useHistoryStore()
const canvasStore = useCanvasStore()
const widgetStore = useWidgetStore()
const copyElement: TdWidgetData[] = JSON.parse(JSON.stringify(store.dCopyElement))
const container = copyElement.find((item) => item.isContainer)
for (let i = 0; i < copyElement.length; ++i) {
@ -63,19 +63,15 @@ export function pasteWidget(store: TWidgetStore) {
}
copyElement[i].top += 30
copyElement[i].left += 30
widgetStore.addWidget(copyElement[i])
}
store.dWidgets = store.dWidgets.concat(copyElement)
// store.dWidgets = store.dWidgets.concat(copyElement)
store.dActiveElement = copyElement[0]
store.dSelectWidgets = copyElement
if (container) {
store.dActiveElement = container
store.dSelectWidgets = []
}
historyStore.pushHistory("pasteWidget")
// store.dispatch('pushHistory', 'pasteWidget')
// 复制以调整下次粘贴的位置
store.copyWidget()
// store.dispatch('copyWidget')
canvasStore.reChangeCanvas()
// store.dispatch('reChangeCanvas')
}