From 48cd77563810ccf0612524d437fd1b96ed61ff66 Mon Sep 17 00:00:00 2001 From: yedf2 <120050102@qq.com> Date: Mon, 16 May 2022 19:47:06 +0800 Subject: [PATCH] dashboard change to admin --- dashboard/.env.development | 2 +- dashboard/src/components.d.ts | 12 -------- dashboard/src/layout/aside.vue | 4 +-- dashboard/src/layout/components/header.vue | 6 ++-- dashboard/src/router/index.ts | 16 +++++----- dashboard/src/type/index.d.ts | 10 +++---- dashboard/vite.config.ts | 2 +- main.go | 34 ++++++++++------------ 8 files changed, 35 insertions(+), 51 deletions(-) diff --git a/dashboard/.env.development b/dashboard/.env.development index 50507c4..cd123c3 100644 --- a/dashboard/.env.development +++ b/dashboard/.env.development @@ -1,2 +1,2 @@ VITE_PROXY=[["/api", "http://localhost:36789"]] -VITE_DASHBOARD_VERSION="v0.0.0-dev" +VITE_ADMIN_VERSION="v0.0.0-dev" diff --git a/dashboard/src/components.d.ts b/dashboard/src/components.d.ts index 1c6807f..10b07fd 100644 --- a/dashboard/src/components.d.ts +++ b/dashboard/src/components.d.ts @@ -5,18 +5,6 @@ import '@vue/runtime-core' declare module '@vue/runtime-core' { export interface GlobalComponents { - ABreadcrumb: typeof import('ant-design-vue/es')['Breadcrumb'] - ABreadcrumbItem: typeof import('ant-design-vue/es')['BreadcrumbItem'] - AButton: typeof import('ant-design-vue/es')['Button'] - ALayout: typeof import('ant-design-vue/es')['Layout'] - ALayoutContent: typeof import('ant-design-vue/es')['LayoutContent'] - ALayoutHeader: typeof import('ant-design-vue/es')['LayoutHeader'] - ALayoutSider: typeof import('ant-design-vue/es')['LayoutSider'] - AMenu: typeof import('ant-design-vue/es')['Menu'] - AMenuItem: typeof import('ant-design-vue/es')['MenuItem'] - ASubMenu: typeof import('ant-design-vue/es')['SubMenu'] - ATable: typeof import('ant-design-vue/es')['Table'] - ATag: typeof import('ant-design-vue/es')['Tag'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] SvgIcon: typeof import('./components/SvgIcon/index.vue')['default'] diff --git a/dashboard/src/layout/aside.vue b/dashboard/src/layout/aside.vue index f32e42d..77d7c74 100644 --- a/dashboard/src/layout/aside.vue +++ b/dashboard/src/layout/aside.vue @@ -4,7 +4,7 @@ -
!!! dashboard version: {{dashVer}} != dtm version: {{layout.dtmVersion}}.
+
!!! admin version: {{dashVer}} != dtm version: {{layout.dtmVersion}}.
{{ mainNav }} {{ subNav }} @@ -30,7 +30,7 @@ import { computed, onMounted, ref } from 'vue' import { getDtmVersion } from '../api/api_dtm' -const dashVer = import.meta.env.VITE_DASHBOARD_VERSION +const dashVer = import.meta.env.VITE_ADMIN_VERSION const route = useRoute() const layout = useLayoutStore() diff --git a/dashboard/src/layout/components/header.vue b/dashboard/src/layout/components/header.vue index 28b2148..bf24541 100644 --- a/dashboard/src/layout/components/header.vue +++ b/dashboard/src/layout/components/header.vue @@ -3,7 +3,7 @@ Promise> = Object.assign export const allowRouter: Array = [ { - name: 'Dashboard', + name: 'Admin', path: '/', - redirect: '/dashboard/global-transactions/all', + redirect: '/admin/global-transactions/all', component: Components['LayoutHeader'], - meta: { title: 'Dashboard', activeMenu: '/dashboard' }, + meta: { title: 'Admin', activeMenu: '/admin' }, children: [ { name: 'Nodes', - path: '/dashboard/nodes', + path: '/admin/nodes', component: Components['LayoutMain'], meta: { title: 'Nodes' }, children: [ { name: 'LivingNodes', - path: '/dashboard/nodes/living', + path: '/admin/nodes/living', component: Components['LivingNodes'], meta: { title: 'Living Nodes' }, } ] }, { name: 'GlobalTransactions', - path: '/dashboard/global-transactions', + path: '/admin/global-transactions', component: Components['LayoutMain'], meta: { title: 'Global Transactions' }, children: [ { name: 'AllTransactions', - path: '/dashboard/global-transactions/all', + path: '/admin/global-transactions/all', component: Components['AllTransactions'], meta: { title: 'All Transactions' }, }, { name: 'UnfinishedTransactions', - path: '/dashboard/global-transactions/unfinished', + path: '/admin/global-transactions/unfinished', component: Components['UnfinishedTransactions'], meta: { title: 'Unfinished Transactions' }, } diff --git a/dashboard/src/type/index.d.ts b/dashboard/src/type/index.d.ts index 47a7f8f..53b355b 100644 --- a/dashboard/src/type/index.d.ts +++ b/dashboard/src/type/index.d.ts @@ -1,4 +1,4 @@ -export {} +export { } declare global { interface IObject { [index: string]: T @@ -7,11 +7,11 @@ declare global { VITE_APP_TITLE: string VITE_PORT: number VITE_PROXY: string - VITE_DASHBOARD_VERSION: string + VITE_ADMIN_VERSION: string } interface ITable { - data: Array - next_position: number, - size: number + data: Array + next_position: number, + size: number } } diff --git a/dashboard/vite.config.ts b/dashboard/vite.config.ts index 18e1f84..969c4f6 100644 --- a/dashboard/vite.config.ts +++ b/dashboard/vite.config.ts @@ -29,7 +29,7 @@ export default ({ }: ConfigEnv): UserConfigExport => { ], server: { port: 5000, - base: 'dashboard', + base: 'admin', proxy: { '/api': { target: 'http://localhost:36789', diff --git a/main.go b/main.go index 1be5ba1..bfdbecf 100644 --- a/main.go +++ b/main.go @@ -27,47 +27,43 @@ var Version string func main() { app, conf := entry.Main(&Version) if app != nil { - addDashboard(app, conf) + addAdmin(app, conf) select {} } } -//go:embed dashboard/dist -var dashboard embed.FS +//go:embed admin/dist +var admin embed.FS -//go:embed dashboard/dist/index.html +//go:embed admin/dist/index.html var indexFile string -var target = "127.0.0.1:5000" +var target = "" func getSub(f1 fs.FS, sub string) fs.FS { f2, err := fs.Sub(f1, sub) logger.FatalIfError(err) return f2 } -func addDashboard(app *gin.Engine, conf *config.ConfigType) { - dist := getSub(dashboard, "dashboard/dist") +func addAdmin(app *gin.Engine, conf *config.ConfigType) { + dist := getSub(admin, "admin/dist") _, err := dist.Open("index.html") if err == nil { app.StaticFS("/assets", http.FS(getSub(dist, "assets"))) - app.GET("/dashboard/*name", func(c *gin.Context) { + app.GET("/admin/*name", func(c *gin.Context) { c.Header("content-type", "text/html;charset=utf-8") c.String(200, indexFile) }) - logger.Infof("dashboard is served from dir 'dashboard/dist/'") + logger.Infof("admin is served from dir 'admin/dist/'") } else { - app.GET("/", proxyDashboard) - app.GET("/dashboard/*name", proxyDashboard) - app.GET("/@vite/*name", proxyDashboard) - app.GET("/node_modules/*name", proxyDashboard) - app.GET("/src/*name", proxyDashboard) - app.GET("/@id/*name", proxyDashboard) - logger.Infof("dashboard is proxied to %s", target) + app.GET("/", proxyAdmin) + app.GET("/admin/*name", proxyAdmin) + logger.Infof("admin is proxied to %s", target) } - logger.Infof("Dashboard is running at: http://localhost:%d", conf.HTTPPort) + logger.Infof("admin is running at: http://localhost:%d", conf.HTTPPort) } -func proxyDashboard(c *gin.Context) { +func proxyAdmin(c *gin.Context) { u := &url.URL{} u.Scheme = "http" @@ -79,7 +75,7 @@ func proxyDashboard(c *gin.Context) { ret := fmt.Sprintf("http proxy error %v", err) _, _ = rw.Write([]byte(ret)) } - logger.Debugf("proxy dashboard to %s", target) + logger.Debugf("proxy admin to %s", target) proxy.ServeHTTP(c.Writer, c.Request) }