Skip to content

Commit

Permalink
fix: 与 pinia 的逻辑解耦 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilfish authored Aug 30, 2023
1 parent 51cc49c commit 00c2966
Show file tree
Hide file tree
Showing 33 changed files with 497 additions and 596 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "weibo-archiver",
"version": "0.1.7",
"version": "0.1.8",
"private": true,
"packageManager": "[email protected]",
"description": "weibo-backup",
Expand All @@ -9,6 +9,7 @@
"scripts": {
"build:preview": "pnpm -F preview build",
"build:monkey": "pnpm -F monkey build",
"build:core": "pnpm -F core build",
"dev:preview": "pnpm -F preview dev",
"dev:monkey": "pnpm -F monkey dev",
"preview": "pnpm -F preview preview",
Expand All @@ -23,13 +24,18 @@
},
"devDependencies": {
"@antfu/eslint-config": "^0.41.0",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.3",
"@types/node": "^20.5.7",
"@vitejs/plugin-vue": "^4.3.4",
"eslint": "^8.48.0",
"lint-staged": "^14.0.1",
"pnpm": "^8.7.0",
"rollup": "^3.28.1",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-dts": "^6.0.0",
"simple-git-hooks": "^2.9.0",
"taze": "^0.11.2",
"typescript": "^5.2.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@weibo-archiver/components",
"version": "0.1.7",
"version": "0.1.8",
"description": "",
"author": "",
"license": "ISC",
Expand Down
21 changes: 13 additions & 8 deletions packages/components/src/Ctrl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import PreviewVue from './Preview.vue'
const id = document.URL.match(/\/(\d+)/)?.[1] || ''
const name = document.URL.match(/\/n\/(.+)/)?.[1] || ''
await fetchUser(id, name)
const userData = await fetchUser(id, name)
useUserStore().set(userData.id, userData.name)
const postStore = usePostStore()
Expand Down Expand Up @@ -40,22 +41,22 @@ async function start() {
if (isFetchAll.value) {
isStart.value = true
await fetchAll(isStop)
await postStore.fetchAll(isStop)
return (isFinish.value = true)
}
const [start, end] = dateRange.value
isStart.value = true
await fetchRange(start, end, isStop)
await postStore.fetchRange(start, end, isStop)
isFinish.value = true
}
watch(isStop, async () => {
const [start, end] = dateRange.value
if (!isStop.value) {
isFetchAll.value
? await fetchAll(isStop)
: await fetchRange(start, end, isStop)
? await postStore.fetchAll(isStop)
: await postStore.fetchRange(start, end, isStop)
isFinish.value = true
}
})
Expand All @@ -66,13 +67,14 @@ watch(isStop, async () => {
class="fixed right-4 top-20 z-9999 w-32rem flex flex-col select-none justify-center gap-4 rounded-2 bg-white p-4 text-black shadow-xl"
>
<h2 class="text-5 font-bold">
Weibo archiver, user: {{ useUserStore().name }}
Weibo archiver, user: {{ userData.name }}
</h2>

<el-alert title="爬取过程中请勿刷新或关闭,否则导致已有的数据丢失而不得不重头来过" type="warning" />

<p>请选择要存档的范围,默认为从头到尾</p>

<!-- @ts-expect-error -->
<!-- @vue-expect-error -->
<el-date-picker
v-model="dateRange"
Expand All @@ -89,11 +91,14 @@ watch(isStop, async () => {
{{ isFinish ? '重新开始' : '开始' }}
</button>

<button v-show="!isFinish && isStart" @click="isStop = !isStop">
<button v-show="isStart" @click="isStop = !isStop">
{{ isStop ? '继续' : '暂停' }}
</button>

<button v-show="isFinish" @click="exportData()">
<button
v-show="isFinish"
@click="exportData(postStore.posts, userData.id)"
>
导出
</button>
</div>
Expand Down
5 changes: 2 additions & 3 deletions packages/components/src/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ defineEmits({
const postStore = usePostStore()
const curPage = ref(props.page || postStore.curPage)
const posts = computed(() => postStore.get())
const isFinish = ref(true)
watch(curPage, (newPage) => {
postStore.curPage = newPage
Expand Down Expand Up @@ -47,14 +46,14 @@ watch(curPage, (newPage) => {
>
<div class="btns mb-4 flex justify-center gap-4">
<button
:disabled="curPage === 1 || !postStore.fetchedPage || !isFinish"
:disabled="curPage === 1 || !postStore.fetchedPage"
@click="curPage--"
>
上一页
</button>

<button
:disabled="curPage === postStore.pages || !postStore.fetchedPage || !isFinish"
:disabled="curPage === postStore.pages || !postStore.fetchedPage || curPage === postStore.fetchedPage"
@click="curPage++"
>
下一页
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/Profile.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { User } from '@core/types'
import type { User } from '@weibo-archiver/core'
defineProps<{
user: User
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/post/Action.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { Post } from '@core/types'
import type { Post } from '@weibo-archiver/core'
defineProps<{
post: Post
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/post/Card.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { CardInfo } from '@core/types'
import type { CardInfo } from '@weibo-archiver/core'
defineProps<{
card: CardInfo
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/post/Comments.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { Comment } from '@core/types'
import type { Comment } from '@weibo-archiver/core'
defineProps<{
comments: Comment[]
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/post/Item.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { Post } from '@core/types'
import type { Post } from '@weibo-archiver/core'
defineProps<{
post: Post
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/post/List.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { Post } from '@core/types'
import type { Post } from '@weibo-archiver/core'
defineProps<{
posts: Post[]
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/post/Meta.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { Meta } from '@core/types'
import type { Meta } from '@weibo-archiver/core'
const props = defineProps<{
meta: Meta
Expand Down
10 changes: 5 additions & 5 deletions packages/components/src/post/Retweeted.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<script setup lang="ts">
import type { CardInfo, Post } from '@core/types'
import type { CardInfo, Retweet } from '@weibo-archiver/core'
defineProps<{
post: Post
post: Retweet
card?: CardInfo
}>()
</script>

<template>
<article class="mt-4 flex flex-col gap-2 rounded-2 bg-light p-3 dark:bg-dark">
<profile v-if="post.user.id" :user="post.user" />
<profile v-if="post.user" :user="post.user" />
<main>
<post-text
:text="post.text"
:class="post.user.id ? '' : 'text-red-7!'"
:class="post.user ? '' : 'text-red-7!'"
/>
<gallery :imgs="post.imgs" />
<post-card v-if="card" :card="card" />
</main>
<div
v-if="post.user.id"
v-if="post.user"
class="flex justify-between text-gray"
>
<post-meta :meta="post" />
Expand Down
5 changes: 4 additions & 1 deletion packages/components/src/ui/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ const searchInput = ref(useRoute().query?.q?.toString() || '')
const router = useRouter()
async function search() {
const res = await useSearch(searchInput.value)
const res = await usePostStore().searchText(searchInput.value)
if (res.length)
router.push(`/s?q=${searchInput.value}`)
}
const isDark = useDark()
const toggleDark = useToggle(isDark)
</script>

<template>
Expand Down
4 changes: 2 additions & 2 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './src/composables'
export * from './src/stores'
export * from './src/types'
export * from './src/utils'
export * from './src/default'
export * from './src/types'
14 changes: 6 additions & 8 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
{
"name": "@weibo-archiver/core",
"version": "0.1.7",
"version": "0.1.8",
"description": "",
"author": "",
"author": "Chilfish",
"license": "ISC",
"keywords": [],
"main": "index.ts",
"scripts": {
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"pinia": "^2.1.6"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.3.3",
"jsdom": "^22.1.0",
"jszip": "^3.10.1",
"unocss": "^0.55.2",
"vite": "^4.4.9",
"vue-tsc": "^1.8.8"
"jszip": "^3.10.1"
}
}
39 changes: 39 additions & 0 deletions packages/core/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import path from 'node:path'
import { defineConfig } from 'rollup'
import { dts } from 'rollup-plugin-dts'
import typescript from '@rollup/plugin-typescript'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import terser from '@rollup/plugin-terser'

const dist = path.resolve(__dirname, '../../dist/core')

export default defineConfig([
{
input: 'index.ts',
output: {
file: `${dist}/core.js`,
format: 'esm',
plugins: [terser()],
},
plugins: [
typescript({
tsconfig: './tsconfig.json',
}),
resolve(),
commonjs(),
],
},
{
input: 'index.ts',
plugins: [
dts({
tsconfig: './tsconfig.json',
}),
],
output: {
file: `${dist}/core.d.ts`,
format: 'esm',
},
},
])
2 changes: 0 additions & 2 deletions packages/core/src/composables/dark.ts

This file was deleted.

Loading

0 comments on commit 00c2966

Please sign in to comment.