-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e3ecbf
commit d4051a4
Showing
35 changed files
with
1,241 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Demo config | ||
VITE_API_URL = '/' | ||
VITE_ENABLE_AD = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# Dev config | ||
VITE_API_URL = '/api' | ||
VITE_API_URL = 'http://localhost:8000' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Dev config | ||
VITE_API_URL = '/api' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// JSON actions | ||
const fetchJSON = (filePath) => { | ||
return fetch(`/__demo__/mock/${filePath}.json`).then((response) => response.json()) | ||
} | ||
// first fetch cache data map | ||
const _cacheData = new Map() | ||
const ensureJSON = async (filePath) => { | ||
if (_cacheData.has(filePath)) { | ||
return _cacheData.get(filePath) | ||
} else { | ||
const data = await fetchJSON(filePath) | ||
_cacheData.set(filePath, data) | ||
return data | ||
} | ||
} | ||
|
||
// mock token | ||
console.info('mock token') | ||
window.localStorage.setItem('id_token', 'veact_admin.mock.token') | ||
|
||
// mock by axios adapter | ||
console.info('mock axios') | ||
window.__axiosAdapter = (config) => { | ||
console.debug('mock request:', config) | ||
// 1. 仅处理所有 Get 请求 | ||
// 2. Auth 相关的必要 Post 请求除外 | ||
// 3. 所有请求返回错误,提示:Demo 站点无法操作数据 | ||
const handlers = { | ||
'/auth/login': { | ||
post: () => ensureJSON('auth/login'), | ||
}, | ||
'/auth/check': { | ||
post: () => ensureJSON('auth/check'), | ||
}, | ||
'/auth/admin': { | ||
get: () => ensureJSON('auth/admin'), | ||
}, | ||
'/expansion/statistic': { | ||
get: () => ensureJSON('expansion/statistic'), | ||
}, | ||
'/expansion/google-token': { | ||
get: () => ensureJSON('expansion/google-token'), | ||
}, | ||
'/expansion/uptoken': { | ||
get: () => ensureJSON('expansion/uptoken'), | ||
}, | ||
'/announcement': { | ||
get: () => ensureJSON('announcement'), | ||
}, | ||
'/category': { | ||
get: () => ensureJSON('category'), | ||
}, | ||
'/tag': { | ||
get: () => ensureJSON('tag'), | ||
}, | ||
'/comment': { | ||
get: () => ensureJSON('comment'), | ||
}, | ||
'/option': { | ||
get: () => ensureJSON('option'), | ||
}, | ||
'/article': { | ||
get: () => ensureJSON('article/list'), | ||
}, | ||
'/article/612c81321a53290533a7b782': { | ||
get: () => ensureJSON('article/612c81321a53290533a7b782'), | ||
}, | ||
'/article/610c29438a907384c63fef00': { | ||
get: () => ensureJSON('article/610c29438a907384c63fef00'), | ||
}, | ||
'/article/61030f5fcf1faa098ee126b2': { | ||
get: () => ensureJSON('article/61030f5fcf1faa098ee126b2'), | ||
}, | ||
} | ||
|
||
return new Promise(async (resolve) => { | ||
const target = handlers?.[config.url]?.[config.method] | ||
if (target) { | ||
return resolve({ | ||
status: 200, | ||
statusText: 'OK', | ||
data: await target(), | ||
}) | ||
} else { | ||
return resolve({ | ||
status: 500, | ||
statusText: 'ERROR', | ||
data: { | ||
status: 'error', | ||
message: '操作失败', | ||
error: 'Demo 站点不支持数据操作', | ||
result: null, | ||
}, | ||
}) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"status": "success", | ||
"message": "获取公告成功", | ||
"result": { | ||
"data": [ | ||
{ | ||
"state": 0, | ||
"_id": "60c2cf0dce41cd0b74cfb001", | ||
"content": "今天天气很好", | ||
"create_at": "2021-07-14T10:04:45.085Z", | ||
"update_at": "2021-07-26T18:38:24.704Z", | ||
"id": 6, | ||
"__v": 0 | ||
}, | ||
{ | ||
"state": 1, | ||
"_id": "60c2cf0dce41cd0b74cfb003", | ||
"content": "今天的饭菜很好吃", | ||
"create_at": "2021-06-11T02:48:45.477Z", | ||
"update_at": "2021-06-11T02:48:45.477Z", | ||
"id": 5, | ||
"__v": 0 | ||
}, | ||
{ | ||
"state": 0, | ||
"_id": "60c2cf0dce41cd0b74cfb002", | ||
"content": "今天不开心", | ||
"create_at": "2021-06-09T15:23:42.855Z", | ||
"update_at": "2021-06-09T15:23:42.855Z", | ||
"id": 4, | ||
"__v": 0 | ||
}, | ||
{ | ||
"state": 0, | ||
"_id": "60c2cf0dce41cd0b74cfb006", | ||
"content": "今天 A 股大跌", | ||
"create_at": "2021-03-03T08:35:51.788Z", | ||
"update_at": "2021-03-03T08:35:51.788Z", | ||
"id": 3, | ||
"__v": 0 | ||
}, | ||
{ | ||
"state": 1, | ||
"_id": "60c2cf0dce41cd0b74cfb007", | ||
"content": "今天抄顶 😢", | ||
"create_at": "2021-02-23T17:15:13.459Z", | ||
"update_at": "2021-02-23T17:15:13.459Z", | ||
"id": 2, | ||
"__v": 0 | ||
}, | ||
{ | ||
"state": 1, | ||
"_id": "60c2cf0dce41cd0b74cfb008", | ||
"content": "Happy new year! 🎉", | ||
"create_at": "2020-12-31T14:21:03.724Z", | ||
"update_at": "2020-12-31T14:21:03.724Z", | ||
"id": 1, | ||
"__v": 0 | ||
} | ||
], | ||
"pagination": { "total": 6, "current_page": 1, "total_page": 1, "per_page": 16 } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
public/__demo__/mock/article/61030f5fcf1faa098ee126b2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"status": "success", | ||
"message": "获取文章详情成功", | ||
"result": { | ||
"password": "", | ||
"keywords": ["旅途日记", "西部之旅"], | ||
"state": 0, | ||
"public": 1, | ||
"origin": 0, | ||
"tag": ["594d2b1251c61940c28c854f", "59b18754c8bfdb5b0c06980b"], | ||
"category": ["589e07c04a4ad562430953d0"], | ||
"_id": "61030f5fcf1faa098ee126b2", | ||
"id": 1, | ||
"title": "旅途感想", | ||
"description": "没有整理好的旅途感想", | ||
"content": "\n旅途的开始,心情是轻松的。\n\n此处省略一万字...\n", | ||
"thumb": "/images/profile/article-thumb.jpg", | ||
"extends": [], | ||
"meta": { "likes": 51, "views": 11672, "comments": 39 }, | ||
"update_at": "2019-07-24T15:53:33.133Z", | ||
"create_at": "2017-05-10T16:17:04.716Z", | ||
"__v": 0 | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
public/__demo__/mock/article/610c29438a907384c63fef00.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"status": "success", | ||
"message": "获取文章详情成功", | ||
"result": { | ||
"password": "", | ||
"keywords": ["每日一记", "上海天气"], | ||
"state": 0, | ||
"public": 1, | ||
"origin": 0, | ||
"tag": ["58c8a3dccc2ca807b19d23cd", "594d2b1251c61940c28c854f"], | ||
"category": ["589e07c04a4ad562430953d0"], | ||
"_id": "610c29438a907384c63fef00", | ||
"id": 2, | ||
"title": "今日日记", | ||
"description": "今天发生的一些事情", | ||
"content": "\n今天上海的天气非常好,万里无云。\n\n此处省略一万字...\n", | ||
"thumb": "/images/profile/article-thumb.jpg", | ||
"extends": [], | ||
"meta": { "likes": 51, "views": 11672, "comments": 39 }, | ||
"update_at": "2019-07-24T15:53:33.133Z", | ||
"create_at": "2017-05-10T16:17:04.716Z", | ||
"__v": 0 | ||
} | ||
} |
Oops, something went wrong.