Browse Source

新增配置页面

master
wanghongjun 3 years ago
parent
commit
2127945dcb
  1. 49
      source/application/admin/controller/setting/Config.php
  2. 2
      source/application/admin/view/pass/pass/index.php
  3. 50
      source/application/admin/view/setting/config/index.php
  4. 39
      source/application/common/dm/Dm.php
  5. 8
      source/application/common/model/Pass.php

49
source/application/admin/controller/setting/Config.php

@ -0,0 +1,49 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\Controller;
use app\common\dm\Dm;
use app\common\model\Pass;
/**
* 配置
* Class Index
* @package app\admin\controller
*/
class Config extends Controller
{
/**
* 清理缓存
* @return mixed
*/
public function index()
{
$dm = new Dm();
if ($this->request->isAjax()) {
$request = $this->request->request();
$threshold = $request['threshold'];
if (empty($threshold)) $this->renderError('请填写阈值');
if (is_numeric($threshold) && $threshold > 0) $this->renderError('阈值必须是数字');
# 修改阈值
$dm->update('bt_config',['value' => $threshold],'"key"='."'threshold'");
return $this->renderSuccess('操作成功');
}
$configList = [];
$configRes = $dm->find("bt_config",' "key" = ' . "'threshold'");
$threshold = $configRes['value'];
return $this->fetch('index', [
'configList' => $configList,
'threshold' => $threshold,
]);
}
}

2
source/application/admin/view/pass/pass/index.php

@ -53,7 +53,7 @@
</tr>
<?php endforeach; else: ?>
<tr>
<td colspan="4" class="am-text-center">暂无记录</td>
<td colspan="11" class="am-text-center">暂无记录</td>
</tr>
<?php endif; ?>
</tbody>

50
source/application/admin/view/setting/config/index.php

@ -0,0 +1,50 @@
<style>
.tpl-form-input {
width: 60px!important;
display: inline-block!important;
text-align: center;
}
.am-checkbox-inline span{
margin-right: 10px;
}
</style>
<div class="row">
<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
<div class="widget am-cf">
<form id="my-form" class="am-form tpl-form-line-form" enctype="multipart/form-data" method="post">
<div class="widget-body">
<fieldset>
<div class="widget-head am-cf">
<div class="widget-title am-fl">预警阈值</div>
</div>
<div class="am-form-group">
<label class="am-u-sm-3 am-form-label form-require"> 阈值 </label>
<div class="am-u-sm-9">
<label class="am-checkbox-inline">
<input type="text" class="tpl-form-input" name="threshold" value="<?= $threshold ?>" required>
</label>
</div>
</div>
<div class="am-form-group">
<div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
<button type="submit" class="j-submit am-btn am-btn-secondary">提交
</button>
</div>
</div>
</fieldset>
</div>
</form>
</div>
</div>
</div>
<script>
$(function () {
/**
* 表单验证提交
* @type {*}
*/
$('#my-form').superForm();
});
</script>

39
source/application/common/dm/Dm.php

@ -72,7 +72,7 @@ class Dm
{
$set = array();
foreach ($data as $key => $value) {
$set[] = $key . '=' . "'{$value}'";
$set[] = '"'.$key.'"' . '=' . "'{$value}'";
}
$tableName = $this->splitTableName($table);
@ -165,6 +165,43 @@ class Dm
return $data;
}
/**
* 查询单条数据
* @param string $table // 查询表名
* @param string $where // 查询条件
* @param string $fields // 查询字段
* @param string $order // 查询排序
* @return array // 返回数组
*/
public function find($table, $where = null, $fields = '*', $order = null)
{
$tableName = $this->splitTableName($table);
$sql = 'SELECT '.$fields.' FROM '.$tableName;
if ($where != null) {
$sql .= ' WHERE '.$where;
}
if ($order != null) {
$sql .= ' ORDER BY '.$order;
}
$sql .= ' LIMIT 1';
$result = dm_exec($this->conn, $sql);
$this->sql = $sql;
$data = array();
while ($row = dm_fetch_array($result)) {
$data = $row;
}
dm_free_result($result);
return $data;
}
/**
* 查询数据总数
* @param string $table // 查询表名

8
source/application/common/model/Pass.php

@ -0,0 +1,8 @@
<?php
namespace app\common\model;
class Pass extends BaseModel
{
public static $unit = [1 => '>', 2 => '<', 3 => '=', 4 => '≥', 5 => '<=', 6 => '!='];
}
Loading…
Cancel
Save