xiangpei
2024-07-08 13b316fead23d7da15f1d974e3e436ecb6efbfb9
课目重构
3个文件已修改
125 ■■■■ 已修改文件
src/api/subject.js 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/education/subject/list.vue 120 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/subject.js
@@ -6,5 +6,6 @@
  edit: query => post('/api/admin/education/subject/edit', query),
  select: id => post('/api/admin/education/subject/select/' + id),
  selectByDeptId: deptId => get('/api/admin/education/subject/select/dept/' + deptId),
  deleteSubject: id => post('/api/admin/education/subject/delete/' + id)
  deleteSubject: id => post('/api/admin/education/subject/delete/' + id),
  add: data => post('/api/admin/education/subject/add', data)
}
src/router.js
@@ -270,7 +270,7 @@
        path: 'subject/list',
        component: () => import('@/views/education/subject/list'),
        name: 'EducationSubjectPage',
        meta: { title: '课目列表', noCache: true }
        meta: { title: '部门课目', noCache: true }
      },
      {
        path: 'department/list',
src/views/education/subject/list.vue
@@ -15,20 +15,56 @@
      </el-form-item>
    </el-form>
    <el-table v-loading="listLoading" :data="tableData" border fit highlight-current-row style="width: 100%">
      <el-table-column prop="name" label="课目名称"/>
      <el-table-column prop="deptNames" label="所属部门" />
      <el-table-column width="220px" label="操作" align="center">
    <el-table
      v-loading="listLoading"
      :data="tableData"
      border fit highlight-current-row style="width: 100%"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      row-key="id"
    >
      <el-table-column prop="name" label="部门" />
      <el-table-column prop="subjectNames" label="课目"/>
      <el-table-column width="240px" label="操作" align="center">
        <template slot-scope="{row}">
          <router-link :to="{path:'/education/subject/edit', query:{id:row.id}}" class="link-left">
            <el-button size="mini">编辑</el-button>
          </router-link>
          <el-button   size="mini" type="danger" @click="delSubject(row)" class="link-left">删除</el-button>
          <el-button type="success" @click="addSubject(row.id, row.name)" size="mini">添加课目</el-button>
          <el-button type="primary" @click="editSubject(row.id, row.name, row.subjectIds)" size="mini">编辑</el-button>
<!--          <el-button   size="mini" type="danger" @click="delSubject(row)" class="link-left">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParam.pageIndex" :limit.sync="queryParam.pageSize"
                @pagination="search"/>
    <el-dialog
      :title="addTitle"
      :visible.sync="addShow"
      width="450px"
    >
      <el-input v-model="addForm.subjectName" placeholder="课目名称" required/>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelAdd">取 消</el-button>
        <el-button type="primary" @click="add">保 存</el-button>
      </span>
    </el-dialog>
    <el-dialog
      :title="editTitle"
      :visible.sync="editShow"
      width="450px"
    >
      <el-form label-position="top">
        <el-form-item label="部门">
          <el-input v-model="editForm.deptName" disabled required/>
        </el-form-item>
        <el-form-item label="课目">
          <el-select v-model="editForm.subjectIds" multiple placeholder="请选择该部门对应的课目">
            <el-option v-for="subject in subjectList" :key="subject.id" :value="subject.id" :label="subject.name"/>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelEdit">取 消</el-button>
        <el-button type="primary" @click="edit">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>
@@ -41,6 +77,20 @@
  components: { Pagination },
  data () {
    return {
      subjectList: [],
      addForm: {
        deptId: null,
        subjectName: ''
      },
      editForm: {
        deptId: null,
        deptName: null,
        subjectIds: []
      },
      addTitle: '',
      editTitle: '',
      addShow: false,
      editShow: false,
      queryParam: {
        level: null,
        pageIndex: 1,
@@ -53,16 +103,56 @@
  },
  created () {
    this.search()
    this.getAllSubject()
  },
  methods: {
    getAllSubject() {
      subjectApi.list().then(res => {
        this.subjectList = res.response
      })
    },
    editSubject(deptId, deptName, subjectIds) {
      this.editTitle = "修改【" + deptName + "】的课目"
      this.editForm.deptId = deptId
      this.editForm.deptName = deptName
      this.editForm.subjectIds = subjectIds;
      this.editShow = true
    },
    addSubject(deptId, deptName) {
      this.addTitle = "为【" + deptName + "】添加课目";
      this.addShow = true;
      this.addForm.deptId = deptId
    },
    add() {
      subjectApi.add(this.addForm).then(res => {
        this.$message.success("添加成功")
        this.addShow = false
        this.search()
      })
    },
    edit() {
      subjectApi.edit(this.editForm).then(res => {
        this.$message.success("修改成功")
        this.editShow = false
        this.search()
      })
    },
    cancelEdit() {
      this.editShow = false
      this.editTitle = ""
      this.editForm.deptId = null
      this.editForm.deptName = ""
      this.editForm.subjectIds = []
    },
    cancelAdd() {
      this.addShow = false
      this.addTitle = ""
      this.addForm.subjectName = ""
    },
    search () {
      this.listLoading = true
      subjectApi.pageList(this.queryParam).then(data => {
        const re = data.response
        this.tableData = re.list
        this.total = re.total
        this.queryParam.pageIndex = re.pageNum
        this.tableData = data.response
        this.listLoading = false
      })
    },