Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export default {
schema: {
route: {
inputMultipleValues: 'Input value then press return button',
propertyHostsTip: 'Any values are supported'
propertyHostsTip: 'Any values are supported',
fileterFunc: 'User-defined filtering function,Begins with "function()" and ends with "end".'
}
},
upstream: {
Expand Down
3 changes: 2 additions & 1 deletion src/lang/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export default {
schema: {
route: {
inputMultipleValues: '输入值后并回车',
propertyHostsTip: '任何值均可'
propertyHostsTip: '任何值均可',
fileterFunc: '用户自定义的过滤函数,以‘function()’开头,以‘end’结尾。'
}
},
upstream: {
Expand Down
37 changes: 31 additions & 6 deletions src/views/schema/routes/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@
@onChange="onVarArgsChange"
/>

<el-form-item
label="filter_func"
prop="filter_func"
>
<el-input
v-model="form.filter_func"
type="textarea"
:autosize="{minRows: 2, maxRows: 4}"
:placeholder="$t('schema.route.fileterFunc')"
/>
</el-form-item>

<el-form-item>
<el-button
type="primary"
Expand Down Expand Up @@ -234,6 +246,8 @@ import { getUpstreamList } from '@/api/schema/upstream'
import { getServiceList } from '@/api/schema/services'
import { TagsViewModule } from '@/store/modules/tags-view'

import i18n from '@/lang'

@Component({
name: 'RouterEdit',
components: {
Expand All @@ -252,17 +266,22 @@ export default class extends Vue {
methods: [],
plugins: {},
vars: [],
desc: ''
desc: '',
filter_func: ''
}

// TODO: can add existed info from route list
private ExistedUris = [{}]
private ExistedHosts = [{}]
private validateFilterFuncRegexp = /^function\(\)[^]*?\bend$/

private rules = {
uris: {
required: true
}
},
filter_func: [
{ pattern: this.validateFilterFuncRegexp, trigger: 'blur', message: i18n.t('schema.route.fileterFunc') }
]
}
private isEditMode: boolean = false

Expand Down Expand Up @@ -302,7 +321,8 @@ export default class extends Vue {
methods: [],
plugins: {},
vars: [],
desc: ''
desc: '',
filter_func: ''
}
}

Expand Down Expand Up @@ -347,7 +367,8 @@ export default class extends Vue {
methods = [],
plugins = {},
vars = [],
desc = ''
desc = '',
filter_func = ''
}
}
} = await getRouter(id) as any
Expand All @@ -369,12 +390,13 @@ export default class extends Vue {
methods,
plugins,
vars,
desc
desc,
filter_func
}
}

private async onSubmit() {
(this.$refs.form as any).validate(async(valid: boolean) => {
(this.$refs.form as any).validate(async(valid: boolean, invalidField: any) => {
if (valid) {
let data = Object.assign({}, this.form)
if (!data.methods.length) {
Expand Down Expand Up @@ -411,6 +433,9 @@ export default class extends Vue {
})
}
} else {
if (invalidField.filter_func) {
this.$message.warning(invalidField.filter_func[0].message)
}
return false
}
})
Expand Down