improve: 代码生成

This commit is contained in:
From-wh 2023-04-11 18:25:56 +08:00
parent a788ecb60d
commit 8d65925deb
4 changed files with 205 additions and 29 deletions

View File

@ -0,0 +1,83 @@
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import request from '@/libs/request';
/**
* @description 代码生成 - 菜单选择列表
*/
export function crudMenus() {
return request({
url: '/system/crud/menus',
method: 'get',
});
}
/**
* @description 代码生成 - sql表选择列表
*/
export function crudColumnType() {
return request({
url: '/system/crud/column_type',
method: 'get',
});
}
/**
* @description 代码生成 - 第一步提交 获取CRUD文件存放
*/
export function crudFilePath(data) {
return request({
url: '/system/crud/file_path',
method: 'post',
data,
});
}
/**
* @description 管理员添加表单
*/
export function adminFromApi() {
return request({
url: '/setting/admin/create',
method: 'get',
});
}
/**
* @description 管理员编辑表单
* @param {Number} param id {Number} 管理员id
*/
export function adminEditFromApi(id) {
return request({
url: `/setting/admin/${id}/edit`,
method: 'get',
});
}
/**
* @description 管理员删除
* @param {Number} param id {Number} 管理员id
*/
export function adminDelFromApi(id) {
return request({
url: `/setting/admin/${id}`,
method: 'DELETE',
});
}
/**
* @description 管理员 修改状态
* @param {Object} param data {Object} 传值
*/
export function setShowApi(data) {
return request({
url: `setting/set_status/${data.id}/${data.status}`,
method: 'PUT',
});
}

View File

@ -2,7 +2,6 @@
<div class="main">
<div class="mb20">
<Button class="mr10" type="primary" @click="addRow">添加行</Button>
<Button>添加</Button>
</div>
<div>
<div class="item" v-for="(item, index) in dataList" :key="index">

View File

@ -2,35 +2,60 @@
<div class="main">
<Form ref="foundation" :model="foundation" :rules="foundation" :label-width="100">
<FormItem label="菜单">
<Select class="form-width" v-model="foundation.pid">
<!-- <Select class="form-width" v-model="foundation.pid">
<Option value="beijing">New York</Option>
<Option value="shanghai">London</Option>
<Option value="shenzhen">Sydney</Option>
</Select>
</Select> -->
<el-cascader
class="form-width"
v-model="foundation.pid"
size="small"
:options="menusList"
:props="{ checkStrictly: true, multiple: false, emitPath: false }"
clearable
></el-cascader>
</FormItem>
<FormItem label="菜单名称">
<Input class="form-width" v-model="foundation.menuName" placeholder="请输入表名"></Input>
</FormItem>
<FormItem label="表名">
<Input class="form-width" v-model="foundation.tableName" placeholder="请输入表名"></Input>
</FormItem>
<FormItem label="是否存在">
<RadioGroup v-model="foundation.required">
<Radio :label="1">是</Radio>
<RadioGroup v-model="foundation.isTable">
<Radio :label="0">否</Radio>
<Radio :label="1">是</Radio>
</RadioGroup>
</FormItem>
<FormItem label="表SQL">
<Input
class="form-width"
v-model="foundation.sql"
type="textarea"
:autosize="{ minRows: 4, maxRows: 8 }"
placeholder="请输入表SQL"
></Input>
<div>
<div class="item" v-for="(item, index) in dataList" :key="index">
<div class="row">
<Select v-model="item.type" transfer>
<Option v-for="item in columnTypeList" :value="item" :key="item">{{ item }}</Option>
</Select>
</div>
<div class="row">
<Input v-model="item.field" class="priceBox" placeholder="字段名称(英文或_)"></Input>
</div>
<div class="row">
<Input v-model="item.limit" type="number" class="priceBox" placeholder="长度"></Input>
</div>
<div class="row">
<Input v-model="item.comment" class="priceBox" placeholder="备注"></Input>
</div>
</div>
</div>
<Button class="mr10" type="primary" @click="addRow">添加行</Button>
</FormItem>
</Form>
</div>
</template>
<script>
import { crudMenus, crudColumnType } from '@/api/systemCodeGeneration';
export default {
name: '',
props: {
@ -40,17 +65,49 @@ export default {
return {};
},
},
dataList: {
type: Array,
default: () => {
return [];
},
},
},
data() {
return {};
return {
menusList: [],
columnTypeList: [],
};
},
created() {
this.getCrudMenus();
},
created() {},
mounted() {},
methods: {},
methods: {
getCrudMenus() {
crudMenus().then((res) => {
console.log(res);
this.menusList = res.data;
});
crudColumnType().then((res) => {
this.columnTypeList = res.data.types;
});
},
addRow() {
this.$emit('addRow');
},
},
};
</script>
<style lang="stylus" scoped>
.form-width {
width: 500px;
}
.item{
display flex
margin-bottom 10px
.row{
width 140px
margin-right 10px
}
}
</style>

