Ver Fonte

修复后端重启前端白屏的bug

修复后端重启前端白屏的bug
奇淼(piexlmax há 3 anos atrás
pai
commit
72f44e7c3d
3 ficheiros alterados com 7 adições e 4 exclusões
  1. 1 0
      server/core/viper.go
  2. 5 1
      server/utils/fmt_plus.go
  3. 1 3
      web/src/permission.js

+ 1 - 0
server/core/viper.go

@@ -36,6 +36,7 @@ func Viper(path ...string) *viper.Viper {
 
 	v := viper.New()
 	v.SetConfigFile(config)
+	v.SetConfigType("yaml")
 	err := v.ReadInConfig()
 	if err != nil {
 		panic(fmt.Errorf("Fatal error config file: %s \n", err))

+ 5 - 1
server/utils/fmt_plus.go

@@ -18,7 +18,11 @@ func StructToMap(obj interface{}) map[string]interface{} {
 
 	var data = make(map[string]interface{})
 	for i := 0; i < obj1.NumField(); i++ {
-		data[obj1.Field(i).Name] = obj2.Field(i).Interface()
+		if obj1.Field(i).Tag.Get("mapstructure") != "" {
+			data[obj1.Field(i).Tag.Get("mapstructure")] = obj2.Field(i).Interface()
+		} else {
+			data[obj1.Field(i).Name] = obj2.Field(i).Interface()
+		}
 	}
 	return data
 }

+ 1 - 3
web/src/permission.js

@@ -24,9 +24,7 @@ router.beforeEach(async (to, from, next) => {
                 asyncRouterFlag++
                 await store.dispatch('router/SetAsyncRouter')
                 const asyncRouters = store.getters['router/asyncRouters']
-                asyncRouters.forEach(item => {
-                    router.addRoute(item)
-                })
+                router.addRoutes(asyncRouters)
                 next({ ...to, replace: true })
             } else {
                 if (to.matched.length) {