diff --git a/package-lock.json b/package-lock.json index a330f84..17c9a94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "antd": "^5.27.3", "axios": "^1.12.2", "element-plus": "^2.11.2", + "pinia": "^3.0.3", "vue": "^3.5.18", "vue-router": "^4.5.1" }, @@ -2681,7 +2682,6 @@ "version": "2.5.0", "resolved": "https://registry.npmmirror.com/birpc/-/birpc-2.5.0.tgz", "integrity": "sha512-VSWO/W6nNQdyP520F1mhf+Lc2f8pjGQOtoHHm7Ze8Go1kX7akpVIrtTa0fn+HB0QJEDVacl6aO08YE0PgXfdnQ==", - "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/antfu" @@ -2938,7 +2938,6 @@ "version": "3.0.5", "resolved": "https://registry.npmmirror.com/copy-anything/-/copy-anything-3.0.5.tgz", "integrity": "sha512-yCEafptTtb4bk7GLEQoM8KVJpxAfdBJYaXyzQEgQQQgYrZiDp8SJmGKlYza6CYjEDNstAdNdKA3UuoULlEbS6w==", - "dev": true, "license": "MIT", "dependencies": { "is-what": "^4.1.8" @@ -3693,7 +3692,6 @@ "version": "5.5.3", "resolved": "https://registry.npmmirror.com/hookable/-/hookable-5.5.3.tgz", "integrity": "sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ==", - "dev": true, "license": "MIT" }, "node_modules/html-encoding-sniffer": { @@ -3917,7 +3915,6 @@ "version": "4.1.16", "resolved": "https://registry.npmmirror.com/is-what/-/is-what-4.1.16.tgz", "integrity": "sha512-ZhMwEosbFJkA0YhFnNDgTM4ZxDRsS6HqTo7qsZM08fehyRYIYa0yHu5R6mgo1n/8MgaPBXiPimPD77baVFYg+A==", - "dev": true, "license": "MIT", "engines": { "node": ">=12.13" @@ -4227,7 +4224,6 @@ "version": "3.0.1", "resolved": "https://registry.npmmirror.com/mitt/-/mitt-3.0.1.tgz", "integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==", - "dev": true, "license": "MIT" }, "node_modules/mlly": { @@ -4486,7 +4482,6 @@ "version": "1.0.0", "resolved": "https://registry.npmmirror.com/perfect-debounce/-/perfect-debounce-1.0.0.tgz", "integrity": "sha512-xCy9V055GLEqoFaHoC1SoLIaLmWctgCUaBaWxDZ7/Zx4CTyX7cJQLJOok/orfjZAh9kEYpjJa4d0KcJmCbctZA==", - "dev": true, "license": "MIT" }, "node_modules/picocolors": { @@ -4508,6 +4503,60 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/pinia": { + "version": "3.0.3", + "resolved": "https://registry.npmmirror.com/pinia/-/pinia-3.0.3.tgz", + "integrity": "sha512-ttXO/InUULUXkMHpTdp9Fj4hLpD/2AoJdmAbAeW2yu1iy1k+pkFekQXw5VpC0/5p51IOR/jDaDRfRWRnMMsGOA==", + "license": "MIT", + "dependencies": { + "@vue/devtools-api": "^7.7.2" + }, + "funding": { + "url": "https://github.com/sponsors/posva" + }, + "peerDependencies": { + "typescript": ">=4.4.4", + "vue": "^2.7.0 || ^3.5.11" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/pinia/node_modules/@vue/devtools-api": { + "version": "7.7.7", + "resolved": "https://registry.npmmirror.com/@vue/devtools-api/-/devtools-api-7.7.7.tgz", + "integrity": "sha512-lwOnNBH2e7x1fIIbVT7yF5D+YWhqELm55/4ZKf45R9T8r9dE2AIOy8HKjfqzGsoTHFbWbr337O4E0A0QADnjBg==", + "license": "MIT", + "dependencies": { + "@vue/devtools-kit": "^7.7.7" + } + }, + "node_modules/pinia/node_modules/@vue/devtools-kit": { + "version": "7.7.7", + "resolved": "https://registry.npmmirror.com/@vue/devtools-kit/-/devtools-kit-7.7.7.tgz", + "integrity": "sha512-wgoZtxcTta65cnZ1Q6MbAfePVFxfM+gq0saaeytoph7nEa7yMXoi6sCPy4ufO111B9msnw0VOWjPEFCXuAKRHA==", + "license": "MIT", + "dependencies": { + "@vue/devtools-shared": "^7.7.7", + "birpc": "^2.3.0", + "hookable": "^5.5.3", + "mitt": "^3.0.1", + "perfect-debounce": "^1.0.0", + "speakingurl": "^14.0.1", + "superjson": "^2.2.2" + } + }, + "node_modules/pinia/node_modules/@vue/devtools-shared": { + "version": "7.7.7", + "resolved": "https://registry.npmmirror.com/@vue/devtools-shared/-/devtools-shared-7.7.7.tgz", + "integrity": "sha512-+udSj47aRl5aKb0memBvcUG9koarqnxNM5yjuREvqwK6T3ap4mn3Zqqc17QrBFTqSMjr3HK1cvStEZpMDpfdyw==", + "license": "MIT", + "dependencies": { + "rfdc": "^1.4.1" + } + }, "node_modules/pkg-types": { "version": "2.3.0", "resolved": "https://registry.npmmirror.com/pkg-types/-/pkg-types-2.3.0.tgz", @@ -5275,7 +5324,6 @@ "version": "1.4.1", "resolved": "https://registry.npmmirror.com/rfdc/-/rfdc-1.4.1.tgz", "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==", - "dev": true, "license": "MIT" }, "node_modules/rollup": { @@ -5472,7 +5520,6 @@ "version": "14.0.1", "resolved": "https://registry.npmmirror.com/speakingurl/-/speakingurl-14.0.1.tgz", "integrity": "sha512-1POYv7uv2gXoyGFpBCmpDVSNV74IfsWlDW216UPjbWufNf+bSU6GdbDsxdcxtfwb4xlI3yxzOTKClUosxARYrQ==", - "dev": true, "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" @@ -5645,7 +5692,6 @@ "version": "2.2.2", "resolved": "https://registry.npmmirror.com/superjson/-/superjson-2.2.2.tgz", "integrity": "sha512-5JRxVqC8I8NuOUjzBbvVJAKNM8qoVuH0O77h4WInc/qC2q5IreqKxYwgkga3PfA22OayK2ikceb/B26dztPl+Q==", - "dev": true, "license": "MIT", "dependencies": { "copy-anything": "^3.0.2" diff --git a/package.json b/package.json index 1067cf0..18ea265 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "antd": "^5.27.3", "axios": "^1.12.2", "element-plus": "^2.11.2", + "pinia": "^3.0.3", "vue": "^3.5.18", "vue-router": "^4.5.1" }, diff --git a/src/components/LeftModule.vue b/src/components/LeftModule.vue index c57dce4..9e84d89 100644 --- a/src/components/LeftModule.vue +++ b/src/components/LeftModule.vue @@ -15,7 +15,7 @@
从全局store获取的数据: {{ globalStore.getValue('exampleData') }}
+全局数据尚未设置
+{{ formatContentPreview(item.content, 150) }}
@@ -42,7 +41,9 @@ import { articleService } from '@/services' import { formatDate, formatRelativeTime } from '@/utils/dateUtils' import { formatContentPreview } from '@/utils/stringUtils' import { ElMessage } from 'element-plus' +import { useGlobalStore } from '@/store/globalStore' +const globalStore = useGlobalStore() // 路由实例 const router = useRouter() const route = useRoute() @@ -58,38 +59,33 @@ const loading = ref(false) * 获取文章列表 */ const fetchArticles = async () => { - try { + try { loading.value = true let res = {} // 使用let而不是const // 检查URL参数 - const query = route.query - const params = route.params + const localhome = route.path.split('/')[2]; // 优先使用attributeId参数(新接口) - if (query.attributeId) { - console.log('根据属性ID获取文章列表') - res = await articleService.getArticlesByAttribute(query.attributeId) - } - // 兼容旧的type参数 - else if (params.type) { - console.log('根据类型ID获取文章列表(兼容模式)') - res = await articleService.getArticlesByCategory(params.type) + if (localhome==='aericletype') { + const data = globalStore.getValue('attribute') + res = await articleService.getArticlesByAttributeId(data.id) } // 搜索标题 - else if (params.title || query.title) { - const title = params.title || query.title - console.log('根据标题获取文章列表') - res = await articleService.getArticlesByTitle(title) + else if (localhome==='aericletitle') { + const data = globalStore.getValue('title') + res = await articleService.getArticlesByTitle(data.title) } // 获取所有文章 else { - res = await articleService.getAllArticles() console.log('获取所有文章列表') + res = await articleService.getAllArticles() } + // 修复:使用正确的属性名data而不是date + console.log('获取文章列表成功:', res.data) datas.value = res.data || [] - console.log('获取文章列表成功:', datas.value) + console.log('文章数据已赋值:', datas.value) } catch (error) { console.error('获取文章列表失败:', error) ElMessage.error('获取文章列表失败,请稍后重试')