Browse Source

dashboard change to admin

pull/288/head
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_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' {
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']

4
dashboard/src/layout/aside.vue

@ -4,7 +4,7 @@
<Sidebar />
</a-layout-sider>
<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-item>{{ mainNav }}</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'
const dashVer = import.meta.env.VITE_DASHBOARD_VERSION
const dashVer = import.meta.env.VITE_ADMIN_VERSION
const route = useRoute()
const layout = useLayoutStore()

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

@ -3,7 +3,7 @@
<a-layout-header class="header flex">
<div class="flex items-center logo h-16">
<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>
<a-menu
v-model:selectedKeys="activeMenu"
@ -25,8 +25,8 @@ import { useLayoutStore } from '/@/store/modules/layout'
const route = useRoute()
const router = useRouter()
const { getMenubar, getCurrentVersion } = useLayoutStore()
const firstRedirectPath = '/dashboard'
const version = import.meta.env.VITE_DASHBOARD_VERSION
const firstRedirectPath = '/admin'
const version = import.meta.env.VITE_ADMIN_VERSION
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> = [
{
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' },
}

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

@ -1,4 +1,4 @@
export {}
export { }
declare global {
interface IObject<T> {
[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<T = any> {
data: Array<T>
next_position: number,
size: number
data: Array<T>
next_position: number,
size: number
}
}

2
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',

34
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)
}

Loading…
Cancel
Save