Merge pull request #118 from palxiao/feature-vue3

Feature vue3
This commit is contained in:
ShawnPhang 2024-03-30 20:45:43 +08:00 committed by GitHub
commit a3d82de967
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 27 additions and 26 deletions

View File

@ -6,12 +6,13 @@
* @LastEditTime: 2024-03-27 21:00:00 * @LastEditTime: 2024-03-27 21:00:00
*/ */
import { useControlStore, usePageStore } from "@/store" import { useControlStore, usePageStore, useWidgetStore } from "@/store"
import { THistoryStore } from ".." import { THistoryStore } from ".."
export default function handleHistory(store: THistoryStore, action: "undo" | "redo") { export default function handleHistory(store: THistoryStore, action: "undo" | "redo") {
const pageStore = usePageStore() const pageStore = usePageStore()
const controlStore = useControlStore() const controlStore = useControlStore()
const widgetStore = useWidgetStore()
controlStore.setShowMoveable(false) // 清理掉上一次的选择框 controlStore.setShowMoveable(false) // 清理掉上一次的选择框
// store.commit('setShowMoveable', false) // 清理掉上一次的选择框 // store.commit('setShowMoveable', false) // 清理掉上一次的选择框
const history = store.dHistory const history = store.dHistory
@ -21,14 +22,14 @@ export default function handleHistory(store: THistoryStore, action: "undo" | "re
historyParams.index -= 1 // 下标向前移1 撤销 historyParams.index -= 1 // 下标向前移1 撤销
console.log(historyParams.index) console.log(historyParams.index)
if (historyParams.index > -1) { if (historyParams.index > -1) {
store.state.dWidgets = JSON.parse(history[historyParams.index]) widgetStore.setDWidgets(JSON.parse(history[historyParams.index]))
pageStore.setDPage(JSON.parse(pageHistory[historyParams.index])) pageStore.setDPage(JSON.parse(pageHistory[historyParams.index]))
} }
} else if (action === 'redo') { } else if (action === 'redo') {
historyParams.index += 1 // 下标向后移1 重做 historyParams.index += 1 // 下标向后移1 重做
// 如果下标小于历史记录列表长度,直接取出历史记录 // 如果下标小于历史记录列表长度,直接取出历史记录
// if (historyParams.index < historyParams.length) { // if (historyParams.index < historyParams.length) {
store.state.dWidgets = JSON.parse(history[historyParams.index]) widgetStore.setDWidgets(JSON.parse(history[historyParams.index]))
pageStore.setDPage(JSON.parse(pageHistory[historyParams.index])) pageStore.setDPage(JSON.parse(pageHistory[historyParams.index]))
// } else { // } else {
// // 否则设置下标为列表最后一项 // // 否则设置下标为列表最后一项

View File

@ -13,10 +13,10 @@ import { proxyToObject } from "@/utils/utils"
/** push操作历史记录 */ /** push操作历史记录 */
export function pushHistory(store: THistoryStore, msg: string = "") { export function pushHistory(store: THistoryStore, msg: string = "") {
const pageStore = usePageStore() const pageStore = usePageStore()
const selectStore = useWidgetStore() const widgetStore = useWidgetStore()
console.log('history压栈', '来源: ' + msg) console.log('history压栈', '来源: ' + msg)
// 如果有上一次记录,并且与新纪录相同,那么不继续操作 // 如果有上一次记录,并且与新纪录相同,那么不继续操作
if (store.dHistory[history.length - 1] && store.dHistory[history.length - 1] === JSON.stringify(selectStore.dWidgets)) { if (store.dHistory[store.dHistory.length - 1] && store.dHistory[store.dHistory.length - 1] === JSON.stringify(widgetStore.dWidgets)) {
return return
} }
if (store.dHistoryParams.index < history.length - 1) { if (store.dHistoryParams.index < history.length - 1) {
@ -24,13 +24,13 @@ export function pushHistory(store: THistoryStore, msg: string = "") {
const len = history.length - index const len = history.length - index
store.dHistory.splice(index, len) store.dHistory.splice(index, len)
store.dPageHistory.splice(index, len) store.dPageHistory.splice(index, len)
store.dHistoryParams.length = history.length store.dHistoryParams.length = store.dHistory.length
store.dHistoryParams.index = history.length - 1 store.dHistoryParams.index = store.dHistory.length - 1
} }
store.dHistory.push(JSON.stringify(selectStore.dWidgets)) store.dHistory.push(JSON.stringify(widgetStore.dWidgets))
store.dPageHistory.push(JSON.stringify(proxyToObject(pageStore.dPage))) store.dPageHistory.push(JSON.stringify(proxyToObject(pageStore.dPage)))
store.dHistoryParams.index = history.length - 1 store.dHistoryParams.index = store.dHistory.length - 1
store.dHistoryParams.length = history.length store.dHistoryParams.length = store.dHistory.length
} }
/** 添加颜色选择历史记录 */ /** 添加颜色选择历史记录 */

View File

@ -64,11 +64,11 @@ const HistoryStore = defineStore<"historyStore", THistoryState, {}, THistoryActi
pushHistory(this, msg) pushHistory(this, msg)
}, },
handleHistory(action) { handleHistory(action) {
const selectStore = useWidgetStore() const widgetStore = useWidgetStore()
const pageStore = usePageStore() const pageStore = usePageStore()
handleHistory(this, action) handleHistory(this, action)
// 激活组件默认为page // 激活组件默认为page
selectStore.dActiveElement = pageStore.dPage widgetStore.setdActiveElement(pageStore.dPage)
}, },
pushColorToHistory(color) { pushColorToHistory(color) {
pushColorToHistory(this, color) pushColorToHistory(this, color)

View File

@ -12,15 +12,16 @@ import { customAlphabet } from 'nanoid/non-secure'
const nanoid = customAlphabet('1234567890abcdef', 12) const nanoid = customAlphabet('1234567890abcdef', 12)
export function addGroup(store: TWidgetStore, group: TdWidgetData[]) { export function addGroup(store: TWidgetStore, group: TdWidgetData[] | TdWidgetData) {
const historyStore = useHistoryStore() const historyStore = useHistoryStore()
const canvasStore = useCanvasStore() const canvasStore = useCanvasStore()
let parent: TdWidgetData | null = null let parent: TdWidgetData | null = null
group.forEach((item) => { const tmpGroup: TdWidgetData[] = !Array.isArray(group) ? [group] : group
tmpGroup.forEach((item) => {
item.uuid = nanoid() // 重设id item.uuid = nanoid() // 重设id
item.type === 'w-group' && (parent = item) // 找出父组件 item.type === 'w-group' && (parent = item) // 找出父组件
}) })
group.forEach((item) => { tmpGroup.forEach((item) => {
!item.isContainer && parent && (item.parent = parent.uuid) // 重设父id !item.isContainer && parent && (item.parent = parent.uuid) // 重设父id
item.text && (item.text = decodeURIComponent(item.text)) item.text && (item.text = decodeURIComponent(item.text))
store.dWidgets.push(item) store.dWidgets.push(item)

View File

@ -7,7 +7,7 @@
*/ */
import { useCanvasStore, useControlStore, usePageStore } from "@/store" import { useCanvasStore, useControlStore, usePageStore } from "@/store"
import { TWidgetStore } from ".." import { TWidgetStore, TdWidgetData } from ".."
export type TInidDMovePayload = { export type TInidDMovePayload = {
startX: number startX: number
@ -123,3 +123,7 @@ export function setDropOver(store: TWidgetStore, uuid: string) {
export function setMouseEvent(state: TWidgetStore, e: MouseEvent | null) { export function setMouseEvent(state: TWidgetStore, e: MouseEvent | null) {
state.activeMouseEvent = e state.activeMouseEvent = e
} }
export function setdActiveElement(state: TWidgetStore, data: TdWidgetData) {
state.dActiveElement = data
}

View File

@ -7,7 +7,7 @@
*/ */
import { Store, defineStore } from "pinia"; import { Store, defineStore } from "pinia";
import { TInidDMovePayload, TMovePayload, dMove, initDMove, setDropOver, setMouseEvent, updateGroupSize, updateHoverUuid } from "./actions"; import { TInidDMovePayload, TMovePayload, dMove, initDMove, setDropOver, setMouseEvent, setdActiveElement, updateGroupSize, updateHoverUuid } from "./actions";
import { TPageState } from "../page"; import { TPageState } from "../page";
import { TInitResize, TResize, TdResizePayload, dResize, initDResize, resize } from "./actions/resize"; import { TInitResize, TResize, TdResizePayload, dResize, initDResize, resize } from "./actions/resize";
import { TUpdateWidgetMultiplePayload, TUpdateWidgetPayload, TsetWidgetStyleData, addWidget, deleteWidget, setDWidgets, setWidgetStyle, updateWidgetData, updateWidgetMultiple } from "./actions/widget"; import { TUpdateWidgetMultiplePayload, TUpdateWidgetPayload, TsetWidgetStyleData, addWidget, deleteWidget, setDWidgets, setWidgetStyle, updateWidgetData, updateWidgetMultiple } from "./actions/widget";
@ -117,6 +117,7 @@ type TAction = {
setWidgetStyle: (data: TsetWidgetStyleData) => void setWidgetStyle: (data: TsetWidgetStyleData) => void
setDWidgets: (data: TdWidgetData[]) => void setDWidgets: (data: TdWidgetData[]) => void
setMouseEvent: (e: MouseEvent | null) => void setMouseEvent: (e: MouseEvent | null) => void
setdActiveElement: (data: TdWidgetData) => void
} }
const WidgetStore = defineStore<"widgetStore", TWidgetState, TGetter, TAction>("widgetStore", { const WidgetStore = defineStore<"widgetStore", TWidgetState, TGetter, TAction>("widgetStore", {
@ -175,7 +176,8 @@ const WidgetStore = defineStore<"widgetStore", TWidgetState, TGetter, TAction>("
resize(data) { resize(this, data) }, resize(data) { resize(this, data) },
setWidgetStyle(data) { setWidgetStyle(this, data) }, setWidgetStyle(data) { setWidgetStyle(this, data) },
setDWidgets(data) { setDWidgets(this, data) }, setDWidgets(data) { setDWidgets(this, data) },
setMouseEvent(event) { setMouseEvent(this, event) } setMouseEvent(event) { setMouseEvent(this, event) },
setdActiveElement(data) { setdActiveElement(this, data) },
} }
}) })

View File

@ -203,8 +203,7 @@ async function load(id: number, tempId: number, type: number, cb: () => void) {
const data = JSON.parse(content) const data = JSON.parse(content)
state.stateBollean = !!_state state.stateBollean = !!_state
state.title = title state.title = title
// store.commit('setShowMoveable', false) // controlStore.setShowMoveable(false) //
controlStore.setShowMoveable(false)
// this.$store.commit('setDWidgets', []) // this.$store.commit('setDWidgets', [])
if (type == 1) { if (type == 1) {
@ -212,18 +211,12 @@ async function load(id: number, tempId: number, type: number, cb: () => void) {
dPage.value.width = width dPage.value.width = width
dPage.value.height = height dPage.value.height = height
widgetStore.addGroup(data) widgetStore.addGroup(data)
// store.dispatch('addGroup', data)
// addGroup(data)
} else { } else {
pageStore.setDPage(data.page) pageStore.setDPage(data.page)
// store.commit('setDPage', data.page)
id ? widgetStore.setDWidgets(data.widgets) : widgetStore.setTemplate(data.widgets) id ? widgetStore.setDWidgets(data.widgets) : widgetStore.setTemplate(data.widgets)
// id ? store.commit('setDWidgets', data.widgets) : store.dispatch('setTemplate', data.widgets)
} }
cb() cb()
historyStore.pushHistory('请求加载load') historyStore.pushHistory('请求加载load')
// store.dispatch('pushHistory', 'load')
// pushHistory('load')
} }
} }