nav.html 22 KB

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