Skip to content

Commit 9adcc89

Browse files
committed
refactor: update mock response body
1 parent 909c2d9 commit 9adcc89

File tree

7 files changed

+46
-32
lines changed

7 files changed

+46
-32
lines changed

.env.production

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
VITE_APP_PREVIEW=false
2-
VITE_APP_API_BASE_URL=https://api.example.com
2+
VITE_APP_API_BASE_URL=http://easyapi.devv.zone:3012/api

mock/data.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import { defineMockData } from 'vite-plugin-mock-dev-server'
22

33
// defineMockData,用于在 mock 文件中使用 data.ts 作为共享数据源。
44
export default defineMockData('proses', [
5-
{ prose: '🔖 躲在某一时间,想念一段时光的掌纹;躲在某一地点,想念一个站在来路也站在去路的,让我牵挂的人。' },
6-
{ prose: '🔖 天空一碧如洗,灿烂的阳光正从密密的松针的缝隙间射下来,形成一束束粗粗细细的光柱,把飘荡着轻纱般薄雾的林荫照得通亮。' },
7-
{ prose: '🔖 这一次相遇,美得彻骨,美得震颤,美得孤绝,美得惊艳。' },
8-
{ prose: '🔖 沉默的状态,能让我感觉到呼吸的自由和自己原来就处于的本色位置。' },
9-
{ prose: '🔖 青春,是一包象征着阳光的向日葵种子,在现在洒下,就会在未来得到收获,那一株株饱含青春的花朵。' },
10-
{ prose: '🔖 燕子去了,有再来的时候;杨柳枯了,有再青的时候;桃花谢了,有再开的时候。但是,聪明的,你告诉我,我们的日子为什么一去不复返呢?' },
11-
{ prose: '🔖 毕业了,青春在无形之中离去,我们即将翻开人生的另一页。' },
12-
{ prose: '🔖 成长,是每个孩子的权力,也是他们必经的征程,或平坦、或崎岖,有悲欢,有离合。' },
13-
{ prose: '🔖 旧时光里的人和事,琐碎而零乱。我的记忆很模糊,好像大部分都成了一种温馨的符号,静静的沉在我心底。' },
14-
{ prose: '🔖 生活是一部大百科全书,包罗万象;生活是一把六弦琴,弹奏出多重美妙的旋律:生活是一座飞马牌大钟,上紧发条,便会使人获得浓缩的生命。' },
15-
{ prose: '🔖 毕业了,身边的朋友一个个各奔东西,开始学会自己撑起生命的暖色。' },
16-
{ prose: '🔖 已经走到尽头的东西,重生也不过是再一次的消亡。就像所有的开始,其实都只是一个写好了的结局。' },
17-
{ prose: '🔖 下午茶的芬香熏陶着房内的任何一个角落,午后的阳光透过窗帘的间隙洒在木制的桌面上,一份思念随着红茶顺滑至心中。' },
18-
{ prose: '🔖 这里再不是我们的校园,当我们就此离开我们的青葱岁月。' },
19-
{ prose: '🔖 很久找你,一直没有找到,微风吹过的时候,我深深的呼吸,才感觉到你也在陪伴着我呼吸。' },
5+
'🔖 躲在某一时间,想念一段时光的掌纹;躲在某一地点,想念一个站在来路也站在去路的,让我牵挂的人。',
6+
'🔖 天空一碧如洗,灿烂的阳光正从密密的松针的缝隙间射下来,形成一束束粗粗细细的光柱,把飘荡着轻纱般薄雾的林荫照得通亮。',
7+
'🔖 这一次相遇,美得彻骨,美得震颤,美得孤绝,美得惊艳。',
8+
'🔖 沉默的状态,能让我感觉到呼吸的自由和自己原来就处于的本色位置。',
9+
'🔖 青春,是一包象征着阳光的向日葵种子,在现在洒下,就会在未来得到收获,那一株株饱含青春的花朵。',
10+
'🔖 燕子去了,有再来的时候;杨柳枯了,有再青的时候;桃花谢了,有再开的时候。但是,聪明的,你告诉我,我们的日子为什么一去不复返呢?',
11+
'🔖 毕业了,青春在无形之中离去,我们即将翻开人生的另一页。',
12+
'🔖 成长,是每个孩子的权力,也是他们必经的征程,或平坦、或崎岖,有悲欢,有离合。',
13+
'🔖 旧时光里的人和事,琐碎而零乱。我的记忆很模糊,好像大部分都成了一种温馨的符号,静静的沉在我心底。',
14+
'🔖 生活是一部大百科全书,包罗万象;生活是一把六弦琴,弹奏出多重美妙的旋律:生活是一座飞马牌大钟,上紧发条,便会使人获得浓缩的生命。',
15+
'🔖 毕业了,身边的朋友一个个各奔东西,开始学会自己撑起生命的暖色。',
16+
'🔖 已经走到尽头的东西,重生也不过是再一次的消亡。就像所有的开始,其实都只是一个写好了的结局。',
17+
'🔖 下午茶的芬香熏陶着房内的任何一个角落,午后的阳光透过窗帘的间隙洒在木制的桌面上,一份思念随着红茶顺滑至心中。',
18+
'🔖 这里再不是我们的校园,当我们就此离开我们的青葱岁月。',
19+
'🔖 很久找你,一直没有找到,微风吹过的时候,我深深的呼吸,才感觉到你也在陪伴着我呼吸。',
2020
])

