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): sqlserver 工具箱 #3485 #6721

Merged
merged 1 commit into from
Sep 6, 2024
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
11 changes: 7 additions & 4 deletions dbm-ui/frontend/src/components/time-zone-picker/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
:model-value="localValue"
:no-match-text="t('无匹配数据')"
:placeholder="t('请输入搜索(国家,城市,简称)')"
:popover-options="{ 'ext-cls': '__bk-date-picker-popover__' }"
:search-placeholder="t('请输入搜索(国家,城市,简称)')"
@change="handleChange">
<template #trigger>
Expand Down Expand Up @@ -94,7 +93,7 @@
import { shallowRef } from 'vue';
import { useI18n } from 'vue-i18n';

import { useTimeZone } from '@stores';
import { useTimeZoneFormat } from '@hooks';

import { encodeRegexp } from '@utils';

Expand Down Expand Up @@ -1642,7 +1641,7 @@
};

const { t } = useI18n();
const timeZoneStore = useTimeZone();
const { timeZone } = useTimeZoneFormat();

const timezoneDetails = getTimezoneDetails();

Expand All @@ -1659,7 +1658,11 @@
(val) => {
const info = getTimezoneInfoByValue(val);
selected.value = info;
timeZoneStore.update(info);
timeZone.value = {
...info,
utc: info.utc.substring(3),
};

emits('change', val, info);
},
{
Expand Down
21 changes: 16 additions & 5 deletions dbm-ui/frontend/src/hooks/useTimeZoneFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,30 @@
* the specific language governing permissions and limitations under the License.
*/
import dayjs from 'dayjs';

import { useTimeZone } from '@stores';
import { ref } from 'vue';

export const useTimeZoneFormat = () => {
const timeZoneStore = useTimeZone();
return (date: string) => {
const timeZone = ref({
abbreviation: '',
country: '',
countryCode: '',
label: '',
utc: '',
});

const format = (date: string) => {
if (!date) {
return '';
}

const targetDate = dayjs(date).format('YYYY-MM-DD HH:mm:ss');
const prefixStr = targetDate.split(' ').join('T');
const suffixStr = timeZoneStore.utc === '' ? '+00:00' : timeZoneStore.utc;
const suffixStr = timeZone.value.utc === '' ? '+00:00' : timeZone.value.utc;
return `${prefixStr}${suffixStr}`;
};

return {
timeZone,
format,
};
};
1 change: 1 addition & 0 deletions dbm-ui/frontend/src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3490,5 +3490,6 @@
"库表名支持数字、字母、中划线、下划线,最大35字符": "库表名支持数字、字母、中划线、下划线,最大35字符",
"不允许输入系统库和特殊库": "不允许输入系统库和特殊库",
"不能以stage_truncate开头或dba_rollback结尾": "不能以 stage_truncate 开头或 dba_rollback 结尾",
"备份记录(d):预期返回 n 个 DB 的备份记录,实际返回 m 个": "备份记录({0}):预期返回 {1} 个 DB 的备份记录,实际返回 {2} 个",
"这行勿动!新增翻译请在上一行添加!": ""
}
1 change: 0 additions & 1 deletion dbm-ui/frontend/src/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ export * from './useMenu';
export * from './useSqlImport';
export * from './useSQLTaskCount';
export * from './useSystemEnviron';
export * from './useTimeZone';
export * from './useUserProfile';
44 changes: 0 additions & 44 deletions dbm-ui/frontend/src/stores/useTimeZone.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
import TimeZonePicker from '@components/time-zone-picker/index.vue';

const { t } = useI18n();
const formatDateToUTC = useTimeZoneFormat();
const { format: formatDateToUTC } = useTimeZoneFormat();

const modelValue = defineModel<{
mode: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
const disableDate = (date: Date) => date && date.valueOf() > Date.now();

const { t } = useI18n();
const formatDateToUTC = useTimeZoneFormat();
const { format: formatDateToUTC } = useTimeZoneFormat();

const timerRules = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
});

const { t } = useI18n();
const formatDateToUTC = useTimeZoneFormat();
const { format: formatDateToUTC } = useTimeZoneFormat();

const editRef = ref();
const isNowTime = ref(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
});

const { t } = useI18n();
const formatDateToUTC = useTimeZoneFormat();
const { format: formatDateToUTC } = useTimeZoneFormat();

const editRef = ref();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
const disableDate = (date: Date) => date && date.valueOf() > Date.now();

const { t } = useI18n();
const formatDateToUTC = useTimeZoneFormat();
const { format: formatDateToUTC } = useTimeZoneFormat();

