增加配置模板

This commit is contained in:
Anyon 2020-09-22 16:13:29 +08:00
parent fba4c6be5a
commit 9ab2fc8f0b
2 changed files with 82 additions and 17 deletions

View File

@ -3,7 +3,6 @@
namespace app\data\controller; namespace app\data\controller;
use think\admin\Controller; use think\admin\Controller;
use think\admin\storage\LocalStorage;
/** /**
* 应用参数配置 * 应用参数配置
@ -12,6 +11,21 @@ use think\admin\storage\LocalStorage;
*/ */
class Config extends Controller class Config extends Controller
{ {
/**
* 关于我们描述
* @auth true
* @menu true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function about()
{
$this->skey = 'about';
$this->title = '关于我们描述';
$this->__sysdata('content');
}
/** /**
* 微信小程序配置 * 微信小程序配置
* @auth true * @auth true
@ -22,16 +36,12 @@ class Config extends Controller
*/ */
public function wxapp() public function wxapp()
{ {
if ($this->request->isGet()) { $this->title = '微信小程序配置';
$this->title = '微信小程序配置'; $this->__sysconf('wxapp');
$this->fetch();
} else {
$this->__save();
}
} }
/** /**
* 首页轮播图片 * 应用轮播图片
* @menu true * @menu true
* @auth true * @auth true
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
@ -41,28 +51,63 @@ class Config extends Controller
public function slider() public function slider()
{ {
$this->skey = 'slider'; $this->skey = 'slider';
$this->title = '应用轮播图片';
$this->__sysdata($this->skey);
}
/**
* 会员服务协议
* @auth true
* @menu true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function agreement()
{
$this->skey = 'agreement';
$this->title = '会员服务协议';
$this->__sysdata('content');
}
/**
* 显示并保存数据
* @param string $template 模板文件
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function __sysdata($template = 'content')
{
if ($this->request->isGet()) { if ($this->request->isGet()) {
$this->title = '轮播图片管理';
$this->data = sysdata($this->skey); $this->data = sysdata($this->skey);
$this->fetch(); $this->fetch($template);
} else { } elseif ($this->request->isPost()) {
if (sysdata($this->skey, json_decode(input('data'), true))) { if (is_string(input('data'))) {
$this->success('轮播图保存成功!', ''); $data = json_decode(input('data'), true);
} else { } else {
$this->error('轮播图保存失败,请稍候再试!'); $data = $this->request->post();
}
if (sysdata($this->skey, $data) !== false) {
$this->success('内容保存成功!', '');
} else {
$this->error('内容保存失败,请稍候再试!');
} }
} }
} }
/** /**
* 保存配置参数 * 显示并保存配置
* @param string $template 模板文件名称
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
private function __save() private function __sysconf($template = 'wxapp')
{ {
if ($this->request->isPost()) { if ($this->request->isGet()) {
$this->fetch($template);
} elseif ($this->request->isPost()) {
$data = $this->request->post(); $data = $this->request->post();
foreach ($data as $k => $v) sysconf($k, $v); foreach ($data as $k => $v) sysconf($k, $v);
$this->success('配置保存成功!'); $this->success('配置保存成功!');

View File

@ -0,0 +1,20 @@
{extend name="../../admin/view/main"}
{block name="content"}
<div class="think-box-shadow">
<form onsubmit="return false;" data-auto="true" action="{$request->url()}" method="post" class='layui-form layui-card' autocomplete="off">
<div class="layui-card-body padding-30">
<textarea class="layui-hide" name="content">{$data.content|default=''}</textarea>
<div class="hr-line-dashed margin-bottom-20"></div>
</div>
<div class="layui-form-item text-center">
<button class="layui-btn" type="submit">保存配置</button>
</div>
</form>
<script>
require(['ckeditor'], function () {
createEditor('[name="content"]', {height: 500});
});
</script>
</div>
{/block}