Skip to content

Commit cfb3ee7

Browse files
authored
feature:allow set filter_func in router configuation page (#164)
* feature:allow set vars filter * feature:allow set vars filter in router configuration page * feature:allow set vars filter in router configuration page * fiexed some irregular style * feature:allow set filter_func in router configuation page
1 parent df4c6be commit cfb3ee7

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

src/lang/en.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export default {
7474
schema: {
7575
route: {
7676
inputMultipleValues: 'Input value then press return button',
77-
propertyHostsTip: 'Any values are supported'
77+
propertyHostsTip: 'Any values are supported',
78+
fileterFunc: 'User-defined filtering function,Begins with "function()" and ends with "end".'
7879
}
7980
},
8081
upstream: {

src/lang/zh.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ export default {
8282
schema: {
8383
route: {
8484
inputMultipleValues: '输入值后并回车',
85-
propertyHostsTip: '任何值均可'
85+
propertyHostsTip: '任何值均可',
86+
fileterFunc: '用户自定义的过滤函数,以‘function()’开头,以‘end’结尾。'
8687
}
8788
},
8889
upstream: {

src/views/schema/routes/edit.vue

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,18 @@
199199
@onChange="onVarArgsChange"
200200
/>
201201

202+
<el-form-item
203+
label="filter_func"
204+
prop="filter_func"
205+
>
206+
<el-input
207+
v-model="form.filter_func"
208+
type="textarea"
209+
:autosize="{minRows: 2, maxRows: 4}"
210+
:placeholder="$t('schema.route.fileterFunc')"
211+
/>
212+
</el-form-item>
213+
202214
<el-form-item>
203215
<el-button
204216
type="primary"
@@ -234,6 +246,8 @@ import { getUpstreamList } from '@/api/schema/upstream'
234246
import { getServiceList } from '@/api/schema/services'
235247
import { TagsViewModule } from '@/store/modules/tags-view'
236248
249+
import i18n from '@/lang'
250+
237251
@Component({
238252
name: 'RouterEdit',
239253
components: {
@@ -252,17 +266,22 @@ export default class extends Vue {
252266
methods: [],
253267
plugins: {},
254268
vars: [],
255-
desc: ''
269+
desc: '',
270+
filter_func: ''
256271
}
257272
258273
// TODO: can add existed info from route list
259274
private ExistedUris = [{}]
260275
private ExistedHosts = [{}]
276+
private validateFilterFuncRegexp = /^function\(\)[^]*?\bend$/
261277
262278
private rules = {
263279
uris: {
264280
required: true
265-
}
281+
},
282+
filter_func: [
283+
{ pattern: this.validateFilterFuncRegexp, trigger: 'blur', message: i18n.t('schema.route.fileterFunc') }
284+
]
266285
}
267286
private isEditMode: boolean = false
268287
@@ -302,7 +321,8 @@ export default class extends Vue {
302321
methods: [],
303322
plugins: {},
304323
vars: [],
305-
desc: ''
324+
desc: '',
325+
filter_func: ''
306326
}
307327
}
308328
@@ -347,7 +367,8 @@ export default class extends Vue {
347367
methods = [],
348368
plugins = {},
349369
vars = [],
350-
desc = ''
370+
desc = '',
371+
filter_func = ''
351372
}
352373
}
353374
} = await getRouter(id) as any
@@ -369,12 +390,13 @@ export default class extends Vue {
369390
methods,
370391
plugins,
371392
vars,
372-
desc
393+
desc,
394+
filter_func
373395
}
374396
}
375397
376398
private async onSubmit() {
377-
(this.$refs.form as any).validate(async(valid: boolean) => {
399+
(this.$refs.form as any).validate(async(valid: boolean, invalidField: any) => {
378400
if (valid) {
379401
let data = Object.assign({}, this.form)
380402
if (!data.methods.length) {
@@ -411,6 +433,9 @@ export default class extends Vue {
411433
})
412434
}
413435
} else {
436+
if (invalidField.filter_func) {
437+
this.$message.warning(invalidField.filter_func[0].message)
438+
}
414439
return false
415440
}
416441
})

0 commit comments

Comments
 (0)