refactor: 横幅及导航新增用于回显的链接数据字段
This commit is contained in:
@@ -3,6 +3,7 @@ declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\controller\v1;
|
||||
|
||||
use app\admin\model\v1\ArticleModel;
|
||||
use app\admin\model\v1\SysBannerItemModel;
|
||||
use app\admin\validate\v1\SysBannerItemValidate;
|
||||
|
||||
@@ -64,6 +65,9 @@ class BannerItem
|
||||
return error('横幅不存在');
|
||||
}
|
||||
|
||||
// 组装用于前台回显的链接数据
|
||||
$banner_item['link_echo_data'] = System::getEchoDataBySystemPageUrl($banner_item['link_to'], $banner_item['link']);
|
||||
|
||||
return success('获取成功', $banner_item);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,9 @@ class NavigationItem
|
||||
return error('导航不存在');
|
||||
}
|
||||
|
||||
// 组装用于前台回显的链接数据
|
||||
$nav['link_echo_data'] = System::getEchoDataBySystemPageUrl($nav['link_to'], $nav['link']);
|
||||
|
||||
return success('获取成功', $nav);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,4 +219,29 @@ class System
|
||||
|
||||
return $data->toArray();
|
||||
}
|
||||
|
||||
// 根据系统页面url获取回显数据项
|
||||
static public function getEchoDataBySystemPageUrl($link_to, $link)
|
||||
{
|
||||
if ('custom' == $link_to) return [];
|
||||
|
||||
$data = [];
|
||||
parse_str(parse_url($link, PHP_URL_QUERY), $params);
|
||||
switch ($link_to) {
|
||||
case 'article':
|
||||
$data = ArticleModel::field(['id', 'title' => 'name'])->bypk($params['id'])->find();
|
||||
break;
|
||||
case 'product':
|
||||
$data = ProductModel::field(['id', 'name'])->bypk($params['id'])->find();
|
||||
break;
|
||||
default:
|
||||
return [];
|
||||
break;
|
||||
}
|
||||
return [
|
||||
'id' => $data['id'],
|
||||
'name' => $data['name'],
|
||||
'link' => $link
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user