diff --git a/README.md b/README.md index fb458f9..e46d872 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ | VirtualDirectory更新时更新文件信息 | ❌ | | 创建音乐播放器组件(仿QQ音乐移动端吧) | ❌ | | miaoDirectory的复制文件/文件夹功能 | ❌ | +| 重构miaoDropHandler的实现 | ❌ | +| 重构主界面,拆分主界面组件的实现 | ❌ | | 长期计划 | @@ -23,5 +25,4 @@ ## 碎碎念: -为什么不直接做成类似于windows的风格呢?其实技术实现上问题应该不大,重构也不用重构太多东西(APP.vue改改,插件部分改改这样),但是开学了事情一大堆,实习又没法比较美好地推掉。平时每天到宿舍都精疲力竭还要准备秋招和学校的破事。更何况搞不好还会被两个学分卡得没法毕业,好烦好烦。 -不过可能我对插件的价值也是有所高估吧。 \ No newline at end of file +为什么不直接做成类似于windows的风格呢?其实技术实现上问题应该不大,重构也不用重构太多东西(APP.vue改改,插件部分改改这样),但是开学了事情一大堆,实习又没法比较美好地推掉。平时每天到宿舍都精疲力竭还要准备秋招和学校的破事。更何况搞不好还会被两个学分卡得没法毕业,好烦好烦。md想这么多干嘛,反正都快岩壁了,mdmdmdmd \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 3edd788..bce09de 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,7 +9,6 @@ import { EllipsisVertical, QrCodeOutline } from '@vicons/ionicons5' -// import miaoDirectory from '@/plugins/miaoDirectory/miaoDirectory.vue' import VirtualDirectory, { VirtualFile } from './class/VirtualDirectory' import MiaoMask from './components/miaoMask.vue' import config from './config' @@ -48,7 +47,7 @@ const createView = ( currentFiles?: VirtualFile[], index?: number ) => { - views.push(component, currentDirectories, currentFiles, index) + views.push(component, currentDirectories, currentFiles, { index }) } const deleteView = (index: number) => { diff --git a/src/class/PluginCenter.ts b/src/class/PluginCenter.ts index ee3813c..04145ee 100644 --- a/src/class/PluginCenter.ts +++ b/src/class/PluginCenter.ts @@ -14,6 +14,8 @@ export interface registerComponentOption { getComponent: () => Promise group?: PluginGroup[] filter: (VDirectories: VirtualDirectory[], VFiles: VirtualFile[]) => boolean + disable?: boolean + exitConfirm?: boolean } type Plugin = { @@ -57,7 +59,9 @@ export default class PluginCenter { getComponent, icon, filter, - group = [PluginGroup.default] + group = [PluginGroup.default], + disable = false, + exitConfirm = false } = option let _component: any const views = useVirtualPages() @@ -66,7 +70,7 @@ export default class PluginCenter { filter, icon: shallowRef(icon), group, - disable: false, + disable, func: async ( VDirectories: VirtualDirectory[], VFiles: VirtualFile[] @@ -75,7 +79,11 @@ export default class PluginCenter { return } if (_component === undefined) _component = await getComponent() - views.push(_component, VDirectories, VFiles) + views.push(_component, VDirectories, VFiles, { + VirtualPageOption: { + exitConfirm + } + }) } }) } diff --git a/src/class/VirtualPage.ts b/src/class/VirtualPage.ts index 9175d87..91bebd7 100644 --- a/src/class/VirtualPage.ts +++ b/src/class/VirtualPage.ts @@ -1,123 +1,158 @@ -import { reactive, shallowRef } from "vue"; -import VirtualDirectory, { VirtualFile } from "./VirtualDirectory"; -import generateId from "@/hooks/generateId"; +import { reactive, shallowRef } from 'vue' +import VirtualDirectory, { VirtualFile } from './VirtualDirectory' +import generateId from '@/hooks/generateId' + +export interface VirtualPageOption { + exitConfirm?: boolean +} + +export interface ViewsPushOption { + index?: number + VirtualPageOption?: VirtualPageOption +} const getRandomWebSafeColor = (() => { - const webSafeColors = ["#009900", "#999900", "#009999", "#990099", "#0000ee"]; - let counter = 0; - return () => { - const color = webSafeColors[counter % webSafeColors.length]; - counter += 1; - return color; - }; -})(); + const webSafeColors = [ + '#009900', + '#999900', + '#009999', + '#990099', + '#0000ee' + ] + let counter = 0 + return () => { + const color = webSafeColors[counter % webSafeColors.length] + counter += 1 + return color + } +})() export default class VirtualPage { - constructor(component: any, initObjects?: { directories?: VirtualDirectory[]; files?: VirtualFile[] }) { - this.component = shallowRef(component); - this.currentDirectories = initObjects?.directories ?? []; - this.currentFiles = initObjects?.files ?? []; - this.visible = true; - this.id = generateId(); - this.refreshKey = Math.random(); - this.color = getRandomWebSafeColor(); - } - // 页面使用的组件 - component: any; - // 是否可见 - visible: boolean; - // 当前正在使用的文件夹 - currentDirectories: VirtualDirectory[]; - // 当前正在使用的文件 - currentFiles: VirtualFile[]; - // 区分每一个页面的唯一id - id: number; - // 当refreshKey改变时需要刷新页面,目前还没接入刷新 - refreshKey: number; - // 为了区分,每个虚拟页面都会分配一个color,这个color会体现在tab上 - color: string; - // 用于展示的title - _title?: string; + constructor( + component: any, + initObjects?: { + directories?: VirtualDirectory[] + files?: VirtualFile[] + option?: VirtualPageOption + } + ) { + this.component = shallowRef(component) + this.currentDirectories = initObjects?.directories ?? [] + this.currentFiles = initObjects?.files ?? [] + this.visible = true + this.id = generateId() + this.refreshKey = Math.random() + this.color = getRandomWebSafeColor() + this.exitConfirm = initObjects?.option?.exitConfirm ?? false + } + // 页面使用的组件 + component: any + // 是否可见 + visible: boolean + // 当前正在使用的文件夹 + currentDirectories: VirtualDirectory[] + // 当前正在使用的文件 + currentFiles: VirtualFile[] + // 区分每一个页面的唯一id + id: number + // 当refreshKey改变时需要刷新页面,目前还没接入刷新 + refreshKey: number + // 为了区分,每个虚拟页面都会分配一个color,这个color会体现在tab上 + color: string + // 用于展示的title + _title?: string + // 关闭时是否需要确认 + exitConfirm: boolean - get title() { - if (this._title) { - return this._title; - } - return this?.currentDirectories[0]?.name ?? this?.currentFiles[0]?.name ?? "未命名标签"; - } + get title() { + if (this._title) { + return this._title + } + return ( + this?.currentDirectories[0]?.name ?? + this?.currentFiles[0]?.name ?? + '未命名标签' + ) + } - setTitle(title: string) { - this._title = title; - } + setTitle(title: string) { + this._title = title + } - // 切换显示状态 - switchShow() { - this.visible = !this.visible; - } + // 切换显示状态 + switchShow() { + this.visible = !this.visible + } - // 刷新,不过好像没有用得到的时候吧 - // 事实上也不应该用得到,因为更新应该是响应式的 - refresh() { - this.refreshKey = Math.random(); - } + // 刷新,不过好像没有用得到的时候吧 + // 事实上也不应该用得到,因为更新应该是响应式的 + refresh() { + this.refreshKey = Math.random() + } } export class VirtualPages { - constructor() { - this._views = reactive([]); - } - _views: VirtualPage[]; + constructor() { + this._views = reactive([]) + } + _views: VirtualPage[] - get length() { - return this._views.length; - } + get length() { + return this._views.length + } - /** - * 查询一个页面位于_views中的次序 - * @param {any} id 要查询的页面的id - * @returns {any} - */ - getIndex(id: number) { - for (let i in this._views) { - if (this._views[i].id === id) { - return parseInt(i); - } - } - return -1; - } - /** - * 根据id得到view - * @param {any} id 要查询的页面的id - */ - getView(id: number) { - for (let v of this._views) { - if (v.id === id) { - return v; - } - } - return undefined; - } + /** + * 查询一个页面位于_views中的次序 + * @param {any} id 要查询的页面的id + * @returns {any} + */ + getIndex(id: number) { + for (let i in this._views) { + if (this._views[i].id === id) { + return parseInt(i) + } + } + return -1 + } + /** + * 根据id得到view + * @param {any} id 要查询的页面的id + */ + getView(id: number) { + for (let v of this._views) { + if (v.id === id) { + return v + } + } + return undefined + } - /** - * 推入一个新的页面 - */ - push(component: any, currentDirectories?: VirtualDirectory[], currentFiles?: VirtualFile[], index?: number) { - index ?? (index = this.length); - this._views.splice( - index, - 0, - reactive( - new VirtualPage(component, { - directories: [...(currentDirectories ?? [])], - files: [...(currentFiles ?? [])] - }) - ) - ); - } - /** - * 根据次序删除一个页面 - */ - deleteView(index: number) { - this._views.splice(index, 1); - } + /** + * 推入一个新的页面 + */ + push( + component: any, + currentDirectories?: VirtualDirectory[], + currentFiles?: VirtualFile[], + option?: ViewsPushOption + ) { + const { index = this.length, VirtualPageOption } = option ?? {} + this._views.splice( + index, + 0, + reactive( + new VirtualPage(component, { + directories: [...(currentDirectories ?? [])], + files: [...(currentFiles ?? [])], + option: VirtualPageOption + }) + ) + ) + } + /** + * 根据次序删除一个页面 + */ + deleteView(index: number) { + this._views.splice(index, 1) + } } diff --git a/src/plugins/miaoImages/miaoImages.vue b/src/plugins/miaoImages/miaoImages.vue index 687722c..35118bf 100644 --- a/src/plugins/miaoImages/miaoImages.vue +++ b/src/plugins/miaoImages/miaoImages.vue @@ -1,9 +1,13 @@