作者 lyh

gx路由设置

... ... @@ -30,14 +30,9 @@ if (!function_exists('generateRoute')) {
if(is_array($string)){
$string = $string[0];
}
$last5Chars = substr($string, -5);
if($last5Chars == '.html'){
return strtolower($string);
}else{
$sign = str_replace(".", "", trim(strtolower(preg_replace('/[^\w.]+/', '-', trim($string))), '-'));
return $sign;
}
}
}
... ...
... ... @@ -46,45 +46,44 @@ class RouteMap extends Base
const PATH_MODULE_CATE = 'module_category_route';//扩展模块
const SOURCE_NAV = 'nav';
/**
* 生成路由标识
* @param $title
* @param $source
* @param $source_id
* @param $project_id
* @return string
* @author zbj
* @date 2023/4/17
* @remark :(新增与编辑)处理路由route
* @name :generateRoute
* @author :lyh
* @method :post
* @time :2025/3/12 9:30
* @param :title:路由 source:模块类型 source_id:对应数据id
* @notes :route_len:路由长度; suffix:路由后缀
*/
public static function generateRoute($title, $source, $source_id, $project_id){
if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $title)){
$title = Translate::tran($title, 'en');
//发现路由是.html结尾时,不做任何处理
$last5Chars = substr($title, -5);
if($last5Chars == '.html'){
return $title;
}
if(contains_russian($title)){
//处理其他情况(俄语+中文时翻译为英文)
if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $title) || contains_russian($title)){
$title = Translate::tran($title, 'en');
}
$i=1;
//过滤特殊字符
$sign = generateRoute($title);
//查看当前路由是否存在
$info = self::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first();
$suffix = '';
$last5Chars = substr($sign, -5);
if($last5Chars == '.html'){
return $last5Chars;
}else{
}
$suffix = '';//设置路由后缀
$route_len = 180;//默认设置字符为180
//产品路由新增时,拼接-product
if(empty($info)){
$len = 60;
if($source == self::SOURCE_PRODUCT){
$suffix = '-product';
}
}else{
$len = 180;
$route_len = 65;
}
$length = strlen($sign);
if($length > $len){
$sign = trim(mb_substr($sign, 0, $len, 'UTF-8'),'-');
if($length > $route_len){
$sign = trim(mb_substr($sign, 0, $route_len, 'UTF-8'),'-');
}
$i=1;//路由重复时拼接
$route = $sign.$suffix;
while(self::isExist($route, $source_id, $project_id)){
$route = $sign .'-'.$i.$suffix;
... ... @@ -94,14 +93,12 @@ class RouteMap extends Base
}
/**
* 路由是否存在
* @param $route
* @param $source
* @param $source_id
* @param $project_id
* @return bool
* @author zbj
* @date 2023/4/17
* @remark :验证路由是否重复
* @name :isExist
* @author :lyh
* @method :post
* @time :2025/3/12 9:51
* @param :route:路由 source:模块类型 source_id:对应数据id
*/
protected static function isExist($route, $source_id, $project_id){
$fixed = ['api']; //固定的路由
... ... @@ -113,23 +110,20 @@ class RouteMap extends Base
];
$route = self::where($where)->first();
if($route){
if($route->source_id == $source_id){
return false;
}
if($route->source_id != $source_id){
return true;
}
}
return false;
}
/**
* @param $title
* @param $source
* @param $source_id
* @param int $project_id
* @return bool
* @throws \Exception
* @author zbj
* @date 2023/4/17
* @remark :保存路由
* @name :setRoute
* @author :lyh
* @method :post
* @time :2025/3/12 9:54
* @param :title:路由 source:模块类型 source_id:对应数据id
*/
public static function setRoute($title, $source, $source_id, $project_id = 0){
$route = self::generateRoute($title, $source, $source_id, $project_id);
... ... @@ -137,7 +131,7 @@ class RouteMap extends Base
throw new \Exception('路由生成失败');
}
try {
$route_map = self::where('project_id', $project_id)->where('source_id', $source_id)->where('source', $source)->first();
$route_map = self::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first();
if(!$route_map){
$route_map = new self();
$route_map->source = $source;
... ... @@ -160,17 +154,6 @@ class RouteMap extends Base
}
/**
* @param $route
* @param $project_id
* @return mixed
* @author zbj
* @date 2023/4/17
*/
public function getRouteInfo($route, $project_id){
return self::where('project_id',$project_id)->where('route', $route)->get();
}
/**
* @param $source
* @param $source_id
* @param $project_id
... ... @@ -183,19 +166,6 @@ class RouteMap extends Base
}
/**
* @param $route
* @param $source
* @param int $project_id
* @return mixed
* @author zbj
* @date 2023/4/17
*/
public static function getSourceId($route, $source, $project_id){
return self::where('project_id', $project_id)->where('source', $source)->where('route', $route)->value('source_id');
}
/**
* @param $source
* @param $source_id
* @param $project_id
... ...