diff --git a/js/background.js b/js/background.js
index 07ee58f..a1315eb 100644
--- a/js/background.js
+++ b/js/background.js
@@ -34,54 +34,3 @@ chrome.alarms.onAlarm.addListener(() => {
const minute = date.getMinutes();
noticeAlert(hour, minute);
});
-
-function request_proxy({ url, method, data }) {
- const XHR = new XMLHttpRequest();
- XHR.open(method, url);
- XHR.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
- XHR.send(data);
- XHR.onreadystatechange = function () {
- if (XHR.readyState === 4) {
- console.log(XHR.responseText);
- }
- };
-}
-
-const wbSpiderConfig = {};
-
-chrome.storage.onChanged.addListener((changes, namespace) => {
- console.log("change ======");
- for (const [key, { oldValue, newValue }] of Object.entries(changes)) {
- console.log("change key", key, newValue);
- if (key === "wbSpider" || key === "wbSpiderStart") {
- if (key === "wbSpider") {
- wbSpiderConfig.url = newValue;
- } else if (key === "wbSpiderStart") {
- wbSpiderConfig.start = newValue;
- }
- }
- console.log(wbSpiderConfig);
- }
-});
-
-chrome.runtime.onMessage.addListener((data, sender, sendResponse) => {
- console.log(data, wbSpiderConfig);
- if (wbSpiderConfig.url !== "" && wbSpiderConfig.start) {
- fetch(wbSpiderConfig.url, {
- method: "POST",
- body: JSON.stringify(data),
- headers: {
- "Content-Type": "application/json;charset=UTF-8",
- },
- })
- .then((resp) => {
- console.log(resp);
- sendResponse({ code: 200 });
- })
- .catch((err) => {
- console.log(err);
- sendResponse({ code: 500 });
- });
- }
- sendResponse({ code: 200 });
-});
diff --git a/manifest.json b/manifest.json
index d13ccc1..34aabd7 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,15 +1,14 @@
{
"name": "dev-tool",
"description": "a dev-tool for chrome extension",
- "version": "2.0.3",
+ "version": "2.0.4",
"manifest_version": 3,
"permissions": [
"alarms",
"notifications",
"webRequest",
"storage",
- "nativeMessaging",
- "http://*/"
+ "nativeMessaging"
],
"background": {
"service_worker": "js/background.js"
diff --git a/package.json b/package.json
index c6131ed..af8c404 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "dev-tool",
- "version": "0.0.0",
+ "version": "2.0.4",
"scripts": {
"dev": "vite",
"build": "vite build",
diff --git a/src/App.vue b/src/App.vue
index e3afa24..31b5a07 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -37,7 +37,6 @@
-
@@ -51,8 +50,8 @@ import HtmlShow from "./components/Html.vue";
import Link from "./components/Link.vue";
import SqlToModel from "./components/SqlToModel.vue";
import Notice from "./components/Notice.vue";
-import Setting from "./components/Setting.vue";
import JsonStuff from "./components/JsonStuff.vue";
+
const lastClickTabStorage = "last:click";
export default {
@@ -89,7 +88,6 @@ export default {
SqlToModel,
Notice,
JsonStuff,
- Setting,
},
};
@@ -103,7 +101,7 @@ export default {
color: #2c3e50;
}
.fixedWidth {
- width: 700px;
+ width: 800px;
}
.fullWidth {
width: 100%;
diff --git a/src/components/Cal.vue b/src/components/Cal.vue
index a303baf..8e9dd7b 100644
--- a/src/components/Cal.vue
+++ b/src/components/Cal.vue
@@ -9,21 +9,18 @@
placeholder="请输入值1"
>
-
-
-
-
+
+
import jsonFormate from "../utils/json-format";
import { jsonToGo } from "../utils/json-to-go";
-
+import { structStrToJson } from "../utils/go/structToJson";
export default {
props: {
isFull: Boolean,
@@ -68,6 +68,10 @@ export default {
type: 3,
name: "json转table (输入json数组)",
},
+ // {
+ // type: 4,
+ // name: "go struct to json",
+ // },
],
};
},
@@ -83,9 +87,16 @@ export default {
} else if (mode === 3) {
this.nowMode = 3;
this.doJsonToTable();
+ } else if (mode === 4) {
+ this.nowMode = 4;
+ this.doGoStructToJson();
}
}
},
+ doGoStructToJson() {
+ const goObj = structStrToJson(this.userInputJson);
+ this.showJson = goObj.go;
+ },
doJsonFormat(type) {
let obj;
try {
diff --git a/src/components/Setting.vue b/src/components/Setting.vue
deleted file mode 100644
index 4ca70e4..0000000
--- a/src/components/Setting.vue
+++ /dev/null
@@ -1,121 +0,0 @@
-
-
-
-
-
-
-
diff --git a/src/utils/go/structToJson.js b/src/utils/go/structToJson.js
new file mode 100644
index 0000000..0ed7b8a
--- /dev/null
+++ b/src/utils/go/structToJson.js
@@ -0,0 +1,77 @@
+function structStrToJson(str) {
+ let columns = parseStrToStructInner(str);
+ let jsonArr = [];
+
+ if (columns.length > 0) {
+ // console.log("----inner");
+ // console.log(columns[0][1]);
+ // console.log(parseStrToOneColumn(columns[0][1]));
+ let spArr = columns[0][1].split("\n");
+ console.log(spArr);
+ for (let i = 0; i < spArr.length; i++) {
+ console.log(spArr[i]);
+ let column = parseStrToOneColumn(spArr[i]);
+ console.log("column", column);
+ if (column.length >= 4) {
+ let jsonName = parseStrToJsonStr(column[3]);
+ console.log("jsonName", jsonName[1], "cType", column[2]);
+ jsonArr.push({ name: jsonName[1], cType: column[2] });
+ }
+ }
+ }
+ console.log(jsonArr);
+ return jsonArr;
+}
+
+function parseStrToStructInner(str) {
+ //type\s\w+\sstruct\s?\{\s((.*\s)*)\}
+ const regex = /type\s\w+\sstruct\s?\{\s((.*\s)*)\}/gm;
+ let m;
+ let obj = [];
+ while ((m = regex.exec(str)) !== null) {
+ if (m.index === regex.lastIndex) {
+ regex.lastIndex++;
+ }
+ const one = {};
+ m.forEach((match, groupIndex) => {
+ one[groupIndex] = match;
+ });
+ obj.push(one);
+ }
+ return obj;
+}
+
+function parseStrToOneColumn(str) {
+ //\s?(\w+)\s*(\w+)\s*\`(.*)`
+ console.log("parseStrToOneColumn--");
+ const regex = /\s?(\w+)\s*(\w+)\s*\`(.*)`/gm;
+ let m;
+ let obj = [];
+ while ((m = regex.exec(str)) !== null) {
+ if (m.index === regex.lastIndex) {
+ regex.lastIndex++;
+ }
+ m.forEach((match, groupIndex) => {
+ obj[groupIndex] = match;
+ });
+ }
+ return obj;
+}
+
+function parseStrToJsonStr(str) {
+ //json:"(.*)"
+ const regex = /json:"(.*)"/gm;
+ let m;
+ let obj = [];
+ while ((m = regex.exec(str)) !== null) {
+ if (m.index === regex.lastIndex) {
+ regex.lastIndex++;
+ }
+ m.forEach((match, groupIndex) => {
+ obj[groupIndex] = match;
+ });
+ }
+ return obj;
+}
+
+export { structStrToJson };