Skip to content

Commit 2810a1f

Browse files
committed
feat(browser): support upload OAS (resolve easy-mock#70 easy-mock#112)
1 parent 96490d0 commit 2810a1f

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

views/locale/en.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ export default {
107107
update: 'Update Success',
108108
delete: '{name} is deleted'
109109
}
110-
}
110+
},
111+
formatError: 'File only supports JSON/YML format',
112+
uploadSuccess: 'Upload Success'
111113
},
112114
profile: {
113115
header: {

views/locale/zh-CN.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ export default {
107107
update: '更新成功',
108108
delete: '{name} 已删除'
109109
}
110-
}
110+
},
111+
formatError: '文件仅支持 JSON/YML 格式',
112+
uploadSuccess: '上传成功'
111113
},
112114
profile: {
113115
header: {

views/pages/new/index.css

+4
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@
3131
border-bottom: 1px solid #eee;
3232
padding-bottom: 30px;
3333
}
34+
35+
@d swagger-type {
36+
margin-bottom: 10px;
37+
}
3438
}

views/pages/new/project.vue

+35-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,25 @@
4848
{{$tc('p.new.form.swagger', 0)}}
4949
<span>({{$tc('p.new.form.swagger', 1)}})</span>
5050
</template>
51-
<i-input v-model="form.projectSwagger" placeholder="http://example.com/swagger.json"></i-input>
51+
<i-select v-model="swaggerType" class="em-new__swagger-type">
52+
<Option value="URL">URL</Option>
53+
<Option value="Upload">Upload</Option>
54+
</i-select>
55+
<i-input v-if="swaggerType === 'URL'" v-model="form.projectSwagger" placeholder="http://example.com/swagger.json"></i-input>
56+
<Upload
57+
type="drag"
58+
:headers="uploadHeaders"
59+
:show-upload-list="false"
60+
:format="['json','yml']"
61+
:action="uploadAPI"
62+
:on-success="handleSwaggerUploadSuccess"
63+
:on-format-error="handleSwaggerUploadError"
64+
v-if="swaggerType === 'Upload'">
65+
<div style="padding: 20px 0">
66+
<Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
67+
<p>JSON / YML</p>
68+
</div>
69+
</Upload>
5270
<p class="em-new__form-description">
5371
{{$tc('p.new.form.swagger', 2)}} <router-link to="/docs#swagger"><Icon type="help-circled"></Icon></router-link>
5472
</p>
@@ -97,12 +115,15 @@
97115
</style>
98116

99117
<script>
118+
import conf from 'config'
100119
import * as api from '../../api'
101120
102121
export default {
103122
name: 'newProject',
104123
data () {
105124
return {
125+
uploadAPI: conf.APIPrefix + '/upload',
126+
swaggerType: 'URL',
106127
remoteLoading: false,
107128
users: [],
108129
groups: [],
@@ -167,9 +188,22 @@ export default {
167188
} else {
168189
return this.form.groupId !== this.user.id
169190
}
191+
},
192+
uploadHeaders () {
193+
return {
194+
Authorization: 'Bearer ' + this.user.token
195+
}
170196
}
171197
},
172198
methods: {
199+
handleSwaggerUploadSuccess (response) {
200+
this.form.projectSwagger = response.data.path
201+
this.swaggerType = 'URL'
202+
this.$Message.success(this.$t('p.new.uploadSuccess'))
203+
},
204+
handleSwaggerUploadError () {
205+
this.$Message.error(this.$t('p.new.formatError'))
206+
},
173207
convertUrl (url) {
174208
const newUrl = '/' + url
175209
return newUrl === '/'

0 commit comments

Comments
 (0)