提交 d1363911 编写于 作者: D DebugIsFalse

feature: 添加收藏绘画功能

上级 c88dce72
...@@ -30,29 +30,32 @@ ...@@ -30,29 +30,32 @@
> >
<div class="flex flex-grow justify-between items-center"> <div class="flex flex-grow justify-between items-center">
<div>{{item.name}}</div> <div>{{item.name}}</div>
<UIcon v-if="selectedCollection.includes(item.id)" name="i-heroicons-check-circle-20-solid" class="text-primary text-lg" /> <UIcon v-if="selected.includes(item.id)" name="i-heroicons-check-circle-20-solid" class="text-primary text-lg" />
</div> </div>
</UButton> </UButton>
</div> </div>
</div> </div>
<!-- <template #footer> <template #footer>
<div class="flex justify-end"> <div class="flex justify-end">
<UButton <UButton
size="md" size="md"
label="保存" label="保存"
:loading="loading"
@click="handleSave"
/> />
</div> </div>
</template> --> </template>
</UCard> </UCard>
</UModal> </UModal>
</template> </template>
<script setup> <script setup>
const { $isLibrarySelectOpen, $selectCollectionId, $selectThreadId } = storeToRefs(useLibraryStore()) const { $isLibrarySelectOpen, $selectCollectionId, $selectThreadId } = storeToRefs(useLibraryStore())
const { $openLibrarySelect, $closeLibrarySelect, $openLibraryCreate, $setSelectCollectionId } = useLibraryStore() const { $openLibrarySelect, $closeLibrarySelect, $openLibraryCreate, $setSelectCollectionId } = useLibraryStore()
const { getCollection, saveCollection } = useCollectionRequest() const { getCollection, saveCollection, deleteCollectionRecord } = useCollectionRequest()
// 合集列表 // 合集列表
const collection = ref([]) const collection = ref([])
const selectedCollection = ref([]) const selected = ref([])
const loading = ref(false)
function handleClose () { function handleClose () {
$closeLibrarySelect() $closeLibrarySelect()
} }
...@@ -67,20 +70,28 @@ async function getCollectionData () { ...@@ -67,20 +70,28 @@ async function getCollectionData () {
collection.value = await getCollection() collection.value = await getCollection()
} }
async function handleSelected(id) { async function handleSelected(id) {
if (selectedCollection.value.includes(id)) { selected.value = [id]
await deleteCollectionRecord(id, $selectThreadId.value) }
async function handleSave() {
if (loading.value) return
loading.value = true
// 取消合集
const hasSelected = $selectCollectionId.value
if (hasSelected.length) {
const { error } = await deleteCollectionRecord(hasSelected[0], $selectThreadId.value)
!error.value && $setSelectCollectionId([])
} }
selectedCollection.value = [id] // 添加合集
$setSelectCollectionId(selectedCollection.value) if (selected.value.length) {
const { error } = await saveCollection({ collection_id: id, c_id: $selectThreadId.value }) const selectedItem = selected.value[0]
if (error.value) { const { error } = await saveCollection({ collection_id: selectedItem, c_id: $selectThreadId.value })
selectedCollection.value = [] !error.value && $setSelectCollectionId([selectedItem])
return
} }
loading.value = false
handleClose() handleClose()
} }
watch(() => $isLibrarySelectOpen.value, () => { watch(() => $isLibrarySelectOpen.value, () => {
selectedCollection.value = $selectCollectionId.value selected.value = [...$selectCollectionId.value]
getCollectionData() getCollectionData()
}) })
</script> </script>
...@@ -136,7 +136,6 @@ async function initData () { ...@@ -136,7 +136,6 @@ async function initData () {
const { data, error } = await findRecordCollection(route.params.id) const { data, error } = await findRecordCollection(route.params.id)
if (!error.value) { if (!error.value) {
const ids = data.value.data.map(item => item.collection_id) const ids = data.value.data.map(item => item.collection_id)
console.log(`ids:`, ids)
$setSelectCollectionId(ids) $setSelectCollectionId(ids)
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册