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

Fix 时间选择器手动输入日期无效问题 #94

Merged
merged 3 commits into from
Aug 16, 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
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { getSyncHistory } from '@/http';
import TableEmpty from '@/components/table-empty.vue';
import { Message } from 'bkui-vue';

const router = useRouter();
const { t, locale } = useI18n();
Expand Down Expand Up @@ -270,10 +271,16 @@ const handleTimeClear = () => {
};

const handleTimeChange = () => {
pagination.current = 1;
nextTick(() => {
getComponents();
});
const internalValue = topDatePicker.value?.internalValue;
if (internalValue) {
dateTimeRange.value = internalValue;
pagination.current = 1;
nextTick(() => {
getComponents();
});
} else {
Message({ theme: 'warning', message: t('输入的时间错误'), delay: 2000, dismissable: false });
}
};

const init = () => {
Expand Down
31 changes: 20 additions & 11 deletions src/dashboard-front/src/views/monitor/alarm-history/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<bk-form class="flex-row">
<bk-form-item :label="t('选择时间')" class="ag-form-item-datepicker" label-width="85">
<bk-date-picker
ref="datePickerRef"
class="w320" v-model="initDateTimeRange" :key="dateKey"
:placeholder="t('选择日期时间范围')" :type="'datetimerange'"
:shortcuts="datepickerShortcuts" :shortcut-close="true" :use-shortcut-text="true" @clear="handleTimeClear"
Expand Down Expand Up @@ -150,6 +151,7 @@ import {
} from '@/http';
import { cloneDeep } from 'lodash';
import TableEmpty from '@/components/table-empty.vue';
import { Message } from 'bkui-vue';

const { t } = useI18n();
const common = useCommon();
Expand All @@ -163,6 +165,7 @@ const scrollLoading = ref<boolean>(false);
const initDateTimeRange = ref([]);
const alarmStrategies = ref([]);
const curStrategyCount = ref<number>(0);
const datePickerRef = ref(null);
const initParams = reactive({
limit: 10,
offset: 0,
Expand Down Expand Up @@ -225,17 +228,23 @@ const handleShortcutChange = (value: any, index: any) => {
};
// 日期快捷方式改变触发
const handleTimeChange = () => {
nextTick(async () => {
const startStr: any = (+new Date(`${initDateTimeRange.value[0]}`)) / 1000;
const endStr: any = (+new Date(`${initDateTimeRange.value[1]}`)) / 1000;
// eslint-disable-next-line radix
const satrt: any = parseInt(startStr);
// eslint-disable-next-line radix
const end: any = parseInt(endStr);
filterData.value.time_start = satrt;
filterData.value.time_end = end;
await fetchRefreshTable();
});
const internalValue = datePickerRef.value?.internalValue;
if (internalValue) {
initDateTimeRange.value = internalValue;
nextTick(async () => {
const startStr: any = (+new Date(`${initDateTimeRange.value[0]}`)) / 1000;
const endStr: any = (+new Date(`${initDateTimeRange.value[1]}`)) / 1000;
// eslint-disable-next-line radix
const satrt: any = parseInt(startStr);
// eslint-disable-next-line radix
const end: any = parseInt(endStr);
filterData.value.time_start = satrt;
filterData.value.time_end = end;
await fetchRefreshTable();
});
} else {
Message({ theme: 'warning', message: t('输入的时间错误'), delay: 2000, dismissable: false });
}
};

// 获取状态name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import { useI18n } from 'vue-i18n';
import { useAccessLog, useCommon } from '@/store';
import editorMonaco from '@/components/ag-editor.vue';
import { getTestHistories, getTestHistoriesDetails } from '@/http';
import { Message } from 'bkui-vue';

const { t } = useI18n();
const common = useCommon();
Expand All @@ -109,6 +110,7 @@ const filterData = ref<any>({
});
const dateTimeRange = ref([]);
const dateKey = ref('dateKey');
const topDatePicker = ref(null);
const AccessLogStore = useAccessLog();
const shortcutSelectedIndex = shallowRef(-1);
const tableRef = ref(null);
Expand Down Expand Up @@ -153,7 +155,13 @@ const setSearchTimeRange = () => {
};

const handleTimeChange = () => {
setSearchTimeRange();
const internalValue = topDatePicker.value?.internalValue;
if (internalValue) {
dateTimeRange.value = internalValue;
setSearchTimeRange();
} else {
Message({ theme: 'warning', message: t('输入的时间错误'), delay: 2000, dismissable: false });
}
};

const handleTimeClear = () => {
Expand Down
29 changes: 19 additions & 10 deletions src/dashboard-front/src/views/permission/record/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<bk-form class="flex-row">
<bk-form-item :label="t('选择时间')" class="ag-form-item-datepicker mb15" label-width="85">
<bk-date-picker
ref="datePickerRef"
class="w320" v-model="initDateTimeRange" :placeholder="t('选择日期时间范围')" :key="dateKey"
:type="'datetimerange'" :shortcuts="datepickerShortcuts" :shortcut-close="true" :use-shortcut-text="true"
@clear="handleTimeClear" :shortcut-selected-index="shortcutSelectedIndex"
Expand Down Expand Up @@ -179,6 +180,7 @@ import { useCommon } from '@/store';
import { useQueryList } from '@/hooks';
import { sortByKey } from '@/common/util';
import TableEmpty from '@/components/table-empty.vue';
import { Message } from 'bkui-vue';

const { t } = useI18n();

Expand All @@ -196,6 +198,7 @@ const initDateTimeRange = ref([]);
const resourceList = ref([]);
const shortcutSelectedIndex = ref<number>(-1);
const dateKey = ref('dateKey');
const datePickerRef = ref(null);
const curRecord = ref({
bk_app_code: '',
applied_by: '',
Expand Down Expand Up @@ -386,16 +389,22 @@ const handleShortcutChange = (value: any, index: any) => {
};
// 日期快捷方式改变触发
const handleTimeChange = () => {
nextTick(() => {
const startStr: any = (+new Date(`${initDateTimeRange.value[0]}`)) / 1000;
const endStr: any = (+new Date(`${initDateTimeRange.value[1]}`)) / 1000;
// eslint-disable-next-line radix
const satrt: any = parseInt(startStr);
// eslint-disable-next-line radix
const end: any = parseInt(endStr);
filterData.value.time_start = satrt;
filterData.value.time_end = end;
});
const internalValue = datePickerRef.value?.internalValue;
if (internalValue) {
initDateTimeRange.value = internalValue;
nextTick(() => {
const startStr: any = (+new Date(`${initDateTimeRange.value[0]}`)) / 1000;
const endStr: any = (+new Date(`${initDateTimeRange.value[1]}`)) / 1000;
// eslint-disable-next-line radix
const satrt: any = parseInt(startStr);
// eslint-disable-next-line radix
const end: any = parseInt(endStr);
filterData.value.time_start = satrt;
filterData.value.time_end = end;
});
} else {
Message({ theme: 'warning', message: t('输入的时间错误'), delay: 2000, dismissable: false });
}
};
// 展示详情
const handleShowRecord = (e: Event, data: any) => {
Expand Down
13 changes: 12 additions & 1 deletion src/dashboard-front/src/views/stage/published/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
:key="dateKey"
@change="handleChange"
@clear="handleClear"
@pick-success="handleComfirm">
@pick-success="handlePickSuccess">
</bk-date-picker>
</div>
<div class="flex-row justify-content-end">
Expand Down Expand Up @@ -113,6 +113,7 @@ import {
getReleaseHistories,
} from '@/http';
import TableEmpty from '@/components/table-empty.vue';
import { Message } from 'bkui-vue';

const router = useRouter();

Expand Down Expand Up @@ -221,6 +222,16 @@ const getTextFromEnum = (e: Enums, key?: unknown) => {
return t(e[key as keyof Enums]);
};

const handlePickSuccess = () => {
const internalValue = datePickerRef.value?.internalValue;
if (internalValue) {
dateValue.value = internalValue;
handleComfirm();
} else {
Message({ theme: 'warning', message: t('输入的时间错误'), delay: 2000, dismissable: false });
}
};

watch(() => filterData.value, () => {
updateTableEmptyConfig();
}, {
Expand Down
Loading