Skip to content

Commit 62a46c3

Browse files
committed
support loading mock config from local file
1 parent 97459fb commit 62a46c3

File tree

13 files changed

+1671
-1387
lines changed

13 files changed

+1671
-1387
lines changed

console/atest-ui/src/views/MockManager.vue

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { ref, watch } from 'vue';
33
import { Codemirror } from 'vue-codemirror';
4+
import { ElMessage } from 'element-plus'
45
import yaml from 'js-yaml';
56
import { jsonSchema } from "codemirror-json-schema";
67
import { NewTemplateLangComplete, NewHeaderLangComplete } from './languageComplete'
@@ -34,6 +35,10 @@ interface MockConfig {
3435
ConfigAsJSON: string
3536
Prefix: string
3637
Port: number
38+
storeKind: string
39+
storeLocalFile?: string
40+
storeURL?: string
41+
storeRemote?: string
3742
}
3843
3944
const tabActive = ref('yaml')
@@ -64,10 +69,18 @@ function jsonToYaml(jsonData: object | string): string {
6469
}
6570
6671
const link = ref('')
67-
API.GetMockConfig((d) => {
68-
mockConfig.value = d
69-
link.value = `http://${window.location.hostname}:${d.Port}${d.Prefix}/api.json`
70-
})
72+
const loadConfig = () => {
73+
API.GetMockConfig((d) => {
74+
ElMessage({
75+
showClose: true,
76+
message: 'Config loaded!',
77+
type: 'success'
78+
});
79+
mockConfig.value = d
80+
link.value = `http://${window.location.hostname}:${d.Port}${d.Prefix}/api.json`
81+
})
82+
}
83+
loadConfig()
7184
const prefixChanged = (p: string) => {
7285
mockConfig.value.Prefix = p
7386
}
@@ -96,13 +109,23 @@ items:
96109
<template>
97110
<div>
98111
<el-button type="primary" @click="insertSample">{{t('button.insertSample')}}</el-button>
99-
<el-button type="warning" @click="API.ReloadMockServer(mockConfig)">{{t('button.reload')}}</el-button>
112+
<el-button type="warning" @click="API.ReloadMockServer(mockConfig).then(() => loadConfig())">{{t('button.reload')}}</el-button>
100113
<el-divider direction="vertical" />
101114
<el-link target="_blank" :href="link">{{ link }}</el-link> <!-- Noncompliant -->
102115
</div>
103116
<div class="config">
104117
API Prefix:<EditButton :value="mockConfig.Prefix" @changed="prefixChanged"/>
105118
Port:<EditButton :value="mockConfig.Port" @changed="portChanged"/>
119+
Store:
120+
<el-select v-model="mockConfig.storeKind" placeholder="Select Store Kind">
121+
<el-option label="Memory" value="memory"></el-option>
122+
<el-option label="Local File" value="localFile"></el-option>
123+
<el-option label="Remote" value="remote"></el-option>
124+
<el-option label="URL" value="url"></el-option>
125+
</el-select>
126+
<span v-if="mockConfig.storeKind === 'localFile'">
127+
File:<el-input v-model="mockConfig.storeLocalFile" placeholder="Local File Path"></el-input>
128+
</span>
106129
</div>
107130
<el-splitter layout="vertical" style="height: calc(100vh - 100px);">
108131
<el-splitter-panel size="70%">

console/atest-ui/src/views/net.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ function ReloadMockServer(config: any) {
746746
},
747747
body: JSON.stringify(config)
748748
}
749-
fetch(`/api/v1/mock/reload`, requestOptions)
749+
return fetch(`/api/v1/mock/reload`, requestOptions)
750750
.then(DefaultResponseProcess)
751751
}
752752

0 commit comments

Comments
 (0)