新增开发工具模块
This commit is contained in:
parent
91b3a09759
commit
7a59fe2140
34
src/api/tool/generator.ts
Normal file
34
src/api/tool/generator.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { http } from '@/utils/http/axios';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 列表
|
||||||
|
*/
|
||||||
|
export function getTableList(params?) {
|
||||||
|
return http.request({
|
||||||
|
url: '/generator/page',
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 一键生成
|
||||||
|
*/
|
||||||
|
export function generator(data:any) {
|
||||||
|
return http.request({
|
||||||
|
url: '/generator/generator',
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 批量删除
|
||||||
|
*/
|
||||||
|
export function batchGenerator(data:any) {
|
||||||
|
return http.request({
|
||||||
|
url: '/generator/batchGenerate',
|
||||||
|
method: 'POST',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
41
src/views/tool/generator/columns.ts
Normal file
41
src/views/tool/generator/columns.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import { h } from 'vue';
|
||||||
|
import { ElTag } from 'element-plus';
|
||||||
|
|
||||||
|
export const columns = [
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数据表名称',
|
||||||
|
prop: 'tableName',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数据表描述',
|
||||||
|
prop: 'tableComment',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数据表引擎',
|
||||||
|
prop: 'engine',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数据表行数',
|
||||||
|
prop: 'tableRows',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数据表长度',
|
||||||
|
prop: 'dataLength',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数据表自增索引',
|
||||||
|
prop: 'autoIncrement',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数据表编码',
|
||||||
|
prop: 'tableCollation',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '创建时间',
|
||||||
|
prop: 'createTime',
|
||||||
|
width: 180,
|
||||||
|
},
|
||||||
|
];
|
194
src/views/tool/generator/edit.vue
Normal file
194
src/views/tool/generator/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>
|
139
src/views/tool/generator/index.vue
Normal file
139
src/views/tool/generator/index.vue
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
<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="handleBatchGenerator()" v-perm="['sys:generator:batchGenerator']">
|
||||||
|
<template #icon>
|
||||||
|
<el-icon class="el-input__icon">
|
||||||
|
<PlusOutlined />
|
||||||
|
</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 { getTableList,generator,batchGenerator } from '@/api/tool/generator';
|
||||||
|
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({
|
||||||
|
tableName:'',
|
||||||
|
tableComment:''
|
||||||
|
});
|
||||||
|
const actionColumn = reactive({
|
||||||
|
width: 150,
|
||||||
|
label: '操作',
|
||||||
|
prop: 'action',
|
||||||
|
fixed: 'right',
|
||||||
|
render(record) {
|
||||||
|
return h(TableAction, {
|
||||||
|
style: 'button',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
label: '一键生成',
|
||||||
|
icon:'Plus',
|
||||||
|
type: 'primary',
|
||||||
|
onClick: handleGenerator.bind(null, record),
|
||||||
|
auth: ['sys:generator:generator'],
|
||||||
|
},
|
||||||
|
|
||||||
|
],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const loadDataTable = async (res: any) => {
|
||||||
|
const result = await getTableList({ ...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] ='';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量生成
|
||||||
|
* @param record 数据记录
|
||||||
|
*/
|
||||||
|
async function handleBatchGenerator(record: Recordable) {
|
||||||
|
let names = []
|
||||||
|
if(!record){
|
||||||
|
names = selectionData.value.map(({tableName}) => tableName);
|
||||||
|
}
|
||||||
|
await confirm('确定要批量一键生成吗?');
|
||||||
|
record? await batchGenerator({tableNames:record.row.tableName}):await batchGenerator({tableNames:names});
|
||||||
|
message("批量生成成功");
|
||||||
|
reloadTable()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一键生成
|
||||||
|
* @param recored 数据记录
|
||||||
|
*/
|
||||||
|
const handleGenerator=async (record: Recordable)=>{
|
||||||
|
await generator({tableNames:record.row.tableName})
|
||||||
|
message("一键生成成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSelectionChange(value){
|
||||||
|
selectionData.value = value
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped></style>
|
19
src/views/tool/generator/querySchemas.ts
Normal file
19
src/views/tool/generator/querySchemas.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { FormSchema } from '@/components/Form/index';
|
||||||
|
export const schemas: FormSchema[] = [
|
||||||
|
{
|
||||||
|
field: 'tableName',
|
||||||
|
component: 'Input',
|
||||||
|
label: '数据表名称',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入数据表名称',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'tableComment',
|
||||||
|
component: 'Input',
|
||||||
|
label: '数据表描述',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入数据表描述',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
Loading…
Reference in New Issue
Block a user