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

feat(frontend): mysql、spider库表校验规则调整 #6595 #6735

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
13 changes: 12 additions & 1 deletion dbm-ui/frontend/src/components/batch-edit-column/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:is-show="isShow"
trigger="manual"
width="395"
@after-show="handleAfterShow"
@cancel="() => (isShow = false)"
@confirm="handleConfirm">
<slot />
Expand All @@ -26,6 +27,7 @@
:list="dataList" />
<BkInput
v-else-if="type === 'textarea'"
ref="inputRef"
v-model="localValue"
:placeholder="placeholder"
:rows="5"
Expand Down Expand Up @@ -53,7 +55,7 @@
(e: 'change', value: string): void;
}

withDefaults(defineProps<Props>(), {
const props = withDefaults(defineProps<Props>(), {
dataList: () => [],
type: 'select',
placeholder: '',
Expand All @@ -68,12 +70,21 @@

const { t } = useI18n();

const inputRef = ref();
const localValue = ref('');

const handleConfirm = () => {
emits('change', localValue.value);
isShow.value = false;
};

const handleAfterShow = () => {
if (props.type === 'textarea') {
nextTick(() => {
inputRef.value?.focus();
});
}
};
</script>

<style lang="less">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,29 @@
:single="single"
@change="handleValueChange">
<template #tip>
<p>{{ t('%:匹配任意长度字符串,如 a%, 不允许独立使用') }}</p>
<p>{{ t('?: 匹配任意单一字符,如 a%?%d') }}</p>
<p>{{ t('* :专门指代 ALL 语义, 只能独立使用') }}</p>
<p>{{ t('注:含通配符的单元格仅支持输入单个对象') }}</p>
<p>{{ t('按Enter或失焦可完成内容输入') }}</p>
<p>{{ t('粘贴多个对象可用换行,空格或;,|分隔') }}</p>
<div class="db-table-tag-tip">
<div style="font-weight: 700">{{ t('库表输入说明') }}:</div>
<div>
<div class="circle-dot"></div>
<span>{{ t('不允许输入系统库和特殊库,如mysql、sys 等') }}</span>
</div>
<div>
<div class="circle-dot"></div>
<span>{{ t('DB名、表名不允许为空,忽略DB名、忽略表名不允许为 *') }}</span>
</div>
<div>
<div class="circle-dot"></div>
<span>{{ t('支持 %(指代任意长度字符串), ?(指代单个字符串), *(指代全部)三个通配符') }}</span>
</div>
<div>
<div class="circle-dot"></div>
<span>{{ t('单元格可同时输入多个对象,使用换行,空格或;,|分隔,按 Enter 或失焦完成内容输入') }}</span>
</div>
<div>
<div class="circle-dot"></div>
<span>{{ t('包含通配符时, 每一单元格只允许输入单个对象。% ? 不能独立使用, * 只能单独使用') }}</span>
</div>
</div>
</template>
</TagInput>
</template>
Expand Down Expand Up @@ -79,3 +96,25 @@
},
});
</script>
<style lang="less" scoped>
.db-table-tag-tip {
display: flex;
flex-direction: column;
line-height: 24px;
padding: 3px 7px;

div {
display: flex;
align-items: center;

.circle-dot {
width: 4px;
height: 4px;
background-color: #63656e;
border-radius: 50%;
display: inline-block;
margin-right: 6px;
}
}
}
</style>
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 @@ -3298,5 +3298,10 @@
"按Enter或失焦可完成内容输入": "按 Enter 或失焦可完成内容输入",
"粘贴多个对象可用换行,空格或;,|分隔": "粘贴多个对象可用换行,空格或;,|分隔",
"RedisCluster集群": "RedisCluster 集群",
"% 或 ? 不允许单独使用": "% 或 ? 不允许单独使用",
"不允许为 *": "不允许为 *",
"库表名支持数字、字母、中划线、下划线,最大35字符": "库表名支持数字、字母、中划线、下划线,最大35字符",
"不允许输入系统库和特殊库": "不允许输入系统库和特殊库",
"不能以stage_truncate开头或dba_rollback结尾": "不能以 stage_truncate 开头或 dba_rollback 结尾",
"这行勿动!新增翻译请在上一行添加!": ""
}
1 change: 1 addition & 0 deletions dbm-ui/frontend/src/services/source/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function getUserList(
limit?: number;
offset?: number;
fuzzy_lookups?: string;
exact_lookups?: string;
} = {},
) {
return http.get<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const useBaseDetails = (immediateFetch = true) => {

const treeNode = inject<ComputedRef<TreeData>>('treeNode');
const route = useRoute();
const clusterType = computed(() => route.params.clusterType as ClusterTypes);
const clusterType = computed(() => (route.params.clusterType as ClusterTypes) || ClusterTypes.TENDBSINGLE);
const dbType = computed(() => clusterTypeInfos[clusterType.value].dbType);
const state = reactive<State>({
loading: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@

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

interface Props {
checkDuplicate?: boolean;
}

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

const props = withDefaults(defineProps<Props>(), {
checkDuplicate: false,
});

const modelValue = defineModel<string[]>({
default: () => [],
});
Expand All @@ -45,32 +53,49 @@

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('库表名支持数字、字母、中划线、下划线,最大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 @@ -17,10 +17,11 @@
<FixedColumn fixed="left">
<RenderDbName
ref="dbnamesRef"
v-model="localDbnames" />
v-model="localDbnames"
check-duplicate />
</FixedColumn>
<td style="padding: 0">
<RenderIgnoreDbName
<RenderDbName
ref="ignoreDbnamesRef"
v-model="localIgnoreDbnames" />
</td>
Expand Down Expand Up @@ -51,7 +52,6 @@
import { random } from '@utils';

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

export interface IDataRow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<td style="padding: 0">
<RenderDbName
ref="ignoreDbsRef"
:allow-asterisk="false"
:cluster-id="localClusterId"
:model-value="data.ignoreDbs"
:required="false"
Expand All @@ -52,10 +53,10 @@
:model-value="data.tablePatterns" />
</td>
<td style="padding: 0">
<RenderIgnoreTables
<RenderTableName
ref="ignoreTablesRef"
:allow-asterisk="false"
:cluster-id="localClusterId"
:ignore-dbs="localRowData.ignoreDbs"
:model-value="data.ignoreTables" />
</td>
<OperateColumn
Expand Down Expand Up @@ -132,7 +133,7 @@
import RenderDbName from '@views/mysql/common/edit-field/DbName.vue';
import RenderTableName from '@views/mysql/common/edit-field/TableName.vue';

import RenderIgnoreTables from './RenderIgnoreTables.vue';
// import RenderIgnoreTables from './RenderIgnoreTables.vue';
import RenderSlave from './RenderSlave.vue';

interface Props {
Expand Down
Loading
Loading