mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-31 06:50:51 +00:00
修改生成文件
This commit is contained in:
parent
1ee97a89f4
commit
77cdf6b646
@ -74,7 +74,7 @@ class SystemCrud extends AuthController
|
||||
|
||||
$fromField = $columnField = [];
|
||||
foreach ($data['tableField'] as $item) {
|
||||
if ($item['is_table']) {
|
||||
if ($item['is_table'] && !in_array($item['field_type'], ['addSoftDelete', 'addSoftDelete'])) {
|
||||
$columnField[] = [
|
||||
'field' => $item['field'],
|
||||
'name' => $item['table_name'],
|
||||
@ -146,6 +146,7 @@ class SystemCrud extends AuthController
|
||||
$tableField[] = [
|
||||
'field' => $item['name'],
|
||||
'file_type' => $item['type'],
|
||||
'primaryKey' => (bool)$item['primaryKey'],
|
||||
'default' => $item['default'],
|
||||
'limit' => $item['limit'],
|
||||
'comment' => $item['comment'],
|
||||
@ -189,9 +190,18 @@ class SystemCrud extends AuthController
|
||||
}
|
||||
}
|
||||
|
||||
$softDelete = false;
|
||||
foreach ((array)$info->field['tableField'] as $item) {
|
||||
if ($item['addSoftDelete']) {
|
||||
$softDelete = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$make = $this->services->makeFile($info->table_name, $routeName, false, [
|
||||
'menuName' => $info->name,
|
||||
'key' => $key,
|
||||
'softDelete' => $softDelete,
|
||||
'fromField' => $info->field['fromField'] ?? [],
|
||||
'columnField' => $info->field['columnField'] ?? [],
|
||||
]);
|
||||
|
||||
@ -233,10 +233,13 @@ class SystemCrudServices extends BaseServices
|
||||
$tableField = $this->valueReplace($data['tableField']);
|
||||
$filePath = $this->valueReplace($data['filePath']);
|
||||
|
||||
|
||||
$data['softDelete'] = false;
|
||||
//创建数据库
|
||||
if ($tableField && !$data['isTable']) {
|
||||
$this->makeDatebase($tableName, $tableComment, $tableField);
|
||||
$tableCreateInfo = $this->makeDatebase($tableName, $tableComment, $tableField);
|
||||
if ($tableCreateInfo['softDelete']) {
|
||||
$data['softDelete'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($tableName, self::NOT_CRUD_TABANAME)) {
|
||||
@ -438,12 +441,16 @@ class SystemCrudServices extends BaseServices
|
||||
* @param string $tableName
|
||||
* @param string $tableComment
|
||||
* @param array $tableField
|
||||
* @return array
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/7
|
||||
*/
|
||||
public function makeDatebase(string $tableName, string $tableComment, array $tableField = [])
|
||||
{
|
||||
$softDelete = false;
|
||||
$timestamps = false;
|
||||
$indexField = [];
|
||||
//创建表
|
||||
$table = new Table($tableName, ['comment' => $tableComment], $this->getAdapter());
|
||||
//创建字段
|
||||
@ -458,9 +465,11 @@ class SystemCrudServices extends BaseServices
|
||||
//创建伪删除
|
||||
if ($item['file_type'] === 'addSoftDelete') {
|
||||
$table->addSoftDelete();
|
||||
$softDelete = true;
|
||||
} else if ($item['file_type'] === 'addTimestamps') {
|
||||
//创建修改和增加时间
|
||||
$table->addTimestamps();
|
||||
$timestamps = true;
|
||||
} else {
|
||||
$option['comment'] = $item['comment'];
|
||||
$table->addColumn($item['field'], $this->changeTabelRule($item['file_type']), $option);
|
||||
@ -468,12 +477,15 @@ class SystemCrudServices extends BaseServices
|
||||
}
|
||||
//创建索引
|
||||
if (!empty($data['tableIndex'])) {
|
||||
$indexField = $data['tableIndex'];
|
||||
foreach ($data['tableIndex'] as $item) {
|
||||
$table->addIndex($item);
|
||||
}
|
||||
}
|
||||
//执行创建
|
||||
$table->create();
|
||||
|
||||
return compact('indexField', 'softDelete', 'timestamps');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -525,6 +537,7 @@ class SystemCrudServices extends BaseServices
|
||||
$viewRouter = app()->make(ViewRouter::class);
|
||||
[$routerContent, $routerPath] = $viewRouter->setFilePathName($filePath['router'] ?? '')->isMake($isMake)->handle($tableName, [
|
||||
'route' => $routeName,
|
||||
'menuName' => $options['menuName'],
|
||||
]);
|
||||
//生成前台接口
|
||||
$viewApi = app()->make(ViewApi::class);
|
||||
|
||||
@ -42,16 +42,20 @@ class Model extends Make
|
||||
|
||||
|
||||
/**
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/12
|
||||
* @param string $name
|
||||
* @param array $options
|
||||
* @return array|mixed|void
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/12
|
||||
*/
|
||||
public function handle(string $name, array $options = [])
|
||||
{
|
||||
$this->value['key'] = $options['key'] ?? 'id';
|
||||
if (isset($options['softDelete']) && $options['softDelete']) {
|
||||
$this->value['use-php'] = "use think\model\concern\SoftDelete;\n";
|
||||
$this->value['content-php'] = $this->tab() . "use SoftDelete;\n";
|
||||
}
|
||||
return parent::handle($name, $options);
|
||||
}
|
||||
|
||||
|
||||
@ -71,7 +71,7 @@ class ViewRouter extends Make
|
||||
$path = $options['path'] ?? '';
|
||||
[$nameData, $content] = $this->getStubContent($name);
|
||||
|
||||
$menus = $options['menus'] ?? $name;
|
||||
$menus = $options['menuName'] ?? $name;
|
||||
$route = $options['route'] ?? Str::snake($name);
|
||||
$pagePath = $options['pagePath'] ?? Str::camel($name);
|
||||
if (!$route) {
|
||||
|
||||
@ -20,7 +20,7 @@ namespace app\model\crud{%path%};
|
||||
|
||||
|
||||
use crmeb\basic\BaseModel;
|
||||
|
||||
{%use-php%}
|
||||
/**
|
||||
* Class {%nameCamel%}
|
||||
* @date {%date%}
|
||||
@ -28,7 +28,7 @@ use crmeb\basic\BaseModel;
|
||||
*/
|
||||
class {%nameCamel%} extends BaseModel
|
||||
{
|
||||
|
||||
{%content-php%}
|
||||
/**
|
||||
* 表名
|
||||
* @var string
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +---------------------------------------------------------------------
|
||||
|
||||
import BasicLayout from '@/components/main';
|
||||
import LayoutMain from '@/layout';
|
||||
import setting from '@/setting'
|
||||
|
||||
let routePre = setting.routePre
|
||||
@ -24,7 +24,7 @@ export default {
|
||||
name: 'crud_{%name%}',
|
||||
header: '{%nameHeader%}',
|
||||
meta,
|
||||
component: BasicLayout,
|
||||
component: LayoutMain,
|
||||
children: [
|
||||
{
|
||||
path: 'list',
|
||||
|
||||
@ -1,7 +1,17 @@
|
||||
<template>
|
||||
<div class="main">
|
||||
<Alert closable>
|
||||
crud生成说明
|
||||
<template #desc>
|
||||
<p>1、字段配置中表存在生成的字段为表内列的信息,并且主键、伪删除字段不允许设置为列,主键默认展示在列表中,伪删除字段不允许展示</p>
|
||||
<p>2、在字段配置中新建表时,字段类型为addTimestamps会自动创建create_time、update_time字段,字段类型为:timestamp</p>
|
||||
<p>3、在字段配置中新建表时,字段类型为addSoftDelete会字段创建delete_time字段,字段类型为:timestamp,作用是伪删除</p>
|
||||
<p>4、在字段配置中,表单类型为frameImageOne时属于图片单选,frameImages时为图片多选</p>
|
||||
<p>5、在字段配置中,表单类型为不生成时创建后不会生成对应的表单项</p>
|
||||
</template>
|
||||
</Alert>
|
||||
<Form ref="foundation" :model="foundation" :rules="foundationRules" :label-width="100">
|
||||
<FormItem label="菜单" prop="pid">
|
||||
<FormItem label="菜单">
|
||||
<!-- <Select class="form-width" v-model="foundation.pid">
|
||||
<Option value="beijing">New York</Option>
|
||||
<Option value="shanghai">London</Option>
|
||||
@ -15,7 +25,7 @@
|
||||
:props="{ checkStrictly: true, multiple: false, emitPath: false }"
|
||||
clearable
|
||||
></el-cascader>
|
||||
<div class="tip">必选项,选择的菜单成功后会自动写入到此菜单下</div>
|
||||
<div class="tip">选项,选择的菜单成功后会自动写入到此菜单下</div>
|
||||
</FormItem>
|
||||
<FormItem label="菜单名称">
|
||||
<Input class="form-width" v-model="foundation.menuName" placeholder="请输入表名"></Input>
|
||||
@ -35,7 +45,7 @@
|
||||
<Radio :label="0">否</Radio>
|
||||
</RadioGroup>
|
||||
<div class="tip">
|
||||
数据库表可以生成系统存在的,也可以选择【否】后手动生成,不过此生成方式不交单一;如果不满足使用需求可以先在数据库中创建表,然后选择【是】再进行操作
|
||||
数据库表可以生成系统存在的,也可以选择【否】后手动生成;如果不满足使用需求可以先在数据库中创建表,然后选择【是】再进行操作
|
||||
</div>
|
||||
</FormItem>
|
||||
<FormItem label="字段配置">
|
||||
@ -71,7 +81,7 @@
|
||||
<Input
|
||||
v-else
|
||||
v-model="tableField[index].limit"
|
||||
:disabled="['addTimestamps', 'addSoftDelete'].includes(tableField[index].file_type)"
|
||||
:disabled="disabledInput(index)"
|
||||
></Input>
|
||||
</template>
|
||||
<template slot-scope="{ row, index }" slot="default">
|
||||
@ -79,7 +89,7 @@
|
||||
<Input
|
||||
v-else
|
||||
v-model="tableField[index].default"
|
||||
:disabled="['addTimestamps', 'addSoftDelete'].includes(tableField[index].file_type)"
|
||||
:disabled="disabledInput(index)"
|
||||
></Input>
|
||||
</template>
|
||||
<template slot-scope="{ row, index }" slot="comment">
|
||||
@ -87,37 +97,38 @@
|
||||
<Input
|
||||
v-else
|
||||
v-model="tableField[index].comment"
|
||||
:disabled="['addTimestamps', 'addSoftDelete'].includes(tableField[index].file_type)"
|
||||
:disabled="disabledInput(index)"
|
||||
></Input>
|
||||
</template>
|
||||
<template slot-scope="{ row, index }" slot="required">
|
||||
<Checkbox
|
||||
v-model="tableField[index].required"
|
||||
:disabled="['addTimestamps', 'addSoftDelete'].includes(tableField[index].file_type)"
|
||||
:disabled="disabledInput(index)"
|
||||
></Checkbox>
|
||||
</template>
|
||||
<template slot-scope="{ row, index }" slot="is_table">
|
||||
<Checkbox
|
||||
v-model="tableField[index].is_table"
|
||||
:disabled="['addTimestamps', 'addSoftDelete'].includes(tableField[index].file_type)"
|
||||
:disabled="disabledInput(index)"
|
||||
></Checkbox>
|
||||
</template>
|
||||
<template slot-scope="{ row, index }" slot="table_name">
|
||||
<Input
|
||||
v-model="tableField[index].table_name"
|
||||
:disabled="['addTimestamps', 'addSoftDelete'].includes(tableField[index].file_type)"
|
||||
:disabled="disabledInput(index)"
|
||||
></Input>
|
||||
</template>
|
||||
<template slot-scope="{ row, index }" slot="from_type">
|
||||
<Select
|
||||
v-model="tableField[index].from_type"
|
||||
:disabled="['addTimestamps', 'addSoftDelete'].includes(tableField[index].file_type)"
|
||||
:disabled="disabledInput(index)"
|
||||
>
|
||||
<Option v-for="item in fromTypeList" :value="item.value" :key="item.value">{{ item.label }}</Option>
|
||||
</Select>
|
||||
</template>
|
||||
<template slot-scope="{ row, index }" slot="action">
|
||||
<a @click="del(row, index)">删除</a>
|
||||
<a v-if="!foundation.isTable" @click="del(row, index)">删除</a>
|
||||
<div v-else>无</div>
|
||||
</template>
|
||||
</Table>
|
||||
</div>
|
||||
@ -142,7 +153,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
foundationRules: {
|
||||
pid: [{ required: true, message: '请输入菜单', trigger: 'blur' }],
|
||||
// pid: [{ required: true, message: '请输入菜单', trigger: 'blur' }],
|
||||
tableName: [{ required: true, message: '请输入表名', trigger: 'blur' }],
|
||||
},
|
||||
menusList: [],
|
||||
@ -196,6 +207,12 @@ export default {
|
||||
width: 70,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
slot: 'action',
|
||||
// fixed: 'right',
|
||||
minWidth: 120,
|
||||
},
|
||||
],
|
||||
fromTypeList: [
|
||||
{
|
||||
@ -240,16 +257,26 @@ export default {
|
||||
},
|
||||
mounted() {},
|
||||
methods: {
|
||||
disabledInput(index){
|
||||
let fieldInfo = this.tableField[index];
|
||||
let res = ['addTimestamps', 'addSoftDelete'].includes(this.tableField[index].file_type)
|
||||
if (fieldInfo.primaryKey) {
|
||||
res = true;
|
||||
}
|
||||
if (fieldInfo.field==='delete_time' && fieldInfo.file_type === 'timestamp') {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
},
|
||||
initfield() {
|
||||
this.tableField = [];
|
||||
},
|
||||
changeItemField(e, i) {
|
||||
console.log(e, i);
|
||||
if (e === 'addSoftDelete') {
|
||||
this.$set(this.tableField[i], 'comment', '添加和修改时间');
|
||||
this.$set(this.tableField[i], 'comment', '伪删除');
|
||||
}
|
||||
if (e === 'addTimestamps') {
|
||||
this.$set(this.tableField[i], 'comment', '伪删除');
|
||||
this.$set(this.tableField[i], 'comment', '添加和修改时间');
|
||||
}
|
||||
},
|
||||
changeRadio(status) {
|
||||
|
||||
@ -1,5 +1,15 @@
|
||||
<template>
|
||||
<div class="main">
|
||||
<Alert closable>
|
||||
crud生成文件位置说明
|
||||
<template #desc>
|
||||
<p>1、生成的文件位置尽量不要修改,可以在创建后自行移动</p>
|
||||
<p>2、生成的文件位置不会包含文件的绝对路径,在创建时会携带提前预设的绝对路径</p>
|
||||
<p>3、前端模板文件默认位置在:config/app.php的admin_template_path自动中配置</p>
|
||||
<p>4、后端默认生成位置为:网站根目录</p>
|
||||
<p>5、确保前端/admin/src目录、后端app目录有写入创建文件权限</p>
|
||||
</template>
|
||||
</Alert>
|
||||
<Form ref="foundation" :model="storage" :rules="storageRules" :label-width="130">
|
||||
<FormItem label="生成controller位置">
|
||||
<Input class="form-width" v-model="storage.controller" placeholder="请输入"></Input>
|
||||
@ -57,8 +67,10 @@ export default {
|
||||
storageRules: {},
|
||||
};
|
||||
},
|
||||
created() {},
|
||||
mounted() {},
|
||||
created() {
|
||||
},
|
||||
mounted() {
|
||||
},
|
||||
methods: {},
|
||||
};
|
||||
</script>
|
||||
|
||||
@ -85,14 +85,14 @@ export default {
|
||||
},
|
||||
nextTab() {
|
||||
if (this.currentTab == 0) {
|
||||
if (!this.formItem.foundation.pid) return this.$Message.warning('请选择菜单');
|
||||
// if (!this.formItem.foundation.pid) return this.$Message.warning('请选择菜单');
|
||||
if (!this.formItem.foundation.tableName) return this.$Message.warning('请输入表名');
|
||||
if (!this.formItem.foundation.isTable) {
|
||||
if (!this.$refs.Foundation.tableField.length) return this.$Message.warning('请先添加表数据');
|
||||
if (this.$refs.Foundation.tableField.length)
|
||||
for (let i = 0; i < this.$refs.Foundation.tableField.length; i++) {
|
||||
const el = this.$refs.Foundation.tableField[i];
|
||||
if (!el.field || !el.file_type || !el.comment) {
|
||||
if (['addSoftDelete','addTimestamps'].indexOf(el.file_type)=== -1 && (!el.field || !el.file_type || !el.comment)) {
|
||||
return this.$Message.warning('请完善sql表数据');
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user