Skip to content

Commit

Permalink
修复jason1571发现的问题
Browse files Browse the repository at this point in the history
修复jason1571发现的问题
  • Loading branch information
ciniran committed Aug 21, 2018
1 parent 5e81b66 commit cdbfca2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
"type": "yii2-extension",
"keywords": ["yii2","extension","dic","dictionary","wordbook"],
"license": "MIT",
"minimum-stability": "stable",
"version": "1.0.1",
"authors": [
{
"name": "xiebo",
"email": "[email protected]"
}
],
"require": {
"minimum-stability": "stable",
"version": "1.0.2",
"require":
{
"yiisoft/yii2": "*"
},
"autoload": {
Expand Down
43 changes: 22 additions & 21 deletions service/SysDic.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ public static function getKey($key, $status = false)
self::initKeys();
}
$keys = self::$dicKeys;
if(!isset($keys[$key])){
if (!isset($keys[$key])) {
throw new Exception(Yii::t('dic', "Not find the key: '{key}' , in system dic", ['key' => $key]));
}
$result = $keys[$key];
if (!$result) {
return null;
}
if(!$status){
if (!$status) {
//去掉禁用的
$result = array_filter($result,function($item){
if ($item['status'] == 1) {
return true;
}else{
return false;
}
});
$result = array_filter($result, function ($item) {
if ($item['status'] == 1) {
return true;
} else {
return false;
}
});

}
return array_column($result, 'name', 'value');
Expand Down Expand Up @@ -118,25 +118,28 @@ public static function getKeyFromDb()
$res = [];
foreach ($keyArrays as $key => $value) {
if ($value['pid']) {
if(isset($res[$value['pid']]))
{
if (isset($res[$value['pid']])) {
$res[$value['pid']]['subKeys'][] = $value;
}else{
throw new Exception(Yii::t('dic','To ensure that the parent entries are added to the database first, modify the data entry order!'));
} else {
throw new Exception(Yii::t('dic', 'To ensure that the parent entries are added to the database first, modify the data entry order!'));
}
} else {
$res[$value['id']] = $value;
}
}
$result = [];
foreach ($res as $item) {
$sort = array_column($item['subKeys'], 'sort');
array_multisort($sort, SORT_DESC, $item['subKeys']);
$temp = [];
foreach ($item['subKeys'] as $v) {
$temp[$v['id']] = $v;
if (isset($item['subKeys'])) {
$sort = array_column($item['subKeys'], 'sort');
array_multisort($sort, SORT_DESC, $item['subKeys']);
$temp = [];
foreach ($item['subKeys'] as $v) {
$temp[$v['id']] = $v;
}
$result[$item['value']] = $temp;
} else {
$result[$item['value']] = null;
}
$result[$item['value']] = $temp;
}
Yii::$app->cache->set('DicToolsAllKey', $result);
self::$dicKeys = $result;
Expand All @@ -145,6 +148,4 @@ public static function getKeyFromDb()
}




}
6 changes: 4 additions & 2 deletions views/default/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $searchModel ciniran\dic\models\SystemDicQuery */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('dic', 'System Dics');
$this->params['breadcrumbs'][] = $this->title;
$url = Url::to(['/dic/default/sub']);
$this->registerJs("
$('.modal').on('hidden.bs.modal', function() {
$(this).removeData('bs.modal');
});
var url = '{$url}';
// 对象绑定点击事件
$('#main-grid >table >tbody >tr >td:not(\".action-column\")').on('click',function (event) {
var key = $(this).parent().attr('data-key');
// 刷新请求,第一参数,将要刷新的dom节点,data:{}json对象传参数
$('.modal').modal({
'show':true,
'remote':'/dic/default/sub?id='+key,
'remote':url + '?id=' + key,
});
// $.pjax.reload({container:\"#countries\",data:{'key':key}});
});"
Expand Down

0 comments on commit cdbfca2

Please sign in to comment.