View File

@ -2,31 +2,35 @@
<div>
<div class="message">
<Card :bordered="false" dis-hover class="">
<Tabs v-model="currentTab" @on-click="changeTab">
<TabPane :label="item.label" :name="item.value.toString()" v-for="(item, index) in headerList" :key="index" />
</Tabs>
<Steps :current="currentTab">
<Step :title="item.label" v-for="(item, index) in headerList" :key="index"></Step>
</Steps>
</Card>
</div>
<div class="pt10" v-show="currentTab == 'foundation'">
<div class="pt10" v-show="currentTab == '0'">
<Card :bordered="false" dis-hover class="ivu-mt">
<FoundationForm :foundation="formItem.foundation" />
<FoundationForm :foundation="formItem.foundation" :dataList="dataList" @addRow="addRow" />
</Card>
</div>
<div class="pt10" v-show="currentTab == 'storage'">
<div class="pt10" v-show="currentTab == '1'">
<Card :bordered="false" dis-hover class="ivu-mt">
<StorageLoc :storage="formItem.storage" />
</Card>
</div>
<div class="pt10" v-show="currentTab == 'field'">
<div class="pt10" v-show="currentTab == '2'">
<Card :bordered="false" dis-hover class="ivu-mt">
<Field :field="formItem.field" />
</Card>
</div>
<div class="pt10" v-show="currentTab == 'formItem'">
<div class="pt10" v-show="currentTab == '3'">
<Card :bordered="false" dis-hover class="ivu-mt">
<FormItem :formItem="formItem.formItem" />
</Card>
</div>
<Card :bordered="false" dis-hover class="mt10">
<Button class="mr20" type="primary" @click="beforeTab">上一步</Button>
<Button type="primary" @click="nextTab">下一步</Button>
</Card>
</div>
</template>
@ -36,12 +40,13 @@ import FoundationForm from './components/FoundationForm.vue';
import StorageLoc from './components/StorageLoc.vue';
import Field from './components/Field.vue';
import FormItem from './components/FormItem.vue';
import { crudFilePath } from '@/api/systemCodeGeneration';
export default {
name: 'system_code_generation',
components: { FoundationForm, StorageLoc, Field, FormItem },
data() {
return {
currentTab: 'formItem',
currentTab: 0,
headerList: [
{ label: '基础信息', value: 'foundation' },
{ label: '存放位置', value: 'storage' },
@ -52,8 +57,8 @@ export default {
foundation: {
pid: '',
tableName: '',
required: 0,
sql: '',
isTable: 0,
menuName: '',
},
storage: {},
field: {},
@ -62,15 +67,47 @@ export default {
ruleValidate: {
foundation: {},
},
dataList: [
{
type: '',
limit: 0,
default: '',
field: '',
},
],
};
},
created() {},
mounted: function () {},
methods: {
changeTab(data) {
this.currentTab = data;
addRow() {
this.dataList.push({
type: '',
limit: 0,
default: '',
field: '',
});
},
beforeTab() {
this.currentTab--;
},
nextTab() {
if (this.currentTab == 0) {
console.log(this.formItem);
let data = {
menuName: this.formItem.foundation.menuName,
tableName: this.formItem.foundation.tableName,
isTable: this.formItem.foundation.isTable,
fromField: [],
columnField: '',
};
crudFilePath(data).then((res) => {
console.log(res);
});
}
this.currentTab++;
},
},
};
</script>
<style scoped></style>
<style lang="scss" scoped></style>