mock/modules/prose.mock.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
// https://github.com/pengzhanbo/vite-plugin-mock-dev-server
21
import { defineMock } from 'vite-plugin-mock-dev-server'
2+
import { builder } from '../util'
33
import proses from '../data'
44

55
export default defineMock({
6-
url: '/api/project/prose',
6+
url: '/api/prose',
77
delay: 100,
88
body: () => {
9-
const prose = proses.value[Math.floor(Math.random() * 8)]
10-
return {
11-
code: 0,
12-
data: prose,
13-
msg: 'success',
14-
}
9+
const rand = Math.floor(Math.random() * proses.value.length)
10+
const prose = proses.value[rand]
11+
return builder(prose)
1512
},
1613
})

mock/util.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const responseBody = {
2+
message: '',
3+
timestamp: 0,
4+
result: null as unknown,
5+
code: 0,
6+
}
7+
8+
export function builder(data: unknown, message = 'success', code = 0) {
9+
responseBody.result = data
10+
11+
if (message !== undefined && message !== null)
12+
responseBody.message = message
13+
14+
if (code !== undefined && code !== 0)
15+
responseBody.code = code
16+
17+
responseBody.timestamp = new Date().getTime()
18+
return responseBody
19+
}

src/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import request from '@/utils/request'
22

33
export async function queryProse(): Promise<any> {
4-
return request('/project/prose')
4+
return request('/prose')
55
}

src/components.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable */
2-
/* prettier-ignore */
32
// @ts-nocheck
43
// Generated by unplugin-vue-components
54
// Read more: https://github.com/vuejs/core/pull/3399
65
export {}
76

7+
/* prettier-ignore */
88
declare module 'vue' {
99
export interface GlobalComponents {
1010
AppMobileDetector: typeof import('./components/AppMobileDetector.vue')['default']

src/pages/mock/index.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ definePage({
1313
const messages = ref<string>('')
1414
1515
function pull() {
16-
queryProse().then((res) => {
17-
messages.value = res.data.prose
16+
queryProse().then(({ code, result }) => {
17+
if (code === 0)
18+
messages.value = result
1819
})
1920
}
20-
21-
// reset data
22-
const reset = () => messages.value = ''
2321
</script>
2422

2523
<template>
@@ -41,7 +39,7 @@ const reset = () => messages.value = ''
4139
<var-button type="primary" block @click="pull">
4240
{{ $t('mock.pull') }}
4341
</var-button>
44-
<var-button type="default" block @click="reset">
42+
<var-button type="default" block @click="messages = ''">
4543
{{ $t('mock.reset') }}
4644
</var-button>
4745
</var-space>

0 commit comments

Comments
 (0)