Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mqtt): add rules for check client_attrs_init #2655

Merged
merged 1 commit into from
May 11, 2024
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
4 changes: 4 additions & 0 deletions src/i18n/BasicConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,8 @@ export default {
zh: '注意:如果更改非 QUIC 类型的监听器端口,将会断开所有已存在的连接,是否继续?',
en: 'Note: If the port of listeners (except QUIC type) is changed, all existing connections will be disconnected. Continue?',
},
duplicatedAttrError: {
zh: '存在相同的属性',
en: 'Duplicated Attribute',
},
}
4 changes: 4 additions & 0 deletions src/i18n/Rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ export default {
zh: '可配置的最大值为 {max}',
en: 'Configurable maximum value is {max}',
},
incompleteTableError: {
zh: '请完整填写表格',
en: 'Please complete the table',
},
}
24 changes: 24 additions & 0 deletions src/views/Config/BasicConfig/Mqtt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<schema-form
ref="SchemaFormCom"
type="mqtt"
need-rules
:according-to="{ ref: ['paths', '/configs/global_zone', 'get'] }"
:form="configs"
:form-props="{ labelWidth: state.lang === 'zh' ? 240 : 284 }"
Expand Down Expand Up @@ -85,6 +86,29 @@ export default defineComponent({
set_as_attr: { minWidth: 140 },
expression: { minWidth: 200 },
}
if (client_attrs_init.path) {
if (!data.rules[client_attrs_init.path]) {
data.rules[client_attrs_init.path] = []
}
data.rules[client_attrs_init.path].push({
validator(rules: any, value: any, cb: (errors?: Error) => void) {
if (
value?.some?.(
({ set_as_attr, expression }: { expression: string; set_as_attr: string }) =>
!set_as_attr || !expression,
)
) {
cb(new Error(t('Rule.incompleteTableError')))
}
const setAsAttrArr = value?.map?.((item: any) => item.set_as_attr)
const uniqueSetAsAttrArr = [...new Set(setAsAttrArr)]
if (setAsAttrArr.length !== uniqueSetAsAttrArr.length) {
cb(new Error(t('BasicConfig.duplicatedAttrError')))
}
cb()
},
})
}
}

const { items } = client_attrs_init || {}
Expand Down
Loading