Skip to content

Commit

Permalink
优化报错反馈
Browse files Browse the repository at this point in the history
增加对夜间和白天主题的适配
  • Loading branch information
loonghfut committed Sep 6, 2024
1 parent 64ee0da commit 63d9adb
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 73 deletions.
118 changes: 66 additions & 52 deletions src/FileTreeApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { url, token } from './index';
import * as api from './api';
import * as myapi from './myapi';
import {selectedOption} from './app.vue';
import { selectedOption } from './app.vue';
import { showMessage } from 'siyuan';

// import { showMessage } from 'siyuan';
export async function ceshi() {
Expand All @@ -16,56 +17,62 @@ export async function ceshi() {

export async function getFileTreeData() {
// 获取笔记本列表
const notebooksResponse = await fetch(`${url}/api/notebook/lsNotebooks`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `token ${token}`
},
body: JSON.stringify({})
});
const notebooksData = await notebooksResponse.json();
if (notebooksData.code !== 0) {
throw new Error(notebooksData.msg);
}


const fileTreeData = [];


for (const notebook of notebooksData.data.notebooks) {
// console.log(selectedOption.value);
if (selectedOption.value !== notebook.name) {
continue;
}
// 获取每个笔记本的文件和文件夹列表
const readDirResponse = await fetch(`${url}/api/file/readDir`, {
try {
const notebooksResponse = await fetch(`${url}/api/notebook/lsNotebooks`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `token ${token}`
},
body: JSON.stringify({ path: `data/${notebook.id}` })
body: JSON.stringify({})
});
const readDirData = await readDirResponse.json();
if (readDirData.code !== 0) {
throw new Error(readDirData.msg);
const notebooksData = await notebooksResponse.json();
if (notebooksData.code !== 0) {
throw new Error(notebooksData.msg);
}

const children = await processDirectory(notebook.id, readDirData.data);

const fileTreeData = [];

fileTreeData.push({
id: notebook.id,
name: notebook.name,
type: 'folder',
expanded: false,
children: children
});

}
for (const notebook of notebooksData.data.notebooks) {
// console.log(selectedOption.value);
if (selectedOption.value !== notebook.name) {
continue;
}
// 获取每个笔记本的文件和文件夹列表
const readDirResponse = await fetch(`${url}/api/file/readDir`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `token ${token}`
},
body: JSON.stringify({ path: `data/${notebook.id}` })
});
const readDirData = await readDirResponse.json();
if (readDirData.code !== 0) {
throw new Error(readDirData.msg);
}

const children = await processDirectory(notebook.id, readDirData.data);


fileTreeData.push({
id: notebook.id,
name: notebook.name,
type: 'folder',
expanded: false,
children: children
});

}

return fileTreeData;
return fileTreeData;
} catch (error) {
console.error(error);
// showMessage("获取文件树失败,请检查配置");
return [{"name": "获取文件树失败,请检查配置"}];
}
}

