mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-30 22:40:48 +00:00
feat: 代码生成
This commit is contained in:
parent
7201cca0d9
commit
624102b3be
@ -1115,9 +1115,9 @@ export function langCodeTranslate(data) {
|
||||
/**
|
||||
* @description 代码生成
|
||||
*/
|
||||
export function codeCurd(data) {
|
||||
export function codeCrud(data) {
|
||||
return request({
|
||||
url: `curd`,
|
||||
url: `system/crud`,
|
||||
method: 'post',
|
||||
data,
|
||||
});
|
||||
|
||||
@ -29,7 +29,7 @@ export function crudColumnType() {
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @description 代码生成 - 第一步提交 获取CRUD文件存放
|
||||
* @description 代码生成 - 第一步提交
|
||||
*/
|
||||
export function crudFilePath(data) {
|
||||
return request({
|
||||
@ -40,44 +40,21 @@ export function crudFilePath(data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 管理员添加表单
|
||||
* @description 代码生成 - 列表
|
||||
*/
|
||||
export function adminFromApi() {
|
||||
export function crudList(data) {
|
||||
return request({
|
||||
url: '/setting/admin/create',
|
||||
url: '/system/crud',
|
||||
method: 'get',
|
||||
params: data,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @description 代码生成 - 列表查看文件
|
||||
*/
|
||||
export function crudDet(id) {
|
||||
return request({
|
||||
url: `/system/crud/${id}`,
|
||||
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',
|
||||
});
|
||||
}
|
||||
|
||||
@ -2,26 +2,49 @@
|
||||
<div class="main">
|
||||
<div class="mb20">
|
||||
<Button class="mr10" type="primary" @click="addRow">添加列</Button>
|
||||
<Button>添加</Button>
|
||||
</div>
|
||||
<Table border :columns="columns" :data="dataList">
|
||||
<!-- <template slot-scope="{ row }" slot="id">
|
||||
<Input v-model="row.id" class="priceBox"></Input>
|
||||
<!-- <Table border :columns="columns" :data="dataList">
|
||||
<template slot-scope="{ row }" slot="action">
|
||||
<a>删除</a>
|
||||
<Divider type="vertical" />
|
||||
<a>修改</a>
|
||||
</template>
|
||||
<template slot-scope="{ row }" slot="field">
|
||||
<Input v-model="row.field" class="priceBox"></Input>
|
||||
</template> -->
|
||||
</Table>
|
||||
<Modal v-model="modal" width="360" title="新增列">
|
||||
</Table> -->
|
||||
<div class="fied-table">
|
||||
<div class="fied-item" v-for="(item, index) in dataList" :key="index">
|
||||
<div v-if="item.slot" class="set-up">
|
||||
<div class="name">{{ item.name }}</div>
|
||||
<div class="field">{{ item.field }}</div>
|
||||
</div>
|
||||
<div v-else class="fied-parameter">
|
||||
<Icon class="close" size="14" type="md-close-circle" @click="delItem(index)" />
|
||||
<div class="name">
|
||||
<Input class="from-width" v-model="item.name"></Input>
|
||||
</div>
|
||||
<div class="field">
|
||||
<Select v-if="item.field !== 'id'" class="from-width" v-model="item.field" transfer>
|
||||
<Option v-for="item in rowList" :value="item.value" :label="item.label" :key="item.value">{{
|
||||
item.label
|
||||
}}</Option>
|
||||
</Select>
|
||||
<span v-else>{{ item.field }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <Modal v-model="modal" width="360" title="新增列">
|
||||
<div>
|
||||
<Select v-model="rowName">
|
||||
<Option v-for="item in rowList" :value="item.value" :key="item.value">{{ item.label }}</Option>
|
||||
<Select v-model="rowName" @on-change="changeRow" :label-in-value="true">
|
||||
<Option v-for="item in rowList" :value="item.value" :label="item.label" :key="item.value">{{
|
||||
item.label
|
||||
}}</Option>
|
||||
</Select>
|
||||
<Input class="mt10" v-model="comment"></Input>
|
||||
</div>
|
||||
<template #footer>
|
||||
<Button type="primary" size="large" long @click="add">添加</Button>
|
||||
</template>
|
||||
</Modal>
|
||||
</Modal> -->
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -35,37 +58,17 @@ export default {
|
||||
return {};
|
||||
},
|
||||
},
|
||||
rowList: {
|
||||
type: Array,
|
||||
default: () => {
|
||||
return [];
|
||||
},
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
modal: false,
|
||||
rowName: '',
|
||||
rowList: [
|
||||
{
|
||||
value: 'New York',
|
||||
label: 'New York',
|
||||
},
|
||||
{
|
||||
value: 'London',
|
||||
label: 'London',
|
||||
},
|
||||
{
|
||||
value: 'Sydney',
|
||||
label: 'Sydney',
|
||||
},
|
||||
{
|
||||
value: 'Ottawa',
|
||||
label: 'Ottawa',
|
||||
},
|
||||
{
|
||||
value: 'Paris',
|
||||
label: 'Paris',
|
||||
},
|
||||
{
|
||||
value: 'Canberra',
|
||||
label: 'Canberra',
|
||||
},
|
||||
],
|
||||
columns: [
|
||||
{
|
||||
title: 'id',
|
||||
@ -74,46 +77,119 @@ export default {
|
||||
width: 110,
|
||||
},
|
||||
{
|
||||
title: 'field',
|
||||
key: 'field',
|
||||
title: '操作',
|
||||
slot: 'action',
|
||||
align: 'center',
|
||||
minWidth: 110,
|
||||
width: 110,
|
||||
},
|
||||
],
|
||||
dataList: [
|
||||
{
|
||||
id: '字段id',
|
||||
field: '字段field',
|
||||
name: 'id',
|
||||
field: 'id',
|
||||
},
|
||||
{
|
||||
name: '操作',
|
||||
field: '删除',
|
||||
slot: true,
|
||||
},
|
||||
],
|
||||
comment: '',
|
||||
rowData: {},
|
||||
};
|
||||
},
|
||||
created() {},
|
||||
mounted() {},
|
||||
methods: {
|
||||
addRow() {
|
||||
this.modal = true;
|
||||
},
|
||||
add() {
|
||||
this.dataList[0][this.rowName] = '字段';
|
||||
this.$nextTick((e) => {
|
||||
this.columns.push({
|
||||
title: this.rowName,
|
||||
key: this.rowName,
|
||||
align: 'center',
|
||||
minWidth: 110,
|
||||
});
|
||||
if (this.dataList.length >= 10) return this.$Message.warning('最多添加10个');
|
||||
let i = this.dataList.length - 1;
|
||||
// this.modal = true;
|
||||
this.dataList.splice(i, 0, {
|
||||
name: '',
|
||||
field: '',
|
||||
});
|
||||
},
|
||||
changeRow(e) {
|
||||
this.rowData = e;
|
||||
this.rowList.map((i) => {
|
||||
if (i.value === e.value) this.rowData.comment = i.comment;
|
||||
});
|
||||
},
|
||||
// add() {
|
||||
// let i = this.dataList.length - 1;
|
||||
// console.log(i);
|
||||
// this.$nextTick((e) => {
|
||||
// this.dataList.splice(i, 0, {
|
||||
// name: this.rowData.label,
|
||||
// field: this.rowData.value,
|
||||
// });
|
||||
// this.comment = '';
|
||||
// });
|
||||
// },
|
||||
delItem(i) {
|
||||
this.dataList.splice(i, 1);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="stylus" scoped>
|
||||
<style lang="scss" scoped>
|
||||
.ivu-table-wrapper {
|
||||
border-top: 1px solid #dcdee2;;
|
||||
border-left: 1px solid #dcdee2;;
|
||||
border-top: 1px solid #dcdee2;
|
||||
border-left: 1px solid #dcdee2;
|
||||
}
|
||||
.form-width {
|
||||
width: 500px;
|
||||
}
|
||||
.fied-table {
|
||||
display: flex;
|
||||
border: 1px solid #dcdee2;
|
||||
width: max-content;
|
||||
.set-up {
|
||||
width: 80px;
|
||||
.name {
|
||||
line-height: 32px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.fied-parameter {
|
||||
position: relative;
|
||||
.close {
|
||||
position: absolute;
|
||||
top: -6px;
|
||||
right: -6px;
|
||||
z-index: 11;
|
||||
}
|
||||
}
|
||||
|
||||
.fied-parameter,
|
||||
.set-up {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
// border-radius: 6px;
|
||||
font-size: 14px;
|
||||
border: 1px solid #dcdee2;
|
||||
height: 108px;
|
||||
.name {
|
||||
width: 100%;
|
||||
height: 52px;
|
||||
text-align: center;
|
||||
padding: 10px 10px;
|
||||
background-color: #f8f8f9;
|
||||
}
|
||||
.field {
|
||||
width: 100%;
|
||||
line-height: 31px;
|
||||
height: 54px;
|
||||
|
||||
text-align: center;
|
||||
border-top: 2px solid #dcdee2;
|
||||
padding: 10px 10px;
|
||||
}
|
||||
.from-width {
|
||||
width: 90px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<div>
|
||||
<div class="item" v-for="(item, index) in dataList" :key="index">
|
||||
<div class="row">
|
||||
<Select v-model="item.rowName" transfer>
|
||||
<Select v-model="item.name" transfer>
|
||||
<Option v-for="item in rowList" :value="item.value" :key="item.value">{{ item.label }}</Option>
|
||||
</Select>
|
||||
</div>
|
||||
@ -14,7 +14,7 @@
|
||||
<Input v-model="item.field" class="priceBox"></Input>
|
||||
</div>
|
||||
<div class="row">
|
||||
<Select v-model="item.method" transfer>
|
||||
<Select v-model="item.type" transfer>
|
||||
<Option v-for="item in reqMetList" :value="item.value" :key="item.value">{{ item.label }}</Option>
|
||||
</Select>
|
||||
</div>
|
||||
@ -23,7 +23,7 @@
|
||||
<Option v-for="item in requiredList" :value="item.value" :key="item.value">{{ item.label }}</Option>
|
||||
</Select>
|
||||
</div>
|
||||
<div class="row" v-if="item.method == 2">
|
||||
<div class="row" v-if="item.type == 2">
|
||||
<Input v-model="item.textarea" class="priceBox"></Input>
|
||||
</div>
|
||||
</div>
|
||||
@ -41,6 +41,12 @@ export default {
|
||||
return {};
|
||||
},
|
||||
},
|
||||
rowList: {
|
||||
type: Array,
|
||||
default: () => {
|
||||
return [];
|
||||
},
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@ -54,7 +60,6 @@ export default {
|
||||
label: '是',
|
||||
},
|
||||
],
|
||||
rowList: [],
|
||||
reqMetList: [
|
||||
{
|
||||
value: 0,
|
||||
@ -77,15 +82,7 @@ export default {
|
||||
label: 'number',
|
||||
},
|
||||
],
|
||||
dataList: [
|
||||
{
|
||||
rowName: 0,
|
||||
method: 0,
|
||||
field: '',
|
||||
required: 0,
|
||||
textarea: '',
|
||||
},
|
||||
],
|
||||
dataList: [],
|
||||
};
|
||||
},
|
||||
created() {},
|
||||
@ -93,8 +90,8 @@ export default {
|
||||
methods: {
|
||||
addRow() {
|
||||
this.dataList.push({
|
||||
rowName: 0,
|
||||
method: 0,
|
||||
name: '',
|
||||
type: '',
|
||||
field: '',
|
||||
required: 0,
|
||||
textarea: '',
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
<Radio :label="1">是</Radio>
|
||||
</RadioGroup>
|
||||
</FormItem>
|
||||
<FormItem label="表SQL">
|
||||
<FormItem label="表SQL" v-if="!foundation.isTable">
|
||||
<div>
|
||||
<div class="item" v-for="(item, index) in dataList" :key="index">
|
||||
<div class="row">
|
||||
@ -42,6 +42,12 @@
|
||||
<div class="row">
|
||||
<Input v-model="item.limit" type="number" class="priceBox" placeholder="长度"></Input>
|
||||
</div>
|
||||
<div class="row">
|
||||
<Select v-model="item.index" transfer placeholder="是否为索引">
|
||||
<Option :value="0">否</Option>
|
||||
<Option :value="1">是</Option>
|
||||
</Select>
|
||||
</div>
|
||||
<div class="row">
|
||||
<Input v-model="item.comment" class="priceBox" placeholder="备注"></Input>
|
||||
</div>
|
||||
@ -1,17 +1,32 @@
|
||||
<template>
|
||||
<div class="main">
|
||||
<Form ref="foundation" :model="storage" :rules="storageRules" :label-width="130">
|
||||
<FormItem label="生成api位置">
|
||||
<Input class="form-width" v-model="storage.api" placeholder="请输入"></Input>
|
||||
</FormItem>
|
||||
<FormItem label="生成controller位置">
|
||||
<Input class="form-width" v-model="storage.input" placeholder="请输入"></Input>
|
||||
<Input class="form-width" v-model="storage.controller" placeholder="请输入"></Input>
|
||||
</FormItem>
|
||||
<FormItem label="生成service位置">
|
||||
<Input class="form-width" v-model="storage.input" placeholder="请输入"></Input>
|
||||
<Input class="form-width" v-model="storage.service" placeholder="请输入"></Input>
|
||||
</FormItem>
|
||||
<FormItem label="生成dao位置">
|
||||
<Input class="form-width" v-model="storage.input" placeholder="请输入"></Input>
|
||||
<Input class="form-width" v-model="storage.dao" placeholder="请输入"></Input>
|
||||
</FormItem>
|
||||
<FormItem label="生成model位置">
|
||||
<Input class="form-width" v-model="storage.input" placeholder="请输入"></Input>
|
||||
<Input class="form-width" v-model="storage.model" placeholder="请输入"></Input>
|
||||
</FormItem>
|
||||
<FormItem label="生成pages位置">
|
||||
<Input class="form-width" v-model="storage.pages" placeholder="请输入"></Input>
|
||||
</FormItem>
|
||||
<FormItem label="生成route位置">
|
||||
<Input class="form-width" v-model="storage.route" placeholder="请输入"></Input>
|
||||
</FormItem>
|
||||
<FormItem label="生成router位置">
|
||||
<Input class="form-width" v-model="storage.router" placeholder="请输入"></Input>
|
||||
</FormItem>
|
||||
<FormItem label="生成validate位置">
|
||||
<Input class="form-width" v-model="storage.validate" placeholder="请输入"></Input>
|
||||
</FormItem>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
@ -19,25 +19,25 @@
|
||||
</div>
|
||||
<div class="pt10" v-show="currentTab == '2'">
|
||||
<Card :bordered="false" dis-hover class="ivu-mt">
|
||||
<Field :field="formItem.field" />
|
||||
<Field ref="Field" :field="formItem.field" :rowList="rowList" />
|
||||
</Card>
|
||||
</div>
|
||||
<div class="pt10" v-show="currentTab == '3'">
|
||||
<Card :bordered="false" dis-hover class="ivu-mt">
|
||||
<FormItem :formItem="formItem.formItem" />
|
||||
<FormItem ref="FormItem" :formItem="formItem.formItem" :rowList="rowList" />
|
||||
</Card>
|
||||
</div>
|
||||
<Card :bordered="false" dis-hover class="mt10">
|
||||
<Card :bordered="false" dis-hover class="mt10 btn">
|
||||
<Button class="mr20" type="primary" @click="beforeTab">上一步</Button>
|
||||
<Button type="primary" @click="nextTab">下一步</Button>
|
||||
<Button type="primary" @click="nextTab">{{ currentTab == 3 ? '提交' : '下一步' }}</Button>
|
||||
</Card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { codeCurd } from '@/api/setting';
|
||||
import FoundationForm from './components/FoundationForm.vue';
|
||||
import { codeCrud } from '@/api/setting';
|
||||
import StorageLoc from './components/StorageLoc.vue';
|
||||
import FoundationForm from './components/FoundationFor.vue';
|
||||
import Field from './components/Field.vue';
|
||||
import FormItem from './components/FormItem.vue';
|
||||
import { crudFilePath } from '@/api/systemCodeGeneration';
|
||||
@ -71,10 +71,12 @@ export default {
|
||||
{
|
||||
type: '',
|
||||
limit: 0,
|
||||
default: '',
|
||||
comment: '',
|
||||
field: '',
|
||||
index: 0,
|
||||
},
|
||||
],
|
||||
rowList: [],
|
||||
};
|
||||
},
|
||||
created() {},
|
||||
@ -86,6 +88,7 @@ export default {
|
||||
limit: 0,
|
||||
default: '',
|
||||
field: '',
|
||||
index: 0,
|
||||
});
|
||||
},
|
||||
beforeTab() {
|
||||
@ -93,7 +96,17 @@ export default {
|
||||
},
|
||||
nextTab() {
|
||||
if (this.currentTab == 0) {
|
||||
console.log(this.formItem);
|
||||
if (!this.formItem.foundation.tableName) {
|
||||
return this.$Message.warning('请输入表名');
|
||||
}
|
||||
if (!this.formItem.foundation.isTable) {
|
||||
for (let i = 0; i < this.dataList.length; i++) {
|
||||
const e = this.dataList[i];
|
||||
if (!e.type || !e.field || !e.comment) {
|
||||
return this.$Message.warning('请完善sql数据');
|
||||
}
|
||||
}
|
||||
}
|
||||
let data = {
|
||||
menuName: this.formItem.foundation.menuName,
|
||||
tableName: this.formItem.foundation.tableName,
|
||||
@ -101,13 +114,71 @@ export default {
|
||||
fromField: [],
|
||||
columnField: [],
|
||||
};
|
||||
crudFilePath(data).then((res) => {
|
||||
console.log(res);
|
||||
});
|
||||
crudFilePath(data)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
this.formItem.storage = res.data.makePath;
|
||||
if (!this.formItem.foundation.isTable) {
|
||||
this.rowList = [];
|
||||
this.dataList.map((e) => {
|
||||
this.rowList.push({
|
||||
label: e.comment,
|
||||
value: e.field,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.rowList = res.data.tableField;
|
||||
}
|
||||
this.currentTab++;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.$Message.error(err.msg);
|
||||
});
|
||||
} else if (this.currentTab == 2) {
|
||||
for (let i = 0; i < this.$refs.Field.dataList.length; i++) {
|
||||
const e = this.$refs.Field.dataList[i];
|
||||
if (!e.name || !e.field) {
|
||||
return this.$Message.warning('请完善表数据');
|
||||
}
|
||||
}
|
||||
this.currentTab++;
|
||||
} else if (this.currentTab == 3) {
|
||||
try {
|
||||
for (let i = 0; i < this.$refs.FormItem.dataList.length; i++) {
|
||||
const e = this.$refs.FormItem.dataList[i];
|
||||
if (!e.name || !e.type || !e.field || !e.required) {
|
||||
return this.$Message.warning('请完善数据');
|
||||
}
|
||||
}
|
||||
let data = {
|
||||
...this.formItem.foundation,
|
||||
filePath: this.formItem.storage,
|
||||
tableField: this.dataList,
|
||||
columnField: this.$refs.Field.dataList,
|
||||
fromField: this.$refs.FormItem.dataList,
|
||||
};
|
||||
console.log(data);
|
||||
codeCrud(data)
|
||||
.then((res) => {
|
||||
this.$Message.success(res.msg);
|
||||
})
|
||||
.catch((err) => {
|
||||
this.$Message.error(err.msg);
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
} else {
|
||||
if (this.currentTab < 3) this.currentTab++;
|
||||
}
|
||||
this.currentTab++;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped></style>
|
||||
<style lang="scss" scoped>
|
||||
.btn {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
476
template/admin/src/pages/system/codeGeneration/list.vue
Normal file
476
template/admin/src/pages/system/codeGeneration/list.vue
Normal file
@ -0,0 +1,476 @@
|
||||
<template>
|
||||
<div>
|
||||
<Card :bordered="false" dis-hover class="ivu-mt">
|
||||
<Button type="primary" @click="groupAdd()" class="mr20">代码生成</Button>
|
||||
<Table
|
||||
:columns="columns1"
|
||||
:data="tabList"
|
||||
ref="table"
|
||||
class="mt25"
|
||||
:loading="loading"
|
||||
highlight-row
|
||||
no-userFrom-text="暂无数据"
|
||||
no-filtered-userFrom-text="暂无筛选结果"
|
||||
>
|
||||
<template slot-scope="{ row, index }" slot="statuss">
|
||||
<i-switch
|
||||
v-model="row.status"
|
||||
:value="row.status"
|
||||
:true-value="1"
|
||||
:false-value="0"
|
||||
@on-change="onchangeIsShow(row)"
|
||||
size="large"
|
||||
>
|
||||
<span slot="open">显示</span>
|
||||
<span slot="close">隐藏</span>
|
||||
</i-switch>
|
||||
</template>
|
||||
<template slot-scope="{ row, index }" slot="action">
|
||||
<a @click="edit(row, '编辑')">查看</a>
|
||||
<Divider type="vertical" />
|
||||
<a @click="del(row, '删除', index)">删除</a>
|
||||
</template>
|
||||
</Table>
|
||||
<div class="acea-row row-right page">
|
||||
<Page
|
||||
:total="total"
|
||||
:current="formValidate.page"
|
||||
show-elevator
|
||||
show-total
|
||||
@on-change="pageChange"
|
||||
:page-size="formValidate.limit"
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
<Modal
|
||||
:class-name="className"
|
||||
v-model="modals"
|
||||
scrollable
|
||||
footer-hide
|
||||
closable
|
||||
:mask-closable="false"
|
||||
width="80%"
|
||||
:before-close="editModalChange"
|
||||
>
|
||||
<p slot="header" class="diy-header" ref="diyHeader">
|
||||
<span>{{ title }}</span>
|
||||
</p>
|
||||
<div style="height: 100%">
|
||||
<div class="file-box">
|
||||
<div class="file-fix"></div>
|
||||
<div class="file-content">
|
||||
<Tabs
|
||||
type="card"
|
||||
v-model="indexEditor"
|
||||
style="height: 100%"
|
||||
@on-click="toggleEditor"
|
||||
:animated="false"
|
||||
closable
|
||||
@on-tab-remove="handleTabRemove"
|
||||
>
|
||||
<TabPane
|
||||
v-for="value in editorIndex"
|
||||
:key="value.index"
|
||||
:name="value.index.toString()"
|
||||
:label="value.title"
|
||||
:icon="value.icon"
|
||||
v-if="value.tab"
|
||||
>
|
||||
<div ref="container" :id="'container_' + value.index" style="height: 100%; min-height: 560px"></div>
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
</div>
|
||||
<Spin size="large" fix v-if="spinShow"></Spin>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapState } from 'vuex';
|
||||
import { crudList, crudDet } from '@/api/systemCodeGeneration';
|
||||
import * as monaco from 'monaco-editor';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
grid: {
|
||||
xl: 7,
|
||||
lg: 7,
|
||||
md: 12,
|
||||
sm: 24,
|
||||
xs: 24,
|
||||
},
|
||||
formValidate: {
|
||||
page: 1,
|
||||
limit: 20,
|
||||
title: '',
|
||||
},
|
||||
loading: false,
|
||||
tabList: [],
|
||||
total: 0,
|
||||
columns1: [
|
||||
{
|
||||
title: 'ID',
|
||||
key: 'id',
|
||||
width: 80,
|
||||
},
|
||||
{
|
||||
title: '菜单名',
|
||||
key: 'name',
|
||||
minWidth: 130,
|
||||
},
|
||||
{
|
||||
title: '表名',
|
||||
key: 'table_name',
|
||||
minWidth: 130,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
slot: 'action',
|
||||
fixed: 'right',
|
||||
minWidth: 150,
|
||||
},
|
||||
],
|
||||
FromData: null,
|
||||
titleFrom: '',
|
||||
groupId: 0,
|
||||
addId: '',
|
||||
editorList: [], //编辑器数组
|
||||
indexEditor: 0, //当前编辑器索引
|
||||
code: '', //当前文件打开时的内容
|
||||
contextData: null, //左侧导航右键点击是产生的数据对象
|
||||
|
||||
fileType: '', // 文件操作类型 createFolder|创建文件夹 createFile|创建文件 delFolder|删除文件夹或者文件
|
||||
className: '', //全屏 class名
|
||||
spinShow: false,
|
||||
modals: false, //编辑器开关
|
||||
editor: '', //当前编辑器对象
|
||||
editorIndex: [],
|
||||
title: '',
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapState('media', ['isMobile']),
|
||||
labelWidth() {
|
||||
return this.isMobile ? undefined : 75;
|
||||
},
|
||||
labelPosition() {
|
||||
return this.isMobile ? 'top' : 'right';
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.getList();
|
||||
},
|
||||
methods: {
|
||||
// 跳转到组合数据列表页面
|
||||
goList(row) {
|
||||
this.$router.push({
|
||||
path: this.$routeProStr + '/system/config/system_group/list/' + row.id,
|
||||
});
|
||||
},
|
||||
// 列表
|
||||
getList() {
|
||||
this.loading = true;
|
||||
crudList(this.formValidate)
|
||||
.then(async (res) => {
|
||||
let data = res.data;
|
||||
this.tabList = data.list;
|
||||
this.total = data.count;
|
||||
this.loading = false;
|
||||
})
|
||||
.catch((res) => {
|
||||
this.loading = false;
|
||||
this.$Message.error(res.msg);
|
||||
});
|
||||
},
|
||||
pageChange(index) {
|
||||
this.formValidate.page = index;
|
||||
this.getList();
|
||||
},
|
||||
// 表格搜索
|
||||
userSearchs() {
|
||||
this.formValidate.page = 1;
|
||||
this.getList();
|
||||
},
|
||||
// 点击添加
|
||||
groupAdd() {
|
||||
this.$router.push({
|
||||
name: 'system_code_generation',
|
||||
});
|
||||
},
|
||||
// 删除
|
||||
del(row, tit, num) {
|
||||
let delfromData = {
|
||||
title: tit,
|
||||
num: num,
|
||||
url: `system/crud/${row.id}`,
|
||||
method: 'DELETE',
|
||||
ids: '',
|
||||
};
|
||||
this.$modalSure(delfromData)
|
||||
.then((res) => {
|
||||
this.$Message.success(res.msg);
|
||||
this.tabList.splice(num, 1);
|
||||
this.getList();
|
||||
})
|
||||
.catch((res) => {
|
||||
this.$Message.error(res.msg);
|
||||
});
|
||||
},
|
||||
// 编辑
|
||||
edit(row) {
|
||||
console.log(row);
|
||||
this.spinShow = true;
|
||||
// 创建代码容器
|
||||
this.title = row.name;
|
||||
this.$nextTick((e) => {
|
||||
this.openfile(row.id, false);
|
||||
});
|
||||
},
|
||||
//打开文件
|
||||
openfile(id) {
|
||||
try {
|
||||
console.log(id);
|
||||
let that = this;
|
||||
crudDet(id)
|
||||
.then(async (res) => {
|
||||
let data = res.data[0];
|
||||
res.data.map((i, index) => {
|
||||
let data = i;
|
||||
this.editorIndex.push({
|
||||
tab: true,
|
||||
index: index + '',
|
||||
title: data.name,
|
||||
pathname: data.path,
|
||||
});
|
||||
that.code = data.content;
|
||||
this.initEditor(index, data.content);
|
||||
this.$nextTick((e) => {
|
||||
// 保存相对信息
|
||||
that.editorList[index].path = data.path;
|
||||
that.editorList[index].oldCode = that.content;
|
||||
that.editorIndex[index].title = data.name;
|
||||
console.log('111');
|
||||
});
|
||||
});
|
||||
that.modals = true;
|
||||
that.spinShow = false;
|
||||
})
|
||||
.catch((res) => {
|
||||
that.catchFun(res);
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 窗口最大化
|
||||
*/
|
||||
winChanges() {
|
||||
if (this.className) {
|
||||
this.className = '';
|
||||
} else {
|
||||
this.className = 'diy-fullscreen';
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 初始化编辑器
|
||||
*/
|
||||
initEditor(index, conetnt) {
|
||||
try {
|
||||
let that = this;
|
||||
console.log('111');
|
||||
that.$nextTick(() => {
|
||||
// 初始化编辑器,确保dom已经渲染
|
||||
that.editor = monaco.editor.create(document.getElementById('container_' + index), {
|
||||
value: conetnt, //编辑器初始显示文字
|
||||
language: 'sql', //语言支持自行查阅demo
|
||||
automaticLayout: true, //自动布局
|
||||
theme: 'vs', //官方自带三种主题vs, hc-black, or vs-dark
|
||||
foldingStrategy: 'indentation', // 代码可分小段折叠
|
||||
overviewRulerBorder: false, // 不要滚动条的边框
|
||||
scrollbar: {
|
||||
// 滚动条设置
|
||||
verticalScrollbarSize: 4, // 竖滚动条
|
||||
horizontalScrollbarSize: 10, // 横滚动条
|
||||
},
|
||||
autoIndent: true, // 自动布局
|
||||
tabSize: 4, // tab缩进长度
|
||||
autoClosingOvertype: 'always',
|
||||
readOnly: true,
|
||||
});
|
||||
that.editorList.push({
|
||||
editor: that.editor,
|
||||
oldCode: that.code,
|
||||
path: '',
|
||||
index: index,
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 处理接口回调
|
||||
* @param {Object} res
|
||||
*/
|
||||
catchFun(res) {
|
||||
if (res.status) {
|
||||
if (res.status == 400) this.$Message.error(res.msg);
|
||||
if (res.status == 110008) {
|
||||
// this.$Message.error(res.msg);
|
||||
this.isShowLogn = true;
|
||||
this.isShowList = false;
|
||||
this.loading = false;
|
||||
}
|
||||
} else {
|
||||
// this.$Message.error('文件编码不被兼容,无法正确读取文件!');
|
||||
}
|
||||
//关闭蒙版层
|
||||
if (this.spinShow) this.spinShow = false;
|
||||
// 关闭文件列表展示
|
||||
if (this.loading) this.loading = false;
|
||||
},
|
||||
//编辑器状态变化
|
||||
editModalChange() {
|
||||
let that = this;
|
||||
that.editorList.forEach(function (value, index) {
|
||||
// 销毁当前编辑器
|
||||
that.editorList[index].editor.dispose();
|
||||
that.editorList[index].editor = null;
|
||||
});
|
||||
// 初始话数据
|
||||
that.modals = false; //编辑器开关
|
||||
that.editor = ''; //当前编辑器对象
|
||||
that.editorIndex = [
|
||||
//选项卡数组
|
||||
{
|
||||
tab: true,
|
||||
index: '0',
|
||||
title: '',
|
||||
icon: '',
|
||||
},
|
||||
];
|
||||
that.editorList = []; //编辑器数组
|
||||
that.indexEditor = '0'; //当前编辑器索引
|
||||
that.code = ''; //当前文件打开时的内容
|
||||
that.contextData = null; //左侧导航右键点击是产生的数据对象
|
||||
},
|
||||
/**
|
||||
* 切换选项卡
|
||||
* @param {Object} index
|
||||
*/
|
||||
toggleEditor(index) {
|
||||
index = Number(index);
|
||||
this.code = this.editorList[index].oldCode; //设置文件打开时的代码
|
||||
this.editor = this.editorList[index].editor; //设置编辑器实例
|
||||
},
|
||||
handleTabRemove(index) {
|
||||
let that = this;
|
||||
// 关闭选项卡
|
||||
that.editorIndex[index].tab = false; // 关闭选项卡
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
// 自定义方法缩小
|
||||
>>> .diy-fullscreen {
|
||||
overflow: hidden;
|
||||
|
||||
.ivu-modal {
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
right: 0px;
|
||||
bottom: 0px;
|
||||
height: 100%;
|
||||
width: 100% !important;
|
||||
|
||||
.ivu-modal-content {
|
||||
height: 100%;
|
||||
|
||||
.ivu-modal-body {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.ivu-tabs {
|
||||
.ivu-tabs-content-animated {
|
||||
height: 92%;
|
||||
background-color: #2f2f2f !important;
|
||||
}
|
||||
}
|
||||
|
||||
.ivu-tabs-content {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.ivu-tabs {
|
||||
.ivu-tabs-tabpane {
|
||||
height: 92%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.diy-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.diy-header-icon {
|
||||
margin-right: 30px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.diy-header-icon:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
>>> .ivu-modal {
|
||||
top: 70px;
|
||||
}
|
||||
|
||||
.ivu-modal-content {
|
||||
.ivu-modal-body {
|
||||
min-height: 632px;
|
||||
height: 80vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
.ivu-tabs {
|
||||
.ivu-tabs-content-animated {
|
||||
min-height: 560px;
|
||||
height: 73vh;
|
||||
margin-top: -1px;
|
||||
}
|
||||
|
||||
.ivu-tabs-tabpane {
|
||||
min-height: 560px;
|
||||
height: 73vh;
|
||||
margin-top: -1px;
|
||||
}
|
||||
}
|
||||
|
||||
.ivu-tabs-nav .ivu-tabs-tab .ivu-icon {
|
||||
color: #f00;
|
||||
}
|
||||
|
||||
>>> body .ivu-select-dropdown .ivu-dropdown-transfer {
|
||||
background: red !important;
|
||||
}
|
||||
|
||||
// 导航栏右键样式 无效
|
||||
.file-left /deep/ .ivu-select-dropdown.ivu-dropdown-transfer .ivu-dropdown-menu .ivu-dropdown-item:hover {
|
||||
background-color: #e5e5e5 !important;
|
||||
}
|
||||
|
||||
// 选项卡头部
|
||||
>>> .ivu-tabs.ivu-tabs-card > .ivu-tabs-bar .ivu-tabs-nav-container {
|
||||
background-color: #333;
|
||||
}
|
||||
</style>
|
||||
@ -35,6 +35,15 @@ export default {
|
||||
},
|
||||
component: () => import('@/pages/system/codeGeneration/index'),
|
||||
},
|
||||
{
|
||||
path: 'code_generation_list',
|
||||
name: `${pre}code_generation_list`,
|
||||
meta: {
|
||||
auth: ['system-config-code-generation-list'],
|
||||
title: '代码生成列表',
|
||||
},
|
||||
component: () => import('@/pages/system/codeGeneration/list'),
|
||||
},
|
||||
{
|
||||
path: 'backend_routing',
|
||||
name: `${pre}backend_routing`,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user