feature: kpi template

This commit is contained in:
zhuyu 2025-05-15 16:54:50 +08:00
parent 24466054c7
commit 8552683047
9 changed files with 50 additions and 7 deletions

View File

@ -10,6 +10,7 @@ use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
use think\response\Json;
/**
* kpi指标
@ -29,7 +30,6 @@ class Item extends Backend
{
parent::_initialize();
$this->model = new \app\admin\model\kpi\Item;
$this->view->assign("typeList", $this->model->getTypeList());
$this->view->assign("unitList", $this->model->getUnitList());
$this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());
@ -79,6 +79,35 @@ class Item extends Backend
*/
/**
* 查看
*
* @return string|Json
* @throws \think\Exception
* @throws DbException
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if (false === $this->request->isAjax()) {
return $this->view->fetch();
}
//如果发送的来源是 Selectpage则转发到 Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
$list = $this->model
->where($where)
->with('admin')
->order($sort, $order)
->paginate($limit);
$result = ['total' => $list->total(), 'rows' => $list->items()];
return json($result);
}
/**
* 添加
*
@ -110,6 +139,7 @@ class Item extends Backend
}
$group = $this->request->post("group/a");
$params['admin_id'] = $this->auth->id;
$params['group_id'] = $group[0];
$params['create_time'] = date('Y-m-d H:i:s');
$params['update_time'] = date('Y-m-d H:i:s');
@ -165,6 +195,7 @@ class Item extends Backend
}
$group = $this->request->post("group/a");
$params['admin_id'] = $this->auth->id;
$params['group_id'] = $group[0];
$params['update_time'] = date('Y-m-d H:i:s');

View File

@ -82,6 +82,7 @@ class Template extends Backend
$list = $this->model
->where($where)
->with('kpiitem')
->with('admin')
->order($sort, $order)
->paginate($limit);
@ -121,6 +122,7 @@ class Template extends Backend
}
$group = $this->request->post("group/a");
$params['admin_id'] = $this->auth->id;
$params['group_id'] = $group[0];
$params['create_time'] = date('Y-m-d H:i:s');
$params['update_time'] = date('Y-m-d H:i:s');
@ -204,6 +206,7 @@ class Template extends Backend
}
$group = $this->request->post("group/a");
$params['admin_id'] = $this->auth->id;
$params['group_id'] = $group[0];
$params['update_time'] = date('Y-m-d H:i:s');
$result = $row->allowField(true)->save($params);

View File

@ -3,6 +3,7 @@
return [
'Id' => 'ID',
'Admin_id' => '创建人id',
'Admin.nickname' => '昵称',
'Name' => '名称',
'Desc' => '描述',
'Target_value' => '目标值',

View File

@ -3,6 +3,7 @@
return [
'Id' => 'ID',
'Admin_id' => '创建人id',
'Admin.nickname' => '昵称',
'Name' => '名称',
'Desc' => '描述',
'Create_time' => '创建时间',

View File

@ -2,6 +2,7 @@
namespace app\admin\model\kpi;
use app\admin\model\Admin;
use think\Model;
@ -25,7 +26,6 @@ class Item extends Model
// 追加属性
protected $append = [
'type_text',
'unit_text'
];
@ -43,7 +43,10 @@ class Item extends Model
return $list[$value] ?? '';
}
public function admin()
{
return $this->belongsTo(Admin::class, 'admin_id')->setEagerlyType(0);
}
}

View File

@ -2,6 +2,7 @@
namespace app\admin\model\kpi;
use app\admin\model\Admin;
use think\Model;
@ -39,7 +40,10 @@ class Template extends Model
public function admin()
{
return $this->belongsTo(Admin::class, 'admin_id')->setEagerlyType(0);
}
}

View File

@ -26,7 +26,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'admin_id', title: __('Admin_id')},
{field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE'},
{field: 'name', title: __('Name'), operate: 'LIKE'},
{field: 'desc', title: __('Desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'target_value', title: __('Target_value')},

View File

@ -26,7 +26,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'admin_id', title: __('Admin_id')},
{field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE'},
{field: 'name', title: __('Name'), operate: 'LIKE'},
{field: 'desc', title: __('Desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{

View File

@ -36,7 +36,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'expire_start_time', title: __('Expire_start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
{field: 'expire_end_time', title: __('Expire_end_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
{field: 'complete_time', title: __('Complete_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
{field: 'admin.username', title: __('Admin.username'), operate: 'LIKE'},
{field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE'},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
buttons:[
{