2024-10-16 17:24:50 +08:00
|
|
|
<template>
|
|
|
|
|
<el-form :model="bizForm" ref="formRef" :rules="rules" label-width="auto">
|
2024-11-20 22:43:53 +08:00
|
|
|
<el-form-item prop="id" label="DB" required>
|
2025-10-07 15:41:19 +08:00
|
|
|
<ResourceSelect
|
2024-10-16 17:24:50 +08:00
|
|
|
v-bind="$attrs"
|
|
|
|
|
v-model="selectRedis"
|
|
|
|
|
@change="changeRedis"
|
|
|
|
|
:resource-type="TagResourceTypeEnum.Redis.value"
|
|
|
|
|
:tag-path-node-type="NodeTypeTagPath"
|
2024-11-20 22:43:53 +08:00
|
|
|
:placeholder="$t('flow.selectRedisPlaceholder')"
|
2024-10-16 17:24:50 +08:00
|
|
|
>
|
2025-10-07 15:41:19 +08:00
|
|
|
</ResourceSelect>
|
2024-10-16 17:24:50 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item prop="cmd" label="CMD" required>
|
2024-11-20 22:43:53 +08:00
|
|
|
<el-input type="textarea" v-model="bizForm.cmd" :placeholder="$t('flow.cmdPlaceholder')" :rows="5" />
|
2024-10-16 17:24:50 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import { computed, ref } from 'vue';
|
|
|
|
|
import { TagResourceTypeEnum } from '@/common/commonEnum';
|
2025-10-07 15:41:19 +08:00
|
|
|
import ResourceSelect from '@/views/ops/resource/ResourceSelect.vue';
|
2024-10-16 17:24:50 +08:00
|
|
|
import { NodeType, TagTreeNode } from '@/views/ops/component/tag';
|
|
|
|
|
import { redisApi } from '@/views/ops/redis/api';
|
|
|
|
|
import { sleep } from '@/common/utils/loading';
|
2024-11-20 22:43:53 +08:00
|
|
|
import { useI18n } from 'vue-i18n';
|
2025-03-05 12:47:52 +08:00
|
|
|
import { Rules } from '@/common/rule';
|
2025-10-07 15:41:19 +08:00
|
|
|
import { RedisIcon } from '@/views/ops/redis/resource';
|
2024-11-20 22:43:53 +08:00
|
|
|
|
|
|
|
|
const { t } = useI18n();
|
2024-10-16 17:24:50 +08:00
|
|
|
|
|
|
|
|
const rules = {
|
|
|
|
|
id: [
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
2024-11-20 22:43:53 +08:00
|
|
|
message: t('flow.selectRedisPlaceholder'),
|
2024-10-16 17:24:50 +08:00
|
|
|
trigger: ['change', 'blur'],
|
|
|
|
|
},
|
|
|
|
|
],
|
2025-03-05 12:47:52 +08:00
|
|
|
cmd: [Rules.requiredInput('flow.runCmd')],
|
2024-10-16 17:24:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// tagpath 节点类型
|
|
|
|
|
const NodeTypeTagPath = new NodeType(TagTreeNode.TagPath).withLoadNodesFunc(async (parentNode: TagTreeNode) => {
|
|
|
|
|
const res = await redisApi.redisList.request({ tagPath: parentNode.key });
|
|
|
|
|
if (!res.total) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const redisInfos = res.list;
|
|
|
|
|
await sleep(100);
|
|
|
|
|
return redisInfos.map((x: any) => {
|
|
|
|
|
x.tagPath = parentNode.key;
|
2025-10-07 15:41:19 +08:00
|
|
|
return new TagTreeNode(`${x.code}`, x.name, NodeTypeRedis).withParams(x).withIcon(RedisIcon);
|
2024-10-16 17:24:50 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// redis实例节点类型
|
|
|
|
|
const NodeTypeRedis = new NodeType(1).withLoadNodesFunc(async (parentNode: TagTreeNode) => {
|
|
|
|
|
const redisInfo = parentNode.params;
|
|
|
|
|
|
|
|
|
|
let dbs: TagTreeNode[] = redisInfo.db.split(',').map((x: string) => {
|
2025-10-07 15:41:19 +08:00
|
|
|
return new TagTreeNode(x, `db${x}`, 2 as any)
|
|
|
|
|
.withIsLeaf(true)
|
|
|
|
|
.withParams({
|
|
|
|
|
id: redisInfo.id,
|
|
|
|
|
db: x,
|
|
|
|
|
name: `db${x}`,
|
|
|
|
|
keys: 0,
|
|
|
|
|
tagPath: redisInfo.tagPath,
|
|
|
|
|
redisName: redisInfo.name,
|
|
|
|
|
code: redisInfo.code,
|
|
|
|
|
})
|
|
|
|
|
.withIcon({ name: 'Coin', color: '#67c23a' });
|
2024-10-16 17:24:50 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (redisInfo.mode == 'cluster') {
|
|
|
|
|
return dbs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const res = await redisApi.redisInfo.request({ id: redisInfo.id, host: redisInfo.host, section: 'Keyspace' });
|
|
|
|
|
for (let db in res.Keyspace) {
|
|
|
|
|
for (let d of dbs) {
|
|
|
|
|
if (db == d.params.name) {
|
|
|
|
|
d.params.keys = res.Keyspace[db]?.split(',')[0]?.split('=')[1] || 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 替换label
|
|
|
|
|
dbs.forEach((e: any) => {
|
|
|
|
|
e.label = `${e.params.name}`;
|
|
|
|
|
});
|
|
|
|
|
return dbs;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['changeResourceCode']);
|
|
|
|
|
|
|
|
|
|
const formRef: any = ref(null);
|
|
|
|
|
|
|
|
|
|
const bizForm = defineModel<any>('bizForm', {
|
|
|
|
|
default: {
|
|
|
|
|
id: 0,
|
|
|
|
|
db: 0,
|
|
|
|
|
cmd: '',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const redisName = ref('');
|
|
|
|
|
const tagPath = ref('');
|
|
|
|
|
|
|
|
|
|
const selectRedis = computed({
|
|
|
|
|
get: () => {
|
|
|
|
|
return redisName.value ? `${tagPath.value} > ${redisName.value} > db${bizForm.value.db}` : '';
|
|
|
|
|
},
|
|
|
|
|
set: () => {
|
|
|
|
|
//
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const changeRedis = (nodeData: TagTreeNode) => {
|
|
|
|
|
const params = nodeData.params;
|
|
|
|
|
tagPath.value = params.tagPath;
|
|
|
|
|
redisName.value = params.redisName;
|
|
|
|
|
bizForm.value.id = params.id;
|
|
|
|
|
bizForm.value.db = parseInt(params.db);
|
|
|
|
|
|
|
|
|
|
changeResourceCode(params.code);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const changeResourceCode = async (redisCode: any) => {
|
|
|
|
|
emit('changeResourceCode', TagResourceTypeEnum.Redis.value, redisCode);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const validateBizForm = async () => {
|
|
|
|
|
return formRef.value.validate();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const resetBizForm = () => {
|
|
|
|
|
//重置表单域
|
|
|
|
|
formRef.value.resetFields();
|
|
|
|
|
bizForm.value.id = 0;
|
|
|
|
|
bizForm.value.db = 0;
|
|
|
|
|
bizForm.value.cmd = '';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
defineExpose({ validateBizForm, resetBizForm });
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss"></style>
|