nav.html 20 KB

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