Skip to content

Commit dbf1b62

Browse files
author
奇淼(piexlmax
authored
Merge pull request flipped-aurora#476 from flipped-aurora/gva_gormv2_dev
Gva gormv2 dev
2 parents 480a798 + 225c7f6 commit dbf1b62

File tree

7 files changed

+67
-36
lines changed

7 files changed

+67
-36
lines changed

server/api/v1/sys_system.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import (
55
"gin-vue-admin/model"
66
"gin-vue-admin/model/response"
77
"gin-vue-admin/service"
8-
"os"
9-
"os/exec"
10-
"runtime"
11-
"strconv"
8+
"gin-vue-admin/utils"
129

1310
"github.com/gin-gonic/gin"
1411
"go.uber.org/zap"
@@ -54,13 +51,7 @@ func SetSystemConfig(c *gin.Context) {
5451
// @Success 200 {string} string "{"code":0,"data":{},"msg":"重启系统成功"}"
5552
// @Router /system/reloadSystem [post]
5653
func ReloadSystem(c *gin.Context) {
57-
if runtime.GOOS == "windows" {
58-
response.FailWithMessage("系统不支持", c)
59-
return
60-
}
61-
pid := os.Getpid()
62-
cmd := exec.Command("kill", "-1", strconv.Itoa(pid))
63-
err := cmd.Run()
54+
err := utils.Reload()
6455
if err != nil {
6556
global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err))
6657
response.FailWithMessage("重启系统失败", c)

server/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ local:
7070

7171
# autocode configuration
7272
autocode:
73+
transfer-restart: true
7374
root: ""
7475
server: /server
7576
server-api: /api/v1

server/config/auto_code.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package config
22

33
type Autocode struct {
4-
Root string `mapstructure:"root" json:"root" yaml:"root"`
5-
Server string `mapstructure:"server" json:"server" yaml:"server"`
6-
SApi string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"`
7-
SInitialize string `mapstructure:"server-initialize" json:"serverInitialize" yaml:"server-initialize"`
8-
SModel string `mapstructure:"server-model" json:"serverModel" yaml:"server-model"`
9-
SRequest string `mapstructure:"server-request" json:"serverRequest" yaml:"server-request"`
10-
SRouter string `mapstructure:"server-router" json:"serverRouter" yaml:"server-router"`
11-
SService string `mapstructure:"server-service" json:"serverService" yaml:"server-service"`
12-
Web string `mapstructure:"web" json:"web" yaml:"web"`
13-
WApi string `mapstructure:"web-api" json:"webApi" yaml:"web-api"`
14-
WForm string `mapstructure:"web-form" json:"webForm" yaml:"web-form"`
15-
WTable string `mapstructure:"web-table" json:"webTable" yaml:"web-table"`
16-
WFlow string `mapstructure:"web-flow" json:"webFlow" yaml:"web-flow"`
4+
TransferRestart bool `mapstructure:"transfer-restart" json:"transferRestart" yaml:"transfer-restart"`
5+
Root string `mapstructure:"root" json:"root" yaml:"root"`
6+
Server string `mapstructure:"server" json:"server" yaml:"server"`
7+
SApi string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"`
8+
SInitialize string `mapstructure:"server-initialize" json:"serverInitialize" yaml:"server-initialize"`
9+
SModel string `mapstructure:"server-model" json:"serverModel" yaml:"server-model"`
10+
SRequest string `mapstructure:"server-request" json:"serverRequest" yaml:"server-request"`
11+
SRouter string `mapstructure:"server-router" json:"serverRouter" yaml:"server-router"`
12+
SService string `mapstructure:"server-service" json:"serverService" yaml:"server-service"`
13+
Web string `mapstructure:"web" json:"web" yaml:"web"`
14+
WApi string `mapstructure:"web-api" json:"webApi" yaml:"web-api"`
15+
WForm string `mapstructure:"web-form" json:"webForm" yaml:"web-form"`
16+
WTable string `mapstructure:"web-table" json:"webTable" yaml:"web-table"`
17+
WFlow string `mapstructure:"web-flow" json:"webFlow" yaml:"web-flow"`
1718
}

server/service/sys_auto_code.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
146146
if err != nil {
147147
return err
148148
}
149+
if global.GVA_CONFIG.AutoCode.TransferRestart {
150+
go func() {
151+
_ = utils.Reload()
152+
}()
153+
}
149154
return errors.New("创建代码成功并移动文件成功")
150155
} else { // 打包
151156
if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil {

server/service/sys_casbin.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"gin-vue-admin/model"
77
"gin-vue-admin/model/request"
88
"strings"
9+
"sync"
910

1011
"github.com/casbin/casbin/v2"
1112
"github.com/casbin/casbin/v2/util"
@@ -89,10 +90,17 @@ func ClearCasbin(v int, p ...string) bool {
8990
//@description: 持久化到数据库 引入自定义规则
9091
//@return: *casbin.Enforcer
9192

93+
var (
94+
e *casbin.Enforcer
95+
once sync.Once
96+
)
97+
9298
func Casbin() *casbin.Enforcer {
93-
a, _ := gormadapter.NewAdapterByDB(global.GVA_DB)
94-
e, _ := casbin.NewEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a)
95-
e.AddFunction("ParamsMatch", ParamsMatchFunc)
99+
once.Do(func() {
100+
a, _ := gormadapter.NewAdapterByDB(global.GVA_DB)
101+
e, _ = casbin.NewEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a)
102+
e.AddFunction("ParamsMatch", ParamsMatchFunc)
103+
})
96104
_ = e.LoadPolicy()
97105
return e
98106
}

server/utils/reload.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package utils
2+
3+
import (
4+
"errors"
5+
"os"
6+
"os/exec"
7+
"runtime"
8+
"strconv"
9+
)
10+
11+
func Reload() error {
12+
if runtime.GOOS == "windows" {
13+
return errors.New("系统不支持")
14+
}
15+
pid := os.Getpid()
16+
cmd := exec.Command("kill", "-1", strconv.Itoa(pid))
17+
return cmd.Run()
18+
}

web/src/components/chooseImg/index.vue

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<el-drawer title="媒体库" :visible.sync="drawer">
3-
<div style="display:flex;justify-content:space-around;flex-wrap:wrap;padding-top:40px">
3+
<div class="media">
44
<el-image
55
class="header-img-box-list"
66
:src="(item.url && item.url.slice(0, 4) !== 'http')?path+item.url:item.url"
@@ -49,13 +49,20 @@ export default {
4949
</script>
5050

5151
<style lang="scss">
52-
.header-img-box-list {
53-
width: 180px;
54-
height: 180px;
55-
border: 1px dashed #ccc;
56-
border-radius: 20px;
57-
text-align: center;
58-
line-height: 180px;
59-
cursor: pointer;
52+
.media{
53+
display:flex;
54+
flex-wrap:wrap;
55+
.header-img-box-list {
56+
margin-top: 20px;
57+
width: 120px;
58+
margin-left: 20px;
59+
height: 120px;
60+
border: 1px dashed #ccc;
61+
border-radius: 20px;
62+
text-align: center;
63+
line-height: 180px;
64+
cursor: pointer;
6065
}
66+
}
67+
6168
</style>

0 commit comments

Comments
 (0)