Skip to content

Commit

Permalink
feat(frontend): 密码规则特殊字符校验 TencentBlueKing#7031
Browse files Browse the repository at this point in the history
  • Loading branch information
JustaCattt authored and hLinx committed Oct 25, 2024
1 parent 8ec8c51 commit 06640f8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
10 changes: 9 additions & 1 deletion dbm-ui/frontend/src/components/db-tab/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@

import { DBTypeInfos, DBTypes } from '@common/const';

interface Props {
exclude?: DBTypes[];
}

interface TabItem {
id: DBTypes;
name: string;
}

const props = withDefaults(defineProps<Props>(), {
exclude: () => [],
});

const funControllerStore = useFunController();

const moduleValue = defineModel<DBTypes>({
Expand All @@ -43,7 +51,7 @@
const renderTabs = Object.values(DBTypeInfos).reduce((result, item) => {
const { id, name, moduleId } = item;
const data = funControllerStore.funControllerData.getFlatData(moduleId);
if (data[id]) {
if (data[id] && !props.exclude.includes(id)) {
result.push({ id, name });
}
return result;
Expand Down
5 changes: 5 additions & 0 deletions dbm-ui/frontend/src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3491,5 +3491,10 @@
"如忽略,有连接的情况下也会执行强制升级": "如忽略,有连接的情况下也会执行强制升级",
"库表名支持数字、字母、中划线、下划线,最大64字符": "库表名支持数字、字母、中划线、下划线,最大64字符",
"暂不支持 use 语句,请使用 db.table 指定 database": "暂不支持 use 语句,请使用 db.table 指定 database",
"请添加账号规则": "请添加账号规则",
"请指定特殊字符": "请指定特殊字符",
"特殊字符不允许包含空格": "特殊字符不允许包含空格",
"请输入除大小写字母、数字外的英文半角字符": "请输入除大小写字母、数字外的英文半角字符",
"请输入英文半角字符,重复字符将去重": "请输入英文半角字符,重复字符将去重",
"这行勿动!新增翻译请在上一行添加!": ""
}
6 changes: 4 additions & 2 deletions dbm-ui/frontend/src/views/password-manage/policy/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
-->

<template>
<DbTab v-model:active="activeTab" />
<DbTab
v-model:active="activeTab"
:exclude="[DBTypes.RIAK]" />
<div class="password-policy-content">
<RenderContent :db-type="activeTab" />
</div>
</template>

<script setup lang="ts">
import type { DBTypes } from '@common/const';
import { DBTypes } from '@common/const';

import DbTab from '@components/db-tab/Index.vue';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@
<div class="input-prefix">
{{ t('指定特殊字符') }}
</div>
<BkInput
v-model="formData.symbols_allowed"
<BkFormItem
class="symbols-input"
@keyup="handleInputChange" />
property="symbols_allowed">
<BkInput
v-model="formData.symbols_allowed"
:placeholder="t('请输入英文半角字符,重复字符将去重')" />
</BkFormItem>
</div>
</BkFormItem>
<BkFormItem
Expand Down Expand Up @@ -136,6 +139,7 @@

<script setup lang="ts">
import { Message } from 'bkui-vue';
import _ from 'lodash';
import { useI18n } from 'vue-i18n';
import { useRequest } from 'vue-request';

Expand Down Expand Up @@ -179,6 +183,38 @@
validator: () => Object.values(formData.include_rule).some((checked) => checked),
},
],
symbols_allowed: [
{
trigger: 'blur',
message: t('请指定特殊字符'),
validator: (value: string) => {
if (formData.include_rule.symbols) {
return !!value;
}
return true;
},
},
{
trigger: 'blur',
message: t('特殊字符不允许包含空格'),
validator: (value: string) => {
if (formData.include_rule.symbols) {
return !/\s/.test(value);
}
return true;
},
},
{
trigger: 'blur',
message: t('请输入除大小写字母、数字外的英文半角字符'),
validator: (value: string) => {
if (formData.include_rule.symbols) {
return /^[\u0021-\u002f\u003a-\u0040\u005b-\u0060\u007b-\u007e]+$/.test(value);
}
return true;
},
},
],
};

const defaultConfig = reactive(initData());
Expand Down Expand Up @@ -243,12 +279,6 @@
formRef.value.validate();
};

const handleInputChange = (value: string) => {
if (/[A-Za-z0-9]/.test(value)) {
formData.symbols_allowed = value.slice(0, -1);
}
};

const handleSubmit = async (reset = false) => {
if (!reset) {
await formRef.value.validate();
Expand All @@ -259,7 +289,10 @@
}
updatePasswordPolicyRun({
...passwordPolicyData,
rule: formData,
rule: {
...formData,
symbols_allowed: _.uniq(formData.symbols_allowed.split('')).join(''),
},
reset,
});
};
Expand Down

0 comments on commit 06640f8

Please sign in to comment.