mycopy.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Dynamic Clipboard Tabs</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: 300px;
  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. </style>
  82. <script src="js/Sortable.min.js"></script>
  83. <script src="js/vuedraggable.umd.min.js"></script>
  84. <script src="js/axios.min.js"></script>
  85. </head>
  86. <body>
  87. <div id="app" class="tab-container">
  88. <!-- 标签导航 -->
  89. <el-tabs v-model="activeTab" @tab-click="handleTabClick" type="card">
  90. <el-tab-pane
  91. v-for="(content, tabName) in myObj"
  92. :key="tabName"
  93. :label="tabName"
  94. :name="tabName">
  95. <!-- 标签页内容 -->
  96. <div class="tab-content">
  97. <!-- 内容项列表 -->
  98. <draggable
  99. :disabled="readOnly"
  100. v-model="myObj[tabName]"
  101. tag="div"
  102. @change="onDragChange(tabName)"
  103. handle=".drag-handle"
  104. class="content-list">
  105. <div
  106. v-for="(item, index) in myObj[tabName]"
  107. :key="item.key"
  108. class="content-item"
  109. @click.stop="copyToClipboard(item.value)"
  110. >
  111. <el-card shadow="hover" class="item-card">
  112. <div slot="header" class="item-content">
  113. <span>{{ item.key }}</span>
  114. <div class="action-buttons">
  115. <el-button
  116. type="text"
  117. class="drag-handle">
  118. <i class="el-icon-rank"></i>
  119. </el-button>
  120. <el-button
  121. type="text"
  122. @click.stop="editContentItem(tabName, item.key, item.value)">
  123. <i class="el-icon-edit"></i>
  124. </el-button>
  125. <el-button
  126. type="text"
  127. @click.stop="deleteContentItem(tabName, item.key)">
  128. <i class="el-icon-delete"></i>
  129. </el-button>
  130. </div>
  131. </div>
  132. <div class="item-2">
  133. <el-tooltip :content="item.value">
  134. <span>{{ item.value }}</span>
  135. </el-tooltip>
  136. </div>
  137. </el-card>
  138. </div>
  139. </draggable>
  140. <div v-if="!readOnly">
  141. <!-- 添加内容项 -->
  142. <div class="add-item">
  143. <el-input
  144. v-model="newItemKey[activeTab]"
  145. placeholder="键名"
  146. style="width: 200px; margin-right: 10px;"></el-input>
  147. <el-input
  148. v-model="newItemValue[activeTab]"
  149. placeholder="键值"
  150. style="width: 200px; margin-right: 10px;"></el-input>
  151. <el-button
  152. type="primary"
  153. @click="addContentItem(activeTab)"
  154. :disabled="!newItemKey[activeTab] || !newItemValue[activeTab]">
  155. 添加内容项
  156. </el-button>
  157. </div>
  158. <br>
  159. <!-- 删除当前标签页 -->
  160. <el-button
  161. type="danger"
  162. size="small"
  163. @click="deleteTab(activeTab)">
  164. 删除当前标签页
  165. </el-button>
  166. <!-- 修改当前标签名-->
  167. <el-button
  168. type="primary"
  169. size="small"
  170. @click="editTabName(activeTab)">
  171. 修改当前标签名
  172. </el-button>
  173. </div>
  174. </div>
  175. </el-tab-pane>
  176. <br>
  177. <!-- 添加新标签页 -->
  178. <div class="add-tab" v-if="!readOnly">
  179. <el-input
  180. v-model="newTabName"
  181. placeholder="新标签页名称"
  182. style="width: 200px; margin-right: 10px;"></el-input>
  183. <el-button
  184. type="primary"
  185. @click="addTab"
  186. :disabled="!newTabName || myObj[newTabName]">
  187. 添加标签页
  188. </el-button>
  189. </div>
  190. </el-tabs>
  191. </div>
  192. <script>
  193. // let all_data = {};
  194. let pageManager = new PageManager();
  195. pageManager.type = 'copy-page';
  196. pageManager.setNameCallBack(() => {
  197. let title = localStorage.getItem("title");
  198. document.title = title + " - 复制";
  199. _this.all_data.title = title;
  200. })
  201. let _this = new Vue({
  202. el: '#app',
  203. data: {
  204. all_data: {},
  205. activeTab: '',
  206. myObj: {
  207. "tab1": [
  208. {key: "ab1", value: "value1"},
  209. {key: "ab2", value: "value2"},
  210. {key: "ab3", value: "value3"}
  211. ],
  212. "tab2": [
  213. {key: "ab1", value: "value4"},
  214. {key: "ab2", value: "value5"}
  215. ]
  216. },
  217. newTabName: '',
  218. newItemKey: {},
  219. newItemValue: {},
  220. editingItem: null,
  221. editingKey: '',
  222. readOnly: false,
  223. },
  224. mounted() {
  225. pageManager.init().then(res => {
  226. this.all_data = res;
  227. console.log(res)
  228. if (res && res.content) {
  229. // 初始化数据
  230. let showContent = res.content;
  231. if (pageManager.isBackup) {
  232. // 如果是备份
  233. showContent = res.content_back;
  234. }
  235. this.myObj = JSON.parse(showContent);
  236. // 设置activeTab
  237. this.activeTab = localStorage.getItem("tab") || Object.keys(this.myObj)[0] || '';
  238. }
  239. if (pageManager.isReadOnly()) {
  240. // 备份页面或分享页面,设置为只读
  241. this.readOnly = true;
  242. }
  243. });
  244. },
  245. methods: {
  246. updateData() {
  247. this.all_data.content = JSON.stringify(this.myObj);
  248. pageManager.updateData(this.all_data);
  249. },
  250. editTabName(activeTab) {
  251. // 先获取当前标签名,弹框提醒用户更改
  252. this.$prompt('请输入新的标签名', '修改标签名', {
  253. confirmButtonText: '确定',
  254. cancelButtonText: '取消',
  255. closeOnClickModal: false,
  256. inputValue: activeTab
  257. })
  258. .then(({value}) => {
  259. // 确认更改后,更新标签名, 让vue监听到,使用 this.$set 方法
  260. this.$set(this.myObj, value, this.myObj[activeTab]);
  261. delete this.myObj[activeTab];
  262. this.activeTab = value;
  263. _this.updateData();
  264. })
  265. },
  266. deleteTab(activeTab) {
  267. if (this.myObj[activeTab]) {
  268. this.$confirm('确定删除该标签页?', '警告', {
  269. confirmButtonText: '确定',
  270. cancelButtonText: '取消',
  271. type: 'warning'
  272. }).then(() => {
  273. delete this.myObj[activeTab];
  274. this.activeTab = Object.keys(this.myObj)[0] || '';
  275. _this.updateData();
  276. }).catch(() => {
  277. });
  278. }
  279. },
  280. handleTabClick(tab) {
  281. this.activeTab = tab.name;
  282. // 保存到本地 localStorage
  283. localStorage.setItem("tab", this.activeTab);
  284. },
  285. // 添加标签页
  286. addTab() {
  287. if (!this.newTabName || this.myObj[this.newTabName]) return;
  288. this.myObj[this.newTabName] = [];
  289. this.activeTab = this.newTabName;
  290. this.newTabName = '';
  291. _this.updateData();
  292. },
  293. // 删除标签页(需确认)
  294. deleteTab(tabName) {
  295. this.$confirm('确定删除该标签页?', '警告', {
  296. confirmButtonText: '确定',
  297. cancelButtonText: '取消',
  298. type: 'warning'
  299. }).then(() => {
  300. delete this.myObj[tabName];
  301. this.activeTab = Object.keys(this.myObj)[0] || '';
  302. _this.updateData();
  303. }).catch(() => {
  304. });
  305. },
  306. // 添加内容项
  307. addContentItem(tabName) {
  308. const key = this.newItemKey[tabName];
  309. const value = this.newItemValue[tabName];
  310. if (!key || !value) return;
  311. this.myObj[tabName].push({key, value});
  312. this.newItemKey[tabName] = '';
  313. this.newItemValue[tabName] = '';
  314. _this.updateData();
  315. },
  316. // 删除内容项
  317. deleteContentItem(tabName, key) {
  318. this.$confirm('确定删除该内容项?', '警告', {
  319. confirmButtonText: '确定',
  320. cancelButtonText: '取消',
  321. type: 'warning'
  322. }).then(() => {
  323. this.myObj[tabName] = this.myObj[tabName].filter(item => item.key !== key);
  324. this.$message({message: '删除成功', type: 'success'});
  325. _this.updateData();
  326. }).catch(() => {
  327. });
  328. },
  329. editContentItem(tabName, key, value) {
  330. this.editingItem = {tabName, key, value};
  331. this.editingKey = key;
  332. // 保存原始值用于回滚
  333. const originalKey = key;
  334. const originalValue = value;
  335. // 第一步:修改Key
  336. this.$prompt('修改Key', '编辑内容', {
  337. confirmButtonText: '保存',
  338. cancelButtonText: '取消',
  339. inputPlaceholder: '输入新Key',
  340. closeOnClickModal: false,
  341. inputValue: key
  342. }).then(({value: newKey}) => {
  343. // 第二步:修改Value
  344. return this.$prompt('修改值', '编辑内容', {
  345. confirmButtonText: '保存',
  346. cancelButtonText: '取消',
  347. inputPlaceholder: '输入新值',
  348. closeOnClickModal: false,
  349. inputValue: value
  350. }).then(({value: newValue}) => {
  351. // 更新数据
  352. const items = this.myObj[tabName];
  353. const itemIndex = items.findIndex(item => item.key === originalKey);
  354. if (itemIndex !== -1) {
  355. items[itemIndex].key = newKey;
  356. items[itemIndex].value = newValue;
  357. }
  358. this.updateData();
  359. this.editingItem = null;
  360. });
  361. }).catch(() => {
  362. // 如果任一步骤取消,重置状态
  363. this.editingItem = null;
  364. });
  365. },
  366. // 复制到剪贴板
  367. copyToClipboard(text) {
  368. const clipboard = new ClipboardJS('.dummy', {
  369. text: () => text
  370. });
  371. clipboard.on('success', () => {
  372. this.$message({message: '复制成功', type: 'success'});
  373. clipboard.destroy();
  374. });
  375. clipboard.on('error', () => {
  376. this.$message({message: '复制失败', type: 'error'});
  377. clipboard.destroy();
  378. });
  379. const dummy = document.createElement('button');
  380. dummy.className = 'dummy';
  381. document.body.appendChild(dummy);
  382. dummy.click();
  383. document.body.removeChild(dummy);
  384. },
  385. // 拖拽排序事件
  386. onDragChange(tabName) {
  387. console.log(`拖拽后 ${tabName} 的顺序:`, this.myObj[tabName]);
  388. this.$message({message: '排序已更新', type: 'success'});
  389. _this.updateData();
  390. }
  391. }
  392. });
  393. </script>
  394. </body>
  395. </html>