index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <script lang="ts" setup>
  2. import { ElMessage, ElMessageBox } from 'element-plus'
  3. import { deleteApiReqById, getApiReqByPage } from '@/api/paas/apiReqApi'
  4. import { getModuleByList } from '@/api/paas/moduleApi'
  5. const { pagination, getParams, onSizeChange, onCurrentChange } = usePagination()
  6. interface TreeNode {
  7. label: string
  8. isLeaf: boolean
  9. moduleId: number
  10. children?: TreeNode[]
  11. }
  12. const state = reactive({
  13. loading: false,
  14. curModuleId: 0,
  15. modules: [] as TreeNode[],
  16. reqList: [],
  17. search: {
  18. keywords: '',
  19. },
  20. })
  21. const leftTreeRef = ref()
  22. const ModuleRef = ref()
  23. // 查询日志列表
  24. const getReqData = async () => {
  25. const params = getParams()
  26. params.moduleId = state.curModuleId
  27. params.keywords = state.search.keywords
  28. state.loading = true
  29. const { data } = await getApiReqByPage(params)
  30. state.reqList = data.data
  31. state.loading = false
  32. }
  33. const getModuleData = async () => {
  34. const { data } = await getModuleByList('')
  35. const children: TreeNode[] = []
  36. data.forEach((item: any) => {
  37. return children.push({
  38. label: item.moduleTitle,
  39. moduleId: item.moduleId,
  40. isLeaf: true,
  41. })
  42. })
  43. state.modules = [
  44. {
  45. label: 'API模块列表',
  46. isLeaf: false,
  47. moduleId: -1,
  48. children,
  49. },
  50. ]
  51. if (data && data.length > 0) {
  52. state.curModuleId = data[0].moduleId
  53. nextTick(() => {
  54. leftTreeRef.value.setCurrentKey(data[0].moduleId)
  55. })
  56. await getReqData()
  57. }
  58. }
  59. // 每页数量切换
  60. function sizeChange(size: number) {
  61. onSizeChange(size).then(() => getReqData())
  62. }
  63. // 当前页码切换(翻页)
  64. function currentChange(page = 1) {
  65. onCurrentChange(page).then(() => getReqData())
  66. }
  67. // 查询
  68. const onSearch = () => {
  69. getReqData()
  70. }
  71. onMounted(() => {
  72. getModuleData()
  73. })
  74. // 模块选择
  75. const onTreeNodeClick = (node: TreeNode) => {
  76. if (node.isLeaf) {
  77. state.curModuleId = node.moduleId
  78. getReqData()
  79. }
  80. }
  81. // 删除日志
  82. const onReqDel = async (data: { apiTitle: any; reqId: number }) => {
  83. ElMessageBox.confirm('确认删除吗?', '确认信息').then(async () => {
  84. await deleteApiReqById(data.reqId)
  85. await getReqData()
  86. ElMessage.success({
  87. message: '删除成功',
  88. center: true,
  89. })
  90. })
  91. }
  92. </script>
  93. <template>
  94. <div class="absolute-container">
  95. <page-header title="日志管理" content="日志调用管理" />
  96. <div class="page-main">
  97. <LayoutContainer left-side-width="300px" hide-left-side-toggle>
  98. <template #leftSide>
  99. <el-scrollbar class="tree">
  100. <ElTree ref="leftTreeRef" :data="state.modules" default-expand-all node-key="moduleId" @node-click="onTreeNodeClick">
  101. <template #default="{ node, data }">
  102. <div class="custom-tree-node">
  103. <div class="label" :title="node.label">
  104. <el-icon v-if="data.isLeaf" size="16px" style="margin-right: 5px;">
  105. <svg-icon name="uim:box" />
  106. </el-icon>
  107. <div class="text">
  108. {{ data.label }}
  109. </div>
  110. </div>
  111. <div v-if="data.isLeaf" class="actions" />
  112. </div>
  113. </template>
  114. </ElTree>
  115. </el-scrollbar>
  116. </template>
  117. <div class="container">
  118. <tool-bar>
  119. <template #right>
  120. <el-input v-model="state.search.keywords" placeholder="请输入名称,支持模糊查询" style="padding-right: 10px;" clearable />
  121. <el-button type="primary" @click="onSearch">
  122. <template #icon>
  123. <el-icon>
  124. <svg-icon name="i-ep:search" />
  125. </el-icon>
  126. </template>
  127. </el-button>
  128. </template>
  129. </tool-bar>
  130. <el-table ref="apiReqTableRef" v-loading="state.loading" class="list-table" :data="state.reqList" border stripe highlight-current-row>
  131. <el-table-column type="index" align="center" label="序号" width="60" />
  132. <el-table-column align="center" width="100" label="接口名称" prop="apiTitle" />
  133. <el-table-column align="center" label="调用者IP" prop="appTitle" />
  134. <el-table-column align="center" label="创建时间" prop="reqTime" />
  135. <el-table-column label="操作" header-align="center" align="center" width="220">
  136. <template #default="scope">
  137. <el-button v-if="scope.row.isFixed !== 1" size="small" type="danger" @click="onReqDel(scope.row)">
  138. 删除
  139. </el-button>
  140. </template>
  141. </el-table-column>
  142. </el-table>
  143. <el-pagination :current-page="pagination.page" :total="pagination.total" :page-size="pagination.size" :page-sizes="pagination.sizes" :layout="pagination.layout" :hide-on-single-page="false" class="pagination" background @current-change="currentChange" @size-change="sizeChange" />
  144. </div>
  145. </LayoutContainer>
  146. </div>
  147. </div>
  148. </template>
  149. <style lang="scss" scoped>
  150. .container {
  151. height: 100%;
  152. display: flex;
  153. flex-direction: column;
  154. }
  155. .absolute-container {
  156. :deep(.left-side) {
  157. display: flex;
  158. flex-direction: column;
  159. height: 100%;
  160. .btns {
  161. display: inline-flex;
  162. width: 100%;
  163. margin-bottom: var(--container-padding);
  164. .add {
  165. width: 100%;
  166. }
  167. }
  168. .tree {
  169. flex: 1;
  170. overflow-y: auto;
  171. .el-tree {
  172. .el-tree-node__content {
  173. height: 40px;
  174. }
  175. .is-current > .el-tree-node__content {
  176. background-color: var(--el-color-primary-light-9);
  177. }
  178. .custom-tree-node {
  179. flex: 1;
  180. position: relative;
  181. width: 0;
  182. height: 100%;
  183. display: flex;
  184. flex-direction: column;
  185. justify-content: center;
  186. .label {
  187. display: inline-flex;
  188. align-items: center;
  189. width: calc(100% - 10px);
  190. color: var(--el-text-color-primary);
  191. .text {
  192. @include text-overflow;
  193. }
  194. }
  195. &:hover {
  196. .actions {
  197. display: block;
  198. }
  199. }
  200. .actions {
  201. display: none;
  202. position: absolute;
  203. right: 10px;
  204. top: 50%;
  205. transform: translateY(-50%);
  206. .el-button {
  207. padding: 5px 8px;
  208. }
  209. }
  210. }
  211. }
  212. }
  213. }
  214. }
  215. </style>