Skip to content

Commit c4a10e2

Browse files
committed
fix(projects): 修复切换接口详情的时候响应数据编辑框内容没有更改的问题
1 parent c607d42 commit c4a10e2

6 files changed

Lines changed: 57 additions & 18 deletions

File tree

.github/ISSUE_TEMPLATE/bug-report.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Bug提交
22
description: 在使用软件或功能的过程中遇到了错误
33
title: '[Bug]: '
4-
labels: [ "bug?" ]
4+
labels: [bug?]
55

66
body:
77
- type: markdown

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ${{ matrix.os }}
1414
strategy:
1515
matrix:
16-
os: [ windows-latest, ubuntu-latest ]
16+
os: [windows-latest, ubuntu-latest]
1717
steps:
1818
- uses: actions/checkout@v3
1919
with:
@@ -66,7 +66,7 @@ jobs:
6666
uses: softprops/action-gh-release@v1
6767
if: startsWith(github.ref, 'refs/tags/')
6868
with:
69-
files: "release/**"
69+
files: 'release/**'
7070
env:
7171
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7272

src/store/modules/mock-project/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,19 @@ export const useProjectStore = defineStore('mock-project', () => {
4949

5050
const editMock = async (pid: number, id: number, mock: tMockItem) => {
5151
try {
52-
await removeMock(pid, id);
53-
await addMock(pid, mock);
54-
return { code: 200 };
52+
const project = projectList.value?.find(p => p?.config?.id === pid);
53+
if (!project) {
54+
return { code: 0, data: [], msg: '没有找到该项目' };
55+
}
56+
const mockList = project.mockList?.map(m => {
57+
if (m.id === id) {
58+
return mock;
59+
}
60+
return m;
61+
});
62+
project.mockList = mockList;
63+
const res: { code: number; data: tMockProject[] } = await updateServer();
64+
return { ...res, msg: '保存成功' };
5565
} catch (e: any) {
5666
return { code: 0, msg: e };
5767
}

src/views/mock/api-detail/index.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<n-divider title-placement="left"> 请求参数 </n-divider>
7070
<n-space :vertical="true"> 开发中敬请期待 </n-space>
7171
<n-divider title-placement="left"> 响应数据 </n-divider>
72-
<n-code :code="resData" language="json" />
72+
<n-code :code="resData" language="json" word-wrap />
7373
</n-tab-pane>
7474
</n-tabs>
7575
</n-card>
@@ -165,7 +165,7 @@ const saveData = async (e: any) => {
165165
window.$message?.error(data.msg);
166166
return;
167167
}
168-
window.$message?.success('验证成功');
168+
window.$message?.success('保存成功');
169169
} else {
170170
window.$message?.error('Invalid');
171171
}
@@ -195,6 +195,7 @@ const fetchData = () => {
195195
if (data) {
196196
mockData.value = data;
197197
}
198+
resData.value = '';
198199
};
199200
watch(
200201
() => props.id,

src/views/mock/api-list/index.vue

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<template>
2-
<n-card title="接口数据" class="h-full shadow-sm rounded-16px">
2+
<n-card title="接口数据" class="h-full shadow-sm">
33
<n-space :vertical="true">
4-
<loading-empty-wrapper class="h-480px" :loading="loading" :empty="empty">
5-
<n-data-table :columns="columns" :data="mockList" :flex-height="true" class="h-480px" />
4+
<loading-empty-wrapper class="h-500px" :loading="loading" :empty="empty">
5+
<n-data-table :columns="columns" :data="mockList" :flex-height="true" class="h-500px" />
66
</loading-empty-wrapper>
77
</n-space>
88
</n-card>
99
</template>
1010

1111
<script setup lang="tsx">
1212
import { watch } from 'vue';
13-
import { NSpace, NTag, NPopconfirm, NButton } from 'naive-ui';
13+
import { NSpace, NTag, NPopconfirm, NButton, NTime } from 'naive-ui';
1414
import type { DataTableColumn } from 'naive-ui';
1515
import { useProjectStore } from '@/store';
1616
import { useLoadingEmpty } from '@/hooks';
@@ -71,6 +71,7 @@ const columns: DataTableColumn<tMockItem>[] = [
7171
{
7272
title: '接口路径',
7373
key: 'method',
74+
minWidth: 400,
7475
align: 'center',
7576
render: row => {
7677
return (
@@ -81,8 +82,33 @@ const columns: DataTableColumn<tMockItem>[] = [
8182
);
8283
}
8384
},
85+
{
86+
title: '创建时间',
87+
key: 'createdAt',
88+
align: 'center',
89+
render: row => {
90+
return (
91+
<NSpace justify={'center'}>
92+
<NTime time={row.createdAt} />
93+
</NSpace>
94+
);
95+
}
96+
},
97+
{
98+
title: '最后更新时间',
99+
key: 'lastUpdateAt',
100+
align: 'center',
101+
render: row => {
102+
return (
103+
<NSpace justify={'center'}>
104+
<NTime time={row.lastUpdateAt} />
105+
</NSpace>
106+
);
107+
}
108+
},
84109
{
85110
title: '状态',
111+
width: 100,
86112
key: 'enable',
87113
align: 'center',
88114
render: row => {
@@ -96,14 +122,16 @@ const columns: DataTableColumn<tMockItem>[] = [
96122
{
97123
title: '延时',
98124
key: 'timeout',
125+
width: 100,
99126
align: 'center',
100127
render: row => {
101-
return row.timeout;
128+
return `${row.timeout}ms`;
102129
}
103130
},
104131
{
105132
key: 'action',
106-
title: 'Action',
133+
title: '操作',
134+
width: 80,
107135
align: 'center',
108136
render: row => {
109137
return (

src/views/mock/project-detail/index.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
:mock-list="project?.mockList || []"
3333
:base-url="project?.config?.baseUrl || ''"
3434
/>
35-
<ApiDetail v-else :id="mockId" :project="project" />
35+
<template v-for="item in project?.mockList">
36+
<ApiDetail v-if="item.id === mockId" :id="mockId" :key="item.id" :project="project" />
37+
</template>
3638
</n-layout>
3739
</n-layout>
3840
</n-layout>
@@ -90,9 +92,7 @@ const handleToProjects = () => {
9092
};
9193
const handleUpdateValue = (key: string, item: any) => {
9294
menuValue.value = key;
93-
if (item.id) {
94-
mockId.value = item.id;
95-
}
95+
mockId.value = item.id;
9696
};
9797
const handleAddMock = async () => {
9898
try {

0 commit comments

Comments
 (0)