2021-07-28 18:03:19 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div>
|
2021-12-21 03:06:29 +00:00
|
|
|
|
<el-card>
|
2021-07-28 18:03:19 +08:00
|
|
|
|
<div style="float: left">
|
|
|
|
|
|
<el-row type="flex" justify="space-between">
|
|
|
|
|
|
<el-col :span="24">
|
2022-10-18 17:21:42 +08:00
|
|
|
|
<project-env-select @changeProjectEnv="changeProjectEnv" @clear="clearRedis" :data="{ projectId, envId:query.envId }" >
|
2021-07-28 18:03:19 +08:00
|
|
|
|
<template #default>
|
|
|
|
|
|
<el-form-item label="redis" label-width="40px">
|
|
|
|
|
|
<el-select v-model="scanParam.id" placeholder="请选择redis" @change="changeRedis" @clear="clearRedis" clearable>
|
2022-10-18 17:21:42 +08:00
|
|
|
|
<el-option v-for="item in redisList" :key="item.id" :value="item.id" :label=" item.remark ">
|
|
|
|
|
|
<span style="float: left">{{ item.remark }}</span>
|
|
|
|
|
|
<span style="float: right; color: #8492a6; margin-left: 6px; font-size: 13px">{{
|
|
|
|
|
|
`${item.host}`
|
|
|
|
|
|
}}</span>
|
|
|
|
|
|
</el-option>
|
2022-09-29 13:14:50 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="库" label-width="20px">
|
2022-10-11 08:25:20 +08:00
|
|
|
|
<el-select v-model="scanParam.db" @change="changeDb" placeholder="库" style="width: 85px">
|
2022-09-29 13:14:50 +08:00
|
|
|
|
<el-option v-for="db in dbList" :key="db" :label="db" :value="db"> </el-option>
|
2021-07-28 18:03:19 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</project-env-select>
|
|
|
|
|
|
</el-col>
|
2022-01-12 16:00:31 +08:00
|
|
|
|
<el-col class="mt10">
|
|
|
|
|
|
<el-form class="search-form" label-position="right" :inline="true" label-width="60px">
|
|
|
|
|
|
<el-form-item label="key" label-width="40px">
|
|
|
|
|
|
<el-input
|
2022-08-05 21:41:21 +08:00
|
|
|
|
placeholder="match 支持*模糊key"
|
2022-02-14 14:58:25 +08:00
|
|
|
|
style="width: 240px"
|
2022-01-12 16:00:31 +08:00
|
|
|
|
v-model="scanParam.match"
|
|
|
|
|
|
@clear="clear()"
|
|
|
|
|
|
clearable
|
|
|
|
|
|
></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="count" label-width="60px">
|
2022-07-10 12:14:06 +08:00
|
|
|
|
<el-input placeholder="count" style="width: 62px" v-model.number="scanParam.count"></el-input>
|
2022-01-12 16:00:31 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item>
|
|
|
|
|
|
<el-button @click="searchKey()" type="success" icon="search" plain></el-button>
|
|
|
|
|
|
<el-button @click="scan()" icon="bottom" plain>scan</el-button>
|
2022-08-05 21:41:21 +08:00
|
|
|
|
<el-popover placement="right" :width="200" trigger="click">
|
|
|
|
|
|
<template #reference>
|
|
|
|
|
|
<el-button type="primary" icon="plus" plain></el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<el-tag @click="onAddData('string')" :color="getTypeColor('string')" style="cursor: pointer">string</el-tag>
|
|
|
|
|
|
<el-tag @click="onAddData('hash')" :color="getTypeColor('hash')" class="ml5" style="cursor: pointer">hash</el-tag>
|
|
|
|
|
|
<el-tag @click="onAddData('set')" :color="getTypeColor('set')" class="ml5" style="cursor: pointer">set</el-tag>
|
2022-09-22 11:56:21 +08:00
|
|
|
|
<!-- <el-tag @click="onAddData('list')" :color="getTypeColor('list')" class="ml5" style="cursor: pointer">list</el-tag> -->
|
2022-08-05 21:41:21 +08:00
|
|
|
|
</el-popover>
|
2022-01-12 16:00:31 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<div style="float: right">
|
|
|
|
|
|
<span>keys: {{ dbsize }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
</el-col>
|
2021-07-28 18:03:19 +08:00
|
|
|
|
</el-row>
|
|
|
|
|
|
</div>
|
2022-01-12 16:00:31 +08:00
|
|
|
|
|
2021-12-21 03:06:29 +00:00
|
|
|
|
<el-table v-loading="loading" :data="keys" stripe :highlight-current-row="true" style="cursor: pointer">
|
|
|
|
|
|
<el-table-column show-overflow-tooltip prop="key" label="key"></el-table-column>
|
2022-03-24 17:50:44 +08:00
|
|
|
|
<el-table-column prop="type" label="type" width="80">
|
|
|
|
|
|
<template #default="scope">
|
|
|
|
|
|
<el-tag :color="getTypeColor(scope.row.type)" size="small">{{ scope.row.type }}</el-tag>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
2022-09-29 13:14:50 +08:00
|
|
|
|
<el-table-column prop="ttl" label="ttl(过期时间)" width="140">
|
2021-12-21 03:06:29 +00:00
|
|
|
|
<template #default="scope">
|
|
|
|
|
|
{{ ttlConveter(scope.row.ttl) }}
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column label="操作">
|
|
|
|
|
|
<template #default="scope">
|
2022-01-12 16:00:31 +08:00
|
|
|
|
<el-button @click="getValue(scope.row)" type="success" icon="search" plain size="small">查看</el-button>
|
|
|
|
|
|
<el-button @click="del(scope.row.key)" type="danger" icon="delete" plain size="small">删除</el-button>
|
2021-12-21 03:06:29 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
</el-table>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
<div style="text-align: center; margin-top: 10px"></div>
|
|
|
|
|
|
|
2022-08-05 21:41:21 +08:00
|
|
|
|
<hash-value
|
|
|
|
|
|
v-model:visible="hashValueDialog.visible"
|
|
|
|
|
|
:operationType="dataEdit.operationType"
|
|
|
|
|
|
:title="dataEdit.title"
|
|
|
|
|
|
:keyInfo="dataEdit.keyInfo"
|
|
|
|
|
|
:redisId="scanParam.id"
|
2022-09-29 13:14:50 +08:00
|
|
|
|
:db="scanParam.db"
|
2022-08-05 21:41:21 +08:00
|
|
|
|
@cancel="onCancelDataEdit"
|
|
|
|
|
|
@valChange="searchKey"
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<string-value
|
|
|
|
|
|
v-model:visible="stringValueDialog.visible"
|
|
|
|
|
|
:operationType="dataEdit.operationType"
|
|
|
|
|
|
:title="dataEdit.title"
|
|
|
|
|
|
:keyInfo="dataEdit.keyInfo"
|
|
|
|
|
|
:redisId="scanParam.id"
|
2022-09-29 13:14:50 +08:00
|
|
|
|
:db="scanParam.db"
|
2022-08-05 21:41:21 +08:00
|
|
|
|
@cancel="onCancelDataEdit"
|
|
|
|
|
|
@valChange="searchKey"
|
|
|
|
|
|
/>
|
2022-01-12 16:00:31 +08:00
|
|
|
|
|
2022-08-05 21:41:21 +08:00
|
|
|
|
<set-value
|
|
|
|
|
|
v-model:visible="setValueDialog.visible"
|
2022-01-12 16:00:31 +08:00
|
|
|
|
:title="dataEdit.title"
|
|
|
|
|
|
:keyInfo="dataEdit.keyInfo"
|
|
|
|
|
|
:redisId="scanParam.id"
|
2022-09-29 13:14:50 +08:00
|
|
|
|
:db="scanParam.db"
|
2022-01-12 16:00:31 +08:00
|
|
|
|
:operationType="dataEdit.operationType"
|
|
|
|
|
|
@valChange="searchKey"
|
|
|
|
|
|
@cancel="onCancelDataEdit"
|
|
|
|
|
|
/>
|
2022-09-22 11:56:21 +08:00
|
|
|
|
|
|
|
|
|
|
<list-value
|
|
|
|
|
|
v-model:visible="listValueDialog.visible"
|
|
|
|
|
|
:title="dataEdit.title"
|
|
|
|
|
|
:keyInfo="dataEdit.keyInfo"
|
|
|
|
|
|
:redisId="scanParam.id"
|
2022-09-29 13:14:50 +08:00
|
|
|
|
:db="scanParam.db"
|
2022-09-22 11:56:21 +08:00
|
|
|
|
:operationType="dataEdit.operationType"
|
|
|
|
|
|
@valChange="searchKey"
|
|
|
|
|
|
@cancel="onCancelDataEdit"
|
|
|
|
|
|
/>
|
2021-07-28 18:03:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
|
import { redisApi } from './api';
|
2022-10-18 17:21:42 +08:00
|
|
|
|
import {toRefs, reactive, defineComponent, watch} from 'vue';
|
2021-07-28 18:03:19 +08:00
|
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
|
|
|
|
|
import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
|
2022-08-05 21:41:21 +08:00
|
|
|
|
import HashValue from './HashValue.vue';
|
|
|
|
|
|
import StringValue from './StringValue.vue';
|
|
|
|
|
|
import SetValue from './SetValue.vue';
|
2022-09-22 11:56:21 +08:00
|
|
|
|
import ListValue from './ListValue.vue';
|
2022-07-10 12:14:06 +08:00
|
|
|
|
import { isTrue, notBlank, notNull } from '@/common/assert';
|
2022-10-18 17:21:42 +08:00
|
|
|
|
import { useStore } from '@/store/index.ts';
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
|
name: 'DataOperation',
|
|
|
|
|
|
components: {
|
2022-08-05 21:41:21 +08:00
|
|
|
|
StringValue,
|
|
|
|
|
|
HashValue,
|
|
|
|
|
|
SetValue,
|
2022-09-22 11:56:21 +08:00
|
|
|
|
ListValue,
|
2021-07-28 18:03:19 +08:00
|
|
|
|
ProjectEnvSelect,
|
|
|
|
|
|
},
|
|
|
|
|
|
setup() {
|
2022-10-18 17:21:42 +08:00
|
|
|
|
let store = useStore();
|
2021-07-28 18:03:19 +08:00
|
|
|
|
const state = reactive({
|
2022-10-18 17:21:42 +08:00
|
|
|
|
projectId: null,
|
2021-07-28 18:03:19 +08:00
|
|
|
|
loading: false,
|
|
|
|
|
|
redisList: [],
|
2022-09-29 13:14:50 +08:00
|
|
|
|
dbList: [],
|
2021-07-28 18:03:19 +08:00
|
|
|
|
query: {
|
|
|
|
|
|
envId: 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
scanParam: {
|
|
|
|
|
|
id: null,
|
2022-10-18 17:21:42 +08:00
|
|
|
|
db: '',
|
2021-07-28 18:03:19 +08:00
|
|
|
|
match: null,
|
|
|
|
|
|
count: 10,
|
2022-07-10 12:14:06 +08:00
|
|
|
|
cursor: {},
|
2021-07-28 18:03:19 +08:00
|
|
|
|
},
|
2022-01-12 16:00:31 +08:00
|
|
|
|
dataEdit: {
|
|
|
|
|
|
visible: false,
|
|
|
|
|
|
title: '新增数据',
|
|
|
|
|
|
operationType: 1,
|
|
|
|
|
|
keyInfo: {
|
|
|
|
|
|
type: 'string',
|
|
|
|
|
|
timed: -1,
|
|
|
|
|
|
key: '',
|
|
|
|
|
|
},
|
2022-08-05 21:41:21 +08:00
|
|
|
|
},
|
|
|
|
|
|
hashValueDialog: {
|
|
|
|
|
|
visible: false,
|
|
|
|
|
|
},
|
|
|
|
|
|
stringValueDialog: {
|
|
|
|
|
|
visible: false,
|
|
|
|
|
|
},
|
|
|
|
|
|
setValueDialog: {
|
|
|
|
|
|
visible: false,
|
2022-01-12 16:00:31 +08:00
|
|
|
|
},
|
2022-09-22 11:56:21 +08:00
|
|
|
|
listValueDialog: {
|
|
|
|
|
|
visible: false,
|
|
|
|
|
|
},
|
2021-07-28 18:03:19 +08:00
|
|
|
|
keys: [],
|
|
|
|
|
|
dbsize: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const searchRedis = async () => {
|
|
|
|
|
|
notNull(state.query.envId, '请先选择项目环境');
|
|
|
|
|
|
const res = await redisApi.redisList.request(state.query);
|
|
|
|
|
|
state.redisList = res.list;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const changeProjectEnv = (projectId: any, envId: any) => {
|
|
|
|
|
|
clearRedis();
|
|
|
|
|
|
if (envId != null) {
|
|
|
|
|
|
state.query.envId = envId;
|
|
|
|
|
|
searchRedis();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-07-10 12:14:06 +08:00
|
|
|
|
const changeRedis = (id: number) => {
|
|
|
|
|
|
resetScanParam(id);
|
2022-10-18 17:21:42 +08:00
|
|
|
|
state.scanParam.db = '';
|
2022-09-29 13:14:50 +08:00
|
|
|
|
state.dbList = (state.redisList.find((x: any) => x.id == id) as any).db.split(',');
|
|
|
|
|
|
state.keys = [];
|
|
|
|
|
|
state.dbsize = 0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const changeDb = () => {
|
|
|
|
|
|
resetScanParam(state.scanParam.id as any);
|
2021-07-28 18:03:19 +08:00
|
|
|
|
state.keys = [];
|
|
|
|
|
|
state.dbsize = 0;
|
|
|
|
|
|
searchKey();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-07-10 12:14:06 +08:00
|
|
|
|
const scan = async () => {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
isTrue(state.scanParam.id != null, '请先选择redis');
|
2022-07-10 12:14:06 +08:00
|
|
|
|
notBlank(state.scanParam.count, 'count不能为空');
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
2022-08-05 21:41:21 +08:00
|
|
|
|
const match = state.scanParam.match;
|
2022-09-26 18:08:12 +08:00
|
|
|
|
if (!match || (match as string).length < 4) {
|
|
|
|
|
|
isTrue(state.scanParam.count <= 200, 'key为空或小于4字符时, count不能超过200');
|
2022-08-05 21:41:21 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
isTrue(state.scanParam.count <= 20000, 'count不能超过20000');
|
|
|
|
|
|
}
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
2022-08-05 21:41:21 +08:00
|
|
|
|
state.loading = true;
|
2022-07-10 12:14:06 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const res = await redisApi.scan.request(state.scanParam);
|
2021-07-28 18:03:19 +08:00
|
|
|
|
state.keys = res.keys;
|
|
|
|
|
|
state.dbsize = res.dbSize;
|
|
|
|
|
|
state.scanParam.cursor = res.cursor;
|
2022-07-10 12:14:06 +08:00
|
|
|
|
} finally {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
state.loading = false;
|
2022-07-10 12:14:06 +08:00
|
|
|
|
}
|
2021-07-28 18:03:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2022-07-10 12:14:06 +08:00
|
|
|
|
const searchKey = async () => {
|
|
|
|
|
|
state.scanParam.cursor = {};
|
|
|
|
|
|
await scan();
|
2021-07-28 18:03:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const clearRedis = () => {
|
|
|
|
|
|
state.redisList = [];
|
|
|
|
|
|
state.scanParam.id = null;
|
|
|
|
|
|
resetScanParam();
|
2022-10-18 17:21:42 +08:00
|
|
|
|
state.scanParam.db = '';
|
2021-07-28 18:03:19 +08:00
|
|
|
|
state.keys = [];
|
|
|
|
|
|
state.dbsize = 0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const clear = () => {
|
|
|
|
|
|
resetScanParam();
|
|
|
|
|
|
if (state.scanParam.id) {
|
|
|
|
|
|
scan();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-07-10 12:14:06 +08:00
|
|
|
|
const resetScanParam = (id: number = 0) => {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
state.scanParam.count = 10;
|
2022-07-10 12:14:06 +08:00
|
|
|
|
if (id != 0) {
|
|
|
|
|
|
const redis: any = state.redisList.find((x: any) => x.id == id);
|
|
|
|
|
|
// 集群模式count设小点,因为后端会从所有master节点scan一遍然后合并结果
|
|
|
|
|
|
if (redis && redis.mode == 'cluster') {
|
2022-09-29 13:14:50 +08:00
|
|
|
|
state.scanParam.count = 4;
|
2022-07-10 12:14:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
state.scanParam.match = null;
|
|
|
|
|
|
state.scanParam.cursor = {};
|
2021-07-28 18:03:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const getValue = async (row: any) => {
|
2022-01-12 16:00:31 +08:00
|
|
|
|
const type = row.type;
|
|
|
|
|
|
|
2022-08-05 21:41:21 +08:00
|
|
|
|
state.dataEdit.keyInfo.type = type;
|
|
|
|
|
|
state.dataEdit.keyInfo.timed = row.ttl;
|
|
|
|
|
|
state.dataEdit.keyInfo.key = row.key;
|
|
|
|
|
|
state.dataEdit.operationType = 2;
|
|
|
|
|
|
state.dataEdit.title = '查看数据';
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
2022-01-12 16:00:31 +08:00
|
|
|
|
if (type == 'hash') {
|
2022-08-05 21:41:21 +08:00
|
|
|
|
state.hashValueDialog.visible = true;
|
|
|
|
|
|
} else if (type == 'string') {
|
|
|
|
|
|
state.stringValueDialog.visible = true;
|
|
|
|
|
|
} else if (type == 'set') {
|
|
|
|
|
|
state.setValueDialog.visible = true;
|
2022-09-22 11:56:21 +08:00
|
|
|
|
} else if (type == 'list') {
|
|
|
|
|
|
state.listValueDialog.visible = true;
|
2022-08-05 21:41:21 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
ElMessage.warning('暂不支持该类型');
|
2022-01-12 16:00:31 +08:00
|
|
|
|
}
|
2022-08-05 21:41:21 +08:00
|
|
|
|
};
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
2022-08-05 21:41:21 +08:00
|
|
|
|
const onAddData = (type: string) => {
|
|
|
|
|
|
notNull(state.scanParam.id, '请先选择redis');
|
|
|
|
|
|
state.dataEdit.operationType = 1;
|
|
|
|
|
|
state.dataEdit.title = '新增数据';
|
2022-01-12 16:00:31 +08:00
|
|
|
|
state.dataEdit.keyInfo.type = type;
|
2022-08-05 21:41:21 +08:00
|
|
|
|
state.dataEdit.keyInfo.timed = -1;
|
|
|
|
|
|
if (type == 'hash') {
|
|
|
|
|
|
state.hashValueDialog.visible = true;
|
|
|
|
|
|
} else if (type == 'string') {
|
|
|
|
|
|
state.stringValueDialog.visible = true;
|
|
|
|
|
|
} else if (type == 'set') {
|
|
|
|
|
|
state.setValueDialog.visible = true;
|
2022-09-22 11:56:21 +08:00
|
|
|
|
} else if (type == 'list') {
|
|
|
|
|
|
state.listValueDialog.visible = true;
|
2022-08-05 21:41:21 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
ElMessage.warning('暂不支持该类型');
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const onCancelDataEdit = () => {
|
|
|
|
|
|
state.dataEdit.keyInfo = {} as any;
|
2022-01-12 16:00:31 +08:00
|
|
|
|
};
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
|
|
|
|
|
const del = (key: string) => {
|
2022-07-10 12:14:06 +08:00
|
|
|
|
ElMessageBox.confirm(`确定删除[ ${key} ] 该key?`, '提示', {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
|
type: 'warning',
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(() => {
|
|
|
|
|
|
redisApi.delKey
|
|
|
|
|
|
.request({
|
|
|
|
|
|
key,
|
2022-07-10 12:14:06 +08:00
|
|
|
|
id: state.scanParam.id,
|
2022-09-29 13:14:50 +08:00
|
|
|
|
db: state.scanParam.db,
|
2021-07-28 18:03:19 +08:00
|
|
|
|
})
|
2021-09-08 17:55:57 +08:00
|
|
|
|
.then(() => {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
ElMessage.success('删除成功!');
|
2022-07-10 12:14:06 +08:00
|
|
|
|
searchKey();
|
2021-07-28 18:03:19 +08:00
|
|
|
|
});
|
|
|
|
|
|
})
|
2021-09-08 17:55:57 +08:00
|
|
|
|
.catch(() => {});
|
2021-07-28 18:03:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const ttlConveter = (ttl: any) => {
|
2022-07-10 12:14:06 +08:00
|
|
|
|
if (ttl == -1 || ttl == 0) {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
return '永久';
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!ttl) {
|
|
|
|
|
|
ttl = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
let second = parseInt(ttl); // 秒
|
|
|
|
|
|
let min = 0; // 分
|
|
|
|
|
|
let hour = 0; // 小时
|
|
|
|
|
|
let day = 0;
|
|
|
|
|
|
if (second > 60) {
|
|
|
|
|
|
min = parseInt(second / 60 + '');
|
|
|
|
|
|
second = second % 60;
|
|
|
|
|
|
if (min > 60) {
|
|
|
|
|
|
hour = parseInt(min / 60 + '');
|
|
|
|
|
|
min = min % 60;
|
|
|
|
|
|
if (hour > 24) {
|
|
|
|
|
|
day = parseInt(hour / 24 + '');
|
|
|
|
|
|
hour = hour % 24;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let result = '' + second + 's';
|
|
|
|
|
|
if (min > 0) {
|
|
|
|
|
|
result = '' + min + 'm:' + result;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (hour > 0) {
|
|
|
|
|
|
result = '' + hour + 'h:' + result;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (day > 0) {
|
|
|
|
|
|
result = '' + day + 'd:' + result;
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-03-24 17:50:44 +08:00
|
|
|
|
const getTypeColor = (type: string) => {
|
|
|
|
|
|
if (type == 'string') {
|
|
|
|
|
|
return '#E4F5EB';
|
|
|
|
|
|
}
|
|
|
|
|
|
if (type == 'hash') {
|
|
|
|
|
|
return '#F9E2AE';
|
|
|
|
|
|
}
|
|
|
|
|
|
if (type == 'set') {
|
|
|
|
|
|
return '#A8DEE0';
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-10-18 17:21:42 +08:00
|
|
|
|
// 加载选中的db
|
|
|
|
|
|
const setSelects = async (redisDbOptInfo: any) =>{
|
|
|
|
|
|
// 设置项目id和环境id
|
|
|
|
|
|
const { projectId, envId, dbId} = redisDbOptInfo.dbOptInfo;
|
|
|
|
|
|
state.projectId = projectId;
|
|
|
|
|
|
state.query.envId = envId
|
|
|
|
|
|
await searchRedis()
|
|
|
|
|
|
state.scanParam.id = dbId
|
|
|
|
|
|
changeRedis(dbId)
|
|
|
|
|
|
if(!state.scanParam.db){
|
|
|
|
|
|
state.scanParam.db = '0'
|
|
|
|
|
|
}
|
|
|
|
|
|
changeDb()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断如果有数据则加载下拉选项
|
|
|
|
|
|
let redisDbOptInfo = store.state.redisDbOptInfo
|
|
|
|
|
|
if(redisDbOptInfo.dbOptInfo.envId){
|
|
|
|
|
|
setSelects(redisDbOptInfo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 监听选中操作的db变化,并加载下拉选项
|
|
|
|
|
|
watch(store.state.redisDbOptInfo,async (newValue) => {
|
|
|
|
|
|
await setSelects(newValue)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
...toRefs(state),
|
|
|
|
|
|
changeProjectEnv,
|
|
|
|
|
|
changeRedis,
|
2022-09-29 13:14:50 +08:00
|
|
|
|
changeDb,
|
2021-07-28 18:03:19 +08:00
|
|
|
|
clearRedis,
|
|
|
|
|
|
searchKey,
|
|
|
|
|
|
scan,
|
|
|
|
|
|
clear,
|
|
|
|
|
|
getValue,
|
|
|
|
|
|
del,
|
|
|
|
|
|
ttlConveter,
|
2022-03-24 17:50:44 +08:00
|
|
|
|
getTypeColor,
|
2022-01-12 16:00:31 +08:00
|
|
|
|
onAddData,
|
|
|
|
|
|
onCancelDataEdit,
|
2021-07-28 18:03:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
</style>
|