add fiel
This commit is contained in:
@@ -50,6 +50,23 @@
|
||||
class="ml10 mr20"
|
||||
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>
|
||||
@@ -67,22 +84,18 @@
|
||||
<el-icon><List /></el-icon>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="teacherNoVal" label="教师" show-overflow-tooltip>
|
||||
<el-table-column
|
||||
v-for="col in visibleColumnsSorted"
|
||||
:key="col.prop"
|
||||
:prop="col.prop"
|
||||
:label="col.label"
|
||||
:width="col.width"
|
||||
:min-width="col.minWidth"
|
||||
:show-overflow-tooltip="col.showOverflowTooltip !== false"
|
||||
:align="col.align || 'center'">
|
||||
<template #header>
|
||||
<el-icon><User /></el-icon>
|
||||
<span style="margin-left: 4px">教师</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="teacherNo" label="工号" show-overflow-tooltip>
|
||||
<template #header>
|
||||
<el-icon><CreditCard /></el-icon>
|
||||
<span style="margin-left: 4px">工号</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="telPhone" label="联系方式" show-overflow-tooltip>
|
||||
<template #header>
|
||||
<el-icon><Phone /></el-icon>
|
||||
<span style="margin-left: 4px">联系方式</span>
|
||||
<el-icon v-if="col.icon"><component :is="col.icon" /></el-icon>
|
||||
<span :style="{ marginLeft: col.icon ? '4px' : '0' }">{{ col.label }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="150" align="center" fixed="right">
|
||||
@@ -118,26 +131,131 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="ClassMasterResume">
|
||||
import { ref, reactive, defineAsyncComponent, onMounted, nextTick } from 'vue'
|
||||
import { ref, reactive, defineAsyncComponent, onMounted, nextTick, computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { BasicTableProps, useTable } from "/@/hooks/table";
|
||||
import { fetchList } from "/@/api/stuwork/classmasterresume";
|
||||
import request from "/@/utils/request";
|
||||
import TableColumnControl from '/@/components/TableColumnControl/index.vue'
|
||||
|
||||
// 引入组件
|
||||
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
|
||||
// 尝试直接导入看看是否能解决问题
|
||||
import DetailDialog from './detail.vue';
|
||||
import { List, User, CreditCard, Phone, Setting } from '@element-plus/icons-vue'
|
||||
import { List, User, CreditCard, Phone, Setting, Menu } from '@element-plus/icons-vue'
|
||||
|
||||
// 定义变量内容
|
||||
const route = useRoute()
|
||||
const formDialogRef = ref()
|
||||
const searchFormRef = ref()
|
||||
const detailDialogRef = ref()
|
||||
const columnControlRef = ref()
|
||||
// 搜索变量
|
||||
const showSearch = ref(true)
|
||||
// 教师列表
|
||||
const teacherList = ref<any[]>([])
|
||||
|
||||
// 表格列配置
|
||||
const tableColumns = [
|
||||
{ prop: 'teacherNoVal', label: '教师', icon: User },
|
||||
{ prop: 'teacherNo', label: '工号', icon: CreditCard },
|
||||
{ prop: 'telPhone', label: '联系方式', icon: Phone }
|
||||
]
|
||||
|
||||
// 当前显示的列
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// 列变化处理
|
||||
const handleColumnChange = (value: string[]) => {
|
||||
visibleColumns.value = value
|
||||
const routePath = route.path.replace(/^\//, '').replace(/\//g, '-')
|
||||
const storageKey = `table-columns-${routePath}`
|
||||
const selectableColumns = value.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}`
|
||||
localStorage.setItem(`${storageKey}-order`, JSON.stringify(order))
|
||||
}
|
||||
|
||||
// 排序后的表格列
|
||||
const visibleColumnsSorted = computed(() => {
|
||||
const columns = tableColumns.filter(col => {
|
||||
const key = col.prop || col.label
|
||||
return visibleColumns.value.includes(key)
|
||||
})
|
||||
|
||||
if (columnOrder.value.length > 0) {
|
||||
const orderedColumns: any[] = []
|
||||
const unorderedColumns: any[] = []
|
||||
|
||||
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 searchForm = reactive({
|
||||
teacherNo: '',
|
||||
@@ -173,7 +291,6 @@ const getTeacherList = async () => {
|
||||
})
|
||||
teacherList.value = res.data || []
|
||||
} catch (err) {
|
||||
console.error('获取教师列表失败', err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,35 +318,26 @@ const exportExcel = () => {
|
||||
|
||||
// 查看履历详情
|
||||
const handleViewDetail = async (row: any) => {
|
||||
console.log('handleViewDetail 被调用,row:', row)
|
||||
|
||||
if (!row.teacherNo) {
|
||||
console.error('缺少教师工号', row)
|
||||
return
|
||||
}
|
||||
|
||||
// 确保组件已挂载
|
||||
await nextTick()
|
||||
|
||||
console.log('nextTick 后,detailDialogRef.value:', detailDialogRef.value)
|
||||
console.log('detailDialogRef.value?.openDialog:', detailDialogRef.value?.openDialog)
|
||||
|
||||
if (detailDialogRef.value && typeof detailDialogRef.value.openDialog === 'function') {
|
||||
detailDialogRef.value.openDialog(row.teacherNo)
|
||||
} else {
|
||||
console.error('详情对话框组件未找到或 openDialog 方法不存在', {
|
||||
detailDialogRef: detailDialogRef.value,
|
||||
hasOpenDialog: detailDialogRef.value?.openDialog
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化
|
||||
loadSavedConfig()
|
||||
onMounted(() => {
|
||||
getTeacherList()
|
||||
// 调试:检查组件是否已挂载
|
||||
nextTick(() => {
|
||||
console.log('组件挂载后,detailDialogRef:', detailDialogRef.value)
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user