优化配置模块代码

This commit is contained in:
hdm 2021-11-16 23:54:15 +08:00
parent f9427e6f13
commit 4ee7b043b3
8 changed files with 53 additions and 187 deletions

View File

@ -33,23 +33,11 @@ class Conf extends BaseController
}
}
//添加
//添加/编辑配置项
public function add()
{
$id = empty(get_params('id')) ? 0 : get_params('id');
if ($id > 0) {
$config = Db::name('Config')->where(['id' => $id])->find();
View::assign('config', $config);
}
View::assign('id', $id);
return view();
}
//提交添加
public function post_submit()
{
$param = get_params();
if (request()->isAjax()) {
$param = get_params();
try {
validate(ConfCheck::class)->check($param);
} catch (ValidateException $e) {
@ -62,7 +50,6 @@ class Conf extends BaseController
if ($res) {
add_log('edit', $param['id'], $param);
}
return to_assign();
} else {
$param['create_time'] = time();
@ -70,12 +57,20 @@ class Conf extends BaseController
if ($insertId) {
add_log('add', $insertId, $param);
}
return to_assign();
}
} else {
$id = empty($param['id']) ? 0 : $param['id'];
if ($id > 0) {
$config = Db::name('Config')->where(['id' => $id])->find();
View::assign('config', $config);
}
View::assign('id', $id);
return view();
}
}
//删除
//删除配置项
public function delete()
{
$id = get_params("id");
@ -90,22 +85,11 @@ class Conf extends BaseController
}
}
//编辑配置
//编辑配置信息
public function edit()
{
$id = empty(get_params('id')) ? 0 : get_params('id');
$conf = Db::name('Config')->where('id', $id)->find();
$config = [];
if ($conf['content']) {
$config = unserialize($conf['content']);
}
return view($conf['name'], ['id' => $id, 'config' => $config]);
}
//提交添加
public function conf_submit()
{
$param = get_params();
if (request()->isAjax()) {
$param = get_params();
$data['content'] = serialize($param);
$data['update_time'] = time();
$data['id'] = $param['id'];
@ -116,6 +100,16 @@ class Conf extends BaseController
add_log('edit', $param['id'], $param);
}
return to_assign();
} else {
$id = empty($param['id']) ? 0 : $param['id'];
$conf = Db::name('Config')->where('id', $id)->find();
$config = [];
if ($conf['content']) {
$config = unserialize($conf['content']);
}
View::assign('id', $id);
View::assign('config', $config);
return view($conf['name']);
}
}
}

View File

