购买后即可阅读完整内容
+ +diff --git a/frontend/wechat/src/api/client.js b/frontend/wechat/src/api/client.js
new file mode 100644
index 0000000..adbb79f
--- /dev/null
+++ b/frontend/wechat/src/api/client.js
@@ -0,0 +1,48 @@
+import { useAuthStore } from '@/stores/auth';
+import axios from 'axios';
+
+// Create axios instance with default config
+const client = axios.create({
+ baseURL: '/v1',
+ timeout: 10000,
+ headers: {
+ 'Content-Type': 'application/json',
+ }
+});
+
+// Request interceptor
+client.interceptors.request.use(
+ config => {
+ const authStore = useAuthStore();
+ if (authStore.isAuthenticated && authStore.token) {
+ config.headers.Authorization = `Bearer ${authStore.token}`;
+ }
+ return config;
+ },
+ error => {
+ return Promise.reject(error);
+ }
+);
+
+// Response interceptor
+client.interceptors.response.use(
+ response => {
+ return response
+ },
+ error => {
+ // Handle HTTP errors here
+ if (error.response) {
+ // Server responded with error status
+ console.error('API Error:', error.response.status, error.response.data);
+ } else if (error.request) {
+ // Request made but no response received
+ console.error('API Error: No response received', error.request);
+ } else {
+ // Something else happened
+ console.error('API Error:', error.message);
+ }
+ return Promise.reject(error);
+ }
+);
+
+export default client;
diff --git a/frontend/wechat/src/api/postApi.js b/frontend/wechat/src/api/postApi.js
new file mode 100644
index 0000000..3b584b2
--- /dev/null
+++ b/frontend/wechat/src/api/postApi.js
@@ -0,0 +1,27 @@
+import client from './client';
+
+export const postApi = {
+ list({ page = 1, limit = 10, keyword = '' } = {}) {
+ return client.get('/api/posts', {
+ params: {
+ page,
+ limit,
+ keyword: keyword.trim()
+ }
+ });
+ },
+ show(id) {
+ return client.get(`/api/posts/${id}`);
+ },
+ mine({ page = 1, limit = 10 } = {}) {
+ return client.get('/api/posts/mine', {
+ params: {
+ page,
+ limit
+ }
+ });
+ },
+ buy(id) {
+ return client.post(`/api/posts/buy/${id}`);
+ }
+}
\ No newline at end of file
diff --git a/frontend/wechat/src/stores/article.js b/frontend/wechat/src/stores/article.js
deleted file mode 100644
index 679ad9d..0000000
--- a/frontend/wechat/src/stores/article.js
+++ /dev/null
@@ -1,36 +0,0 @@
-import { defineStore } from 'pinia'
-
-export const useArticleStore = defineStore('article', {
- state: () => ({
- articles: [],
- page: 1,
- loading: false,
- hasMore: true,
- searchQuery: ''
- }),
-
- actions: {
- async fetchArticles() {
- if (this.loading || !this.hasMore) return
- this.loading = true
- try {
- const response = await fetch(`/api/posts?page=${this.page}&q=${this.searchQuery}`)
- const data = await response.json()
- const items = data.items || []
- this.articles = [...this.articles, ...items]
- this.hasMore = items.length > 0 // 只有当返回的列表为空时,才设置 hasMore 为 false
- this.page++
- } finally {
- this.loading = false
- }
- },
-
- setSearchQuery(query) {
- this.searchQuery = query
- this.articles = []
- this.page = 1
- this.hasMore = true
- this.fetchArticles()
- }
- }
-})
diff --git a/frontend/wechat/src/stores/article_list.json b/frontend/wechat/src/stores/article_list.json
deleted file mode 100644
index e135c57..0000000
--- a/frontend/wechat/src/stores/article_list.json
+++ /dev/null
@@ -1,297 +0,0 @@
-{
- "page": 7,
- "limit": 10,
- "total": 100,
- "items": [
- {
- "id": 40,
- "created_at": "2025-04-11T15:03:25.666419Z",
- "updated_at": "2025-04-11T15:03:25.666419Z",
- "deleted_at": null,
- "status": 1,
- "title": "test-title-39",
- "description": "test-description-39",
- "content": "test-content-39",
- "price": 6747,
- "discount": 98,
- "views": 8091,
- "likes": 9914,
- "tags": [
- "tag1",
- "tag2",
- "tag3"
- ],
- "assets": [
- {
- "type": "audio",
- "media": 8143
- },
- {
- "type": "video",
- "media": 2977
- }
- ]
- },
- {
- "id": 39,
- "created_at": "2025-04-11T15:03:25.661237Z",
- "updated_at": "2025-04-11T15:03:25.661237Z",
- "deleted_at": null,
- "status": 1,
- "title": "test-title-38",
- "description": "test-description-38",
- "content": "test-content-38",
- "price": 2891,
- "discount": 45,
- "views": 4462,
- "likes": 6110,
- "tags": [
- "tag1",
- "tag2",
- "tag3"
- ],
- "assets": [
- {
- "type": "audio",
- "media": 5431
- },
- {
- "type": "video",
- "media": 3866
- }
- ]
- },
- {
- "id": 38,
- "created_at": "2025-04-11T15:03:25.657112Z",
- "updated_at": "2025-04-11T15:03:25.657112Z",
- "deleted_at": null,
- "status": 1,
- "title": "test-title-37",
- "description": "test-description-37",
- "content": "test-content-37",
- "price": 904,
- "discount": 70,
- "views": 8988,
- "likes": 816,
- "tags": [
- "tag1",
- "tag2",
- "tag3"
- ],
- "assets": [
- {
- "type": "audio",
- "media": 3307
- },
- {
- "type": "video",
- "media": 2933
- }
- ]
- },
- {
- "id": 37,
- "created_at": "2025-04-11T15:03:25.65266Z",
- "updated_at": "2025-04-11T15:03:25.65266Z",
- "deleted_at": null,
- "status": 1,
- "title": "test-title-36",
- "description": "test-description-36",
- "content": "test-content-36",
- "price": 4476,
- "discount": 45,
- "views": 9910,
- "likes": 9295,
- "tags": [
- "tag1",
- "tag2",
- "tag3"
- ],
- "assets": [
- {
- "type": "audio",
- "media": 3472
- },
- {
- "type": "video",
- "media": 3283
- }
- ]
- },
- {
- "id": 36,
- "created_at": "2025-04-11T15:03:25.644946Z",
- "updated_at": "2025-04-11T15:03:25.644946Z",
- "deleted_at": null,
- "status": 1,
- "title": "test-title-35",
- "description": "test-description-35",
- "content": "test-content-35",
- "price": 7397,
- "discount": 56,
- "views": 2486,
- "likes": 673,
- "tags": [
- "tag1",
- "tag2",
- "tag3"
- ],
- "assets": [
- {
- "type": "audio",
- "media": 1183
- },
- {
- "type": "video",
- "media": 9735
- }
- ]
- },
- {
- "id": 35,
- "created_at": "2025-04-11T15:03:25.640256Z",
- "updated_at": "2025-04-11T15:03:25.640256Z",
- "deleted_at": null,
- "status": 1,
- "title": "test-title-34",
- "description": "test-description-34",
- "content": "test-content-34",
- "price": 3733,
- "discount": 15,
- "views": 3705,
- "likes": 1863,
- "tags": [
- "tag1",
- "tag2",
- "tag3"
- ],
- "assets": [
- {
- "type": "audio",
- "media": 8713
- },
- {
- "type": "video",
- "media": 9442
- }
- ]
- },
- {
- "id": 34,
- "created_at": "2025-04-11T15:03:25.634088Z",
- "updated_at": "2025-04-11T15:03:25.634088Z",
- "deleted_at": null,
- "status": 1,
- "title": "test-title-33",
- "description": "test-description-33",
- "content": "test-content-33",
- "price": 6591,
- "discount": 12,
- "views": 3834,
- "likes": 7400,
- "tags": [
- "tag1",
- "tag2",
- "tag3"
- ],
- "assets": [
- {
- "type": "audio",
- "media": 7429
- },
- {
- "type": "video",
- "media": 9401
- }
- ]
- },
- {
- "id": 33,
- "created_at": "2025-04-11T15:03:25.628572Z",
- "updated_at": "2025-04-11T15:03:25.628572Z",
- "deleted_at": null,
- "status": 1,
- "title": "test-title-32",
- "description": "test-description-32",
- "content": "test-content-32",
- "price": 3740,
- "discount": 92,
- "views": 7324,
- "likes": 3705,
- "tags": [
- "tag1",
- "tag2",
- "tag3"
- ],
- "assets": [
- {
- "type": "audio",
- "media": 8942
- },
- {
- "type": "video",
- "media": 2618
- }
- ]
- },
- {
- "id": 32,
- "created_at": "2025-04-11T15:03:25.623885Z",
- "updated_at": "2025-04-11T15:03:25.623885Z",
- "deleted_at": null,
- "status": 1,
- "title": "test-title-31",
- "description": "test-description-31",
- "content": "test-content-31",
- "price": 1839,
- "discount": 37,
- "views": 4750,
- "likes": 2995,
- "tags": [
- "tag1",
- "tag2",
- "tag3"
- ],
- "assets": [
- {
- "type": "audio",
- "media": 7409
- },
- {
- "type": "video",
- "media": 8843
- }
- ]
- },
- {
- "id": 31,
- "created_at": "2025-04-11T15:03:25.61745Z",
- "updated_at": "2025-04-11T15:03:25.61745Z",
- "deleted_at": null,
- "status": 1,
- "title": "test-title-30",
- "description": "test-description-30",
- "content": "test-content-30",
- "price": 2297,
- "discount": 56,
- "views": 715,
- "likes": 1224,
- "tags": [
- "tag1",
- "tag2",
- "tag3"
- ],
- "assets": [
- {
- "type": "audio",
- "media": 9268
- },
- {
- "type": "video",
- "media": 4416
- }
- ]
- }
- ]
-}
\ No newline at end of file
diff --git a/frontend/wechat/src/views/ArticleDetail.vue b/frontend/wechat/src/views/ArticleDetail.vue
index dae51f0..eaafdba 100644
--- a/frontend/wechat/src/views/ArticleDetail.vue
+++ b/frontend/wechat/src/views/ArticleDetail.vue
@@ -1,15 +1,54 @@
@@ -18,10 +57,7 @@ onMounted(async () => {
购买后即可阅读完整内容{{ article?.title || '文章详情' }}