nav.html 18 KB

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