准备验证

This commit is contained in:
2026-01-19 12:49:30 +08:00
parent 083d9d5c13
commit 41c2b106d7
100 changed files with 21014 additions and 31 deletions

View File

@@ -0,0 +1,368 @@
<template>
<div class="layout-padding">
<div class="layout-padding-auto layout-padding-view">
<!-- 搜索表单 -->
<el-row v-show="showSearch">
<el-form :model="state.queryForm" ref="searchFormRef" :inline="true" @keyup.enter="getDataList">
<el-form-item label="班级" prop="classCode">
<el-select
v-model="state.queryForm.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 label="班号" prop="classNo">
<el-input
v-model="state.queryForm.classNo"
placeholder="请输入班号"
clearable
style="width: 200px" />
</el-form-item>
<el-form-item label="姓名" prop="realName">
<el-input
v-model="state.queryForm.realName"
placeholder="请输入姓名"
clearable
style="width: 200px" />
</el-form-item>
<el-form-item label="团员编号" prop="serNo">
<el-input
v-model="state.queryForm.serNo"
placeholder="请输入团员编号"
clearable
style="width: 200px" />
</el-form-item>
<el-form-item label="入学年份" prop="grade">
<el-select
v-model="state.queryForm.grade"
placeholder="请选择入学年份"
clearable
style="width: 200px">
<el-option
v-for="item in gradeList"
:key="item.grade"
:label="item.grade"
:value="item.grade">
</el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" plain icon="Search" @click="getDataList">查询</el-button>
<el-button icon="Refresh" @click="handleReset">重置</el-button>
</el-form-item>
</el-form>
</el-row>
<!-- 操作按钮 -->
<el-row>
<div class="mb8" style="width: 100%">
<el-button
icon="Plus"
type="primary"
class="ml10"
@click="formDialogRef.openDialog()">
新增
</el-button>
<el-button
icon="Upload"
type="primary"
class="ml10"
@click="handleImport">
导入
</el-button>
<el-button
icon="Download"
type="primary"
class="ml10"
@click="handleExport">
导出
</el-button>
<right-toolbar
v-model:showSearch="showSearch"
class="ml10 mr20"
style="float: right;"
@queryTable="getDataList">
</right-toolbar>
</div>
</el-row>
<!-- 表格 -->
<el-table
:data="state.dataList"
v-loading="state.loading"
border
:cell-style="tableStyle.cellStyle"
:header-cell-style="tableStyle.headerCellStyle">
<el-table-column type="index" label="序号" width="60" align="center" />
<el-table-column prop="deptName" label="学院" show-overflow-tooltip align="center" min-width="150" />
<el-table-column prop="classNo" label="班级" show-overflow-tooltip align="center" width="120" />
<el-table-column prop="stuNo" label="学号" show-overflow-tooltip align="center" width="120" />
<el-table-column prop="realName" label="姓名" show-overflow-tooltip align="center" width="100" />
<el-table-column prop="phone" label="联系电话" show-overflow-tooltip align="center" width="120" />
<el-table-column prop="enterTime" label="入团时间" show-overflow-tooltip align="center" width="120">
<template #default="scope">
<span>{{ parseTime(scope.row.enterTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column prop="serNo" label="团员编号" show-overflow-tooltip align="center" width="120" />
<el-table-column prop="position" label="团内职务" show-overflow-tooltip align="center" width="120" />
<el-table-column label="操作" width="150" align="center" fixed="right">
<template #default="scope">
<el-button
icon="Edit"
text
type="primary"
@click="handleEdit(scope.row)">
编辑
</el-button>
<el-button
icon="Delete"
text
type="danger"
@click="handleDelete(scope.row)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<pagination
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
v-bind="state.pagination" />
</div>
<!-- 新增/编辑表单弹窗 -->
<form-dialog ref="formDialogRef" @refresh="getDataList" />
<!-- 导入弹窗 -->
<el-dialog
title="导入团员"
v-model="importDialogVisible"
:close-on-click-modal="false"
width="500px">
<el-upload
ref="uploadRef"
:auto-upload="false"
:limit="1"
:on-exceed="handleExceed"
:on-change="handleFileChange"
:file-list="fileList"
accept=".xlsx,.xls"
drag>
<el-icon class="el-icon--upload"><upload-filled /></el-icon>
<div class="el-upload__text">
将文件拖到此处<em>点击上传</em>
</div>
<template #tip>
<div class="el-upload__tip">
只能上传 xlsx/xls 文件
</div>
</template>
</el-upload>
<template #footer>
<span class="dialog-footer">
<el-button @click="importDialogVisible = false"> </el-button>
<el-button type="primary" @click="handleImportSubmit" :loading="importLoading"> </el-button>
</span>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts" name="StuUnionLeague">
import { reactive, ref, onMounted } from 'vue'
import { BasicTableProps, useTable } from "/@/hooks/table";
import { fetchList, delObj, importExcel, exportExcel } from "/@/api/stuwork/stuunionleague";
import { getClassListByRole } from "/@/api/basic/basicclass";
import { getGradeList } from "/@/api/basic/basicclass";
import { useMessage, useMessageBox } from "/@/hooks/message";
import { parseTime } from "/@/utils/formatTime";
import { UploadFilled } from '@element-plus/icons-vue';
import type { UploadFile, UploadFiles } from 'element-plus';
import FormDialog from './form.vue'
// 定义变量内容
const formDialogRef = ref()
const searchFormRef = ref()
const uploadRef = ref()
const showSearch = ref(true)
const classList = ref<any[]>([])
const gradeList = ref<any[]>([])
const importDialogVisible = ref(false)
const importLoading = ref(false)
const fileList = ref<UploadFile[]>([])
// 表格样式
const tableStyle = {
cellStyle: { padding: '8px 0' },
headerCellStyle: { background: '#f5f7fa', color: '#606266', fontWeight: 'bold' }
}
// 配置 useTable
const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {
classCode: '',
classNo: '',
realName: '',
serNo: '',
grade: ''
},
pageList: fetchList,
props: {
item: 'records',
totalCount: 'total'
},
createdIsNeed: true
})
// table hook
const {
getDataList,
currentChangeHandle,
sizeChangeHandle,
tableStyle: _tableStyle
} = useTable(state)
// 重置
const handleReset = () => {
searchFormRef.value?.resetFields()
state.queryForm.classCode = ''
state.queryForm.classNo = ''
state.queryForm.realName = ''
state.queryForm.serNo = ''
state.queryForm.grade = ''
getDataList()
}
// 编辑
const handleEdit = (row: any) => {
formDialogRef.value?.openDialog('edit', row)
}
// 删除
const handleDelete = async (row: any) => {
const { confirm } = useMessageBox()
try {
await confirm('确定要删除该团员吗?')
await delObj([row.id])
useMessage().success('删除成功')
getDataList()
} catch (err: any) {
if (err !== 'cancel') {
useMessage().error(err.msg || '删除失败')
}
}
}
// 导入
const handleImport = () => {
importDialogVisible.value = true
fileList.value = []
}
// 文件变化
const handleFileChange = (file: UploadFile, files: UploadFiles) => {
fileList.value = [file]
}
// 文件超出限制
const handleExceed = () => {
useMessage().warning('只能上传一个文件')
}
// 提交导入
const handleImportSubmit = async () => {
if (fileList.value.length === 0) {
useMessage().warning('请选择要上传的文件')
return
}
const file = fileList.value[0].raw
if (!file) {
useMessage().warning('文件不存在')
return
}
importLoading.value = true
try {
await importExcel(file as File)
useMessage().success('导入成功')
importDialogVisible.value = false
fileList.value = []
getDataList()
} catch (err: any) {
useMessage().error(err.msg || '导入失败')
} finally {
importLoading.value = false
}
}
// 导出
const handleExport = async () => {
try {
const res = await exportExcel(state.queryForm)
const blob = new Blob([res.data as BlobPart])
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = `团员列表_${parseTime(new Date(), '{y}{m}{d}{h}{i}{s}')}.xlsx`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
useMessage().success('导出成功')
} catch (err: any) {
useMessage().error(err.msg || '导出失败')
}
}
// 获取班级列表
const getClassListData = async () => {
try {
const res = await getClassListByRole()
if (res.data && Array.isArray(res.data)) {
classList.value = res.data
} else {
classList.value = []
}
} catch (err) {
console.error('获取班级列表失败', err)
classList.value = []
}
}
// 获取入学年份列表
const getGradeListData = async () => {
try {
const res = await getGradeList()
if (res.data && Array.isArray(res.data)) {
gradeList.value = res.data
} else {
gradeList.value = []
}
} catch (err) {
console.error('获取入学年份列表失败', err)
gradeList.value = []
}
}
// 初始化
onMounted(() => {
getClassListData()
getGradeListData()
})
</script>
<style scoped lang="scss">
</style>