mirror of
https://gitcode.com/flipped-aurora/gin-vue-admin.git
synced 2025-12-30 03:42:26 +00:00
Merge pull request #2145 from bypanghu/main
fix: 更新优化插件注册 api 和注册 menus 逻辑。
This commit is contained in:
@@ -264,7 +264,7 @@ func (b *BaseApi) SetUserAuthority(c *gin.Context) {
|
||||
}
|
||||
c.Header("new-token", token)
|
||||
c.Header("new-expires-at", strconv.FormatInt(claims.ExpiresAt.Unix(), 10))
|
||||
utils.SetToken(c, token, int((claims.ExpiresAt.Unix()-time.Now().Unix())/60))
|
||||
utils.SetToken(c, token, int(claims.ExpiresAt.Unix()-time.Now().Unix()))
|
||||
response.OkWithMessage("修改成功", c)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ type SysBaseMenu struct {
|
||||
Hidden bool `json:"hidden" gorm:"comment:是否在列表隐藏"` // 是否在列表隐藏
|
||||
Component string `json:"component" gorm:"comment:对应前端文件路径"` // 对应前端文件路径
|
||||
Sort int `json:"sort" gorm:"comment:排序标记"` // 排序标记
|
||||
Meta `json:"meta" gorm:"embedded;comment:附加属性"` // 附加属性
|
||||
Meta `json:"meta" gorm:"embedded"` // 附加属性
|
||||
SysAuthoritys []SysAuthority `json:"authoritys" gorm:"many2many:sys_authority_menus;"`
|
||||
Children []SysBaseMenu `json:"children" gorm:"-"`
|
||||
Parameters []SysBaseMenuParameter `json:"parameters"`
|
||||
|
||||
@@ -1,50 +1,53 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
)
|
||||
|
||||
func RegisterApis(apis ...system.SysApi) {
|
||||
var count int64
|
||||
var apiPaths []string
|
||||
for i := range apis {
|
||||
apiPaths = append(apiPaths, apis[i].Path)
|
||||
}
|
||||
global.GVA_DB.Find(&[]system.SysApi{}, "path in (?)", apiPaths).Count(&count)
|
||||
if count > 0 {
|
||||
return
|
||||
}
|
||||
err := global.GVA_DB.Create(&apis).Error
|
||||
func RegisterApis( apis ...system.SysApi) {
|
||||
err := global.GVA_DB.Transaction(func(tx *gorm.DB) error {
|
||||
for _, api := range apis {
|
||||
err := tx.Model(system.SysApi{}).Where("path = ? AND method = ? AND api_group = ? ", api.Path, api.Method, api.ApiGroup).FirstOrCreate(&api).Error
|
||||
if err != nil {
|
||||
zap.L().Error("注册API失败", zap.Error(err), zap.String("api", api.Path), zap.String("method", api.Method), zap.String("apiGroup", api.ApiGroup))
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
zap.L().Error("注册API失败", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
func RegisterMenus(menus ...system.SysBaseMenu) {
|
||||
var count int64
|
||||
var menuNames []string
|
||||
func RegisterMenus( menus ...system.SysBaseMenu) {
|
||||
parentMenu := menus[0]
|
||||
otherMenus := menus[1:]
|
||||
for i := range menus {
|
||||
menuNames = append(menuNames, menus[i].Name)
|
||||
}
|
||||
global.GVA_DB.Find(&[]system.SysBaseMenu{}, "name in (?)", menuNames).Count(&count)
|
||||
if count > 0 {
|
||||
return
|
||||
}
|
||||
err := global.GVA_DB.Create(&parentMenu).Error
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
for i := range otherMenus {
|
||||
err := global.GVA_DB.Transaction(func(tx *gorm.DB) error {
|
||||
err := tx.Model(system.SysBaseMenu{}).Where("name = ? ", parentMenu.Name).FirstOrCreate(&parentMenu).Error
|
||||
if err != nil {
|
||||
zap.L().Error("注册菜单失败", zap.Error(err))
|
||||
return errors.Wrap(err, "注册菜单失败")
|
||||
}
|
||||
pid := parentMenu.ID
|
||||
otherMenus[i].ParentId = pid
|
||||
}
|
||||
err = global.GVA_DB.Create(&otherMenus).Error
|
||||
for i := range otherMenus {
|
||||
otherMenus[i].ParentId = pid
|
||||
err = tx.Model(system.SysBaseMenu{}).Where("name = ? ", otherMenus[i].Name).FirstOrCreate(&otherMenus[i]).Error
|
||||
if err != nil {
|
||||
zap.L().Error("注册菜单失败", zap.Error(err))
|
||||
return errors.Wrap(err, "注册菜单失败")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
zap.L().Error("注册菜单失败", zap.Error(err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ func GenerateSearchFormItem(field systemReq.AutoCodeField) string {
|
||||
if field.FieldType == "array" {
|
||||
multipleAttr = "multiple "
|
||||
}
|
||||
result += fmt.Sprintf(` <el-tree-select v-model="formData.%s" placeholder="请选择%s" :data="%sOptions" style="width:100%%" filterable :clearable="%v" check-strictly %s></el-tree-select>
|
||||
result += fmt.Sprintf(` <el-tree-select v-model="searchInfo.%s" placeholder="请选择%s" :data="%sOptions" style="width:100%%" filterable :clearable="%v" check-strictly %s></el-tree-select>
|
||||
`,
|
||||
field.FieldJson, field.FieldDesc, field.DictType, field.Clearable, multipleAttr)
|
||||
} else if field.CheckDataSource {
|
||||
|
||||
@@ -49,7 +49,7 @@ func GetToken(c *gin.Context) string {
|
||||
global.GVA_LOG.Error("重新写入cookie token失败,未能成功解析token,请检查请求头是否存在x-token且claims是否为规定结构")
|
||||
return token
|
||||
}
|
||||
SetToken(c, token, int((claims.ExpiresAt.Unix()-time.Now().Unix())/60))
|
||||
SetToken(c, token, int(claims.ExpiresAt.Unix()-time.Now().Unix()))
|
||||
}
|
||||
return token
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ const greenText = (text) => `\x1b[32m${text}\x1b[0m`
|
||||
export const config = {
|
||||
appName: 'Gin-Vue-Admin',
|
||||
showViteLogo: true,
|
||||
KeepAliveTabs: true,
|
||||
keepAliveTabs: false,
|
||||
logs: []
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ export const useRouterStore = defineStore('router', () => {
|
||||
|
||||
// 1. 首先添加原有的keepAlive配置
|
||||
keepArrTemp.push(...keepAliveRoutersArr)
|
||||
if (config.KeepAliveTabs) {
|
||||
if (config.keepAliveTabs) {
|
||||
history.forEach((item) => {
|
||||
// 2. 为所有history中的路由强制启用keep-alive
|
||||
// 通过routeMap获取路由信息,然后通过pathInfo获取组件名
|
||||
|
||||
@@ -174,7 +174,7 @@
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
|
||||
<el-drawer
|
||||
v-model="addUserDialog"
|
||||
:size="appStore.drawerSize"
|
||||
@@ -356,6 +356,12 @@
|
||||
}
|
||||
)
|
||||
|
||||
const authOptions = ref([])
|
||||
const setOptions = (authData) => {
|
||||
authOptions.value = []
|
||||
setAuthorityOptions(authData, authOptions.value)
|
||||
}
|
||||
|
||||
const initPage = async () => {
|
||||
getTableData()
|
||||
const res = await getAuthorityList()
|
||||
@@ -373,7 +379,7 @@
|
||||
nickName: '',
|
||||
password: ''
|
||||
})
|
||||
|
||||
|
||||
// 生成随机密码
|
||||
const generateRandomPassword = () => {
|
||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*'
|
||||
@@ -395,7 +401,7 @@
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 打开重置密码对话框
|
||||
const resetPasswordFunc = (row) => {
|
||||
resetPwdInfo.value.ID = row.ID
|
||||
@@ -404,7 +410,7 @@
|
||||
resetPwdInfo.value.password = ''
|
||||
resetPwdDialog.value = true
|
||||
}
|
||||
|
||||
|
||||
// 确认重置密码
|
||||
const confirmResetPassword = async () => {
|
||||
if (!resetPwdInfo.value.password) {
|
||||
@@ -414,12 +420,12 @@
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
const res = await resetPassword({
|
||||
ID: resetPwdInfo.value.ID,
|
||||
password: resetPwdInfo.value.password
|
||||
})
|
||||
|
||||
|
||||
if (res.code === 0) {
|
||||
ElMessage({
|
||||
type: 'success',
|
||||
@@ -433,7 +439,7 @@
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 关闭重置密码对话框
|
||||
const closeResetPwdDialog = () => {
|
||||
resetPwdInfo.value.password = ''
|
||||
@@ -450,12 +456,6 @@
|
||||
})
|
||||
}
|
||||
|
||||
const authOptions = ref([])
|
||||
const setOptions = (authData) => {
|
||||
authOptions.value = []
|
||||
setAuthorityOptions(authData, authOptions.value)
|
||||
}
|
||||
|
||||
const deleteUserFunc = async (row) => {
|
||||
ElMessageBox.confirm('确定要删除吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
|
||||
Reference in New Issue
Block a user