网站配置
parent
8546a43f9e
commit
4f312527ae
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use App\Services\Auth;
|
||||
use App\Models\GConfig;
|
||||
|
||||
class GConfigController extends AdminController
|
||||
{
|
||||
public function index($ajax_url, $tpl_path)
|
||||
{
|
||||
$table_config['total_column'] = array(
|
||||
'op' => '操作',
|
||||
'name' => '配置名称',
|
||||
'key' => '配置名',
|
||||
'value' => '配置值',
|
||||
'operator_id' => '操作员 ID',
|
||||
'operator_name' => '操作员名称',
|
||||
'operator_email' => '操作员邮箱',
|
||||
'last_update' => '修改时间'
|
||||
);
|
||||
$table_config['default_show_column'] = array();
|
||||
foreach ($table_config['total_column'] as $column => $value) {
|
||||
$table_config['default_show_column'][] = $column;
|
||||
}
|
||||
$table_config['ajax_url'] = $ajax_url;
|
||||
return $this->view()->assign('table_config', $table_config)->fetch($tpl_path);
|
||||
}
|
||||
|
||||
public function edit($key, $tpl_path)
|
||||
{
|
||||
$config = GConfig::find($key);
|
||||
return $this->view()->assign('edit_config', $config)->fetch($tpl_path);
|
||||
}
|
||||
|
||||
public function update($request, $response, $args)
|
||||
{
|
||||
$key = trim($args['key']);
|
||||
$user = Auth::getUser();
|
||||
|
||||
$config = GConfig::find($key);
|
||||
$config->oldvalue = $config->value;
|
||||
$config->value = $request->getParam('value');
|
||||
$config->operator_id = $user->id;
|
||||
$config->operator_name = $user->user_name;
|
||||
$config->operator_email = $user->email;
|
||||
$config->last_update = time();
|
||||
if (!$config->save()) {
|
||||
$rs['ret'] = 0;
|
||||
$rs['msg'] = '修改失败';
|
||||
return $response->write(json_encode($rs));
|
||||
}
|
||||
$rs['ret'] = 1;
|
||||
$rs['msg'] = '修改成功';
|
||||
return $response->write(json_encode($rs));
|
||||
}
|
||||
|
||||
public function telegram($request, $response, $args)
|
||||
{
|
||||
return self::index('telegram/ajax', 'admin/config/telegram/index.tpl');
|
||||
}
|
||||
|
||||
public function telegram_edit($request, $response, $args)
|
||||
{
|
||||
$key = trim($args['key']);
|
||||
return self::edit($key, 'admin/config/telegram/edit.tpl');
|
||||
}
|
||||
|
||||
public function telegram_update($request, $response, $args)
|
||||
{
|
||||
return self::update($request, $response, $args);
|
||||
}
|
||||
|
||||
public function telegram_ajax($request, $response, $args)
|
||||
{
|
||||
$configs = GConfig::where('key', 'LIKE', "%Telegram%")->get();
|
||||
$data = [];
|
||||
foreach ($configs as $config) {
|
||||
$tempdata = [];
|
||||
$tempdata['op'] = '<a class="btn btn-brand" href="/admin/config/telegram/' . $config->key . '/edit">编辑</a>';
|
||||
$tempdata['name'] = $config->name;
|
||||
$tempdata['key'] = $config->key;
|
||||
$tempdata['value'] = $config->value;
|
||||
$tempdata['operator_id'] = $config->operator_id;
|
||||
$tempdata['operator_name'] = $config->operator_name;
|
||||
$tempdata['operator_email'] = $config->operator_email;
|
||||
$tempdata['last_update'] = date('Y-m-d H:i:s', $config->last_update);
|
||||
if (strpos($config->key, '.enable.')) {
|
||||
switch ((int) $config->value) {
|
||||
case 0:
|
||||
$tempdata['value'] = '关闭';
|
||||
break;
|
||||
case 1:
|
||||
$tempdata['value'] = '开启';
|
||||
break;
|
||||
default:
|
||||
$tempdata['value'] = '未知';
|
||||
break;
|
||||
}
|
||||
}
|
||||
$data[] = $tempdata;
|
||||
}
|
||||
$info = [
|
||||
'draw' => $request->getParam('draw'),
|
||||
'recordsTotal' => count($configs),
|
||||
'recordsFiltered' => count($configs),
|
||||
'data' => $data
|
||||
];
|
||||
|
||||
return json_encode($info, true);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\DefaultConfig;
|
||||
|
||||
class GConfig extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connection = 'default';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'gconfig';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'key';
|
||||
|
||||
/**
|
||||
* Indicates if the IDs are auto-incrementing.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $incrementing = false;
|
||||
|
||||
/**
|
||||
* The "type" of the auto-incrementing ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $keyType = 'string';
|
||||
|
||||
public static function recover($user)
|
||||
{
|
||||
$this->oldvalue = $this->value;
|
||||
$this->value = DefaultConfig::default_value($this->key)['value'];
|
||||
$this->operator_id = $user->id;
|
||||
$this->operator_name = ('[恢复默认] - ' . $user->user_name);
|
||||
$this->operator_email = $user->email;
|
||||
$this->last_update = time();
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,119 @@
|
||||
{include file='admin/main.tpl'}
|
||||
|
||||
|
||||
<main class="content">
|
||||
<div class="content-header ui-content-header">
|
||||
<div class="container">
|
||||
<h1 class="content-heading">配置编辑 #{$edit_config->id}</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="col-lg-12 col-sm-12">
|
||||
<section class="content-inner margin-top-no">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-main">
|
||||
<div class="card-inner">
|
||||
|
||||
<div class="form-group form-group-label">
|
||||
<label class="floating-label" for="key">配置名</label>
|
||||
<input class="form-control maxwidth-edit" id="key" type="text" value="{$edit_config->key}" readonly>
|
||||
</div>
|
||||
|
||||
<div class="form-group form-group-label">
|
||||
<label class="floating-label" for="name">配置名称</label>
|
||||
<input class="form-control maxwidth-edit" id="name" type="text" value="{$edit_config->name}" readonly>
|
||||
</div>
|
||||
|
||||
{if $edit_config->comment!=''}
|
||||
<div class="form-group form-group-label">
|
||||
<label class="floating-label" for="comment">配置描述</label>
|
||||
<textarea class="form-control maxwidth-edit" id="comment" rows="4" readonly>{$edit_config->comment}</textarea>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{if strpos($edit_config->key,'.enable.')===false}
|
||||
<div class="form-group form-group-label">
|
||||
<label class="floating-label" for="value">配置值</label>
|
||||
<textarea class="form-control maxwidth-edit" id="value" rows="5">{$edit_config->value}</textarea>
|
||||
</div>
|
||||
{else}
|
||||
<div class="form-group form-group-label">
|
||||
<label for="value">
|
||||
<label class="floating-label" for="value">配置开关</label>
|
||||
<select id="value" class="form-control maxwidth-edit" name="value">
|
||||
<option value="0" {if $edit_config->value=='0'}selected{/if}>关闭</option>
|
||||
<option value="1" {if $edit_config->value=='1'}selected{/if}>开启</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-main">
|
||||
<div class="card-inner">
|
||||
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-md-10 col-md-push-1">
|
||||
<button id="submit" type="submit"
|
||||
class="btn btn-block btn-brand waves-attach waves-light">修改
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{include file='dialog.tpl'}
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
{include file='admin/footer.tpl'}
|
||||
|
||||
|
||||
<script>
|
||||
window.addEventListener('load', () => {
|
||||
function submit() {
|
||||
$.ajax({
|
||||
type: "PUT",
|
||||
url: "/admin/config/telegram/{$edit_config->key}",
|
||||
dataType: "json",
|
||||
data: {
|
||||
value: $$getValue('value')
|
||||
},
|
||||
success: data => {
|
||||
if (data.ret) {
|
||||
$("#result").modal();
|
||||
$$.getElementById('msg').innerHTML = data.msg;
|
||||
window.setTimeout("location.href=top.document.referrer", {$config['jump_delay']});
|
||||
} else {
|
||||
$("#result").modal();
|
||||
$$.getElementById('msg').innerHTML = data.msg;
|
||||
}
|
||||
},
|
||||
error: jqXHR => {
|
||||
$("#result").modal();
|
||||
$$.getElementById('msg').innerHTML = `发生错误:${
|
||||
jqXHR.status
|
||||
}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$("html").keydown(event => {
|
||||
if (event.keyCode == 13) login();
|
||||
});
|
||||
|
||||
$$.getElementById('submit').addEventListener('click', submit);
|
||||
})
|
||||
</script>
|
||||
@ -0,0 +1,41 @@
|
||||
{include file='admin/main.tpl'}
|
||||
|
||||
<main class="content">
|
||||
<div class="content-header ui-content-header">
|
||||
<div class="container">
|
||||
<h1 class="content-heading">Telegram 配置</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="col-lg-12 col-sm-12">
|
||||
<section class="content-inner margin-top-no">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-main">
|
||||
<div class="card-inner">
|
||||
<p>显示表项: {include file='table/checkbox.tpl'}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
{include file='table/table.tpl'}
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{include file='admin/footer.tpl'}
|
||||
|
||||
<script>
|
||||
{include file='table/js_1.tpl'}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
{include file='table/js_2.tpl'}
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
CREATE TABLE IF NOT EXISTS `gconfig` (
|
||||
`key` varchar(50) NOT NULL COMMENT '配置名',
|
||||
`value` text NOT NULL COMMENT '配置值',
|
||||
`oldvalue` text NOT NULL COMMENT '之前的配置值',
|
||||
`name` varchar(128) NOT NULL COMMENT '配置名称',
|
||||
`comment` text NOT NULL COMMENT '配置描述',
|
||||
`operator_id` int(11) NOT NULL COMMENT '操作员 ID',
|
||||
`operator_name` varchar(128) NOT NULL COMMENT '操作员名称',
|
||||
`operator_email` varchar(32) NOT NULL COMMENT '操作员邮箱',
|
||||
`last_update` bigint(20) NOT NULL COMMENT '修改时间',
|
||||
PRIMARY KEY (`key`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='网站配置';
|
||||
Loading…
Reference in New Issue