nav.html 22 KB

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