mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-30 22:40:48 +00:00
修改crud前端图片展示
This commit is contained in:
parent
698e2d0d9b
commit
4bb2ca6aae
@ -78,6 +78,7 @@ class SystemCrud extends AuthController
|
||||
$columnField[] = [
|
||||
'field' => $item['field'],
|
||||
'name' => $item['table_name'],
|
||||
'type' => $item['from_type'],
|
||||
];
|
||||
}
|
||||
if ($item['from_type']) {
|
||||
@ -145,7 +146,7 @@ class SystemCrud extends AuthController
|
||||
foreach ($field as $item) {
|
||||
$tableField[] = [
|
||||
'field' => $item['name'],
|
||||
'file_type' => $item['type'],
|
||||
'field_type' => $item['type'],
|
||||
'primaryKey' => (bool)$item['primaryKey'],
|
||||
'default' => $item['default'],
|
||||
'limit' => $item['limit'],
|
||||
@ -191,8 +192,9 @@ class SystemCrud extends AuthController
|
||||
}
|
||||
|
||||
$softDelete = false;
|
||||
|
||||
foreach ((array)$info->field['tableField'] as $item) {
|
||||
if ($item['addSoftDelete']) {
|
||||
if ($item['field_type'] === 'addSoftDelete') {
|
||||
$softDelete = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -159,7 +159,7 @@ class SystemCrudServices extends BaseServices
|
||||
|
||||
$tableInfo = Db::query($sql, [config('database.connections.mysql.database'), $this->getTableName($tableName)]);
|
||||
|
||||
return $tableInfo;
|
||||
return $tableInfo[0] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,6 +233,10 @@ class SystemCrudServices extends BaseServices
|
||||
$tableField = $this->valueReplace($data['tableField']);
|
||||
$filePath = $this->valueReplace($data['filePath']);
|
||||
|
||||
if ($this->dao->value(['table_name' => $tableName])) {
|
||||
throw new ValidateException('此表已经生成请在列表中查看');
|
||||
}
|
||||
|
||||
$data['softDelete'] = false;
|
||||
//创建数据库
|
||||
if ($tableField && !$data['isTable']) {
|
||||
@ -299,6 +303,7 @@ class SystemCrudServices extends BaseServices
|
||||
'name' => $data['menuName'] . '列表接口',
|
||||
'app_name' => 'adminapi',
|
||||
'cate_id' => $cateId,
|
||||
'unique_auth' => '',
|
||||
'add_time' => date('Y-m-d H:i:s')
|
||||
],
|
||||
[
|
||||
@ -307,6 +312,7 @@ class SystemCrudServices extends BaseServices
|
||||
'name' => $data['menuName'] . '获取创建表单接口',
|
||||
'app_name' => 'adminapi',
|
||||
'cate_id' => $cateId,
|
||||
'unique_auth' => Str::snake($tableName) . '-add',
|
||||
'add_time' => date('Y-m-d H:i:s')
|
||||
],
|
||||
[
|
||||
@ -315,6 +321,7 @@ class SystemCrudServices extends BaseServices
|
||||
'name' => $data['menuName'] . '保存数据接口',
|
||||
'app_name' => 'adminapi',
|
||||
'cate_id' => $cateId,
|
||||
'unique_auth' => '',
|
||||
'add_time' => date('Y-m-d H:i:s')
|
||||
],
|
||||
[
|
||||
@ -323,6 +330,7 @@ class SystemCrudServices extends BaseServices
|
||||
'name' => $data['menuName'] . '获取修改表单接口',
|
||||
'app_name' => 'adminapi',
|
||||
'cate_id' => $cateId,
|
||||
'unique_auth' => '',
|
||||
'add_time' => date('Y-m-d H:i:s')
|
||||
],
|
||||
[
|
||||
@ -331,6 +339,7 @@ class SystemCrudServices extends BaseServices
|
||||
'name' => $data['menuName'] . '修改数据接口',
|
||||
'app_name' => 'adminapi',
|
||||
'cate_id' => $cateId,
|
||||
'unique_auth' => '',
|
||||
'add_time' => date('Y-m-d H:i:s')
|
||||
],
|
||||
[
|
||||
@ -339,6 +348,7 @@ class SystemCrudServices extends BaseServices
|
||||
'name' => $data['menuName'] . '删除数据接口',
|
||||
'app_name' => 'adminapi',
|
||||
'cate_id' => $cateId,
|
||||
'unique_auth' => '',
|
||||
'add_time' => date('Y-m-d H:i:s')
|
||||
],
|
||||
];
|
||||
@ -350,6 +360,7 @@ class SystemCrudServices extends BaseServices
|
||||
'pid' => $menuInfo->id,
|
||||
'methods' => $item['method'],
|
||||
'api_url' => $item['path'],
|
||||
'unique_auth' => $item['unique_auth'],
|
||||
'name' => $item['name'],
|
||||
'is_del' => 0,
|
||||
];
|
||||
|
||||
@ -150,7 +150,7 @@ class Service extends Make
|
||||
{
|
||||
$requiredText = $required ? '->required()' : '';
|
||||
$content = <<<CONTENT
|
||||
\$rule[] = FormBuilder::frameImage('$field', '$name', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => '$field']), \$info[\'$field\'] ?? '')->icon('$icon')->width('$width')->height('$height')->modal(['footer-hide' => true])$requiredText
|
||||
\$rule[] = FormBuilder::frameImage('$field', '$name', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => '$field']), \$info['$field'] ?? '')->icon('$icon')->width('$width')->height('$height')->modal(['footer-hide' => true])$requiredText
|
||||
CONTENT;
|
||||
return $content;
|
||||
}
|
||||
@ -172,7 +172,7 @@ CONTENT;
|
||||
{
|
||||
$requiredText = $required ? '->required()' : '';
|
||||
$content = <<<CONTENT
|
||||
\$rule[] = FormBuilder::frameImages('$field', '$name', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => '$field', 'type' => 'many', 'maxLength' => $maxLength]), \$info[\'$field\'] ?? [])->maxLength($maxLength)->icon('$icon')->width('$width')->height('$height')->modal(['footer-hide' => true])$requiredText
|
||||
\$rule[] = FormBuilder::frameImages('$field', '$name', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => '$field', 'type' => 'many', 'maxLength' => $maxLength]), \$info['$field'] ?? [])->maxLength($maxLength)->icon('$icon')->width('$width')->height('$height')->modal(['footer-hide' => true])$requiredText
|
||||
CONTENT;
|
||||
return $content;
|
||||
}
|
||||
|
||||
@ -72,7 +72,20 @@ class ViewPages extends Make
|
||||
$route = $options['route'] ?? '';
|
||||
|
||||
$columnStr = [];
|
||||
$contentVue = [];
|
||||
foreach ($field as $key => $item) {
|
||||
if (isset($item['type'])) {
|
||||
switch ($item['type']) {
|
||||
case 'frameImageOne':
|
||||
$templateContent = file_get_contents($this->getStub('image'));
|
||||
$contentVue[] = str_replace(['{%field%}'], [$item['field']], $templateContent);
|
||||
break;
|
||||
case 'frameImages':
|
||||
$templateContent = file_get_contents($this->getStub('images'));
|
||||
$contentVue[] = str_replace(['{%field%}'], [$item['field']], $templateContent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$columnStr[] = ($key == 0 ? $this->tab(2) : '') . "{\n" . $this->tab(3) . "title:\"{$item['name']}\"," . $this->tab(2) . "\n" . $this->tab(3) . "key:\"{$item['field']}\"\n" . $this->tab(2) . "}\n";
|
||||
}
|
||||
$this->value['route'] = $route;
|
||||
@ -81,6 +94,7 @@ class ViewPages extends Make
|
||||
$this->value['pathApiJs'] = $options['pathApiJs'] ?? '';
|
||||
$this->value['nameStudly'] = Str::studly($name);
|
||||
$this->value['nameCamel'] = Str::camel($name);
|
||||
$this->value['content-table-vue'] = $contentVue ? implode("\n", $contentVue) : '';
|
||||
|
||||
return parent::handle($name, $options);
|
||||
}
|
||||
@ -106,10 +120,16 @@ class ViewPages extends Make
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/1
|
||||
*/
|
||||
protected function getStub(string $type = '')
|
||||
protected function getStub(string $type = 'index')
|
||||
{
|
||||
return __DIR__ . DS . 'stubs' . DS . 'view' .
|
||||
DS . 'pages' . DS . 'crud' .
|
||||
DS . 'index.stub';
|
||||
$pagesPath = __DIR__ . DS . 'stubs' . DS . 'view' . DS . 'pages' . DS . 'crud' . DS;
|
||||
|
||||
$stubs = [
|
||||
'index' => $pagesPath . 'index.stub',
|
||||
'image' => $pagesPath . 'image.stub',
|
||||
'images' => $pagesPath . 'images.stub',
|
||||
];
|
||||
|
||||
return $type ? $stubs[$type] : $stubs['index'];
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
<template slot-scope="{ row, index }" slot="{%field%}">
|
||||
<div class="tabBox_img" v-viewer>
|
||||
<img v-lazy="row.{%field%}" />
|
||||
</div>
|
||||
</template>
|
||||
@ -0,0 +1,5 @@
|
||||
<template slot-scope="{ row, index }" slot="{%field%}">
|
||||
<div class="tabBox_img" v-viewer>
|
||||
<img v-lazy="img" v-for="img in row.{%field%}" />
|
||||
</div>
|
||||
</template>
|
||||
@ -3,7 +3,7 @@
|
||||
<Card :bordered="false" dis-hover class="ivu-mt">
|
||||
<Row type="flex">
|
||||
<Col v-bind="grid">
|
||||
<Button v-auth="['{%auth%}']" type="primary" icon="md-add" @click="add">添加{%menus%}</Button>
|
||||
<Button v-auth="['{%auth%}-add']" type="primary" icon="md-add" @click="add">添加{%menus%}</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
<Table
|
||||
@ -16,11 +16,7 @@
|
||||
no-userFrom-text="暂无数据"
|
||||
no-filtered-userFrom-text="暂无筛选结果"
|
||||
>
|
||||
<template slot-scope="{ row, index }" slot="icons">
|
||||
<div class="tabBox_img" v-viewer>
|
||||
<img v-lazy="row.icon" />
|
||||
</div>
|
||||
</template>
|
||||
{%content-table-vue%}
|
||||
<template slot-scope="{ row, index }" slot="action">
|
||||
<a @click="edit(row.id)">修改</a>
|
||||
<Divider type="vertical" />
|
||||
|
||||
@ -66,13 +66,13 @@
|
||||
<span v-if="foundation.isTable">{{ row.field }}</span>
|
||||
<Input
|
||||
v-else
|
||||
:disabled="['addTimestamps', 'addSoftDelete'].includes(tableField[index].file_type)"
|
||||
:disabled="disabledInput(index)"
|
||||
v-model="tableField[index].field"
|
||||
></Input>
|
||||
</template>
|
||||
<template slot-scope="{ row, index }" slot="file_type">
|
||||
<span v-if="foundation.isTable">{{ row.file_type }}</span>
|
||||
<Select v-else v-model="tableField[index].file_type" @on-change="changeItemField($event, index)">
|
||||
<template slot-scope="{ row, index }" slot="field_type">
|
||||
<span v-if="foundation.isTable">{{ row.disabledInput }}</span>
|
||||
<Select v-else v-model="tableField[index].field_type" @on-change="changeItemField($event, index)">
|
||||
<Option v-for="item in columnTypeList" :value="item" :key="item">{{ item }}</Option>
|
||||
</Select>
|
||||
</template>
|
||||
@ -166,7 +166,7 @@ export default {
|
||||
},
|
||||
{
|
||||
title: '字段类型',
|
||||
slot: 'file_type',
|
||||
slot: 'field_type',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
@ -259,11 +259,11 @@ export default {
|
||||
methods: {
|
||||
disabledInput(index){
|
||||
let fieldInfo = this.tableField[index];
|
||||
let res = ['addTimestamps', 'addSoftDelete'].includes(this.tableField[index].file_type)
|
||||
let res = ['addTimestamps', 'addSoftDelete'].includes(this.tableField[index].field_type)
|
||||
if (fieldInfo.primaryKey) {
|
||||
res = true;
|
||||
}
|
||||
if (fieldInfo.field==='delete_time' && fieldInfo.file_type === 'timestamp') {
|
||||
if (fieldInfo.field==='delete_time' && fieldInfo.field_type === 'timestamp') {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
@ -304,7 +304,7 @@ export default {
|
||||
if (!this.tableField.length) {
|
||||
this.tableField.push({
|
||||
field: '',
|
||||
file_type: '',
|
||||
field_type: '',
|
||||
default: '',
|
||||
comment: '',
|
||||
required: false,
|
||||
@ -326,18 +326,18 @@ export default {
|
||||
for (let i = 0; i < this.tableField.length; i++) {
|
||||
const el = this.tableField[i];
|
||||
if (
|
||||
(!el.field || !el.file_type || !el.comment) &&
|
||||
!['addTimestamps', 'addSoftDelete'].includes(el.file_type)
|
||||
(!el.field || !el.field_type || !el.comment) &&
|
||||
!['addTimestamps', 'addSoftDelete'].includes(el.field_type)
|
||||
) {
|
||||
return this.$Message.warning('请先完善上一条数据');
|
||||
}
|
||||
if (el.is_table && !el.table_name && !['addTimestamps', 'addSoftDelete'].includes(el.file_type)) {
|
||||
if (el.is_table && !el.table_name && !['addTimestamps', 'addSoftDelete'].includes(el.field_type)) {
|
||||
return this.$Message.warning('请输入列表名');
|
||||
}
|
||||
}
|
||||
this.tableField.push({
|
||||
field: '',
|
||||
file_type: '',
|
||||
field_type: '',
|
||||
default: '',
|
||||
comment: '',
|
||||
required: false,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<template #desc>
|
||||
<p>1、生成的文件位置尽量不要修改,可以在创建后自行移动</p>
|
||||
<p>2、生成的文件位置不会包含文件的绝对路径,在创建时会携带提前预设的绝对路径</p>
|
||||
<p>3、前端模板文件默认位置在:config/app.php的admin_template_path自动中配置</p>
|
||||
<p>3、前端模板文件默认位置在:config/app.php的admin_template_path中配置</p>
|
||||
<p>4、后端默认生成位置为:网站根目录</p>
|
||||
<p>5、确保前端/admin/src目录、后端app目录有写入创建文件权限</p>
|
||||
</template>
|
||||
|
||||
@ -92,7 +92,7 @@ export default {
|
||||
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 (['addSoftDelete','addTimestamps'].indexOf(el.file_type)=== -1 && (!el.field || !el.file_type || !el.comment)) {
|
||||
if (['addSoftDelete','addTimestamps'].indexOf(el.field_type)=== -1 && (!el.field || !el.field_type || !el.comment)) {
|
||||
return this.$Message.warning('请完善sql表数据');
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,6 +126,21 @@ export default {
|
||||
key: 'table_name',
|
||||
minWidth: 130,
|
||||
},
|
||||
{
|
||||
title: '字符集',
|
||||
key: 'table_collation',
|
||||
minWidth: 130,
|
||||
},
|
||||
{
|
||||
title: '表备注',
|
||||
key: 'table_comment',
|
||||
minWidth: 130,
|
||||
},
|
||||
{
|
||||
title: '添加时间',
|
||||
key: 'add_time',
|
||||
minWidth: 130,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
slot: 'action',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user