feat: 更新数据集创建页面,添加选择存储路径和数据集名称功能
This commit is contained in:
@@ -11,10 +11,10 @@ afterNavigate(() => {
|
||||
|
||||
<main class="flex flex-col justify-center items-center overflow-hidden size-full">
|
||||
<div class="flex flex-col justify-center items-stretch gap-3">
|
||||
<button class="btn">
|
||||
<a class="btn" href="/create">
|
||||
<NewFolder width="20" />
|
||||
New Dataset
|
||||
</button>
|
||||
</a>
|
||||
<button class="btn">
|
||||
<OpenFolder width="20" />
|
||||
Open Dataset
|
||||
|
||||
@@ -1,8 +1,63 @@
|
||||
<script lang="ts">
|
||||
import { afterNavigate } from '$app/navigation';
|
||||
import { currentActivate } from '$lib/stores/navigate';
|
||||
import { message, open } from '@tauri-apps/plugin-dialog';
|
||||
import { readDir } from '@tauri-apps/plugin-fs';
|
||||
|
||||
afterNavigate(() => {
|
||||
currentActivate.set('dataset');
|
||||
});
|
||||
|
||||
let storePath = $state('');
|
||||
let datasetName = $state('');
|
||||
|
||||
async function selectStorePath() {
|
||||
try {
|
||||
const selectResult = await open({
|
||||
directory: true,
|
||||
multiple: false,
|
||||
title: 'Select Dataset store path',
|
||||
});
|
||||
let selectedPath = '';
|
||||
if (Array.isArray(selectResult)) {
|
||||
selectedPath = selectResult[0] ?? '';
|
||||
} else if (typeof selectResult === 'string') {
|
||||
selectedPath = selectResult;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!selectedPath) {
|
||||
return;
|
||||
}
|
||||
|
||||
const entries = await readDir(selectedPath);
|
||||
if (entries.length > 0) {
|
||||
await message('The selected directory is not empty. Please choose an empty directory.', {
|
||||
kind: 'warning',
|
||||
title: 'Directory Unavailable',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
storePath = selectedPath;
|
||||
} catch (error) {
|
||||
console.error('Failed to select store path:', error);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<main class="flex flex-col gap-2 p-4 self-start">
|
||||
<div class="join">
|
||||
<label class="input input-md focus-within:outline-0 w-fit join-item">
|
||||
<span class="label min-w-[10em]">Store Path</span>
|
||||
<input type="text" class="min-w-[25em]" readonly value={storePath} />
|
||||
</label>
|
||||
<button class="btn join-item" onclick={selectStorePath}>Select</button>
|
||||
</div>
|
||||
<label class="input input-md focus-within:outline-0 w-fit">
|
||||
<span class="label min-w-[10em]">Dataset Name</span>
|
||||
<input type="text" class="min-w-[20em]" bind:value={datasetName} />
|
||||
</label>
|
||||
<button class="btn btn-primary btn-md w-fit self-center">Create</button>
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user