async function processDirectory(notebookId, items) {
Expand Down Expand Up @@ -141,18 +148,25 @@ async function GetNameByID(id: string) {
return name;
}

export async function listNotebooks(){
const notebooksResponse = await fetch(`${url}/api/notebook/lsNotebooks`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `token ${token}`
},
body: JSON.stringify({})
});
const notebooksData = await notebooksResponse.json();
if (notebooksData.code !== 0) {
throw new Error(notebooksData.msg);
export async function listNotebooks() {
try {
const notebooksResponse = await fetch(`${url}/api/notebook/lsNotebooks`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `token ${token}`
},
body: JSON.stringify({})
});
const notebooksData = await notebooksResponse.json();
if (notebooksData.code !== 0) {
showMessage("获取目标源笔记本列表失败,请检查配置");
throw new Error(notebooksData.msg);
}
return notebooksData.data.notebooks;
} catch (error) {
console.error(error);
showMessage("获取目标源笔记本列表失败,请检查配置");
return [];
}
return notebooksData.data.notebooks;
}
14 changes: 9 additions & 5 deletions src/MyVue/FileTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<script>
import {ref} from 'vue';
import { ref } from 'vue';
export const selectedFileIds = ref([]);
export const selectedFileIdsName = ref([]);
export const selectedFileBox = ref([]);
Expand All @@ -29,7 +29,7 @@ export default {
selectedFileIds,
selectedFileIdsName,
selectedFileBox
};
},
methods: {
Expand Down Expand Up @@ -61,7 +61,11 @@ export default {
.file-tree {
list-style-type: none;
padding-left: 15px;
color: #c0c0c0;
color: var(--b3-theme-on-background);
}
.tree-item:hook {
background-color: var(--b3-list-hover);
}
.tree-item {
Expand All @@ -76,15 +80,15 @@ export default {
}
.tree-item.expanded {
background-color: #333;
background-color: var(--b3-theme-primary-lightest);
}
.name {
margin-right: auto;
}
.tree-item.selected {
background-color: #2560f8;
background-color: var(--b3-theme-primary-lightest);
/* 加圆角 */
border-radius: 5px;
/* 你可以根据需要调整颜色 */
Expand Down
61 changes: 45 additions & 16 deletions src/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<p v-if="selectedFileIdsName.length" class="info-item">已选笔记: <span class="info-value">{{ selectedFileIdsName
}}</span></p>
<p>-----------------</p>
<p v-if="selectedFileIdsName.length" class="info-item"><button class="MY-refresh-button"
@click="plugin.pullNote(selectedFileIds)">拉取笔记</button></p>
<div v-if="selectedFileIdsName.length"><button class="MY-pull-note-button"
@click="plugin.pullNote(selectedFileIds)">拉取笔记</button></div>
</div>
</div>
</template>
Expand Down Expand Up @@ -106,7 +106,7 @@ export default {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #f6f8fa;
color: var(--b3-theme-on-background);
/* background-color: #1e1e1e;
min-height: 98%; */
padding: 10px;
Expand All @@ -125,7 +125,7 @@ export default {
}
.title {
color: #f6f8fa;
color: var(--b3-theme-on-background);
font-size: 20px;
margin-bottom: 20px;
}
Expand All @@ -138,17 +138,17 @@ export default {
}
.title {
margin-right: 30px;
margin-right: 15px;
/* 给标题和按钮之间添加一点间隔 */
}
.MY-refresh-button {
background: none;
/* 按钮背景色 */
color: white;
color: var(--b3-theme-on-background);
/* 按钮文字颜色 */
/* 加个边框 */
border: 1px solid white;
border: 1px solid var(--b3-theme-on-background);
/* 字体大小 */
font-size: 13px;
margin-bottom: 20px;
Expand All @@ -159,16 +159,18 @@ export default {
/* 鼠标移动到按钮上时变为手型 */
transition: background-color 0.3s ease;
/* 添加过渡效果 */
margin-right: 4px;
margin-left: auto;
/* 靠右侧边 */
}
.MY-refresh-button:hover {
background-color: #0056b3;
background-color: var(--b3-list-hover);
/* 悬停时的背景色 */
}
.info-container {
background-color: #2e2e2e;
background-color: var(--b3-theme-surface);
/* 深色背景 */
padding: 15px;
border-radius: 8px;
Expand All @@ -178,7 +180,7 @@ export default {
.info-item {
font-size: 16px;
color: #ccc;
color: var(--b3-theme-on-background);;
/* 浅色文本 */
}
Expand All @@ -189,9 +191,9 @@ export default {
}
.MY-select-box {
background-color: #333;
color: #fff;
border: 1px solid #555;
background-color: var(--b3-theme-surface);
color: var(--b3-theme-on-background);
border: 1px solid var(--b3-theme-on-background);
/* padding: 5px; */
border-radius: 4px;
font-size: 13px;
Expand All @@ -200,11 +202,38 @@ export default {
}
.MY-select-box option {
background-color: #333;
color: #fff;
background-color: var(--b3-theme-surface);;
color: var(--b3-theme-on-background);;
}
.MY-select-label {
margin-right: 10px;
}
.MY-pull-note-button {
background: none;
/* 按钮背景色 */
color: var(--b3-theme-on-background);
/* 按钮文字颜色 */
/* 加个边框 */
border: 1px solid var(--b3-theme-on-background);
/* 字体大小 */
font-size: 13px;
margin-bottom: 5px;
border-radius: 5px;
/* 圆角效果 */
/* padding: 2px 2px; 内边距 */
cursor: pointer;
/* 鼠标移动到按钮上时变为手型 */
transition: background-color 0.3s ease;
/* 添加过渡效果 */
margin-left: auto;
}
.MY-pull-note-button:hover {
background-color: var(--b3-list-hover);
/* 悬停时的背景色 */
}
</style>

0 comments on commit 63d9adb

Please sign in to comment.