8000 feat(projects): 完成api详情界面数据获取 · lixin59/electron-mock-api@a9ac7ce · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit a9ac7ce

Browse files
committed
feat(projects): 完成api详情界面数据获取
1 parent fc76019 commit a9ac7ce

File tree

2 files changed

+41
-13
lines changed

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,21 @@
1010
>
1111
<n-tab-pane name="signin" tab="编辑">
1212
<n-form>
13-
<n-form-item-row label="用户名">
13+
<n-form-item-row label="接口名称">
1414
<n-input />
1515
</n-form-item-row>
16-
<n-form-item-row label="密码">
16+
<n-form-item-row label="url">
1717
<n-input />
1818
</n-form-item-row>
1919
</n-form>
20-
<n-button type="primary" block secondary strong> 登录 </n-button>
20+
<n-button type="primary" block secondary strong> 接口名称 </n-button>
2121
</n-tab-pane>
22-
<n-tab-pane name="signup" tab="编辑">
22+
<n-tab-pane name="signup" tab="预览">
2323
<n-form>
24-
<n-form-item-row label="用户名">
24+
<n-form-item-row label="接口名称">
2525
<n-input />
2626
</n-form-item-row>
27-
<n-form-item-row label="密码">
28-
<n-input />
29-
</n-form-item-row>
30-
<n-form-item-row label="重复密码">
27+
<n-form-item-row label="url">
3128
<n-input />
3229
</n-form-item-row>
3330
</n-form>
@@ -38,6 +35,33 @@
3835
</template>
3936

4037
<script setup lang="ts">
38+
import { ref, onMounted, watch } from 'vue';
39+
import type { tMockItem, tMockProject } from '~/electron/utils/mock/types';
40+
41+
interface Props {
42+
id: number;
43+
project: tMockProject | null;
44+
}
45+
const props = defineProps<Props>();
46+
47+
const mockData = ref<tMockItem>();
48+
49+
const fetchData = () => {
50+
const { id, project } = props;
51+
const data = project?.mockList.find((m: tMockItem) => m.id === id);
52+
if (data) {
53+
mockData.value = data;
54+
}
55+
};
56+
watch(
57+
() => props.project,
58+
() => {
59+
fetchData();
60+
}
61+
);
62+
onMounted(() => {
63+
fetchData();
64+
});
4165
</script>
4266

4367
<style scoped></style>

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
:mock-list="project?.mockList || []"
3333
:base-url="project?.config?.baseUrl || ''"
3434
/>
35-
<ApiDetail v-else />
35+
<ApiDetail v-else :id="mockId" :project="project" />
3636
</n-layout>
3737
</n-layout>
3838
</n-layout>
@@ -56,15 +56,16 @@ const { routerPush } = useRouterPush();
5656
const route = useRoute();
5757
const id = Number(route.query?.id);
5858
const menuValue = ref('api-list');
59-
// eslint-disable-next-line @typescript-eslint/ban-types
6059
const project = ref<tMockProject | null>(null);
60+
const mockId = ref(0);
6161
6262
const { iconRender } = useIconRender();
6363
6464
const options = computed<any[]>(() => {
6565
const baseItem = {
6666
label: '全部接口',
6767
key: 'api-list',
68+
id: 0,
6869
icon: iconRender({ icon: 'vscode-icons:default-folder-opened' })
6970
};
7071
const list =
@@ -87,8 +88,11 @@ const fetchData = async () => {
8788
const handleToProjects = () => {
8889
routerPush({ name: routeName('mock_projects') });
8990
};
90-
const handleUpdateValue = (key: string) => {
91+
const handleUpdateValue = (key: string, item: any) => {
9192
menuValue.value = key;
93+
if (item.id) {
94+
mockId.value = item.id;
95+
}
9296
};
9397
const handleAddMock = async () => {
9498
try {
@@ -101,7 +105,7 @@ const handleAddMock = async () => {
101105
createdAt: new Date().getTime(),
102106
data: {
103107
code: 200,
104-
msg: 'holle',
108+
msg: 'test',
105109
data: {
106110
'list|1-10': [
107111
{

0 commit comments

Comments
 (0)
0