nav.html 22 KB

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