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