数据源管理
This commit is contained in:
parent
c353b10dc4
commit
4912593167
56
src/views/content/ad/querySchemas.ts
Normal file
56
src/views/content/ad/querySchemas.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import { FormSchema } from '@/components/Form/index';
|
||||||
|
import { getAdSortAllList } from '@/api/content/adSort';
|
||||||
|
export const loadSelectData = async(res)=> {
|
||||||
|
//这里可以进行数据转换处理
|
||||||
|
return (await getAdSortAllList({ ...res })).map((item, index) => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
label:item.name,
|
||||||
|
value:item.id,
|
||||||
|
index,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export const schemas: FormSchema[] = [
|
||||||
|
{
|
||||||
|
field: 'title',
|
||||||
|
component: 'Input',
|
||||||
|
label: '广告标题',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输广告标题',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'status',
|
||||||
|
component: 'Select',
|
||||||
|
label: '广告状态',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择广告状态',
|
||||||
|
clearable: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '在用',
|
||||||
|
value: '1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '停用',
|
||||||
|
value: '2',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'adSortId',
|
||||||
|
component: 'BasicSelect',
|
||||||
|
label: '广告位',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择广告位',
|
||||||
|
clearable: true,
|
||||||
|
block:true,
|
||||||
|
request: loadSelectData,
|
||||||
|
onChange: (e: any) => {
|
||||||
|
console.log(e);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
51
src/views/monitor/dataSource/columns.ts
Normal file
51
src/views/monitor/dataSource/columns.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { h } from 'vue';
|
||||||
|
import { ElTag } from 'element-plus';
|
||||||
|
|
||||||
|
export const columns = [
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数据源名称',
|
||||||
|
prop: 'name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数据库类型',
|
||||||
|
prop: 'dbType',
|
||||||
|
render(record) {
|
||||||
|
let typeText = ''
|
||||||
|
switch (record.row.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 || '-');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数据源编码',
|
||||||
|
prop: 'code',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数据库名称',
|
||||||
|
prop: 'dbName',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数据源地址',
|
||||||
|
prop: 'dbUrl',
|
||||||
|
},
|
||||||
|
];
|
194
src/views/monitor/dataSource/edit.vue
Normal file
194
src/views/monitor/dataSource/edit.vue
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
v-model="props.visible"
|
||||||
|
:title="props.dataSourceId?'编辑':'新增'"
|
||||||
|
width="600"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:before-close="dialogClose"
|
||||||
|
>
|
||||||
|
<el-form
|
||||||
|
class="ls-form"
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
label-width="110px"
|
||||||
|
>
|
||||||
|
<el-form-item
|
||||||
|
label="数据源名称"
|
||||||
|
prop="name"
|
||||||
|
:rules="{ required: true, message: '请输入数据源名称', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
class="ls-input"
|
||||||
|
v-model="formData.name"
|
||||||
|
placeholder="请输入数据源名称"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
label="数据源编码"
|
||||||
|
prop="code"
|
||||||
|
:rules="{ required: true, message: '请输入数据源编码', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
class="ls-input"
|
||||||
|
v-model="formData.code"
|
||||||
|
placeholder="请输入数据源编码"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
label="数据库类型"
|
||||||
|
prop="dbType"
|
||||||
|
:rules="{ required: true, message: '请选择数据库类型', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<el-select v-model="formData.dbType" placeholder="请选择数据库类型">
|
||||||
|
<el-option label="MySQL" :value="1"></el-option>
|
||||||
|
<el-option label="PostgreSQL" :value="2"></el-option>
|
||||||
|
<el-option label="SQLServer" :value="3"></el-option>
|
||||||
|
<el-option label="Oracle" :value="4"></el-option>
|
||||||
|
<el-option label="Sqlite" :value="5"></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
label="数据库驱动类"
|
||||||
|
prop="dbDriver"
|
||||||
|
:rules="{ required: true, message: '请选择数据库驱动类', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
class="ls-input"
|
||||||
|
v-model="formData.dbDriver"
|
||||||
|
placeholder="请选择数据库驱动类"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
label="数据源地址"
|
||||||
|
prop="dbUrl"
|
||||||
|
:rules="{ required: true, message: '请输入数据源地址', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
class="ls-input"
|
||||||
|
v-model="formData.dbUrl"
|
||||||
|
placeholder="请输入数据源地址"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
label="数据库名称"
|
||||||
|
prop="dbName"
|
||||||
|
:rules="{ required: true, message: '请输入数据库名称', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
class="ls-input"
|
||||||
|
v-model="formData.dbName"
|
||||||
|
placeholder="请输入数据库名称"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
label="数据库用户名"
|
||||||
|
prop="dbUsername"
|
||||||
|
:rules="{ required: true, message: '请输入数据库用户名', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
class="ls-input"
|
||||||
|
v-model="formData.dbUsername"
|
||||||
|
placeholder="请输入数据库用户名"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
label="数据库密码"
|
||||||
|
prop="dbPassword"
|
||||||
|
:rules="{ required: true, message: '请输入数据库密码', trigger: 'blur' }"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
class="ls-input"
|
||||||
|
v-model="formData.dbPassword"
|
||||||
|
type="password"
|
||||||
|
show-password
|
||||||
|
placeholder="请输入数据库密码"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注" prop="note">
|
||||||
|
<el-input v-model="formData.note" type="textarea"/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<span class="dialog-footer">
|
||||||
|
<el-button @click="dialogClose">取消</el-button>
|
||||||
|
<el-button :loading="subLoading" type="primary" @click="submit">
|
||||||
|
确定
|
||||||
|
</el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type {FormInstance} from "element-plus";
|
||||||
|
import {getDataSourceDetail,dataSourceAdd,dataSourceUpdate} from "@/api/monitor/dataSource";
|
||||||
|
import {onMounted, reactive, shallowRef} from "vue";
|
||||||
|
import {message} from "@/utils/auth";
|
||||||
|
import {useLockFn} from "@/utils/useLockFn";
|
||||||
|
|
||||||
|
const emit = defineEmits(["success", "update:visible"]);
|
||||||
|
const formRef = shallowRef<FormInstance>();
|
||||||
|
const formData = reactive({
|
||||||
|
id: "",
|
||||||
|
name: "",
|
||||||
|
code: "",
|
||||||
|
dbType: "",
|
||||||
|
dbDriver: "",
|
||||||
|
dbUrl: "",
|
||||||
|
dbName: "",
|
||||||
|
dbUsername: "",
|
||||||
|
dbPassword: "",
|
||||||
|
note: ""
|
||||||
|
});
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
dataSourceId: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
default: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
await formRef.value?.validate();
|
||||||
|
props.dataSourceId ? await dataSourceUpdate(formData) : await dataSourceAdd(formData);
|
||||||
|
message("操作成功");
|
||||||
|
emit("update:visible", false);
|
||||||
|
emit("success");
|
||||||
|
};
|
||||||
|
|
||||||
|
const dialogClose = () => {
|
||||||
|
emit("update:visible", false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const { isLock:subLoading,lockFn: submit } = useLockFn(handleSubmit);
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
148
src/views/monitor/dataSource/index.vue
Normal file
148
src/views/monitor/dataSource/index.vue
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
<template>
|
||||||
|
<PageWrapper>
|
||||||
|
<el-card :bordered="false" class="pt-3 mb-3 proCard">
|
||||||
|
<BasicForm @register="register" @submit="handleSubmit" @reset="handleReset"></BasicForm>
|
||||||
|
</el-card>
|
||||||
|
<el-card :bordered="false" class="proCard">
|
||||||
|
<BasicTable
|
||||||
|
:columns="columns"
|
||||||
|
:request="loadDataTable"
|
||||||
|
:row-key="(row) => row.id"
|
||||||
|
ref="tableRef"
|
||||||
|
:actionColumn="actionColumn"
|
||||||
|
@selection-change="onSelectionChange"
|
||||||
|
>
|
||||||
|
<template #tableTitle>
|
||||||
|
<el-button type="primary" @click="handleAdd" v-perm="['sys:dataSource:add']">
|
||||||
|
<template #icon>
|
||||||
|
<el-icon class="el-input__icon">
|
||||||
|
<PlusOutlined />
|
||||||
|
</el-icon>
|
||||||
|
</template>
|
||||||
|
添加数据源
|
||||||
|
</el-button>
|
||||||
|
<el-button type="danger" @click="handleDelete()" :disabled="!selectionData.length" v-perm="['sys:dataSource:batchDelete']">
|
||||||
|
<template #icon>
|
||||||
|
<el-icon class="el-input__icon">
|
||||||
|
<Delete />
|
||||||
|
</el-icon>
|
||||||
|
</template>
|
||||||
|
删除
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
</el-card>
|
||||||
|
|
||||||
|
<editDialog
|
||||||
|
v-if="editVisible"
|
||||||
|
:dataSourceId="dataSourceId"
|
||||||
|
v-model:visible="editVisible"
|
||||||
|
@success="reloadTable('noRefresh')"
|
||||||
|
>
|
||||||
|
</editDialog>
|
||||||
|
</PageWrapper>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { reactive, ref, h,nextTick,defineAsyncComponent } from 'vue';
|
||||||
|
import { ColProps } from 'element-plus';
|
||||||
|
import { schemas } from './querySchemas';
|
||||||
|
import { useForm } from '@/components/Form/index';
|
||||||
|
import { TableAction } from '@/components/Table';
|
||||||
|
import { getDataSourceList,dataSourceDelete,dataSourceBatchDelete } from '@/api/monitor/dataSource';
|
||||||
|
import { columns } from './columns';
|
||||||
|
import { PlusOutlined } from '@vicons/antd';
|
||||||
|
import {message,confirm} from "@/utils/auth";
|
||||||
|
const editDialog = defineAsyncComponent(() =>
|
||||||
|
import('./edit.vue')
|
||||||
|
)
|
||||||
|
const dataSourceId =ref(0)
|
||||||
|
const editVisible=ref(false)
|
||||||
|
const selectionData = ref([])
|
||||||
|
const tableRef = ref();
|
||||||
|
const formParams = reactive({
|
||||||
|
name:'',
|
||||||
|
dbType:''
|
||||||
|
});
|
||||||
|
const actionColumn = reactive({
|
||||||
|
width: 250,
|
||||||
|
label: '操作',
|
||||||
|
prop: 'action',
|
||||||
|
fixed: 'right',
|
||||||
|
render(record) {
|
||||||
|
return h(TableAction, {
|
||||||
|
style: 'button',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
label: '编辑',
|
||||||
|
type: 'warning',
|
||||||
|
onClick: handleEdit.bind(null, record),
|
||||||
|
auth: ['sys:dataSource:update'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '删除',
|
||||||
|
type: 'danger',
|
||||||
|
onClick: handleDelete.bind(null, record),
|
||||||
|
auth: ['sys:dataSource:delete'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const loadDataTable = async (res: any) => {
|
||||||
|
const result = await getDataSourceList({ ...formParams, ...res });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
function reloadTable(noRefresh='') {
|
||||||
|
tableRef.value.reload(noRefresh?{}:{pageNo:1});
|
||||||
|
}
|
||||||
|
const [register, {}] = useForm({
|
||||||
|
labelWidth: 100,
|
||||||
|
layout: 'horizontal',
|
||||||
|
colProps: { span: 6 } as ColProps,
|
||||||
|
submitOnReset:true,
|
||||||
|
schemas
|
||||||
|
});
|
||||||
|
function handleSubmit(values: Recordable) {
|
||||||
|
handleReset()
|
||||||
|
for (const key in values) {
|
||||||
|
formParams[key] = values[key]
|
||||||
|
}
|
||||||
|
reloadTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleReset() {
|
||||||
|
for (const key in formParams) {
|
||||||
|
formParams[key] ='';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const handleAdd = async () => {
|
||||||
|
dataSourceId.value=0
|
||||||
|
await nextTick();
|
||||||
|
editVisible.value=true
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEdit = async (record: Recordable) => {
|
||||||
|
dataSourceId.value=record.row.id
|
||||||
|
await nextTick();
|
||||||
|
editVisible.value=true
|
||||||
|
};
|
||||||
|
|
||||||
|
async function handleDelete(record: Recordable) {
|
||||||
|
let ids = []
|
||||||
|
if(!record){
|
||||||
|
ids = selectionData.value.map(({id}) => id);
|
||||||
|
}
|
||||||
|
await confirm('确定要删除?');
|
||||||
|
record? await dataSourceDelete(record.row.id):await dataSourceBatchDelete(ids);
|
||||||
|
message("删除成功");
|
||||||
|
reloadTable()
|
||||||
|
}
|
||||||
|
function onSelectionChange(value){
|
||||||
|
selectionData.value = value
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped></style>
|
30
src/views/monitor/dataSource/querySchemas.ts
Normal file
30
src/views/monitor/dataSource/querySchemas.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { FormSchema } from '@/components/Form/index';
|
||||||
|
export const schemas: FormSchema[] = [
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
component: 'Input',
|
||||||
|
label: '数据源名称',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入数据源名称',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'dbType',
|
||||||
|
component: 'Select',
|
||||||
|
label: '数据库类型',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择数据库类型',
|
||||||
|
clearable: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '关系型数据库',
|
||||||
|
value: '0',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '图形数据库',
|
||||||
|
value: '1',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
@ -84,7 +84,6 @@
|
|||||||
import { PlusOutlined } from '@vicons/antd';
|
import { PlusOutlined } from '@vicons/antd';
|
||||||
import {message,confirm,loading, closeLoading} from "@/utils/auth";
|
import {message,confirm,loading, closeLoading} from "@/utils/auth";
|
||||||
import { useUserStore } from '@/store/modules/user';
|
import { useUserStore } from '@/store/modules/user';
|
||||||
import {downloadByData} from '@/utils/file/download';
|
|
||||||
const editDialog = defineAsyncComponent(() =>
|
const editDialog = defineAsyncComponent(() =>
|
||||||
import('./edit.vue')
|
import('./edit.vue')
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user