mirror of https://github.com/1099438829/apeblog
修复文章编辑和初始化分类
This commit is contained in:
parent
212edac63a
commit
30d6a554e5
|
|
@ -3,6 +3,7 @@
|
|||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\DocumentCategory as aModel;
|
||||
use app\admin\model\DocumentCategoryContent;
|
||||
use app\Request;
|
||||
use FormBuilder\Exception\FormBuilderException;
|
||||
use FormBuilder\Factory\Elm;
|
||||
|
|
@ -47,63 +48,6 @@ class Category extends AuthController
|
|||
return app("json")->layui(aModel::systemPage($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param int $pid
|
||||
* @return string
|
||||
* @throws FormBuilderException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function add($pid = 0)
|
||||
{
|
||||
$form = array();
|
||||
$form[] = Elm::select('pid','上级权限',(int)$pid)->options(aModel::returnOptions())->col(10);
|
||||
$form[] = Elm::input('name','权限名称')->col(10);
|
||||
$form[] = Elm::frameInput('icon','图标',Url::buildUrl('admin/widget.icon/index',array('fodder'=>'icon')))->icon("ios-ionic")->width('96%')->height('390px')->col(10);
|
||||
$form[] = Elm::input('module','模块名')->col(10);
|
||||
$form[] = Elm::input('controller','控制器名')->col(10);
|
||||
$form[] = Elm::input('action','方法名')->col(10);
|
||||
$form[] = Elm::input('params','参数')->placeholder("php数组,不懂不要填写")->col(10);
|
||||
$form[] = Elm::number('rank','排序')->col(10);
|
||||
$form[] = Elm::radio('is_menu','是否菜单',1)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(10);
|
||||
$form[] = Elm::radio('status','状态',1)->options([['label'=>'启用','value'=>1],['label'=>'冻结','value'=>0]])->col(10);
|
||||
$form = Form::make_post_form($form, url('save')->build());
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch("public/form-builder");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param int $id
|
||||
* @return string
|
||||
* @throws FormBuilderException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit($id = 0)
|
||||
{
|
||||
if (!$id) return app("json")->fail("权限id不能为空");
|
||||
$ainfo = aModel::get($id);
|
||||
if (!$ainfo) return app("json")->fail("没有该权限");
|
||||
$form = array();
|
||||
$form[] = Elm::select('pid','上级权限',$ainfo['pid'])->options(aModel::returnOptions())->col(10);
|
||||
$form[] = Elm::input('name','权限名称',$ainfo['name'])->col(10);
|
||||
$form[] = Elm::frameInput('icon','图标',Url::buildUrl('admin/widget.icon/index',array('fodder'=>'icon')),$ainfo['icon'])->icon("ios-ionic")->width('96%')->height('390px')->col(10);
|
||||
$form[] = Elm::input('module','模块名',$ainfo['module'])->col(10);
|
||||
$form[] = Elm::input('controller','控制器名',$ainfo['controller'])->col(10);
|
||||
$form[] = Elm::input('action','方法名',$ainfo['action'])->col(10);
|
||||
$form[] = Elm::input('params','参数',$ainfo['params'])->placeholder("php数组,不懂不要填写")->col(10);
|
||||
$form[] = Elm::number('rank','排序',$ainfo['rank'])->col(10);
|
||||
$form[] = Elm::radio('is_menu','是否菜单',$ainfo['is_menu'])->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(10);
|
||||
$form[] = Elm::radio('status','状态',$ainfo['status'])->options([['label'=>'启用','value'=>1],['label'=>'冻结','value'=>0]])->col(10);
|
||||
$form = Form::make_post_form($form, url('save',['id'=>$id])->build());
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch("public/form-builder");
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
* @param $id
|
||||
|
|
@ -155,4 +99,43 @@ class Category extends AuthController
|
|||
if ($where['field'] == '' || $where['value'] =='') return app("json")->fail("参数有误!");
|
||||
return aModel::update([$where['field']=>$where['value']],['id'=>$id]) ? app("json")->success("操作成功") : app("json")->fail("操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增页
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$where = [
|
||||
'name' => '',
|
||||
'status' => ''
|
||||
];
|
||||
$category = aModel::systemPage($where);
|
||||
$category = get_tree_list($category);
|
||||
$this->assign("category",$category);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑页
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
* @author 李玉坤
|
||||
* @date 2021-02-20 17:00
|
||||
*/
|
||||
public function edit(Request $request)
|
||||
{
|
||||
$where = [
|
||||
'name' => '',
|
||||
'status' => ''
|
||||
];
|
||||
$category = aModel::systemPage($where);
|
||||
$category = get_tree_list($category);
|
||||
$info = aModel::get($request->param(['id']));
|
||||
$info->content = DocumentCategoryContent::get($request->param(['id']))->content;
|
||||
$this->assign("category",$category);
|
||||
$this->assign("info",$info);
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,14 @@ class Document extends BaseModel
|
|||
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'],(int)$where['limit']);
|
||||
$data = $model->select();
|
||||
if ($data) $data = $data->toArray();
|
||||
$categoryList = DocumentCategory::where('id','in',array_column($data,'category_id'))->column('title','id');
|
||||
foreach ($data as &$item){
|
||||
if (!empty($categoryList[$item['category_id']])){
|
||||
$item['category_title'] = $categoryList[$item['category_id']];
|
||||
}else{
|
||||
$item['category_title'] = '';
|
||||
}
|
||||
}
|
||||
return compact('data','count');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,211 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<title>添加分类 - {:system_config("title")}后台管理系统</title>
|
||||
{include file="public/header" /}
|
||||
<!--标签插件-->
|
||||
<link rel="stylesheet" href="__ADMIN_PATH__js/jquery-tags-input/jquery.tagsinput.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4>基本样式</h4>
|
||||
<ul class="card-actions">
|
||||
<li>
|
||||
<button type="button" data-toggle="tooltip" title="" data-original-title="返回" onclick="javascript:history.back(-1);return false;">返 回</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul id="myTabs" class="nav nav-tabs" role="tablist">
|
||||
<li class="active"><a href="#home" id="home-tab" role="tab" data-toggle="tab">基本信息</a></li>
|
||||
<li><a href="#profile" role="tab" id="profile-tab" data-toggle="tab">SEO设置</a></li>
|
||||
</ul>
|
||||
<div id="myTabContent" class="tab-content">
|
||||
<div class="tab-pane fade active in" id="home">
|
||||
<form action="#!" method="post" class="row add-form" onsubmit="return false;">
|
||||
<div class="form-group col-md-12">
|
||||
<label>分类名称</label>
|
||||
<input type="text" class="form-control" id="title" name="title" value="" placeholder="分类名称" />
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label>英文名称</label>
|
||||
<input type="text" class="form-control" id="en_title" name="en_title" value="" placeholder="英文名称" />
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="pid">上级分类</label>
|
||||
<div class="form-controls">
|
||||
<select name="pid" id="pid" class="form-control">
|
||||
<option value="0">请选择</option>
|
||||
{volist name="category" id="vo"}
|
||||
<option value="{$vo.id}">{$vo.html}{$vo.title}</option>
|
||||
{/volist}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row col-md-12">
|
||||
<label for="pid">属性</label>
|
||||
<div class="form-controls">
|
||||
<select name="pid" class="form-control">
|
||||
<option value="0">请选择</option>
|
||||
<option value="1">列表</option>
|
||||
<option value="2">单页</option>
|
||||
<option value="3">外联</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label>排序</label>
|
||||
<input type="text" class="form-control" name="sort" placeholder="请输入排序" value="99">
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="link_str">外链</label>
|
||||
<input type="text" class="form-control" name="link_str" id="link_str" placeholder="外链">
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="content">文章内容</label>
|
||||
<textarea id="content" name="content"></textarea>
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">立即提交</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="profile">
|
||||
<form action="#!" method="post" class="row add-form" onsubmit="return false;">
|
||||
<div class="form-group col-md-12">
|
||||
<label for="keywords">seo关键字</label>
|
||||
<input type="text" class="form-control" id="keywords" name="keywords" placeholder="请输入seo关键字">
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="description">seo描述</label>
|
||||
<input type="text" class="form-control" name="description" id="description" placeholder="seo描述" >
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">立即提交</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{include file="public/footer"/}
|
||||
<!--select2-->
|
||||
<script src="__ADMIN_PATH__js/select2.min.js"></script>
|
||||
<!--富文本输入框-->
|
||||
<script src="__ADMIN_PATH__js/tinymce/tinymce.min.js"></script>
|
||||
<!--标签-->
|
||||
<script src="__ADMIN_PATH__js/jquery-tags-input/jquery.tagsinput.min.js"></script>
|
||||
<script>
|
||||
$(function () {
|
||||
$('#tag').select2();
|
||||
});
|
||||
$(document).ready(function(){
|
||||
tinymce.init({
|
||||
selector: '#content',
|
||||
language: 'zh_CN',
|
||||
directionality: 'ltl',
|
||||
browser_spellcheck: true,
|
||||
contextmenu: false,
|
||||
height: 480,
|
||||
plugins: [
|
||||
"advlist autolink lists link image charmap print preview anchor",
|
||||
"searchreplace visualblocks code fullscreen",
|
||||
"insertdatetime media table contextmenu paste imagetools wordcount",
|
||||
"code"
|
||||
],
|
||||
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code",
|
||||
images_upload_url: '/admin/files/tinymce',
|
||||
});
|
||||
});
|
||||
/**
|
||||
* 选择文件
|
||||
* @param inputName
|
||||
*/
|
||||
function btnClick(inputName) {
|
||||
$("#file_"+inputName).click()
|
||||
}
|
||||
/**
|
||||
* 异步上传
|
||||
* @param inputName
|
||||
*/
|
||||
function upload(inputName) {
|
||||
var formData = new FormData();
|
||||
formData.append("type",'images');
|
||||
formData.append("file",$("#file_"+inputName)[0].files[0]);
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'/admin/files/upload',
|
||||
data: formData,
|
||||
cache: false,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function (res) {
|
||||
if (res.code == 200){
|
||||
$("#"+inputName).val(res.data.filePath);
|
||||
let html =' <figure>\n' +
|
||||
' <img src="'+res.data.filePath+'" alt="'+res.data.name+'">\n' +
|
||||
' <figcaption>\n' +
|
||||
' <a class="btn btn-round btn-square btn-danger btn-image-delete" href="#!"><i class="mdi mdi-delete"></i></a>\n' +
|
||||
' </figcaption>\n' +
|
||||
' </figure>';
|
||||
$('#pic-image').html(html);
|
||||
$('#pic-image').show().next('li').hide();
|
||||
}else{
|
||||
lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
$(".add-form").submit(function () {
|
||||
let Arr = $('.add-form').serializeArray();
|
||||
let checkResult = true;
|
||||
$.each(Arr,function (index,item) {
|
||||
try {
|
||||
switch (item.name) {
|
||||
case 'parent_id':
|
||||
if (!item.value) {
|
||||
throw "上级分类不能为空";
|
||||
}
|
||||
break;
|
||||
case 'title':
|
||||
if (!item.value) {
|
||||
throw "分类名称不能为空";
|
||||
}
|
||||
break;
|
||||
case 'cover_path':
|
||||
if (!item.value) {
|
||||
throw "主图不能为空";
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
lightyear.notify(error, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
checkResult = false;
|
||||
return false;
|
||||
}
|
||||
})
|
||||
// 检验不通过终止执行
|
||||
if (!checkResult) {
|
||||
return false;
|
||||
}
|
||||
$.post(url="/admin/article/save",$('.add-form').serialize(),function (res) {
|
||||
if (res.code == 200) {lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');setTimeout(function () {location.href='/admin/article/index';},2000)}
|
||||
else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
});
|
||||
return true;
|
||||
})
|
||||
|
||||
//删除事件
|
||||
$('body').on('click','.btn-image-delete',function(){
|
||||
$('#pic-image').hide().next('li').show();
|
||||
$('#cover_path').val('');
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,276 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<title>添加文章 - {:system_config("title")}后台管理系统</title>
|
||||
{include file="public/header" /}
|
||||
<!--标签插件-->
|
||||
<link rel="stylesheet" href="__ADMIN_PATH__js/jquery-tags-input/jquery.tagsinput.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4>基本样式</h4>
|
||||
<ul class="card-actions">
|
||||
<li>
|
||||
<button type="button" data-toggle="tooltip" title="" data-original-title="返回" onclick="javascript:history.back(-1);return false;">返 回</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul id="myTabs" class="nav nav-tabs" role="tablist">
|
||||
<li class="active"><a href="#home" id="home-tab" role="tab" data-toggle="tab">基本信息</a></li>
|
||||
<li><a href="#profile" role="tab" id="profile-tab" data-toggle="tab">文章设置</a></li>
|
||||
</ul>
|
||||
<div id="myTabContent" class="tab-content">
|
||||
<div class="tab-pane fade active in" id="home">
|
||||
<form action="#!" method="post" class="row add-form" onsubmit="return false;">
|
||||
<div class="form-group col-md-12">
|
||||
<label>文章名称</label>
|
||||
<input type="hidden" name="id" value="{$info.id}">
|
||||
<input type="text" class="form-control" id="title" name="title" placeholder="文章名称" value="{$info.title}" />
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="category_id">栏目分类</label>
|
||||
<div class="form-controls">
|
||||
<select name="category_id" id="category_id" class="form-control">
|
||||
<option value="0">请选择</option>
|
||||
{volist name="category" id="vo"}
|
||||
<option value="{$vo.id}" {if $vo.id == $info.category_id}selected{/if}>{$vo.html}{$vo.title}</option>
|
||||
{/volist}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="author">作者</label>
|
||||
<input type="text" class="form-control" id="author" name="author" placeholder="原作者" value="{$info.author}"/>
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label>主图</label>
|
||||
<div class="form-controls">
|
||||
<ul class="list-inline clearfix lyear-uploads-pic">
|
||||
{notempty name="info.cover_path"}
|
||||
<li class="col-xs-4 col-sm-3 col-md-2" id="pic-image" style="display: block;"> <figure>
|
||||
<img src="{$info.cover_path}" alt="{$info.cover_path|basename}">
|
||||
<figcaption>
|
||||
<a class="btn btn-round btn-square btn-danger btn-image-delete" href="#!"><i class="mdi mdi-delete"></i></a>
|
||||
</figcaption>
|
||||
</figure></li>
|
||||
<li class="col-xs-4 col-sm-3 col-md-2" id="pic-upload" style="display: none;">
|
||||
<input type="hidden" class="form-control" name="cover_path" id="cover_path" value="{$info.cover_path}">
|
||||
<input type="file" id="file_cover_path" style="display: none;" onchange="upload('cover_path')">
|
||||
<a class="pic-add" href="#!" onclick="btnClick('cover_path')" title="上传"></a>
|
||||
</li>
|
||||
{else /}
|
||||
<li class="col-xs-4 col-sm-3 col-md-2" id="pic-image" style="display: none;"></li>
|
||||
<li class="col-xs-4 col-sm-3 col-md-2" id="pic-upload">
|
||||
<input type="hidden" class="form-control" name="cover_path" id="cover_path">
|
||||
<input type="file" id="file_cover_path" style="display: none;" onchange="upload('cover_path')">
|
||||
<a class="pic-add" href="#!" onclick="btnClick('cover_path')" title="上传"></a>
|
||||
</li>
|
||||
{/notempty}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="abstract">摘要</label>
|
||||
<input type="text" class="form-control" name="abstract" id="abstract" placeholder="请输入摘要" value="{$info.abstract}">
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="abstract">标签</label>
|
||||
<input class="form-control js-tags-input" type="text" name="tags" data-height="38px" placeholder="请输入标签" value="{$info.tags}">
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="content">文章内容</label>
|
||||
<textarea id="content" name="content">{$info.content}</textarea>
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="show_time">发布时间</label>
|
||||
<input class="form-control js-datetimepicker" type="text" id="show_time" name="show_time" placeholder="请选择具体时间" value="{$info.show_time}" data-side-by-side="true" data-locale="zh-cn" data-format="YYYY-MM-DD HH:mm:ss" />
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">立即提交</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="profile">
|
||||
<form action="#!" method="post" class="row add-form" onsubmit="return false;">
|
||||
<div class="form-group row col-md-2">
|
||||
<div class="col-xs-6">推荐</div>
|
||||
<div class="col-xs-6">
|
||||
<label class="lyear-switch switch-solid switch-primary">
|
||||
<input type="checkbox" name="is_recommend" {if $info.is_recommend = 1}checked{/if}>
|
||||
<span></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row col-md-2">
|
||||
<div class="col-xs-6">热门</div>
|
||||
<div class="col-xs-6">
|
||||
<label class="lyear-switch switch-solid switch-primary">
|
||||
<input type="checkbox" name="is_hot" {if $info.is_hot = 1}checked{/if}>
|
||||
<span></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row col-md-2">
|
||||
<div class="col-xs-6">顶置</div>
|
||||
<div class="col-xs-6">
|
||||
<label class="lyear-switch switch-solid switch-primary">
|
||||
<input type="checkbox" name="is_top" {if $info.is_top = 1}checked{/if}>
|
||||
<span></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row col-md-2">
|
||||
<div class="col-xs-6">显示</div>
|
||||
<div class="col-xs-6">
|
||||
<label class="lyear-switch switch-solid switch-primary">
|
||||
<input type="checkbox" name="display" {if $info.is_top = 1}checked{/if}>
|
||||
<span></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="abstract">排序</label>
|
||||
<input type="text" class="form-control" name="sort" placeholder="请输入排序" value="{$info.sort}">
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="link_str">外链</label>
|
||||
<input type="text" class="form-control" name="link_str" id="link_str" placeholder="外链" value="{$info.link_str}">
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="keywords">seo关键字</label>
|
||||
<input type="text" class="form-control" id="keywords" name="keywords" placeholder="请输入seo关键字" value="{$info.keywords}">
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="description">seo描述</label>
|
||||
<input type="text" class="form-control" name="description" id="description" placeholder="seo描述" value="{$info.description}">
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">立即提交</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{include file="public/footer"/}
|
||||
<!--select2-->
|
||||
<script src="__ADMIN_PATH__js/select2.min.js"></script>
|
||||
<!--富文本输入框-->
|
||||
<script src="__ADMIN_PATH__js/tinymce/tinymce.min.js"></script>
|
||||
<!--标签-->
|
||||
<script src="__ADMIN_PATH__js/jquery-tags-input/jquery.tagsinput.min.js"></script>
|
||||
<script>
|
||||
$(function () {
|
||||
$('#tag').select2();
|
||||
});
|
||||
$(document).ready(function(){
|
||||
tinymce.init({
|
||||
selector: '#content',
|
||||
language: 'zh_CN',
|
||||
directionality: 'ltl',
|
||||
browser_spellcheck: true,
|
||||
contextmenu: false,
|
||||
height: 480,
|
||||
plugins: [
|
||||
"advlist autolink lists link image charmap print preview anchor",
|
||||
"searchreplace visualblocks code fullscreen",
|
||||
"insertdatetime media table contextmenu paste imagetools wordcount",
|
||||
"code"
|
||||
],
|
||||
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code",
|
||||
images_upload_url: '/admin/files/tinymce',
|
||||
});
|
||||
});
|
||||
/**
|
||||
* 选择文件
|
||||
* @param inputName
|
||||
*/
|
||||
function btnClick(inputName) {
|
||||
$("#file_"+inputName).click()
|
||||
}
|
||||
/**
|
||||
* 异步上传
|
||||
* @param inputName
|
||||
*/
|
||||
function upload(inputName) {
|
||||
var formData = new FormData();
|
||||
formData.append("type",'images');
|
||||
formData.append("file",$("#file_"+inputName)[0].files[0]);
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'/admin/files/upload',
|
||||
data: formData,
|
||||
cache: false,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function (res) {
|
||||
if (res.code == 200){
|
||||
$("#"+inputName).val(res.data.filePath);
|
||||
let html =' <figure>\n' +
|
||||
' <img src="'+res.data.filePath+'" alt="'+res.data.name+'">\n' +
|
||||
' <figcaption>\n' +
|
||||
' <a class="btn btn-round btn-square btn-danger btn-image-delete" href="#!"><i class="mdi mdi-delete"></i></a>\n' +
|
||||
' </figcaption>\n' +
|
||||
' </figure>';
|
||||
$('#pic-image').html(html);
|
||||
$('#pic-image').show().next('li').hide();
|
||||
}else{
|
||||
lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
$(".add-form").submit(function () {
|
||||
let Arr = $('.add-form').serializeArray();
|
||||
let checkResult = true;
|
||||
$.each(Arr,function (index,item) {
|
||||
try {
|
||||
switch (item.name) {
|
||||
case 'category_id':
|
||||
if (!item.value) {
|
||||
throw "栏目分类不能为空";
|
||||
}
|
||||
break;
|
||||
case 'title':
|
||||
if (!item.value) {
|
||||
throw "文章名称不能为空";
|
||||
}
|
||||
break;
|
||||
case 'cover_path':
|
||||
if (!item.value) {
|
||||
throw "主图不能为空";
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
lightyear.notify(error, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
checkResult = false;
|
||||
return false;
|
||||
}
|
||||
})
|
||||
// 检验不通过终止执行
|
||||
if (!checkResult) {
|
||||
return false;
|
||||
}
|
||||
$.post(url="/admin/article/save",$('.add-form').serialize(),function (res) {
|
||||
if (res.code == 200) {lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');setTimeout(function () {location.href='/admin/article/index';},2000)}
|
||||
else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
});
|
||||
return true;
|
||||
})
|
||||
|
||||
//删除事件
|
||||
$('body').on('click','.btn-image-delete',function(){
|
||||
$('#pic-image').hide().next('li').show();
|
||||
$('#cover_path').val('');
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue