Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
g122622 committed Aug 25, 2023
1 parent c365ebc commit 4cd448e
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 29 deletions.
4 changes: 3 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<!-- 动态对话框 -->
<DialogGenerator v-for="item in dialogStore.dialogs" :key="item.guid" v-bind="item"></DialogGenerator>
<!-- 内置文件选择器 -->
<BuiltinFilePicker></BuiltinFilePicker>
<Suspense>
<BuiltinFilePicker></BuiltinFilePicker>
</Suspense>

<div :style="{ opacity: backgroundOpacity }">
<v-app>
Expand Down
43 changes: 25 additions & 18 deletions src/api/core/adapters/localFiles/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import AdapterBase from "@/api/core/types/AdapterBase"
import fs from "fs-extra";
import path from 'path'

const forbiddenDirents = ["System Volume Information", "$RECYCLE.BIN", "desktop.ini"]
const forbiddenDirents = ["System Volume Information",
"$RECYCLE.BIN",
"desktop.ini",
"DumpStack.log.tmp",
"Config.Msi",
"DumpStack.log",
"WindowsApps",
"pagefile.sys"]

class LocalFileAdapter extends AdapterBase {
private currentDirectory: Addr
Expand Down Expand Up @@ -40,29 +47,29 @@ class LocalFileAdapter extends AdapterBase {
this.currentFileTable = await this._getFileTable(newDir)
}

/**
* 核心函数: 根据传入的dir递归遍历文件系统,将找到的filetable传回
*/
private async _getFileTable(dir: Addr): Promise<fileTable> {
const res: fileTable = { items: [] as dirSingleItem[], selfKey: '' }
const pathBase = dir.toPathStr()
try {
let dirs = await fs.readdir(pathBase);
for (const dirent of dirs) {
if (!forbiddenDirents.includes(dirent)) {
const stats = await fs.stat(path.join(pathBase, dirent))
res.items.push({
name: dirent,
type: stats.isDirectory() ? 'folder' : 'file',
key: dirent,
meta: {
accessedTime: stats.atime.getTime(),
createdTime: stats.ctime.getTime(),
modifiedTime: stats.mtime.getTime(),
size: stats.size
}
})
}
try {
if (!forbiddenDirents.includes(dirent)) {
// console.log(pathBase, dirent, path.join(pathBase, dirent))
const stats = await fs.stat(path.join(pathBase, dirent))
res.items.push({
name: dirent,
type: stats.isDirectory() ? 'folder' : 'file',
key: dirent,
meta: {
accessedTime: stats.atime.getTime(),
createdTime: stats.ctime.getTime(),
modifiedTime: stats.mtime.getTime(),
size: stats.size
}
})
}
} catch (e) { }
}
return res
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/registerBuiltinOpenMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default async function registerBulitinOpenMethods(mgr) {
icon: 'mdi-export-variant',
fileType: /./,
async onSelected(file: File) {
const directory = (await pickFile("G:/", true, false, true))[0]
const directory = (await pickFile(null, true, false, true))[0]
await file.exportToExt(directory)
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/assets/whatsNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export default {
"1.3.1": ['应用锁bug修复'],
"1.4.0": ['支持从外部拖入文件以导入', "完全重写加密引擎,支持异步加密,且显著优化输出文件大小", "改正一处错别字", "临时文件自动销毁"],
"1.5.0": ['若干bug和细节修复', '任务处理并行化,显著提高运行效率', '支持导出文件', '支持快捷打开store所在的目录'],
"2.0.0": ['若干bug和细节修复', '增加内置文件选择器', '内置浏览器可用', '内置代码编辑器可用'],
"2.0.0": ['若干bug和细节修复', '增加内置文件选择器', '内置浏览器可用', '内置代码编辑器可用', "列表性能优化"],
}
13 changes: 12 additions & 1 deletion src/components/BuiltinFilePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
:title="item.fileMgrOptions.onlyAllowFolderSelection ? '选择文件夹' : '选择文件'" :isPersistent="true"
useCompactContentOuterMargin v-for="item in filePickers" :key="item.taskId">
<template #title>
<div style="margin-left: 7px; width: 150px;">
<v-select density="compact" label="选择盘符" clearable :items="allDrive.map(i => i.drive).sort()"
v-model="currentDrive"></v-select>
</div>
<v-spacer></v-spacer>
<v-btn color="primary" style="margin-right: 10px;" @click="item.cancellHandler()">取消</v-btn>
<v-btn color="primary" @click="item.confirmHandler(item.selectedItems, item.adapter)">确定</v-btn>
</template>
<template #mainContent>
<FileMgr :adapter="item.adapter" height="300px" :options="item.fileMgrOptions"
v-model:selectedItems="item.selectedItems"></FileMgr>
v-model:selectedItems="item.selectedItems" :directory="currentDrive ? new Addr(`${currentDrive}:/`) : null">
</FileMgr>
</template>
</DialogGenerator>
</template>
Expand All @@ -23,6 +28,8 @@ import { FileMgrOptions } from '@/components/FileMgr/types/FileMgrOptions';
import dirSingleItem from '@/api/core/types/dirSingleItem';
import path from 'path'
import notification from '@/api/notification';
import getAllDrive from '@/utils/file/getAllDrive'
import Addr from '@/api/core/common/Addr';
const filePickers = ref<{
isDialogOpen: boolean,
Expand All @@ -33,6 +40,8 @@ const filePickers = ref<{
confirmHandler(selectedItems: Set<dirSingleItem>, adapter: Adapter): void,
cancellHandler(): void
}[]>([])
const currentDrive = ref("")
const allDrive = await getAllDrive()
emitter.on("Action::openFilePicker", async ({ directory, taskId, onlyAllowFolderSelection, allowMultipleSelection }) => {
const adapter = new Adapter()
Expand Down Expand Up @@ -74,3 +83,5 @@ onUnmounted(() => {
emitter.off("Action::openFilePicker")
})
</script>

<style lang="less" scoped></style>
20 changes: 14 additions & 6 deletions src/components/FileMgr/FileMgr.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ interface Props {
adapter: AdapterBase,
height?: string,
options?: FileMgrOptions,
selectedItems?: Set<dirSingleItem>
selectedItems?: Set<dirSingleItem>,
directory?: Addr
}
const props = defineProps<Props>()
const emit = defineEmits(['update:selectedItems'])
Expand Down Expand Up @@ -224,11 +225,6 @@ onMounted(async () => {
})
// <核心功能-文件相关>
watch(currentDir, async (newVal) => {
await refresh(newVal)
},
{ deep: true })
const refresh = async (arg?: Addr) => {
isLoading.value = true
if (arg) {
Expand All @@ -254,6 +250,18 @@ const refresh = async (arg?: Addr) => {
isLoading.value = false
}
watch(currentDir, async (newVal) => {
await refresh(newVal)
},
{ deep: true })
watch(() => props.directory, async (newVal) => {
if (newVal) {
currentDir.value = newVal
await refresh(newVal)
}
}, { immediate: true })
const up = () => {
currentDir.value.up()
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/AdvancedList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const props = defineProps<Props>()
const guid = sharedUtils.getHash(16)
const searchWord = ref("")
const matchedItems = computed(() => {
if (props.useSearch) {
if (props.useSearch && searchWord.value) {
return props.items.filter((item) => {
let flag = false
// 优化:flag一旦为true就立即返回(abort),不继续遍历
Expand Down
4 changes: 4 additions & 0 deletions src/styles/globalVuetifyOverrides.less
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@

.v-toolbar {
width: unset;
}

.v-input__details {
display: none !important;
}
72 changes: 72 additions & 0 deletions src/utils/file/getAllDrive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* @Description 获取电脑中所盘符及其名称
* @Author WJW
* @Date 2022-01-25
*/

import process from 'child_process'
// cmd命令
const cmdOrder = {
getAllDrive: () => ("wmic logicaldisk where drivetype=3 get deviceid"),
getOneDriveName: (drive: string) => (`wmic logicaldisk where name="${drive}:" get volumename`)
}

/**
* 获取电脑中所有盘符及其名称
* @returns 电脑中所有盘符及其名称
*/
export default async function getAllDrive(): Promise<{
drive: string;
name: string;
}[]> {
return new Promise((resolve, reject) => {
// 获取电脑中所有盘符
process.exec(cmdOrder.getAllDrive(), (error: any, stdout: any) => {
if (error !== null) {
console.error(error);
return;
}
let stdoutArr = [...stdout];
let res: string[] = [];
stdoutArr.forEach((v: string, i: number) => {
if (v === ':') {
res.push(stdoutArr[i - 1]);
}
})
let resList: {
drive: string,
name: string
}[] = [];
let promiseArr: Promise<any>[] = [];
// 获取所有盘符的所有名称
res.forEach((v: string) => {
promiseArr.push(
new Promise((resolve, reject) => {
process.exec(cmdOrder.getOneDriveName(v), (error: any, stdout: any) => {
if (error !== null) {
console.error(error);
return;
}
let stdoutArr = [...stdout];
let res: string[] = [];
stdoutArr.forEach((v: string, i: number) => {
if (v !== ' ' && v !== '\n' && v !== '\r') {
res.push(v);
}
})
res.splice(0, 10);
resList.push({
drive: v,
name: res.join('')
});
resolve(true);
})
})
)
})
Promise.all(promiseArr).then(res => {
resolve(resList);
});
});
})
}

0 comments on commit 4cd448e

Please sign in to comment.