1

【新生指南-002】牛刀小试-优秀的导航页Sun-panel部署(喂奶级)

发表于:6 天前 Docker 552
本帖最后由 madrays 于 2024-10-13 13:23 编辑



Sun-Panel简介

简单、易用、美观
一个NAS、服务器导航面板、简易docker管理器、Homepage、浏览器首页

特点​
🍉 界面简洁,功能强大,资源占用少
🍊 上手简单,可视化操作,可0代码使用
🍠 一键切换内、外网模式链接
🍵 支持docker部署(支持Arm系统)
🎪 支持多账号隔离使用
🎏 支持查看系统状态
🫙 支持自定义js、css
🍻 简单使用可以无需连接外部数据库
🍾 丰富图标风格自由搭配,支持iconify图标库
🚁 支持网页内置小窗口打开(部分三方网站屏蔽此功能)
🐳 简单的docker管理器,支持查看容器状态、控制容器的开启和关闭

      Sun-Panel是一个优秀的导航页,尝试了各种导航页部署后,最终选用了Sun-Panel,集易上手、方便快捷、作者大大@红烧猎人更新神速,需求更新的快快的,最近又更新了docker和侧边栏这些非常实用的功能,本次直接使用docker的方式部署。

🚀拉取镜像
首先连接飞牛SSH,关于SSH看下面:

     飞牛的设置页面开启SSH选项,默认端口22,强烈建议修改此端口,并在不用的时候关闭SSH选项,当后期我们Nas暴露在公网时能优秀的保护我们的数据安全。
打开Xshenll,新建一个连接:

设置好飞牛ip以及SSH端口点击连接即可,并根据提示输入nas的用户名和密码即可进入SSH。
进入SSH后,输入sudo -i,接着输入密码进入root模式(输密码不显示字符,直接回车就好):
  1. sudo -i
复制代码
  1. username@XXX:/$ sudo -i
  2. Password:
  3. root@XXX:~#
复制代码
显示上面的代码就可以了,接着拉取镜像:
  1. docker pull hslr/sun-panel:latest
复制代码

文件管理器中找到你设置的docker所在存储空间中的appshare文件夹,这个就是前面的应用文件,新建一个sunpanel文件夹,接着在sunpanel文件夹中新建一个conf文件夹,文件树如下图所示:

🛑一键部署
使用SSH 命令一键部署即可,记得需要root权限
#注意这里与官方命令不一样的是前面的本机路径,请根据自己的实际情况选择刚刚新建的conf文件夹的真实地址,对这个不太了解的同学可以看下我的上篇docker简介帖子哈 #docker管理功能实现需要挂载docker守护进程 #镜像与上面pull的版本保持一致
  1. docker run -d --restart=always -p 3002:3002 \
  2. -v /vol1/@appshare/sunpanel/conf:/app/conf \
  3. -v /var/run/docker.sock:/var/run/docker.sock \
  4. --name sun-panel \
  5. hslr/sun-panel:latest
复制代码
显示如下界面表示已经部署成功了,访问127.0.0.2:3002(127.0.0.2替换为飞牛的ip地址)即可享用Sun-Panel了。
  1. root@XXX:~# docker run -d --restart=always -p 3002:3002 \
  2. > -v /vol1/@appshare/sunpanel/conf:/app/conf \
  3. > -v /var/run/docker.sock:/var/run/docker.sock \
  4. > --name sun-panel \
  5. > hslr/sun-panel:latest
  6. 641570e4558559ef705307d58c6c949b54bba29a47a03503040cbb2c7334157d
  7. root@XXX:~#
复制代码
登录后可以看到docker已经挂载成功了,说明安装很完美!

具体更多的功能相信大家点点鼠标就明白了哈哈。

🏝️侧边栏导航JS部署
这是最近大佬新推出的功能,对于站点内容巨多的我来说太需要这个功能了,快速定位各个菜单,而且还适配了手机端,其实挂载这个很简单,不过需要支持一下大佬,毕竟为爱发电不是长久之计,现在优惠100年(终身)会员88币,需要PRO功能的同学可以支持一下。
侧边栏导航JS部署其实很简单,大佬提供了完整的JS代码(后附),粘贴到设置栏的JS对应位置即可。
安装好的效果,有环保行业的同学也可以看看我的Sunpanel导航页效果:



