8
0

api.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.name" :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. <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" :is-index="false" is-new lazy :load="tableLoad">
  14. <template #sysId="{ row }">{{ getSystemNmae(row.sysId) }}</template>
  15. <template #action="{ row }">
  16. <el-link type="primary" @click="authRowClick(row)">权限配置</el-link>
  17. </template>
  18. </hc-table>
  19. <!-- 权限配置 -->
  20. <HcApiAuth v-model="isDataAuthShow" :mid="rowAuthInfo.id" :title="rowAuthInfo.name" @close="dataAuthClose" />
  21. </hc-new-card>
  22. </template>
  23. <script setup>
  24. import { nextTick, onActivated, ref } from 'vue'
  25. import { useRoute, useRouter } from 'vue-router'
  26. import { getArrValue, getObjValue } from 'js-fast-way'
  27. import HcApiAuth from './modules/api/auth.vue'
  28. import { getClinetAll } from '~api/other'
  29. import menuApi from '~api/system/menu'
  30. //初始组合式
  31. const router = useRouter()
  32. const useRoutes = useRoute()
  33. //激活
  34. onActivated(() => {
  35. //获取参数
  36. const { sysId, name } = getObjValue(useRoutes.query)
  37. searchForm.value = { sysId: sysId, name: name }
  38. //获取数据
  39. getClinetAllApi()
  40. getTableData()
  41. })
  42. //获取所有系统
  43. const clinets = ref([])
  44. const getClinetAllApi = async () => {
  45. const { data } = await getClinetAll()
  46. clinets.value = getArrValue(data)
  47. }
  48. //获取系统名称
  49. const getSystemNmae = (id) => {
  50. const item = clinets.value.find((item) => item.id === id)
  51. return item ? item.name : ''
  52. }
  53. //搜索表单
  54. const searchForm = ref({ sysId: null, name: null })
  55. //搜索
  56. const searchClick = () => {
  57. router.push({
  58. name: 'api_scope',
  59. query: searchForm.value,
  60. })
  61. getTableData()
  62. }
  63. //表格数据
  64. const tableColumn = ref([
  65. { key: 'name', name: '菜单名称' },
  66. { key: 'sysId', name: '所属系统' },
  67. { key: 'path', name: '路由地址' },
  68. { key: 'code', name: '菜单编号' },
  69. { key: 'sort', name: '排序', width: 80, align: 'center' },
  70. { key: 'action', name: '操作', width: 90, align: 'center' },
  71. ])
  72. const tableData = ref([])
  73. //获取表格数据
  74. const tableLoading = ref(true)
  75. const getTableData = async () => {
  76. tableData.value = []
  77. tableLoading.value = true
  78. tableData.value = await getLazyList(0)
  79. tableLoading.value = false
  80. }
  81. //懒加载表格
  82. const tableLoad = async (row, node, resolve) => {
  83. resolve(await getLazyList(row.id))
  84. }
  85. //获取表格数据
  86. const getLazyList = async (id) => {
  87. let newArr = []
  88. const { data } = await menuApi.getLazyList({
  89. ...searchForm.value,
  90. parentId: id,
  91. })
  92. //处理数据
  93. const res = getArrValue(data)
  94. for (let i = 0; i < res.length; i++) {
  95. if (res[i].category === 1) {
  96. newArr.push(res[i])
  97. }
  98. }
  99. return newArr
  100. }
  101. //数据权限配置
  102. const isDataAuthShow = ref(false)
  103. const rowAuthInfo = ref({})
  104. const authRowClick = (row) => {
  105. rowAuthInfo.value = row
  106. nextTick(() => {
  107. isDataAuthShow.value = true
  108. })
  109. }
  110. //关闭权限配置弹窗
  111. const dataAuthClose = () => {
  112. isDataAuthShow.value = false
  113. rowAuthInfo.value = {}
  114. }
  115. </script>