Skip to content

Commit

Permalink
feat(frontend): 轮值支持排除业务、指定部分业务 TencentBlueKing#8922
Browse files Browse the repository at this point in the history
  • Loading branch information
jinquantianxia committed Jan 7, 2025
1 parent 1edaaf4 commit f435c3f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
display: none;
width: 20px;
height: 20px;
margin-top: -15px;
margin-top: -10px;
font-size: 12px;
line-height: 20px;
color: #979ba5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
{
label: t('状态'),
field: 'status',
minWidth: 150,
width: 120,
render: ({ data }: {data: DutyRuleModel}) => {
const { label, theme } = statusMap[data.status as RuleStatus];
return <bk-tag theme={theme}>{label}</bk-tag>;
Expand Down Expand Up @@ -245,7 +245,7 @@
label: t('轮值表'),
field: 'duty_arranges',
showOverflowTooltip: false,
width: 250,
width: 280,
render: ({ data }: {data: DutyRuleModel}) => {
let title = '';
if (data.status in statusMap) {
Expand Down Expand Up @@ -331,7 +331,7 @@
fixed: 'right',
showOverflowTooltip: false,
field: '',
width: 180,
width: 120,
render: ({ data }: {data: DutyRuleModel}) => (
<div class="operate-box">
<auth-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,34 @@
-->

<template>
<div class="title-spot custom-item-title mt-24">{{ t('轮值起止时间') }}<span class="required" /></div>
<BkDatePicker
ref="datePickerRef"
v-model="dateTimeRange"
append-to-body
:clearable="false"
style="width: 100%"
type="daterange"
@change="handleDatetimeRangeChange" />
<div class="title-spot custom-item-title mt-24">{{ t('轮值排班') }}<span class="required" /></div>
<DbOriginalTable
class="custom-table-box"
:columns="columns"
:data="tableData" />
<BkForm
ref="formRef"
class="mt-24"
form-type="vertical"
:model="formModel">
<BkFormItem
:label="t('轮值起止时间')"
property="dateTimeRange"
required>
<BkDatePicker
ref="datePickerRef"
v-model="formModel.dateTimeRange"
append-to-body
:clearable="false"
style="width: 100%"
type="daterange"
@change="handleDatetimeRangeChange" />
</BkFormItem>
<BkFormItem
:label="t('轮值排班')"
property="tableData"
required>
<DbOriginalTable
class="custom-table-box"
:columns="columns"
:data="formModel.tableData" />
</BkFormItem>
</BkForm>
</template>

<script setup lang="tsx">
Expand Down Expand Up @@ -53,23 +67,27 @@
}

interface Exposes {
getValue: () => {
getValue: () => Promise<{
effective_time: string,
end_time: string,
duty_arranges:{
date: string,
work_times: string[],
members: string[],
}[],
}
}>
}

const props = defineProps<Props>();

const { t } = useI18n();

const dateTimeRange = ref<[string, string]>();
const tableData = ref<RowData[]>([]);
const formRef = ref();

const formModel = reactive({
dateTimeRange: undefined as [string, string] | undefined,
tableData: [] as RowData[],
});

const columns = [
{
Expand Down Expand Up @@ -127,8 +145,8 @@
}

if (data && data.category === 'regular') {
dateTimeRange.value = [data.effective_time, data.end_time];
tableData.value = (data.duty_arranges as DutyCustomItem[]).map(item => ({
formModel.dateTimeRange = [data.effective_time, data.end_time];
formModel.tableData = (data.duty_arranges as DutyCustomItem[]).map(item => ({
dateTime: item.date,
timeRange: item.work_times.map(i => ({
id: random(),
Expand All @@ -137,44 +155,48 @@
members: item.members,
}));
} else {
tableData.value = []
formModel.tableData = []
}
}, {
immediate: true,
});


const handleDatetimeRangeChange = (value: [string, string]) => {
dateTimeRange.value = value;
formModel.dateTimeRange = value;
const dateArr = getDiffDays(value[0], value[1]);
tableData.value = dateArr.map(item => ({
formModel.tableData = dateArr.map(item => ({
dateTime: item,
timeRange: [{
id: random(),
value: ['00:00:00', '23:59:59'],
}],
members: [],
}));
nextTick(() => {
formRef.value.validate('tableData');
})
}

const handelPeopleChange = (value: string[], index: number) => {
tableData.value[index].members = value
formModel.tableData[index].members = value
}

const handleAddTime = (index: number) => {
tableData.value[index].timeRange.push({
formModel.tableData[index].timeRange.push({
id: random(),
value: ['00:00:00', '23:59:59'],
});
};

const handleDeleteTime = (outerIndex: number, innerIndex: number) => {
tableData.value[outerIndex].timeRange.splice(innerIndex, 1);
formModel.tableData[outerIndex].timeRange.splice(innerIndex, 1);
};


defineExpose<Exposes>({
getValue() {
async getValue() {
await formRef.value.validate();
const splitTimeToMinute = (str: string) => {
const strArr = str.split(':');
if (strArr.length <= 2) {
Expand All @@ -184,9 +206,9 @@
return strArr.join(':');
};
return {
effective_time: dayjs(dateTimeRange.value![0]).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
end_time: dayjs(dateTimeRange.value![1]).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
duty_arranges: tableData.value.map(item => ({
effective_time: dayjs(formModel.dateTimeRange![0]).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
end_time: dayjs(formModel.dateTimeRange![1]).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
duty_arranges: formModel.tableData.map(item => ({
date: item.dateTime,
work_times: item.timeRange.map(data => data.value.map(str => splitTimeToMinute(str)).join('--')),
members: item.members,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
property="peopleList"
required>
<span class="cycle-title-tip">({{ t('排班时将会按照人员的顺序进行排班,可拖动 Tag 进行排序') }})</span>
<MemberSelector v-model="formModel.peopleList" />
<MemberSelector
v-model="formModel.peopleList"
@change="handleMemberSelectorChange" />
</BkFormItem>
<div class="cycle-duty-box">
<BkFormItem
Expand Down Expand Up @@ -137,10 +139,7 @@

import MemberSelector from '@components/db-member-selector/index.vue';

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

interface RowData {
dateTime: string,
Expand Down Expand Up @@ -375,12 +374,15 @@
dateSelect.value.date = workType;
let workdays = arranges[0].work_days;
workdays = workType === 'weekly' ? workdays.map(num => (num === 7 ? 0 : num)) : workdays;
dateSelect.value.weekday = workdays;
dateSelect.value.weekday = workdays || [];
}
}, {
immediate: true,
});

const handleMemberSelectorChange = () => {
formRef.value.validate('peopleList');
}

const handleAddTime = () => {
dateSelect.value.timeList.push({
Expand All @@ -396,6 +398,7 @@

defineExpose<Exposes>({
async getValue() {
await formRef.value.validate();
const splitTimeToMinute = (str: string) => {
const strArr = str.split(':');
if (strArr.length <= 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@
const errorMessage = ref('');
watch(
() => props.data.biz_config,
() => props.data?.biz_config,
(bizConfig) => {
if (!bizConfig) {
return;
}
if (bizConfig.exclude) {
excludeBizs.value = bizConfig.exclude;
modelValue.value = 'all';
Expand Down

0 comments on commit f435c3f

Please sign in to comment.