@ -8,9 +8,7 @@
</td>
<td>
<input type="hidden" name="id" value="{$id}" />
<input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入配置名称"
class="layui-input" {notempty name="$config.title"}
value="{$config.title}" {/notempty}>
<input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入配置名称" lay-reqText="请输入配置名称" class="layui-input" {notempty name="$config.title"} value="{$config.title}" {/notempty}>
</td>
<td class="layui-td-gray2">状态<font>*</font></td>
<td>{if condition="$id eq 0"}
@ -29,7 +27,7 @@
配置标识<font>*</font>
</td>
<td colspan="3">
<input style="width: 300px;" type="text" name="name" placeholder="请输入配置标识" lay-verify="required" autocomplete="off" class="layui-input" {notempty name="$config.name"} value="{$config.name}" {/notempty}>
<input style="width: 300px;" type="text" name="name" lay-verify="required" placeholder="请输入配置标识" lay-reqText="请输入配置标识" autocomplete="off" class="layui-input" {notempty name="$config.name"} value="{$config.name}" {/notempty}>
<span style ="color: red; font-size: 12px; margin-top: 5px;">(注意:新增配置项以后,需要对应新增模板文件,模板文件名称需与标识名称一致,建议复制现有的配置模板文件,然后根据需求修改对应的表单即可)</span>
</td>
</tr>
@ -52,14 +50,13 @@
//监听提交
form.on('submit(webform)', function (data) {
$.ajax({
url: "{:url('home/conf/conf_submit')}",
url: "{:url('home/conf/add')}",
type: 'post',
data: data.field,
success: function (e) {
if (e.code == 0) {
layer.confirm('保存成功,返回列表页吗?', { icon: 3, title: '提示' }, function (index) {
history.back(-1);
layer.close(index);
window.location.href="{:url('home/conf/index')}";
});
} else {
layer.msg(e.msg);

View File

@ -9,8 +9,7 @@
</td>
<td>
<input type="hidden" name="id" value="{$id}">
<input type="text" name="smtp" lay-verify="required" autocomplete="off" placeholder="请输入SMTP服务器地址"
class="layui-input" {notempty name="$config.smtp"} value="{$config.smtp}" {/notempty} style="width:240px;display: inline-block;">
<input type="text" name="smtp" lay-verify="required" autocomplete="off" placeholder="请输入SMTP服务器地址" lay-reqText="请输入SMTP服务器地址" class="layui-input" {notempty name="$config.smtp"} value="{$config.smtp}" {/notempty} style="width:240px;display: inline-block;">
<span style="color:#999; font-size:12px;">QQ邮箱的SMTP服务器地址是smtp.qq.com163邮箱的SMTP服务器地址是smtp.163.com</span>
</td>
</tr>
@ -18,8 +17,7 @@
<td class="layui-td-gray2">协议端口号<font>*</font>
</td>
<td>
<input type="text" name="smtp_port" lay-verify="required" autocomplete="off" placeholder="请输入端口"
class="layui-input" {notempty name="$config.smtp_port"} value="{$config.smtp_port}" {/notempty} style="width:240px;display: inline-block;">
<input type="text" name="smtp_port" lay-verify="required" autocomplete="off" placeholder="请输入端口" lay-reqText="请输入端口" class="layui-input" {notempty name="$config.smtp_port"} value="{$config.smtp_port}" {/notempty} style="width:240px;display: inline-block;">
<span style="color:#999; font-size:12px;">QQ邮箱的ssl协议方式端口号是465/587163邮箱的ssl协议方式端口号是465/994</span>
</td>
</tr>
@ -27,8 +25,7 @@
<td class="layui-td-gray2">邮箱账户<font>*</font>
</td>
<td>
<input type="text" name="smtp_user" lay-verify="required" autocomplete="off" placeholder="请输入邮箱用户名"
class="layui-input" {notempty name="$config.smtp_user"} value="{$config.smtp_user}" {/notempty} style="width:240px;display: inline-block;">
<input type="text" name="smtp_user" autocomplete="off" lay-verify="required" placeholder="请输入邮箱用户名" lay-reqText="请输入邮箱用户名" class="layui-input" {notempty name="$config.smtp_user"} value="{$config.smtp_user}" {/notempty} style="width:240px;display: inline-block;">
<span style="color:#999; font-size:12px;">gougucms@qq.com</span>
</td>
</tr>
@ -47,7 +44,7 @@
<td class="layui-td-gray2">发送人<font>*</font>
</td>
<td>
<input type="text" name="from" lay-verify="required" autocomplete="off" placeholder="请输入要显示的发送者"
<input type="text" name="from" autocomplete="off" lay-verify="required" placeholder="请输入要显示的发送者" lay-reqText="请输入要显示的发送者"
class="layui-input" {notempty name="$config.from"} value="{$config.from}" {/notempty} style="width:240px; display: inline-block;">
<span style="color:#999; font-size:12px;">用于展示给发送方勾股CMS系统管理员</span>
</td>
@ -56,7 +53,7 @@
<td class="layui-td-gray2">显示的邮箱<font>*</font>
</td>
<td>
<input type="text" name="email" lay-verify="required" autocomplete="off" placeholder="请输入要显示的发送者邮箱"
<input type="text" name="email" lay-verify="required" autocomplete="off" placeholder="请输入要显示的发送者邮箱" lay-reqText="请输入要显示的发送者邮箱"
class="layui-input" {notempty name="$config.email"} value="{$config.email}" {/notempty} style="width:240px;display: inline-block;">
<span style="color:#999;font-size:12px;">可以不同于上面的账户用于展示给发送方的邮箱admin@gougucms.com</span>
</td>
@ -86,7 +83,7 @@
//监听提交
form.on('submit(webform)', function (data) {
$.ajax({
url: "{:url('home/conf/conf_submit')}",
url: "{:url('home/conf/edit')}",
type: 'post',
data: data.field,
success: function (e) {

View File

@ -38,6 +38,7 @@
align: 'center'
},{
field: 'title',
width: 200,
title: '配置名称'
}, {
field: 'name',

View File

@ -8,14 +8,12 @@
<td class="layui-td-gray2">开发者</td>
<td>
<input type="hidden" value="{$id}" name="id">
<input type="text" name="author" autocomplete="off" placeholder="请输入开发者"
lay-reqText="请输入开发者" class="layui-input"{notempty name="$config.author"} value="{$config.author}" {/notempty}>
<input type="text" name="author" autocomplete="off" placeholder="请输入开发者" lay-reqText="请输入开发者" class="layui-input"{notempty name="$config.author"} value="{$config.author}" {/notempty}>
</td>
<td class="layui-td-gray2">开发版本号
</td>
<td>
<input type="text" name="version" autocomplete="off" placeholder="请输入版本号"
lay-reqText="请输入版本号" class="layui-input" {notempty name="$config.version"} value="{$config.version}" {/notempty}>
<input type="text" name="version" autocomplete="off" placeholder="请输入版本号" lay-reqText="请输入版本号" class="layui-input" {notempty name="$config.version"} value="{$config.version}" {/notempty}>
</td>
</tr>
</table>
@ -39,7 +37,7 @@
//监听提交
form.on('submit(webform)', function (data) {
$.ajax({
url: "{:url('home/conf/conf_submit')}",
url: "{:url('home/conf/edit')}",
type: 'post',
data: data.field,
success: function (e) {

View File

@ -8,27 +8,23 @@
<td class="layui-td-gray2">Token签发组织</td>
<td>
<input type="hidden" value="{$id}" name="id">
<input type="text" name="iss" autocomplete="off" placeholder="请输入签发组织"
lay-reqText="请输入签发组织" class="layui-input"{notempty name="$config.iss"} value="{$config.iss}" {/notempty}>
<input type="text" name="iss" autocomplete="off" placeholder="请输入签发组织" lay-reqText="请输入签发组织" class="layui-input"{notempty name="$config.iss"} value="{$config.iss}" {/notempty}>
</td>
<td class="layui-td-gray2">Token签发作者
</td>
<td>
<input type="text" name="aud" autocomplete="off" placeholder="请输入签发作者"
lay-reqText="请输入签发作者" class="layui-input" {notempty name="$config.aud"} value="{$config.aud}" {/notempty}>
<input type="text" name="aud" autocomplete="off" placeholder="请输入签发作者" lay-reqText="请输入签发作者" class="layui-input" {notempty name="$config.aud"} value="{$config.aud}" {/notempty}>
</td>
</tr>
<tr>
<td class="layui-td-gray2">Token Secrect</td>
<td>
<input type="text" name="secrect" autocomplete="off" placeholder="请输入secrect"
lay-reqText="请输入secrect" class="layui-input"{notempty name="$config.secrect"} value="{$config.secrect}" {/notempty}>
<input type="text" name="secrect" autocomplete="off" placeholder="请输入secrect" lay-reqText="请输入secrect" class="layui-input"{notempty name="$config.secrect"} value="{$config.secrect}" {/notempty}>
</td>
<td class="layui-td-gray2">Token过期时间
</td>
<td>
<input type="text" name="exptime" autocomplete="off" placeholder="请输入过期时间"
lay-reqText="请输入过期时间" class="layui-input" {notempty name="$config.exptime"} value="{$config.exptime}" {/notempty}>
<input type="text" name="exptime" autocomplete="off" placeholder="请输入过期时间" lay-reqText="请输入过期时间" class="layui-input" {notempty name="$config.exptime"} value="{$config.exptime}" {/notempty}>
</td>
</tr>
</table>
@ -60,7 +56,7 @@
//监听提交
form.on('submit(webform)', function (data) {
$.ajax({
url: "{:url('home/conf/conf_submit')}",
url: "{:url('home/conf/edit')}",
type: 'post',
data: data.field,
success: function (e) {

View File

@ -9,14 +9,12 @@
</td>
<td>
<input type="hidden" name="id" value="{$id}">
<input type="text" name="admin_title" lay-verify="required" autocomplete="off" placeholder="请输入系统名称"
lay-reqText="请输入系统名称" class="layui-input" {notempty name="$config.admin_title"} value="{$config.admin_title}" {/notempty}>
<input type="text" name="admin_title" lay-verify="required" autocomplete="off" placeholder="请输入系统名称" lay-reqText="请输入系统名称" class="layui-input" {notempty name="$config.admin_title"} value="{$config.admin_title}" {/notempty}>
</td>
<td class="layui-td-gray2">网站名称<font>*</font>
</td>
<td>
<input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入网站平台名称"
lay-reqText="请输入网站名称" class="layui-input" {notempty name="$config.title"} value="{$config.title}" {/notempty}>
<input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入网站平台名称" lay-reqText="请输入网站名称" class="layui-input" {notempty name="$config.title"} value="{$config.title}" {/notempty}>
</td>
<td rowspan="3" class="layui-td-gray2">系统LOGO</td>
<td rowspan="3" style="width: 240px;">
@ -34,34 +32,29 @@
<td class="layui-td-gray2">网站域名<font>*</font>
</td>
<td>
<input type="text" name="domain" lay-verify="required" autocomplete="off" placeholder="请输入网站域名"
lay-reqText="请输入网站域名" class="layui-input" {notempty name="$config.domain"} value="{$config.domain}" {/notempty}>
<input type="text" name="domain" lay-verify="required" autocomplete="off" placeholder="请输入网站域名" lay-reqText="请输入网站域名" class="layui-input" {notempty name="$config.domain"} value="{$config.domain}" {/notempty}>
</td>
<td class="layui-td-gray2">ICP备案号</td>
<td>
<input type="text" name="icp" autocomplete="off" placeholder="请输入ICP备案号" class="layui-input"
{notempty name="$config.icp"} value="{$config.icp}" {/notempty}>
<input type="text" name="icp" autocomplete="off" placeholder="请输入ICP备案号" class="layui-input" {notempty name="$config.icp"} value="{$config.icp}" {/notempty}>
</td>
</tr>
<tr>
<td class="layui-td-gray2">SEO关键词<font>*</font>
</td>
<td>
<input type="text" name="keywords" lay-verify="required" autocomplete="off" placeholder="多个关键词用“,”隔开"
lay-reqText="请输入SEO关键字" class="layui-input" {notempty name="$config.keywords"} value="{$config.keywords}" {/notempty}>
<input type="text" name="keywords" lay-verify="required" autocomplete="off" placeholder="多个关键词用“,”隔开" lay-reqText="请输入SEO关键字" class="layui-input" {notempty name="$config.keywords"} value="{$config.keywords}" {/notempty}>
</td>
<td class="layui-td-gray2">公安备案号</td>
<td>
<input type="text" name="beian" autocomplete="off" placeholder="请输入公安备案号" class="layui-input"
{notempty name="$config.beian"} value="{$config.beian}" {/notempty}>
<input type="text" name="beian" autocomplete="off" placeholder="请输入公安备案号" class="layui-input" {notempty name="$config.beian"} value="{$config.beian}" {/notempty}>
</td>
</tr>
<tr>
<td class="layui-td-gray2">SEO描述<font>*</font>
</td>
<td colspan="5">
<textarea name="desc" lay-verify="required" placeholder="请输入网站描述" lay-reqText="请输入网站描述"
class="layui-textarea">{notempty name="$config.desc"}{$config.desc} {/notempty}</textarea>
<textarea name="desc" lay-verify="required" placeholder="请输入网站描述" lay-reqText="请输入网站描述" class="layui-textarea">{notempty name="$config.desc"}{$config.desc} {/notempty}</textarea>
</td>
</tr>
<tr>
@ -73,14 +66,12 @@
<tr>
<td class="layui-td-gray2">版权信息</td>
<td colspan="3">
<input type="text" name="copyright" autocomplete="off" placeholder="请输入版权信息"
lay-reqText="请输入版权信息" class="layui-input"{notempty name="$config.copyright"} value="{$config.copyright}" {/notempty}>
<input type="text" name="copyright" autocomplete="off" placeholder="请输入版权信息" lay-reqText="请输入版权信息" class="layui-input"{notempty name="$config.copyright"} value="{$config.copyright}" {/notempty}>
</td>
<td class="layui-td-gray2">代码版本号<font>*</font>
</td>
<td>
<input type="text" lay-verify="required" name="version" autocomplete="off" placeholder="请输入版本号"
lay-reqText="请输入版本号" class="layui-input" {notempty name="$config.version"} value="{$config.version}" {/notempty}>
<input type="text" lay-verify="required" name="version" autocomplete="off" placeholder="请输入版本号" lay-reqText="请输入版本号" class="layui-input" {notempty name="$config.version"} value="{$config.version}" {/notempty}>
</td>
</tr>
</table>
@ -122,7 +113,7 @@
//监听提交
form.on('submit(webform)', function (data) {
$.ajax({
url: "{:url('home/conf/conf_submit')}",
url: "{:url('home/conf/edit')}",
type: 'post',
data: data.field,
success: function (e) {

View File

@ -1,108 +0,0 @@
{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<form class="layui-form body-content">
<h3 style="height:36px">微信配置</h3>
<table class="layui-table layui-table-form">
<tr>
<td class="layui-td-gray3">token<font>*</font></td>
<td>
<input type="hidden" value="{$id}" name="id">
<input type="text" name="token" lay-verify="required" autocomplete="off" placeholder="请输入Token" class="layui-input" {notempty name="$config.token"} value="{$config.token}" {/notempty}>
</td>
<td class="layui-td-gray3">登录回调地址<font>*</font></td>
<td>
<input type="text" name="login_back_url" lay-verify="required" autocomplete="off" placeholder="请输入微信登录回调地址" class="layui-input" {notempty name="$config.login_back_url"} value="{$config.login_back_url}" {/notempty}>
</td>
</tr>
<tr>
<td class="layui-td-gray3">公众号appid<font>*</font></td>
<td>
<input type="text" name="appid" lay-verify="required" autocomplete="off" placeholder="请输入appID" class="layui-input" {notempty name="$config.appid"} value="{$config.appid}" {/notempty}>
</td>
<td class="layui-td-gray3">公众号appsecret<font>*</font></td>
<td>
<input type="text" name="appsecret" lay-verify="required" autocomplete="off" placeholder="请输入secretey" class="layui-input" {notempty name="$config.appsecret"} value="{$config.appsecret}" {/notempty}>
</td>
</tr>
<tr>
<td class="layui-td-gray3">支付商户号</td>
<td>
<input type="text" name="mchid" autocomplete="off" placeholder="请输入微信支付商户号" class="layui-input" {notempty name="$config.mchid"} value="{$config.mchid}" {/notempty}>
</td>
<td class="layui-td-gray3">支付API密钥</td>
<td>
<input type="text" name="secrect_key" autocomplete="off" placeholder="请输入微信支付API密钥" class="layui-input"
{notempty name="$config.secrect_key"} value="{$config.secrect_key}" {/notempty}>
</td>
</tr>
<tr>
<td class="layui-td-gray3">支付证书路径</td>
<td>
<input type="text" name="cert_url" autocomplete="off" placeholder="请输入微信支付证书路径" class="layui-input"
{notempty name="$config.cert_url"} value="{$config.cert_url}" {/notempty}>
</td>
<td class="layui-td-gray3">支付回调地址</td>
<td>
<input type="text" name="pay_back_url" autocomplete="off" placeholder="请输入微信支付回调地址" class="layui-input" {notempty name="$config.pay_back_url"} value="{$config.pay_back_url}" {/notempty}>
</td>
</tr>
<tr>
<td class="layui-td-gray3">小程序appid<font>*</font></td>
<td>
<input type="text" name="xcx_appid" lay-verify="required" autocomplete="off" placeholder="请输入小程序appid" class="layui-input" {notempty name="$config.xcx_appid"} value="{$config.xcx_appid}" {/notempty}>
</td>
<td class="layui-td-gray3">小程序appsecret<font>*</font></td>
<td>
<input type="text" name="xcx_appsecret" lay-verify="required" autocomplete="off" placeholder="请输入小程序appsecret" class="layui-input" {notempty name="$config.xcx_appsecret"} value="{$config.xcx_appsecret}" {/notempty}>
</td>
</tr>
</table>
<div style="padding: 10px 0">
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
<button lay-event="back" class="layui-btn layui-btn-primary">返回</button>
</div>
</form>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script>
function init(layui) {
var form = layui.form,
layer = layui.layer;
//监听提交
form.on('submit(webform)', function(data) {
$.ajax({
url: "{:url('home/conf/conf_submit')}",
type: 'post',
data: data.field,
success: function(e) {
if (e.code == 0) {
layer.confirm('保存成功,关闭本页面吗?', {
icon: 3,
title: '提示'
}, function(index) {
history.back(-1);
layer.close(index);
});
} else {
layer.msg(e.msg);
}
}
})
return false;
});
//监听返回
$('.body-content').on('click', '[lay-event="back"]', function () {
history.back(-1);
return false;
});
}
</script>
{include file="common/layui" base="base" extend="[]" callback="init" /}
{/block}
<!-- /脚本 -->