469 lines
15 KiB
PHP
469 lines
15 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller\Code;
|
|
|
|
use app\BaseController;
|
|
use app\common\model\Code\CodeModule as ModelCodeModule;
|
|
use app\Request;
|
|
use think\Validate;
|
|
use think\exception\ValidateException;
|
|
use think\facade\Filesystem;
|
|
use app\common\arw\adjfut\src\Excel;
|
|
use app\common\arw\adjfut\src\UploadFile;
|
|
use app\common\exception\Tool;
|
|
use think\facade\Db;
|
|
use think\facade\Env;
|
|
|
|
|
|
class CodeModule extends BaseController
|
|
{
|
|
/**
|
|
* 获取代码块列表
|
|
*/
|
|
public function getCodeModuleList(Request $request, $isExport = false): array
|
|
{
|
|
$params = $request->param();
|
|
$con = [];
|
|
|
|
$con = Tool::getOptionalQuery(['a.code_module_category_guid', '='], ['code_module_name', 'LIKE'], ['code_module_audit', '='], );
|
|
|
|
$query = ModelCodeModule::where($con)
|
|
->alias('a')
|
|
->leftjoin('code_module_category c', 'a.code_module_category_guid = c.code_module_category_guid')
|
|
->field([
|
|
'a.code_module_id',
|
|
'a.code_module_guid',
|
|
'c.code_module_category_name',
|
|
'a.code_module_category_guid',
|
|
'a.code_module_name',
|
|
'a.code_module_html',
|
|
'a.code_module_style',
|
|
'a.code_module_script',
|
|
'a.code_module_sort',
|
|
'a.code_module_audit',
|
|
'a.customer_guid'
|
|
])
|
|
->order('code_module_sort', 'asc');
|
|
|
|
return $isExport ? $query->select()->toArray() : msg("获取代码块列表成功!", $query);
|
|
}
|
|
|
|
/**
|
|
* 添加代码块
|
|
*/
|
|
public function addCodeModule(Request $request): array
|
|
{
|
|
$params = $request->param();
|
|
$this->validate($params, [
|
|
'code_module_category_guid|类目' => 'require',
|
|
'code_module_name|代码块名称' => 'require',
|
|
'code_module_html|html内容' => 'require',
|
|
]);
|
|
|
|
$params['code_module_audit'] = ModelCodeModule::AUDIT_PASS;
|
|
$model = ModelCodeModule::create($params, [
|
|
'code_module_category_guid',
|
|
'code_module_name',
|
|
'code_module_html',
|
|
'code_module_style',
|
|
'code_module_script',
|
|
'code_module_sort',
|
|
'code_module_audit',
|
|
'code_module_guid',
|
|
'code_module_create_user_guid',
|
|
'code_module_update_user_guid'
|
|
]);
|
|
return msg('添加成功!');
|
|
}
|
|
|
|
/**
|
|
* 编辑代码块
|
|
*/
|
|
public function editCodeModule(Request $request): array
|
|
{
|
|
$params = $request->param();
|
|
$this->validate($params, [
|
|
'code_module_category_guid|类目' => 'require',
|
|
'code_module_name|代码块名称' => 'require',
|
|
'code_module_html|html内容' => 'require',
|
|
'code_module_sort|排序' => 'require',
|
|
'code_module_audit|审核状态' => 'require',
|
|
'code_module_guid|代码块' => 'require'
|
|
]);
|
|
$model = ModelCodeModule::where('code_module_guid', $params['code_module_guid'])->find();
|
|
if (!$model) {
|
|
throwErrorMsg("该代码块不存在", 1);
|
|
}
|
|
$model->allowField([
|
|
'code_module_category_guid',
|
|
'code_module_name',
|
|
'code_module_html',
|
|
'code_module_style',
|
|
'code_module_script',
|
|
'code_module_sort',
|
|
'code_module_audit',
|
|
'code_module_update_user_guid'
|
|
])->save($params);
|
|
return msg('编辑成功!');
|
|
}
|
|
|
|
/**
|
|
* 删除代码块
|
|
*/
|
|
public function deleteCodeModule(Request $request): array
|
|
{
|
|
$params = $request->param();
|
|
$this->validate($params, [
|
|
'code_module_guid' => 'require',
|
|
]);
|
|
$code_module = ModelCodeModule::where([
|
|
'code_module_guid' => explode(',', $params['code_module_guid'])
|
|
])->select();
|
|
$code_module->delete();
|
|
return msg('删除成功!');
|
|
}
|
|
|
|
|
|
/**
|
|
* 审核代码块
|
|
*/
|
|
public function auditCodeModule(Request $request)
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
$params = $request->param();
|
|
$this->validate($params, [
|
|
'code_module_guid|代码块guid' => 'require',
|
|
'code_module_audit|审核状态' => 'require|in:2,3',
|
|
]);
|
|
ModelCodeModule::auditCodeModule($params);
|
|
Db::commit();
|
|
} catch (\Throwable $th) {
|
|
Db::rollback();
|
|
throw $th;
|
|
}
|
|
return [
|
|
'code' => 0,
|
|
'msg' => '审核成功'
|
|
];
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 导出Excel
|
|
*/
|
|
public function exportExcel(Request $request): void
|
|
{
|
|
ModelCodeModule::exportExcel(self::getCodeModuleList($request, true));
|
|
}
|
|
|
|
/**
|
|
* 下载导入模板
|
|
*/
|
|
public function downloadTemplate(Request $request): void
|
|
{
|
|
$params = $request->param();
|
|
$data = [
|
|
array_values(ModelCodeModule::EXCELFIELD),
|
|
[
|
|
'卡片',
|
|
'超级卡片',
|
|
'<div class="wrapper">
|
|
|
|
<div class="card radius shadowDepth1">
|
|
<div class="card__image border-tlr-radius">
|
|
<img src="http://lorempixel.com/400/200/sports/" alt="image" class="border-tlr-radius">
|
|
</div>
|
|
|
|
<div class="card__content card__padding">
|
|
<div class="card__share">
|
|
<div class="card__social">
|
|
<a class="share-icon facebook" href="#"><span class="fa fa-facebook"></span></a>
|
|
<a class="share-icon twitter" href="#"><span class="fa fa-twitter"></span></a>
|
|
<a class="share-icon googleplus" href="#"><span class="fa fa-google-plus"></span></a>
|
|
</div>
|
|
|
|
<a id="share" class="share-toggle share-icon" href="#"></a>
|
|
</div>
|
|
|
|
<div class="card__meta">
|
|
<a href="#">Web Design</a>
|
|
<time>17th March</time>
|
|
</div>
|
|
|
|
<article class="card__article">
|
|
<h2><a href="#">Material Design Card - For Blog Post Article</a></h2>
|
|
|
|
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ducimus harum...</p>
|
|
</article>
|
|
</div>
|
|
|
|
<div class="card__action">
|
|
|
|
<div class="card__author">
|
|
<img src="http://lorempixel.com/40/40/sports/" alt="user">
|
|
<div class="card__author-content">
|
|
By <a href="#">John Doe</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<p class="text-center">Created By <a href="https://twitter.com/mithicher">Mithicher Baro</a></p>
|
|
</div>',
|
|
`@import 'https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css';
|
|
@import 'https://fonts.googleapis.com/css?family=Roboto:700,400';
|
|
/*
|
|
* Basic Reset
|
|
*/
|
|
|
|
*,
|
|
*:after,
|
|
*:before {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
/**
|
|
* Basics Styles
|
|
*/
|
|
html {
|
|
font-size: 62.5%;
|
|
}
|
|
body {
|
|
background-color: #eee;
|
|
font-family: Roboto;
|
|
font-weight: 400;
|
|
font-size: 1.6em;
|
|
line-height: 1.6;
|
|
color: #666;
|
|
}
|
|
|
|
a {
|
|
text-decoration: none;
|
|
color: #3498db;
|
|
}
|
|
a:hover {
|
|
color: #2980b9;
|
|
}
|
|
|
|
h2 {
|
|
line-height: 1.2;
|
|
margin-bottom: 1.6rem;
|
|
}
|
|
|
|
.wrapper {
|
|
max-width: 400px;
|
|
margin: 50px auto;
|
|
padding-left: 1em;
|
|
padding-right: 1em;
|
|
}
|
|
|
|
/**
|
|
* Helpers
|
|
*/
|
|
.border-tlr-radius {
|
|
border-top-left-radius: 2px;
|
|
border-top-right-radius: 2px;
|
|
}
|
|
|
|
.text-center { text-align: center; }
|
|
|
|
.radius { border-radius: 2px; }
|
|
|
|
.padding-tb { padding-top: 1.6rem; padding-bottom: 1.6rem;}
|
|
|
|
.shadowDepth0 { box-shadow: 0 1px 3px rgba(0,0,0, 0.12); }
|
|
|
|
.shadowDepth1 {
|
|
box-shadow:
|
|
0 1px 3px rgba(0,0,0, 0.12),
|
|
0 1px 2px rgba(0,0,0, 0.24);
|
|
}
|
|
|
|
|
|
/**
|
|
* Card Styles
|
|
*/
|
|
|
|
.card {
|
|
background-color: #fff;
|
|
margin-bottom: 1.6rem;
|
|
}
|
|
|
|
.card__padding {
|
|
padding: 1.6rem;
|
|
}
|
|
|
|
.card__image {
|
|
min-height: 100px;
|
|
background-color: #eee;
|
|
}
|
|
.card__image img {
|
|
width: 100%;
|
|
max-width: 100%;
|
|
display: block;
|
|
}
|
|
|
|
.card__content {
|
|
position: relative;
|
|
}
|
|
|
|
/* card meta */
|
|
.card__meta time {
|
|
font-size: 1.5rem;
|
|
color: #bbb;
|
|
margin-left: 0.8rem;
|
|
}
|
|
|
|
/* card article */
|
|
.card__article a {
|
|
text-decoration: none;
|
|
color: #444;
|
|
transition: all 0.5s ease;
|
|
}
|
|
.card__article a:hover {
|
|
color: #2980b9;
|
|
}
|
|
|
|
/* card action */
|
|
.card__action {
|
|
overflow: hidden;
|
|
padding-right: 1.6rem;
|
|
padding-left: 1.6rem;
|
|
padding-bottom: 1.6rem;
|
|
}
|
|
|
|
.card__author {}
|
|
|
|
.card__author img,
|
|
.card__author-content {
|
|
display: inline-block;
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.card__author img{
|
|
border-radius: 50%;
|
|
margin-right: 0.6em;
|
|
}
|
|
|
|
.card__share {
|
|
float: right;
|
|
position: relative;
|
|
margin-top: -42px;
|
|
}
|
|
|
|
.card__social {
|
|
position: absolute;
|
|
top: 0;
|
|
right: 0;
|
|
visibility: hidden;
|
|
width: 160px;
|
|
transform: translateZ(0);
|
|
transform: translateX(0px);
|
|
transition: transform 0.35s ease;
|
|
}
|
|
.card__social--active {
|
|
visibility: visible;
|
|
/*z-index: 3;*/
|
|
transform: translateZ(0);
|
|
transform: translateX(-48px);
|
|
transition: transform 0.35s ease;
|
|
}
|
|
|
|
.share-toggle {
|
|
z-index: 2;
|
|
}
|
|
.share-toggle:before {
|
|
content: "\f1e0";
|
|
font-family: 'FontAwesome';
|
|
color: #3498db;
|
|
}
|
|
.share-toggle.share-expanded:before {
|
|
content: "\f00d";
|
|
}
|
|
|
|
.share-icon {
|
|
display: inline-block;
|
|
width: 48px;
|
|
height: 48px;
|
|
line-height: 48px;
|
|
text-align: center;
|
|
border-radius: 50%;
|
|
background-color: #fff;
|
|
transition: all 0.3s ease;
|
|
outline: 0;
|
|
|
|
box-shadow:
|
|
0 2px 4px rgba(0,0,0, 0.12),
|
|
0 2px 4px rgba(0,0,0, 0.24);
|
|
}
|
|
.share-icon:hover,
|
|
.share-icon:focus {
|
|
box-shadow:
|
|
0 3px 6px rgba(0,0,0, 0.12),
|
|
0 3px 6px rgba(0,0,0, 0.24);
|
|
|
|
-webkit-transform: scale(1.2);
|
|
-moz-transform: scale(1.2);
|
|
-ms-transform: scale(1.2);
|
|
-o-transform: scale(1.2);
|
|
transform: scale(1.2);
|
|
}
|
|
|
|
.facebook {
|
|
background-color: #3b5998;
|
|
}
|
|
.twitter {
|
|
background-color: #00abe3;
|
|
}
|
|
.googleplus {
|
|
background-color: #d3492c;
|
|
}
|
|
|
|
.facebook,
|
|
.twitter,
|
|
.googleplus {
|
|
color: #fff;
|
|
}
|
|
|
|
.facebook:hover,
|
|
.twitter:hover,
|
|
.googleplus:hover {
|
|
color: #eee;
|
|
}
|
|
`,
|
|
`$(document).ready(function($) {
|
|
|
|
$('.card__share > a').on('click', function(e){
|
|
e.preventDefault() // prevent default action - hash doesn't appear in url
|
|
$(this).parent().find( 'div' ).toggleClass( 'card__social--active' );
|
|
$(this).toggleClass('share-expanded');
|
|
});
|
|
|
|
});
|
|
`,
|
|
'1',
|
|
]
|
|
];
|
|
$excel = (new Excel())->exporTsheet($data);
|
|
$excel->save('代码块导入模板.xlsx');
|
|
}
|
|
|
|
/**
|
|
* 导入excel
|
|
*/
|
|
public function importExcel(Request $request): array
|
|
{
|
|
|
|
$file = new UploadFile('uploads', 'fileExt:xlsx');
|
|
$file->putFile('code_module');
|
|
$msg = ModelCodeModule::importExcel($file);
|
|
return [
|
|
'code' => 0,
|
|
'msg' => $msg
|
|
];
|
|
}
|
|
} |