index.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <div class="app-container" style="overflow: auto">
  3. <el-row :gutter="10" class="mb8 mtt"><el-button type="primary" icon="el-icon-plus" @click="op('add', {})">新增</el-button></el-row>
  4. <el-table :data="response" row-key="id" :default-expand-all="false" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
  5. <el-table-column prop="title" label="名称" width="260"></el-table-column>
  6. <el-table-column prop="orderNum" label="排序" align="center" width="200"></el-table-column>
  7. <el-table-column label="状态" align="center" prop="state" width="170">
  8. <template slot-scope="scope">
  9. <el-tag type="success" v-if="scope.row.state == 0">正常</el-tag>
  10. <el-tag type="danger" v-if="scope.row.state == 1">停用</el-tag>
  11. </template>
  12. </el-table-column>
  13. <el-table-column label="操作" align="center">
  14. <template slot-scope="scope">
  15. <el-button size="mini" type="text" icon="el-icon-edit" @click="op('edit', scope.row)" v-hasPermi="['work:column:edit']">修改</el-button>
  16. <el-button size="mini" type="text" icon="el-icon-plus" @click="op('add', scope.row)" v-if="scope.row.ancestors.length < 2">新增</el-button>
  17. <el-button v-if="scope.row.parentId != 0" size="mini" type="text" icon="el-icon-delete" @click="del(scope.row)">删除</el-button>
  18. </template>
  19. </el-table-column>
  20. <template slot="empty">
  21. <el-empty></el-empty>
  22. </template>
  23. </el-table>
  24. </div>
  25. </template>
  26. <script>
  27. import edit from './edit';
  28. export default {
  29. name: 'Column',
  30. data() {
  31. return {
  32. response: [{ ancestors: [] }],
  33. queryParams: {}
  34. };
  35. },
  36. created() {
  37. this.getList();
  38. },
  39. methods: {
  40. getList() {
  41. this.get({ url: '/work/column/tree', data: this.queryParams }).then(response => {
  42. response.data.forEach(item => {
  43. if (item.ancestors) {
  44. item.ancestors = item.ancestors.split(',');
  45. } else {
  46. item.ancestors = [];
  47. }
  48. });
  49. this.response = this.handleTree(response.data, 'id');
  50. });
  51. },
  52. op(tag, row) {
  53. if (tag == 'add') {
  54. this.iframe({ obj: edit, param: { parentId: row.id, parentName: row.title }, title: '新增栏目', width: '550px', height: '400px' });
  55. }
  56. if (tag == 'edit') {
  57. this.iframe({ obj: edit, param: { id: row.id }, title: '编辑栏目', width: '50%', height: '60%' });
  58. }
  59. },
  60. del(row) {
  61. this.$confirm('是否确认删除选中数据?,会和下级数据一起删除', '警告', { type: 'warning' }).then(() => {
  62. this.get({ url: '/work/column/remove/' + row.id }).then(response => {
  63. this.$modal.msgSuccess('删除成功');
  64. this.getList();
  65. });
  66. });
  67. }
  68. }
  69. };
  70. </script>