@@ -3,7 +3,7 @@ import { ref, watch, reactive } from 'vue'
33import { ElMessage } from ' element-plus'
44import { Edit , Delete , Search , CopyDocument } from ' @element-plus/icons-vue'
55import JsonViewer from ' vue-json-viewer'
6- import type { Pair , TestResult , TestCaseWithSuite } from ' ./types'
6+ import type { Pair , TestResult , TestCaseWithSuite , TestCase } from ' ./types'
77import { NewSuggestedAPIsQuery , CreateFilter , GetHTTPMethods , FlattenObject } from ' ./types'
88import { Cache } from ' ./cache'
99import { API } from ' ./net'
@@ -241,7 +241,8 @@ const emptyTestCaseWithSuite: TestCaseWithSuite = {
241241 query: [],
242242 cookie: [],
243243 form: [],
244- body: ' '
244+ body: ' ' ,
245+ filepath: ' '
245246 },
246247 response: {
247248 statusCode: 0 ,
@@ -324,7 +325,7 @@ function formatDate(createTimeStr : string){
324325 return formattedDate
325326}
326327
327- function determineBodyType(e ) {
328+ function determineBodyType(e : TestCase ) {
328329 e .request .header .forEach (item => {
329330 if (item .key === " Content-Type" ) {
330331 switch (item .value ) {
@@ -334,6 +335,15 @@ function determineBodyType(e) {
334335 case ' application/json' :
335336 bodyType .value = 5
336337 break
338+ case ' multipart/form-data' :
339+ bodyType .value = 6
340+
341+ e .request .form .forEach (fItem => {
342+ if (fItem .key !== ' ' && fItem .key !== ' ' ) {
343+ e .request .filepath = fItem .key + " =" + fItem .value
344+ }
345+ })
346+ break
337347 }
338348 }
339349 });
@@ -721,6 +731,17 @@ function bodyTypeChange(e: number) {
721731 case 5 :
722732 contentType = ' application/json'
723733 break ;
734+ case 6 :
735+ contentType = ' multipart/form-data'
736+
737+ const items = testCaseWithSuite .value .data .request .filepath .split (" =" )
738+ if (items && items .length > 1 ) {
739+ testCaseWithSuite .value .data .request .form = [{
740+ key: items [0 ],
741+ value: items [1 ]
742+ } as Pair ]
743+ }
744+ break ;
724745 }
725746
726747 if (contentType !== " " ) {
@@ -732,7 +753,7 @@ function bodyTypeChange(e: number) {
732753}
733754
734755const lintingError = ref (' ' )
735- function jsonFormat(space ) {
756+ function jsonFormat(space : number ) {
736757 const jsonText = testCaseWithSuite .value .data .request .body
737758 if (bodyType .value !== 5 || jsonText === ' ' ) {
738759 return
@@ -987,10 +1008,14 @@ Magic.Keys(() => {
9871008 <el-radio :label =" 3" >raw</el-radio >
9881009 <el-radio :label =" 4" >x-www-form-urlencoded</el-radio >
9891010 <el-radio :label =" 5" >JSON</el-radio >
1011+ <el-radio :label =" 6" >EmbedFile</el-radio >
9901012 </el-radio-group >
9911013
9921014 <div style =" flex-grow : 1 ;" >
993- <Codemirror v-if =" bodyType === 3 || bodyType === 5"
1015+ <div v-if =" bodyType === 6" >
1016+ Filename: <el-input v-model =" testCaseWithSuite.data.request.filepath" placeholder =" file=sample.txt" />
1017+ </div >
1018+ <Codemirror v-if =" bodyType === 3 || bodyType === 5 || bodyType === 6"
9941019 @blur =" jsonFormat(-1)"
9951020 v-model =" testCaseWithSuite.data.request.body"
9961021 :disabled =" isHistoryTestCase" />
0 commit comments