移除书签机制 更新了项目描述 增加对有章节作品阅读支持 [BugFix] BetterHr 无法在 Markdown 显示的问题 [Base] 增加 Markdown 渲染锚点支持
This commit is contained in:
@ -102,8 +102,9 @@ export const useApiStore = defineStore('api', () => {
|
||||
inited = false
|
||||
await init()
|
||||
}
|
||||
async function getWork(workId) {
|
||||
return await apiGet('work',{ workId })
|
||||
async function getWork(workId, chapterId) {
|
||||
if (chapterId) return await apiGet(`work/${workId}/${chapterId}`)
|
||||
return await apiGet(`work/${workId}`)
|
||||
}
|
||||
return {
|
||||
init,
|
||||
|
@ -1,58 +0,0 @@
|
||||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
import { openDB } from 'idb';
|
||||
|
||||
export const useDB = defineStore('_db', () => {
|
||||
const dbPromise = openDB('data', 1, {
|
||||
upgrade(db) {
|
||||
const bookmarkStore = db.createObjectStore('bookmarks', {
|
||||
keyPath: 'id',
|
||||
autoIncrement: true,
|
||||
})
|
||||
bookmarkStore.createIndex('by-workId', 'workId');
|
||||
},
|
||||
})
|
||||
return {
|
||||
db: dbPromise
|
||||
}
|
||||
})
|
||||
|
||||
export const useBookmarkStore = defineStore('bookmark', () => {
|
||||
const db = useDB().db
|
||||
async function getAll(workId) {
|
||||
return (await db).getAllFromIndex('bookmarks', 'by-workId', workId);
|
||||
}
|
||||
async function get(id) {
|
||||
return (await db).get('bookmarks', id);
|
||||
}
|
||||
async function add(workId, index, para, name ) {
|
||||
return (await db).add('bookmarks', {
|
||||
workId, name, para, index
|
||||
});
|
||||
}
|
||||
async function del(id) {
|
||||
(await db).delete('bookmarks', id);
|
||||
}
|
||||
async function delByWork(workId) {
|
||||
(await getAll(workId)).forEach(async (item) => {
|
||||
del(item.id)
|
||||
})
|
||||
}
|
||||
async function updateName(id, name) {
|
||||
const raw = await get(id)
|
||||
if (raw) {
|
||||
raw.name = name
|
||||
console.log(name)
|
||||
await (await db).put('bookmarks', raw);
|
||||
}
|
||||
}
|
||||
return {
|
||||
get,
|
||||
add,
|
||||
del,
|
||||
getAll,
|
||||
delByWork,
|
||||
updateName
|
||||
}
|
||||
})
|
@ -8,6 +8,7 @@ import { useApiStore } from '@/stores/api.js'
|
||||
export const useWorkReadState = defineStore('workRead', () => {
|
||||
const api = useApiStore()
|
||||
const id = ref(null)
|
||||
const cid = ref(null)
|
||||
const summary = ref(null)
|
||||
const pesud = ref(null)
|
||||
const title = ref(null)
|
||||
@ -25,7 +26,7 @@ export const useWorkReadState = defineStore('workRead', () => {
|
||||
title.value = data.title
|
||||
summary.value = [escapeAndFormatText(data.summary)]
|
||||
pesud.value = data.pesud
|
||||
text.value = data.text.split('\n\n')
|
||||
text.value = data.text
|
||||
publishedTime.value = data.stats.publishedTime
|
||||
wordCount.value = data.stats.wordCount
|
||||
kudoCount.value = data.stats.kudoCount
|
||||
@ -34,10 +35,10 @@ export const useWorkReadState = defineStore('workRead', () => {
|
||||
fandom.value = data.fandom
|
||||
lang.value = data.lang
|
||||
}
|
||||
async function loadWork(target) {
|
||||
if (target == id.value || state.value == 'loading') return
|
||||
async function loadWork(target, targetc) {
|
||||
if (target == id.value && targetc == cid.value || state.value == 'loading') return
|
||||
state.value = 'loading'
|
||||
const result = await api.getWork(target)
|
||||
const result = await api.getWork(target, targetc)
|
||||
if (result.status == 200) {
|
||||
setData(result.data)
|
||||
state.value = 'ready'
|
||||
@ -47,7 +48,7 @@ export const useWorkReadState = defineStore('workRead', () => {
|
||||
}
|
||||
}
|
||||
return {
|
||||
id,
|
||||
id, cid,
|
||||
title,
|
||||
summary,
|
||||
pesud,
|
||||
|
Reference in New Issue
Block a user