nav.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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. transition: opacity 0.3s;
  154. }
  155. .show-hover-class:hover {
  156. opacity: 1;
  157. }
  158. </style>
  159. <style scoped>
  160. /* 如果是 scoped CSS 需要穿透 >>> 或者使用 ::v-deep */
  161. .extra-links {
  162. display: flex !important;
  163. flex-direction: column;
  164. gap: 8px; /* 可选:添加标签间距 */
  165. }
  166. /* 如果标签宽度需要撑满容器 */
  167. .extra-links .el-tag {
  168. width: 100%;
  169. margin-right: 0 !important; /* 清除默认右边距 */
  170. }
  171. /* 链接对齐优化 */
  172. .extra-links .el-tag .el-link {
  173. width: 100%;
  174. display: block;
  175. }
  176. </style>
  177. <script src="js/Sortable.min.js"></script>
  178. <script src="js/vuedraggable.umd.min.js"></script>
  179. <script src="js/axios.min.js"></script>
  180. </head>
  181. <body>
  182. <div id="app" class="tab-container">
  183. <!-- 标签排序栏 -->
  184. <div class="tab-sort-bar show-hover-class" style="display: flex">
  185. <div style="">排序:</div>
  186. <draggable
  187. :disabled="readOnly"
  188. v-model="groups"
  189. @change="onTabOrderChange"
  190. handle=".drag-handle"
  191. style="display: flex; flex-wrap: wrap;"
  192. animation="300">
  193. <div
  194. v-for="item in groups"
  195. :key="item"
  196. class="tab-item drag-handle"
  197. @click="scrollToGroup(item.name)">
  198. <span>{{ item.name }}</span>
  199. </div>
  200. </draggable>
  201. </div>
  202. <!-- 分组内容展示 -->
  203. <div v-for="(group,group_index) in groups"
  204. :key="group.name"
  205. :id="'group-'+group.name">
  206. <div class="group-title">
  207. <!-- <i class="el-icon-folder-opened"></i>-->
  208. <div style="margin-right: 20px; margin-left: 5px">{{ group.name }}</div>
  209. <div class="show-hover-class" v-if="!readOnly" style="display: flex">
  210. <!-- 新增按钮 -->
  211. <el-button type="text" @click.stop="addTabAfter(group.name)">
  212. <i class="el-icon-plus"></i>
  213. </el-button>
  214. <el-button type="text" @click.stop="editCurrentTabName(group.name)">
  215. <i class="el-icon-edit"></i>
  216. </el-button>
  217. <el-button type="text" @click.stop="deleteTab(group.name)" :disabled="Object.keys(groups).length <= 1">
  218. <i class="el-icon-delete"></i>
  219. </el-button>
  220. <div style="margin: 0 20px;color: #ccc;" v-if="!readOnly">|</div>
  221. <el-button type="text" @click.stop="addContentItemAfter(group.name, group.datas.length-1)">
  222. 新增卡片
  223. </el-button>
  224. </div>
  225. </div>
  226. <draggable
  227. group="site"
  228. animation="300"
  229. :disabled="readOnly"
  230. v-model="group.datas"
  231. tag="div"
  232. @change="onDragChange(group.name)"
  233. handle=".drag-handle"
  234. class="content-list">
  235. <transition-group>
  236. <div v-for="(item, index) in group.datas"
  237. :key="index"
  238. class="content-item">
  239. <el-card shadow="hover" class="item-card">
  240. <div slot="header" class="item-content drag-handle">
  241. <el-image
  242. :src="item.icon"
  243. style="width: 20px; height: 20px; margin-right: 8px;"
  244. fit="contain"
  245. ></el-image>
  246. <span>{{ item.title }}</span>
  247. <div class="action-buttons show-hover-class">
  248. <div v-if="!readOnly">
  249. <el-button
  250. type="text"
  251. @click.stop="openEditDialog(group,item)">
  252. <i class="el-icon-edit"></i>
  253. </el-button>
  254. <el-button
  255. type="text"
  256. @click.stop="deleteContentItem(group.name, index)">
  257. <i class="el-icon-delete"></i>
  258. </el-button>
  259. <el-button
  260. type="text"
  261. @click.stop="addContentItemAfter(group.name, index)">
  262. <i class="el-icon-plus"></i>
  263. </el-button>
  264. </div>
  265. </div>
  266. </div>
  267. <div class="item-content">
  268. <div style="width: 100%">
  269. <el-tooltip placement="top" v-if="item.description && item.description.length > 15">
  270. <div class="item-description">{{ item.description.substring(0, 15) }}...</div>
  271. <div slot="content">{{ item.description }}</div>
  272. </el-tooltip>
  273. <div v-else class="item-description">{{ item.description || item.title }}</div>
  274. <el-tooltip placement="bottom-start">
  275. <div class="link-section">
  276. <el-link
  277. type="primary"
  278. :href="item.extraUrls[0]"
  279. target="_blank">{{ item.extraUrls[0] }}
  280. </el-link>
  281. </div>
  282. <div slot="content" v-if="item.extraUrls && item.extraUrls.length" class="extra-links">
  283. <el-tag
  284. v-for="(url, idx) in item.extraUrls"
  285. :key="idx"
  286. type="info"
  287. class="extra-link-tag">
  288. <el-link :href="url" target="_blank">{{ url }}</el-link>
  289. </el-tag>
  290. </div>
  291. <div slot="content" v-else>
  292. 没有更多链接
  293. </div>
  294. </el-tooltip>
  295. <div v-if="item.screenshot" class="screenshot-section">
  296. <el-image
  297. :src="item.screenshot"
  298. style="max-width: 100%; height: 175px;"
  299. :preview-src-list="[item.screenshot]"
  300. fit="cover"></el-image>
  301. </div>
  302. </div>
  303. </div>
  304. </el-card>
  305. </div>
  306. </transition-group>
  307. </draggable>
  308. </div>
  309. <br>
  310. <!-- 编辑对话框 -->
  311. <el-dialog
  312. :close-on-click-modal="false"
  313. :title="isEditing ? '编辑项目' : '添加新项'"
  314. :visible.sync="dialogVisible"
  315. width="600px">
  316. <el-form :model="currentItem" label-width="80px">
  317. <el-form-item label="* 标题">
  318. <el-input v-model="currentItem.title"></el-input>
  319. </el-form-item>
  320. <el-form-item label="* 地址">
  321. <draggable
  322. v-model="currentItem.extraUrls"
  323. animation="300"
  324. handle=".drag-handle"
  325. class="extra-links">
  326. <div v-for="(url, index) in currentItem.extraUrls" :key="index" style="display: flex; align-items: center; margin-bottom: 5px;">
  327. <!-- 地址输入框 -->
  328. <el-input v-model="currentItem.extraUrls[index]" style="flex: 1;">
  329. <el-button
  330. slot="append"
  331. icon="el-icon-remove"
  332. @click="removeExtraUrl(index)"></el-button>
  333. </el-input>
  334. <!-- 拖拽手柄 -->
  335. <el-button class="drag-handle" icon="el-icon-rank" style="margin-left: 8px; cursor: move;"></el-button></div>
  336. </draggable>
  337. <el-button @click="addExtraUrl">添加附加地址</el-button>
  338. </el-form-item>
  339. <el-form-item label="描述">
  340. <el-input v-model="currentItem.description" type="textarea"></el-input>
  341. </el-form-item>
  342. <el-form-item label="图标URL">
  343. <el-input v-model="currentItem.icon"></el-input>
  344. </el-form-item>
  345. <el-form-item label="截图URL">
  346. <el-input v-model="currentItem.screenshot"></el-input>
  347. </el-form-item>
  348. <el-form-item label="所属标签">
  349. <el-select v-model="targetTab" placeholder="请选择标签页">
  350. <el-option
  351. v-for="tab in groups"
  352. :key="tab.name"
  353. :label="tab.name"
  354. :value="tab.name">
  355. </el-option>
  356. </el-select>
  357. </el-form-item>
  358. </el-form>
  359. <span slot="footer" class="dialog-footer">
  360. <el-button @click="dialogVisible = false">取 消</el-button>
  361. <el-button type="primary" @click="saveItem">确 定</el-button>
  362. </span>
  363. </el-dialog>
  364. </div>
  365. <script>
  366. let pageManager = new PageManager();
  367. pageManager.type = 'nav-page';
  368. pageManager.setNameCallBack(() => {
  369. let title = localStorage.getItem("title");
  370. document.title = title + " - 导航";
  371. _this.all_data.title = title;
  372. })
  373. let initItem = {
  374. title: '',
  375. icon: '',
  376. // mainUrl: '',
  377. description: '',
  378. extraUrls: [''],
  379. screenshot: ''
  380. }
  381. let _this = new Vue({
  382. el: '#app',
  383. data: {
  384. all_data: {},
  385. activeTab: '常用工具',
  386. groups: [
  387. {
  388. name: "常用工具",
  389. datas: [{
  390. title: "GitHub",
  391. icon: "https://github.githubassets.com/favicons/favicon.svg",
  392. // mainUrl: "https://github.com",
  393. description: "代码托管平台",
  394. extraUrls: [
  395. "https://pages.github.com",
  396. ],
  397. screenshot: ""
  398. }]
  399. }
  400. ],
  401. newTabName: '',
  402. readOnly: false,
  403. showTabManage: false,
  404. // 对话框相关
  405. dialogVisible: false,
  406. isEditing: false,
  407. currentItem: initItem,
  408. originalTab: '',
  409. originalIndex: -1, // 编辑时,记录原始数据在当前标签页中的索引
  410. targetTabIndex: -1, // 编辑时,记录目标标签页名称
  411. targetTab: ''
  412. },
  413. mounted() {
  414. pageManager.init().then(res => {
  415. this.all_data = res;
  416. if (res && res.content) {
  417. let showContent = res.content;
  418. if (pageManager.isBackup) showContent = res.content_back;
  419. this.groups = JSON.parse(showContent);
  420. // groups 里的 extraUrls 应该包含 mainUrl,如果没有,添加进去,为了兼容老数据
  421. this.groups.forEach(group => {
  422. group.datas.forEach(item => {
  423. if (!item.extraUrls) item.extraUrls = [];
  424. if (item.mainUrl) {
  425. if (!item.extraUrls.includes(item.mainUrl)) {
  426. item.extraUrls.unshift(item.mainUrl);
  427. }
  428. }
  429. });
  430. });
  431. }
  432. if (pageManager.isReadOnly()) this.readOnly = true;
  433. });
  434. },
  435. methods: {
  436. scrollToGroup(tabName) {
  437. const element = document.getElementById('group-' + tabName);
  438. if (element) {
  439. element.scrollIntoView({
  440. behavior: 'smooth',
  441. block: 'start'
  442. });
  443. }
  444. },
  445. onTabOrderChange() {
  446. this.updateData();
  447. },
  448. openAddDialog() {
  449. this.isEditing = false;
  450. this.currentItem = JSON.parse(JSON.stringify(initItem));
  451. this.targetTab = this.activeTab;
  452. this.dialogVisible = true;
  453. },
  454. openEditDialog(group, item) {
  455. // 根据 groupName 和 index 获取对应的数据
  456. this.isEditing = true;
  457. this.dialogVisible = true;
  458. this.currentItem = JSON.parse(JSON.stringify(item))
  459. this.targetTab = group.name;
  460. this.originalTab = group.name;
  461. },
  462. getTabNames() {
  463. return this.groups.map(g => g.name);
  464. },
  465. // 根据标签名获取数据
  466. getGroupByName(name) {
  467. return this.groups.find(g => g.name === name);
  468. },
  469. // 新增标签页
  470. addTab() {
  471. if (!this.newTabName) return;
  472. this.groups.push({
  473. name: this.newTabName,
  474. datas: []
  475. });
  476. this.activeTab = this.newTabName;
  477. this.newTabName = '';
  478. this.updateData();
  479. },
  480. // 保存新项目
  481. saveItem() {
  482. if (!this.currentItem.title || !this.currentItem.extraUrls) {
  483. this.$message.warning('标题和主地址为必填项');
  484. return;
  485. }
  486. const targetGroup = this.getGroupByName(this.targetTab);
  487. if (!targetGroup) return;
  488. if (this.isEditing) {
  489. // 编辑模式
  490. const originalGroup = this.getGroupByName(this.originalTab);
  491. if (originalGroup) {
  492. // 更新原始数据
  493. if (this.targetTab === this.originalTab) {
  494. // 同标签页内修改
  495. originalGroup.datas.splice(this.originalIndex, 1, this.currentItem);
  496. } else {
  497. // 跨标签页移动
  498. originalGroup.datas.splice(this.originalIndex, 1);
  499. targetGroup.datas.push(this.currentItem);
  500. }
  501. }
  502. } else {
  503. // 新增模式
  504. if (this.originalIndex !== undefined) {
  505. // 在指定位置后插入
  506. targetGroup.datas.splice(this.originalIndex + 1, 0, this.currentItem);
  507. } else {
  508. // 直接添加到末尾
  509. targetGroup.datas.push(this.currentItem);
  510. }
  511. }
  512. this.updateData();
  513. this.dialogVisible = false;
  514. // 重置位置信息
  515. this.originalIndex = undefined;
  516. this.originalTab = '';
  517. },
  518. addExtraUrl() {
  519. this.currentItem.extraUrls.push('');
  520. },
  521. removeExtraUrl(index) {
  522. this.currentItem.extraUrls.splice(index, 1);
  523. },
  524. // 删除标签页
  525. deleteTab(name) {
  526. this.$confirm('此操作将永久删除该标签页, 是否继续?', '提示', {
  527. confirmButtonText: '确定',
  528. cancelButtonText: '取消',
  529. type: 'warning'
  530. }).then(() => {
  531. const idx = this.groups.findIndex(g => g.name === name);
  532. if (idx > -1) {
  533. this.groups.splice(idx, 1);
  534. this.activeTab = this.groups[0]?.name;
  535. this.updateData();
  536. }
  537. this.$message({
  538. type: 'success',
  539. message: '删除成功!'
  540. });
  541. }).catch(() => {
  542. this.$message({
  543. type: 'info',
  544. message: '已取消删除'
  545. });
  546. });
  547. },
  548. // 修改标签名
  549. editCurrentTabName(oldName) {
  550. this.$prompt('请输入新标签名', '修改标签名称', {
  551. inputValue: oldName,
  552. closeOnClickModal: false,
  553. inputValidator: (value) => {
  554. if (!value) return '标签名不能为空';
  555. if (this.getGroupByName(value) && value !== oldName) {
  556. return '标签名已存在';
  557. }
  558. return true;
  559. }
  560. }).then(({value}) => {
  561. if (value !== oldName) {
  562. const group = this.getGroupByName(oldName);
  563. if (group) {
  564. group.name = value;
  565. this.activeTab = value;
  566. this.updateData();
  567. }
  568. }
  569. });
  570. },
  571. // 删除内容项
  572. deleteContentItem(groupName, index) {
  573. this.$confirm('此操作将永久删除该内容项, 是否继续?', '提示', {
  574. confirmButtonText: '确定',
  575. cancelButtonText: '取消',
  576. type: 'warning'
  577. }).then(() => {
  578. const group = this.getGroupByName(groupName);
  579. if (group) {
  580. group.datas.splice(index, 1);
  581. this.updateData();
  582. }
  583. this.$message({
  584. type: 'success',
  585. message: '删除成功!'
  586. });
  587. }).catch(() => {
  588. this.$message({
  589. type: 'info',
  590. message: '已取消删除'
  591. });
  592. });
  593. },
  594. updateData() {
  595. this.all_data.content = JSON.stringify(this.groups);
  596. pageManager.updateData(this.all_data);
  597. },
  598. onDragChange(tabName) {
  599. this.updateData();
  600. },
  601. handleTabClick(tab) {
  602. this.activeTab = tab.name;
  603. },
  604. // 在当前标签后新增标签
  605. addTabAfter(name) {
  606. this.$prompt('请输入新标签名', '添加标签名称', {
  607. closeOnClickModal: false,
  608. inputValidator: (value) => {
  609. if (!value) return '标签名不能为空';
  610. if (this.getGroupByName(value)) return '标签名已存在';
  611. return true;
  612. }
  613. }).then(({value}) => {
  614. const idx = this.groups.findIndex(g => g.name === name);
  615. this.groups.splice(idx + 1, 0, {
  616. name: value,
  617. datas: []
  618. });
  619. this.activeTab = value;
  620. this.updateData();
  621. });
  622. },
  623. addContentItemAfter(groupName, index) {
  624. this.isEditing = false;
  625. // 重置当前项
  626. this.currentItem = JSON.parse(JSON.stringify(initItem));
  627. // 存储目标位置信息
  628. this.targetTab = groupName;
  629. this.originalTab = groupName;
  630. this.originalIndex = index;
  631. this.dialogVisible = true;
  632. },
  633. }
  634. });
  635. </script>
  636. </body>
  637. </html>