nav.html 18 KB

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