소스 검색

Merge pull request #476 from flipped-aurora/gva_gormv2_dev

Gva gormv2 dev
奇淼(piexlmax 3 년 전
부모
커밋
dbf1b62979
7개의 변경된 파일67개의 추가작업 그리고 36개의 파일을 삭제
  1. 2 11
      server/api/v1/sys_system.go
  2. 1 0
      server/config.yaml
  3. 14 13
      server/config/auto_code.go
  4. 5 0
      server/service/sys_auto_code.go
  5. 11 3
      server/service/sys_casbin.go
  6. 18 0
      server/utils/reload.go
  7. 16 9
      web/src/components/chooseImg/index.vue

+ 2 - 11
server/api/v1/sys_system.go

@@ -5,10 +5,7 @@ import (
 	"gin-vue-admin/model"
 	"gin-vue-admin/model/response"
 	"gin-vue-admin/service"
-	"os"
-	"os/exec"
-	"runtime"
-	"strconv"
+	"gin-vue-admin/utils"
 
 	"github.com/gin-gonic/gin"
 	"go.uber.org/zap"
@@ -54,13 +51,7 @@ func SetSystemConfig(c *gin.Context) {
 // @Success 200 {string} string "{"code":0,"data":{},"msg":"重启系统成功"}"
 // @Router /system/reloadSystem [post]
 func ReloadSystem(c *gin.Context) {
-	if runtime.GOOS == "windows" {
-		response.FailWithMessage("系统不支持", c)
-		return
-	}
-	pid := os.Getpid()
-	cmd := exec.Command("kill", "-1", strconv.Itoa(pid))
-	err := cmd.Run()
+	err := utils.Reload()
 	if err != nil {
 		global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err))
 		response.FailWithMessage("重启系统失败", c)

+ 1 - 0
server/config.yaml

@@ -70,6 +70,7 @@ local:
 
 # autocode configuration
 autocode:
+  transfer-restart: true
   root: ""
   server: /server
   server-api: /api/v1

+ 14 - 13
server/config/auto_code.go

@@ -1,17 +1,18 @@
 package config
 
 type Autocode struct {
-	Root        string `mapstructure:"root" json:"root" yaml:"root"`
-	Server      string `mapstructure:"server" json:"server" yaml:"server"`
-	SApi        string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"`
-	SInitialize string `mapstructure:"server-initialize" json:"serverInitialize" yaml:"server-initialize"`
-	SModel      string `mapstructure:"server-model" json:"serverModel" yaml:"server-model"`
-	SRequest    string `mapstructure:"server-request" json:"serverRequest"  yaml:"server-request"`
-	SRouter     string `mapstructure:"server-router" json:"serverRouter" yaml:"server-router"`
-	SService    string `mapstructure:"server-service" json:"serverService" yaml:"server-service"`
-	Web         string `mapstructure:"web" json:"web" yaml:"web"`
-	WApi        string `mapstructure:"web-api" json:"webApi" yaml:"web-api"`
-	WForm       string `mapstructure:"web-form" json:"webForm" yaml:"web-form"`
-	WTable      string `mapstructure:"web-table" json:"webTable" yaml:"web-table"`
-	WFlow       string `mapstructure:"web-flow" json:"webFlow" yaml:"web-flow"`
+	TransferRestart bool   `mapstructure:"transfer-restart" json:"transferRestart" yaml:"transfer-restart"`
+	Root            string `mapstructure:"root" json:"root" yaml:"root"`
+	Server          string `mapstructure:"server" json:"server" yaml:"server"`
+	SApi            string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"`
+	SInitialize     string `mapstructure:"server-initialize" json:"serverInitialize" yaml:"server-initialize"`
+	SModel          string `mapstructure:"server-model" json:"serverModel" yaml:"server-model"`
+	SRequest        string `mapstructure:"server-request" json:"serverRequest"  yaml:"server-request"`
+	SRouter         string `mapstructure:"server-router" json:"serverRouter" yaml:"server-router"`
+	SService        string `mapstructure:"server-service" json:"serverService" yaml:"server-service"`
+	Web             string `mapstructure:"web" json:"web" yaml:"web"`
+	WApi            string `mapstructure:"web-api" json:"webApi" yaml:"web-api"`
+	WForm           string `mapstructure:"web-form" json:"webForm" yaml:"web-form"`
+	WTable          string `mapstructure:"web-table" json:"webTable" yaml:"web-table"`
+	WFlow           string `mapstructure:"web-flow" json:"webFlow" yaml:"web-flow"`
 }

+ 5 - 0
server/service/sys_auto_code.go

@@ -146,6 +146,11 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
 		if err != nil {
 			return err
 		}
+		if global.GVA_CONFIG.AutoCode.TransferRestart {
+			go func() {
+				_ = utils.Reload()
+			}()
+		}
 		return errors.New("创建代码成功并移动文件成功")
 	} else { // 打包
 		if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil {

+ 11 - 3
server/service/sys_casbin.go

@@ -6,6 +6,7 @@ import (
 	"gin-vue-admin/model"
 	"gin-vue-admin/model/request"
 	"strings"
+	"sync"
 
 	"github.com/casbin/casbin/v2"
 	"github.com/casbin/casbin/v2/util"
@@ -89,10 +90,17 @@ func ClearCasbin(v int, p ...string) bool {
 //@description: 持久化到数据库  引入自定义规则
 //@return: *casbin.Enforcer
 
+var (
+	e    *casbin.Enforcer
+	once sync.Once
+)
+
 func Casbin() *casbin.Enforcer {
-	a, _ := gormadapter.NewAdapterByDB(global.GVA_DB)
-	e, _ := casbin.NewEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a)
-	e.AddFunction("ParamsMatch", ParamsMatchFunc)
+	once.Do(func() {
+		a, _ := gormadapter.NewAdapterByDB(global.GVA_DB)
+		e, _ = casbin.NewEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a)
+		e.AddFunction("ParamsMatch", ParamsMatchFunc)
+	})
 	_ = e.LoadPolicy()
 	return e
 }

+ 18 - 0
server/utils/reload.go

@@ -0,0 +1,18 @@
+package utils
+
+import (
+	"errors"
+	"os"
+	"os/exec"
+	"runtime"
+	"strconv"
+)
+
+func Reload() error {
+	if runtime.GOOS == "windows" {
+		return errors.New("系统不支持")
+	}
+	pid := os.Getpid()
+	cmd := exec.Command("kill", "-1", strconv.Itoa(pid))
+	return cmd.Run()
+}

+ 16 - 9
web/src/components/chooseImg/index.vue

@@ -1,6 +1,6 @@
 <template>
   <el-drawer title="媒体库" :visible.sync="drawer">
-    <div style="display:flex;justify-content:space-around;flex-wrap:wrap;padding-top:40px">
+    <div class="media">
       <el-image
         class="header-img-box-list"
         :src="(item.url && item.url.slice(0, 4) !== 'http')?path+item.url:item.url"
@@ -49,13 +49,20 @@ export default {
 </script>
 
 <style lang="scss">
-.header-img-box-list {
-  width: 180px;
-  height: 180px;
-  border: 1px dashed #ccc;
-  border-radius: 20px;
-  text-align: center;
-  line-height: 180px;
-  cursor: pointer;
+.media{
+  display:flex;
+  flex-wrap:wrap;
+  .header-img-box-list {
+    margin-top: 20px;
+    width: 120px;
+    margin-left: 20px;
+    height: 120px;
+    border: 1px dashed #ccc;
+    border-radius: 20px;
+    text-align: center;
+    line-height: 180px;
+    cursor: pointer;
 }
+}
+
 </style>