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 2, 2024
1 parent 5c6b817 commit e3d6bc3
Show file tree
Hide file tree
Showing 27 changed files with 301 additions and 223 deletions.
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 @@ -27,6 +28,7 @@
:list="dataList" />
<BkInput
v-else-if="type === 'textarea'"
ref="inputRef"
v-model="localValue"
:placeholder="placeholder"
:rows="5"
Expand Down Expand Up @@ -54,7 +56,7 @@
(e: 'change', value: string): void;
}
withDefaults(defineProps<Props>(), {
const props = withDefaults(defineProps<Props>(), {
dataList: () => [],
type: 'select',
placeholder: '',
Expand All @@ -69,12 +71,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
2 changes: 2 additions & 0 deletions dbm-ui/frontend/src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3459,5 +3459,7 @@
"所有集群已免审批": "所有集群已免审批",
"单据免审批设置": "单据免审批设置",
"内置策略为平台预设的审批规则,不可修改。根据业务需求,您可对全部或部分集群应用免审批策略。": "内置策略为平台预设的审批规则,不可修改。根据业务需求,您可对全部或部分集群应用免审批策略。",
"% 或 ? 不允许单独使用": "% 或 ? 不允许单独使用",
"不允许为 *": "不允许为 *",
"这行勿动!新增翻译请在上一行添加!": ""
}
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,8 +63,8 @@ export const useBaseDetails = (immediateFetch = true) => {

const treeNode = inject<ComputedRef<TreeData>>('treeNode');
const route = useRoute();
const clusterType = computed(() => route.params.clusterType as ClusterTypes);
const dbType = computed(() => clusterTypeInfos[clusterType.value]?.dbType);
const clusterType = computed(() => (route.params.clusterType as ClusterTypes) || ClusterTypes.TENDBSINGLE);
const dbType = computed(() => clusterTypeInfos[clusterType.value].dbType);
const state = reactive<State>({
loading: false,
loadingDetails: false,
Expand Down Expand Up @@ -148,7 +148,7 @@ export const useBaseDetails = (immediateFetch = true) => {
}
}
},
{ deep: true, immediate: true }
{ deep: true, immediate: true },
);

return {
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
19 changes: 14 additions & 5 deletions dbm-ui/frontend/src/views/mysql/common/edit-field/DbName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
single?: boolean;
checkExist?: boolean;
checkNotExist?: boolean;
allowAsterisk?: boolean;
rules?: {
validator: (value: string[]) => boolean;
message: string;
Expand All @@ -63,6 +64,7 @@
checkNotExist: false,
rules: undefined,
disabledModelValueInit: false,
allowAsterisk: true,
});

const emits = defineEmits<Emits>();
Expand All @@ -87,16 +89,24 @@
},
message: t('DB 名不能为空'),
},
{
validator: (value: string[]) => {
if (props.allowAsterisk) {
return true;
}

return _.every(value, (item) => item !== '*');
},
message: t('不允许为 *'),
},
{
validator: (value: string[]) =>
!_.some(value, (item) => (/\*/.test(item) && item.length > 1) || (value.length > 1 && item === '*')),
message: t('* 只能独立使用'),
trigger: 'change',
},
{
validator: (value: string[]) => _.every(value, (item) => !/^%$/.test(item)),
message: t('% 不允许单独使用'),
trigger: 'change',
validator: (value: string[]) => _.every(value, (item) => !/^[%?]$/.test(item)),
message: t('% 或 ? 不允许单独使用'),
},
{
validator: (value: string[]) => {
Expand All @@ -106,7 +116,6 @@
return true;
},
message: t('含通配符的单元格仅支持输入单个对象'),
trigger: 'change',
},
{
validator: (value: string[]) => {
Expand Down
19 changes: 14 additions & 5 deletions dbm-ui/frontend/src/views/mysql/common/edit-field/TableName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
required?: boolean;
placeholder?: string;
single?: boolean;
allowAsterisk?: boolean; // 是否允许单个 *
rules?: {
validator: (value: string[]) => boolean;
message: string;
Expand All @@ -60,6 +61,7 @@
rules: undefined,
disabledModelValueInit: false,
disabled: false,
allowAsterisk: true,
});

const emits = defineEmits<Emits>();
Expand All @@ -84,16 +86,24 @@
},
message: t('表名不能为空'),
},
{
validator: (value: string[]) => {
if (props.allowAsterisk) {
return true;
}

return _.every(value, (item) => item !== '*');
},
message: t('不允许为 *'),
},
{
validator: (value: string[]) =>
!_.some(value, (item) => (/\*/.test(item) && item.length > 1) || (value.length > 1 && item === '*')),
message: t('* 只能独立使用'),
trigger: 'change',
},
{
validator: (value: string[]) => _.every(value, (item) => !/^%$/.test(item)),
message: t('% 不允许单独使用'),
trigger: 'change',
validator: (value: string[]) => _.every(value, (item) => !/^[%?]$/.test(item)),
message: t('% 或 ? 不允许单独使用'),
},
{
validator: (value: string[]) => {
Expand All @@ -103,7 +113,6 @@
return true;
},
message: t('含通配符的单元格仅支持输入单个对象'),
trigger: 'change',
},
// TODO: 表不存在
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@
</RenderTableHeadColumn>
<RenderTableHeadColumn
:min-width="200"
:required="false"
:width="250">
{{ t('目标表名') }}
{{ t('忽略DB名') }}
</RenderTableHeadColumn>
<RenderTableHeadColumn
:min-width="200"
:required="false"
:width="250">
{{ t('忽略DB名') }}
{{ t('目标表名') }}
</RenderTableHeadColumn>
<RenderTableHeadColumn
:min-width="200"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,26 @@
:cluster-id="localClusterId"
:model-value="data.dbPatterns" />
</td>
<td style="padding: 0">
<RenderTableName
ref="tablePatternsRef"
:cluster-id="localClusterId"
:disabled="isDropDatabase"
:model-value="tablePatterns" />
</td>
<td style="padding: 0">
<RenderDbName
ref="ignoreDbsRef"
:allow-asterisk="false"
:cluster-id="localClusterId"
:model-value="data.ignoreDbs"
:required="false"
@change="handleIgnoreDbsChange" />
</td>
<td style="padding: 0">
<RenderTableName
ref="tablePatternsRef"
:cluster-id="localClusterId"
:disabled="isDropDatabase"
:model-value="tablePatterns" />
</td>
<td style="padding: 0">
<RenderTableName
ref="ignoreTablesRef"
:allow-asterisk="false"
:cluster-id="localClusterId"
:disabled="isDropDatabase"
:model-value="ignoreTables"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
</RenderTableHeadColumn>
<RenderTableHeadColumn
:min-width="240"
:required="false"
:width="240">
{{ t('备份表名') }}
{{ t('忽略DB名') }}
</RenderTableHeadColumn>
<RenderTableHeadColumn
:min-width="240"
:required="false"
:width="240">
{{ t('忽略DB名') }}
{{ t('备份表名') }}
</RenderTableHeadColumn>
<RenderTableHeadColumn
:min-width="240"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,24 @@
:cluster-id="localClusterId"
:model-value="data.dbPatterns" />
</td>
<td style="padding: 0">
<RenderTableName
ref="tablePatternsRef"
:cluster-id="localClusterId"
:model-value="data.tablePatterns" />
</td>
<td style="padding: 0">
<RenderDbName
ref="ignoreDbsRef"
:allow-asterisk="false"
:cluster-id="localClusterId"
:model-value="data.ignoreDbs"
:required="false" />
</td>
<td style="padding: 0">
<RenderTableName
ref="tablePatternsRef"
:cluster-id="localClusterId"
:model-value="data.tablePatterns" />
</td>
<td style="padding: 0">
<RenderTableName
ref="ignoreTablesRef"
:allow-asterisk="false"
:cluster-id="localClusterId"
:model-value="data.ignoreTables"
:required="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<BkPopConfirm
trigger="click"
width="330"
@after-show="handleAfterShow"
@confirm="handleConfirm">
<slot />
<template #content>
Expand All @@ -16,6 +17,7 @@
</div>
<BkInput
v-if="isShowInput"
ref="inputRef"
v-model="localValue"
class="input-box"
:min="1"
Expand All @@ -36,14 +38,14 @@
interface Props {
config: {
type: 'text' | 'number' | 'password' | 'textarea' | string
title: string,
placeholder: string,
}
type: 'text' | 'number' | 'password' | 'textarea' | string;
title: string;
placeholder: string;
};
}
interface Emits {
(e: 'data-change', value: string[], isBatch: boolean): void,
(e: 'data-change', value: string[], isBatch: boolean): void;
}
const props = defineProps<Props>();
Expand All @@ -52,6 +54,7 @@
const { t } = useI18n();
const inputRef = ref();
const multipleInputRef = ref();
const localValue = ref('');
Expand All @@ -68,6 +71,17 @@
}
localValue.value = '';
};
const handleAfterShow = () => {
nextTick(() => {
if (isShowInput.value) {
inputRef.value?.focus();
return;
}
multipleInputRef.value?.focus();
});
};
</script>

<style lang="less">
Expand Down
Loading

0 comments on commit e3d6bc3

Please sign in to comment.