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, "css.validate": false,
"less.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 * left 12.6262638 input 12.63
* @LastEditors: ShawnPhang <https://m.palxp.cn> * @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 { onMounted } from 'vue'
// import WebWorker from '@/utils/plugins/webWorker' // import WebWorker from '@/utils/plugins/webWorker'
@ -14,7 +14,7 @@ import historyFactory from '@/utils/widgets/diffLayouts'
import { useHistoryStore, useWidgetStore } from '@/store' import { useHistoryStore, useWidgetStore } from '@/store'
const blackClass: string[] = ['operation-item', 'icon-undo', 'icon-redo'] 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 historyStore = useHistoryStore()
const widgetStore = useWidgetStore() const widgetStore = useWidgetStore()

View File

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

View File

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