作者 刘朕

日记类型优化

@@ -3,5 +3,6 @@ @@ -3,5 +3,6 @@
3 return [ 3 return [
4 'Id' => 'ID', 4 'Id' => 'ID',
5 'Type' => '日记类型', 5 'Type' => '日记类型',
  6 + 'Weigh' => '排序',
6 'Image' => '图标' 7 'Image' => '图标'
7 ]; 8 ];
@@ -27,8 +27,15 @@ class Type extends Model @@ -27,8 +27,15 @@ class Type extends Model
27 protected $append = [ 27 protected $append = [
28 28
29 ]; 29 ];
30 -  
31 30
  31 +
  32 + protected static function init()
  33 + {
  34 + self::afterInsert(function ($row) {
  35 + $pk = $row->getPk();
  36 + $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  37 + });
  38 + }
32 39
33 40
34 41
@@ -6,6 +6,12 @@ @@ -6,6 +6,12 @@
6 <input id="c-type" data-rule="required" class="form-control" name="row[type]" type="text"> 6 <input id="c-type" data-rule="required" class="form-control" name="row[type]" 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" data-rule="required" class="form-control" name="row[weigh]" type="number" value="0">
  13 + </div>
  14 + </div>
9 <!--<div class="form-group">--> 15 <!--<div class="form-group">-->
10 <!--<label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>--> 16 <!--<label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>-->
11 <!--<div class="col-xs-12 col-sm-8">--> 17 <!--<div class="col-xs-12 col-sm-8">-->
@@ -6,6 +6,12 @@ @@ -6,6 +6,12 @@
6 <input id="c-type" data-rule="required" class="form-control" name="row[type]" type="text" value="{$row.type|htmlentities}"> 6 <input id="c-type" data-rule="required" class="form-control" name="row[type]" type="text" value="{$row.type|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" data-rule="required" class="form-control" name="row[weigh]" type="number" value="{$row.weigh|htmlentities}">
  13 + </div>
  14 + </div>
9 <!--<div class="form-group">--> 15 <!--<div class="form-group">-->
10 <!--<label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>--> 16 <!--<label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>-->
11 <!--<div class="col-xs-12 col-sm-8">--> 17 <!--<div class="col-xs-12 col-sm-8">-->
@@ -28,6 +28,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -28,6 +28,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
28 {field: 'id', title: __('Id')}, 28 {field: 'id', title: __('Id')},
29 // {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image}, 29 // {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
30 {field: 'type', title: __('Type'), operate: 'LIKE'}, 30 {field: 'type', title: __('Type'), operate: 'LIKE'},
  31 + {field: 'weigh', title: __('Weigh'), operate: false},
31 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} 32 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
32 ] 33 ]
33 ] 34 ]