init
This commit is contained in:
@@ -0,0 +1,588 @@
|
||||
<template>
|
||||
<basic-container>
|
||||
<avue-crud
|
||||
:option="option"
|
||||
:table-loading="loading"
|
||||
:data="data"
|
||||
ref="crud"
|
||||
v-model="form"
|
||||
:permission="permissionList"
|
||||
v-model:page="page"
|
||||
@row-del="rowDel"
|
||||
@row-update="rowUpdate"
|
||||
@row-save="rowSave"
|
||||
:before-open="beforeOpen"
|
||||
@search-change="searchChange"
|
||||
@search-reset="searchReset"
|
||||
@selection-change="selectionChange"
|
||||
@current-change="currentChange"
|
||||
@size-change="sizeChange"
|
||||
@refresh-change="refreshChange"
|
||||
@on-load="onLoad"
|
||||
>
|
||||
<template #menu-left>
|
||||
<el-button
|
||||
type="danger"
|
||||
icon="el-icon-delete"
|
||||
v-if="permission.code_delete"
|
||||
plain
|
||||
@click="handleDelete"
|
||||
>删 除
|
||||
</el-button>
|
||||
<el-tooltip
|
||||
class="item"
|
||||
effect="dark"
|
||||
content="将选中的多重配置集合批量生成代码"
|
||||
placement="top"
|
||||
>
|
||||
<el-button type="primary" plain icon="el-icon-refresh" @click="handleBuild"
|
||||
>代码批量生成
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip
|
||||
class="item"
|
||||
effect="dark"
|
||||
content="不通过多重配置直接生成最简化的CRUD代码"
|
||||
placement="top"
|
||||
>
|
||||
<el-button type="info" plain icon="el-icon-cpu" @click="handleCodeGen"
|
||||
>代码快速生成
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<template #menu-right>
|
||||
<el-tooltip
|
||||
class="item"
|
||||
effect="dark"
|
||||
content="通过可视化表单设计器快速生成单表模块"
|
||||
placement="top"
|
||||
>
|
||||
<el-button
|
||||
plain
|
||||
v-if="userInfo.authority.includes('administrator')"
|
||||
:loading="!componentLoaded"
|
||||
icon="el-icon-connection"
|
||||
@click="handleFormSetting"
|
||||
>可视化表单设计器
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip
|
||||
class="item"
|
||||
effect="dark"
|
||||
content="配置代码生成的默认参数后自动绑定"
|
||||
placement="top"
|
||||
>
|
||||
<el-button
|
||||
plain
|
||||
v-if="userInfo.authority.includes('administrator')"
|
||||
icon="el-icon-message-box"
|
||||
@click="handleCodeSetting"
|
||||
>默认配置管理
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<template #menu="scope">
|
||||
<el-button
|
||||
type="primary"
|
||||
text
|
||||
icon="el-icon-document-copy"
|
||||
v-if="permission.code_edit"
|
||||
class="none-border"
|
||||
@click.stop="handleCopy(scope.row)"
|
||||
>复制
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
text
|
||||
icon="el-icon-refresh"
|
||||
v-if="userInfo.authority.includes('administrator')"
|
||||
class="none-border"
|
||||
@click.stop="handleBuildSingle(scope.row)"
|
||||
>生成
|
||||
</el-button>
|
||||
</template>
|
||||
</avue-crud>
|
||||
<el-drawer title="代码快速生成" append-to-body v-model="codeGenBox" direction="rtl" size="50%">
|
||||
<avue-form :option="genOption" v-model="genForm" @submit="handleCodeGenSubmit" />
|
||||
</el-drawer>
|
||||
<el-drawer
|
||||
title="可视化表单管理"
|
||||
append-to-body
|
||||
v-model="formSettingBox"
|
||||
direction="rtl"
|
||||
size="1000px"
|
||||
>
|
||||
<form-setting></form-setting>
|
||||
</el-drawer>
|
||||
<el-drawer
|
||||
title="默认配置管理"
|
||||
append-to-body
|
||||
v-model="codeSettingBox"
|
||||
direction="rtl"
|
||||
size="1000px"
|
||||
>
|
||||
<code-setting></code-setting>
|
||||
</el-drawer>
|
||||
</basic-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getList, getCode, build, remove, add, update, copy, buildFast } from '@/api/tool/code';
|
||||
import { getEnableDetail, getTableForm } from '@/api/tool/codesetting';
|
||||
import {
|
||||
getDetail as modelDetail,
|
||||
getTableInfoByName,
|
||||
getTableList,
|
||||
prototypeDetail,
|
||||
} from '@/api/tool/model';
|
||||
import { codeOption, genOption } from '@/option/tool/code';
|
||||
import { validatejson, validatenull } from '@/utils/validate';
|
||||
import { mapGetters } from 'vuex';
|
||||
import { getMenuTree } from '@/api/system/menu';
|
||||
import { loadFormDesignModule, loadFormModule } from '@/utils/module';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
form: {},
|
||||
genForm: {},
|
||||
selectionList: [],
|
||||
componentLoaded: false,
|
||||
loading: true,
|
||||
loadingOption: {
|
||||
lock: true,
|
||||
text: '物理表读取中',
|
||||
background: 'rgba(0, 0, 0, 0.7)',
|
||||
},
|
||||
addMode: false,
|
||||
codeGenBox: false,
|
||||
codeSettingBox: false,
|
||||
codeSetting: {},
|
||||
formSettingBox: false,
|
||||
query: {},
|
||||
page: {
|
||||
pageSize: 10,
|
||||
currentPage: 1,
|
||||
total: 0,
|
||||
},
|
||||
option: codeOption,
|
||||
genOption: genOption,
|
||||
data: [],
|
||||
};
|
||||
},
|
||||
created() {
|
||||
// 懒加载表单设计器模块
|
||||
Promise.all([loadFormModule(this.$app), loadFormDesignModule(this.$app)]).then(() => {
|
||||
this.componentLoaded = true;
|
||||
});
|
||||
},
|
||||
watch: {
|
||||
'form.modelId'() {
|
||||
if (!validatenull(this.form.modelId) && this.addMode) {
|
||||
// 获取数据模型信息
|
||||
modelDetail(this.form.modelId).then(res => {
|
||||
const result = res.data;
|
||||
if (result.success) {
|
||||
const { modelName, modelTable, modelCode } = result.data;
|
||||
const lowerModelCode = modelCode.toLowerCase();
|
||||
//if (validatenull(this.form.tablePrefix)) {
|
||||
this.form.tablePrefix = modelTable.split('_')[0] + '_';
|
||||
//}
|
||||
//if (validatenull(this.form.tableName)) {
|
||||
this.form.tableName = modelTable;
|
||||
//}
|
||||
//if (validatenull(this.form.codeName)) {
|
||||
this.form.codeName = modelName;
|
||||
//}
|
||||
if (validatenull(this.form.serviceName)) {
|
||||
this.form.serviceName = `blade-${lowerModelCode}`;
|
||||
}
|
||||
//if (validatenull(this.form.pkName)) {
|
||||
this.form.pkName = 'id';
|
||||
//}
|
||||
if (validatenull(this.form.packageName)) {
|
||||
this.form.packageName = `org.springblade.${lowerModelCode}`;
|
||||
}
|
||||
//if (validatenull(this.form.subFkId) && !validatenull(this.form.tablePrefix)) {
|
||||
this.form.subFkId = modelTable.replace(this.form.tablePrefix, '') + '_id';
|
||||
//}
|
||||
|
||||
// 获取数据原型信息
|
||||
prototypeDetail(this.form.modelId).then(res => {
|
||||
const result = res.data;
|
||||
if (result.success) {
|
||||
const columnTreeId = this.findColumn(this.option.group, 'treeId');
|
||||
const columnTreePid = this.findColumn(this.option.group, 'treePid');
|
||||
const columnTreeName = this.findColumn(this.option.group, 'treeName');
|
||||
columnTreeId.dicData = result.data;
|
||||
columnTreePid.dicData = result.data;
|
||||
columnTreeName.dicData = result.data;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
'form.templateType'() {
|
||||
// 模版类型
|
||||
const type = this.form.templateType;
|
||||
|
||||
// 主子表字段显隐
|
||||
const columnSubModelId = this.findColumn(this.option.group, 'subModelId');
|
||||
const columnSubFkId = this.findColumn(this.option.group, 'subFkId');
|
||||
columnSubModelId.display = type === 'sub';
|
||||
columnSubFkId.display = type === 'sub';
|
||||
|
||||
// 树表字段显隐
|
||||
const columnTreeId = this.findColumn(this.option.group, 'treeId');
|
||||
const columnTreePid = this.findColumn(this.option.group, 'treePid');
|
||||
const columnTreeName = this.findColumn(this.option.group, 'treeName');
|
||||
columnTreeId.display = type === 'tree';
|
||||
columnTreePid.display = type === 'tree';
|
||||
columnTreeName.display = type === 'tree';
|
||||
},
|
||||
'genForm.datasourceId'() {
|
||||
if (!validatenull(this.genForm.datasourceId)) {
|
||||
const fullLoading = this.$loading(this.loadingOption);
|
||||
getTableList(this.genForm.datasourceId)
|
||||
.then(res => {
|
||||
const column = this.findColumn(this.genOption.column, 'modelTable');
|
||||
column.dicData = res.data.data;
|
||||
fullLoading.close();
|
||||
})
|
||||
.catch(() => {
|
||||
fullLoading.close();
|
||||
});
|
||||
}
|
||||
},
|
||||
'genForm.modelTable'() {
|
||||
if (!validatenull(this.genForm.modelTable)) {
|
||||
const fullLoading = this.$loading(this.loadingOption);
|
||||
getTableInfoByName(this.genForm.modelTable, this.genForm.datasourceId)
|
||||
.then(res => {
|
||||
const result = res.data;
|
||||
if (result.success) {
|
||||
// 赋默认值
|
||||
const { comment, entityName } = result.data;
|
||||
this.genForm.modelClass = entityName;
|
||||
this.genForm.modelCode = entityName.replace(/^\S/, s => s.toLowerCase());
|
||||
const lowerModelCode = this.genForm.modelCode.toLowerCase();
|
||||
this.genForm.tablePrefix = this.genForm.modelTable.split('_')[0] + '_';
|
||||
this.genForm.tableName = this.genForm.modelTable;
|
||||
this.genForm.codeName = comment;
|
||||
this.genForm.pkName = 'id';
|
||||
if (validatenull(this.genForm.serviceName)) {
|
||||
this.genForm.serviceName = `blade-${lowerModelCode}`;
|
||||
}
|
||||
if (validatenull(this.genForm.packageName)) {
|
||||
this.genForm.packageName = `org.springblade.${lowerModelCode}`;
|
||||
}
|
||||
// 字段显隐
|
||||
const columnModelForm = this.findColumn(this.genOption.column, 'modelForm');
|
||||
const columnModelClass = this.findColumn(this.genOption.column, 'modelClass');
|
||||
const columnModelCode = this.findColumn(this.genOption.column, 'modelCode');
|
||||
const columnTablePrefix = this.findColumn(this.genOption.column, 'tablePrefix');
|
||||
const columnTableName = this.findColumn(this.genOption.column, 'tableName');
|
||||
const columnCodeName = this.findColumn(this.genOption.column, 'codeName');
|
||||
const columnPkName = this.findColumn(this.genOption.column, 'pkName');
|
||||
this.genForm.modelForm = '';
|
||||
getTableForm(this.genForm.modelTable).then(res => {
|
||||
columnModelForm.dicData = res.data.data;
|
||||
});
|
||||
columnModelForm.display = true;
|
||||
columnModelClass.display = true;
|
||||
columnModelCode.display = true;
|
||||
columnTablePrefix.display = true;
|
||||
columnTableName.display = true;
|
||||
columnCodeName.display = true;
|
||||
columnPkName.display = true;
|
||||
fullLoading.close();
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
fullLoading.close();
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['userInfo', 'permission']),
|
||||
permissionList() {
|
||||
return {
|
||||
addBtn: this.validData(this.permission.code_add, false),
|
||||
viewBtn: this.validData(this.permission.code_view, false),
|
||||
delBtn: this.validData(this.permission.code_delete, false),
|
||||
editBtn: this.validData(this.permission.code_edit, false),
|
||||
};
|
||||
},
|
||||
ids() {
|
||||
let ids = [];
|
||||
this.selectionList.forEach(ele => {
|
||||
ids.push(ele.id);
|
||||
});
|
||||
return ids.join(',');
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
initData() {
|
||||
return getMenuTree().then(res => {
|
||||
const column = this.findColumn(this.option.group, 'menuId');
|
||||
column.dicData = res.data.data;
|
||||
});
|
||||
},
|
||||
initGenData() {
|
||||
getMenuTree().then(res => {
|
||||
const column = this.findColumn(this.genOption.column, 'menuId');
|
||||
column.dicData = res.data.data;
|
||||
});
|
||||
getEnableDetail().then(res => {
|
||||
if (validatejson(res.data.data.settings)) {
|
||||
this.codeSetting = JSON.parse(res.data.data.settings);
|
||||
this.genForm = {
|
||||
menuId: this.codeSetting.menuId,
|
||||
serviceName: this.codeSetting.serviceName,
|
||||
packageName: this.codeSetting.packageName,
|
||||
baseMode: this.codeSetting.baseMode,
|
||||
wrapMode: this.codeSetting.wrapMode,
|
||||
feignMode: this.codeSetting.feignMode,
|
||||
codeStyle: this.codeSetting.codeStyle,
|
||||
apiPath: this.codeSetting.apiPath,
|
||||
webPath: this.codeSetting.webPath,
|
||||
};
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '默认配置加载成功',
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
initSetting() {
|
||||
return getEnableDetail().then(res => {
|
||||
if (validatejson(res.data.data.settings)) {
|
||||
this.codeSetting = JSON.parse(res.data.data.settings);
|
||||
this.form = {
|
||||
menuId: this.codeSetting.menuId,
|
||||
serviceName: this.codeSetting.serviceName,
|
||||
packageName: this.codeSetting.packageName,
|
||||
baseMode: this.codeSetting.baseMode,
|
||||
wrapMode: this.codeSetting.wrapMode,
|
||||
feignMode: this.codeSetting.feignMode,
|
||||
codeStyle: this.codeSetting.codeStyle,
|
||||
apiPath: this.codeSetting.apiPath,
|
||||
webPath: this.codeSetting.webPath,
|
||||
};
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '默认配置加载成功',
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
initCode(id) {
|
||||
return getCode(id).then(res => {
|
||||
this.form = res.data.data;
|
||||
});
|
||||
},
|
||||
rowSave(row, done, loading) {
|
||||
add(row).then(
|
||||
() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
done();
|
||||
},
|
||||
error => {
|
||||
window.console.log(error);
|
||||
loading();
|
||||
}
|
||||
);
|
||||
},
|
||||
rowUpdate(row, index, done, loading) {
|
||||
update(row).then(
|
||||
() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
done();
|
||||
},
|
||||
error => {
|
||||
window.console.log(error);
|
||||
loading();
|
||||
}
|
||||
);
|
||||
},
|
||||
rowDel(row) {
|
||||
this.$confirm('确定将选择数据删除?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
return remove(row.id);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
});
|
||||
},
|
||||
handleCodeGen() {
|
||||
this.initGenData();
|
||||
this.codeGenBox = true;
|
||||
},
|
||||
handleFormSetting() {
|
||||
this.formSettingBox = true;
|
||||
},
|
||||
handleCodeSetting() {
|
||||
this.codeSettingBox = true;
|
||||
},
|
||||
searchReset() {
|
||||
this.query = {};
|
||||
this.onLoad(this.page);
|
||||
},
|
||||
searchChange(params, done) {
|
||||
this.query = params;
|
||||
this.page.currentPage = 1;
|
||||
this.onLoad(this.page, params);
|
||||
done();
|
||||
},
|
||||
selectionChange(list) {
|
||||
this.selectionList = list;
|
||||
},
|
||||
selectionClear() {
|
||||
this.selectionList = [];
|
||||
this.$refs.crud.toggleSelection();
|
||||
},
|
||||
handleDelete() {
|
||||
if (this.selectionList.length === 0) {
|
||||
this.$message.warning('请选择至少一条数据');
|
||||
return;
|
||||
}
|
||||
this.$confirm('确定将选择数据删除?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
return remove(this.ids);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
this.$refs.crud.toggleSelection();
|
||||
});
|
||||
},
|
||||
handleBuild() {
|
||||
if (this.selectionList.length === 0) {
|
||||
this.$message.warning('请选择至少一条数据');
|
||||
return;
|
||||
}
|
||||
this.$confirm('是否生成选中模块的代码?', {
|
||||
title: '代码生成确认',
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
}).then(() => {
|
||||
return build(this.ids).then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
this.$refs.crud.toggleSelection();
|
||||
});
|
||||
});
|
||||
},
|
||||
handleBuildSingle(row) {
|
||||
this.$confirm(`是否生成选中模块 [${row.codeName}] 的代码?`, {
|
||||
title: '代码生成确认',
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
}).then(() => {
|
||||
return build(row.id).then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
this.$refs.crud.toggleSelection();
|
||||
});
|
||||
});
|
||||
},
|
||||
handleCodeGenSubmit(form, done) {
|
||||
buildFast(form).then(
|
||||
() => {
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '代码生成成功!',
|
||||
});
|
||||
done();
|
||||
this.codeGenBox = false;
|
||||
},
|
||||
error => {
|
||||
window.console.log(error);
|
||||
done();
|
||||
}
|
||||
);
|
||||
},
|
||||
handleCopy(row) {
|
||||
copy(row.id).then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '复制成功!',
|
||||
});
|
||||
});
|
||||
},
|
||||
async beforeOpen(done, type) {
|
||||
const tasks = [];
|
||||
|
||||
if (['add'].includes(type)) {
|
||||
this.addMode = true;
|
||||
tasks.push(this.initSetting());
|
||||
}
|
||||
|
||||
if (['add', 'edit'].includes(type)) {
|
||||
tasks.push(this.initData());
|
||||
}
|
||||
|
||||
if (['edit', 'view'].includes(type)) {
|
||||
this.addMode = false;
|
||||
tasks.push(this.initCode(this.form.id));
|
||||
}
|
||||
|
||||
await Promise.all(tasks);
|
||||
done();
|
||||
},
|
||||
currentChange(currentPage) {
|
||||
this.page.currentPage = currentPage;
|
||||
},
|
||||
sizeChange(pageSize) {
|
||||
this.page.pageSize = pageSize;
|
||||
},
|
||||
refreshChange() {
|
||||
this.onLoad(this.page, this.query);
|
||||
},
|
||||
onLoad(page, params = {}) {
|
||||
this.loading = true;
|
||||
getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
|
||||
const data = res.data.data;
|
||||
this.page.total = data.total;
|
||||
this.data = data.records;
|
||||
this.loading = false;
|
||||
this.selectionClear();
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,281 @@
|
||||
<template>
|
||||
<basic-container>
|
||||
<avue-crud
|
||||
:option="option"
|
||||
v-model:search="search"
|
||||
v-model:page="page"
|
||||
v-model="form"
|
||||
:table-loading="loading"
|
||||
:data="data"
|
||||
:permission="permissionList"
|
||||
:before-open="beforeOpen"
|
||||
ref="crud"
|
||||
@row-update="rowUpdate"
|
||||
@row-save="rowSave"
|
||||
@row-del="rowDel"
|
||||
@search-change="searchChange"
|
||||
@search-reset="searchReset"
|
||||
@selection-change="selectionChange"
|
||||
@current-change="currentChange"
|
||||
@size-change="sizeChange"
|
||||
@refresh-change="refreshChange"
|
||||
@on-load="onLoad"
|
||||
>
|
||||
<template #menu-left>
|
||||
<el-button type="danger" icon="el-icon-delete" plain @click="handleDelete"
|
||||
>删 除
|
||||
</el-button>
|
||||
</template>
|
||||
<template #menu="scope">
|
||||
<el-button
|
||||
type="primary"
|
||||
text
|
||||
icon="el-icon-circle-check"
|
||||
@click.stop="handleEnable(scope.row)"
|
||||
>启 用
|
||||
</el-button>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<el-tag>{{ row.status === 1 ? '否' : '是' }}</el-tag>
|
||||
</template>
|
||||
</avue-crud>
|
||||
</basic-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getList, getDetail, add, update, remove, enable } from '@/api/tool/codesetting';
|
||||
import { getMenuTree } from '@/api/system/menu';
|
||||
import option from '@/option/tool/codesetting';
|
||||
import { mapGetters } from 'vuex';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
form: {},
|
||||
query: {},
|
||||
search: {},
|
||||
loading: true,
|
||||
page: {
|
||||
pageSize: 10,
|
||||
currentPage: 1,
|
||||
total: 0,
|
||||
},
|
||||
selectionList: [],
|
||||
option: option,
|
||||
data: [],
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['userInfo', 'permission']),
|
||||
permissionList() {
|
||||
return {
|
||||
addBtn: true,
|
||||
viewBtn: true,
|
||||
delBtn: true,
|
||||
editBtn: true,
|
||||
};
|
||||
},
|
||||
ids() {
|
||||
let ids = [];
|
||||
this.selectionList.forEach(ele => {
|
||||
ids.push(ele.id);
|
||||
});
|
||||
return ids.join(',');
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
initData() {
|
||||
getMenuTree().then(res => {
|
||||
const column = this.findColumn(this.option.column, 'menuId');
|
||||
column.dicData = res.data.data;
|
||||
});
|
||||
},
|
||||
rowSettings(row) {
|
||||
return JSON.stringify({
|
||||
serviceName: row.serviceName,
|
||||
packageName: row.packageName,
|
||||
menuId: row.menuId,
|
||||
baseMode: row.baseMode,
|
||||
wrapMode: row.wrapMode,
|
||||
feignMode: row.feignMode,
|
||||
codeStyle: row.codeStyle,
|
||||
apiPath: row.apiPath,
|
||||
webPath: row.webPath,
|
||||
});
|
||||
},
|
||||
rowSettingsForm(data) {
|
||||
const row = JSON.parse(data);
|
||||
return {
|
||||
serviceName: row.serviceName,
|
||||
packageName: row.packageName,
|
||||
menuId: row.menuId,
|
||||
baseMode: row.baseMode,
|
||||
wrapMode: row.wrapMode,
|
||||
feignMode: row.feignMode,
|
||||
codeStyle: row.codeStyle,
|
||||
apiPath: row.apiPath,
|
||||
webPath: row.webPath,
|
||||
};
|
||||
},
|
||||
rowSave(row, done, loading) {
|
||||
const data = {
|
||||
name: row.name,
|
||||
code: row.code,
|
||||
settings: this.rowSettings(row),
|
||||
};
|
||||
add(data).then(
|
||||
() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
done();
|
||||
},
|
||||
error => {
|
||||
loading();
|
||||
window.console.log(error);
|
||||
}
|
||||
);
|
||||
},
|
||||
rowUpdate(row, index, done, loading) {
|
||||
const data = {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
code: row.code,
|
||||
settings: this.rowSettings(row),
|
||||
};
|
||||
update(data).then(
|
||||
() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
done();
|
||||
},
|
||||
error => {
|
||||
loading();
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
},
|
||||
rowDel(row) {
|
||||
this.$confirm('确定将选择数据删除?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
return remove(row.id);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
});
|
||||
},
|
||||
handleDelete() {
|
||||
if (this.selectionList.length === 0) {
|
||||
this.$message.warning('请选择至少一条数据');
|
||||
return;
|
||||
}
|
||||
this.$confirm('确定将选择数据删除?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
return remove(this.ids);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
this.$refs.crud.toggleSelection();
|
||||
});
|
||||
},
|
||||
handleEnable(row) {
|
||||
this.$confirm('是否确定启用这条配置?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
return enable(row.id);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
this.$refs.crud.toggleSelection();
|
||||
});
|
||||
},
|
||||
beforeOpen(done, type) {
|
||||
if (['add', 'edit'].includes(type)) {
|
||||
this.initData();
|
||||
}
|
||||
if (['edit', 'view'].includes(type)) {
|
||||
getDetail(this.form.id).then(res => {
|
||||
this.form = {
|
||||
...this.form,
|
||||
...this.rowSettingsForm(res.data.data.settings),
|
||||
};
|
||||
});
|
||||
}
|
||||
done();
|
||||
},
|
||||
searchReset() {
|
||||
this.query = {};
|
||||
this.onLoad(this.page);
|
||||
},
|
||||
searchChange(params, done) {
|
||||
this.query = params;
|
||||
this.page.currentPage = 1;
|
||||
this.onLoad(this.page, params);
|
||||
done();
|
||||
},
|
||||
selectionChange(list) {
|
||||
this.selectionList = list;
|
||||
},
|
||||
selectionClear() {
|
||||
this.selectionList = [];
|
||||
this.$refs.crud.toggleSelection();
|
||||
},
|
||||
currentChange(currentPage) {
|
||||
this.page.currentPage = currentPage;
|
||||
},
|
||||
sizeChange(pageSize) {
|
||||
this.page.pageSize = pageSize;
|
||||
},
|
||||
refreshChange() {
|
||||
this.onLoad(this.page, this.query);
|
||||
},
|
||||
onLoad(page, params = {}) {
|
||||
this.loading = true;
|
||||
|
||||
let values = {
|
||||
...params,
|
||||
...this.query,
|
||||
category: 1,
|
||||
};
|
||||
|
||||
getList(page.currentPage, page.pageSize, values).then(res => {
|
||||
const data = res.data.data;
|
||||
this.page.total = data.total;
|
||||
this.data = data.records;
|
||||
this.loading = false;
|
||||
this.selectionClear();
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style></style>
|
||||
@@ -0,0 +1,409 @@
|
||||
<template>
|
||||
<basic-container>
|
||||
<avue-crud
|
||||
:option="option"
|
||||
:table-loading="loading"
|
||||
:data="data"
|
||||
v-model:page="page"
|
||||
:permission="permissionList"
|
||||
:before-open="beforeOpen"
|
||||
v-model="form"
|
||||
ref="crud"
|
||||
@row-update="rowUpdate"
|
||||
@row-save="rowSave"
|
||||
@row-del="rowDel"
|
||||
@search-change="searchChange"
|
||||
@search-reset="searchReset"
|
||||
@selection-change="selectionChange"
|
||||
@current-change="currentChange"
|
||||
@size-change="sizeChange"
|
||||
@refresh-change="refreshChange"
|
||||
@on-load="onLoad"
|
||||
>
|
||||
<template #menu-left>
|
||||
<el-button
|
||||
type="danger"
|
||||
icon="el-icon-delete"
|
||||
plain
|
||||
v-if="permission.datasource_delete"
|
||||
@click="handleDelete"
|
||||
>删 除
|
||||
</el-button>
|
||||
</template>
|
||||
</avue-crud>
|
||||
</basic-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getList, getDetail, add, update, remove } from '@/api/tool/datasource';
|
||||
import { mapGetters } from 'vuex';
|
||||
import func from '@/utils/func';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
form: {},
|
||||
query: {},
|
||||
loading: true,
|
||||
page: {
|
||||
pageSize: 10,
|
||||
currentPage: 1,
|
||||
total: 0,
|
||||
},
|
||||
selectionList: [],
|
||||
option: {
|
||||
height: 'auto',
|
||||
calcHeight: 32,
|
||||
dialogWidth: 900,
|
||||
tip: false,
|
||||
searchShow: true,
|
||||
searchMenuSpan: 6,
|
||||
border: true,
|
||||
index: true,
|
||||
viewBtn: true,
|
||||
grid: true,
|
||||
selection: true,
|
||||
dialogClickModal: false,
|
||||
column: [
|
||||
{
|
||||
label: '名称',
|
||||
prop: 'name',
|
||||
width: 120,
|
||||
span: 24,
|
||||
search: true,
|
||||
gridRow: true,
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入数据源名称',
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '数据类型',
|
||||
type: 'radio',
|
||||
value: 1,
|
||||
span: 24,
|
||||
width: 120,
|
||||
searchLabelWidth: 100,
|
||||
row: true,
|
||||
gridRow: true,
|
||||
display: false,
|
||||
dicData: [
|
||||
{
|
||||
label: 'jdbc',
|
||||
value: 1,
|
||||
},
|
||||
],
|
||||
dataType: 'number',
|
||||
prop: 'category',
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择分类',
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'YAML',
|
||||
prop: 'shardingConfig',
|
||||
span: 24,
|
||||
minRows: 5,
|
||||
hide: true,
|
||||
display: false,
|
||||
gridRow: true,
|
||||
type: 'textarea',
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入YAML配置',
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '驱动类',
|
||||
prop: 'driverClass',
|
||||
type: 'select',
|
||||
span: 24,
|
||||
gridRow: true,
|
||||
dicData: [
|
||||
{
|
||||
label: 'com.mysql.cj.jdbc.Driver',
|
||||
value: 'com.mysql.cj.jdbc.Driver',
|
||||
},
|
||||
{
|
||||
label: 'org.postgresql.Driver',
|
||||
value: 'org.postgresql.Driver',
|
||||
},
|
||||
{
|
||||
label: 'oracle.jdbc.OracleDriver',
|
||||
value: 'oracle.jdbc.OracleDriver',
|
||||
},
|
||||
{
|
||||
label: 'com.microsoft.sqlserver.jdbc.SQLServerDriver',
|
||||
value: 'com.microsoft.sqlserver.jdbc.SQLServerDriver',
|
||||
},
|
||||
{
|
||||
label: 'dm.jdbc.driver.DmDriver',
|
||||
value: 'dm.jdbc.driver.DmDriver',
|
||||
},
|
||||
{
|
||||
label: 'com.yashandb.jdbc.Driver',
|
||||
value: 'com.yashandb.jdbc.Driver',
|
||||
},
|
||||
{
|
||||
label: 'com.kingbase8.Driver',
|
||||
value: 'com.kingbase8.Driver',
|
||||
},
|
||||
],
|
||||
width: 200,
|
||||
display: true,
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入驱动类',
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '连接地址',
|
||||
prop: 'url',
|
||||
span: 24,
|
||||
display: true,
|
||||
gridRow: true,
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入连接地址',
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '用户名',
|
||||
prop: 'username',
|
||||
width: 120,
|
||||
display: true,
|
||||
gridRow: true,
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入用户名',
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '密码',
|
||||
prop: 'password',
|
||||
hide: true,
|
||||
display: true,
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入密码',
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '备注',
|
||||
prop: 'remark',
|
||||
span: 24,
|
||||
minRows: 3,
|
||||
hide: true,
|
||||
type: 'textarea',
|
||||
},
|
||||
],
|
||||
},
|
||||
data: [],
|
||||
driverUrlTemplates: {
|
||||
'com.mysql.cj.jdbc.Driver':
|
||||
'jdbc:mysql://localhost:3306/bladex?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true',
|
||||
'org.postgresql.Driver': 'jdbc:postgresql://127.0.0.1:5432/bladex',
|
||||
'oracle.jdbc.OracleDriver': 'jdbc:oracle:thin:@//127.0.0.1:1521/ORCLPDB',
|
||||
'com.microsoft.sqlserver.jdbc.SQLServerDriver':
|
||||
'jdbc:sqlserver://127.0.0.1:1433;DatabaseName=bladex',
|
||||
'dm.jdbc.driver.DmDriver':
|
||||
'jdbc:dm://127.0.0.1:5236/bladex?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8',
|
||||
'com.yashandb.jdbc.Driver': 'jdbc:yasdb://127.0.0.1:1688/bladex',
|
||||
'com.kingbase8.Driver': 'jdbc:kingbase8://localhost:4321/bladex',
|
||||
},
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
'form.category'() {
|
||||
const category = func.toInt(this.form.category);
|
||||
this.$refs.crud.option.column.filter(item => {
|
||||
if (item.prop === 'driverClass') {
|
||||
item.display = category === 1;
|
||||
}
|
||||
if (item.prop === 'url') {
|
||||
item.display = category === 1;
|
||||
}
|
||||
if (item.prop === 'username') {
|
||||
item.display = category === 1;
|
||||
}
|
||||
if (item.prop === 'password') {
|
||||
item.display = category === 1;
|
||||
}
|
||||
if (item.prop === 'shardingConfig') {
|
||||
item.display = category === 2;
|
||||
}
|
||||
});
|
||||
},
|
||||
'form.driverClass'(newDriverClass) {
|
||||
// 当驱动类发生变化时,自动设置对应的默认URL
|
||||
if (newDriverClass && this.driverUrlTemplates[newDriverClass]) {
|
||||
// 只在URL为空或者是其他驱动的默认URL时才自动填充
|
||||
const isDefaultUrl =
|
||||
!this.form.url || Object.values(this.driverUrlTemplates).includes(this.form.url);
|
||||
if (isDefaultUrl) {
|
||||
this.form.url = this.driverUrlTemplates[newDriverClass];
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['permission']),
|
||||
permissionList() {
|
||||
return {
|
||||
addBtn: this.validData(this.permission.datasource_add, false),
|
||||
viewBtn: this.validData(this.permission.datasource_view, false),
|
||||
delBtn: this.validData(this.permission.datasource_delete, false),
|
||||
editBtn: this.validData(this.permission.datasource_edit, false),
|
||||
};
|
||||
},
|
||||
ids() {
|
||||
let ids = [];
|
||||
this.selectionList.forEach(ele => {
|
||||
ids.push(ele.id);
|
||||
});
|
||||
return ids.join(',');
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
rowSave(row, done, loading) {
|
||||
add(row).then(
|
||||
() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
done();
|
||||
},
|
||||
error => {
|
||||
window.console.log(error);
|
||||
loading();
|
||||
}
|
||||
);
|
||||
},
|
||||
rowUpdate(row, index, done, loading) {
|
||||
update(row).then(
|
||||
() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
done();
|
||||
},
|
||||
error => {
|
||||
window.console.log(error);
|
||||
loading();
|
||||
}
|
||||
);
|
||||
},
|
||||
rowDel(row) {
|
||||
this.$confirm('确定将选择数据删除?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
return remove(row.id);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
});
|
||||
},
|
||||
handleDelete() {
|
||||
if (this.selectionList.length === 0) {
|
||||
this.$message.warning('请选择至少一条数据');
|
||||
return;
|
||||
}
|
||||
this.$confirm('确定将选择数据删除?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
return remove(this.ids);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
this.$refs.crud.toggleSelection();
|
||||
});
|
||||
},
|
||||
beforeOpen(done, type) {
|
||||
if (['edit', 'view'].includes(type)) {
|
||||
getDetail(this.form.id).then(res => {
|
||||
this.form = res.data.data;
|
||||
});
|
||||
}
|
||||
done();
|
||||
},
|
||||
searchReset() {
|
||||
this.query = {};
|
||||
this.onLoad(this.page);
|
||||
},
|
||||
searchChange(params, done) {
|
||||
this.query = params;
|
||||
this.page.currentPage = 1;
|
||||
this.onLoad(this.page, params);
|
||||
done();
|
||||
},
|
||||
selectionChange(list) {
|
||||
this.selectionList = list;
|
||||
},
|
||||
selectionClear() {
|
||||
this.selectionList = [];
|
||||
this.$refs.crud.toggleSelection();
|
||||
},
|
||||
currentChange(currentPage) {
|
||||
this.page.currentPage = currentPage;
|
||||
},
|
||||
sizeChange(pageSize) {
|
||||
this.page.pageSize = pageSize;
|
||||
},
|
||||
refreshChange() {
|
||||
this.onLoad(this.page, this.query);
|
||||
},
|
||||
onLoad(page, params = {}) {
|
||||
this.loading = true;
|
||||
getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
|
||||
const data = res.data.data;
|
||||
this.page.total = data.total;
|
||||
this.data = data.records;
|
||||
this.loading = false;
|
||||
this.selectionClear();
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style></style>
|
||||
@@ -0,0 +1,419 @@
|
||||
<template>
|
||||
<basic-container>
|
||||
<avue-crud
|
||||
:option="option"
|
||||
v-model:search="search"
|
||||
v-model:page="page"
|
||||
v-model="form"
|
||||
:table-loading="loading"
|
||||
:data="data"
|
||||
:permission="permissionList"
|
||||
:before-open="beforeOpen"
|
||||
ref="crud"
|
||||
@row-update="rowUpdate"
|
||||
@row-save="rowSave"
|
||||
@row-del="rowDel"
|
||||
@search-change="searchChange"
|
||||
@search-reset="searchReset"
|
||||
@selection-change="selectionChange"
|
||||
@current-change="currentChange"
|
||||
@size-change="sizeChange"
|
||||
@refresh-change="refreshChange"
|
||||
@on-load="onLoad"
|
||||
>
|
||||
<template #menu-left>
|
||||
<el-button type="danger" icon="el-icon-delete" plain @click="handleDelete"
|
||||
>删 除
|
||||
</el-button>
|
||||
</template>
|
||||
<template #menu="scope">
|
||||
<el-button type="primary" text icon="el-icon-setting" @click.stop="handleDesign(scope.row)"
|
||||
>设 计
|
||||
</el-button>
|
||||
</template>
|
||||
</avue-crud>
|
||||
<el-dialog
|
||||
title="可视化表单设计"
|
||||
v-model="designBox"
|
||||
:fullscreen="true"
|
||||
:before-close="handleDesignClose"
|
||||
append-to-body
|
||||
>
|
||||
<nf-form-design
|
||||
ref="formDesign"
|
||||
style="height: 90vh"
|
||||
:options="options"
|
||||
:toolbar="['clear', 'preview', 'import', 'generate']"
|
||||
:includeFields="[
|
||||
'group', // 分组
|
||||
'dynamic', // 子表单
|
||||
'title', // 标题
|
||||
'table', // 表格
|
||||
'input', // 输入框
|
||||
'password', // 密码
|
||||
'textarea', // 文本域
|
||||
'number', // 数字
|
||||
'ueditor', // 富文本
|
||||
'map', // 地图选择器
|
||||
'radio', // 单选
|
||||
'checkbox', // 多选
|
||||
'select', // 下拉选择
|
||||
'tree', // 树形选择
|
||||
'cascader', // 级联选择
|
||||
'table-select', // 表格选择
|
||||
'upload', // 上传
|
||||
'year', // 年
|
||||
'month', // 月
|
||||
'week', // 周
|
||||
'date', // 日期
|
||||
'time', // 时间
|
||||
'datetime', // 日期时间
|
||||
'daterange', // 日期范围
|
||||
'datetimerange', // 日期时间范围
|
||||
'timerange', // 时间范围
|
||||
'sign', // 签名
|
||||
'switch', // 开关
|
||||
'rate', // 评价
|
||||
'color', // 颜色
|
||||
'icon', // 图标
|
||||
'slider', // 滑块
|
||||
]"
|
||||
:is-crud="isCrud"
|
||||
>
|
||||
<template #toolbar>
|
||||
<el-button
|
||||
style="padding: 0"
|
||||
text
|
||||
type="primary"
|
||||
size="default"
|
||||
icon="el-icon-download"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
保存
|
||||
</el-button>
|
||||
</template>
|
||||
</nf-form-design>
|
||||
</el-dialog>
|
||||
</basic-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getList, getDetail, add, update, remove, getTablePrototype } from '@/api/tool/codesetting';
|
||||
import option from '@/option/tool/formsetting';
|
||||
import { mapGetters } from 'vuex';
|
||||
import { validatenull } from '@/utils/validate';
|
||||
import { getTableInfoByName, getTableList } from '@/api/tool/model';
|
||||
import func from '@/utils/func';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
form: {},
|
||||
query: {},
|
||||
search: {},
|
||||
loading: true,
|
||||
loadingOption: {
|
||||
lock: true,
|
||||
text: '物理表读取中',
|
||||
background: 'rgba(0, 0, 0, 0.7)',
|
||||
},
|
||||
designId: '',
|
||||
designBox: false,
|
||||
page: {
|
||||
pageSize: 10,
|
||||
currentPage: 1,
|
||||
total: 0,
|
||||
},
|
||||
selectionList: [],
|
||||
option: option,
|
||||
data: [],
|
||||
modelTable: '',
|
||||
datasourceId: '',
|
||||
isCrud: true,
|
||||
options: {},
|
||||
// 默认不需要显示的字段名
|
||||
hideFields: [
|
||||
'id',
|
||||
'tenant_id',
|
||||
'create_user',
|
||||
'create_dept',
|
||||
'create_time',
|
||||
'update_user',
|
||||
'update_time',
|
||||
'status',
|
||||
'is_deleted',
|
||||
],
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['userInfo', 'permission']),
|
||||
permissionList() {
|
||||
return {
|
||||
addBtn: true,
|
||||
viewBtn: true,
|
||||
delBtn: true,
|
||||
editBtn: true,
|
||||
};
|
||||
},
|
||||
ids() {
|
||||
let ids = [];
|
||||
this.selectionList.forEach(ele => {
|
||||
ids.push(ele.id);
|
||||
});
|
||||
return ids.join(',');
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
'form.datasourceId'() {
|
||||
if (!validatenull(this.form.datasourceId)) {
|
||||
this.datasourceId = this.form.datasourceId;
|
||||
const fullLoading = this.$loading(this.loadingOption);
|
||||
getTableList(this.form.datasourceId)
|
||||
.then(res => {
|
||||
const column = this.findColumn(this.option.column, 'modelTable');
|
||||
column.dicData = res.data.data;
|
||||
fullLoading.close();
|
||||
})
|
||||
.catch(() => {
|
||||
fullLoading.close();
|
||||
});
|
||||
}
|
||||
},
|
||||
'form.modelTable'() {
|
||||
if (!validatenull(this.form.modelTable)) {
|
||||
this.modelTable = this.form.modelTable;
|
||||
const fullLoading = this.$loading(this.loadingOption);
|
||||
getTableInfoByName(this.form.modelTable, this.form.datasourceId)
|
||||
.then(res => {
|
||||
const result = res.data;
|
||||
if (result.success) {
|
||||
// 赋默认值
|
||||
const { comment } = result.data;
|
||||
this.form.name = comment;
|
||||
this.form.code = this.form.modelTable;
|
||||
fullLoading.close();
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
fullLoading.close();
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
rowSave(row, done, loading) {
|
||||
const data = {
|
||||
name: row.name,
|
||||
code: row.code,
|
||||
category: 2,
|
||||
settings: row.settings,
|
||||
};
|
||||
add(data).then(
|
||||
res => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
let design = {
|
||||
id: res.data.data.id,
|
||||
name: data.name,
|
||||
code: data.code,
|
||||
};
|
||||
this.handleDesign(design);
|
||||
done();
|
||||
},
|
||||
error => {
|
||||
loading();
|
||||
window.console.log(error);
|
||||
}
|
||||
);
|
||||
},
|
||||
rowUpdate(row, index, done, loading) {
|
||||
const data = {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
code: row.code,
|
||||
settings: row.settings,
|
||||
};
|
||||
update(data).then(
|
||||
() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
done();
|
||||
},
|
||||
error => {
|
||||
loading();
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
},
|
||||
rowDel(row) {
|
||||
this.$confirm('确定将选择数据删除?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
return remove(row.id);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
});
|
||||
},
|
||||
handleDelete() {
|
||||
if (this.selectionList.length === 0) {
|
||||
this.$message.warning('请选择至少一条数据');
|
||||
return;
|
||||
}
|
||||
this.$confirm('确定将选择数据删除?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
return remove(this.ids);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
this.$refs.crud.toggleSelection();
|
||||
});
|
||||
},
|
||||
handleDesign(design) {
|
||||
this.designBox = true;
|
||||
this.designId = design.id;
|
||||
getDetail(design.id).then(res => {
|
||||
const settings = res.data.data.settings;
|
||||
if (!validatenull(settings)) {
|
||||
this.options = JSON.parse(settings);
|
||||
} else if (!validatenull(this.modelTable) && !validatenull(this.datasourceId)) {
|
||||
getTablePrototype(this.modelTable, this.datasourceId).then(res => {
|
||||
const result = res.data;
|
||||
if (result.success) {
|
||||
const column = result.data
|
||||
.filter(field => {
|
||||
return !validatenull(field.name) && !this.hideFields.includes(field.name);
|
||||
})
|
||||
.map(field => {
|
||||
return {
|
||||
type: 'input',
|
||||
label: field.comment,
|
||||
display: true,
|
||||
prop: func.camelCaseString(field.name),
|
||||
};
|
||||
});
|
||||
this.options = {
|
||||
column: column,
|
||||
};
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
handleDesignClose() {
|
||||
this.modelTable = '';
|
||||
this.datasourceId = '';
|
||||
this.options = {};
|
||||
this.designBox = false;
|
||||
},
|
||||
// 可视化表单提交
|
||||
handleSubmit() {
|
||||
// json, string, app
|
||||
this.$refs.formDesign.getData('json').then(data => {
|
||||
// 表单/表格option
|
||||
console.log(data);
|
||||
const row = {
|
||||
id: this.designId,
|
||||
settings: JSON.stringify(data),
|
||||
};
|
||||
update(row).then(
|
||||
() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
this.designBox = false;
|
||||
},
|
||||
error => {
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
this.$refs.formDesign.getChangeList().then(changeList => {
|
||||
// 字段prop, type, label修改记录
|
||||
console.log(changeList);
|
||||
});
|
||||
});
|
||||
},
|
||||
beforeOpen(done, type) {
|
||||
if (['add', 'edit'].includes(type)) {
|
||||
}
|
||||
if (['edit', 'view'].includes(type)) {
|
||||
getDetail(this.form.id).then(res => {
|
||||
this.form = {
|
||||
...this.form,
|
||||
};
|
||||
});
|
||||
}
|
||||
done();
|
||||
},
|
||||
searchReset() {
|
||||
this.query = {};
|
||||
this.onLoad(this.page);
|
||||
},
|
||||
searchChange(params, done) {
|
||||
this.query = params;
|
||||
this.page.currentPage = 1;
|
||||
this.onLoad(this.page, params);
|
||||
done();
|
||||
},
|
||||
selectionChange(list) {
|
||||
this.selectionList = list;
|
||||
},
|
||||
selectionClear() {
|
||||
this.selectionList = [];
|
||||
this.$refs.crud.toggleSelection();
|
||||
},
|
||||
currentChange(currentPage) {
|
||||
this.page.currentPage = currentPage;
|
||||
},
|
||||
sizeChange(pageSize) {
|
||||
this.page.pageSize = pageSize;
|
||||
},
|
||||
refreshChange() {
|
||||
this.onLoad(this.page, this.query);
|
||||
},
|
||||
onLoad(page, params = {}) {
|
||||
this.loading = true;
|
||||
|
||||
let values = {
|
||||
...params,
|
||||
...this.query,
|
||||
category: 2,
|
||||
};
|
||||
|
||||
getList(page.currentPage, page.pageSize, values).then(res => {
|
||||
const data = res.data.data;
|
||||
this.page.total = data.total;
|
||||
this.data = data.records;
|
||||
this.loading = false;
|
||||
this.selectionClear();
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style></style>
|
||||
@@ -0,0 +1,393 @@
|
||||
<template>
|
||||
<basic-container>
|
||||
<avue-crud
|
||||
:option="option"
|
||||
:table-loading="loading"
|
||||
:data="data"
|
||||
:page="page"
|
||||
:permission="permissionList"
|
||||
:before-open="beforeOpen"
|
||||
v-model="form"
|
||||
v-loading.fullscreen.lock="fullscreenLoading"
|
||||
ref="crud"
|
||||
@row-update="rowUpdate"
|
||||
@row-save="rowSave"
|
||||
@row-del="rowDel"
|
||||
@search-change="searchChange"
|
||||
@search-reset="searchReset"
|
||||
@selection-change="selectionChange"
|
||||
@current-change="currentChange"
|
||||
@size-change="sizeChange"
|
||||
@on-load="onLoad"
|
||||
>
|
||||
<template #menu-left>
|
||||
<el-button type="danger" icon="el-icon-delete" plain @click="handleDelete"
|
||||
>删 除
|
||||
</el-button>
|
||||
</template>
|
||||
<template #menu="{ row }">
|
||||
<el-button
|
||||
type="primary"
|
||||
text
|
||||
icon="el-icon-setting"
|
||||
plain
|
||||
class="none-border"
|
||||
@click.stop="handleModel(row)"
|
||||
>模型配置
|
||||
</el-button>
|
||||
</template>
|
||||
<template #modelTable="{ row }">
|
||||
<el-tag>{{ row.modelTable }}</el-tag>
|
||||
</template>
|
||||
</avue-crud>
|
||||
<el-dialog title="数据库模型配置" v-model="modelBox" :fullscreen="true" append-to-body>
|
||||
<avue-crud
|
||||
ref="crudModel"
|
||||
:option="optionModel"
|
||||
:table-loading="loading"
|
||||
:data="fields"
|
||||
></avue-crud>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button type="danger" @click="modelBox = false">关 闭</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">提 交</el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</basic-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
getList,
|
||||
getDetail,
|
||||
add,
|
||||
update,
|
||||
remove,
|
||||
getTableList,
|
||||
getTableInfoByName,
|
||||
getModelPrototype,
|
||||
submitModelPrototype,
|
||||
} from '@/api/tool/model';
|
||||
import { entityDic, option, optionModel } from '@/const/tool/model';
|
||||
import { validatenull } from '@/utils/validate';
|
||||
import { mapGetters } from 'vuex';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
form: {},
|
||||
query: {},
|
||||
loading: true,
|
||||
loadingOption: {
|
||||
lock: true,
|
||||
text: '物理表读取中',
|
||||
background: 'rgba(0, 0, 0, 0.7)',
|
||||
},
|
||||
fullscreenLoading: false,
|
||||
page: {
|
||||
pageSize: 10,
|
||||
currentPage: 1,
|
||||
total: 0,
|
||||
},
|
||||
selectionList: [],
|
||||
modelBox: false,
|
||||
modelId: 0,
|
||||
datasourceId: 1,
|
||||
tableInfo: {},
|
||||
active: 0,
|
||||
stepStart: 0,
|
||||
stepEnd: 4,
|
||||
data: [],
|
||||
option: option,
|
||||
optionModel: optionModel,
|
||||
formStep: {},
|
||||
fields: [],
|
||||
selectionModelList: [],
|
||||
// 默认不需要显示的字段名
|
||||
hideFields: [
|
||||
'id',
|
||||
'tenant_id',
|
||||
'create_user',
|
||||
'create_dept',
|
||||
'create_time',
|
||||
'update_user',
|
||||
'update_time',
|
||||
'status',
|
||||
'is_deleted',
|
||||
],
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
'form.datasourceId'() {
|
||||
if (!validatenull(this.form.datasourceId)) {
|
||||
const fullLoading = this.$loading(this.loadingOption);
|
||||
getTableList(this.form.datasourceId)
|
||||
.then(res => {
|
||||
const column = this.findColumn(this.option.column, 'modelTable');
|
||||
column.dicData = res.data.data;
|
||||
fullLoading.close();
|
||||
})
|
||||
.catch(() => {
|
||||
fullLoading.close();
|
||||
});
|
||||
}
|
||||
},
|
||||
'form.modelTable'() {
|
||||
if (!validatenull(this.form.modelTable)) {
|
||||
const fullLoading = this.$loading(this.loadingOption);
|
||||
getTableInfoByName(this.form.modelTable, this.form.datasourceId)
|
||||
.then(res => {
|
||||
const result = res.data;
|
||||
if (result.success) {
|
||||
const { comment, entityName } = result.data;
|
||||
//if (validatenull(this.form.modelClass)) {
|
||||
this.form.modelClass = entityName;
|
||||
//}
|
||||
//if (validatenull(this.form.modelName)) {
|
||||
this.form.modelName = comment;
|
||||
//}
|
||||
//if (validatenull(this.form.modelCode)) {
|
||||
this.form.modelCode = entityName.replace(/^\S/, s => s.toLowerCase());
|
||||
//}
|
||||
fullLoading.close();
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
fullLoading.close();
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['permission']),
|
||||
permissionList() {
|
||||
return {
|
||||
addBtn: true,
|
||||
delBtn: true,
|
||||
editBtn: true,
|
||||
viewBtn: false,
|
||||
};
|
||||
},
|
||||
ids() {
|
||||
let ids = [];
|
||||
this.selectionList.forEach(ele => {
|
||||
ids.push(ele.id);
|
||||
});
|
||||
return ids.join(',');
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
rowSave(row, done, loading) {
|
||||
add(row).then(
|
||||
res => {
|
||||
done();
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
this.$confirm('是否进行模型配置?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
}).then(() => {
|
||||
let model = {
|
||||
id: res.data.data.id,
|
||||
datasourceId: res.data.data.datasourceId,
|
||||
};
|
||||
this.handleModel(model);
|
||||
});
|
||||
},
|
||||
error => {
|
||||
loading();
|
||||
window.console.log(error);
|
||||
}
|
||||
);
|
||||
},
|
||||
rowUpdate(row, index, done, loading) {
|
||||
update(row).then(
|
||||
() => {
|
||||
done();
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
},
|
||||
error => {
|
||||
loading();
|
||||
window.console.log(error);
|
||||
}
|
||||
);
|
||||
},
|
||||
rowDel(row) {
|
||||
this.$confirm('确定将选择数据删除?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
return remove(row.id);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
});
|
||||
},
|
||||
handleDelete() {
|
||||
if (this.selectionList.length === 0) {
|
||||
this.$message.warning('请选择至少一条数据');
|
||||
return;
|
||||
}
|
||||
this.$confirm('确定将选择数据删除?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
return remove(this.ids);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: '操作成功!',
|
||||
});
|
||||
this.$refs.crud.toggleSelection();
|
||||
});
|
||||
},
|
||||
beforeOpen(done, type) {
|
||||
if (['edit', 'view'].includes(type)) {
|
||||
getDetail(this.form.id).then(res => {
|
||||
this.form = res.data.data;
|
||||
});
|
||||
}
|
||||
done();
|
||||
},
|
||||
searchReset() {
|
||||
this.query = {};
|
||||
this.onLoad(this.page);
|
||||
},
|
||||
searchChange(params, done) {
|
||||
this.query = params;
|
||||
this.onLoad(this.page, params);
|
||||
done();
|
||||
},
|
||||
selectionChange(list) {
|
||||
this.selectionList = list;
|
||||
},
|
||||
selectionModelChange(list) {
|
||||
this.selectionModelList = list;
|
||||
},
|
||||
selectionClear() {
|
||||
this.selectionList = [];
|
||||
this.$refs.crud.toggleSelection();
|
||||
},
|
||||
currentChange(currentPage) {
|
||||
this.page.currentPage = currentPage;
|
||||
},
|
||||
sizeChange(pageSize) {
|
||||
this.page.pageSize = pageSize;
|
||||
},
|
||||
onLoad(page, params = {}) {
|
||||
this.loading = true;
|
||||
getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
|
||||
const data = res.data.data;
|
||||
this.page.total = data.total;
|
||||
this.data = data.records;
|
||||
this.loading = false;
|
||||
this.selectionClear();
|
||||
});
|
||||
},
|
||||
handleModel(row) {
|
||||
this.fields = [];
|
||||
this.modelBox = true;
|
||||
this.loading = true;
|
||||
this.modelId = row.id;
|
||||
this.datasourceId = row.datasourceId;
|
||||
getModelPrototype(this.modelId, this.datasourceId).then(res => {
|
||||
const result = res.data;
|
||||
if (result.success) {
|
||||
this.fields = result.data;
|
||||
this.fields.forEach(item => {
|
||||
item.$cellEdit = true;
|
||||
item.modelId = this.modelId;
|
||||
// 根据字段物理类型自动适配实体类型
|
||||
if (!validatenull(item.name)) {
|
||||
item.jdbcName = item.name;
|
||||
item.jdbcType = item.propertyType;
|
||||
item.jdbcComment = item.comment;
|
||||
if (item.propertyType === 'LocalDateTime') {
|
||||
item.propertyType = 'Date';
|
||||
item.propertyEntity = 'java.util.Date';
|
||||
} else {
|
||||
entityDic.forEach(d => {
|
||||
if (d.label === item.propertyType) {
|
||||
item.propertyType = d.label;
|
||||
item.propertyEntity = d.value;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// 首次加载配置默认值
|
||||
if (validatenull(item.id)) {
|
||||
item.isList = 1;
|
||||
item.isForm = 1;
|
||||
item.isRow = 0;
|
||||
item.isRequired = 0;
|
||||
item.isQuery = 0;
|
||||
item.componentType = 'input';
|
||||
// 默认不需要显示的字段名配置
|
||||
if (this.hideFields.includes(item.jdbcName)) {
|
||||
item.isList = 0;
|
||||
item.isForm = 0;
|
||||
item.isRequired = 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
handleSubmit() {
|
||||
console.log(this.fields);
|
||||
this.$confirm('确定提交模型配置?', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
}).then(() => {
|
||||
this.fields.forEach(item => {
|
||||
entityDic.forEach(d => {
|
||||
if (d.value === item.propertyEntity) {
|
||||
item.propertyType = d.label;
|
||||
}
|
||||
});
|
||||
});
|
||||
submitModelPrototype(this.fields).then(res => {
|
||||
const result = res.data;
|
||||
if (result.success) {
|
||||
this.$message.success(result.msg);
|
||||
this.modelBox = false;
|
||||
} else {
|
||||
this.$message.error(result.msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
.none-border {
|
||||
border: 0;
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
.step-div {
|
||||
margin-top: 30px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user