add fiel
This commit is contained in:
@@ -81,9 +81,26 @@
|
||||
</el-button>
|
||||
<right-toolbar
|
||||
v-model:showSearch="showSearch"
|
||||
class="ml10 mr20"
|
||||
class="ml10"
|
||||
style="float: right;"
|
||||
@queryTable="getDataList">
|
||||
<TableColumnControl
|
||||
ref="columnControlRef"
|
||||
:columns="tableColumns"
|
||||
v-model="visibleColumns"
|
||||
trigger-type="default"
|
||||
trigger-circle
|
||||
@change="handleColumnChange"
|
||||
@order-change="handleColumnOrderChange"
|
||||
>
|
||||
<template #trigger>
|
||||
<el-tooltip class="item" effect="dark" content="列设置" placement="top">
|
||||
<el-button circle style="margin-left: 0;">
|
||||
<el-icon><Menu /></el-icon>
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</TableColumnControl>
|
||||
</right-toolbar>
|
||||
</div>
|
||||
</el-row>
|
||||
@@ -101,89 +118,50 @@
|
||||
<el-icon><List /></el-icon>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="buildingNo" label="楼号" show-overflow-tooltip align="center">
|
||||
<template #header>
|
||||
<el-icon><OfficeBuilding /></el-icon>
|
||||
<span style="margin-left: 4px">楼号</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="deptName" label="学院" show-overflow-tooltip align="center">
|
||||
<template #header>
|
||||
<el-icon><OfficeBuilding /></el-icon>
|
||||
<span style="margin-left: 4px">学院</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="classStatus" label="班级状态" show-overflow-tooltip align="center">
|
||||
<template #header>
|
||||
<el-icon><CircleCheck /></el-icon>
|
||||
<span style="margin-left: 4px">班级状态</span>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<el-tag size="small" type="info" effect="plain">
|
||||
{{ formatClassStatus(scope.row.classStatus) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="position" label="教室位置" show-overflow-tooltip align="center">
|
||||
<template #header>
|
||||
<el-icon><Location /></el-icon>
|
||||
<span style="margin-left: 4px">教室位置</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="stuNum" label="人数" show-overflow-tooltip align="center">
|
||||
<template #header>
|
||||
<el-icon><UserFilled /></el-icon>
|
||||
<span style="margin-left: 4px">人数</span>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<el-tag v-if="scope.row.stuNum" size="small" type="success" effect="plain">
|
||||
{{ scope.row.stuNum }}
|
||||
</el-tag>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="teacherRealName" label="班主任" show-overflow-tooltip align="center">
|
||||
<template #header>
|
||||
<el-icon><UserFilled /></el-icon>
|
||||
<span style="margin-left: 4px">班主任</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="platformType" label="讲台类型" show-overflow-tooltip align="center">
|
||||
<template #header>
|
||||
<el-icon><Collection /></el-icon>
|
||||
<span style="margin-left: 4px">讲台类型</span>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<el-tag size="small" type="info" effect="plain">
|
||||
{{ formatDict(scope.row.platformType, platformTypeList) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="tyType" label="投影类型" show-overflow-tooltip align="center">
|
||||
<template #header>
|
||||
<el-icon><Collection /></el-icon>
|
||||
<span style="margin-left: 4px">投影类型</span>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<el-tag size="small" type="info" effect="plain">
|
||||
{{ formatDict(scope.row.tyType, tyTypeList) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="tvType" label="电视机" show-overflow-tooltip align="center">
|
||||
<template #header>
|
||||
<el-icon><Collection /></el-icon>
|
||||
<span style="margin-left: 4px">电视机</span>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<el-tag size="small" type="info" effect="plain">
|
||||
{{ formatDict(scope.row.tvType, tvTypeList) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="chairCnt" label="方凳数量" show-overflow-tooltip align="center" />
|
||||
<el-table-column prop="tableCnt" label="课桌数量" show-overflow-tooltip align="center" />
|
||||
<el-table-column prop="password" label="锁密码" show-overflow-tooltip align="center" />
|
||||
<template v-for="col in sortedTableColumns" :key="col.prop || col.label">
|
||||
<el-table-column
|
||||
v-if="checkColumnVisible(col.prop || '') && col.prop !== '操作'"
|
||||
:prop="col.prop"
|
||||
:label="col.label"
|
||||
show-overflow-tooltip
|
||||
align="center">
|
||||
<template #header>
|
||||
<el-icon><component :is="columnConfigMap[col.prop]?.icon || Calendar" /></el-icon>
|
||||
<span style="margin-left: 4px">{{ col.label }}</span>
|
||||
</template>
|
||||
<!-- 班级状态列特殊模板 -->
|
||||
<template v-if="col.prop === 'classStatus'" #default="scope">
|
||||
<el-tag size="small" type="info" effect="plain">
|
||||
{{ formatClassStatus(scope.row.classStatus) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<!-- 人数列特殊模板 -->
|
||||
<template v-else-if="col.prop === 'stuNum'" #default="scope">
|
||||
<el-tag v-if="scope.row.stuNum" size="small" type="success" effect="plain">
|
||||
{{ scope.row.stuNum }}
|
||||
</el-tag>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<!-- 讲台类型列特殊模板 -->
|
||||
<template v-else-if="col.prop === 'platformType'" #default="scope">
|
||||
<el-tag size="small" type="info" effect="plain">
|
||||
{{ formatDict(scope.row.platformType, platformTypeList) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<!-- 投影类型列特殊模板 -->
|
||||
<template v-else-if="col.prop === 'tyType'" #default="scope">
|
||||
<el-tag size="small" type="info" effect="plain">
|
||||
{{ formatDict(scope.row.tyType, tyTypeList) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<!-- 电视机列特殊模板 -->
|
||||
<template v-else-if="col.prop === 'tvType'" #default="scope">
|
||||
<el-tag size="small" type="info" effect="plain">
|
||||
{{ formatDict(scope.row.tvType, tvTypeList) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</template>
|
||||
<el-table-column label="操作" width="120" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
@@ -210,18 +188,22 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="ClassroomBase">
|
||||
import { reactive, ref, onMounted } from 'vue'
|
||||
import { reactive, ref, onMounted, computed, nextTick } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { BasicTableProps, useTable } from "/@/hooks/table";
|
||||
import { fetchList, exportData, syncClassroomArrangement } from "/@/api/stuwork/classroombase";
|
||||
import { getDeptListByLevelTwo } from "/@/api/basic/basicdept";
|
||||
import { queryAllClass } from "/@/api/basic/basicclass";
|
||||
import { getDicts } from "/@/api/admin/dict";
|
||||
import { useMessage, useMessageBox } from "/@/hooks/message";
|
||||
import TableColumnControl from '/@/components/TableColumnControl/index.vue'
|
||||
import ArrangeDialog from './arrange.vue'
|
||||
import { List, OfficeBuilding, CircleCheck, Location, UserFilled, Collection, Setting } from '@element-plus/icons-vue'
|
||||
import { List, OfficeBuilding, CircleCheck, Location, UserFilled, Collection, Setting, Menu, Calendar } from '@element-plus/icons-vue'
|
||||
|
||||
// 定义变量内容
|
||||
const route = useRoute()
|
||||
const searchFormRef = ref()
|
||||
const columnControlRef = ref<any>()
|
||||
const showSearch = ref(true)
|
||||
const deptList = ref<any[]>([])
|
||||
const classList = ref<any[]>([])
|
||||
@@ -231,6 +213,142 @@ const tyTypeList = ref<any[]>([])
|
||||
const tvTypeList = ref<any[]>([])
|
||||
const arrangeDialogRef = ref()
|
||||
|
||||
// 表格列配置
|
||||
const tableColumns = [
|
||||
{ prop: 'buildingNo', label: '楼号' },
|
||||
{ prop: 'deptName', label: '学院' },
|
||||
{ prop: 'classStatus', label: '班级状态' },
|
||||
{ prop: 'position', label: '教室位置' },
|
||||
{ prop: 'stuNum', label: '人数' },
|
||||
{ prop: 'teacherRealName', label: '班主任' },
|
||||
{ prop: 'platformType', label: '讲台类型' },
|
||||
{ prop: 'tyType', label: '投影类型' },
|
||||
{ prop: 'tvType', label: '电视机' },
|
||||
{ prop: 'chairCnt', label: '方凳数量' },
|
||||
{ prop: 'tableCnt', label: '课桌数量' },
|
||||
{ prop: 'password', label: '锁密码' }
|
||||
]
|
||||
|
||||
// 列配置映射(用于图标)
|
||||
const columnConfigMap: Record<string, { icon: any }> = {
|
||||
buildingNo: { icon: OfficeBuilding },
|
||||
deptName: { icon: OfficeBuilding },
|
||||
classStatus: { icon: CircleCheck },
|
||||
position: { icon: Location },
|
||||
stuNum: { icon: UserFilled },
|
||||
teacherRealName: { icon: UserFilled },
|
||||
platformType: { icon: Collection },
|
||||
tyType: { icon: Collection },
|
||||
tvType: { icon: Collection },
|
||||
chairCnt: { icon: Calendar },
|
||||
tableCnt: { icon: Calendar },
|
||||
password: { icon: Calendar }
|
||||
}
|
||||
|
||||
// 当前显示的列
|
||||
const visibleColumns = ref<string[]>([])
|
||||
// 列排序顺序
|
||||
const columnOrder = ref<string[]>([])
|
||||
|
||||
// 立即从 localStorage 加载配置
|
||||
const loadSavedConfig = () => {
|
||||
const routePath = route.path.replace(/^\//, '').replace(/\//g, '-')
|
||||
const storageKey = `table-columns-${routePath}`
|
||||
const saved = localStorage.getItem(storageKey)
|
||||
if (saved) {
|
||||
try {
|
||||
const savedColumns = JSON.parse(saved)
|
||||
const validColumns = tableColumns.map(col => col.prop || col.label)
|
||||
const filteredSaved = savedColumns.filter((col: string) => validColumns.includes(col))
|
||||
visibleColumns.value = filteredSaved.length > 0 ? filteredSaved : validColumns
|
||||
} catch (e) {
|
||||
visibleColumns.value = tableColumns.map(col => col.prop || col.label)
|
||||
}
|
||||
} else {
|
||||
visibleColumns.value = tableColumns.map(col => col.prop || col.label)
|
||||
}
|
||||
|
||||
const orderKey = `${storageKey}-order`
|
||||
const savedOrder = localStorage.getItem(orderKey)
|
||||
if (savedOrder) {
|
||||
try {
|
||||
const parsedOrder = JSON.parse(savedOrder)
|
||||
const validColumns = tableColumns.map(col => col.prop || col.label)
|
||||
columnOrder.value = parsedOrder.filter((key: string) => validColumns.includes(key))
|
||||
validColumns.forEach(key => {
|
||||
if (!columnOrder.value.includes(key)) {
|
||||
columnOrder.value.push(key)
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
columnOrder.value = tableColumns.map(col => col.prop || col.label)
|
||||
}
|
||||
} else {
|
||||
columnOrder.value = tableColumns.map(col => col.prop || col.label)
|
||||
}
|
||||
}
|
||||
|
||||
loadSavedConfig()
|
||||
|
||||
// 排序后的表格列
|
||||
const sortedTableColumns = computed(() => {
|
||||
const columns = tableColumns.filter(col => {
|
||||
const key = col.prop || col.label
|
||||
return visibleColumns.value.includes(key)
|
||||
})
|
||||
|
||||
if (columnOrder.value.length > 0) {
|
||||
const orderedColumns: typeof tableColumns = []
|
||||
const unorderedColumns: typeof tableColumns = []
|
||||
|
||||
columnOrder.value.forEach(key => {
|
||||
const col = columns.find(c => (c.prop || c.label) === key)
|
||||
if (col) {
|
||||
orderedColumns.push(col)
|
||||
}
|
||||
})
|
||||
|
||||
columns.forEach(col => {
|
||||
const key = col.prop || col.label
|
||||
if (!columnOrder.value.includes(key)) {
|
||||
unorderedColumns.push(col)
|
||||
}
|
||||
})
|
||||
|
||||
return [...orderedColumns, ...unorderedColumns]
|
||||
}
|
||||
|
||||
return columns
|
||||
})
|
||||
|
||||
// 列显示控制函数
|
||||
const checkColumnVisible = (prop: string): boolean => {
|
||||
if (visibleColumns.value.length === 0) {
|
||||
return true
|
||||
}
|
||||
return visibleColumns.value.includes(prop)
|
||||
}
|
||||
|
||||
// 监听列变化
|
||||
const handleColumnChange = (columns: string[]) => {
|
||||
visibleColumns.value = columns
|
||||
const routePath = route.path.replace(/^\//, '').replace(/\//g, '-')
|
||||
const storageKey = `table-columns-${routePath}`
|
||||
const selectableColumns = columns.filter(col => {
|
||||
const column = tableColumns.find(c => (c.prop || c.label) === col)
|
||||
return column && !column.alwaysShow && !column.fixed
|
||||
})
|
||||
localStorage.setItem(storageKey, JSON.stringify(selectableColumns))
|
||||
}
|
||||
|
||||
// 监听列排序变化
|
||||
const handleColumnOrderChange = (order: string[]) => {
|
||||
columnOrder.value = order
|
||||
const routePath = route.path.replace(/^\//, '').replace(/\//g, '-')
|
||||
const storageKey = `table-columns-${routePath}-order`
|
||||
localStorage.setItem(storageKey, JSON.stringify(order))
|
||||
}
|
||||
|
||||
// 班级状态列表
|
||||
const classStatusListData = [
|
||||
{ label: '在校', value: '0' },
|
||||
@@ -296,7 +414,6 @@ const state: BasicTableProps = reactive<BasicTableProps>({
|
||||
}
|
||||
} catch (err: any) {
|
||||
// 确保即使出错也返回正确的数据结构
|
||||
console.error('获取数据失败', err)
|
||||
throw err
|
||||
}
|
||||
},
|
||||
@@ -391,7 +508,6 @@ const getDeptListData = async () => {
|
||||
deptList.value = Array.isArray(res.data) ? res.data : []
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取系部列表失败', err)
|
||||
deptList.value = []
|
||||
}
|
||||
}
|
||||
@@ -404,7 +520,6 @@ const getClassListData = async () => {
|
||||
classList.value = Array.isArray(res.data) ? res.data : []
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取班级列表失败', err)
|
||||
classList.value = []
|
||||
}
|
||||
}
|
||||
@@ -420,7 +535,6 @@ const getPlatformTypeDict = async () => {
|
||||
})) : []
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取讲台类型字典失败', err)
|
||||
platformTypeList.value = []
|
||||
}
|
||||
}
|
||||
@@ -436,7 +550,6 @@ const getTyTypeDict = async () => {
|
||||
})) : []
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取投影类型字典失败', err)
|
||||
tyTypeList.value = []
|
||||
}
|
||||
}
|
||||
@@ -452,7 +565,6 @@ const getTvTypeDict = async () => {
|
||||
})) : []
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取电视机类型字典失败', err)
|
||||
tvTypeList.value = []
|
||||
}
|
||||
}
|
||||
@@ -465,6 +577,11 @@ onMounted(() => {
|
||||
getPlatformTypeDict()
|
||||
getTyTypeDict()
|
||||
getTvTypeDict()
|
||||
nextTick(() => {
|
||||
if (visibleColumns.value.length === 0) {
|
||||
loadSavedConfig()
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user