提交 43a6ddf4 编写于 作者: View Design's avatar View Design

收藏夹

上级 3134f178
......@@ -50,8 +50,8 @@
</template>
<script setup>
const { $isLibrarySelectOpen, $selectCollectionId, $selectThreadId } = storeToRefs(useLibraryStore())
const { $openLibrarySelect, $closeLibrarySelect, $openLibraryCreate, $setSelectCollectionId } = useLibraryStore()
const { getCollection, saveCollection, deleteCollectionRecord } = useCollectionRequest()
const { $openLibrarySelect, $closeLibrarySelect, $openLibraryCreate, $setSelectCollectionId, $getCollection } = useLibraryStore()
const { saveCollection, deleteCollectionRecord } = useCollectionRequest()
// 合集列表
const collection = ref([])
const selected = ref([])
......@@ -66,9 +66,6 @@ function handleOpenCreate () {
handleClose()
$openLibraryCreate()
}
async function getCollectionData () {
collection.value = await getCollection()
}
async function handleSelected(id) {
selected.value = [id]
}
......@@ -94,6 +91,6 @@ async function handleSave() {
}
watch(() => $isLibrarySelectOpen.value, () => {
selected.value = [...$selectCollectionId.value]
getCollectionData()
$getCollection()
})
</script>
......@@ -14,16 +14,6 @@ export default () => {
})
return { data, error }
}
// 合集列表
const getCollection = async () => {
const { data, error } = await useRequest('/v1/collection/list', {
method: 'get'
})
if (error.value) {
return []
}
return data.value.data || []
}
// 删除收藏夹
const deleteCollection = async (collection_id) => {
const {data, error} = await useRequest(`/v1/collection/${collection_id}/remove`, {
......@@ -43,7 +33,7 @@ export default () => {
}
// 查询收藏夹会话列表
const findCollection = async (collection_id) => {
const {data, error} = await useRequest(`/v1/collection/${collection_id}/items`, { method: 'get' })
const {data, error} = await useRequest(`/v1/collection/${collection_id}/items`)
if (error.value) {
return []
}
......@@ -59,13 +49,10 @@ export default () => {
}
// 查询会话是否被收藏
const findRecordCollection = async (c_id) => {
const {data, error} = await useRequest(`/v1/collection/item/check/${c_id}`, {
method: 'get'
})
const {data, error} = await useRequest(`/v1/collection/item/check/${c_id}`)
return { data, error }
}
return {
getCollection,
setOrUpdateCollection,
deleteCollection,
saveCollection,
......
......@@ -19,13 +19,14 @@
</template>
<script setup>
const route = useRoute()
const { findCollection, getCollection } = useCollectionRequest()
const { findCollection } = useCollectionRequest()
const { $collection } = storeToRefs(useLibraryStore())
const { $getCollection } = useLibraryStore()
const state = reactive({
id: Number(route.params.id)
})
const themesTagList = ref([])
const collection = ref([])
const currentCollect = computed(() => collection.value.find(i => i.id === state.id))
const currentCollect = computed(() => $collection.value.find(i => i.id === state.id))
async function findCollectionData() {
const data = await findCollection(state.id)
themesTagList.value = data.map(item => {
......@@ -36,8 +37,5 @@ async function findCollectionData() {
})
}
await findCollectionData()
async function getCollectionData () {
collection.value = await getCollection()
}
await getCollectionData()
await $getCollection()
</script>
\ No newline at end of file
......@@ -26,7 +26,7 @@
</div>
<div class="flex flex-col gap-4 mt-4">
<ILibraryCollect
v-for="item in collection"
v-for="item in $collection"
:item="item"
:key="item.id"
/>
......@@ -37,23 +37,18 @@
</div>
</template>
<script setup>
const { $openLibraryCreate } = useLibraryStore()
const { getCollection } = useCollectionRequest()
const { $collection } = storeToRefs(useLibraryStore())
const { $openLibraryCreate, $getCollection } = useLibraryStore()
const { getThreadsList } = useLibraryRequest()
function handleOpenCreateLibrary () {
$openLibraryCreate()
}
// 合集列表
const collection = ref([])
// 主题列表
const threads = ref([])
async function getCollectionData () {
collection.value = await getCollection()
}
async function getThreadData() {
threads.value = await getThreadsList()
}
await getThreadData()
await getCollectionData()
await $getCollection()
</script>
......@@ -6,6 +6,8 @@ export const useLibraryStore = defineStore('library', () => {
const $selectThreadId = ref('')
const $selectCollectionId = ref([])
const $collection = ref([])
function $openLibraryCreate () {
$isLibraryCreateOpen.value = true
}
......@@ -23,6 +25,11 @@ export const useLibraryStore = defineStore('library', () => {
function $setSelectCollectionId (ids) {
$selectCollectionId.value = ids
}
async function $getCollection () {
const { data } = await useRequest('/v1/collection/list')
$collection.value = data.value.data
}
return {
$selectThreadId,
$isLibraryCreateOpen,
......@@ -32,6 +39,8 @@ export const useLibraryStore = defineStore('library', () => {
$openLibrarySelect,
$closeLibrarySelect,
$selectCollectionId,
$setSelectCollectionId
$setSelectCollectionId,
$collection,
$getCollection
}
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册