feature: kpi item

This commit is contained in:
zhuyu 2025-05-15 16:29:41 +08:00
parent 6d34c446a4
commit 34ae25bf46
4 changed files with 40 additions and 18 deletions

View File

@ -2,8 +2,10 @@
namespace app\admin\controller\kpi;
use app\admin\model\AuthGroup;
use app\common\controller\Backend;
use Exception;
use fast\Tree;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
@ -29,6 +31,35 @@ class Item extends Backend
$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());
$this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
$groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
Tree::instance()->init($groupList);
$groupdata = [];
if ($this->auth->isSuperAdmin()) {
$result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
foreach ($result as $k => $v) {
$groupdata[$v['id']] = $v['name'];
}
} else {
$result = [];
$groups = $this->auth->getGroups();
foreach ($groups as $m => $n) {
$childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id']));
$temp = [];
foreach ($childlist as $k => $v) {
$temp[$v['id']] = $v['name'];
}
$result[__($n['name'])] = $temp;
}
$groupdata = $result;
}
$this->view->assign('groupdata', $groupdata);
}
/**
@ -78,6 +109,8 @@ class Item extends Backend
$this->model->validateFailException()->validate($validate);
}
$group = $this->request->post("group/a");
$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');
@ -112,6 +145,7 @@ class Item extends Backend
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign("groupid", $row['group_id']);
$this->view->assign('row', $row);
return $this->view->fetch();
}
@ -130,7 +164,8 @@ class Item extends Backend
$row->validateFailException()->validate($validate);
}
$group = $this->request->post("group/a");
$params['group_id'] = $group[0];
$params['update_time'] = date('Y-m-d H:i:s');
$result = $row->allowField(true)->save($params);

View File

@ -1,15 +1,9 @@
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
<label class="control-label col-xs-12 col-sm-2">{:__('Group')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-type" data-rule="required" class="form-control selectpicker" name="row[type]">
{foreach name="typeList" item="vo"}
<option value="{$key}" {in name="key" value="0"}selected{/in}>{$vo}</option>
{/foreach}
</select>
{:build_select('group', $groupdata, null, ['class'=>'form-control selectpicker', 'data-rule'=>'required'])}
</div>
</div>
<div class="form-group">

View File

@ -1,15 +1,9 @@
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
<label class="control-label col-xs-12 col-sm-2">{:__('Group')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-type" data-rule="required" class="form-control selectpicker" name="row[type]">
{foreach name="typeList" item="vo"}
<option value="{$key}" {in name="key" value="$row.type"}selected{/in}>{$vo}</option>
{/foreach}
</select>
{:build_select('group', $groupdata, $groupid, ['class'=>'form-control selectpicker', 'data-rule'=>'required'])}
</div>
</div>
<div class="form-group">

View File

@ -27,7 +27,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'admin_id', title: __('Admin_id')},
{field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
{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')},