const rules = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
</div>
</template>
<script setup lang="ts">
import dayjs from 'dayjs';
import _ from 'lodash';
import tippy, { type Instance, type SingleTarget } from 'tippy.js';
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
Expand All @@ -138,9 +137,17 @@
queryLatesBackupLog,
} from '@services/source/fixpointRollback';

import { useDebouncedRef } from '@hooks';
import { useDebouncedRef, useTimeZoneFormat } from '@hooks';

import { useGlobalBizs, useTimeZone } from '@stores';
import { useGlobalBizs } from '@stores';

const props = withDefaults(defineProps<Props>(), {
backupid: '',
backupSource: '',
modelValue: '',
disabled: false,
clearable: false,
});

import useValidtor, { type Rules } from '@components/render-table/hooks/useValidtor';

Expand All @@ -163,16 +170,9 @@
getValue: () => Promise<BackupLogRecord>;
}

const props = withDefaults(defineProps<Props>(), {
backupid: '',
backupSource: '',
modelValue: '',
disabled: false,
clearable: false,
});

let tippyIns: Instance;
const { t } = useI18n();
const { format: formatDateToUTC } = useTimeZoneFormat();

enum OperateType {
MANUAL = 'maunal',
Expand Down Expand Up @@ -220,7 +220,6 @@

const { message: errorMessage, validator } = useValidtor(rules);
const { currentBizId } = useGlobalBizs();
const timeZoneStore = useTimeZone();
const searchKey = useDebouncedRef('');

const rootRef = ref();
Expand Down Expand Up @@ -249,11 +248,37 @@

const renderText = computed(() => {
const item = _.find(logRecordList.value, (i) => i.backup_id === localValue.value) as BackupLogRecord;
return !item
? ''
: `${item.mysql_role ? `${item.mysql_role} ` : ' '}${dayjs(item.backup_time).tz(timeZoneStore.label).format('YYYY-MM-DD HH:mm:ss ZZ')}`;
return !item ? '' : `${item.mysql_role ? `${item.mysql_role} ` : ' '}${formatDateToUTC(item.backup_time)}`;
});

watch(
() => [props.backupSource, props.clusterId],
() => {
if (!props.clusterId || !props.backupSource) {
return;
}
fetchLogData();
},
{
immediate: true,
},
);

watch(
() => props.backupid,
(newVal) => {
if (newVal) {
validator(newVal);
const currentRecordType = isDateType(newVal) ? OperateType.MATCH : OperateType.MANUAL;
hanldeChangeTab(currentRecordType);
localValue.value = newVal;
}
},
{
immediate: true,
},
);

const fetchLogData = () => {
logRecordOptions.value = [];
logRecordList.value = [];
Expand All @@ -263,7 +288,7 @@
}).then((dataList) => {
logRecordOptions.value = dataList.map((item) => ({
id: item.backup_id,
name: `${item.mysql_role ? `${item.mysql_role} ` : ' '} ${dayjs(item.backup_time).tz(timeZoneStore.label).format('YYYY-MM-DD HH:mm:ss ZZ')}`,
name: `${item.mysql_role ? `${item.mysql_role} ` : ' '} ${formatDateToUTC(item.backup_time)}`,
}));
logRecordList.value = dataList;
});
Expand Down Expand Up @@ -346,34 +371,6 @@
}
});

watch(
() => [props.backupSource, props.clusterId, timeZoneStore.label],
() => {
if (!props.clusterId || !props.backupSource) {
return;
}
fetchLogData();
},
{
immediate: true,
},
);

watch(
() => props.backupid,
(newVal) => {
if (newVal) {
validator(newVal);
const currentRecordType = isDateType(newVal) ? OperateType.MATCH : OperateType.MANUAL;
hanldeChangeTab(currentRecordType);
localValue.value = newVal;
}
},
{
immediate: true,
},
);

defineExpose<Exposes>({
getValue() {
return validator(localValue.value).then(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
});

const { t } = useI18n();
const formatDateToUTC = useTimeZoneFormat();
const { format: formatDateToUTC } = useTimeZoneFormat();

const editRef = ref();
const dateValue = ref(props.data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
const { t } = useI18n();
const router = useRouter();
const { currentBizId } = useGlobalBizs();
const formatDateToUTC = useTimeZoneFormat();
const { format: formatDateToUTC } = useTimeZoneFormat();

const rowRefs = ref();
const isShowBatchSelector = ref(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
});

const { t } = useI18n();
const formatDateToUTC = useTimeZoneFormat();
const { format: formatDateToUTC } = useTimeZoneFormat();

const editRef = ref();
const isNowTime = ref(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
});

const { t } = useI18n();
const formatDateToUTC = useTimeZoneFormat();
const { format: formatDateToUTC } = useTimeZoneFormat();

const editRef = ref();

Expand Down
Loading
Loading