menu.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <hc-new-card>
  3. <template #header>
  4. <div class="w-40">
  5. <el-select v-model="searchForm.sysId" filterable clearable block placeholder="选择所属系统">
  6. <el-option v-for="item in clinets" :key="item.id" :label="item.clientId" :value="item.id" />
  7. </el-select>
  8. </div>
  9. <div class="ml-3 w-60">
  10. <hc-search-input v-model="searchForm.name" placeholder="请输入菜单名称" @search="searchClick" />
  11. </div>
  12. </template>
  13. <template #extra>
  14. <el-button hc-btn type="primary">新增</el-button>
  15. <el-button hc-btn type="danger">删除</el-button>
  16. </template>
  17. <hc-table
  18. ref="tableRef" :column="tableColumn" :datas="tableData" :loading="tableLoading"
  19. :is-index="false" is-new is-check :check-style="{ width: 29 }" lazy :load="tableLoad"
  20. @selection-change="tableCheckChange"
  21. >
  22. <template #sysId="{ row }">
  23. {{ getSystemNmae(row.sysId) }}
  24. </template>
  25. <template #category="{ row }">
  26. {{ row.category === 1 ? '菜单' : '按钮' }}
  27. </template>
  28. <template #action="{ row }">
  29. <el-link type="warning">修改</el-link>
  30. <el-link type="success">新增子项</el-link>
  31. <el-link type="primary">复制</el-link>
  32. <el-link type="danger">删除</el-link>
  33. </template>
  34. </hc-table>
  35. </hc-new-card>
  36. </template>
  37. <script setup>
  38. import { onActivated, ref } from 'vue'
  39. import mainApi from '~api/system/menu'
  40. import { getArrValue } from 'js-fast-way'
  41. import { getClinetAll } from '~api/other'
  42. //激活
  43. onActivated(() => {
  44. getClinetAllApi()
  45. getTableData()
  46. })
  47. //获取所有系统
  48. const clinets = ref([])
  49. const getClinetAllApi = async () => {
  50. const { data } = await getClinetAll()
  51. clinets.value = getArrValue(data)
  52. }
  53. //获取系统名称
  54. const getSystemNmae = (id) => {
  55. const item = clinets.value.find((item) => item.id === id)
  56. return item ? item.clientId : ''
  57. }
  58. //搜索表单
  59. const searchForm = ref({
  60. sysId: null, name: null,
  61. })
  62. //搜索
  63. const searchClick = () => {
  64. getTableData()
  65. }
  66. //表格数据
  67. const tableRef = ref(null)
  68. const tableColumn = ref([
  69. { key: 'name', name: '菜单名称' },
  70. { key: 'sysId', name: '所属系统' },
  71. { key: 'path', name: '路由地址' },
  72. { key: 'code', name: '菜单编号' },
  73. { key: 'category', name: '菜单类型', width: 90, align: 'center' },
  74. { key: 'sort', name: '排序', width: 80, align: 'center' },
  75. { key: 'action', name: '操作', width: 200, align: 'center' },
  76. ])
  77. //获取表格数据
  78. const tableLoading = ref(false)
  79. const tableData = ref([{}])
  80. const getTableData = async () => {
  81. tableData.value = []
  82. tableLoading.value = true
  83. const { data } = await mainApi.getLazyList({
  84. ...searchForm.value,
  85. parentId: 0,
  86. })
  87. tableData.value = getArrValue(data)
  88. tableLoading.value = false
  89. }
  90. //懒加载表格
  91. const tableLoad = async (row, node, resolve) => {
  92. const { data } = await mainApi.getLazyList({
  93. ...searchForm.value,
  94. parentId: row.id,
  95. })
  96. resolve(getArrValue(data))
  97. }
  98. //表格被选择
  99. const tableCheckChange = () => {
  100. }
  101. </script>
  102. <style scoped lang="scss">
  103. </style>