Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
lightCMS
提交
2cbfd005
L
lightCMS
项目概览
OpenDocCN
/
lightCMS
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
lightCMS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2cbfd005
编写于
1月 20, 2020
作者:
E
eddy8
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add: copy entity
上级
a839ef88
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
101 addition
and
1 deletion
+101
-1
app/Http/Controllers/Admin/EntityController.php
app/Http/Controllers/Admin/EntityController.php
+33
-0
app/Repository/Admin/EntityRepository.php
app/Repository/Admin/EntityRepository.php
+32
-0
resources/views/admin/entity/index.blade.php
resources/views/admin/entity/index.blade.php
+33
-1
routes/admin.php
routes/admin.php
+3
-0
未找到文件。
app/Http/Controllers/Admin/EntityController.php
浏览文件 @
2cbfd005
...
...
@@ -167,4 +167,37 @@ class EntityController extends Controller
'reload'
=>
true
];
}
/**
* 模型管理-复制模型
*
* @param Request $request
* @param integer $id
* @return array
*/
public
function
copy
(
Request
$request
,
$id
)
{
$this
->
validate
(
$request
,
[
'table_name'
=>
[
'required'
,
'max:64'
,
'regex:/^[0-9a-zA-Z$_]+$/'
],
],
[
'table_name.required'
=>
'表名称不能为空'
,
'table_name.max'
=>
'表名称长度不能超过64'
,
'table_name.regex'
=>
'表名称格式有误'
,
]);
try
{
$tableName
=
$request
->
post
(
'table_name'
);
EntityRepository
::
copy
(
$tableName
,
$id
);
return
[
'code'
=>
0
,
'msg'
=>
'复制成功'
,
'reload'
=>
true
];
}
catch
(
\
RuntimeException
$e
)
{
return
[
'code'
=>
5
,
'msg'
=>
$e
->
getMessage
(),
];
}
}
}
app/Repository/Admin/EntityRepository.php
浏览文件 @
2cbfd005
...
...
@@ -33,6 +33,7 @@ class EntityRepository
xssFilter
(
$item
);
$item
->
editUrl
=
route
(
'admin::entity.edit'
,
[
'id'
=>
$item
->
id
]);
$item
->
deleteUrl
=
route
(
'admin::entity.delete'
,
[
'id'
=>
$item
->
id
]);
$item
->
copyUrl
=
route
(
'admin::entity.copy'
,
[
'id'
=>
$item
->
id
]);
$item
->
fieldUrl
=
route
(
'admin::entityField.index'
)
.
'?entity_id='
.
$item
->
id
;
$item
->
contentUrl
=
route
(
'admin::content.index'
,
[
'entity'
=>
$item
->
id
]);
$item
->
commentListUrl
=
route
(
'admin::comment.index'
,
[
'entity_id'
=>
$item
->
id
]);
...
...
@@ -80,6 +81,37 @@ class EntityRepository
}
}
public
static
function
copy
(
$tableName
,
$id
)
{
$entity
=
Entity
::
findOrFail
(
$id
);
if
(
Schema
::
hasTable
(
$tableName
))
{
throw
new
\
RuntimeException
(
"数据库表已存在"
);
}
try
{
// 仅在 Mysql 下测试通过,不支持 Sqlite
DB
::
statement
(
"CREATE TABLE
{
$tableName
}
LIKE
{
$entity
->
table_name
}
"
);
DB
::
beginTransaction
();
$newEntity
=
$entity
->
replicate
();
$newEntity
->
table_name
=
$tableName
;
$newEntity
->
name
.
=
'_copy'
;
$newEntity
->
save
();
EntityField
::
where
(
'entity_id'
,
$id
)
->
get
()
->
each
(
function
(
$item
)
use
(
$newEntity
)
{
$m
=
$item
->
replicate
();
$m
->
entity_id
=
$newEntity
->
id
;
$m
->
save
();
});
DB
::
commit
();
}
catch
(
\
Exception
$e
)
{
Schema
::
dropIfExists
(
$tableName
);
throw
$e
;
}
}
public
static
function
update
(
$id
,
$data
)
{
return
Entity
::
query
()
->
where
(
'id'
,
$id
)
->
update
(
$data
);
...
...
resources/views/admin/entity/index.blade.php
浏览文件 @
2cbfd005
...
...
@@ -21,8 +21,9 @@
@
endsection
<
script
type
=
"text/html"
id
=
"action"
>
<
a
href
=
"<% d.editUrl %>"
class
=
"layui-table-link"
title
=
"编辑"
><
i
class
=
"layui-icon layui-icon-edit"
></
i
></
a
>
<%
# if(d.enable_comment == {{ App\Model\Admin\Entity::COMMENT_ENABLE }}){ %> <a href="<% d.commentListUrl %>" class="layui-table-link" title="评论列表" style="margin-left: 5px"><i class="layui-icon layui-icon-reply-fill"></i></a> <%# } %>
<
a
href
=
"javascript:;"
class
=
"layui-table-link"
title
=
"删除"
style
=
"margin-left: 10px"
onclick
=
"deleteEntity('<% d.deleteUrl %>')"
><
i
class
=
"layui-icon layui-icon-delete"
></
i
></
a
>
<
a
href
=
"javascript:;"
class
=
"layui-table-link"
title
=
"复制"
style
=
"margin-left: 10px"
onclick
=
"copyEntity('<% d.copyUrl %>')"
><
i
class
=
"layui-icon layui-icon-file"
></
i
></
a
>
<%
# if(d.enable_comment == {{ App\Model\Admin\Entity::COMMENT_ENABLE }}){ %> <a href="<% d.commentListUrl %>" class="layui-table-link" title="评论列表" style="margin-left: 5px"><i class="layui-icon layui-icon-reply-fill"></i></a> <%# } %>
<
a
href
=
"<% d.fieldUrl %>"
class
=
"layui-table-link"
title
=
"字段管理"
style
=
"margin-left: 5px"
>
字段管理
</
a
>
<
a
href
=
"<% d.contentUrl %>"
class
=
"layui-table-link"
title
=
"字段管理"
style
=
"margin-left: 5px"
>
内容管理
</
a
>
</
script
>
...
...
@@ -71,5 +72,36 @@
layer
.
close
(
index
);
});
}
function
copyEntity
(
url
)
{
layer
.
confirm
(
'复制模型将新建一个和当前模型一样的模型(数据库表结构、表单定义等信息一致),确定要复制?'
,
function
(
index
){
layer
.
prompt
({
formType
:
0
,
title
:
'请输入新模型的数据库表名称'
,
},
function
(
value
,
index
,
elem
){
$
.
ajax
({
url
:
url
,
data
:
{
'table_name'
:
value
},
success
:
function
(
result
)
{
if
(
result
.
code
!==
0
)
{
layer
.
msg
(
result
.
msg
,
{
shift
:
6
});
return
false
;
}
layer
.
msg
(
result
.
msg
,
{
icon
:
1
},
function
()
{
if
(
result
.
reload
)
{
location
.
reload
();
}
if
(
result
.
redirect
)
{
location
.
href
=
'{!! url()->previous() !!}'
;
}
});
}
});
layer
.
close
(
index
);
});
layer
.
close
(
index
);
});
}
</
script
>
@
endsection
routes/admin.php
浏览文件 @
2cbfd005
...
...
@@ -81,6 +81,9 @@ Route::group(
// 内容
Route
::
post
(
'/entity/{entity}/batch'
,
'ContentController@batch'
)
->
name
(
'content.batch'
);
// 模型
Route
::
post
(
'/entities/{id}/copy'
,
'EntityController@copy'
)
->
name
(
'entity.copy'
);
// 自动加载生成的其它路由
foreach
(
new
DirectoryIterator
(
base_path
(
'routes/auto'
))
as
$f
)
{
if
(
$f
->
isDot
())
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录