From a1e9064bb4c0a41c9a1e389cdd0f0f9bab009309 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期日, 08 十一月 2026 09:45:52 +0800
Subject: [PATCH] feat(hrm): 请假批量导入、加班选申请人、批量排班与节假日区间联动
---
src/views/hrm/schedule/index.vue | 313 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 308 insertions(+), 5 deletions(-)
diff --git a/src/views/hrm/schedule/index.vue b/src/views/hrm/schedule/index.vue
index 891cc11..703268b 100644
--- a/src/views/hrm/schedule/index.vue
+++ b/src/views/hrm/schedule/index.vue
@@ -17,6 +17,7 @@
Modal,
Pagination,
Radio,
+ RangePicker,
Segmented,
Select,
TreeSelect,
@@ -24,10 +25,16 @@
import { Page } from '#/packages/effects/common-ui/src';
+import { getAttendanceHolidayList } from '#/api/hrm/attendance/holiday';
import { getEmployeePage } from '#/api/hrm/employee';
import { getShiftList } from '#/api/hrm/shift';
-import { getEmployeeScheduleList, saveEmployeeSchedule } from '#/api/hrm/schedule';
+import {
+ batchSaveEmployeeSchedule,
+ getEmployeeScheduleList,
+ saveEmployeeSchedule,
+} from '#/api/hrm/schedule';
import { getDeptList } from '#/api/system/dept';
+import { getSimplePostList } from '#/api/system/post';
import { handleTree } from '#/packages/utils/src';
import {
@@ -59,6 +66,10 @@
// ========== 鏁版嵁 ==========
const employees = ref<HrmEmployeeApi.Employee[]>([]);
const shiftList = ref<HrmShiftApi.Shift[]>([]);
+/**
+ * 褰撳墠瑙嗗浘鏃ユ湡鑼冨洿鍐呯殑鑺傚亣鏃ラ厤缃細key = yyyy-MM-dd锛寁alue = 1-浼戞伅鏃� / 2-宸ヤ綔鏃�
+ */
+const holidayMap = ref(new Map<string, number>());
const loading = ref(false);
const saving = ref(false);
/** 鏄惁宸叉墽琛岃繃鏌ヨ */
@@ -150,8 +161,14 @@
const week = new Date(
`${month.value}-${String(day).padStart(2, '0')}`,
).getDay();
+ // 鑺傚亣鏃ラ厤缃紭鍏堬細浼戞伅鏃ュ己鍒朵紤鎭紝宸ヤ綔鏃ュ己鍒舵帓鐝紙鍚皟浼戜笂鐝殑鍛ㄦ湯锛�
+ const holidayType = getHolidayType(date);
let rest = false;
- if (autoRestMode.value === REST_MODE.DOUBLE) {
+ if (holidayType === 1) {
+ rest = true;
+ } else if (holidayType === 2) {
+ rest = false;
+ } else if (autoRestMode.value === REST_MODE.DOUBLE) {
rest = week === 0 || week === 6;
} else if (autoRestMode.value === REST_MODE.SINGLE) {
rest = week === 0;
@@ -162,6 +179,100 @@
scheduleMap.value = map;
autoOpen.value = false;
message.success('鑷姩鎺掔彮宸茬敓鎴愶紝鍙墜鍔ㄥ井璋冨悗淇濆瓨');
+}
+
+// ========== 鎸夌兢浣撴壒閲忔帓鐝紙涓�绫讳汉涓�娆℃帓瀹岋級 ==========
+const batchOpen = ref(false);
+const batchDeptId = ref<number>();
+const batchPostId = ref<number>();
+/** 0-鍦ㄨ亴鍙婅瘯鐢紝1-鍦ㄨ亴锛�2-璇曠敤锛�3-绂昏亴 */
+const batchEmployeeStatus = ref<number>(0);
+/** 0 琛ㄧず浼戞伅锛堟竻闄ゆ帓鐝級 */
+const batchShiftId = ref<number>();
+const batchRestMode = ref<RestMode>(REST_MODE.DOUBLE);
+const batchDateRange = ref<[string, string]>();
+const batchSaving = ref(false);
+const postList = ref<{ label: string; value: number }[]>([]);
+
+const batchEmployeeStatusOptions = [
+ { label: '鍦ㄨ亴鍙婅瘯鐢�', value: 0 },
+ { label: '鍦ㄨ亴', value: 1 },
+ { label: '璇曠敤', value: 2 },
+ { label: '绂昏亴', value: 3 },
+];
+
+const batchShiftOptions = computed(() => [
+ { label: '浼戞伅锛堟竻闄ゆ帓鐝級', value: 0 },
+ ...shiftList.value.map((shift) => ({
+ label: `${shift.name} (${shift.startTime}~${shift.endTime})`,
+ value: shift.id!,
+ })),
+]);
+
+async function loadPostList() {
+ if (postList.value.length > 0) {
+ return;
+ }
+ const posts = await getSimplePostList();
+ postList.value = posts.map((post) => ({
+ label: post.name,
+ value: post.id!,
+ }));
+}
+
+async function openBatch() {
+ if (!month.value) {
+ message.warning('璇峰厛閫夋嫨鏈堜唤');
+ return;
+ }
+ if (shiftList.value.length === 0) {
+ shiftList.value = await getShiftList();
+ }
+ batchDeptId.value = deptId.value;
+ batchPostId.value = undefined;
+ batchEmployeeStatus.value = 0;
+ batchShiftId.value = shiftList.value[0]?.id;
+ batchRestMode.value = REST_MODE.DOUBLE;
+ batchDateRange.value = [
+ `${month.value}-01`,
+ dayjs(`${month.value}-01`).endOf('month').format('YYYY-MM-DD'),
+ ];
+ batchOpen.value = true;
+ await loadPostList();
+}
+
+async function applyBatchSchedule() {
+ if (!batchDeptId.value) {
+ message.warning('璇烽�夋嫨閮ㄩ棬');
+ return;
+ }
+ if (!batchDateRange.value?.[0] || !batchDateRange.value?.[1]) {
+ message.warning('璇烽�夋嫨鎺掔彮鏃ユ湡鑼冨洿');
+ return;
+ }
+ if (batchShiftId.value == null) {
+ message.warning('璇烽�夋嫨鎺掔彮鐝鎴栦紤鎭�');
+ return;
+ }
+ batchSaving.value = true;
+ try {
+ const result = await batchSaveEmployeeSchedule({
+ deptId: batchDeptId.value,
+ postId: batchPostId.value,
+ employeeStatus: batchEmployeeStatus.value || undefined,
+ startDate: batchDateRange.value[0],
+ endDate: batchDateRange.value[1],
+ shiftId: batchShiftId.value === 0 ? null : batchShiftId.value,
+ restMode: batchRestMode.value,
+ });
+ message.success(
+ `鎵归噺鎺掔彮瀹屾垚锛氬叡 ${result.employeeCount ?? 0} 鍚嶅憳宸ワ紝鍐欏叆/娓呴櫎 ${result.itemCount ?? 0} 鏉℃帓鐝璥,
+ );
+ batchOpen.value = false;
+ await loadData();
+ } finally {
+ batchSaving.value = false;
+ }
}
/** 鐝 id 鈫� 鐝 鏄犲皠 */
@@ -237,6 +348,67 @@
};
});
});
+
+/** 鏌愭棩鑺傚亣鏃ョ被鍨嬶細1-浼戞伅鏃ワ紝2-宸ヤ綔鏃ワ紝undefined-鏈厤缃� */
+function getHolidayType(date: string): number | undefined {
+ return holidayMap.value.get(date);
+}
+
+/** 鑺傚亣鏃ヨ鏍囨枃妗堬細浼� / 鐝� */
+function holidayLabel(date: string): string {
+ const type = getHolidayType(date);
+ if (type === 1) {
+ return '浼�';
+ }
+ if (type === 2) {
+ return '鐝�';
+ }
+ return '';
+}
+
+/** 鍔犺浇褰撳墠瑙嗗浘鏃ユ湡鑼冨洿鍐呯殑鑺傚亣鏃ラ厤缃� */
+async function loadHolidays() {
+ const list = viewDays.value;
+ const first = list[0];
+ const last = list[list.length - 1];
+ if (!first || !last) {
+ holidayMap.value = new Map();
+ return;
+ }
+ const holidays = await getAttendanceHolidayList({
+ startDate: first.date,
+ endDate: last.date,
+ });
+ const map = new Map<string, number>();
+ for (const item of holidays) {
+ if (item.date) {
+ map.set(item.date, item.type ?? 1);
+ }
+ }
+ holidayMap.value = map;
+}
+
+/** 瑙嗗浘鏃ユ湡鍙樺寲锛堝垏鏈�/鍒囧懆/鍒囪鍥撅級鏃堕噸鏂版媺鍙栬妭鍋囨棩 */
+watch(
+ () => viewDays.value.map((vd) => vd.date).join(','),
+ (key) => {
+ if (key) {
+ loadHolidays();
+ }
+ },
+);
+
+/** 鑺傚亣鏃ユ爣璁扮殑鍗曞厓鏍�/琛ㄥご閰嶈壊 */
+function holidayClass(date: string): string {
+ const type = getHolidayType(date);
+ if (type === 1) {
+ return 'holiday-rest';
+ }
+ if (type === 2) {
+ return 'holiday-work';
+ }
+ return '';
+}
/** 鍛ㄨ鍥惧綋鍓嶆樉绀鸿寖鍥存爣绛� */
const weekRangeLabel = computed(() => {
@@ -464,6 +636,9 @@
<Button :disabled="!employees.length" @click="autoOpen = true">
鑷姩鎺掔彮
</Button>
+ <Button type="primary" ghost :disabled="!month" @click="openBatch">
+ 鎵归噺鎺掔彮锛堟寜浜虹兢锛�
+ </Button>
<Button
type="primary"
:loading="saving"
@@ -545,11 +720,22 @@
:key="vd.date"
:class="[
'schedule-date-col text-center',
- vd.isWeekend ? 'bg-red-50' : 'bg-gray-50',
+ holidayClass(vd.date)
+ ? holidayClass(vd.date)
+ : vd.isWeekend
+ ? 'bg-red-50'
+ : 'bg-gray-50',
]"
>
<div class="font-medium">{{ vd.day }}</div>
- <div class="text-xs text-gray-400">{{ vd.weekLabel }}</div>
+ <div class="text-xs text-gray-400">
+ {{ vd.weekLabel }}
+ <span
+ v-if="holidayLabel(vd.date)"
+ class="holiday-tag"
+ >{{ holidayLabel(vd.date) }}</span
+ >
+ </div>
</th>
</tr>
</thead>
@@ -569,7 +755,7 @@
v-for="vd in viewDays"
:key="vd.date"
class="schedule-cell"
- :class="[vd.isWeekend ? 'bg-red-50/40' : '']"
+ :class="[vd.isWeekend ? 'bg-red-50/40' : '', holidayClass(vd.date)]"
@click="openPicker(emp, vd.date)"
>
<span
@@ -681,6 +867,96 @@
</div>
</div>
</Modal>
+
+ <!-- 鎸変汉缇ゆ壒閲忔帓鐝脊绐楋細閫夐儴闂�/宀椾綅/鍦ㄨ亴鐘舵�� + 鏃ユ湡鑼冨洿 + 鐝锛屼竴娆℃帓瀹屼竴绫讳汉 -->
+ <Modal
+ v-model:open="batchOpen"
+ title="鎵归噺鎺掔彮锛堟寜浜虹兢锛�"
+ :footer="null"
+ :width="520"
+ >
+ <div class="space-y-4">
+ <div>
+ <div class="mb-1.5 text-sm text-gray-500">
+ 閮ㄩ棬锛堝惈涓嬬骇閮ㄩ棬锛�<span class="text-red-500">*</span>
+ </div>
+ <TreeSelect
+ v-model:value="batchDeptId"
+ :tree-data="deptTree"
+ :field-names="{ label: 'name', value: 'id', children: 'children' }"
+ allow-clear
+ placeholder="璇烽�夋嫨閮ㄩ棬"
+ tree-default-expand-all
+ style="width: 100%"
+ />
+ </div>
+ <div class="grid grid-cols-2 gap-3">
+ <div>
+ <div class="mb-1.5 text-sm text-gray-500">宀椾綅</div>
+ <Select
+ v-model:value="batchPostId"
+ :options="postList"
+ allow-clear
+ placeholder="涓嶉檺宀椾綅"
+ show-search
+ option-filter-prop="label"
+ style="width: 100%"
+ />
+ </div>
+ <div>
+ <div class="mb-1.5 text-sm text-gray-500">鍛樺伐鐘舵��</div>
+ <Select
+ v-model:value="batchEmployeeStatus"
+ :options="batchEmployeeStatusOptions"
+ style="width: 100%"
+ />
+ </div>
+ </div>
+ <div>
+ <div class="mb-1.5 text-sm text-gray-500">
+ 鎺掔彮鏃ユ湡鑼冨洿<span class="text-red-500">*</span>
+ </div>
+ <RangePicker
+ v-model:value="batchDateRange"
+ value-format="YYYY-MM-DD"
+ :allow-clear="false"
+ style="width: 100%"
+ />
+ </div>
+ <div>
+ <div class="mb-1.5 text-sm text-gray-500">
+ 鎺掔彮鐝<span class="text-red-500">*</span>
+ </div>
+ <Select
+ v-model:value="batchShiftId"
+ :options="batchShiftOptions"
+ placeholder="璇烽�夋嫨鐝锛屾垨閫夋嫨浼戞伅"
+ style="width: 100%"
+ />
+ </div>
+ <div v-if="batchShiftId !== 0">
+ <div class="mb-1.5 text-sm text-gray-500">浼戞伅妯″紡</div>
+ <Radio.Group
+ v-model:value="batchRestMode"
+ :options="REST_MODE_OPTIONS"
+ option-type="button"
+ />
+ </div>
+ <div class="rounded bg-blue-50 px-3 py-2 text-xs text-blue-600">
+ 灏嗗鎵�閫夐儴闂�/宀椾綅/鍦ㄨ亴鐘舵�佺殑鍏ㄩ儴鍛樺伐锛屽湪鏃ユ湡鑼冨洿鍐呴�愭棩鎺掔彮锛歿{
+ batchShiftId === 0
+ ? '閫夋嫨銆屼紤鎭�嶅皢娓呴櫎璇ヨ寖鍥村唴宸叉湁鎺掔彮銆�'
+ : '鎸変笂鏂逛紤鎭ā寮忚烦杩囧懆鏈紝鍏朵綑鏃ユ湡鎺掓墍閫夌彮娆°��'
+ }}宸查厤缃妭鍋囨棩鐨勬棩鏈熶互鑺傚亣鏃ヤ负鍑嗭細浼戞伅鏃ュ己鍒朵紤鎭紝宸ヤ綔鏃ュ己鍒舵帓鐝紙鍚皟浼戜笂鐝殑鍛ㄦ湯锛夈��
+ </div>
+ <div class="flex justify-end gap-2">
+ <Button @click="batchOpen = false">鍙栨秷</Button>
+ <Button type="primary" :loading="batchSaving" @click="applyBatchSchedule">
+ 寮�濮嬫帓鐝�
+ </Button>
+ </div>
+ </div>
+ </Modal>
</Page>
</template>
@@ -740,6 +1016,33 @@
}
}
+ /* 鑺傚亣鏃ユ爣璁帮細浼戞伅鏃ユ鑹层�佽皟浼戝伐浣滄棩缁胯壊锛屼紭鍏堜簬鍛ㄦ湯搴曡壊 */
+ .holiday-rest {
+ background-color: #fff1e6 !important;
+ }
+
+ .holiday-work {
+ background-color: #e8f8ec !important;
+ }
+
+ .holiday-tag {
+ display: inline-block;
+ padding: 0 3px;
+ margin-left: 2px;
+ color: #fff;
+ font-size: 10px;
+ line-height: 14px;
+ border-radius: 2px;
+ }
+
+ .holiday-rest .holiday-tag {
+ background-color: #fa8c16;
+ }
+
+ .holiday-work .holiday-tag {
+ background-color: #52c41a;
+ }
+
.shift-chip {
display: inline-block;
max-width: 100%;
--
Gitblit v1.9.3