Skip to content

Commit

Permalink
web端优化数据加载
Browse files Browse the repository at this point in the history
  • Loading branch information
Xwite committed Oct 15, 2024
1 parent b326d2a commit 123d9b4
Show file tree
Hide file tree
Showing 21 changed files with 197 additions and 139 deletions.
3 changes: 3 additions & 0 deletions modules/web/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# d.ts files Generated by unplugin-auto unplugin-vue-components
auto-imports.d.ts
components.d.ts
20 changes: 9 additions & 11 deletions modules/web/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import type { AxiosResponse } from 'axios'
import type { LeagdoApiResponse } from './api'
import API, {
setWebsocketOnError,
legado_http_entry_point,
legado_webSocket_entry_point,
setApiEntryPoint,
} from './api'
import API, { setWebsocketOnError, setApiEntryPoint } from './api'
import ajax from './axios'
import { validatorHttpUrl } from '@/utils/utils'

const LeagdoApiResponseKeys: string[] = Array.of('isSuccess', 'errorMsg')

const notification = ElMessage
/** Axios.Interceptor: check if resp is LeagaoLeagdoApiResponse*/
const responseCheckInterceptor = (resp: AxiosResponse) => {
let isLeagdoApiResponse = true
Expand All @@ -26,21 +22,23 @@ const responseCheckInterceptor = (resp: AxiosResponse) => {
if ((data as LeagdoApiResponse<unknown>).isSuccess === true) {
if (!('data' in data)) {
isLeagdoApiResponse = false
LeagdoApiResponseKeys.length = 0
}
}
} catch {
isLeagdoApiResponse = false
}
if (isLeagdoApiResponse === false) {
ElNotification.warning('后端返回内容格式错误')
notification.warning({ message: '后端返回内容格式错误', grouping: true })
throw new Error()
}
return resp
}

const axiosErrorInterceptor = (err: unknown) => {
ElNotification.error('后端连接失败,请检查阅读WEB服务或者设置其它可用链接')
notification.error({
message: '后端连接失败,请检查阅读WEB服务或者设置其它可用链接',
grouping: true,
})
throw err
}
// http全局
Expand Down Expand Up @@ -80,8 +78,8 @@ export const parseLeagdoHttpUrlWithDefault = (

console.info('legado_api_config:')
console.table({
'http API入口': legado_http_entry_point,
'webSocket API入口': legado_webSocket_entry_point,
'http API入口': http_entry_point,
'webSocket API入口': webSocket_entry_point,
})
return [http_entry_point, webSocket_entry_point]
}
Expand Down
1 change: 0 additions & 1 deletion modules/web/src/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ declare global {
const EffectScope: typeof import('vue')['EffectScope']
const ElMessage: typeof import('element-plus/es')['ElMessage']
const ElMessageBox: typeof import('element-plus/es')['ElMessageBox']
const ElNotification: typeof import('element-plus/es')['ElNotification']
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
const computed: typeof import('vue')['computed']
const createApp: typeof import('vue')['createApp']
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/components/BookItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const subJustify = computed(() =>
)
</script>
<style scoped>
<style lang="scss" scoped>
.books-wrapper {
overflow: auto;
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/components/CatalogItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const catas = computed(() => {
})
</script>

<style scoped>
<style lang="scss" scoped>
.selected {
color: #eb4259;
}
Expand Down
3 changes: 2 additions & 1 deletion modules/web/src/components/ChapterContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type { webReadConfig } from '@/web'
const store = useBookStore()
const readWidth = computed(() => store.config.readWidth)
const bookUrl = computed(() => store.readingBook.bookUrl)
const props = defineProps<{
chapterIndex: number
contents: Array<string>
Expand Down Expand Up @@ -116,7 +117,7 @@ onUnmounted(() => {
})
</script>

<style scoped>
<style lang="scss" scoped>
.title {
margin-bottom: 57px;
font:
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/components/PopCatalog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const gotoChapter = (chapter: BookChapter) => {
}
</script>

<style scoped>
<style lang="scss" scoped>
.cata-wrapper {
margin: -16px;
padding: 18px 0 24px 25px;
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/components/ReadSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ const setInfiniteLoading = (loading: boolean) => {
}
</script>

<style scoped>
<style lang="scss" scoped>
:deep(.iconfont) {
font-family: iconfont;
font-style: normal;
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/components/SourceDebug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const isBookSource = computed(() => {
})
</script>

<style scoped>
<style lang="scss" scoped>
:deep(#debug-text) {
height: calc(100vh - 45px - 36px - 5px);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/components/SourceHelp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { Link } from '@element-plus/icons-vue'
</div>
</template>

<style scoped>
<style lang="scss" scoped>
.el-link {
padding: 4px;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/components/SourceItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const isSaveError = computed(() => {
return !map.has(sourceUrl.value)
})
</script>
<style scoped>
<style lang="scss" scoped>
:deep(.el-checkbox__label) {
flex: 1;
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/components/SourceJson.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ watchEffect(async () => {
}
})
</script>
<style scoped>
<style lang="scss" scoped>
:deep(.el-input) {
width: 100%;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/components/SourceList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const outExport = () => {
}
</script>

<style scoped>
<style lang="scss" scoped>
.tool {
display: flex;
margin: 4px 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/components/ToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ onMounted(() => {
})
</script>

<style scoped>
<style lang="scss" scoped>
.flex-space-between {
display: flex;
justify-content: space-between;
Expand Down
5 changes: 0 additions & 5 deletions modules/web/src/config/sourceConfig.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import type { Source } from '@/source'
import bookSourceEditConfig from './bookSourceEditConfig'
import rssSourceEditConfig from './rssSourceEditConfig'

type PickAnyValueKey<T> = {
[K in keyof T]: T[K] extends { [prop: string]: string } ? K : never
}
type b = keyof PickAnyValueKey<BookSoure>

type SourceConfigKey =
| keyof typeof bookSourceEditConfig
| keyof typeof rssSourceEditConfig
Expand Down
14 changes: 14 additions & 0 deletions modules/web/src/router/bookRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,18 @@ const router = createRouter({
routes: bookRoutes,
})

import { createApp } from 'vue'
import App from '@/App.vue'
import store, { useBookStore } from '@/store'

// init pinia instance
createApp(App).use(store)
router.beforeEach((to, from, next) => {
// 自动加载阅读配置
useBookStore()
.loadWebConfig()
.then(() => next())
.catch(() => next())
})

export default router
15 changes: 15 additions & 0 deletions modules/web/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,19 @@ const router = createRouter({
router.afterEach(to => {
if (to.name == 'shelf') document.title = '书架'
})

import { createApp } from 'vue'
import App from '@/App.vue'
import store, { useBookStore } from '@/store'

// init pinia instance
createApp(App).use(store)
router.beforeEach((to, from, next) => {
// 自动加载阅读配置
useBookStore()
.loadWebConfig()
.then(() => next())
.catch(() => next())
})

export default router
Loading

0 comments on commit 123d9b4

Please sign in to comment.