8
0

api.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <hc-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" 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-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. defineOptions({
  34. name: 'ApiScope',
  35. })
  36. //激活
  37. onActivated(() => {
  38. //获取参数
  39. const { sysId, name } = getObjValue(useRoutes.query)
  40. searchForm.value = { sysId: sysId, name: name }
  41. //获取数据
  42. getClinetAllApi()
  43. getTableData()
  44. })
  45. //获取所有系统
  46. const clinets = ref([])
  47. const getClinetAllApi = async () => {
  48. const { data } = await getClinetAll()
  49. clinets.value = getArrValue(data)
  50. }
  51. //获取系统名称
  52. const getSystemNmae = (id) => {
  53. const item = clinets.value.find((item) => item.id === id)
  54. return item ? item.name : ''
  55. }
  56. //搜索表单
  57. const searchForm = ref({ sysId: null, name: null })
  58. //搜索
  59. const searchClick = () => {
  60. router.push({
  61. name: 'api_scope',
  62. query: searchForm.value,
  63. })
  64. getTableData()
  65. }
  66. //表格数据
  67. const tableColumn = ref([
  68. { key: 'name', name: '菜单名称' },
  69. { key: 'sysId', name: '所属系统' },
  70. { key: 'path', name: '路由地址' },
  71. { key: 'code', name: '菜单编号' },
  72. { key: 'sort', name: '排序', width: 80, align: 'center' },
  73. { key: 'action', name: '操作', width: 90, align: 'center' },
  74. ])
  75. const tableData = ref([])
  76. //获取表格数据
  77. const tableLoading = ref(true)
  78. const getTableData = async () => {
  79. tableData.value = []
  80. tableLoading.value = true
  81. tableData.value = await getLazyList(0)
  82. tableLoading.value = false
  83. }
  84. //懒加载表格
  85. const tableLoad = async (row, node, resolve) => {
  86. resolve(await getLazyList(row.id))
  87. }
  88. //获取表格数据
  89. const getLazyList = async (id) => {
  90. let newArr = []
  91. const { data } = await menuApi.getLazyList({
  92. ...searchForm.value,
  93. parentId: id,
  94. })
  95. //处理数据
  96. const res = getArrValue(data)
  97. for (let i = 0; i < res.length; i++) {
  98. if (res[i].category === 1) {
  99. newArr.push(res[i])
  100. }
  101. }
  102. return newArr
  103. }
  104. //数据权限配置
  105. const isDataAuthShow = ref(false)
  106. const rowAuthInfo = ref({})
  107. const authRowClick = (row) => {
  108. rowAuthInfo.value = row
  109. nextTick(() => {
  110. isDataAuthShow.value = true
  111. })
  112. }
  113. //关闭权限配置弹窗
  114. const dataAuthClose = () => {
  115. isDataAuthShow.value = false
  116. rowAuthInfo.value = {}
  117. }
  118. </script>