mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
🐛 修复数据库插入错误
This commit is contained in:
@@ -5,19 +5,38 @@
|
||||
<v-select
|
||||
v-model="curSelect"
|
||||
class="pc-select"
|
||||
:items="collections.map((i) => i.title)"
|
||||
:items="collections"
|
||||
:clearable="curSelect !== '未分类'"
|
||||
variant="outlined"
|
||||
label="合集"
|
||||
>
|
||||
<template v-slot:item="{ props, item }">
|
||||
<v-list-item v-bind="props" :title="item.raw.title" :subtitle="item.raw.desc" />
|
||||
</template>
|
||||
</v-select>
|
||||
<v-btn
|
||||
size="small"
|
||||
class="pc-btn"
|
||||
icon="mdi-refresh"
|
||||
title="获取用户收藏"
|
||||
@click="freshUser()"
|
||||
/>
|
||||
<v-btn
|
||||
size="small"
|
||||
class="pc-btn"
|
||||
icon="mdi-import"
|
||||
@click="freshOther"
|
||||
title="导入其他用户收藏"
|
||||
/>
|
||||
<v-btn size="small" class="pc-btn" icon="mdi-pencil" @click="toEdit()" title="编辑收藏" />
|
||||
<v-btn
|
||||
size="small"
|
||||
v-if="curSelect !== '未分类'"
|
||||
class="pc-btn"
|
||||
icon="mdi-delete"
|
||||
@click="deleteCollect()"
|
||||
title="删除合集"
|
||||
/>
|
||||
<v-btn rounded class="pc-btn" prepend-icon="mdi-refresh" @click="freshUser()"
|
||||
>获取用户收藏
|
||||
</v-btn>
|
||||
<v-btn rounded class="pc-btn" prepend-icon="mdi-import" @click="freshOther"
|
||||
>导入其他用户收藏
|
||||
</v-btn>
|
||||
<v-btn rounded class="pc-btn" prepend-icon="mdi-pencil" @click="toEdit()"> 编辑收藏 </v-btn>
|
||||
<!-- todo 编辑收藏 -->
|
||||
<v-pagination class="pc-page" v-model="page" :total-visible="view" :length="length" />
|
||||
</div>
|
||||
<div class="pc-posts">
|
||||
@@ -100,6 +119,33 @@ function toEdit() {
|
||||
});
|
||||
}
|
||||
|
||||
async function deleteCollect(): Promise<void> {
|
||||
const res = await showConfirm({
|
||||
title: "确定删除分类?",
|
||||
text: selected.value.length > 0 ? `该分类下 ${selected.value.length} 条帖子将变为未分类` : "",
|
||||
});
|
||||
if (!res) {
|
||||
showSnackbar({
|
||||
text: "取消删除",
|
||||
color: "cancel",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const resD = await TSUserCollection.deleteCollect(curSelect.value);
|
||||
if (resD) {
|
||||
showSnackbar({
|
||||
text: "删除成功",
|
||||
color: "success",
|
||||
});
|
||||
window.location.reload();
|
||||
} else {
|
||||
showSnackbar({
|
||||
text: "删除失败",
|
||||
color: "error",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 根据合集筛选
|
||||
async function freshPost(select: string | null): Promise<void> {
|
||||
if (select === null) {
|
||||
|
||||
@@ -167,7 +167,7 @@ async function addCollect(
|
||||
let collectionRes: TGApp.Sqlite.UserCollection.UFCollection[] = await db.select(collectionSql, [
|
||||
collection,
|
||||
]);
|
||||
if (collectionRes.length === 0 || collectionRes.length > 1) {
|
||||
if (collectionRes.length === 0) {
|
||||
if (!recursive) {
|
||||
return false;
|
||||
}
|
||||
@@ -177,16 +177,35 @@ async function addCollect(
|
||||
}
|
||||
collectionRes = await db.select(collectionSql, [collection]);
|
||||
}
|
||||
const insertMapSql =
|
||||
"INSERT INTO UFMap (postId, collectionId,post, collection, desc, updated) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
await db.execute(insertMapSql, [
|
||||
// 查找是否已经有了数据
|
||||
const mapSql = "SELECT * FROM UFMap WHERE postId = ? AND collectionId = ?";
|
||||
const mapRes: TGApp.Sqlite.UserCollection.UFMap[] = await db.select(mapSql, [
|
||||
postId,
|
||||
collectionRes[0].id,
|
||||
post.post.subject,
|
||||
collection,
|
||||
collectionRes[0].desc,
|
||||
new Date().getTime(),
|
||||
]);
|
||||
if (mapRes.length > 0) {
|
||||
const updateMapSql =
|
||||
"UPDATE UFMap SET post = ?, collection = ?, desc = ?, updated = ? WHERE postId = ? AND collectionId = ?";
|
||||
await db.execute(updateMapSql, [
|
||||
post.post.subject,
|
||||
collection,
|
||||
collectionRes[0].desc,
|
||||
new Date().getTime(),
|
||||
postId,
|
||||
collectionRes[0].id,
|
||||
]);
|
||||
} else {
|
||||
const insertMapSql =
|
||||
"INSERT INTO UFMap (postId, collectionId,post, collection, desc, updated) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
await db.execute(insertMapSql, [
|
||||
postId,
|
||||
collectionRes[0].id,
|
||||
post.post.subject,
|
||||
collection,
|
||||
collectionRes[0].desc,
|
||||
new Date().getTime(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user