| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- <template>
- <div class="teacher_list_container">
- <!-- 顶部导航 -->
- <div class="header">
- <el-button class="back_button" @click="GoBack">
- <i class="iconfont icon_xiangzuo back_icon" ></i>
- 返回
- </el-button>
- <div class="school_name">{{ schoolName }}</div>
- </div>
- <!-- 筛选区域 -->
- <div class="filter_area">
- <TabSearch.default
- :tabList="tabList"
- tabType="box"
- :defaultTabKey="currentTab"
- @tabChange="ChangeTab"
- />
- <div class="search_area">
- <el-input
- v-model="searchKeyword"
- placeholder="请输入姓名/账号"
- @input="HandleSearch"
- >
- <template #append>
- <el-button :icon="Search" @click="HandleSearch" />
- </template>
- </el-input>
- </div>
- </div>
- <!-- 表格区域 -->
- <div class="page_table">
- <el-table
- :data="tableData"
- stripe
- v-loading="tableLoading"
- element-loading-text="拼命加载中……"
- :height="tableHeight"
- >
- <el-table-column type="index" label="序号" width="60" align="center" :index="GetTableIndex" />
- <el-table-column prop="userAccount" label="账号" min-width="100" align="center" show-overflow-tooltip />
- <el-table-column prop="userName" label="姓名" min-width="100" align="center">
- <template #default="{ row }">
- <span class="name_text" @click="GoEnter(row)">{{ row.userName }}</span>
- </template>
- </el-table-column>
- <el-table-column prop="wxName" label="微信名" min-width="100" align="center">
- <template #default="{ row }">
- {{ row.wxName || '-' }}
- </template>
- </el-table-column>
- <el-table-column prop="phone" label="手机号" min-width="120" align="center">
- <template #default="{ row }">
- {{ row.phone || '-' }}
- </template>
- </el-table-column>
- <el-table-column prop="binXKW" label="是否绑定学科网" width="160" align="center">
- <template #default="{ row }">
- {{ row.binXKW === 1 ? '是' : '否' }}
- </template>
- </el-table-column>
- <el-table-column prop="xkwId" label="学科网" width="160" align="center">
- <template #default="{ row }">
- {{ row.xkwId || '-' }}
- </template>
- </el-table-column>
- <el-table-column prop="status" label="状态" width="80" align="center">
- <template #default="{ row }">
- <div class="status_container">
- <span
- class="status_dot"
- :class="row.status === 1 ? 'active' : 'disabled'"
- ></span>
- <span :class="row.status === 1 ? 'status_active' : 'status_disabled'">
- {{ row.status === 1 ? '启用' : '禁用' }}
- </span>
- </div>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="80" align="center" fixed="right">
- <template #default="{ row }">
- <span class="enter_button" @click="GoEnter(row)">进入</span>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <!-- 分页器 -->
- <div class="page_pagination">
- <el-pagination
- v-model:current-page="pageNum"
- v-model:page-size="pageSize"
- :page-sizes="[20, 50, 100]"
- background
- layout="sizes, prev, pager, next"
- :total="total"
- @current-change="HandleCurrentChange"
- @size-change="HandleSizeChange"
- />
- </div>
- </div>
- </template>
- <script lang="ts" setup>
- import { ref, onMounted, onUnmounted, nextTick } from 'vue'
- import { useRoute, useRouter } from 'vue-router'
- import { Search } from '@element-plus/icons-vue'
- import { ElMessage } from 'element-plus'
- import { throttle } from 'lodash'
- import * as TabSearch from '@/baseComponents/TabSearch.vue'
- import { getAllTeacher, getTicket } from '@/api/school'
- const route = useRoute()
- const router = useRouter()
- // 学校信息
- const schoolName = ref('')
- const schoolId = ref('')
- // Tab列表
- interface TabItem {
- label: string
- key: string
- prefix?: string
- prefixLight?: string
- suffix?: string | number
- }
- const tabList = ref<TabItem[]>([
- { label: '全部', key: 'all' },
- { label: '已绑定学科网', key: 'bound' },
- { label: '未绑定学科网', key: 'unbound' },
- ])
- // Tab切换
- const currentTab = ref('all')
- // 搜索关键字
- const searchKeyword = ref('')
- // 表格数据
- interface Teacher {
- userId: number | string
- userAccount: string
- userName: string
- wxName: string
- phone: string
- status: number
- binXKW: number
- [key: string]: any
- }
- const tableData = ref<Teacher[]>([])
- const allData = ref<Teacher[]>([])
- const tableLoading = ref(false)
- const pageNum = ref(1)
- const pageSize = ref(20)
- const total = ref(0)
- const tableHeight = ref(0)
- // 跨页连续序号
- const GetTableIndex = (index: number) => {
- return (pageNum.value - 1) * pageSize.value + index + 1
- }
- // 前端筛选 + 分页
- const FilterAndPaginate = () => {
- let filteredData = [...allData.value]
- // tab筛选
- if (currentTab.value === 'bound') {
- filteredData = filteredData.filter(item => item.binXKW === 1)
- } else if (currentTab.value === 'unbound') {
- filteredData = filteredData.filter(item => item.binXKW === 0)
- }
- // 搜索筛选
- if (searchKeyword.value) {
- const keyword = searchKeyword.value.toLowerCase()
- filteredData = filteredData.filter(item =>
- (item.userName || '').toLowerCase().includes(keyword) ||
- (item.userAccount || '').toLowerCase().includes(keyword)
- )
- }
- total.value = filteredData.length
- const start = (pageNum.value - 1) * pageSize.value
- const end = start + pageSize.value
- tableData.value = filteredData.slice(start, end)
- }
- // 获取教师列表(仅初始化时调用)
- const GetTeacherList = async () => {
- tableLoading.value = true
- try {
- const params: Record<string, any> = {
- schoolId: schoolId.value,
- }
- const res = await getAllTeacher(params)
- allData.value = res.data || []
- FilterAndPaginate()
- } catch (error) {
- console.error('获取教师列表失败', error)
- } finally {
- tableLoading.value = false
- }
- }
- // 切换Tab(前端筛选)
- const ChangeTab = (tab: string) => {
- currentTab.value = tab
- pageNum.value = 1
- FilterAndPaginate()
- }
- // 搜索(前端筛选)
- const HandleSearch = () => {
- pageNum.value = 1
- FilterAndPaginate()
- }
- // 分页操作(前端分页)
- const HandleCurrentChange = (val: number) => {
- pageNum.value = val
- FilterAndPaginate()
- }
- const HandleSizeChange = (val: number) => {
- pageSize.value = val
- pageNum.value = 1
- FilterAndPaginate()
- }
- // 返回
- const GoBack = () => {
- router.back()
- }
- // 进入
- const GoEnter = (row: Teacher) => {
- // 禁用状态禁止进入
- if (row.status === 0) {
- ElMessage.error('该教师已禁用,无法进入')
- return
- }
- const params = {
- id: row.userId,
- }
- getTicket(params).then((res: any) => {
- const ticket = res.data
- let url = `https://www.k12100.com/#/otherLogin?type=1&schoolId=${schoolId.value}&id=${row.userId}&ticket=${ticket}`
- if (import.meta.env.VITE_API_BASE_URL === 'https://admin.k12100.com/admin/') {
- url = `https://www.k12100.com/#/otherLogin?type=1&schoolId=${schoolId.value}&id=${row.userId}&ticket=${ticket}`
- } else {
- url = `https://index.k12100.net/#/otherLogin?type=1&schoolId=${schoolId.value}&id=${row.userId}&ticket=${ticket}`
- }
- window.open(url)
- }).catch(() => {})
- }
- // 计算表格高度
- const SetTableHeight = () => {
- const containerHeight = document.documentElement.clientHeight
- const headerHeight = 60 // 顶部导航
- const filterHeight = 100 // 筛选区域
- const paginationHeight = 100 // 分页器
- const marginHeight = 40 // 边距
- tableHeight.value = containerHeight - headerHeight - filterHeight - paginationHeight - marginHeight
- }
- // 监听窗口大小变化
- const HandleResize = throttle(() => {
- SetTableHeight()
- }, 500)
- onMounted(() => {
- // 获取路由参数
- schoolName.value = route.query.schoolName as string || ''
- schoolId.value = route.query.schoolId as string || ''
-
- nextTick(() => {
- SetTableHeight()
- GetTeacherList()
- })
-
- window.addEventListener('resize', HandleResize)
- })
- onUnmounted(() => {
- window.removeEventListener('resize', HandleResize)
- })
- </script>
- <style lang="scss" scoped>
- .teacher_list_container {
- margin: 20px;
- box-sizing: border-box;
- background:#fff;
- border-radius: 10px;
- padding:20px;
- width: 100%;
- overflow: hidden;
- }
- // 顶部导航
- .header {
- display: flex;
- align-items: center;
- gap: 20px;
- margin-bottom: 20px;
-
- .back_button {
- width: 82px;
- height: 36px;
- background: #FFFFFF !important;
- border-radius: 4px;
- border: 1px solid #DCDFE6 !important;
- color: #606266;
- font-size: 14px;
- padding: 0;
- .back_icon {
- width: 14px;
- height: 14px;
- font-size: 14px;
- vertical-align: middle;
- color: #333;
- margin-right: 5px;
- }
- }
-
- .school_name {
- font-size: 16px;
- font-weight: 550;
- color: #333;
- }
- }
- // 筛选区域
- .filter_area {
- display: flex;
- align-items: center;
- gap: 20px;
- border-radius: 8px;
- margin-bottom: 16px;
-
- .search_area {
- flex: 1;
- max-width: 217px;
- }
-
- // TabSearch 组件样式穿透
- :deep(.box_tab) {
- .un_selected {
- color: #BBBBBB !important;
- }
- }
- }
- .page_table {
- width: 100%;
- min-width: 0;
- overflow: hidden;
- }
- // 表格内自定义样式
- .name_text {
- color: #2E64FA;
- cursor: pointer;
-
- &:hover {
- text-decoration: underline;
- }
- }
- // 状态样式
- .status_container {
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 4px;
- }
- .status_dot {
- width: 8px;
- height: 8px;
- border-radius: 50%;
-
- &.active {
- background: #2BC644;
- }
-
- &.disabled {
- background: #F56C6C;
- }
- }
- .status_active {
- color: #2BC644;
- }
- .status_disabled {
- color: #F56C6C;
- }
- .enter_button {
- color: #2E64FA;
- cursor: pointer;
-
- &:hover {
- text-decoration: underline;
- }
- }
- </style>
|