index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div style="padding: 0px 0px 8px 8px">
  3. <el-row :gutter="8" style="width: 100%">
  4. <el-col :span="24" :xs="24">
  5. <el-card shadow="never" :body-style="{ paddingBottom: '0' }" style="margin-top: 8px">
  6. <el-form :model="state.filterModel" :inline="true" @submit.stop.prevent>
  7. <el-form-item label="部门名称" prop="name">
  8. <el-input v-model="state.filterModel.name" placeholder="部门名称" @keyup.enter="onQuery" />
  9. </el-form-item>
  10. <el-form-item>
  11. <el-button type="primary" icon="ele-Search" @click="onQuery"> 查询 </el-button>
  12. <el-button v-auth="'api:admin:org:add'" type="primary" icon="ele-Plus" @click="onAdd"> 新增 </el-button>
  13. </el-form-item>
  14. </el-form>
  15. </el-card>
  16. <el-card shadow="never" style="margin-top: 8px">
  17. <el-table
  18. :data="state.orgTreeData"
  19. style="width: 100%"
  20. v-loading="state.loading"
  21. row-key="id"
  22. default-expand-all
  23. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  24. >
  25. <el-table-column prop="name" label="部门名称" min-width="120" show-overflow-tooltip />
  26. <el-table-column prop="code" label="部门编码" min-width="120" show-overflow-tooltip />
  27. <el-table-column prop="value" label="部门值" min-width="80" show-overflow-tooltip />
  28. <el-table-column prop="sort" label="排序" width="80" align="center" show-overflow-tooltip />
  29. <el-table-column label="状态" width="80" align="center" show-overflow-tooltip>
  30. <template #default="{ row }">
  31. <el-tag type="success" v-if="row.enabled">启用</el-tag>
  32. <el-tag type="danger" v-else>禁用</el-tag>
  33. </template>
  34. </el-table-column>
  35. <el-table-column label="操作" width="160" fixed="right" header-align="center" align="center">
  36. <template #default="{ row }">
  37. <el-button v-auth="'api:admin:org:update'" icon="ele-EditPen" size="small" text type="primary" @click="onEdit(row)">编辑</el-button>
  38. <el-button v-auth="'api:admin:org:delete'" icon="ele-Delete" size="small" text type="danger" @click="onDelete(row)">删除</el-button>
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. </el-card>
  43. </el-col>
  44. </el-row>
  45. <org-form ref="orgFormRef" :title="state.orgFormTitle" :org-tree-data="state.orgTreeData"></org-form>
  46. </div>
  47. </template>
  48. <script lang="ts" setup name="admin/org">
  49. import { ref, reactive, onMounted, getCurrentInstance, onUnmounted, defineAsyncComponent } from 'vue'
  50. import { OrgListOutput } from '/@/api/admin/data-contracts'
  51. import { OrgApi } from '/@/api/admin/Org'
  52. import { listToTree } from '/@/utils/tree'
  53. import eventBus from '/@/utils/mitt'
  54. // 引入组件
  55. const OrgForm = defineAsyncComponent(() => import('./components/org-form.vue'))
  56. const { proxy } = getCurrentInstance() as any
  57. const orgFormRef = ref()
  58. const state = reactive({
  59. loading: false,
  60. orgFormTitle: '',
  61. filterModel: {
  62. name: '',
  63. },
  64. orgTreeData: [] as Array<OrgListOutput>,
  65. })
  66. onMounted(() => {
  67. onQuery()
  68. eventBus.on('refreshOrg', () => {
  69. onQuery()
  70. })
  71. })
  72. onUnmounted(() => {
  73. eventBus.off('refreshOrg')
  74. })
  75. const onQuery = async () => {
  76. state.loading = true
  77. const res = await new OrgApi().getList()
  78. if (res.data && res.data.length > 0) {
  79. state.orgTreeData = listToTree(res.data)
  80. } else {
  81. state.orgTreeData = []
  82. }
  83. state.loading = false
  84. }
  85. const onAdd = () => {
  86. state.orgFormTitle = '新增部门'
  87. orgFormRef.value.open()
  88. }
  89. const onEdit = (row: OrgListOutput) => {
  90. state.orgFormTitle = '编辑部门'
  91. orgFormRef.value.open(row)
  92. }
  93. const onDelete = (row: OrgListOutput) => {
  94. proxy.$modal
  95. .confirmDelete(`确定要删除部门【${row.name}】?`)
  96. .then(async () => {
  97. await new OrgApi().delete({ id: row.id }, { loading: true })
  98. onQuery()
  99. })
  100. .catch(() => {})
  101. }
  102. </script>
  103. <style scoped lang="scss"></style>