Browse Source

dashboard change to admin

topic
yedf2 4 years ago
parent
commit
48cd775638
  1. 2
      dashboard/.env.development
  2. 12
      dashboard/src/components.d.ts
  3. 4
      dashboard/src/layout/aside.vue
  4. 6
      dashboard/src/layout/components/header.vue
  5. 16
      dashboard/src/router/index.ts
  6. 10
      dashboard/src/type/index.d.ts
  7. 2
      dashboard/vite.config.ts
  8. 34
      main.go

2
dashboard/.env.development

@ -1,2 +1,2 @@
VITE_PROXY=[["/api", "http://localhost:36789"]] VITE_PROXY=[["/api", "http://localhost:36789"]]
VITE_DASHBOARD_VERSION="v0.0.0-dev" VITE_ADMIN_VERSION="v0.0.0-dev"

12
dashboard/src/components.d.ts

@ -5,18 +5,6 @@ import '@vue/runtime-core'
declare module '@vue/runtime-core' { declare module '@vue/runtime-core' {
export interface GlobalComponents { 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'] RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView'] RouterView: typeof import('vue-router')['RouterView']
SvgIcon: typeof import('./components/SvgIcon/index.vue')['default'] SvgIcon: typeof import('./components/SvgIcon/index.vue')['default']

4
dashboard/src/layout/aside.vue

@ -4,7 +4,7 @@
<Sidebar /> <Sidebar />
</a-layout-sider> </a-layout-sider>
<a-layout style="padding: 0 24px 24px"> <a-layout style="padding: 0 24px 24px">
<div v-if="layout.dtmVersion && layout.dtmVersion != dashVer" style="color:#f00"> !!! dashboard version: {{dashVer}} != dtm version: {{layout.dtmVersion}}. </div> <div v-if="layout.dtmVersion && layout.dtmVersion != dashVer" style="color:#f00"> !!! admin version: {{dashVer}} != dtm version: {{layout.dtmVersion}}. </div>
<a-breadcrumb style="margin: 16px 0"> <a-breadcrumb style="margin: 16px 0">
<a-breadcrumb-item>{{ mainNav }}</a-breadcrumb-item> <a-breadcrumb-item>{{ mainNav }}</a-breadcrumb-item>
<a-breadcrumb-item>{{ subNav }}</a-breadcrumb-item> <a-breadcrumb-item>{{ subNav }}</a-breadcrumb-item>
@ -30,7 +30,7 @@ import { computed, onMounted, ref } from 'vue'
import { getDtmVersion } from '../api/api_dtm' 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 route = useRoute()
const layout = useLayoutStore() const layout = useLayoutStore()

6
dashboard/src/layout/components/header.vue

@ -3,7 +3,7 @@
<a-layout-header class="header flex"> <a-layout-header class="header flex">
<div class="flex items-center logo h-16"> <div class="flex items-center logo h-16">
<svg-icon style="width: 36px; height: 36px; margin-right: 84px;" icon-class="svg-logo" /> <svg-icon style="width: 36px; height: 36px; margin-right: 84px;" icon-class="svg-logo" />
<span class="text-gray-400 text-lg">DTM dashboard {{ version }}</span> <span class="text-gray-400 text-lg">DTM admin {{ version }}</span>
</div> </div>
<a-menu <a-menu
v-model:selectedKeys="activeMenu" v-model:selectedKeys="activeMenu"
@ -25,8 +25,8 @@ import { useLayoutStore } from '/@/store/modules/layout'
const route = useRoute() const route = useRoute()
const router = useRouter() const router = useRouter()
const { getMenubar, getCurrentVersion } = useLayoutStore() const { getMenubar, getCurrentVersion } = useLayoutStore()
const firstRedirectPath = '/dashboard' const firstRedirectPath = '/admin'
const version = import.meta.env.VITE_DASHBOARD_VERSION const version = import.meta.env.VITE_ADMIN_VERSION
const activeMenu = ref([route.meta.activeMenu !== firstRedirectPath ? route.meta.activeMenu : '/']) const activeMenu = ref([route.meta.activeMenu !== firstRedirectPath ? route.meta.activeMenu : '/'])

16
dashboard/src/router/index.ts

@ -9,39 +9,39 @@ const Components: IObject<() => Promise<typeof import('*.vue')>> = Object.assign
export const allowRouter: Array<IMenubarList> = [ export const allowRouter: Array<IMenubarList> = [
{ {
name: 'Dashboard', name: 'Admin',
path: '/', path: '/',
redirect: '/dashboard/global-transactions/all', redirect: '/admin/global-transactions/all',
component: Components['LayoutHeader'], component: Components['LayoutHeader'],
meta: { title: 'Dashboard', activeMenu: '/dashboard' }, meta: { title: 'Admin', activeMenu: '/admin' },
children: [ children: [
{ {
name: 'Nodes', name: 'Nodes',
path: '/dashboard/nodes', path: '/admin/nodes',
component: Components['LayoutMain'], component: Components['LayoutMain'],
meta: { title: 'Nodes' }, meta: { title: 'Nodes' },
children: [ children: [
{ {
name: 'LivingNodes', name: 'LivingNodes',
path: '/dashboard/nodes/living', path: '/admin/nodes/living',
component: Components['LivingNodes'], component: Components['LivingNodes'],
meta: { title: 'Living Nodes' }, meta: { title: 'Living Nodes' },
} }
] ]
}, { }, {
name: 'GlobalTransactions', name: 'GlobalTransactions',
path: '/dashboard/global-transactions', path: '/admin/global-transactions',
component: Components['LayoutMain'], component: Components['LayoutMain'],
meta: { title: 'Global Transactions' }, meta: { title: 'Global Transactions' },
children: [ children: [
{ {
name: 'AllTransactions', name: 'AllTransactions',
path: '/dashboard/global-transactions/all', path: '/admin/global-transactions/all',
component: Components['AllTransactions'], component: Components['AllTransactions'],
meta: { title: 'All Transactions' }, meta: { title: 'All Transactions' },
}, { }, {
name: 'UnfinishedTransactions', name: 'UnfinishedTransactions',
path: '/dashboard/global-transactions/unfinished', path: '/admin/global-transactions/unfinished',
component: Components['UnfinishedTransactions'], component: Components['UnfinishedTransactions'],
meta: { title: 'Unfinished Transactions' }, meta: { title: 'Unfinished Transactions' },
} }

10
dashboard/src/type/index.d.ts

@ -1,4 +1,4 @@
export {} export { }
declare global { declare global {
interface IObject<T> { interface IObject<T> {
[index: string]: T [index: string]: T
@ -7,11 +7,11 @@ declare global {
VITE_APP_TITLE: string VITE_APP_TITLE: string
VITE_PORT: number VITE_PORT: number
VITE_PROXY: string VITE_PROXY: string
VITE_DASHBOARD_VERSION: string VITE_ADMIN_VERSION: string
} }
interface ITable<T = any> { interface ITable<T = any> {
data: Array<T> data: Array<T>
next_position: number, next_position: number,
size: number size: number
} }
} }

2
dashboard/vite.config.ts

@ -29,7 +29,7 @@ export default ({ }: ConfigEnv): UserConfigExport => {
], ],
server: { server: {
port: 5000, port: 5000,
base: 'dashboard', base: 'admin',
proxy: { proxy: {
'/api': { '/api': {
target: 'http://localhost:36789', target: 'http://localhost:36789',

34
main.go

@ -27,47 +27,43 @@ var Version string
func main() { func main() {
app, conf := entry.Main(&Version) app, conf := entry.Main(&Version)
if app != nil { if app != nil {
addDashboard(app, conf) addAdmin(app, conf)
select {} select {}
} }
} }
//go:embed dashboard/dist //go:embed admin/dist
var dashboard embed.FS var admin embed.FS
//go:embed dashboard/dist/index.html //go:embed admin/dist/index.html
var indexFile string var indexFile string
var target = "127.0.0.1:5000" var target = ""
func getSub(f1 fs.FS, sub string) fs.FS { func getSub(f1 fs.FS, sub string) fs.FS {
f2, err := fs.Sub(f1, sub) f2, err := fs.Sub(f1, sub)
logger.FatalIfError(err) logger.FatalIfError(err)
return f2 return f2
} }
func addDashboard(app *gin.Engine, conf *config.ConfigType) { func addAdmin(app *gin.Engine, conf *config.ConfigType) {
dist := getSub(dashboard, "dashboard/dist") dist := getSub(admin, "admin/dist")
_, err := dist.Open("index.html") _, err := dist.Open("index.html")
if err == nil { if err == nil {
app.StaticFS("/assets", http.FS(getSub(dist, "assets"))) 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.Header("content-type", "text/html;charset=utf-8")
c.String(200, indexFile) c.String(200, indexFile)
}) })
logger.Infof("dashboard is served from dir 'dashboard/dist/'") logger.Infof("admin is served from dir 'admin/dist/'")
} else { } else {
app.GET("/", proxyDashboard) app.GET("/", proxyAdmin)
app.GET("/dashboard/*name", proxyDashboard) app.GET("/admin/*name", proxyAdmin)
app.GET("/@vite/*name", proxyDashboard) logger.Infof("admin is proxied to %s", target)
app.GET("/node_modules/*name", proxyDashboard)
app.GET("/src/*name", proxyDashboard)
app.GET("/@id/*name", proxyDashboard)
logger.Infof("dashboard 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 := &url.URL{}
u.Scheme = "http" u.Scheme = "http"
@ -79,7 +75,7 @@ func proxyDashboard(c *gin.Context) {
ret := fmt.Sprintf("http proxy error %v", err) ret := fmt.Sprintf("http proxy error %v", err)
_, _ = rw.Write([]byte(ret)) _, _ = rw.Write([]byte(ret))
} }
logger.Debugf("proxy dashboard to %s", target) logger.Debugf("proxy admin to %s", target)
proxy.ServeHTTP(c.Writer, c.Request) proxy.ServeHTTP(c.Writer, c.Request)
} }

Loading…
Cancel
Save