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

收藏夹

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