From add11e937ba3b8951394fb81237434457aea97f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E8=B6=85=E8=89=AF?= <983944994@qq.com> Date: Fri, 20 Oct 2023 10:41:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0web?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/package.json | 20 ++++++++++++++++++++ web/tsconfig.json | 25 +++++++++++++++++++++++++ web/tsconfig.node.json | 10 ++++++++++ 3 files changed, 55 insertions(+) create mode 100644 web/package.json create mode 100644 web/tsconfig.json create mode 100644 web/tsconfig.node.json diff --git a/web/package.json b/web/package.json new file mode 100644 index 0000000..76e2ec6 --- /dev/null +++ b/web/package.json @@ -0,0 +1,20 @@ +{ + "name": "web", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "vue-tsc && vite build", + "preview": "vite preview" + }, + "dependencies": { + "vue": "^3.3.4" + }, + "devDependencies": { + "@vitejs/plugin-vue": "^4.2.3", + "typescript": "^5.0.2", + "vite": "^4.4.5", + "vue-tsc": "^1.8.5" + } +} diff --git a/web/tsconfig.json b/web/tsconfig.json new file mode 100644 index 0000000..f82888f --- /dev/null +++ b/web/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "preserve", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], + "references": [{ "path": "./tsconfig.node.json" }] +} diff --git a/web/tsconfig.node.json b/web/tsconfig.node.json new file mode 100644 index 0000000..42872c5 --- /dev/null +++ b/web/tsconfig.node.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.ts"] +} From 8abf72e7849e7d7b9797390cbf26a4009dfe7615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E8=B6=85=E8=89=AF?= <983944994@qq.com> Date: Fri, 20 Oct 2023 10:42:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0web?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/.editorconfig | 15 +++ web/.gitignore | 24 ++++ web/.vscode/extensions.json | 3 + web/README.md | 18 +++ web/index.html | 13 +++ web/package.json | 15 ++- web/postcss.config.js | 6 + web/public/logo.svg | 13 +++ web/src/App.vue | 12 ++ web/src/apis/index.ts | 119 +++++++++++++++++++ web/src/assets/logo.svg | 13 +++ web/src/components/HelloWorld.vue | 38 ++++++ web/src/layout/MainLayout.vue | 45 +++++++ web/src/main.ts | 9 ++ web/src/router/index.ts | 32 +++++ web/src/styles/dark/css-vars.css | 3 + web/src/styles/index.css | 7 ++ web/src/types/index.ts | 48 ++++++++ web/src/views/ConfigPage.vue | 35 ++++++ web/src/views/HomePage.vue | 188 ++++++++++++++++++++++++++++++ web/src/vite-env.d.ts | 1 + web/tailwind.config.js | 13 +++ web/tsconfig.json | 5 + web/vite.config.ts | 30 +++++ 24 files changed, 702 insertions(+), 3 deletions(-) create mode 100644 web/.editorconfig create mode 100644 web/.gitignore create mode 100644 web/.vscode/extensions.json create mode 100644 web/README.md create mode 100644 web/index.html create mode 100644 web/postcss.config.js create mode 100644 web/public/logo.svg create mode 100644 web/src/App.vue create mode 100644 web/src/apis/index.ts create mode 100644 web/src/assets/logo.svg create mode 100644 web/src/components/HelloWorld.vue create mode 100644 web/src/layout/MainLayout.vue create mode 100644 web/src/main.ts create mode 100644 web/src/router/index.ts create mode 100644 web/src/styles/dark/css-vars.css create mode 100644 web/src/styles/index.css create mode 100644 web/src/types/index.ts create mode 100644 web/src/views/ConfigPage.vue create mode 100644 web/src/views/HomePage.vue create mode 100644 web/src/vite-env.d.ts create mode 100644 web/tailwind.config.js create mode 100644 web/vite.config.ts diff --git a/web/.editorconfig b/web/.editorconfig new file mode 100644 index 0000000..3bfaa5b --- /dev/null +++ b/web/.editorconfig @@ -0,0 +1,15 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = false +insert_final_newline = false + +[*.vue] +max_line_length = 320 # 最大行长度 \ No newline at end of file diff --git a/web/.gitignore b/web/.gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/web/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/web/.vscode/extensions.json b/web/.vscode/extensions.json new file mode 100644 index 0000000..c0a6e5a --- /dev/null +++ b/web/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"] +} diff --git a/web/README.md b/web/README.md new file mode 100644 index 0000000..ef72fd5 --- /dev/null +++ b/web/README.md @@ -0,0 +1,18 @@ +# Vue 3 + TypeScript + Vite + +This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 ` + + diff --git a/web/package.json b/web/package.json index 76e2ec6..b13c249 100644 --- a/web/package.json +++ b/web/package.json @@ -1,7 +1,7 @@ { - "name": "web", + "name": "gtun-web", "private": true, - "version": "0.0.0", + "version": "1.0.0", "type": "module", "scripts": { "dev": "vite", @@ -9,10 +9,19 @@ "preview": "vite preview" }, "dependencies": { - "vue": "^3.3.4" + "@element-plus/icons-vue": "^2.1.0", + "@vueuse/core": "^10.5.0", + "element-plus": "^2.4.0", + "md-editor-v3": "^4.8.1", + "vue": "^3.3.4", + "vue-router": "^4.2.5" }, "devDependencies": { + "@types/node": "^20.8.6", "@vitejs/plugin-vue": "^4.2.3", + "autoprefixer": "^10.4.16", + "postcss": "^8.4.31", + "tailwindcss": "^3.3.3", "typescript": "^5.0.2", "vite": "^4.4.5", "vue-tsc": "^1.8.5" diff --git a/web/postcss.config.js b/web/postcss.config.js new file mode 100644 index 0000000..2e7af2b --- /dev/null +++ b/web/postcss.config.js @@ -0,0 +1,6 @@ +export default { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +} diff --git a/web/public/logo.svg b/web/public/logo.svg new file mode 100644 index 0000000..c41c87b --- /dev/null +++ b/web/public/logo.svg @@ -0,0 +1,13 @@ + + + + + +G + diff --git a/web/src/App.vue b/web/src/App.vue new file mode 100644 index 0000000..9049311 --- /dev/null +++ b/web/src/App.vue @@ -0,0 +1,12 @@ + + diff --git a/web/src/apis/index.ts b/web/src/apis/index.ts new file mode 100644 index 0000000..6f80fe3 --- /dev/null +++ b/web/src/apis/index.ts @@ -0,0 +1,119 @@ +import { MetaDataResult, MetaData, ApiResult, RegionData } from "@/types"; + +/** + * 查询meta信息 + */ +export function getMeta(): Promise { + return new Promise((resolve, reject) => { + fetch("/meta").then(async (res) => { + if (res.ok) { + const json = await res.json(); + const data = json as MetaDataResult; + console.log("load meta", data); + + if (data.code != 0) { + reject(data.message); + } else { + resolve(data.data); + } + } else { + reject(res.statusText); + } + }); + }); +} + +/** + * 添加加速IP + * @param ip 需要加速的IP + * @param region 区域 + */ +export function addIp(ip: string, region: string): Promise { + return new Promise((resolve, reject) => { + fetch("/ip/add", { + method: "post", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ ip: ip, region: region }), + }) + .then(async (res) => { + if (res.ok) { + const result = await res.json(); + const { code, message } = result; + if (code === 0) { + resolve(); + } else { + reject(message); + } + } else { + reject(res.statusText); + } + }) + .catch((err) => { + reject(err.message || err); + }); + }); +} + +/** + * 删除加速IP + * @param ip 加速IP + * @param region 区域 + */ +export function deleteIp(ip: string, region: string): Promise { + return new Promise((resolve, reject) => { + fetch("/ip/delete", { + method: "delete", + body: JSON.stringify({ + region: region, + ip: ip, + }), + headers: { + "Content-Type": "application/json", + }, + }) + .then(async (res) => { + if (res.ok) { + const result = await res.json(); + const { code, message } = result; + if (code === 0) { + resolve(); + } else { + reject(message); + } + } else { + reject(res.statusText); + } + }) + .catch((err) => { + reject(err.message || err); + }); + }); +} + +/** + * 查询ip列表 + * @param region 区域 + */ +export function listIp(region?: string): Promise { + return new Promise((resolve, reject) => { + fetch("/ip/list" + (region ? "?region=" + region : "")).then( + async (res) => { + if (res.ok) { + const json = await res.json(); + const data = json as ApiResult; + console.log("load ip list " + region, data); + + if (data.code != 0) { + reject(data.message); + } else { + resolve(data.data); + } + } else { + reject(res.statusText); + } + } + ); + }); +} diff --git a/web/src/assets/logo.svg b/web/src/assets/logo.svg new file mode 100644 index 0000000..c41c87b --- /dev/null +++ b/web/src/assets/logo.svg @@ -0,0 +1,13 @@ + + + + + +G + diff --git a/web/src/components/HelloWorld.vue b/web/src/components/HelloWorld.vue new file mode 100644 index 0000000..7b25f3f --- /dev/null +++ b/web/src/components/HelloWorld.vue @@ -0,0 +1,38 @@ + + + + + diff --git a/web/src/layout/MainLayout.vue b/web/src/layout/MainLayout.vue new file mode 100644 index 0000000..de7200c --- /dev/null +++ b/web/src/layout/MainLayout.vue @@ -0,0 +1,45 @@ + + + diff --git a/web/src/main.ts b/web/src/main.ts new file mode 100644 index 0000000..966a75e --- /dev/null +++ b/web/src/main.ts @@ -0,0 +1,9 @@ +import { createApp } from "vue"; +import "./styles/index.css"; +import "element-plus/dist/index.css"; +import "element-plus/theme-chalk/dark/css-vars.css"; +import "./styles/dark/css-vars.css"; +import App from "./App.vue"; +import router from "./router"; + +createApp(App).use(router).mount("#app"); diff --git a/web/src/router/index.ts b/web/src/router/index.ts new file mode 100644 index 0000000..b787c50 --- /dev/null +++ b/web/src/router/index.ts @@ -0,0 +1,32 @@ +import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router"; + +// 路由 +const routes = [ + { + path: "/", + name: "ROOT", + redirect: "/home", + component: () => import("@/layout/MainLayout.vue"), + children: [ + { + path: "home", + name: "HomePage", + component: () => import("@/views/HomePage.vue"), + }, + { + path: "config", + name: "ConfigPage", + component: () => import("@/views/ConfigPage.vue"), + }, + ], + }, +] as RouteRecordRaw[]; + +// 创建路由对象 +const router = createRouter({ + history: createWebHashHistory(), + routes, +}); + +// 导出路由对象 +export default router; diff --git a/web/src/styles/dark/css-vars.css b/web/src/styles/dark/css-vars.css new file mode 100644 index 0000000..a8acbd6 --- /dev/null +++ b/web/src/styles/dark/css-vars.css @@ -0,0 +1,3 @@ +html.dark { + /* 自定义深色背景颜色 */ +} diff --git a/web/src/styles/index.css b/web/src/styles/index.css new file mode 100644 index 0000000..1150c70 --- /dev/null +++ b/web/src/styles/index.css @@ -0,0 +1,7 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +#app { + height: 100vh; +} diff --git a/web/src/types/index.ts b/web/src/types/index.ts new file mode 100644 index 0000000..7db3816 --- /dev/null +++ b/web/src/types/index.ts @@ -0,0 +1,48 @@ +export interface ApiResult { + code: number; + message: string; + data: T; +} + +export interface LogConfig { + Days: number; + Level: string; + Path: string; +} + +export interface RouteConfig { + Region: string; + TraceAddr: string; + Scheme: string; + Addr: string; + AuthKey: string; +} + +export interface RegionConfig { + Route: RouteConfig[]; + ProxyFile: string; + Proxy: Map; +} + +export interface HttpServerConfig { + listen_addr: string; +} + +export interface Config { + Log: LogConfig; + Settings: Map; + http_server: HttpServerConfig; +} + +export interface MetaData { + regions: string[]; + Cfg: any; +} + +export interface RegionData { + [region: string]: string[]; +} + +export interface MetaDataResult extends ApiResult {} + +export default {}; diff --git a/web/src/views/ConfigPage.vue b/web/src/views/ConfigPage.vue new file mode 100644 index 0000000..596495e --- /dev/null +++ b/web/src/views/ConfigPage.vue @@ -0,0 +1,35 @@ + + + + diff --git a/web/src/views/HomePage.vue b/web/src/views/HomePage.vue new file mode 100644 index 0000000..22c84fe --- /dev/null +++ b/web/src/views/HomePage.vue @@ -0,0 +1,188 @@ + + + + + diff --git a/web/src/vite-env.d.ts b/web/src/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/web/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/web/tailwind.config.js b/web/tailwind.config.js new file mode 100644 index 0000000..18417e3 --- /dev/null +++ b/web/tailwind.config.js @@ -0,0 +1,13 @@ +/** @type {import('tailwindcss').Config} */ +export default { + content: [ + "./index.html", + "./src/**/*.{ts,vue}", + ], + theme: { + extend: {}, + }, + darkMode: "class", + plugins: [], +} + diff --git a/web/tsconfig.json b/web/tsconfig.json index f82888f..268b290 100644 --- a/web/tsconfig.json +++ b/web/tsconfig.json @@ -5,6 +5,11 @@ "module": "ESNext", "lib": ["ES2020", "DOM", "DOM.Iterable"], "skipLibCheck": true, + "baseUrl": ".", + "paths": { + "@/*": ["./src/*"] + }, + "types": ["element-plus/global"], /* Bundler mode */ "moduleResolution": "bundler", diff --git a/web/vite.config.ts b/web/vite.config.ts new file mode 100644 index 0000000..e44dd28 --- /dev/null +++ b/web/vite.config.ts @@ -0,0 +1,30 @@ +import { defineConfig } from "vite"; +import vue from "@vitejs/plugin-vue"; +import { resolve } from "path"; + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [vue()], + // 配置别名 + resolve: { + alias: [ + { + find: "@", + replacement: resolve(__dirname, "./src"), + }, + ], + }, + // 配置本地代理 + server: { + proxy: { + "/meta": { + target: "http://wjw7d13q1zdi.glana.link", + changeOrigin: true, + }, + "/ip": { + target: "http://wjw7d13q1zdi.glana.link", + changeOrigin: true, + }, + }, + }, +});