作者 景琛

雷达维度字数限制

@@ -3,6 +3,9 @@ @@ -3,6 +3,9 @@
3 namespace app\admin\controller; 3 namespace app\admin\controller;
4 4
5 use app\common\controller\Backend; 5 use app\common\controller\Backend;
  6 +use think\Db;
  7 +use think\exception\PDOException;
  8 +use think\exception\ValidateException;
6 9
7 /** 10 /**
8 * 雷达维度管理 11 * 雷达维度管理
@@ -67,4 +70,47 @@ class Radar extends Backend @@ -67,4 +70,47 @@ class Radar extends Backend
67 return $this->view->fetch(); 70 return $this->view->fetch();
68 } 71 }
69 72
  73 + /**
  74 + * 添加
  75 + *
  76 + * @return string
  77 + * @throws \think\Exception
  78 + */
  79 + public function add()
  80 + {
  81 + if (false === $this->request->isPost()) {
  82 + return $this->view->fetch();
  83 + }
  84 + $params = $this->request->post('row/a');
  85 + if (empty($params)) {
  86 + $this->error(__('Parameter %s can not be empty', ''));
  87 + }
  88 + $params = $this->preExcludeFields($params);
  89 +
  90 + if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  91 + $params[$this->dataLimitField] = $this->auth->id;
  92 + }
  93 + $result = false;
  94 + Db::startTrans();
  95 + try {
  96 + //是否采用模型验证
  97 + if ($this->modelValidate) {
  98 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  99 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  100 + $this->model->validateFailException()->validate($validate);
  101 + }
  102 + $result = $this->model->allowField(true)->save($params);
  103 + $id = $this->model->id;
  104 + $this->model->save(['weigh'=>$id],['id'=>$id]);
  105 + Db::commit();
  106 + } catch (ValidateException|PDOException|Exception $e) {
  107 + Db::rollback();
  108 + $this->error($e->getMessage());
  109 + }
  110 + if ($result === false) {
  111 + $this->error(__('No rows were inserted'));
  112 + }
  113 + $this->success();
  114 + }
  115 +
70 } 116 }
@@ -10,18 +10,21 @@ class Radar extends Validate @@ -10,18 +10,21 @@ class Radar extends Validate
10 * 验证规则 10 * 验证规则
11 */ 11 */
12 protected $rule = [ 12 protected $rule = [
  13 + 'title'=> 'require|max:4',
13 ]; 14 ];
14 /** 15 /**
15 * 提示消息 16 * 提示消息
16 */ 17 */
17 protected $message = [ 18 protected $message = [
  19 + 'title.require' => '名称必填',
  20 + 'title.max' => '长度不超过4个字符',
18 ]; 21 ];
19 /** 22 /**
20 * 验证场景 23 * 验证场景
21 */ 24 */
22 protected $scene = [ 25 protected $scene = [
23 - 'add' => [],  
24 - 'edit' => [], 26 + 'add' => ['title'],
  27 + 'edit' => ['title'],
25 ]; 28 ];
26 29
27 } 30 }
@@ -6,12 +6,12 @@ @@ -6,12 +6,12 @@
6 <input id="c-title" class="form-control" name="row[title]" type="text"> 6 <input id="c-title" class="form-control" name="row[title]" type="text">
7 </div> 7 </div>
8 </div> 8 </div>
9 - <div class="form-group">  
10 - <label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>  
11 - <div class="col-xs-12 col-sm-8">  
12 - <input id="c-weigh" class="form-control" name="row[weigh]" type="number">  
13 - </div>  
14 - </div> 9 +<!-- <div class="form-group">-->
  10 +<!-- <label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>-->
  11 +<!-- <div class="col-xs-12 col-sm-8">-->
  12 +<!-- <input id="c-weigh" class="form-control" name="row[weigh]" type="number">-->
  13 +<!-- </div>-->
  14 +<!-- </div>-->
15 <div class="form-group layer-footer"> 15 <div class="form-group layer-footer">
16 <label class="control-label col-xs-12 col-sm-2"></label> 16 <label class="control-label col-xs-12 col-sm-2"></label>
17 <div class="col-xs-12 col-sm-8"> 17 <div class="col-xs-12 col-sm-8">
@@ -6,12 +6,12 @@ @@ -6,12 +6,12 @@
6 <input id="c-title" class="form-control" name="row[title]" type="text" value="{$row.title|htmlentities}"> 6 <input id="c-title" class="form-control" name="row[title]" type="text" value="{$row.title|htmlentities}">
7 </div> 7 </div>
8 </div> 8 </div>
9 - <div class="form-group">  
10 - <label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>  
11 - <div class="col-xs-12 col-sm-8">  
12 - <input id="c-weigh" class="form-control" name="row[weigh]" type="number" value="{$row.weigh|htmlentities}">  
13 - </div>  
14 -</div> 9 +<!-- <div class="form-group">-->
  10 +<!-- <label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>-->
  11 +<!-- <div class="col-xs-12 col-sm-8">-->
  12 +<!-- <input id="c-weigh" class="form-control" name="row[weigh]" type="number" value="{$row.weigh|htmlentities}">-->
  13 +<!-- </div>-->
  14 +<!--</div>-->
15 <div class="form-group layer-footer"> 15 <div class="form-group layer-footer">
16 <label class="control-label col-xs-12 col-sm-2"></label> 16 <label class="control-label col-xs-12 col-sm-2"></label>
17 <div class="col-xs-12 col-sm-8"> 17 <div class="col-xs-12 col-sm-8">