teacherList.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <div class="teacher_list_container">
  3. <!-- 顶部导航 -->
  4. <div class="header">
  5. <el-button class="back_button" @click="GoBack">
  6. <i class="iconfont icon_xiangzuo back_icon" ></i>
  7. 返回
  8. </el-button>
  9. <div class="school_name">{{ schoolName }}</div>
  10. </div>
  11. <!-- 筛选区域 -->
  12. <div class="filter_area">
  13. <TabSearch.default
  14. :tabList="tabList"
  15. tabType="box"
  16. :defaultTabKey="currentTab"
  17. @tabChange="ChangeTab"
  18. />
  19. <div class="search_area">
  20. <el-input
  21. v-model="searchKeyword"
  22. placeholder="请输入姓名/账号"
  23. @input="HandleSearch"
  24. >
  25. <template #append>
  26. <el-button :icon="Search" @click="HandleSearch" />
  27. </template>
  28. </el-input>
  29. </div>
  30. </div>
  31. <!-- 表格区域 -->
  32. <div class="page_table">
  33. <el-table
  34. :data="tableData"
  35. stripe
  36. v-loading="tableLoading"
  37. element-loading-text="拼命加载中……"
  38. :height="tableHeight"
  39. >
  40. <el-table-column type="index" label="序号" width="60" align="center" :index="GetTableIndex" />
  41. <el-table-column prop="userAccount" label="账号" min-width="100" align="center" show-overflow-tooltip />
  42. <el-table-column prop="userName" label="姓名" min-width="100" align="center">
  43. <template #default="{ row }">
  44. <span class="name_text" @click="GoEnter(row)">{{ row.userName }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column prop="wxName" label="微信名" min-width="100" align="center">
  48. <template #default="{ row }">
  49. {{ row.wxName || '-' }}
  50. </template>
  51. </el-table-column>
  52. <el-table-column prop="phone" label="手机号" min-width="120" align="center">
  53. <template #default="{ row }">
  54. {{ row.phone || '-' }}
  55. </template>
  56. </el-table-column>
  57. <el-table-column prop="binXKW" label="是否绑定学科网" width="160" align="center">
  58. <template #default="{ row }">
  59. {{ row.binXKW === 1 ? '是' : '否' }}
  60. </template>
  61. </el-table-column>
  62. <el-table-column prop="xkwId" label="学科网" width="160" align="center">
  63. <template #default="{ row }">
  64. {{ row.xkwId || '-' }}
  65. </template>
  66. </el-table-column>
  67. <el-table-column prop="status" label="状态" width="80" align="center">
  68. <template #default="{ row }">
  69. <div class="status_container">
  70. <span
  71. class="status_dot"
  72. :class="row.status === 1 ? 'active' : 'disabled'"
  73. ></span>
  74. <span :class="row.status === 1 ? 'status_active' : 'status_disabled'">
  75. {{ row.status === 1 ? '启用' : '禁用' }}
  76. </span>
  77. </div>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="操作" width="80" align="center" fixed="right">
  81. <template #default="{ row }">
  82. <span class="enter_button" @click="GoEnter(row)">进入</span>
  83. </template>
  84. </el-table-column>
  85. </el-table>
  86. </div>
  87. <!-- 分页器 -->
  88. <div class="page_pagination">
  89. <el-pagination
  90. v-model:current-page="pageNum"
  91. v-model:page-size="pageSize"
  92. :page-sizes="[20, 50, 100]"
  93. background
  94. layout="sizes, prev, pager, next"
  95. :total="total"
  96. @current-change="HandleCurrentChange"
  97. @size-change="HandleSizeChange"
  98. />
  99. </div>
  100. </div>
  101. </template>
  102. <script lang="ts" setup>
  103. import { ref, onMounted, onUnmounted, nextTick } from 'vue'
  104. import { useRoute, useRouter } from 'vue-router'
  105. import { Search } from '@element-plus/icons-vue'
  106. import { ElMessage } from 'element-plus'
  107. import { throttle } from 'lodash'
  108. import * as TabSearch from '@/baseComponents/TabSearch.vue'
  109. import { getAllTeacher, getTicket } from '@/api/school'
  110. const route = useRoute()
  111. const router = useRouter()
  112. // 学校信息
  113. const schoolName = ref('')
  114. const schoolId = ref('')
  115. // Tab列表
  116. interface TabItem {
  117. label: string
  118. key: string
  119. prefix?: string
  120. prefixLight?: string
  121. suffix?: string | number
  122. }
  123. const tabList = ref<TabItem[]>([
  124. { label: '全部', key: 'all' },
  125. { label: '已绑定学科网', key: 'bound' },
  126. { label: '未绑定学科网', key: 'unbound' },
  127. ])
  128. // Tab切换
  129. const currentTab = ref('all')
  130. // 搜索关键字
  131. const searchKeyword = ref('')
  132. // 表格数据
  133. interface Teacher {
  134. userId: number | string
  135. userAccount: string
  136. userName: string
  137. wxName: string
  138. phone: string
  139. status: number
  140. binXKW: number
  141. [key: string]: any
  142. }
  143. const tableData = ref<Teacher[]>([])
  144. const allData = ref<Teacher[]>([])
  145. const tableLoading = ref(false)
  146. const pageNum = ref(1)
  147. const pageSize = ref(20)
  148. const total = ref(0)
  149. const tableHeight = ref(0)
  150. // 跨页连续序号
  151. const GetTableIndex = (index: number) => {
  152. return (pageNum.value - 1) * pageSize.value + index + 1
  153. }
  154. // 前端筛选 + 分页
  155. const FilterAndPaginate = () => {
  156. let filteredData = [...allData.value]
  157. // tab筛选
  158. if (currentTab.value === 'bound') {
  159. filteredData = filteredData.filter(item => item.binXKW === 1)
  160. } else if (currentTab.value === 'unbound') {
  161. filteredData = filteredData.filter(item => item.binXKW === 0)
  162. }
  163. // 搜索筛选
  164. if (searchKeyword.value) {
  165. const keyword = searchKeyword.value.toLowerCase()
  166. filteredData = filteredData.filter(item =>
  167. (item.userName || '').toLowerCase().includes(keyword) ||
  168. (item.userAccount || '').toLowerCase().includes(keyword)
  169. )
  170. }
  171. total.value = filteredData.length
  172. const start = (pageNum.value - 1) * pageSize.value
  173. const end = start + pageSize.value
  174. tableData.value = filteredData.slice(start, end)
  175. }
  176. // 获取教师列表(仅初始化时调用)
  177. const GetTeacherList = async () => {
  178. tableLoading.value = true
  179. try {
  180. const params: Record<string, any> = {
  181. schoolId: schoolId.value,
  182. }
  183. const res = await getAllTeacher(params)
  184. allData.value = res.data || []
  185. FilterAndPaginate()
  186. } catch (error) {
  187. console.error('获取教师列表失败', error)
  188. } finally {
  189. tableLoading.value = false
  190. }
  191. }
  192. // 切换Tab(前端筛选)
  193. const ChangeTab = (tab: string) => {
  194. currentTab.value = tab
  195. pageNum.value = 1
  196. FilterAndPaginate()
  197. }
  198. // 搜索(前端筛选)
  199. const HandleSearch = () => {
  200. pageNum.value = 1
  201. FilterAndPaginate()
  202. }
  203. // 分页操作(前端分页)
  204. const HandleCurrentChange = (val: number) => {
  205. pageNum.value = val
  206. FilterAndPaginate()
  207. }
  208. const HandleSizeChange = (val: number) => {
  209. pageSize.value = val
  210. pageNum.value = 1
  211. FilterAndPaginate()
  212. }
  213. // 返回
  214. const GoBack = () => {
  215. router.back()
  216. }
  217. // 进入
  218. const GoEnter = (row: Teacher) => {
  219. // 禁用状态禁止进入
  220. if (row.status === 0) {
  221. ElMessage.error('该教师已禁用,无法进入')
  222. return
  223. }
  224. const params = {
  225. id: row.userId,
  226. }
  227. getTicket(params).then((res: any) => {
  228. const ticket = res.data
  229. let url = `https://www.k12100.com/#/otherLogin?type=1&schoolId=${schoolId.value}&id=${row.userId}&ticket=${ticket}`
  230. if (import.meta.env.VITE_API_BASE_URL === 'https://admin.k12100.com/admin/') {
  231. url = `https://www.k12100.com/#/otherLogin?type=1&schoolId=${schoolId.value}&id=${row.userId}&ticket=${ticket}`
  232. } else {
  233. url = `https://index.k12100.net/#/otherLogin?type=1&schoolId=${schoolId.value}&id=${row.userId}&ticket=${ticket}`
  234. }
  235. window.open(url)
  236. }).catch(() => {})
  237. }
  238. // 计算表格高度
  239. const SetTableHeight = () => {
  240. const containerHeight = document.documentElement.clientHeight
  241. const headerHeight = 60 // 顶部导航
  242. const filterHeight = 100 // 筛选区域
  243. const paginationHeight = 100 // 分页器
  244. const marginHeight = 40 // 边距
  245. tableHeight.value = containerHeight - headerHeight - filterHeight - paginationHeight - marginHeight
  246. }
  247. // 监听窗口大小变化
  248. const HandleResize = throttle(() => {
  249. SetTableHeight()
  250. }, 500)
  251. onMounted(() => {
  252. // 获取路由参数
  253. schoolName.value = route.query.schoolName as string || ''
  254. schoolId.value = route.query.schoolId as string || ''
  255. nextTick(() => {
  256. SetTableHeight()
  257. GetTeacherList()
  258. })
  259. window.addEventListener('resize', HandleResize)
  260. })
  261. onUnmounted(() => {
  262. window.removeEventListener('resize', HandleResize)
  263. })
  264. </script>
  265. <style lang="scss" scoped>
  266. .teacher_list_container {
  267. margin: 20px;
  268. box-sizing: border-box;
  269. background:#fff;
  270. border-radius: 10px;
  271. padding:20px;
  272. width: 100%;
  273. overflow: hidden;
  274. }
  275. // 顶部导航
  276. .header {
  277. display: flex;
  278. align-items: center;
  279. gap: 20px;
  280. margin-bottom: 20px;
  281. .back_button {
  282. width: 82px;
  283. height: 36px;
  284. background: #FFFFFF !important;
  285. border-radius: 4px;
  286. border: 1px solid #DCDFE6 !important;
  287. color: #606266;
  288. font-size: 14px;
  289. padding: 0;
  290. .back_icon {
  291. width: 14px;
  292. height: 14px;
  293. font-size: 14px;
  294. vertical-align: middle;
  295. color: #333;
  296. margin-right: 5px;
  297. }
  298. }
  299. .school_name {
  300. font-size: 16px;
  301. font-weight: 550;
  302. color: #333;
  303. }
  304. }
  305. // 筛选区域
  306. .filter_area {
  307. display: flex;
  308. align-items: center;
  309. gap: 20px;
  310. border-radius: 8px;
  311. margin-bottom: 16px;
  312. .search_area {
  313. flex: 1;
  314. max-width: 217px;
  315. }
  316. // TabSearch 组件样式穿透
  317. :deep(.box_tab) {
  318. .un_selected {
  319. color: #BBBBBB !important;
  320. }
  321. }
  322. }
  323. .page_table {
  324. width: 100%;
  325. min-width: 0;
  326. overflow: hidden;
  327. }
  328. // 表格内自定义样式
  329. .name_text {
  330. color: #2E64FA;
  331. cursor: pointer;
  332. &:hover {
  333. text-decoration: underline;
  334. }
  335. }
  336. // 状态样式
  337. .status_container {
  338. display: flex;
  339. align-items: center;
  340. justify-content: center;
  341. gap: 4px;
  342. }
  343. .status_dot {
  344. width: 8px;
  345. height: 8px;
  346. border-radius: 50%;
  347. &.active {
  348. background: #2BC644;
  349. }
  350. &.disabled {
  351. background: #F56C6C;
  352. }
  353. }
  354. .status_active {
  355. color: #2BC644;
  356. }
  357. .status_disabled {
  358. color: #F56C6C;
  359. }
  360. .enter_button {
  361. color: #2E64FA;
  362. cursor: pointer;
  363. &:hover {
  364. text-decoration: underline;
  365. }
  366. }
  367. </style>