Skip to content

Commit

Permalink
✨ 收藏功能基本完成
Browse files Browse the repository at this point in the history
close #100
  • Loading branch information
BTMuli committed Mar 22, 2024
1 parent 417e98a commit 17c5d87
Show file tree
Hide file tree
Showing 5 changed files with 387 additions and 74 deletions.
16 changes: 13 additions & 3 deletions src/components/main/t-postcard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<img :src="card.forum.icon" :alt="card.forum.name" />
<span>{{ card.forum.name }}</span>
</div>
<!-- todo 需要测试 -->
<div v-if="props.selectMode" class="tpc-select">
<v-checkbox-btn v-model="selectedList" :value="props.modelValue.post.post_id" />
</div>
Expand All @@ -60,12 +59,23 @@ interface TPostCardProps {
selected?: string[];
}
interface TPostCardEmits {
(e: "update:selected", value: string[]): void;
}
const props = withDefaults(defineProps<TPostCardProps>(), {
selectMode: false,
});
const emits = defineEmits<TPostCardEmits>();
const isAct = ref<boolean>(false);
const card = ref<TGApp.Plugins.Mys.News.RenderCard>();
const selectedList = computed(() => props.selected);
const selectedList = computed({
get: () => props.selected,
set: (v) => {
if (v === undefined) return;
emits("update:selected", v);
},
});
onBeforeMount(() => {
card.value = getPostCard(props.modelValue);
Expand Down Expand Up @@ -235,7 +245,7 @@ function getPostCard(item: TGApp.Plugins.Mys.Post.FullData): TGApp.Plugins.Mys.N
.tpc-select {
position: absolute;
top: 0;
bottom: 0;
left: 0;
display: flex;
align-items: center;
Expand Down
198 changes: 198 additions & 0 deletions src/components/overlay/to-collectPost.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<template>
<TOverlay v-model="visible" hide :to-click="onCancel" blur-val="20px">
<div class="tocp-container">
<div class="tocp-title">选择分类</div>
<div class="tocp-list">
<v-list-item v-for="item in collectList" :key="item.id">
<template #prepend>
<v-list-item-action start>
<v-checkbox-btn v-model="select" :value="item.title" />
</v-list-item-action>
</template>
<template #title>{{ item.title }}</template>
<template #subtitle>{{ item.desc }}</template>
</v-list-item>
</div>
<div class="tocp-bottom">
<v-btn class="tocp-btn" rounded @click="newCollect">新建分类</v-btn>
<v-btn class="tocp-btn" rounded @click="onCancel">取消</v-btn>
<v-btn :loading="submit" class="tocp-btn" rounded @click="onSubmit">确定</v-btn>
</div>
</div>
</TOverlay>
</template>
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import TSUserCollection from "../../plugins/Sqlite/modules/userCollect";
import showConfirm from "../func/confirm";
import showSnackbar from "../func/snackbar";
import TOverlay from "../main/t-overlay.vue";
interface ToPostCollectProps {
modelValue: boolean;
post: string[];
}
interface ToPostCollectEmits {
(e: "update:modelValue", value: boolean): void;
(e: "submit"): void;
}
const props = defineProps<ToPostCollectProps>();
const emits = defineEmits<ToPostCollectEmits>();
const select = ref<string>();
const collectList = ref<TGApp.Sqlite.UserCollection.UFCollection[]>([]);
const submit = ref(false);
const visible = computed({
get: () => props.modelValue,
set: (value) => {
emits("update:modelValue", value);
},
});
function onCancel() {
visible.value = false;
}
watch(
() => props.modelValue,
async (val) => {
if (val) {
await freshData();
}
},
);
async function onSubmit(): Promise<void> {
if (!select.value) {
showSnackbar({
text: "请选择分类",
color: "error",
});
return;
}
submit.value = true;
let force = false;
const forceCheck = await showConfirm({
title: "是否保留原分类",
text: "若否则仅保留新分类",
});
if (forceCheck === false) force = true;
const check = await TSUserCollection.updatePostsCollect(props.post, select.value, force);
if (!check) {
showSnackbar({
text: "处理失败",
color: "error",
});
submit.value = false;
return;
}
showSnackbar({
text: `成功处理 ${props.post.length} 个帖子`,
color: "success",
});
submit.value = false;
visible.value = false;
emits("submit");
}
async function newCollect(): Promise<void> {
let title, desc;
const titleC = await showConfirm({
mode: "input",
title: "新建分类",
text: "请输入分类名称",
});
if (titleC === undefined || titleC === false) return;
if (titleC === "未分类") {
showSnackbar({
text: "分类名不可为未分类",
color: "error",
});
return;
}
if (collectList.value.find((i) => i.title === titleC)) {
showSnackbar({
text: "分类已存在",
color: "error",
});
return;
}
title = titleC;
const descC = await showConfirm({
mode: "input",
title: "新建分类",
text: "请输入分类描述",
});
if (descC === false) return;
if (descC === undefined) desc = title;
else desc = descC;
const res = await TSUserCollection.createCollect(title, desc);
if (res) {
showSnackbar({
text: "新建成功",
color: "success",
});
await freshData();
} else {
showSnackbar({
text: "新建失败",
color: "error",
});
}
}
async function freshData(): Promise<void> {
collectList.value = await TSUserCollection.getCollectList();
select.value = undefined;
}
</script>
<style lang="css" scoped>
.tocp-container {
display: flex;
width: 400px;
flex-direction: column;
align-items: flex-start;
justify-content: center;
padding: 10px;
border-radius: 10px;
background: var(--app-page-bg);
row-gap: 10px;
}
.tocp-title {
font-family: var(--font-title);
font-size: 20px;
}
.tocp-list {
display: flex;
width: 100%;
max-height: 300px;
flex-direction: column;
overflow-y: auto;
row-gap: 10px;
}
.tocp-bottom {
display: flex;
align-items: center;
justify-content: center;
margin-top: 20px;
margin-left: auto;
column-gap: 10px;
}
.tocp-btn {
background: var(--btn-bg-1);
color: var(--btn-text-1);
font-family: var(--font-title);
}
.dark .tocp-btn {
border: 1px solid var(--common-shadow-2);
}
</style>
6 changes: 3 additions & 3 deletions src/components/overlay/to-postCollect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
当前所属分类:{{ postCollect.map((i) => i.collection).join(",") }}
</div>
<div v-else class="topc-cur-collect">当前所属分类:未分类</div>
<div class="tpoc-collect-list">
<div class="topc-collect-list">
<v-list-item v-for="item in collectList" :key="item.id">
<template #prepend>
<v-list-item-action start>
Expand Down Expand Up @@ -208,8 +208,8 @@ function onCancel() {
}

.topc-post-info {
font-family: var(--font-title);
font-size: 18px;
font-weight: bold;
}

.topc-cur-collect {
Expand All @@ -218,7 +218,7 @@ function onCancel() {
word-break: break-all;
}

.tpoc-collect-list {
.topc-collect-list {
display: flex;
width: 100%;
max-height: 300px;
Expand Down
Loading

0 comments on commit 17c5d87

Please sign in to comment.