Skip to content

Commit

Permalink
fix(useSubscription.ts): name can only contain numbers and letters
Browse files Browse the repository at this point in the history
  • Loading branch information
oucb authored and ysfscream committed Sep 13, 2023
1 parent c72b49c commit 6c70a5d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 29 deletions.
19 changes: 18 additions & 1 deletion src/composables/config/useSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,24 @@ export const useSubscriptionGroup = () => {
const keys = Object.keys(value)
const values = Object.values(value)
const isAllEmpty = values.every((val) => !val?.length)

const re = /^[0-9a-zA-Z]*$/g
const nodeGroups = Object.entries(value)
nodeGroups.forEach(([key, groups]) => {
const groupLen = groups.length
if (groupLen) {
if (!re.test(key)) {
callback(new Error(t('config.subscribeSouthDriverDeviceIllegal')))
} else {
Object.values(groups).forEach((item) => {
// 数据更新
console.log(re.test(item))
if (!re.test(item)) {
callback(new Error(t('config.subscribeSouthDriverGroupIllegal')))
}
})
}
}
})
if (!keys.length || isAllEmpty) {
callback(new Error(t('config.subscribeSouthDriverDataRequired')))
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,12 @@ export default {
zh: '请输入数组',
en: 'Please enter an array',
},
subscribeSouthDriverDeviceIllegal: {
zh: '注册的设备,名称只能包含数字和字母',
en: 'Subscribed devices, names can only contain numbers and letters',
},
subscribeSouthDriverGroupIllegal: {
zh: '设备下的分组,名称只能包含数字和字母',
en: 'The group name under the device can only contain numbers and letters',
},
}
58 changes: 30 additions & 28 deletions src/views/config/components/SouthGroupsCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,37 @@

<section class="southGroupCheckboxGroups" :class="{ 'empty-southGroupCheckboxGroups': !southNodeList.length }">
<el-collapse v-if="southNodeList.length" v-model="activeNames" @change="handleCollapseStatus">
<el-collapse-item v-for="node in southNodeList" :key="node.name" :title="node.name" :name="node.name">
<template #title>
<i
class="icon-arrow"
:class="activeNames.includes(node.name) ? 'el-icon-arrow-down' : 'el-icon-arrow-right'"
/>
<el-checkbox
v-model="node.checkedAll"
:indeterminate="isIndeterminateValues[node.name]"
class="node-name"
@change="handelCheckedAll($event, node.name)"
>
{{ node.name }}
</el-checkbox>
</template>

<main class="groups-wrapper">
<el-checkbox-group
v-if="isHasGroups(node.name)"
v-model="checkedValue[node.name]"
@change="handleCheckedGroups($event, node.name)"
>
<el-checkbox v-for="group in allSouthGroups[node.name]" :key="group" :label="group" class="group-item">
{{ group }}
<template v-for="node in southNodeList" :key="node.name">
<el-collapse-item v-if="isHasGroups(node.name)" :title="node.name" :name="node.name">
<template #title>
<i
class="icon-arrow"
:class="activeNames.includes(node.name) ? 'el-icon-arrow-down' : 'el-icon-arrow-right'"
/>
<el-checkbox
v-model="node.checkedAll"
:indeterminate="isIndeterminateValues[node.name]"
class="node-name"
@change="handelCheckedAll($event, node.name)"
>
{{ node.name }}
</el-checkbox>
</el-checkbox-group>
<span v-else class="empty-groups">{{ $t('common.emptyData') }}</span>
</main>
</el-collapse-item>
</template>

<main class="groups-wrapper">
<el-checkbox-group
v-if="isHasGroups(node.name)"
v-model="checkedValue[node.name]"
@change="handleCheckedGroups($event, node.name)"
>
<el-checkbox v-for="group in allSouthGroups[node.name]" :key="group" :label="group" class="group-item">
{{ group }}
</el-checkbox>
</el-checkbox-group>
<span v-else class="empty-groups">{{ $t('common.emptyData') }}</span>
</main>
</el-collapse-item>
</template>
</el-collapse>

<span v-else class="empty-groups">{{ $t('common.emptyData') }}</span>
Expand Down

0 comments on commit 6c70a5d

Please sign in to comment.