重构项目文件夹目录
This commit is contained in:
@@ -0,0 +1,309 @@
|
||||
<template>
|
||||
<div class="schedules">
|
||||
<a-page-header v-if="!isMobile" title="排班管理" sub-title="维护美甲师班次、容量和可约状态" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">排班</span>
|
||||
<h1 class="admin-page-intro__title">排班管理</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">班次 {{ schedules.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">班次列表</template>
|
||||
<template #extra>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-button type="primary" @click="openCreateModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增排班
|
||||
</a-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<AdminFilterPanel :active-count="activeFilterCount">
|
||||
<a-select
|
||||
v-model:value="filters.artistId"
|
||||
allow-clear
|
||||
placeholder="选择美甲师"
|
||||
:options="artistOptions"
|
||||
style="width: 180px"
|
||||
@change="loadSchedules"
|
||||
/>
|
||||
<a-range-picker
|
||||
v-model:value="filters.dateRange"
|
||||
value-format="YYYY-MM-DD"
|
||||
style="width: 240px"
|
||||
@change="loadSchedules"
|
||||
/>
|
||||
<a-button @click="resetFilters">重置筛选</a-button>
|
||||
</AdminFilterPanel>
|
||||
|
||||
<a-table v-if="!isMobile" :columns="columns" :data-source="schedules" :loading="loading" row-key="id" :scroll="{ x: 'max-content' }">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'artist'">{{ artistName(record.artistId) }}</template>
|
||||
<template v-else-if="column.key === 'time'">{{ record.startTime }} - {{ record.endTime }}</template>
|
||||
<template v-else-if="column.key === 'capacity'">{{ record.capacity ?? '-' }} / {{ record.slotMinutes ?? '-' }} 分钟</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 0 ? 'red' : 'green'">{{ scheduleStatusText(record.status) }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-button type="link" size="small" @click="openEditModal(record as ArtistScheduleVO)">编辑</a-button>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="schedules" empty-description="暂无排班数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ artistName(item.artistId) }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.workDate }} {{ item.startTime }} - {{ item.endTime }}</div>
|
||||
</div>
|
||||
<a-tag :color="item.status === 0 ? 'red' : 'green'">{{ scheduleStatusText(item.status) }}</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>容量</span>
|
||||
<strong>{{ item.capacity ?? '-' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>间隔</span>
|
||||
<strong>{{ item.slotMinutes ?? '-' }} 分钟</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>备注</span>
|
||||
<strong>{{ item.remark || '-' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button size="small" @click="openEditModal(item)">编辑</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="modalOpen"
|
||||
:title="editingSchedule ? '编辑排班' : '新增排班'"
|
||||
:desktop-width="720"
|
||||
:confirm-loading="saving"
|
||||
@ok="saveSchedule"
|
||||
@cancel="closeModal"
|
||||
>
|
||||
<a-form ref="formRef" :model="formState" :rules="rules" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
|
||||
<a-form-item label="美甲师" name="artistId">
|
||||
<a-select v-model:value="formState.artistId" placeholder="选择美甲师" :options="artistOptions" />
|
||||
</a-form-item>
|
||||
<a-form-item label="工作日期" name="workDate">
|
||||
<a-date-picker v-model:value="formState.workDate" value-format="YYYY-MM-DD" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="开始时间" name="startTime">
|
||||
<a-input v-model:value="formState.startTime" placeholder="09:00:00" />
|
||||
</a-form-item>
|
||||
<a-form-item label="结束时间" name="endTime">
|
||||
<a-input v-model:value="formState.endTime" placeholder="18:00:00" />
|
||||
</a-form-item>
|
||||
<a-form-item label="预约间隔">
|
||||
<a-input-number v-model:value="formState.slotMinutes" :min="5" :step="5" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="容量">
|
||||
<a-input-number v-model:value="formState.capacity" :min="1" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="状态">
|
||||
<a-select v-model:value="formState.status">
|
||||
<a-select-option :value="1">可预约</a-select-option>
|
||||
<a-select-option :value="0">停用</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="备注">
|
||||
<a-textarea v-model:value="formState.remark" :rows="3" :maxlength="200" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import {
|
||||
adminArtistScheduleApi,
|
||||
adminNailArtistApi,
|
||||
type ArtistScheduleRequest,
|
||||
type ArtistScheduleVO,
|
||||
type NailArtistInfoVO
|
||||
} from '@/api/admin'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminFilterPanel from '@/components/admin/AdminFilterPanel.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { isMobile } = useAdminViewport()
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const modalOpen = ref(false)
|
||||
const schedules = ref<ArtistScheduleVO[]>([])
|
||||
const artists = ref<NailArtistInfoVO[]>([])
|
||||
const editingSchedule = ref<ArtistScheduleVO | null>(null)
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const filters = reactive({
|
||||
artistId: undefined as string | undefined,
|
||||
dateRange: undefined as [string, string] | undefined
|
||||
})
|
||||
|
||||
const formState = reactive<ArtistScheduleRequest>({
|
||||
artistId: undefined,
|
||||
workDate: '',
|
||||
startTime: '09:00:00',
|
||||
endTime: '18:00:00',
|
||||
slotMinutes: 30,
|
||||
capacity: 1,
|
||||
status: 1,
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const rules = {
|
||||
artistId: [{ required: true, message: '请选择美甲师', trigger: 'change' }],
|
||||
workDate: [{ required: true, message: '请选择工作日期', trigger: 'change' }],
|
||||
startTime: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
|
||||
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }]
|
||||
} as any
|
||||
|
||||
const columns = [
|
||||
{ title: '美甲师', key: 'artist', width: 160 },
|
||||
{ title: '工作日期', dataIndex: 'workDate', key: 'workDate', width: 140 },
|
||||
{ title: '工作时段', key: 'time', width: 180 },
|
||||
{ title: '容量 / 间隔', key: 'capacity', width: 140 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '备注', dataIndex: 'remark', key: 'remark' },
|
||||
{ title: '操作', key: 'actions', width: 90 }
|
||||
]
|
||||
|
||||
const artistOptions = computed(() => artists.value.map(artist => ({
|
||||
label: artist.nickname || artist.identity || `美甲师 ${artist.userId}`,
|
||||
value: String(artist.userId || artist.id)
|
||||
})))
|
||||
|
||||
const activeFilterCount = computed(() => [
|
||||
filters.artistId,
|
||||
filters.dateRange?.length ? 'date' : ''
|
||||
].filter(Boolean).length)
|
||||
|
||||
const artistName = (artistId?: unknown) => {
|
||||
const artist = artists.value.find(item => String(item.userId || item.id) === String(artistId))
|
||||
return artist?.nickname || artist?.identity || (artistId ? `美甲师 ${artistId}` : '-')
|
||||
}
|
||||
|
||||
const scheduleStatusText = (status?: number) => status === 0 ? '停用' : '可预约'
|
||||
|
||||
const resetForm = () => {
|
||||
Object.assign(formState, {
|
||||
artistId: undefined,
|
||||
workDate: '',
|
||||
startTime: '09:00:00',
|
||||
endTime: '18:00:00',
|
||||
slotMinutes: 30,
|
||||
capacity: 1,
|
||||
status: 1,
|
||||
remark: ''
|
||||
})
|
||||
}
|
||||
|
||||
const loadArtists = async () => {
|
||||
try {
|
||||
artists.value = await adminNailArtistApi.listNailArtists() as unknown as NailArtistInfoVO[]
|
||||
} catch (error) {
|
||||
console.error('加载美甲师失败:', error)
|
||||
artists.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const loadSchedules = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
schedules.value = await adminArtistScheduleApi.listSchedules({
|
||||
artistId: filters.artistId,
|
||||
startDate: filters.dateRange?.[0],
|
||||
endDate: filters.dateRange?.[1]
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('加载排班失败:', error)
|
||||
message.error('加载排班失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resetFilters = () => {
|
||||
filters.artistId = undefined
|
||||
filters.dateRange = undefined
|
||||
void loadSchedules()
|
||||
}
|
||||
|
||||
const openCreateModal = () => {
|
||||
editingSchedule.value = null
|
||||
resetForm()
|
||||
modalOpen.value = true
|
||||
}
|
||||
|
||||
const openEditModal = (record: ArtistScheduleVO) => {
|
||||
editingSchedule.value = record
|
||||
Object.assign(formState, {
|
||||
artistId: String(record.artistId),
|
||||
workDate: record.workDate,
|
||||
startTime: record.startTime,
|
||||
endTime: record.endTime,
|
||||
slotMinutes: record.slotMinutes ?? 30,
|
||||
capacity: record.capacity ?? 1,
|
||||
status: record.status ?? 1,
|
||||
remark: record.remark || ''
|
||||
})
|
||||
modalOpen.value = true
|
||||
}
|
||||
|
||||
const closeModal = () => {
|
||||
modalOpen.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const saveSchedule = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
saving.value = true
|
||||
await runWithGlobalLoading(async () => {
|
||||
await adminArtistScheduleApi.saveSchedule({ ...formState })
|
||||
await loadSchedules()
|
||||
})
|
||||
message.success('排班已保存')
|
||||
closeModal()
|
||||
} catch (error: any) {
|
||||
if (error?.errorFields) {
|
||||
return
|
||||
}
|
||||
console.error('保存排班失败:', error)
|
||||
message.error(error?.message || '保存排班失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadArtists()
|
||||
await loadSchedules()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.schedules {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user