Просмотр исходного кода

花掌柜-金刚区默认图标处理

ouyang 1 день назад
Родитель
Сommit
4977c1d575

+ 3 - 4
biz-hd/homePageConfig/classes/HomePageDisplayClass.php

@@ -100,11 +100,10 @@ class HomePageDisplayClass
             $icon = $item['icon'] ?? '';
             $iconUrl = $icon;
             $iconType = intval($item['iconType'] ?? 1);
-            // 默认图标库 preset:N → OSS 静态图完整 URL(与前端默认图库一致)
+            // 默认图标库 preset:N → OSS 静态图完整 URL(与 HomePageModuleClass 图库一致)
             if (preg_match('/^preset:(\d+)$/', $icon, $m)) {
-                $n = intval($m[1]);
-                if ($n >= 1 && $n <= 12) {
-                    $path = 'hhb/images/navGrid-default/navGrid-default' . $n . '.png';
+                $path = HomePageModuleClass::resolveNavPresetIconPath($icon);
+                if ($path !== '') {
                     $formatted = business::formatUploadImg($path);
                     $iconUrl = $formatted['url'] ?? $path;
                 }

+ 39 - 0
biz-hd/homePageConfig/classes/HomePageModuleClass.php

@@ -32,6 +32,10 @@ class HomePageModuleClass
 
     const NAV_OSS_ROOT = 'uploads_home_nav';
     const MAX_NAV_COUNT = 20;
+    /** 默认图标库数量(OSS:hhb/images/navGrid-default/navGrid-default{N}.png) */
+    const NAV_PRESET_ICON_COUNT = 29;
+    /** 默认图标 OSS 路径前缀(不含序号与扩展名) */
+    const NAV_PRESET_ICON_PATH_PREFIX = 'hhb/images/navGrid-default/navGrid-default';
 
     /** 关联:商品 */
     const LINK_GOODS = 2;
@@ -89,6 +93,41 @@ class HomePageModuleClass
 
     // -------------------- 金刚区 --------------------
 
+    /**
+     * 金刚区默认图标库列表(供 hdApp 编辑页拉取,避免前端写死)
+     * @return array [['key'=>'preset:1','path'=>'hhb/...','url'=>'http://...'], ...]
+     */
+    public static function getNavGridPresetIcons()
+    {
+        $list = [];
+        for ($n = 1; $n <= self::NAV_PRESET_ICON_COUNT; $n++) {
+            $path = self::NAV_PRESET_ICON_PATH_PREFIX . $n . '.png';
+            $list[] = [
+                'key' => 'preset:' . $n,
+                'path' => $path,
+                'url' => imgUtil::groupImg($path),
+            ];
+        }
+        return $list;
+    }
+
+    /**
+     * preset:N → OSS 相对路径;非法序号返回空串
+     * @param string $icon
+     * @return string
+     */
+    public static function resolveNavPresetIconPath($icon)
+    {
+        if (!preg_match('/^preset:(\d+)$/', (string)$icon, $m)) {
+            return '';
+        }
+        $n = (int)$m[1];
+        if ($n < 1 || $n > self::NAV_PRESET_ICON_COUNT) {
+            return '';
+        }
+        return self::NAV_PRESET_ICON_PATH_PREFIX . $n . '.png';
+    }
+
     public static function getNavGrid($mainId, $shopId)
     {
         $mainId = intval($mainId);