nav.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>导航</title>
  6. <!-- 解决资源跨域 -->
  7. <meta name="referrer" content="no-referrer"/>
  8. <!-- 解决缓存问题 -->
  9. <meta http-equiv="pragma" content="no-cache"/>
  10. <meta http-equiv="Cache-Control" content="no-cache, must-revalidate"/>
  11. <meta http-equiv="expires" content="0"/>
  12. <script src="https://map.tianyunperfect.cn/common-page.js"></script>
  13. <script src="js/clipboard.min.js"></script>
  14. <script src="js/vue.min.js"></script>
  15. <script src="elementUI/index.js"></script>
  16. <link rel="stylesheet" href="elementUI/index.css"/>
  17. <style>
  18. /* 新增样式 */
  19. .group-title {
  20. /*padding: 20px 0 10px;*/
  21. font-size: 20px;
  22. font-weight: bold;
  23. color: #409EFF;
  24. border-bottom: 1px solid #c7daf5;
  25. margin: 20px 0;
  26. display: flex;
  27. align-items: center;
  28. }
  29. .group-title i {
  30. margin-right: 8px;
  31. }
  32. .tab-sort-bar {
  33. background: #fdfdfd;
  34. /*padding: 10px;*/
  35. margin-bottom: 10px;
  36. border-radius: 4px;
  37. /*box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);*/
  38. /* 固定在顶部*/
  39. position: fixed;
  40. top: 0;
  41. padding: 5px;
  42. }
  43. .tab-item {
  44. min-width: 100px;
  45. max-width: 200px;
  46. /* 文字居中*/
  47. text-align: center;
  48. /*文字垂直居中*/
  49. /*line-height: 2em;*/
  50. background: #ecf5f0;
  51. margin: 0 10px;
  52. /* 鼠标变成手*/
  53. cursor: pointer;
  54. /* 圆角*/
  55. border-radius: 4px;
  56. }
  57. .tab-item:hover {
  58. background-color: #a3badc;
  59. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
  60. }
  61. .tab-container {
  62. max-width: calc(80%);
  63. margin: 0 auto;
  64. padding: 20px;
  65. }
  66. .tab-content {
  67. margin-top: 20px;
  68. }
  69. .content-item {
  70. margin: 10px;
  71. border: 1px solid #ebeef5;
  72. border-radius: 4px;
  73. transition: all .3s;
  74. cursor: pointer;
  75. display: inline-block;
  76. width: 300px;
  77. box-sizing: border-box;
  78. margin-bottom: 15px;
  79. }
  80. .content-item:hover {
  81. background-color: #f5f7fa;
  82. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
  83. }
  84. .el-tabs__item.is-active {
  85. color: #409EFF !important;
  86. }
  87. .el-tabs__active-bar {
  88. background-color: #409EFF;
  89. }
  90. .action-buttons {
  91. text-align: right;
  92. }
  93. .item-card {
  94. width: 100%;
  95. border: none;
  96. box-shadow: none;
  97. }
  98. .item-content {
  99. display: flex;
  100. justify-content: space-between;
  101. align-items: center;
  102. }
  103. .item-2 {
  104. /* 禁止换行 - */
  105. white-space: nowrap;
  106. /* 超出部分隐藏 */
  107. overflow: hidden;
  108. /* 超出部分显示省略号 */
  109. text-overflow: ellipsis;
  110. }
  111. @media (max-width: 768px) {
  112. .content-item {
  113. width: calc(50% - 20px);
  114. }
  115. }
  116. @media (max-width: 480px) {
  117. .content-item {
  118. width: 100%;
  119. }
  120. }
  121. /* 原有样式保留,新增以下样式 */
  122. .link-section {
  123. /*margin: 8px 0;*/
  124. white-space: nowrap; /* 禁止换行 */
  125. overflow: hidden; /* 隐藏溢出内容 */
  126. text-overflow: ellipsis; /* 超出部分显示省略号 */
  127. }
  128. .extra-links {
  129. margin-top: 8px;
  130. }
  131. .extra-link-tag {
  132. margin: 2px;
  133. padding: 0 5px;
  134. }
  135. .item-description {
  136. color: #666;
  137. font-size: 12px;
  138. /*margin-bottom: 8px;*/
  139. }
  140. .screenshot-section {
  141. border-top: 1px solid #eee;
  142. margin-top: 8px;
  143. padding-top: 8px;
  144. }
  145. .edit-dialog .el-dialog__body {
  146. padding: 20px;
  147. }
  148. .el-card__header{
  149. padding: 8px 20px;
  150. }
  151. .show-hover-class{
  152. opacity: 0;
  153. }
  154. </style>
  155. <script src="js/Sortable.min.js"></script>
  156. <script src="js/vuedraggable.umd.min.js"></script>
  157. <script src="js/axios.min.js"></script>
  158. </head>
  159. <body>
  160. <div id="app" class="tab-container">
  161. <!-- 标签排序栏 -->
  162. <div class="tab-sort-bar show-hover-class" style="display: flex">
  163. <div style="">排序:</div>
  164. <draggable
  165. :disabled="readOnly"
  166. v-model="groups"
  167. @change="onTabOrderChange"
  168. handle=".drag-handle"
  169. style="display: flex; flex-wrap: wrap;"
  170. animation="300">
  171. <div
  172. v-for="item in groups"
  173. :key="item"
  174. class="tab-item drag-handle"
  175. @click="scrollToGroup(item.name)">
  176. <span>{{ item.name }}</span>
  177. </div>
  178. </draggable>
  179. </div>
  180. <!-- 分组内容展示 -->
  181. <div v-for="(group,group_index) in groups"
  182. :key="group.name"
  183. :id="'group-'+group.name">
  184. <div class="group-title">
  185. <!-- <i class="el-icon-folder-opened"></i>-->
  186. <div style="margin-right: 20px; margin-left: 5px">{{ group.name }}</div>
  187. <div class="show-hover-class" v-if="!readOnly" style="display: flex" >
  188. <!-- 新增按钮 -->
  189. <el-button type="text" @click.stop="addTabAfter(group.name)" >
  190. <i class="el-icon-plus"></i>
  191. </el-button>
  192. <el-button type="text" @click.stop="editCurrentTabName(group.name)" >
  193. <i class="el-icon-edit"></i>
  194. </el-button>
  195. <el-button type="text" @click.stop="deleteTab(group.name)" :disabled="Object.keys(groups).length <= 1" >
  196. <i class="el-icon-delete"></i>
  197. </el-button>
  198. <div style="margin: 0 20px;color: #ccc;" v-if="!readOnly" >|</div>
  199. <el-button type="text" @click.stop="addContentItemAfter(group.name, group.datas.length-1)" >
  200. 新增卡片
  201. </el-button>
  202. </div>
  203. </div>
  204. <draggable
  205. group="site"
  206. animation="300"
  207. :disabled="readOnly"
  208. v-model="group.datas"
  209. tag="div"
  210. @change="onDragChange(group.name)"
  211. handle=".drag-handle"
  212. class="content-list">
  213. <transition-group>
  214. <div v-for="(item, index) in group.datas"
  215. :key="index"
  216. class="content-item">
  217. <el-card shadow="hover" class="item-card">
  218. <div slot="header" class="item-content drag-handle">
  219. <el-image
  220. :src="item.icon"
  221. style="width: 20px; height: 20px; margin-right: 8px;"
  222. fit="contain"
  223. ></el-image>
  224. <span>{{ item.title }}</span>
  225. <div class="action-buttons show-hover-class">
  226. <div v-if="!readOnly">
  227. <el-button
  228. type="text"
  229. @click.stop="openEditDialog(group,item)">
  230. <i class="el-icon-edit"></i>
  231. </el-button>
  232. <el-button
  233. type="text"
  234. @click.stop="deleteContentItem(group.name, index)">
  235. <i class="el-icon-delete"></i>
  236. </el-button>
  237. <el-button
  238. type="text"
  239. @click.stop="addContentItemAfter(group.name, index)">
  240. <i class="el-icon-plus"></i>
  241. </el-button>
  242. </div>
  243. </div>
  244. </div>
  245. <div class="item-content">
  246. <div style="width: 100%">
  247. <div class="item-description">{{ item.description || item.title }}</div>
  248. <el-tooltip>
  249. <div class="link-section">
  250. <el-link
  251. type="primary"
  252. :href="item.mainUrl"
  253. target="_blank">{{ item.mainUrl }}
  254. </el-link>
  255. </div>
  256. <div slot="content" v-if="item.extraUrls && item.extraUrls.length" class="extra-links">
  257. <el-tag
  258. v-for="(url, idx) in item.extraUrls"
  259. :key="idx"
  260. type="info"
  261. class="extra-link-tag">
  262. <el-link :href="url" target="_blank">{{ url }}</el-link>
  263. </el-tag>
  264. </div>
  265. <div slot="content" v-else>
  266. 没有更多链接
  267. </div>
  268. </el-tooltip>
  269. <div v-if="item.screenshot" class="screenshot-section">
  270. <el-image
  271. :src="item.screenshot"
  272. style="max-width: 100%; height: 175px;"
  273. :preview-src-list="[item.screenshot]"
  274. fit="cover"></el-image>
  275. </div>
  276. </div>
  277. </div>
  278. </el-card>
  279. </div>
  280. </transition-group>
  281. </draggable>
  282. </div>
  283. <br>
  284. <!-- 编辑对话框 -->
  285. <el-dialog
  286. :close-on-click-modal="false"
  287. :title="isEditing ? '编辑项目' : '添加新项'"
  288. :visible.sync="dialogVisible"
  289. width="600px">
  290. <el-form :model="currentItem" label-width="80px">
  291. <el-form-item label="标题">
  292. <el-input v-model="currentItem.title"></el-input>
  293. </el-form-item>
  294. <el-form-item label="图标URL">
  295. <el-input v-model="currentItem.icon"></el-input>
  296. </el-form-item>
  297. <el-form-item label="主地址">
  298. <el-input v-model="currentItem.mainUrl"></el-input>
  299. </el-form-item>
  300. <el-form-item label="描述">
  301. <el-input v-model="currentItem.description" type="textarea"></el-input>
  302. </el-form-item>
  303. <el-form-item label="附加地址">
  304. <div v-for="(url, index) in currentItem.extraUrls" :key="index">
  305. <el-input v-model="currentItem.extraUrls[index]" style="margin-bottom: 5px;">
  306. <el-button
  307. slot="append"
  308. icon="el-icon-remove"
  309. @click="removeExtraUrl(index)"></el-button>
  310. </el-input>
  311. </div>
  312. <el-button @click="addExtraUrl">添加附加地址</el-button>
  313. </el-form-item>
  314. <el-form-item label="截图URL">
  315. <el-input v-model="currentItem.screenshot"></el-input>
  316. </el-form-item>
  317. <el-form-item label="所属标签">
  318. <el-select v-model="targetTab" placeholder="请选择标签页">
  319. <el-option
  320. v-for="tab in groups"
  321. :key="tab.name"
  322. :label="tab.name"
  323. :value="tab.name">
  324. </el-option>
  325. </el-select>
  326. </el-form-item>
  327. </el-form>
  328. <span slot="footer" class="dialog-footer">
  329. <el-button @click="dialogVisible = false">取 消</el-button>
  330. <el-button type="primary" @click="saveItem">确 定</el-button>
  331. </span>
  332. </el-dialog>
  333. </div>
  334. <script>
  335. let pageManager = new PageManager();
  336. pageManager.type = 'nav-page';
  337. pageManager.setNameCallBack(() => {
  338. let title = localStorage.getItem("title");
  339. document.title = title + " - 导航";
  340. _this.all_data.title = title;
  341. })
  342. let _this = new Vue({
  343. el: '#app',
  344. data: {
  345. all_data: {},
  346. activeTab: '常用工具',
  347. groups: [
  348. {
  349. name: "常用工具",
  350. datas: [{
  351. title: "GitHub",
  352. icon: "https://github.githubassets.com/favicons/favicon.svg",
  353. mainUrl: "https://github.com",
  354. description: "代码托管平台",
  355. extraUrls: [
  356. "",
  357. "https://pages.github.com"
  358. ],
  359. screenshot: ""
  360. }]
  361. }
  362. ],
  363. newTabName: '',
  364. readOnly: false,
  365. showTabManage: false,
  366. // 对话框相关
  367. dialogVisible: false,
  368. isEditing: false,
  369. currentItem: {
  370. title: '',
  371. icon: '',
  372. mainUrl: '',
  373. description: '',
  374. extraUrls: [],
  375. screenshot: ''
  376. },
  377. originalTab: '',
  378. originalIndex: -1, // 编辑时,记录原始数据在当前标签页中的索引
  379. targetTabIndex: -1, // 编辑时,记录目标标签页名称
  380. targetTab:''
  381. },
  382. mounted() {
  383. pageManager.init().then(res => {
  384. this.all_data = res;
  385. if (res && res.content) {
  386. let showContent = res.content;
  387. if (pageManager.isBackup) showContent = res.content_back;
  388. this.groups = JSON.parse(showContent);
  389. }
  390. if (pageManager.isReadOnly()) this.readOnly = true;
  391. // .show-hover-class 鼠标滑过,设置 透明度为可见,移走则为0
  392. this.$nextTick(()=>{
  393. const elements = document.querySelectorAll('.show-hover-class');
  394. for (let i = 0; i < elements.length; i++) {
  395. elements[i].addEventListener('mouseenter', function () {
  396. this.style.opacity = 1;
  397. });
  398. elements[i].addEventListener('mouseleave', function () {
  399. this.style.opacity = 0;
  400. });
  401. }
  402. })
  403. });
  404. },
  405. methods: {
  406. scrollToGroup(tabName) {
  407. const element = document.getElementById('group-' + tabName);
  408. if (element) {
  409. element.scrollIntoView({
  410. behavior: 'smooth',
  411. block: 'start'
  412. });
  413. }
  414. },
  415. onTabOrderChange() {
  416. this.updateData();
  417. },
  418. openAddDialog() {
  419. this.isEditing = false;
  420. this.currentItem = {
  421. title: '',
  422. icon: '',
  423. mainUrl: '',
  424. description: '',
  425. extraUrls: [],
  426. screenshot: ''
  427. };
  428. this.targetTab = this.activeTab;
  429. this.dialogVisible = true;
  430. },
  431. openEditDialog(group, item) {
  432. // 根据 groupName 和 index 获取对应的数据
  433. this.isEditing = true;
  434. this.dialogVisible = true;
  435. this.currentItem = item;
  436. this.targetTab = group.name;
  437. this.originalTab = group.name;
  438. },
  439. getTabNames() {
  440. return this.groups.map(g => g.name);
  441. },
  442. // 根据标签名获取数据
  443. getGroupByName(name) {
  444. return this.groups.find(g => g.name === name);
  445. },
  446. // 新增标签页
  447. addTab() {
  448. if (!this.newTabName) return;
  449. this.groups.push({
  450. name: this.newTabName,
  451. datas: []
  452. });
  453. this.activeTab = this.newTabName;
  454. this.newTabName = '';
  455. this.updateData();
  456. },
  457. // 保存新项目
  458. saveItem() {
  459. if (!this.currentItem.title || !this.currentItem.mainUrl) {
  460. this.$message.warning('标题和主地址为必填项');
  461. return;
  462. }
  463. const targetGroup = this.getGroupByName(this.targetTab);
  464. if (!targetGroup) return;
  465. if (this.isEditing) {
  466. // 编辑模式
  467. const originalGroup = this.getGroupByName(this.originalTab);
  468. if (originalGroup) {
  469. originalGroup.datas.splice(this.originalIndex, 1);
  470. if (this.targetTab === this.originalTab) {
  471. // 同组内移动,插入到原位置
  472. targetGroup.datas.splice(this.originalIndex, 0, this.currentItem);
  473. } else {
  474. // 跨组移动,添加到末尾
  475. targetGroup.datas.push(this.currentItem);
  476. }
  477. }
  478. } else {
  479. // 新增模式
  480. if (this.originalIndex !== undefined) {
  481. // 在指定位置后插入
  482. targetGroup.datas.splice(this.originalIndex + 1, 0, this.currentItem);
  483. } else {
  484. // 直接添加到末尾
  485. targetGroup.datas.push(this.currentItem);
  486. }
  487. }
  488. this.updateData();
  489. this.dialogVisible = false;
  490. // 重置位置信息
  491. this.originalIndex = undefined;
  492. this.originalTab = '';
  493. },
  494. addExtraUrl() {
  495. this.currentItem.extraUrls.push('');
  496. },
  497. removeExtraUrl(index) {
  498. this.currentItem.extraUrls.splice(index, 1);
  499. },
  500. // 删除标签页
  501. deleteTab(name) {
  502. const idx = this.groups.findIndex(g => g.name === name);
  503. if (idx > -1) {
  504. this.groups.splice(idx, 1);
  505. this.activeTab = this.groups[0]?.name;
  506. this.updateData();
  507. }
  508. },
  509. // 修改标签名
  510. editCurrentTabName(oldName) {
  511. this.$prompt('请输入新标签名', '修改标签名称', {
  512. inputValue: oldName,
  513. closeOnClickModal: false,
  514. inputValidator: (value) => {
  515. if (!value) return '标签名不能为空';
  516. if (this.getGroupByName(value) && value !== oldName) {
  517. return '标签名已存在';
  518. }
  519. return true;
  520. }
  521. }).then(({value}) => {
  522. if (value !== oldName) {
  523. const group = this.getGroupByName(oldName);
  524. if (group) {
  525. group.name = value;
  526. this.activeTab = value;
  527. this.updateData();
  528. }
  529. }
  530. });
  531. },
  532. // 删除内容项
  533. deleteContentItem(groupName, index) {
  534. const group = this.getGroupByName(groupName);
  535. if (group) {
  536. group.datas.splice(index, 1);
  537. this.updateData();
  538. }
  539. },
  540. updateData() {
  541. this.all_data.content = JSON.stringify(this.groups);
  542. pageManager.updateData(this.all_data);
  543. },
  544. onDragChange(tabName) {
  545. this.updateData();
  546. },
  547. handleTabClick(tab) {
  548. this.activeTab = tab.name;
  549. },
  550. // 在当前标签后新增标签
  551. addTabAfter(name) {
  552. this.$prompt('请输入新标签名', '添加标签名称', {
  553. closeOnClickModal: false,
  554. inputValidator: (value) => {
  555. if (!value) return '标签名不能为空';
  556. if (this.getGroupByName(value)) return '标签名已存在';
  557. return true;
  558. }
  559. }).then(({value}) => {
  560. const idx = this.groups.findIndex(g => g.name === name);
  561. this.groups.splice(idx + 1, 0, {
  562. name: value,
  563. datas: []
  564. });
  565. this.activeTab = value;
  566. this.updateData();
  567. });
  568. },
  569. addContentItemAfter(groupName, index) {
  570. this.isEditing = false;
  571. // 重置当前项
  572. this.currentItem = {
  573. title: '',
  574. icon: '',
  575. mainUrl: '',
  576. description: '',
  577. extraUrls: [],
  578. screenshot: ''
  579. };
  580. // 存储目标位置信息
  581. this.targetTab = groupName;
  582. this.originalTab = groupName;
  583. this.originalIndex = index;
  584. this.dialogVisible = true;
  585. },
  586. }
  587. });
  588. </script>
  589. </body>
  590. </html>