index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div class="sys-cache-container h100">
  3. <el-splitter class="smallbar-el-splitter">
  4. <el-splitter-panel size="20%" :min="200">
  5. <CardPro title="缓存列表" v-loading="state.loading" full-height body-style="overflow:auto">
  6. <template #suffix>
  7. <el-button icon="ele-Refresh" type="success" circle plain @click="handleQuery" v-auth="'sysCache:keyList'" />
  8. <el-button icon="ele-DeleteFilled" type="danger" circle plain @click="clearCache" v-auth="'sysCache:clear'"> </el-button>
  9. </template>
  10. <el-tree
  11. ref="treeRef"
  12. class="filter-tree"
  13. :data="state.cacheData"
  14. node-key="id"
  15. :props="{ children: 'children', label: 'name' }"
  16. @node-click="nodeClick"
  17. :default-checked-keys="state.cacheData"
  18. highlight-current
  19. check-strictly
  20. default-expand-all
  21. accordion
  22. />
  23. </CardPro>
  24. </el-splitter-panel>
  25. <el-splitter-panel :min="200">
  26. <CardPro :title="`缓存数据${state.cacheKey ? `【${state.cacheKey}】` : ''}`" v-loading="state.loading1" full-height body-style="overflow:auto">
  27. <template #suffix>
  28. <el-button icon="ele-Delete" type="danger" @click="delCache" v-auth="'sysCache:delete'"> 删除缓存 </el-button>
  29. </template>
  30. <vue-json-pretty :data="state.cacheValue" showLength showIcon showLineNumber showSelectController />
  31. </CardPro>
  32. </el-splitter-panel>
  33. </el-splitter>
  34. </div>
  35. </template>
  36. <script lang="ts" setup name="sysCache">
  37. import { onMounted, reactive, ref } from 'vue';
  38. import { ElMessageBox, ElMessage, ElTree } from 'element-plus';
  39. import CardPro from '/@/components/CardPro/index.vue';
  40. import VueJsonPretty from 'vue-json-pretty';
  41. import 'vue-json-pretty/lib/styles.css';
  42. import 'splitpanes/dist/splitpanes.css';
  43. import { getAPI } from '/@/utils/axios-utils';
  44. import { SysCacheApi } from '/@/api-services';
  45. const treeRef = ref<InstanceType<typeof ElTree>>();
  46. const currentNode = ref<any>({});
  47. const state = reactive({
  48. loading: false,
  49. loading1: false,
  50. cacheData: [] as any,
  51. cacheValue: undefined as any,
  52. cacheKey: undefined,
  53. });
  54. onMounted(async () => {
  55. await handleQuery();
  56. });
  57. // 查询操作
  58. const handleQuery = async () => {
  59. state.cacheData = [];
  60. state.cacheValue = undefined;
  61. state.cacheKey = undefined;
  62. state.loading = true;
  63. var res = await getAPI(SysCacheApi).apiSysCacheKeyListGet();
  64. let keyList: any = res.data.result;
  65. // 构造树(以分号分割)
  66. for (let i = 0; i < keyList.length; i++) {
  67. let keyNames = keyList[i].split(':');
  68. let pName = keyNames[0];
  69. if (state.cacheData.filter((x: any) => x.name == pName).length === 0) {
  70. state.cacheData.push({
  71. id: keyNames.length > 1 ? 0 : keyList[i],
  72. name: pName,
  73. children: [],
  74. });
  75. }
  76. if (keyNames.length > 1) {
  77. let pNode = state.cacheData.filter((x: any) => x.name == pName)[0] || {};
  78. pNode.children.push({
  79. id: keyList[i],
  80. name: keyList[i].substr(pName.length + 1),
  81. });
  82. }
  83. }
  84. state.loading = false;
  85. };
  86. // 删除
  87. const delCache = () => {
  88. if (currentNode.value.id == 0) {
  89. ElMessage.warning('禁止删除顶层缓存');
  90. return;
  91. }
  92. ElMessageBox.confirm(`确定删除缓存:【${currentNode.value.id}】?`, '提示', {
  93. confirmButtonText: '确定',
  94. cancelButtonText: '取消',
  95. type: 'warning',
  96. })
  97. .then(async () => {
  98. await getAPI(SysCacheApi).apiSysCacheDeleteKeyPost(currentNode.value.id);
  99. await handleQuery();
  100. state.cacheValue = undefined;
  101. state.cacheKey = undefined;
  102. ElMessage.success('删除成功');
  103. })
  104. .catch(() => {});
  105. };
  106. // 清空
  107. const clearCache = () => {
  108. ElMessageBox.confirm(`确认清空所有缓存?`, '提示', {
  109. confirmButtonText: '确定',
  110. cancelButtonText: '取消',
  111. type: 'warning',
  112. })
  113. .then(async () => {
  114. await getAPI(SysCacheApi).apiSysCacheClearPost();
  115. await handleQuery();
  116. state.cacheValue = undefined;
  117. state.cacheKey = undefined;
  118. ElMessage.success('清空成功');
  119. })
  120. .catch(() => {});
  121. };
  122. // 树点击
  123. const nodeClick = async (node: any) => {
  124. if (node.id == 0) return;
  125. currentNode.value = node;
  126. state.loading1 = true;
  127. var res = await getAPI(SysCacheApi).apiSysCacheValueKeyGet(node.id);
  128. // state.cacheValue = JSON.parse(res.data.result);
  129. var result = res.data.result;
  130. if (typeof result == 'string') {
  131. try {
  132. var obj = JSON.parse(result);
  133. if (typeof obj == 'object') {
  134. state.cacheValue = obj;
  135. } else {
  136. state.cacheValue = result;
  137. }
  138. } catch (e) {
  139. state.cacheValue = result;
  140. }
  141. } else {
  142. state.cacheValue = result;
  143. }
  144. state.cacheKey = node.id;
  145. state.loading1 = false;
  146. };
  147. </script>