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