修复长按dock栏图标,拖拽至新页面,不松手的情况下再拖拽回dock栏,此时会新建一个空白页

Signed-off-by: zhengyongjie <15531316327@163.com>
This commit is contained in:
zhengyongjie 2024-09-22 14:03:54 +08:00
parent 73fc1a163b
commit a5de0d9f93
3 changed files with 15 additions and 2 deletions

View File

@ -85,6 +85,7 @@ export default struct GridSwiper {
}
private buildLog(): boolean {
AppStorage.setOrCreate('dockAddedPage', this.pageList);
let isDesktopLoadFinished = AppStorage.get('isDesktopLoadFinished') as boolean;
Log.showDebug(TAG, `build start ${isDesktopLoadFinished} page ${this.pageIndex}`);
return isDesktopLoadFinished == true;

View File

@ -998,8 +998,8 @@ export class PageDesktopViewModel extends BaseViewModel {
/**
* Delete the chosen blank page.
*/
private deleteBlankPage(): void {
const curPageIndex = this.mPageDesktopModel.getPageIndex();
deleteBlankPage(pageIndex?:number): void {
const curPageIndex = pageIndex!== undefined? pageIndex : this.mPageDesktopModel.getPageIndex();
this.deleteGridPage(curPageIndex);
if (curPageIndex === 0) {
this.mPageDesktopModel.setPageIndex(curPageIndex);

View File

@ -29,6 +29,9 @@ import {
} from '@ohos/common';
import { SmartDockStyleConfig } from '../config/SmartDockStyleConfig';
import SmartDockDragHandler from '../common/SmartDockDragHandler';
import {
PageDesktopViewModel
} from '../../../../../../pagedesktop/src/main/ets/default/viewmodel/PageDesktopViewModel';
let mSmartDockStyleConfig: SmartDockStyleConfig | null = null;
const TAG = 'ResidentLayout';
@ -48,6 +51,7 @@ export default struct ResidentLayout {
onItemClick: (event: ClickEvent, item: DockItemInfo) => void = (event: ClickEvent, item: DockItemInfo) => {};
buildMenu: (item: DockItemInfo) => MenuInfo[] = (item: DockItemInfo): MenuInfo[] => [];
onDockListChangeFunc: () => void = () => {};
oldPageList:number[] | undefined = [0];
aboutToAppear(): void {
mSmartDockStyleConfig = this.mSmartDockStyleConfig;
@ -120,9 +124,17 @@ export default struct ResidentLayout {
})
.onDragLeave((event: DragEvent, extraParams: string) => {
Log.showDebug(TAG, `onDragLeave event: [${event.getWindowX()}, ${event.getWindowY()}]`);
let oldPageList: number[]| undefined = AppStorage.get('dockAddedPage');
if (oldPageList) {
this.oldPageList = [...oldPageList];
}
})
.onDrop((event: DragEvent, extraParams: string) => {
Log.showInfo(TAG, `onDrop event: [${event.getWindowX()}, ${event.getWindowY()}]`);
let newPageList: number[] | undefined = AppStorage.get('dockAddedPage');
if (newPageList && newPageList?.length !== this.oldPageList?.length) {
PageDesktopViewModel.getInstance().deleteBlankPage(newPageList[newPageList.length - 1]);
}
const dragResult = SmartDockDragHandler.getInstance().onDragDrop(event.getWindowX(), event.getWindowY());
AppStorage.setOrCreate('selectAppIndex', null);
const dragItemInfo: LauncherDragItemInfo = AppStorage.get('dragItemInfo') as LauncherDragItemInfo;