index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="sys-cache-container">
  3. <NoticeBar text="系统缓存数据管理,请慎重操作!" leftIcon="iconfont icon-tongzhi2" background="var(--el-color-primary-light-9)" color="var(--el-color-primary)" />
  4. <el-row :gutter="8" style="width: 100%">
  5. <el-col :span="8" :xs="24">
  6. <el-card shadow="hover" header="缓存列表" v-loading="state.loading" class="mt8">
  7. <template #header>
  8. <div class="card-header">
  9. <span>缓存列表</span>
  10. <el-button icon="ele-Refresh" size="small" circle text @click="handleQuery" v-auth="'sysCache:keyList'" />
  11. </div>
  12. </template>
  13. <el-tree
  14. ref="treeRef"
  15. class="filter-tree"
  16. :data="state.cacheData"
  17. node-key="id"
  18. :props="{ children: 'children', label: 'name' }"
  19. @node-click="nodeClick"
  20. :default-checked-keys="state.cacheData"
  21. highlight-current
  22. check-strictly
  23. default-expand-all
  24. accordion
  25. />
  26. </el-card>
  27. </el-col>
  28. <el-col :span="16" :xs="24">
  29. <el-card shadow="hover" header="缓存数据" v-loading="state.loading1" class="mt8">
  30. <template #header>
  31. <div class="card-header">
  32. <span>{{ `缓存数据${state.cacheKey ? ` - ${state.cacheKey}` : ''}` }}</span>
  33. <el-button icon="ele-Delete" size="small" type="danger" @click="delCache" v-auth="'sysCache:delete'"> 删除缓存 </el-button>
  34. </div>
  35. </template>
  36. <vue-json-pretty :data="state.cacheValue" showLength showIcon showLineNumber showSelectController />
  37. </el-card>
  38. </el-col>
  39. </el-row>
  40. </div>
  41. </template>
  42. <script lang="ts" setup name="sysCache">
  43. import { onMounted, reactive, ref } from 'vue';
  44. import { ElMessageBox, ElMessage, ElTree } from 'element-plus';
  45. import NoticeBar from '/@/components/noticeBar/index.vue';
  46. import VueJsonPretty from 'vue-json-pretty';
  47. import 'vue-json-pretty/lib/styles.css';
  48. import { getAPI } from '/@/utils/axios-utils';
  49. import { SysCacheApi } from '/@/api-services';
  50. const treeRef = ref<InstanceType<typeof ElTree>>();
  51. const currentNode = ref<any>({});
  52. const state = reactive({
  53. loading: false,
  54. loading1: false,
  55. cacheData: [] as any,
  56. cacheValue: undefined,
  57. cacheKey: undefined,
  58. });
  59. onMounted(async () => {
  60. handleQuery();
  61. });
  62. // 查询操作
  63. const handleQuery = async () => {
  64. state.cacheData = [];
  65. state.cacheValue = undefined;
  66. state.cacheKey = undefined;
  67. state.loading = true;
  68. var res = await getAPI(SysCacheApi).apiSysCacheKeyListGet();
  69. let keyList: any = res.data.result;
  70. // 构造树(以分号分割)
  71. for (let i = 0; i < keyList.length; i++) {
  72. let keyNames = keyList[i].split(':');
  73. let pName = keyNames[0];
  74. if (state.cacheData.filter((x: any) => x.name == pName).length === 0) {
  75. state.cacheData.push({
  76. id: keyNames.length > 1 ? 0 : keyList[i],
  77. name: pName,
  78. children: [],
  79. });
  80. }
  81. if (keyNames.length > 1) {
  82. let pNode = state.cacheData.filter((x: any) => x.name == pName)[0] || {};
  83. pNode.children.push({
  84. id: keyList[i],
  85. name: keyList[i].substr(pName.length + 1),
  86. });
  87. }
  88. }
  89. state.loading = false;
  90. };
  91. // 删除
  92. const delCache = () => {
  93. if (currentNode.value.id == 0) {
  94. ElMessage.warning('禁止删除顶层缓存');
  95. return;
  96. }
  97. ElMessageBox.confirm(`确定删除缓存:【${currentNode.value.id}】?`, '提示', {
  98. confirmButtonText: '确定',
  99. cancelButtonText: '取消',
  100. type: 'warning',
  101. })
  102. .then(async () => {
  103. await getAPI(SysCacheApi).apiSysCacheDeleteKeyPost(currentNode.value.id);
  104. handleQuery();
  105. state.cacheValue = undefined;
  106. state.cacheKey = undefined;
  107. ElMessage.success('删除成功');
  108. })
  109. .catch(() => {});
  110. };
  111. // 树点击
  112. const nodeClick = async (node: any) => {
  113. if (node.id == 0) return;
  114. currentNode.value = node;
  115. state.loading1 = true;
  116. var res = await getAPI(SysCacheApi).apiSysCacheValueKeyGet(node.id);
  117. state.cacheValue = res.data.result;
  118. state.cacheKey = node.id;
  119. state.loading1 = false;
  120. };
  121. </script>
  122. <style lang="scss" scoped>
  123. .card-header {
  124. display: flex;
  125. justify-content: space-between;
  126. align-items: center;
  127. }
  128. </style>