🌐侧边导航栏JS代码
  1. (function () {
  2.   // =========== Config Start ===========
  3.   // ------------------------------------
  4.   // 距离滚动偏移量
  5.   const scrollOffset = 80

  6.   // 显示风格( auto:自动(默认) | mobile:左上角显示触发按钮-移动端风格 | sidebar:常态显示侧栏)
  7.   const displayStyle = 'auto'

  8.   // 移动端宽度定义
  9.   const mobileWidth = 800

  10.   const SunPanelTOCDomIdName = 'sun-panel-toc-dom'

  11.   // 左上角按钮 SVG 图标
  12.   const svgTocMobileBtn = '<svg xmlns="http://www.w3.org/2000/svg"  viewBox="0 0 24 24"><path fill="currentColor" d="M17.5 4.5c-1.95 0-4.05.4-5.5 1.5c-1.45-1.1-3.55-1.5-5.5-1.5c-1.45 0-2.99.22-4.28.79C1.49 5.62 1 6.33 1 7.14v11.28c0 1.3 1.22 2.26 2.48 1.94c.98-.25 2.02-.36 3.02-.36c1.56 0 3.22.26 4.56.92c.6.3 1.28.3 1.87 0c1.34-.67 3-.92 4.56-.92c1 0 2.04.11 3.02.36c1.26.33 2.48-.63 2.48-1.94V7.14c0-.81-.49-1.52-1.22-1.85c-1.28-.57-2.82-.79-4.27-.79M21 17.23c0 .63-.58 1.09-1.2.98c-.75-.14-1.53-.2-2.3-.2c-1.7 0-4.15.65-5.5 1.5V8c1.35-.85 3.8-1.5 5.5-1.5c.92 0 1.83.09 2.7.28c.46.1.8.51.8.98z"/><path fill="currentColor" d="M13.98 11.01c-.32 0-.61-.2-.71-.52c-.13-.39.09-.82.48-.94c1.54-.5 3.53-.66 5.36-.45c.41.05.71.42.66.83s-.42.71-.83.66c-1.62-.19-3.39-.04-4.73.39c-.08.01-.16.03-.23.03m0 2.66c-.32 0-.61-.2-.71-.52c-.13-.39.09-.82.48-.94c1.53-.5 3.53-.66 5.36-.45c.41.05.71.42.66.83s-.42.71-.83.66c-1.62-.19-3.39-.04-4.73.39a1 1 0 0 1-.23.03m0 2.66c-.32 0-.61-.2-.71-.52c-.13-.39.09-.82.48-.94c1.53-.5 3.53-.66 5.36-.45c.41.05.71.42.66.83s-.42.7-.83.66c-1.62-.19-3.39-.04-4.73.39a1 1 0 0 1-.23.03"/></svg>'

  13.   // ------------------------------------
  14.   // =========== Config End ===========

  15.   // 滚动容器的类名
  16.   const scrollContainerElementClassName = '.scroll-container'

  17.   // 一些函数
  18.   const isMobile = () => {
  19.     if (displayStyle === 'mobile') {
  20.       return true
  21.     }
  22.     else if (displayStyle === 'pc') {
  23.       return false
  24.     }
  25.     const width = window.innerWidth
  26.     return width < mobileWidth
  27.   }

  28.   function createDom() {
  29.     // 检测是否已经存在TOC DOM,存在则删除
  30.     (function () {
  31.       const element = document.getElementById(SunPanelTOCDomIdName)
  32.       if (element) {
  33.         element.remove()
  34.       }
  35.     })()

  36.     const SunPanelTOCDom = document.createElement('div')
  37.     SunPanelTOCDom.id = SunPanelTOCDomIdName
  38.     document.body.appendChild(SunPanelTOCDom)

  39.     // ========= Add style start =========
  40.     const style = document.createElement('style')
  41.     const SunPanelTOCDomStyleId = `#${SunPanelTOCDomIdName}`
  42.     style.textContent = `
  43.     ${SunPanelTOCDomStyleId} #toc-mobile-btn {
  44.         top: 20px !important;
  45.         left: 20px !important;
  46.         position: fixed;
  47.         width: 46px;
  48.         height: 46px;
  49.         background-color: #2a2a2a6b;
  50.         color: white;
  51.         border-radius: 0.5rem;
  52.         display: flex;
  53.         justify-content: center;
  54.         align-items: center;
  55.         cursor: pointer;
  56.     }

  57.     ${SunPanelTOCDomStyleId} .hidden {
  58.         display: none !important;
  59.     }

  60.     ${SunPanelTOCDomStyleId} #toc-sidebar {
  61.         width: 40px;
  62.         padding: 10px;
  63.         position: fixed;
  64.         top: 0;
  65.         left: 0;
  66.         height: 100%;
  67.         overflow: hidden;
  68.         display: flex;
  69.         flex-direction: column;
  70.         justify-content: center;
  71.         transition: width 0.3s ease, background-color 0.3s ease;
  72.         border-top-right-radius: 20px;
  73.         border-bottom-right-radius: 20px;
  74.         background-color: none;
  75.     }

  76.     ${SunPanelTOCDomStyleId} .toc-mobile-btn-svg-container{
  77.       width:21px;
  78.       height:21px;
  79.     }

  80.     ${SunPanelTOCDomStyleId} .toc-sidebar-expansion {
  81.         width: 200px !important;
  82.         display: flex;
  83.         background-color: rgb(42 42 42 / 90%);
  84.         box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2);
  85.     }

  86.     ${SunPanelTOCDomStyleId} #toc-sidebar .toc-sidebar-box {
  87.         width: 500px;
  88.     }

  89.     ${SunPanelTOCDomStyleId} .title-bar-box {
  90.         display: flex;
  91.         align-items: center;
  92.         position: relative;
  93.         cursor: pointer;
  94.     }

  95.     ${SunPanelTOCDomStyleId} .title-bar-slip {
  96.         width: 20px;
  97.         height: 6px;
  98.         background-color: white;
  99.         border-radius: 4px;
  100.         margin: 15px 0;
  101.         transition: height 0.3s ease, width 0.3s ease;
  102.         box-shadow: 2px 0 5px rgba(0, 0, 0, 0.5);
  103.     }

  104.     ${SunPanelTOCDomStyleId} .title-bar-title {
  105.         opacity: 0;
  106.         white-space: nowrap;
  107.         transition: opacity 0.3s ease, transform 0.3s ease, margin-left 0.3s ease;
  108.         font-size: 14px;
  109.         color: white;
  110.     }

  111.     ${SunPanelTOCDomStyleId} .toc-sidebar-expansion .title-bar-title {
  112.         opacity: 1;
  113.         margin-left: 10px;
  114.     }

  115.     ${SunPanelTOCDomStyleId} .toc-sidebar-expansion .title-bar-slip {
  116.         box-shadow: none;
  117.     }

  118.     ${SunPanelTOCDomStyleId} .toc-sidebar-expansion .title-bar-box:hover .title-bar-slip {
  119.         width: 40px;
  120.     }

  121.     ${SunPanelTOCDomStyleId} .toc-sidebar-expansion .title-bar-box:hover .title-bar-title {
  122.         font-size: 20px;
  123.     }

  124.       `
  125.     // 添加样式到文档头部
  126.     SunPanelTOCDom.appendChild(style)

  127.     // ========= Add style end =========

  128.     // 添加移动端菜单按钮
  129.     const tocMobileBtn = document.createElement('div')
  130.     tocMobileBtn.id = 'toc-mobile-btn'
  131.     tocMobileBtn.classList.add('back**-blur-[2px]')
  132.     SunPanelTOCDom.appendChild(tocMobileBtn)

  133.     const tocMobileBtnSvgcContainer = document.createElement('div')
  134.     tocMobileBtnSvgcContainer.innerHTML = svgTocMobileBtn
  135.     tocMobileBtnSvgcContainer.classList.add('toc-mobile-btn-svg-container')
  136.     tocMobileBtn.appendChild(tocMobileBtnSvgcContainer)

  137.     // 创建侧边栏容器
  138.     const sidebar = document.createElement('div')
  139.     sidebar.id = 'toc-sidebar'

  140.     const sidebarBox = document.createElement('div')
  141.     sidebarBox.className = 'toc-sidebar-box'

  142.     // 查询出所有类名包含 item-group-index- 的元素
  143.     const items = document.querySelectorAll('[class*="item-group-index-"]')

  144.     // 遍历并打印每个元素的完整类名
  145.     items.forEach((item) => {
  146.       item.classList.forEach((className) => {
  147.         if (className.startsWith('item-group-index-')) {
  148.           const titleBarBox = document.createElement('div')
  149.           titleBarBox.className = 'title-bar-box'
  150.           // titleBarBox.href = `#${item.id}`
  151.           titleBarBox.dataset.groupClassName = className

  152.           // 目录条
  153.           const titleBarSlip = document.createElement('div')
  154.           titleBarSlip.className = 'title-bar-slip'

  155.           // 创建一个链接
  156.           const titleBarTitle = document.createElement('div')
  157.           titleBarTitle.className = 'title-bar-title'

  158.           // 获取子元素中 class="group-title" 的内容
  159.           const titleElement = item.querySelector('.group-title')
  160.           const titleText = titleElement ? titleElement.textContent : item.id
  161.           titleBarTitle.textContent = titleText

  162.           titleBarBox.appendChild(titleBarSlip)
  163.           titleBarBox.appendChild(titleBarTitle)

  164.           sidebarBox.appendChild(titleBarBox)
  165.         }
  166.       })
  167.     })

  168.     sidebar.appendChild(sidebarBox)

  169.     // 将侧边栏添加到页面中
  170.     SunPanelTOCDom.appendChild(sidebar)

  171.     function mobileHideSidebar() {
  172.       sidebar.classList.remove('toc-sidebar-expansion')
  173.       sidebar.classList.add('hidden')
  174.     }

  175.     function hideSidebar() {
  176.       sidebar.classList.remove('toc-sidebar-expansion')
  177.     }

  178.     function showSidebar() {
  179.       sidebar.classList.add('toc-sidebar-expansion')
  180.       sidebar.classList.remove('hidden')
  181.     }

  182.     // ----------------
  183.     // 监听宽度变化开始
  184.     // ----------------
  185.     function debounce(func, wait) {
  186.       let timeout
  187.       return function (...args) {
  188.         clearTimeout(timeout)
  189.         timeout = setTimeout(() => {
  190.           func.apply(this, args)
  191.         }, wait)
  192.       }
  193.     }

  194.     function handleResize() {
  195.       if (isMobile()) {
  196.         tocMobileBtn.classList.remove('hidden')
  197.         sidebar.classList.add('hidden')
  198.       }
  199.       else {
  200.         tocMobileBtn.classList.add('hidden')
  201.         sidebar.classList.remove('hidden')
  202.       }
  203.     }

  204.     // 使用防抖函数包装你的处理函数
  205.     const debouncedHandleResize = debounce(handleResize, 200)

  206.     // 添加事件**
  207.     window.addEventListener('resize', debouncedHandleResize)

  208.     // 首次触发
  209.     handleResize()

  210.     // ----------------
  211.     // 监听宽度变化结束
  212.     // ----------------

  213.     // 监听移动端按钮点击
  214.     tocMobileBtn.addEventListener('click', () => {
  215.       if (sidebar.classList.contains('toc-sidebar-expansion')) {
  216.         // 隐藏
  217.         mobileHideSidebar()
  218.       }
  219.       else {
  220.         // 显示
  221.         showSidebar()
  222.       }
  223.     })

  224.     // 监听TOC栏失去hover
  225.     sidebar.addEventListener('mouseleave', () => {
  226.       if (isMobile()) {
  227.         // 隐藏
  228.         mobileHideSidebar()
  229.       }
  230.       else {
  231.         hideSidebar()
  232.       }
  233.     })

  234.     // 监听TOC栏获得hover
  235.     sidebar.addEventListener('mouseenter', () => {
  236.       showSidebar()
  237.     })

  238.     // 监听TOC点击事件
  239.     document.querySelectorAll('.title-bar-box').forEach((box) => {
  240.       box.addEventListener('click', function (event) {
  241.       // 检查触发事件的元素是否有 'data-groupClassName' 属性
  242.         if (this.dataset.groupClassName) {
  243.         // 获取 'data-groupClass' 属性的值
  244.           const groupClassName = this.dataset.groupClassName
  245.           // 使用属性值作为选择器查询对应的元素
  246.           const targetElement = document.querySelector(`.${groupClassName}`)
  247.           if (targetElement) {
  248.           // 获取目标元素的 'top' 坐标
  249.             const targetTop = targetElement.offsetTop
  250.             const scrollContainerElement = document.querySelector(scrollContainerElementClassName)
  251.             if (scrollContainerElement) {
  252.               scrollContainerElement.scrollTo({
  253.                 top: targetTop - scrollOffset,
  254.                 behavior: 'smooth', // 平滑滚动
  255.               })
  256.             }
  257.           }
  258.         }
  259.       })
  260.     })
  261.   }

  262.   // 判断是否已经存在分组,不存在将定时监听
  263.   const items = document.querySelectorAll('[class*="item-group-index-"]')
  264.   if (items.length > 0) {
  265.     createDom()
  266.     return
  267.   }

  268.   const interval = setInterval(() => {
  269.     const items = document.querySelectorAll('[class*="item-group-index-"]')
  270.     if (items.length > 0) {
  271.       createDom()
  272.       clearInterval(interval)
  273.     }
  274.   }, 1000)
  275. })()
复制代码


收藏
送赞 1
分享

发表回复

评论列表(16)

回帖奖励 +1 飞牛币

补充一点,访问:3002  后,默认账号为admin@sun.cc,密码12345678
4 天前 回复
是的 这段被吃掉了  详情 回复
4 天前

回帖奖励 +1 飞牛币

刚好最近也在折腾sun面板,感谢楼主提供想法
5 天前 回复
可以看下第三篇美化教程哦  详情 回复
5 天前
可以看下第三篇美化教程哦
5 天前 回复

回帖奖励 +1 飞牛币

看看还行
5 天前 回复

回帖奖励 +1 飞牛币

巧了,最近也在找导航页,没有满意的,试试这个。
5 天前 回复

回帖奖励 +1 飞牛币

谢谢分享教程!
5 天前 回复

回帖奖励 +1 飞牛币

感谢分享
4 天前 回复

回帖奖励 +1 飞牛币

感谢大佬分享
4 天前 回复

回帖奖励 +1 飞牛币

谢谢分享
4 天前 回复
12下一页