Skip to content

Commit

Permalink
feat(frontend): mysql、spider库表校验规则调整 TencentBlueKing#6595
Browse files Browse the repository at this point in the history
  • Loading branch information
jinquantianxia committed Sep 6, 2024
1 parent f73f5a2 commit 8afe0f4
Show file tree
Hide file tree
Showing 27 changed files with 75 additions and 3,187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,47 +30,72 @@

import { makeMap, random } from '@utils';

interface Props {
checkDuplicate?: boolean;
}

interface Exposes {
getValue: () => Promise<string[]>;
}

const { t } = useI18n();

const instanceKey = random();
tagMemo[instanceKey] = [];
const props = withDefaults(defineProps<Props>(), {
checkDuplicate: false,
});

const modelValue = defineModel<string[]>({
default: () => [],
});

const { t } = useI18n();

const instanceKey = random();
tagMemo[instanceKey] = [];

const editTagRef = ref<InstanceType<typeof TableEditTag>>();

const systemDbNames = ['mysql', 'db_infobase', 'information_schema', 'performance_schema', 'sys', 'infodba_schema'];

const rules = [
{
validator: (value: string[]) => {
tagMemo[instanceKey] = value;
return value && value.length > 0;
},
message: t('DB名不能为空'),
validator: (value: string[]) => value && value.length > 0,
message: t('DB 名不能为空'),
},
{
validator: (value: string[]) => {
const hasAllMatch = _.find(value, (item) => /%$/.test(item));
return !(value.length > 1 && hasAllMatch);
},
message: t('一格仅支持单个_对象'),
validator: (value: string[]) => _.every(value, (item) => /^(?!stage_truncate)(?!.*dba_rollback$).*/.test(item)),
message: t('不能以stage_truncate开头或dba_rollback结尾'),
},
{
validator: (value: string[]) => _.every(value, (item) => /^[-_a-zA-Z0-9*?%]{0,35}$/.test(item)),
message: t('库表只能由[0-9],[a-z],[A-Z],-,_ 组成,支持* % ?通配符,最大35字符'),
},
{
validator: (value: string[]) => _.every(value, (item) => !systemDbNames.includes(item)),
message: t('不允许填写系统库'),
},
{
validator: (value: string[]) =>
!_.some(value, (item) => (/\*/.test(item) && item.length > 1) || (value.length > 1 && item === '*')),
message: t('* 只能独立使用'),
},
{
validator: (value: string[]) => _.every(value, (item) => !/^%$/.test(item)),
message: t('% 不允许单独使用'),
validator: (value: string[]) => _.every(value, (item) => !/^[%?]$/.test(item)),
message: t('% 或 ? 不允许单独使用'),
},
{
validator: (value: string[]) => {
if (_.some(value, (item) => /[*%?]/.test(item))) {
return value.length < 2;
}
return true;
},
message: t('含通配符的单元格仅支持输入单个对象'),
},
{
validator: (value: string[]) => {
if (!props.checkDuplicate) {
return true;
}

const otherTagMap = { ...tagMemo };
delete otherTagMap[instanceKey];

Expand All @@ -84,7 +109,9 @@
watch(
modelValue,
() => {
tagMemo[instanceKey] = modelValue.value;
if (props.checkDuplicate) {
tagMemo[instanceKey] = modelValue.value;
}
},
{
immediate: true,
Expand All @@ -93,7 +120,9 @@

const handleChange = (value: string[]) => {
modelValue.value = value;
tagMemo[instanceKey] = value;
if (props.checkDuplicate) {
tagMemo[instanceKey] = value;
}
};

onBeforeUnmount(() => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,34 @@
-->

<template>
<tr>
<FixedColumn fixed="left">
<RenderDbName
ref="dbnamesRef"
v-model="localDbnames" />
</FixedColumn>
<td style="padding: 0">
<RenderIgnoreDbName
ref="ignoreDbnamesRef"
v-model="localIgnoreDbnames"
:required="false" />
</td>
<td style="padding: 0">
<RenderSql
ref="sqlFielsRef"
v-model="localSqlFiles"
v-model:importMode="localImportMode"
:cluster-version-list="clusterVersionList"
:db-names="localDbnames"
:ignore-db-names="localIgnoreDbnames" />
</td>
<OperateColumn
:removeable="removeable"
@add="handleAppend"
@remove="handleRemove" />
</tr>
<tbody>
<tr>
<FixedColumn fixed="left">
<RenderDbName
ref="dbnamesRef"
v-model="localDbnames"
check-duplicate />
</FixedColumn>
<td style="padding: 0">
<RenderDbName
ref="ignoreDbnamesRef"
v-model="localIgnoreDbnames" />
</td>
<td style="padding: 0">
<RenderSql
ref="sqlFielsRef"
v-model="localSqlFiles"
v-model:importMode="localImportMode"
:cluster-version-list="clusterVersionList"
:db-names="localDbnames"
:ignore-db-names="localIgnoreDbnames" />
</td>
<OperateColumn
:removeable="removeable"
@add="handleAppend"
@remove="handleRemove" />
</tr>
</tbody>
</template>
<script lang="ts">
import { ref } from 'vue';
Expand All @@ -48,7 +50,6 @@
import { random } from '@utils';

import RenderDbName from './RenderDbName.vue';
import RenderIgnoreDbName from './RenderIgnoreDbName.vue';

export interface IDataRow {
rowKey: string;
Expand Down
Loading

0 comments on commit 8afe0f4

Please sign in to comment.