Ferat
This commit is contained in:
@@ -29,21 +29,6 @@
|
||||
clearable
|
||||
style="width: 200px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="班号" prop="classCode">
|
||||
<el-select
|
||||
v-model="searchForm.classCode"
|
||||
placeholder="请选择班号"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 200px">
|
||||
<el-option
|
||||
v-for="item in classList"
|
||||
:key="item.classCode"
|
||||
:label="item.classNo"
|
||||
:value="item.classCode">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" plain icon="Search" @click="handleSearch">查询</el-button>
|
||||
<el-button icon="Refresh" @click="handleReset">重置</el-button>
|
||||
@@ -166,7 +151,6 @@ import { ref, reactive, defineAsyncComponent, onMounted, computed } from 'vue'
|
||||
import { BasicTableProps, useTable } from "/@/hooks/table";
|
||||
import { fetchList } from "/@/api/stuwork/classhygienedailyanalysis";
|
||||
import { useMessage } from "/@/hooks/message";
|
||||
import { getClassListByRole } from '/@/api/basic/basicclass'
|
||||
import { getBuildingList } from '/@/api/stuwork/dormbuilding'
|
||||
|
||||
// 定义变量内容
|
||||
@@ -174,7 +158,6 @@ const searchFormRef = ref()
|
||||
const scoreFormRef = ref()
|
||||
// 搜索变量
|
||||
const showSearch = ref(true)
|
||||
const classList = ref<any[]>([])
|
||||
const buildingList = ref<any[]>([])
|
||||
const scoreDialogVisible = ref(false)
|
||||
const scoreDialogTitle = ref('加分')
|
||||
@@ -192,8 +175,7 @@ const scoreForm = reactive({
|
||||
// 搜索表单
|
||||
const searchForm = reactive({
|
||||
buildingNo: '',
|
||||
month: '',
|
||||
classCode: ''
|
||||
month: ''
|
||||
})
|
||||
|
||||
// 计算月份的天数列
|
||||
@@ -206,31 +188,77 @@ const dayColumns = computed(() => {
|
||||
return Array.from({ length: daysInMonth }, (_, i) => i + 1)
|
||||
})
|
||||
|
||||
// 配置 useTable - 需要将月份转换为开始和结束时间,且不传分页参数
|
||||
// 配置 useTable - 接口参数为 buildingNo 和 month(数组格式)
|
||||
const state: BasicTableProps = reactive<BasicTableProps>({
|
||||
queryForm: searchForm,
|
||||
isPage: false, // 接口不支持分页
|
||||
pageList: async (queryParams: any) => {
|
||||
// 如果选择了月份,转换为开始和结束时间
|
||||
const params: any = {}
|
||||
|
||||
// 如果选择了月份,转换为开始和结束时间
|
||||
// 接口文档要求 buildingNo 和 month 都是数组格式
|
||||
if (searchForm.buildingNo) {
|
||||
params.buildingNo = Array.isArray(searchForm.buildingNo) ? searchForm.buildingNo : [searchForm.buildingNo]
|
||||
}
|
||||
if (searchForm.month) {
|
||||
const [year, month] = searchForm.month.split('-').map(Number)
|
||||
const daysInMonth = new Date(year, month, 0).getDate()
|
||||
params.startTime = `${year}-${String(month).padStart(2, '0')}-01`
|
||||
params.endTime = `${year}-${String(month).padStart(2, '0')}-${String(daysInMonth).padStart(2, '0')}`
|
||||
params.month = Array.isArray(searchForm.month) ? searchForm.month : [searchForm.month]
|
||||
}
|
||||
|
||||
// 如果选择了班号,转换为数组格式(接口要求classCode是数组)
|
||||
if (searchForm.classCode) {
|
||||
params.classCode = Array.isArray(searchForm.classCode) ? searchForm.classCode : [searchForm.classCode]
|
||||
const res = await fetchList(params)
|
||||
|
||||
// 接口返回的数据结构:数组,每个元素包含日期字段(如 2025-12-01)和班级信息
|
||||
// 需要确保返回数组格式给 useTable
|
||||
let dataList = []
|
||||
|
||||
if (Array.isArray(res.data)) {
|
||||
dataList = res.data
|
||||
} else if (res.data && Array.isArray(res.data.records)) {
|
||||
dataList = res.data.records
|
||||
} else if (res.data && Array.isArray(res.data.list)) {
|
||||
dataList = res.data.list
|
||||
} else if (res.data && typeof res.data === 'object') {
|
||||
// 如果 res.data 是单个对象,转换为数组
|
||||
dataList = [res.data]
|
||||
}
|
||||
|
||||
// 楼号参数 - 接口文档中没有buildingNo参数,可能需要通过其他方式处理
|
||||
// 暂时不传递buildingNo,如果需要可以后续添加
|
||||
// 处理数据:将日期字段转换为 day1, day2 等格式,方便表格显示
|
||||
const processedData = dataList.map((item: any) => {
|
||||
const processed: any = {
|
||||
classCode: item.classCode || '',
|
||||
classNo: item.classNo || '',
|
||||
totalScore: item.scoreTotal || 0,
|
||||
rank: item.order || 0,
|
||||
isAddScore: item.isAddScore || 0
|
||||
}
|
||||
|
||||
// 提取所有日期字段(格式为 YYYY-MM-DD)
|
||||
const datePattern = /^\d{4}-\d{2}-\d{2}$/
|
||||
Object.keys(item).forEach(key => {
|
||||
if (datePattern.test(key)) {
|
||||
// 将日期转换为 day1, day2 等格式(根据日期中的天数)
|
||||
const date = new Date(key)
|
||||
const day = date.getDate()
|
||||
processed[`day${day}`] = item[key]
|
||||
}
|
||||
})
|
||||
|
||||
// 确保所有日期字段都存在(即使值为0或null),避免表格列无法显示
|
||||
if (searchForm.month) {
|
||||
const [year, month] = searchForm.month.split('-').map(Number)
|
||||
const daysInMonth = new Date(year, month, 0).getDate()
|
||||
for (let i = 1; i <= daysInMonth; i++) {
|
||||
if (!processed.hasOwnProperty(`day${i}`)) {
|
||||
processed[`day${i}`] = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return processed
|
||||
})
|
||||
|
||||
// 不传递分页参数(current、size)
|
||||
return await fetchList(params)
|
||||
return {
|
||||
...res,
|
||||
data: processedData
|
||||
}
|
||||
},
|
||||
props: {
|
||||
item: 'records',
|
||||
@@ -262,7 +290,6 @@ const handleReset = () => {
|
||||
searchFormRef.value?.resetFields()
|
||||
searchForm.buildingNo = ''
|
||||
searchForm.month = ''
|
||||
searchForm.classCode = ''
|
||||
getDataList()
|
||||
}
|
||||
|
||||
@@ -317,19 +344,6 @@ const submitScore = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取班号列表
|
||||
const getClassListData = async () => {
|
||||
try {
|
||||
const res = await getClassListByRole()
|
||||
if (res.data) {
|
||||
classList.value = Array.isArray(res.data) ? res.data : []
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取班号列表失败', err)
|
||||
classList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// 获取楼号列表
|
||||
const getBuildingListData = async () => {
|
||||
try {
|
||||
@@ -352,7 +366,6 @@ const getBuildingListData = async () => {
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
getClassListData()
|
||||
getBuildingListData()
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user