nav.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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" style="display: flex;line-height: 2em">
  256. <div>拖拽排序:</div>
  257. <draggable v-model="tabOrder" @change="onTabOrderChange" handle=".drag-handle" style="display: flex;">
  258. <div v-for="tabName in tabOrder" :key="tabName" class="tab-item drag-handle">
  259. <span>{{ tabName }}</span>
  260. </div>
  261. </draggable>
  262. </div>
  263. <!-- 编辑对话框 -->
  264. <el-dialog
  265. :title="isEditing ? '编辑项目' : '添加新项'"
  266. :visible.sync="dialogVisible"
  267. width="600px">
  268. <el-form :model="currentItem" label-width="80px">
  269. <el-form-item label="标题">
  270. <el-input v-model="currentItem.title"></el-input>
  271. </el-form-item>
  272. <el-form-item label="图标URL">
  273. <el-input v-model="currentItem.icon"></el-input>
  274. </el-form-item>
  275. <el-form-item label="主地址">
  276. <el-input v-model="currentItem.mainUrl"></el-input>
  277. </el-form-item>
  278. <el-form-item label="描述">
  279. <el-input v-model="currentItem.description" type="textarea"></el-input>
  280. </el-form-item>
  281. <el-form-item label="附加地址">
  282. <div v-for="(url, index) in currentItem.extraUrls" :key="index">
  283. <el-input v-model="currentItem.extraUrls[index]" style="margin-bottom: 5px;">
  284. <el-button
  285. slot="append"
  286. icon="el-icon-remove"
  287. @click="removeExtraUrl(index)"></el-button>
  288. </el-input>
  289. </div>
  290. <el-button @click="addExtraUrl">添加附加地址</el-button>
  291. </el-form-item>
  292. <el-form-item label="截图URL">
  293. <el-input v-model="currentItem.screenshot"></el-input>
  294. </el-form-item>
  295. <el-form-item label="所属标签">
  296. <el-select v-model="targetTab" placeholder="请选择标签页">
  297. <el-option
  298. v-for="tab in Object.keys(myObj)"
  299. :key="tab"
  300. :label="tab"
  301. :value="tab">
  302. </el-option>
  303. </el-select>
  304. </el-form-item>
  305. </el-form>
  306. <span slot="footer" class="dialog-footer">
  307. <el-button @click="dialogVisible = false">取 消</el-button>
  308. <el-button type="primary" @click="saveItem">确 定</el-button>
  309. </span>
  310. </el-dialog>
  311. </div>
  312. <script>
  313. let pageManager = new PageManager();
  314. pageManager.type = 'nav-page';
  315. pageManager.setNameCallBack(() => {
  316. let title = localStorage.getItem("title");
  317. document.title = title + " - 导航";
  318. _this.all_data.title = title;
  319. })
  320. let _this = new Vue({
  321. el: '#app',
  322. data: {
  323. tabOrder: [],
  324. all_data: {},
  325. activeTab: '常用工具',
  326. myObj: {
  327. "常用工具": [{
  328. title: "GitHub",
  329. icon: "https://github.githubassets.com/favicons/favicon.svg",
  330. mainUrl: "https://github.com",
  331. description: "代码托管平台",
  332. extraUrls: [
  333. "https://gist.github.com",
  334. "https://pages.github.com"
  335. ],
  336. screenshot: ""
  337. }]
  338. },
  339. newTabName: '',
  340. readOnly: false,
  341. showTabManage: false,
  342. // 对话框相关
  343. dialogVisible: false,
  344. isEditing: false,
  345. currentItem: {
  346. title: '',
  347. icon: '',
  348. mainUrl: '',
  349. description: '',
  350. extraUrls: [],
  351. screenshot: ''
  352. },
  353. originalTab: '',
  354. originalIndex: -1,
  355. targetTab: ''
  356. },
  357. mounted() {
  358. pageManager.init().then(res => {
  359. this.all_data = res;
  360. if (res && res.content) {
  361. let showContent = res.content;
  362. if (pageManager.isBackup) showContent = res.content_back;
  363. this.myObj = JSON.parse(showContent);
  364. }
  365. this.activeTab = Object.keys(this.myObj)[0] || '';
  366. if (pageManager.isReadOnly()) this.readOnly = true;
  367. this.mouseOver();
  368. this.tabOrder = Object.keys(this.myObj);
  369. });
  370. },
  371. methods: {
  372. onTabOrderChange() {
  373. const newMyObj = {};
  374. this.tabOrder.forEach(tabName => {
  375. newMyObj[tabName] = this.myObj[tabName];
  376. });
  377. this.myObj = newMyObj;
  378. this.updateData();
  379. },
  380. // 鼠标滑过,切换tabs
  381. mouseOver() {
  382. this.$nextTick(() => {
  383. this.$refs.navTabs.$refs.nav.$nextTick(() => {
  384. // console.log('$refs.nav', this.$refs.navTabs.$refs.nav.$el)
  385. // 此时tab的nav才渲染dom 否则拿不到el-tabs__item
  386. const target = document.getElementsByClassName('el-tabs__item')
  387. for (let i = 0; i < target.length; i++) {
  388. target[i].addEventListener('mouseover', () => {
  389. target[i].click();
  390. })
  391. }
  392. })
  393. });
  394. },
  395. editCurrentTabName() {
  396. this.$prompt('请输入新标签名', '修改标签名称', {
  397. inputValue: this.activeTab,
  398. closeOnClickModal: false,
  399. inputValidator: (value) => {
  400. if (!value) return '标签名不能为空';
  401. if (this.myObj[value] && value !== this.activeTab) return '标签名已存在';
  402. return true;
  403. }
  404. }).then(({value}) => {
  405. if (value !== this.activeTab) {
  406. // 创建新标签并转移数据
  407. this.$set(this.myObj, value, this.myObj[this.activeTab]);
  408. delete this.myObj[this.activeTab];
  409. this.activeTab = value;
  410. this.updateData();
  411. }
  412. }).catch(() => {
  413. });
  414. },
  415. openAddDialog() {
  416. this.isEditing = false;
  417. this.currentItem = {
  418. title: '',
  419. icon: '',
  420. mainUrl: '',
  421. description: '',
  422. extraUrls: [],
  423. screenshot: ''
  424. };
  425. this.targetTab = this.activeTab;
  426. this.dialogVisible = true;
  427. },
  428. openEditDialog(tabName, index) {
  429. this.isEditing = true;
  430. this.originalTab = tabName;
  431. this.originalIndex = index;
  432. this.currentItem = JSON.parse(JSON.stringify(this.myObj[tabName][index]));
  433. this.targetTab = tabName;
  434. this.dialogVisible = true;
  435. },
  436. saveItem() {
  437. if (!this.currentItem.title || !this.currentItem.mainUrl) {
  438. this.$message.warning('标题和主地址为必填项');
  439. return;
  440. }
  441. // 删除原有项(编辑时)
  442. if (this.isEditing) {
  443. this.myObj[this.originalTab].splice(this.originalIndex, 1);
  444. }
  445. // 添加到目标标签
  446. if (!this.myObj[this.targetTab]) this.myObj[this.targetTab] = [];
  447. this.myObj[this.targetTab].push(this.currentItem);
  448. this.updateData();
  449. this.dialogVisible = false;
  450. },
  451. addExtraUrl() {
  452. this.currentItem.extraUrls.push('');
  453. },
  454. removeExtraUrl(index) {
  455. this.currentItem.extraUrls.splice(index, 1);
  456. },
  457. addTab() {
  458. if (!this.newTabName) return;
  459. this.$set(this.myObj, this.newTabName, []);
  460. this.activeTab = this.newTabName;
  461. this.newTabName = '';
  462. _this.tabOrder = Object.keys(this.myObj);
  463. this.updateData();
  464. },
  465. deleteTab(tabName) {
  466. this.$confirm('确定删除该标签页?', '警告', {
  467. confirmButtonText: '确定',
  468. cancelButtonText: '取消',
  469. type: 'warning'
  470. }).then(() => {
  471. delete this.myObj[tabName];
  472. this.activeTab = Object.keys(this.myObj)[0] || '';
  473. this.updateData();
  474. });
  475. },
  476. deleteContentItem(tabName, index) {
  477. this.$confirm('确定删除该项?', '警告', {
  478. confirmButtonText: '确定',
  479. cancelButtonText: '取消',
  480. type: 'warning'
  481. }).then(() => {
  482. this.myObj[tabName].splice(index, 1);
  483. this.updateData();
  484. });
  485. },
  486. updateData() {
  487. this.all_data.content = JSON.stringify(this.myObj);
  488. pageManager.updateData(this.all_data);
  489. },
  490. onDragChange(tabName) {
  491. this.updateData();
  492. },
  493. handleTabClick(tab) {
  494. this.activeTab = tab.name;
  495. }
  496. }
  497. });
  498. </script>
  499. </body>
  500. </html>