数据源管理、缓存监控
This commit is contained in:
parent
b1c16b04e5
commit
7c0f166bbd
323
src/views/monitor/caches/index.vue
Normal file
323
src/views/monitor/caches/index.vue
Normal file
@ -0,0 +1,323 @@
|
|||||||
|
<template>
|
||||||
|
<PageWrapper>
|
||||||
|
<div class="cache-box">
|
||||||
|
<n-card title="缓存列表">
|
||||||
|
<n-data-table
|
||||||
|
:style="{ minHeight: fwbHeight + 'px' }"
|
||||||
|
:scroll="{ x: '100%', y: fwbHeight + 'px' }"
|
||||||
|
:data="cacheNameData"
|
||||||
|
:columns="cacheNameColumns"
|
||||||
|
:row-props="rowNameProps"
|
||||||
|
:row-key="(row) => row.cacheName"
|
||||||
|
:checked-row-keys="cacheName"
|
||||||
|
@update:checked-row-keys="handleNameChange"
|
||||||
|
>
|
||||||
|
</n-data-table>
|
||||||
|
</n-card>
|
||||||
|
<n-card title="键名列表">
|
||||||
|
<n-data-table
|
||||||
|
:columns="cacheKeyColumns"
|
||||||
|
:row-key="(row) => row.cacheKey"
|
||||||
|
:checked-row-keys="cacheKey"
|
||||||
|
:row-props="rowKeyProps"
|
||||||
|
:style="{ minHeight: fwbHeight + 'px' }"
|
||||||
|
:scroll="{ x: '100%', y: fwbHeight + 'px' }"
|
||||||
|
:data="cacheKeyData"
|
||||||
|
@update:checked-row-keys="handleKeyChange"
|
||||||
|
>
|
||||||
|
>
|
||||||
|
</n-data-table>
|
||||||
|
</n-card>
|
||||||
|
<n-card>
|
||||||
|
<template #header>
|
||||||
|
<div class="clearfix">
|
||||||
|
<span>缓存内容</span>
|
||||||
|
<n-button @click="clearAll" style="float: right; padding: 3px 0" type="text">
|
||||||
|
<template #icon>
|
||||||
|
<RedoOutlined />
|
||||||
|
</template>
|
||||||
|
清理全部
|
||||||
|
</n-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<n-form
|
||||||
|
ref="form"
|
||||||
|
:model="formData"
|
||||||
|
:label-col="{ style: { width: '80px' } }"
|
||||||
|
layout="vertical"
|
||||||
|
v-if="cacheKeyData.length > 0"
|
||||||
|
>
|
||||||
|
<n-form-item label="缓存名称:">
|
||||||
|
<n-input v-model:value="formData.cacheName" />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="缓存键值:">
|
||||||
|
<n-input v-model:value="formData.cacheKey" />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="缓存内容:">
|
||||||
|
<n-input v-model:value="formData.cacheValue" type="textarea" />
|
||||||
|
</n-form-item>
|
||||||
|
</n-form>
|
||||||
|
<div v-else>暂无数据</div>
|
||||||
|
</n-card>
|
||||||
|
</div>
|
||||||
|
</PageWrapper>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref, onMounted, reactive, h } from 'vue';
|
||||||
|
import { RedoOutlined, DeleteOutlined } from '@vicons/antd';
|
||||||
|
import {
|
||||||
|
getCacheNames,
|
||||||
|
getCacheKeys,
|
||||||
|
getCacheValue,
|
||||||
|
deleteCacheName,
|
||||||
|
deleteCacheKey,
|
||||||
|
deleteCacheAll,
|
||||||
|
} from '@/api/monitor/caches';
|
||||||
|
import { TableAction } from '@/components/Table';
|
||||||
|
import { renderIcon } from '@/utils';
|
||||||
|
import { useMessage, useDialog } from 'naive-ui';
|
||||||
|
import { cacheNameColumns } from './cacheNameColumns';
|
||||||
|
import { cacheKeyColumns } from './cacheKeyColumns';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义参数变量
|
||||||
|
*/
|
||||||
|
const message = useMessage();
|
||||||
|
const dialog = useDialog();
|
||||||
|
const cacheNameData = ref([]);
|
||||||
|
const cacheKeyData = ref([]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义表单数据
|
||||||
|
*/
|
||||||
|
const formData = reactive({
|
||||||
|
cacheKey: '',
|
||||||
|
cacheName: '',
|
||||||
|
cacheValue: '',
|
||||||
|
message: '',
|
||||||
|
});
|
||||||
|
const cacheName = ref([]);
|
||||||
|
const cacheKey = ref([]);
|
||||||
|
const fwbHeight = document.body.clientHeight - 320;
|
||||||
|
|
||||||
|
const cacheNameColumns = [
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
width: 50,
|
||||||
|
fixed: 'left',
|
||||||
|
multiple: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '缓存名称',
|
||||||
|
key: 'cacheName',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '备注',
|
||||||
|
key: 'message',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
fixed: 'right',
|
||||||
|
key: 'action',
|
||||||
|
width: 100,
|
||||||
|
render(record) {
|
||||||
|
return h(TableAction as any, {
|
||||||
|
style: 'button',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
label: '删除',
|
||||||
|
icon: renderIcon(DeleteOutlined),
|
||||||
|
type: 'error',
|
||||||
|
onClick: handleDelete.bind(null, record, 'cacheName'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const cacheKeyColumns = [
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
width: 50,
|
||||||
|
fixed: 'left',
|
||||||
|
multiple: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '缓存键名',
|
||||||
|
key: 'cacheKey',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
fixed: 'right',
|
||||||
|
key: 'action',
|
||||||
|
width: 100,
|
||||||
|
render(record) {
|
||||||
|
return h(TableAction as any, {
|
||||||
|
style: 'button',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
label: '删除',
|
||||||
|
icon: renderIcon(DeleteOutlined),
|
||||||
|
type: 'error',
|
||||||
|
onClick: handleDelete.bind(null, record, 'cacheKey'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const rowNameProps = (row) => {
|
||||||
|
console.log(row);
|
||||||
|
return {
|
||||||
|
style: 'cursor: pointer;',
|
||||||
|
onClick: () => {
|
||||||
|
cacheName.value = [row.cacheName];
|
||||||
|
loadCachekeys();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const rowKeyProps = (row) => {
|
||||||
|
return {
|
||||||
|
style: 'cursor: pointer;',
|
||||||
|
onClick: () => {
|
||||||
|
cacheKey.value = [row.cacheKey];
|
||||||
|
loadCacheValue();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行名称发生变化
|
||||||
|
* @param value 参数
|
||||||
|
*/
|
||||||
|
const handleNameChange = (value) => {
|
||||||
|
cacheName.value = value;
|
||||||
|
if (cacheName.value) {
|
||||||
|
loadCachekeys();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行缓存KEY发生变化
|
||||||
|
* @param value 参数
|
||||||
|
*/
|
||||||
|
const handleKeyChange = (value) => {
|
||||||
|
cacheKey.value = value;
|
||||||
|
if (cacheKey.value) {
|
||||||
|
loadCacheValue();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载缓存名列表
|
||||||
|
*/
|
||||||
|
const loadCacheNames = async () => {
|
||||||
|
const result = await getCacheNames();
|
||||||
|
cacheNameData.value = result;
|
||||||
|
cacheName.value = result.length > 0 ? [result[0].cacheName] : '';
|
||||||
|
if (cacheName.value) {
|
||||||
|
loadCachekeys();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载缓存key列表
|
||||||
|
*/
|
||||||
|
const loadCachekeys = async () => {
|
||||||
|
let datas = [];
|
||||||
|
const result = await getCacheKeys(cacheName.value[0]);
|
||||||
|
result.map((item) => {
|
||||||
|
let len = item.split(':').length;
|
||||||
|
datas.push({
|
||||||
|
cacheKey: item.split(':')[len - 1],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
cacheKeyData.value = datas;
|
||||||
|
cacheKey.value = datas.length > 0 ? [datas[0].cacheKey] : '';
|
||||||
|
if (cacheKey.value) {
|
||||||
|
loadCacheValue();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载缓存value列表
|
||||||
|
*/
|
||||||
|
const loadCacheValue = async () => {
|
||||||
|
const data = await getCacheValue({
|
||||||
|
cacheName: cacheName.value[0],
|
||||||
|
cacheKey: cacheKey.value[0],
|
||||||
|
});
|
||||||
|
for (const key in formData) {
|
||||||
|
if (data[key] != null && data[key] != undefined) {
|
||||||
|
formData[key] = data[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行删除
|
||||||
|
* @param row 数据行
|
||||||
|
* @param type 类型
|
||||||
|
*/
|
||||||
|
const handleDelete = async (row, type) => {
|
||||||
|
dialog.warning({
|
||||||
|
title: '提示',
|
||||||
|
content: '确定要删除?',
|
||||||
|
positiveText: '确定',
|
||||||
|
negativeText: '取消',
|
||||||
|
onPositiveClick: async () => {
|
||||||
|
if (type == 'cacheName') {
|
||||||
|
await deleteCacheName(row.cacheName);
|
||||||
|
message.success('删除成功');
|
||||||
|
loadCacheNames();
|
||||||
|
} else {
|
||||||
|
await deleteCacheKey(row.cacheKey);
|
||||||
|
message.success('删除成功');
|
||||||
|
loadCachekeys();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清楚全部缓存
|
||||||
|
*/
|
||||||
|
const clearAll = async () => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '提示',
|
||||||
|
content: '确定要清理全部?',
|
||||||
|
onOk: async () => {
|
||||||
|
await deleteCacheAll();
|
||||||
|
loadCacheNames();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 钩子函数
|
||||||
|
*/
|
||||||
|
onMounted(() => {
|
||||||
|
loadCacheNames();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<style lang="less">
|
||||||
|
.cache-box {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
> .ant-card {
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
&:nth-child(2) {
|
||||||
|
margin: 0 15px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
</style>
|
89
src/views/monitor/dataSource/columns.ts
Normal file
89
src/views/monitor/dataSource/columns.ts
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
import { h } from 'vue';
|
||||||
|
import { NTag } from 'naive-ui';
|
||||||
|
|
||||||
|
export const columns = [
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
width: 50,
|
||||||
|
fixed: 'left',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'ID',
|
||||||
|
key: 'id',
|
||||||
|
fixed: 'left',
|
||||||
|
width: 50,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '数据源名称',
|
||||||
|
key: 'name',
|
||||||
|
width: 150,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '数据库类型',
|
||||||
|
key: 'dbType',
|
||||||
|
width: 100,
|
||||||
|
render(record) {
|
||||||
|
let typeText = '';
|
||||||
|
switch (record.dbType) {
|
||||||
|
case 1:
|
||||||
|
typeText = 'MySQL';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
typeText = 'PostgreSQL';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
typeText = 'SQLServer';
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
typeText = 'Oracle';
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
typeText = 'Sqlite';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return h('span', typeText || '-');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '数据源编码',
|
||||||
|
key: 'code',
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '数据库驱动类',
|
||||||
|
key: 'dbDriver',
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '数据源地址',
|
||||||
|
key: 'dbUrl',
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '数据库名称',
|
||||||
|
key: 'dbName',
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '数据库用户名',
|
||||||
|
key: 'dbUsername',
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '备注',
|
||||||
|
key: 'note',
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建人',
|
||||||
|
key: 'createUser',
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
key: 'createTime',
|
||||||
|
width: 180,
|
||||||
|
},
|
||||||
|
];
|
193
src/views/monitor/dataSource/edit.vue
Normal file
193
src/views/monitor/dataSource/edit.vue
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
<template>
|
||||||
|
<basicModal
|
||||||
|
@register="modalRegister"
|
||||||
|
ref="modalRef"
|
||||||
|
class="basicModal basicFormModal"
|
||||||
|
@on-ok="handleSubmit"
|
||||||
|
@on-close="handleClose"
|
||||||
|
>
|
||||||
|
<template #default>
|
||||||
|
<n-form
|
||||||
|
class="ls-form"
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
label-placement="left"
|
||||||
|
label-width="110px"
|
||||||
|
>
|
||||||
|
<n-form-item
|
||||||
|
label="数据源名称"
|
||||||
|
path="name"
|
||||||
|
:rule="{ required: true, message: '请输入数据源名称', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<n-input v-model:value="formData.name" placeholder="请输入数据源名称" clearable />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item
|
||||||
|
label="数据源编码"
|
||||||
|
path="code"
|
||||||
|
:rule="{ required: true, message: '请输入数据源编码', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<n-input v-model:value="formData.code" placeholder="请输入数据源编码" clearable />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item
|
||||||
|
label="数据库类型"
|
||||||
|
path="dbType"
|
||||||
|
:rule="{ type: 'number', required: true, message: '请选择数据库类型', trigger: 'change' }"
|
||||||
|
>
|
||||||
|
<n-select
|
||||||
|
v-model:value="formData.dbType"
|
||||||
|
placeholder="请选择数据库类型"
|
||||||
|
:options="dbTypeList"
|
||||||
|
/>
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item
|
||||||
|
label="数据库驱动类"
|
||||||
|
path="dbDriver"
|
||||||
|
:rule="{ required: true, message: '请输入数据库驱动类', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<n-input v-model:value="formData.dbDriver" placeholder="请输入数据库驱动类" clearable />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item
|
||||||
|
label="数据源地址"
|
||||||
|
path="dbUrl"
|
||||||
|
:rule="{ required: true, message: '请输入数据源地址', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<n-input v-model:value="formData.dbUrl" placeholder="请输入数据源地址" clearable />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item
|
||||||
|
label="数据库名称"
|
||||||
|
path="dbName"
|
||||||
|
:rule="{ required: true, message: '请输入数据库名称', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<n-input v-model:value="formData.dbName" placeholder="请输入数据库名称" clearable />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item
|
||||||
|
label="数据库用户名"
|
||||||
|
path="dbUsername"
|
||||||
|
:rule="{ required: true, message: '请输入数据库用户名', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<n-input v-model:value="formData.dbUsername" placeholder="请输入数据库用户名" clearable />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item
|
||||||
|
label="数据库密码"
|
||||||
|
path="dbPassword"
|
||||||
|
:rule="{ required: true, message: '请输入数据库密码', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<n-input
|
||||||
|
type="password"
|
||||||
|
v-model:value="formData.dbPassword"
|
||||||
|
show-password-on="mousedown"
|
||||||
|
placeholder="请输入数据库密码"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="备注" path="note">
|
||||||
|
<n-input v-model:value="formData.note" type="textarea" />
|
||||||
|
</n-form-item>
|
||||||
|
</n-form>
|
||||||
|
</template>
|
||||||
|
</basicModal>
|
||||||
|
</template>
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { getDataSourceDetail, dataSourceAdd, dataSourceUpdate } from '@/api/monitor/dataSource';
|
||||||
|
import { onMounted, reactive, ref } from 'vue';
|
||||||
|
import { useMessage } from 'naive-ui';
|
||||||
|
import { useModal } from '@/components/Modal';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success', 'update:visible']);
|
||||||
|
const formRef = ref();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义表单参数
|
||||||
|
*/
|
||||||
|
const message = useMessage();
|
||||||
|
const formData = reactive({
|
||||||
|
id: '',
|
||||||
|
name: '',
|
||||||
|
code: '',
|
||||||
|
dbType: undefined,
|
||||||
|
dbDriver: '',
|
||||||
|
dbUrl: '',
|
||||||
|
dbName: '',
|
||||||
|
dbUsername: '',
|
||||||
|
dbPassword: '',
|
||||||
|
note: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义接收的参数
|
||||||
|
*/
|
||||||
|
const props = defineProps({
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
dataSourceId: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const [modalRegister, { openModal, setSubLoading }] = useModal({
|
||||||
|
title: props.dataSourceId ? '编辑数据源' : '添加数据源',
|
||||||
|
subBtuText: '确定',
|
||||||
|
width: 600,
|
||||||
|
});
|
||||||
|
const dbTypeList = [
|
||||||
|
{ label: 'MySQL', value: 1 },
|
||||||
|
{ label: 'PostgreSQL', value: 2 },
|
||||||
|
{ label: 'SQLServer', value: 3 },
|
||||||
|
{ label: 'Oracle', value: 4 },
|
||||||
|
{ label: 'Sqlite', value: 5 },
|
||||||
|
];
|
||||||
|
/**
|
||||||
|
* 执行提交
|
||||||
|
*/
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
formRef.value
|
||||||
|
.validate()
|
||||||
|
.then(async () => {
|
||||||
|
props.dataSourceId ? await dataSourceUpdate(formData) : await dataSourceAdd(formData);
|
||||||
|
message.success('操作成功');
|
||||||
|
setSubLoading(false);
|
||||||
|
emit('update:visible', false);
|
||||||
|
emit('success');
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
setSubLoading(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭窗体
|
||||||
|
*/
|
||||||
|
const handleClose = () => {
|
||||||
|
emit('update:visible', false);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置表单数据
|
||||||
|
*/
|
||||||
|
const setFormData = async () => {
|
||||||
|
const data = await getDataSourceDetail(props.dataSourceId);
|
||||||
|
for (const key in formData) {
|
||||||
|
if (data[key] != null && data[key] != undefined) {
|
||||||
|
//@ts-ignore
|
||||||
|
formData[key] = data[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 钩子函数
|
||||||
|
*/
|
||||||
|
onMounted(() => {
|
||||||
|
if (props.dataSourceId) {
|
||||||
|
setFormData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//导出方法
|
||||||
|
defineExpose({
|
||||||
|
openModal,
|
||||||
|
});
|
||||||
|
</script>
|
201
src/views/monitor/dataSource/index.vue
Normal file
201
src/views/monitor/dataSource/index.vue
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<n-card :bordered="false" class="pt-3 mb-3 proCard">
|
||||||
|
<BasicForm @register="register" @submit="handleSubmit" @reset="handleReset">
|
||||||
|
<template #statusSlot="{ model, field }">
|
||||||
|
<n-input v-model:value="model[field]" />
|
||||||
|
</template>
|
||||||
|
</BasicForm>
|
||||||
|
</n-card>
|
||||||
|
<n-card :bordered="false" class="proCard">
|
||||||
|
<BasicTable
|
||||||
|
:columns="columns"
|
||||||
|
:request="loadDataTable"
|
||||||
|
:row-key="(row) => row.id"
|
||||||
|
ref="basicTableRef"
|
||||||
|
:actionColumn="actionColumn"
|
||||||
|
@update:checked-row-keys="onCheckedRow"
|
||||||
|
:autoScrollX="true"
|
||||||
|
>
|
||||||
|
<template #tableTitle>
|
||||||
|
<n-space>
|
||||||
|
<n-button type="primary" @click="handleAdd" v-perm="['sys:dataSource:add']">
|
||||||
|
<template #icon>
|
||||||
|
<n-icon>
|
||||||
|
<PlusOutlined />
|
||||||
|
</n-icon>
|
||||||
|
</template>
|
||||||
|
新建
|
||||||
|
</n-button>
|
||||||
|
|
||||||
|
<n-button
|
||||||
|
type="error"
|
||||||
|
@click="handleDelete"
|
||||||
|
:disabled="!rowKeys.length"
|
||||||
|
v-perm="['sys:dataSource:batchDelete']"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<n-icon>
|
||||||
|
<DeleteOutlined />
|
||||||
|
</n-icon>
|
||||||
|
</template>
|
||||||
|
删除
|
||||||
|
</n-button>
|
||||||
|
</n-space>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
</n-card>
|
||||||
|
<editDialog
|
||||||
|
ref="createModalRef"
|
||||||
|
:dataSourceId="dataSourceId"
|
||||||
|
v-if="editVisible"
|
||||||
|
v-model:visible="editVisible"
|
||||||
|
@success="reloadTable('noRefresh')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { h, nextTick, reactive, ref, unref } from 'vue';
|
||||||
|
import { useMessage, useDialog } from 'naive-ui';
|
||||||
|
import { TableAction } from '@/components/Table';
|
||||||
|
import { BasicForm, useForm } from '@/components/Form/index';
|
||||||
|
import {
|
||||||
|
getDataSourceList,
|
||||||
|
dataSourceDelete,
|
||||||
|
dataSourceBatchDelete,
|
||||||
|
} from '@/api/monitor/dataSource';
|
||||||
|
import { columns } from './columns';
|
||||||
|
import { PlusOutlined, DeleteOutlined, FormOutlined } from '@vicons/antd';
|
||||||
|
import CreateModal from './CreateModal.vue';
|
||||||
|
import editDialog from './edit.vue';
|
||||||
|
import { basicModal, useModal } from '@/components/Modal';
|
||||||
|
import { schemas } from './querySchemas';
|
||||||
|
import { renderIcon } from '@/utils';
|
||||||
|
|
||||||
|
const message = useMessage();
|
||||||
|
const dialog = useDialog();
|
||||||
|
const basicTableRef = ref();
|
||||||
|
const createModalRef = ref();
|
||||||
|
const editVisible = ref(false);
|
||||||
|
const dataSourceId = ref(0);
|
||||||
|
const rowKeys = ref([]);
|
||||||
|
const exportLoading = ref(false);
|
||||||
|
|
||||||
|
const showModal = ref(false);
|
||||||
|
const formParams = reactive({
|
||||||
|
name: '',
|
||||||
|
dbType: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const actionColumn = reactive({
|
||||||
|
width: 200,
|
||||||
|
title: '操作',
|
||||||
|
align: 'center',
|
||||||
|
key: 'action',
|
||||||
|
fixed: 'right',
|
||||||
|
render(record) {
|
||||||
|
return h(TableAction as any, {
|
||||||
|
style: 'button',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
label: '编辑',
|
||||||
|
icon: renderIcon(FormOutlined),
|
||||||
|
type: 'info',
|
||||||
|
onClick: handleEdit.bind(null, record),
|
||||||
|
auth: ['sys:dataSource:update'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '删除',
|
||||||
|
icon: renderIcon(DeleteOutlined),
|
||||||
|
type: 'error',
|
||||||
|
onClick: handleDelete.bind(null, record),
|
||||||
|
auth: ['sys:dataSource:delete'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
function addTable() {
|
||||||
|
showModal.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadDataTable = async (res) => {
|
||||||
|
rowKeys.value = [];
|
||||||
|
const result = await getDataSourceList({ ...formParams, ...res });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
function onCheckedRow(keys) {
|
||||||
|
rowKeys.value = keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
function reloadTable(noRefresh = '') {
|
||||||
|
basicTableRef.value.reload(noRefresh ? {} : { pageNo: 1 });
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSubmit(values: Recordable) {
|
||||||
|
for (const key in formParams) {
|
||||||
|
formParams[key] = '';
|
||||||
|
}
|
||||||
|
for (const key in values) {
|
||||||
|
formParams[key] = values[key];
|
||||||
|
}
|
||||||
|
reloadTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleReset(values: Recordable) {
|
||||||
|
for (const key in formParams) {
|
||||||
|
formParams[key] = '';
|
||||||
|
}
|
||||||
|
for (const key in values) {
|
||||||
|
formParams[key] = values[key];
|
||||||
|
}
|
||||||
|
reloadTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
const [register, {}] = useForm({
|
||||||
|
gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
|
||||||
|
labelWidth: 110,
|
||||||
|
schemas,
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行添加
|
||||||
|
*/
|
||||||
|
const handleAdd = async () => {
|
||||||
|
dataSourceId.value = 0;
|
||||||
|
editVisible.value = true;
|
||||||
|
await nextTick();
|
||||||
|
createModalRef.value.openModal();
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 执行编辑
|
||||||
|
*/
|
||||||
|
async function handleEdit(record: Recordable) {
|
||||||
|
dataSourceId.value = record.id;
|
||||||
|
editVisible.value = true;
|
||||||
|
await nextTick();
|
||||||
|
createModalRef.value.openModal();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 执行删除
|
||||||
|
* @param id 参数
|
||||||
|
*/
|
||||||
|
async function handleDelete(record) {
|
||||||
|
dialog.warning({
|
||||||
|
title: '提示',
|
||||||
|
content: '确定要删除?',
|
||||||
|
positiveText: '确定',
|
||||||
|
negativeText: '取消',
|
||||||
|
onPositiveClick: async () => {
|
||||||
|
record.id ? await dataSourceDelete(record.id) : await dataSourceBatchDelete(rowKeys.value);
|
||||||
|
message.success('删除成功');
|
||||||
|
reloadTable();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped></style>
|
42
src/views/monitor/dataSource/querySchemas.ts
Normal file
42
src/views/monitor/dataSource/querySchemas.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import { FormSchema } from '@/components/Form/index';
|
||||||
|
export const schemas: FormSchema[] = [
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
component: 'NInput',
|
||||||
|
label: '数据源名称',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入数据源名称',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'dbType',
|
||||||
|
component: 'NSelect',
|
||||||
|
label: '数据库类型',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择数据库类型',
|
||||||
|
clearable: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'MySQL',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'PostgreSQL',
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'SQLServer',
|
||||||
|
value: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Oracle',
|
||||||
|
value: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Sqlite',
|
||||||
|
value: 5,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
Loading…
Reference in New Issue
Block a user