Skip to content

Commit 7a879dd

Browse files
committed
feat(Main): 优化工作区创建和增加数据导入导出功能
- 移除不必要的页面组件 - 重构工作区创建逻辑,增加表单验证 - 添加工作区数据导入导出功能 - 优化工作区列表显示和操作 - 调整页面样式和布局
1 parent cbf4f1c commit 7a879dd

File tree

9 files changed

+309
-209
lines changed

9 files changed

+309
-209
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "TabManager",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"description": "chrome和QQ浏览器有个好用的功能,就是当你直接关闭浏览器时,如果当时打开了多个tab,在你再次打开浏览器时,可以在历史记录(最近关闭的标签)一次恢复他们.但是如果你忘记了恢复,并且开了一些网页并关闭过,再想恢复时,发现找不到了...",
66
"icons": {
77
"16": "src/assets/images/tab.png",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tabmanager",
33
"private": true,
4-
"version": "0.0.1",
4+
"version": "1.0.1",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup>
2-
import {computed, onMounted, ref} from "vue";
2+
import {computed, ref} from "vue";
33
import {routes} from "./router.js";
44
import NotFound from "./pages/NotFound.vue";
55

src/common.js

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
import localforage from "localforage";
22

33
export const TabItem = function () {
4-
this.id = "";
5-
this.title = "";
6-
this.url = "";
4+
this.id = "";
5+
this.title = "";
6+
this.url = "";
77
}
88

99
export var WorkSpaceItem = function () {
10-
this.fid = ""; // 主键ID
11-
this.workSpaceName = ""; // 工作区名称
12-
this.saveDataTime = ""; // 保存时间
13-
this.spaceTabs = []; // 工作区中的页面
10+
this.fid = ""; // 主键ID
11+
this.workSpaceName = ""; // 工作区名称
12+
this.saveDataTime = ""; // 保存时间
13+
this.spaceTabs = []; // 工作区中的页面
1414
}
1515
/**
1616
* 地址让获取参数
1717
* @param variable 地址栏参数名称
1818
* @returns {string|boolean} 参数数据
1919
*/
2020
export const getQueryVariable = (variable) => {
21-
const hashUrl = window.location.hash
22-
const query = hashUrl.split('?')[1]
23-
const vars = query.split('&')
24-
for (const element of vars) {
25-
const pair = element.split('=')
26-
if (pair[0] === variable) {
27-
return pair[1]
28-
}
21+
const hashUrl = window.location.hash
22+
const query = hashUrl.split('?')[1]
23+
const vars = query.split('&')
24+
for (const element of vars) {
25+
const pair = element.split('=')
26+
if (pair[0] === variable) {
27+
return pair[1]
2928
}
30-
return ''
29+
}
30+
return ''
3131
}
3232

3333
/**
@@ -37,22 +37,54 @@ export const getQueryVariable = (variable) => {
3737
* @param serialization 是否序列化
3838
*/
3939
export const saveData = async (key, data, serialization = true) => {
40-
console.debug("saveData key:" , key + " data:" , data)
41-
if (serialization) {
42-
data = JSON.stringify(data)
43-
}
44-
await localforage.setItem(key, data)
40+
console.debug("saveData key:", key + " data:", data)
41+
if (serialization) {
42+
data = JSON.stringify(data)
43+
}
44+
await localforage.setItem(key, data)
4545
}
4646

4747
export const getData = (key, serialization = true) => {
48-
return new Promise((resolve, reject) => {
49-
localforage.getItem(key).then((data) => {
50-
if (serialization) {
51-
data = JSON.parse(data)
52-
}
53-
resolve(data)
54-
}).catch((err) => {
55-
reject(err)
56-
})
48+
return new Promise((resolve, reject) => {
49+
localforage.getItem(key).then((data) => {
50+
if (serialization) {
51+
data = JSON.parse(data)
52+
}
53+
resolve(data)
54+
}).catch((err) => {
55+
reject(err)
5756
})
58-
}
57+
})
58+
}
59+
60+
/**
61+
* 合并数据(将本地的数据合并到上传的数据中)
62+
* @param data1 需要合并的数据(上传的)
63+
* @param data2 需要合并的数据(本地的)
64+
* @returns {*[]}
65+
*/
66+
export const mergeData = (data1, data2) => {
67+
const mergedData = [...data1];
68+
data2.forEach(newItem => {
69+
const existingItemIndex = mergedData.findIndex(item => item.fid === newItem.fid);
70+
if (existingItemIndex === -1) {
71+
// 如果新数据的fid不存在,则添加新的工作空间
72+
mergedData.push(newItem);
73+
} else {
74+
// 如果fid已经存在,合并spaceTabs
75+
const existingItem = mergedData[existingItemIndex];
76+
newItem.spaceTabs.forEach(newTab => {
77+
// 判断是否存在相同title和url的tab
78+
const existingTabIndex = existingItem.spaceTabs.findIndex(tab => tab.title === newTab.title && tab.url === newTab.url);
79+
if (existingTabIndex === -1) {
80+
// 如果tab不存在,添加新的tab
81+
existingItem.spaceTabs.push(newTab);
82+
} else {
83+
// 如果tab已经存在,可以选择合并字段或者跳过
84+
console.log(`Tab 已存在:${newTab.title} - ${newTab.url}`);
85+
}
86+
});
87+
}
88+
});
89+
return mergedData;
90+
}

src/pages/NotFound.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
</script>
44

55
<template>
6-
<h1>404</h1>
6+
<h1>404</h1>
77
</template>
88

99
<style scoped>

src/pages/haha.vue

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/pages/test.vue

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/router.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import Test from "./pages/test.vue";
2-
import Haha from "./pages/haha.vue";
31
import Main from "./views/Main.vue";
42
import WorkspaceManager from "./views/workspaceManager.vue";
53

64
export const routes = {
7-
"/": Main,
8-
"/workspaceManager": WorkspaceManager,
9-
"/test": Test,
10-
"/haha": Haha,
5+
"/": Main,
6+
"/workspaceManager": WorkspaceManager,
117
}

0 commit comments

Comments
 (0)