EducationSystems.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="education-systems admin-page">
  3. <el-card>
  4. <div slot="header" class="admin-page-header">
  5. <span class="admin-page-title">教育体系管理</span>
  6. <div class="flex items-center gap-sm">
  7. <el-input v-model="keyword" placeholder="搜索体系..." prefix-icon="el-icon-search" clearable @keyup.enter.native="handleSearch" @clear="handleSearch" />
  8. <el-button type="primary" size="small" @click="handleCreate">+ 添加体系</el-button>
  9. </div>
  10. </div>
  11. <div class="table-scroll-wrap"><el-table :data="filteredData" stripe>
  12. <el-table-column prop="id" label="ID" width="80"></el-table-column>
  13. <el-table-column prop="name" label="编码" width="120"></el-table-column>
  14. <el-table-column prop="label" label="显示名称"></el-table-column>
  15. <el-table-column prop="description" label="描述"></el-table-column>
  16. <el-table-column prop="sortOrder" label="排序" width="80"></el-table-column>
  17. <el-table-column prop="status" label="状态" width="100">
  18. <template slot-scope="scope">
  19. <el-tag :type="scope.row.status === 'ACTIVE' ? 'success' : 'danger'">
  20. {{ scope.row.status === 'ACTIVE' ? '启用' : '停用' }}
  21. </el-tag>
  22. </template>
  23. </el-table-column>
  24. <el-table-column label="操作" width="200" fixed="right">
  25. <template slot-scope="{ row }">
  26. <el-button size="mini" type="primary" @click="handleEdit(row)">编辑</el-button>
  27. <el-dropdown trigger="hover" @command="(cmd) => handleActionCmd(row, cmd)">
  28. <el-button size="mini">
  29. 更多<i class="el-icon-arrow-down el-icon--right"></i>
  30. </el-button>
  31. <el-dropdown-menu slot="dropdown">
  32. <el-dropdown-item :command="row.status === 'ACTIVE' ? 'disable' : 'enable'" icon="el-icon-switch-button">{{ row.status === 'ACTIVE' ? '停用' : '启用' }}</el-dropdown-item>
  33. </el-dropdown-menu>
  34. </el-dropdown>
  35. </template>
  36. </el-table-column>
  37. </el-table></div>
  38. </el-card>
  39. <el-dialog :visible.sync="dialogVisible" :title="isEdit ? '编辑教育体系' : '添加教育体系'" width="500px">
  40. <el-form :model="form" label-width="80px">
  41. <el-form-item label="编码">
  42. <el-input v-model="form.name" placeholder="如: bachelor"></el-input>
  43. </el-form-item>
  44. <el-form-item label="显示名称">
  45. <el-input v-model="form.label" placeholder="如: 本科"></el-input>
  46. </el-form-item>
  47. <el-form-item label="描述">
  48. <el-input v-model="form.description" type="textarea"></el-input>
  49. </el-form-item>
  50. <el-form-item label="排序">
  51. <el-input-number v-model="form.sortOrder" :min="0"></el-input-number>
  52. </el-form-item>
  53. </el-form>
  54. <div slot="footer">
  55. <el-button @click="dialogVisible = false">取消</el-button>
  56. <el-button type="primary" @click="handleSubmit">保存</el-button>
  57. </div>
  58. </el-dialog>
  59. </div>
  60. </template>
  61. <script>
  62. import { getAllEducationSystems, createEducationSystem, updateEducationSystem } from '@/api/admin'
  63. export default {
  64. name: 'EducationSystems',
  65. data() {
  66. return {
  67. systems: [],
  68. keyword: '',
  69. dialogVisible: false,
  70. isEdit: false,
  71. form: {
  72. id: null,
  73. name: '',
  74. label: '',
  75. description: '',
  76. sortOrder: 0,
  77. status: 'ACTIVE'
  78. }
  79. }
  80. },
  81. computed: {
  82. filteredData() {
  83. if (!this.keyword) return this.systems
  84. const kw = this.keyword.toLowerCase()
  85. return this.systems.filter(item => item.name?.toLowerCase().includes(kw) || item.label?.toLowerCase().includes(kw))
  86. }
  87. },
  88. created() {
  89. this.loadData()
  90. },
  91. methods: {
  92. async loadData() {
  93. try {
  94. const res = await getAllEducationSystems()
  95. if (res.data) {
  96. this.systems = res.data
  97. }
  98. } catch (e) {
  99. console.error(e)
  100. }
  101. },
  102. handleCreate() {
  103. this.isEdit = false
  104. this.form = { id: null, name: '', label: '', description: '', sortOrder: 0, status: 'ACTIVE' }
  105. this.dialogVisible = true
  106. },
  107. handleEdit(row) {
  108. this.isEdit = true
  109. this.form = { ...row }
  110. this.dialogVisible = true
  111. },
  112. async toggleStatus(row) {
  113. row.status = row.status === 'ACTIVE' ? 'DISABLED' : 'ACTIVE'
  114. try {
  115. await updateEducationSystem(row)
  116. this.$message.success('状态已更新')
  117. } catch (e) {
  118. row.status = row.status === 'ACTIVE' ? 'DISABLED' : 'ACTIVE'
  119. this.$message.error('更新失败')
  120. }
  121. },
  122. async handleSubmit() {
  123. try {
  124. if (this.isEdit) {
  125. await updateEducationSystem(this.form)
  126. } else {
  127. await createEducationSystem(this.form)
  128. }
  129. this.$message.success('保存成功')
  130. this.dialogVisible = false
  131. this.loadData()
  132. } catch (e) {
  133. this.$message.error('保存失败')
  134. }
  135. },
  136. handleSearch() {},
  137. handleActionCmd(row, cmd) {
  138. switch (cmd) {
  139. case 'disable':
  140. row.status = 'DISABLED'
  141. this.toggleStatus(row)
  142. break
  143. case 'enable':
  144. row.status = 'ACTIVE'
  145. this.toggleStatus(row)
  146. break
  147. }
  148. }
  149. }
  150. }
  151. </script>
  152. <style scoped>
  153. </style>