浏览代码

Merge branch 'feature/v4.8.31' of https://jygit.jydev.jianyu360.cn/qmx/jy into feature/v4.8.31

wangchuanjin 2 年之前
父节点
当前提交
9720d33b23
共有 2 个文件被更改,包括 47 次插入38 次删除
  1. 41 32
      src/jfw/tag/menu.go
  2. 6 6
      src/web/templates/common/pchead.html

+ 41 - 32
src/jfw/tag/menu.go

@@ -8,22 +8,22 @@ import (
 )
 
 const (
-	mainSite  = "main"  //剑鱼主站
-	brandFlag = "brand" //品牌网站
-	infoFlag  = "info"  //资讯网站
+	mainSite  = iota //剑鱼主站
+	brandFlag        //品牌网站
+	infoFlag         //资讯网站
 
 	cacheKey = "jyMenuCache"
 )
 
 type MenuItem struct {
-	Title    string   `json:"title"` // 标题文字
-	Style    string   `json:"style"` // css样式
-	Link     string   `json:"link"`  // 跳转连接
-	Tag      string   `json:"tag"`   // 节点设置
-	Icon     string   `json:"icon"`  // 图标
-	Attr     string   `json:"attr"`  // 节点属性
-	Site     []string `json:"site"`
-	Position []string `json:"position"`
+	Title      string `json:"title"` // 标题文字
+	Style      string `json:"style"` // css样式
+	Link       string `json:"link"`  // 跳转连接
+	Tag        string `json:"tag"`   // 节点设置
+	Icon       string `json:"icon"`  // 图标
+	Attr       string `json:"attr"`  // 节点属性
+	TopMenu    []int  `json:"top_menu"`
+	BottomLink []int  `json:"bottom_link"`
 }
 
 type TopMenuItem struct {
@@ -33,9 +33,9 @@ type TopMenuItem struct {
 }
 
 type MenuCache struct {
-	AllMenu     []*TopMenuItem            //所有菜单
-	SiteMenuMap map[string][]*TopMenuItem //顶部
-	BottomLink  map[string][]*TopMenuItem //底部
+	AllMenu       []*TopMenuItem         //所有菜单
+	TopMenuMap    map[int][]*TopMenuItem //顶部
+	BottomLinkMap map[int][]*TopMenuItem //底部
 }
 
 // AllMenuCache 剑鱼所有菜单
@@ -59,23 +59,23 @@ func AllMenuCache() (cache *MenuCache) {
 		log.Println("Menu Unmarshal err:", err)
 		return
 	}
-	cache.BottomLink, cache.SiteMenuMap = map[string][]*TopMenuItem{}, map[string][]*TopMenuItem{}
+	cache.BottomLinkMap, cache.TopMenuMap = map[int][]*TopMenuItem{}, map[int][]*TopMenuItem{}
 	for _, menu := range cache.AllMenu {
-		if len(menu.Site) == 0 {
+		if len(menu.TopMenu) == 0 {
 			//默认主站展示
-			cache.SiteMenuMap[mainSite] = append(cache.SiteMenuMap[mainSite], menu)
+			cache.TopMenuMap[mainSite] = append(cache.TopMenuMap[mainSite], menu)
 		} else {
-			for _, value := range menu.Site {
-				cache.SiteMenuMap[value] = append(cache.SiteMenuMap[value], menu)
+			for _, value := range menu.TopMenu {
+				cache.TopMenuMap[value] = append(cache.TopMenuMap[value], menu)
 			}
 		}
 
-		if len(menu.Position) == 0 {
+		if len(menu.BottomLink) == 0 {
 			//默认主站底部展示
-			cache.BottomLink[mainSite] = append(cache.BottomLink[mainSite], menu)
+			cache.BottomLinkMap[mainSite] = append(cache.BottomLinkMap[mainSite], menu)
 		} else {
-			for _, value := range menu.Position {
-				cache.BottomLink[value] = append(cache.BottomLink[value], menu)
+			for _, value := range menu.BottomLink {
+				cache.BottomLinkMap[value] = append(cache.BottomLinkMap[value], menu)
 			}
 		}
 	}
@@ -85,7 +85,7 @@ func AllMenuCache() (cache *MenuCache) {
 }
 
 // GetSite 获取当前地址所属站点
-func (mc *MenuCache) GetSite(url string) string {
+func (mc *MenuCache) GetSite(url string, isTopMenu bool) int {
 	//配置文件
 	if url == "/" {
 		return mainSite
@@ -94,15 +94,24 @@ func (mc *MenuCache) GetSite(url string) string {
 	}
 
 	//
-	var sites []string
+	var sites []int
 	for _, item := range mc.AllMenu {
 		if strings.HasPrefix(item.Link, url) {
-			sites = item.Site
+			if isTopMenu {
+				sites = item.TopMenu
+			} else {
+				sites = item.BottomLink
+			}
+
 			break
 		}
 		for _, c := range item.Child {
 			if strings.HasPrefix(c.Link, url) {
-				sites = c.Site
+				if isTopMenu {
+					sites = item.TopMenu
+				} else {
+					sites = item.BottomLink
+				}
 				break
 			}
 		}
@@ -115,25 +124,25 @@ func (mc *MenuCache) GetSite(url string) string {
 
 type SiteMenu struct {
 	MenuList []*TopMenuItem
-	Site     string // 0:剑鱼标讯官网 1:品牌网站 2:资讯
+	Site     int // 0:剑鱼标讯官网 1:品牌网站 2:资讯
 }
 
 // TopMenu 获取当前站点顶部导航
 func TopMenu(url string) *SiteMenu {
 	cacheMenu := AllMenuCache()
-	site := cacheMenu.GetSite(url)
+	site := cacheMenu.GetSite(url, true)
 	return &SiteMenu{
 		Site:     site,
-		MenuList: cacheMenu.SiteMenuMap[site],
+		MenuList: cacheMenu.TopMenuMap[site],
 	}
 }
 
 // BottomLink 获取当前站点底部链接
 func BottomLink(url string) (rData *SiteMenu) {
 	cacheMenu := AllMenuCache()
-	site := cacheMenu.GetSite(url)
+	site := cacheMenu.GetSite(url, false)
 	return &SiteMenu{
 		Site:     site,
-		MenuList: cacheMenu.BottomLink[site],
+		MenuList: cacheMenu.BottomLinkMap[site],
 	}
 }

+ 6 - 6
src/web/templates/common/pchead.html

@@ -3,13 +3,13 @@
 {{$TopMenu := JyTopMenu .Request.URL.Path}}
 <section class="public-nav" id="public-nav" style="display: none">
   <div class="advertising_position">
-    {{if eq $TopMenu.Site "brand"}}
+    {{if eq $TopMenu.Site 1}}
     <div class="advertising_position_index">
       <img src="{{Msg "seo" "cdn"}}/images/index/new/index_bg.png?v={{Msg "seo" "version"}}" alt="" class="one" onclick="golink('index')">
       <img src="{{Msg "seo" "cdn"}}/images/index/new/xyzx_bg.png?v={{Msg "seo" "version"}}" alt="" class="two" onclick="golink('zx')">
     </div>
     {{end}}
-    {{if eq $TopMenu.Site "main"}}
+    {{if eq $TopMenu.Site 0}}
     <div class="advertising_position_brand">
       <img src="{{Msg "seo" "cdn"}}/images/index/new/brand_bg.png?v={{Msg "seo" "version"}}" alt="" class="one" onclick="golink('brand')">
       <img src="{{Msg "seo" "cdn"}}/images/index/new/xyzx_bg.png?v={{Msg "seo" "version"}}" alt="" class="two" onclick="golink('zx')">
@@ -25,23 +25,23 @@
         </a>
         <div class="logo_desc">
           <div class="line"></div>
-          {{if eq $TopMenu.Site "main"}}
+          {{if eq $TopMenu.Site 0}}
           <p class="index">标讯主站</p>
           {{end}}
-          {{if eq $TopMenu.Site "brand"}}
+          {{if eq $TopMenu.Site 1}}
           <p class="brand">品牌官网</p>
           {{end}}
           <div class="line"></div>
         </div>
         <div class="btn_box">
-          {{if ne $TopMenu.Site "main"}}
+          {{if ne $TopMenu.Site 0}}
           <div class="brand" onclick="golink('index')">
             <img data-theme="dark" src='{{Msg "seo" "cdn"}}/images/index/new/book.png?v={{Msg "seo" "version"}}' alt="" />
             <img data-theme="light" src='{{Msg "seo" "cdn"}}/images/index/new/book1.png?v={{Msg "seo" "version"}}' alt="" />
             <span>标讯主站</span>
           </div>
           {{end}}
-          {{if ne $TopMenu.Site "brand"}}
+          {{if ne $TopMenu.Site 1}}
           <div class="index" onclick="golink('brand')">
             <img data-theme="dark" src='{{Msg "seo" "cdn"}}/images/index/new/king.png?v={{Msg "seo" "version"}}' alt="" />
             <img data-theme="light" src='{{Msg "seo" "cdn"}}/images/index/new/king1.png?v={{Msg "seo" "version"}}' alt="" />