nav.html 19 KB

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