nav.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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. animation="300"
  147. :disabled="readOnly"
  148. v-model="myObj[tabName]"
  149. tag="div"
  150. @change="onDragChange(tabName)"
  151. handle=".drag-handle"
  152. class="content-list">
  153. <div
  154. v-for="(item, index) in myObj[tabName]"
  155. :key="index"
  156. class="content-item">
  157. <el-card shadow="hover" class="item-card">
  158. <div slot="header" class="item-content">
  159. <el-image
  160. :src="item.icon"
  161. style="width: 20px; height: 20px; margin-right: 8px;"
  162. fit="contain"
  163. ></el-image>
  164. <span>{{ item.title }}</span>
  165. <div class="action-buttons">
  166. <div v-if="!readOnly">
  167. <el-button type="text" class="drag-handle">
  168. <i class="el-icon-rank"></i>
  169. </el-button>
  170. <el-button
  171. type="text"
  172. @click.stop="openEditDialog(tabName, index)">
  173. <i class="el-icon-edit"></i>
  174. </el-button>
  175. <el-button
  176. type="text"
  177. @click.stop="deleteContentItem(tabName, index)">
  178. <i class="el-icon-delete"></i>
  179. </el-button>
  180. </div>
  181. </div>
  182. </div>
  183. <div class="item-content">
  184. <div style="width: 100%">
  185. <div class="item-description">{{ item.description || item.title }}</div>
  186. <el-tooltip>
  187. <div class="link-section">
  188. <el-link
  189. type="primary"
  190. :href="item.mainUrl"
  191. target="_blank">{{ item.mainUrl }}
  192. </el-link>
  193. </div>
  194. <div slot="content" v-if="item.extraUrls && item.extraUrls.length" class="extra-links">
  195. <el-tag
  196. v-for="(url, idx) in item.extraUrls"
  197. :key="idx"
  198. type="info"
  199. class="extra-link-tag">
  200. <el-link :href="url" target="_blank">{{ url }}</el-link>
  201. </el-tag>
  202. </div>
  203. <div slot="content" v-else>
  204. 没有更多链接
  205. </div>
  206. </el-tooltip>
  207. <div v-if="item.screenshot" class="screenshot-section">
  208. <el-image
  209. :src="item.screenshot"
  210. style="max-width: 100%; height: 220px;"
  211. :preview-src-list="[item.screenshot]"
  212. fit="cover"></el-image>
  213. </div>
  214. </div>
  215. </div>
  216. </el-card>
  217. </div>
  218. </draggable>
  219. <!-- 添加新项部分 -->
  220. <div v-if="!readOnly">
  221. <el-button type="primary" @click="openAddDialog">添加新项</el-button>
  222. <el-button @click="showTabManage = !showTabManage">
  223. {{ showTabManage ? '隐藏标签管理' : '显示标签管理' }}
  224. </el-button>
  225. <!-- 标签管理 -->
  226. <!-- 标签管理部分 -->
  227. <div v-if="showTabManage" style="margin-top: 20px;">
  228. <el-input
  229. v-model="newTabName"
  230. placeholder="新标签页名称"
  231. style="width: 200px; margin-right: 10px;"></el-input>
  232. <el-button
  233. type="primary"
  234. @click="addTab"
  235. :disabled="!newTabName || myObj[newTabName]">
  236. 添加标签页
  237. </el-button>
  238. <el-button
  239. type="warning"
  240. @click="editCurrentTabName"
  241. :disabled="!activeTab">
  242. 修改当前标签名
  243. </el-button>
  244. <el-button
  245. type="danger"
  246. @click="deleteTab(activeTab)"
  247. :disabled="Object.keys(myObj).length <= 1">
  248. 删除当前标签
  249. </el-button>
  250. </div>
  251. </div>
  252. </div>
  253. </el-tab-pane>
  254. </el-tabs>
  255. <br>
  256. <div v-if="showTabManage" style="display: flex;line-height: 2em">
  257. <div>拖拽排序:</div>
  258. <draggable v-model="tabOrder" @change="onTabOrderChange" handle=".drag-handle" style="display: flex;" animation="300">
  259. <div v-for="tabName in tabOrder" :key="tabName" class="tab-item drag-handle">
  260. <span>{{ tabName }}</span>
  261. </div>
  262. </draggable>
  263. </div>
  264. <!-- 编辑对话框 -->
  265. <el-dialog
  266. :close-on-click-modal="false"
  267. :title="isEditing ? '编辑项目' : '添加新项'"
  268. :visible.sync="dialogVisible"
  269. width="600px">
  270. <el-form :model="currentItem" label-width="80px">
  271. <el-form-item label="标题">
  272. <el-input v-model="currentItem.title"></el-input>
  273. </el-form-item>
  274. <el-form-item label="图标URL">
  275. <el-input v-model="currentItem.icon"></el-input>
  276. </el-form-item>
  277. <el-form-item label="主地址">
  278. <el-input v-model="currentItem.mainUrl"></el-input>
  279. </el-form-item>
  280. <el-form-item label="描述">
  281. <el-input v-model="currentItem.description" type="textarea"></el-input>
  282. </el-form-item>
  283. <el-form-item label="附加地址">
  284. <div v-for="(url, index) in currentItem.extraUrls" :key="index">
  285. <el-input v-model="currentItem.extraUrls[index]" style="margin-bottom: 5px;">
  286. <el-button
  287. slot="append"
  288. icon="el-icon-remove"
  289. @click="removeExtraUrl(index)"></el-button>
  290. </el-input>
  291. </div>
  292. <el-button @click="addExtraUrl">添加附加地址</el-button>
  293. </el-form-item>
  294. <el-form-item label="截图URL">
  295. <el-input v-model="currentItem.screenshot"></el-input>
  296. </el-form-item>
  297. <el-form-item label="所属标签">
  298. <el-select v-model="targetTab" placeholder="请选择标签页">
  299. <el-option
  300. v-for="tab in Object.keys(myObj)"
  301. :key="tab"
  302. :label="tab"
  303. :value="tab">
  304. </el-option>
  305. </el-select>
  306. </el-form-item>
  307. </el-form>
  308. <span slot="footer" class="dialog-footer">
  309. <el-button @click="dialogVisible = false">取 消</el-button>
  310. <el-button type="primary" @click="saveItem">确 定</el-button>
  311. </span>
  312. </el-dialog>
  313. </div>
  314. <script>
  315. let pageManager = new PageManager();
  316. pageManager.type = 'nav-page';
  317. pageManager.setNameCallBack(() => {
  318. let title = localStorage.getItem("title");
  319. document.title = title + " - 导航";
  320. _this.all_data.title = title;
  321. })
  322. let _this = new Vue({
  323. el: '#app',
  324. data: {
  325. tabOrder: [],
  326. all_data: {},
  327. activeTab: '常用工具',
  328. myObj: {
  329. "常用工具": [{
  330. title: "GitHub",
  331. icon: "https://github.githubassets.com/favicons/favicon.svg",
  332. mainUrl: "https://github.com",
  333. description: "代码托管平台",
  334. extraUrls: [
  335. "https://gist.github.com",
  336. "https://pages.github.com"
  337. ],
  338. screenshot: ""
  339. }]
  340. },
  341. newTabName: '',
  342. readOnly: false,
  343. showTabManage: false,
  344. // 对话框相关
  345. dialogVisible: false,
  346. isEditing: false,
  347. currentItem: {
  348. title: '',
  349. icon: '',
  350. mainUrl: '',
  351. description: '',
  352. extraUrls: [],
  353. screenshot: ''
  354. },
  355. originalTab: '',
  356. originalIndex: -1,
  357. targetTab: ''
  358. },
  359. mounted() {
  360. pageManager.init().then(res => {
  361. this.all_data = res;
  362. if (res && res.content) {
  363. let showContent = res.content;
  364. if (pageManager.isBackup) showContent = res.content_back;
  365. this.myObj = JSON.parse(showContent);
  366. }
  367. this.activeTab = Object.keys(this.myObj)[0] || '';
  368. if (pageManager.isReadOnly()) this.readOnly = true;
  369. this.mouseOver();
  370. this.tabOrder = Object.keys(this.myObj);
  371. });
  372. },
  373. methods: {
  374. onTabOrderChange() {
  375. const newMyObj = {};
  376. this.tabOrder.forEach(tabName => {
  377. newMyObj[tabName] = this.myObj[tabName];
  378. });
  379. this.myObj = newMyObj;
  380. this.updateData();
  381. },
  382. // 鼠标滑过,切换tabs
  383. mouseOver() {
  384. this.$nextTick(() => {
  385. this.$refs.navTabs.$refs.nav.$nextTick(() => {
  386. // console.log('$refs.nav', this.$refs.navTabs.$refs.nav.$el)
  387. // 此时tab的nav才渲染dom 否则拿不到el-tabs__item
  388. const target = document.getElementsByClassName('el-tabs__item')
  389. for (let i = 0; i < target.length; i++) {
  390. target[i].addEventListener('mouseover', () => {
  391. target[i].click();
  392. })
  393. }
  394. })
  395. });
  396. },
  397. editCurrentTabName() {
  398. this.$prompt('请输入新标签名', '修改标签名称', {
  399. inputValue: this.activeTab,
  400. closeOnClickModal: false,
  401. inputValidator: (value) => {
  402. if (!value) return '标签名不能为空';
  403. if (this.myObj[value] && value !== this.activeTab) return '标签名已存在';
  404. return true;
  405. }
  406. }).then(({value}) => {
  407. if (value !== this.activeTab) {
  408. // 创建新标签并转移数据
  409. this.$set(this.myObj, value, this.myObj[this.activeTab]);
  410. delete this.myObj[this.activeTab];
  411. this.activeTab = value;
  412. this.updateData();
  413. }
  414. }).catch(() => {
  415. });
  416. },
  417. openAddDialog() {
  418. this.isEditing = false;
  419. this.currentItem = {
  420. title: '',
  421. icon: '',
  422. mainUrl: '',
  423. description: '',
  424. extraUrls: [],
  425. screenshot: ''
  426. };
  427. this.targetTab = this.activeTab;
  428. this.dialogVisible = true;
  429. },
  430. openEditDialog(tabName, index) {
  431. this.isEditing = true;
  432. this.originalTab = tabName;
  433. this.originalIndex = index;
  434. this.currentItem = JSON.parse(JSON.stringify(this.myObj[tabName][index]));
  435. this.targetTab = tabName;
  436. this.dialogVisible = true;
  437. },
  438. saveItem() {
  439. if (!this.currentItem.title || !this.currentItem.mainUrl) {
  440. this.$message.warning('标题和主地址为必填项');
  441. return;
  442. }
  443. // 删除原有项(编辑时)
  444. if (this.isEditing) {
  445. this.myObj[this.originalTab].splice(this.originalIndex, 1);
  446. }
  447. // 添加到目标标签
  448. if (!this.myObj[this.targetTab]) this.myObj[this.targetTab] = [];
  449. this.myObj[this.targetTab].push(this.currentItem);
  450. this.updateData();
  451. this.dialogVisible = false;
  452. },
  453. addExtraUrl() {
  454. this.currentItem.extraUrls.push('');
  455. },
  456. removeExtraUrl(index) {
  457. this.currentItem.extraUrls.splice(index, 1);
  458. },
  459. addTab() {
  460. if (!this.newTabName) return;
  461. this.$set(this.myObj, this.newTabName, []);
  462. this.activeTab = this.newTabName;
  463. this.newTabName = '';
  464. _this.tabOrder = Object.keys(this.myObj);
  465. this.updateData();
  466. },
  467. deleteTab(tabName) {
  468. this.$confirm('确定删除该标签页?', '警告', {
  469. confirmButtonText: '确定',
  470. cancelButtonText: '取消',
  471. type: 'warning'
  472. }).then(() => {
  473. delete this.myObj[tabName];
  474. this.activeTab = Object.keys(this.myObj)[0] || '';
  475. this.updateData();
  476. });
  477. },
  478. deleteContentItem(tabName, index) {
  479. this.$confirm('确定删除该项?', '警告', {
  480. confirmButtonText: '确定',
  481. cancelButtonText: '取消',
  482. type: 'warning'
  483. }).then(() => {
  484. this.myObj[tabName].splice(index, 1);
  485. this.updateData();
  486. });
  487. },
  488. updateData() {
  489. this.all_data.content = JSON.stringify(this.myObj);
  490. pageManager.updateData(this.all_data);
  491. },
  492. onDragChange(tabName) {
  493. this.updateData();
  494. },
  495. handleTabClick(tab) {
  496. this.activeTab = tab.name;
  497. }
  498. }
  499. });
  500. </script>
  501. </body>
  502. </html>