Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions server/api/v1/example/exa_file_upload_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,26 @@ func (b *FileUploadAndDownloadApi) GetFileList(c *gin.Context) {
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}

// ImportURL
// @Tags ExaFileUploadAndDownload
// @Summary 导入URL
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body example.ExaFileUploadAndDownload true "对象"
// @Success 200 {object} response.Response{msg=string} "导入URL"
// @Router /fileUploadAndDownload/importURL [post]
func (b *FileUploadAndDownloadApi) ImportURL(c *gin.Context) {
var file []example.ExaFileUploadAndDownload
err := c.ShouldBindJSON(&file)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := fileUploadAndDownloadService.ImportURL(&file); err != nil {
global.GVA_LOG.Error("导入URL失败!", zap.Error(err))
response.FailWithMessage("导入URL失败", c)
return
}
response.OkWithMessage("导入URL成功", c)
}
27 changes: 27 additions & 0 deletions server/api/v1/system/sys_user.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package system

import (
"gorm.io/datatypes"
"strconv"
"time"

Expand Down Expand Up @@ -415,6 +416,32 @@ func (b *BaseApi) SetSelfInfo(c *gin.Context) {
response.OkWithMessage("设置成功", c)
}

// SetSelfSetting
// @Tags SysUser
// @Summary 设置用户配置
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body datatypes.JSON
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户配置"
// @Router /user/SetSelfSetting [put]
func (b *BaseApi) SetSelfSetting(c *gin.Context) {
var req datatypes.JSON
err := c.ShouldBindJSON(&req)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}

err = userService.SetSelfSetting(&req, utils.GetUserID(c))
if err != nil {
global.GVA_LOG.Error("设置失败!", zap.Error(err))
response.FailWithMessage("设置失败", c)
return
}
response.OkWithMessage("设置成功", c)
}

// GetUserInfo
// @Tags SysUser
// @Summary 获取用户信息
Expand Down
28 changes: 15 additions & 13 deletions server/model/system/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package system
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/gofrs/uuid/v5"
"gorm.io/datatypes"
)

type Login interface {
Expand All @@ -18,19 +19,20 @@ var _ Login = new(SysUser)

type SysUser struct {
global.GVA_MODEL
UUID uuid.UUID `json:"uuid" gorm:"index;comment:用户UUID"` // 用户UUID
Username string `json:"userName" gorm:"index;comment:用户登录名"` // 用户登录名
Password string `json:"-" gorm:"comment:用户登录密码"` // 用户登录密码
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
SideMode string `json:"sideMode" gorm:"default:dark;comment:用户侧边主题"` // 用户侧边主题
HeaderImg string `json:"headerImg" gorm:"default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像"` // 用户头像
BaseColor string `json:"baseColor" gorm:"default:#fff;comment:基础颜色"` // 基础颜色
AuthorityId uint `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID
Authority SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"`
Authorities []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"`
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户手机号
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
Enable int `json:"enable" gorm:"default:1;comment:用户是否被冻结 1正常 2冻结"` //用户是否被冻结 1正常 2冻结
UUID uuid.UUID `json:"uuid" gorm:"index;comment:用户UUID"` // 用户UUID
Username string `json:"userName" gorm:"index;comment:用户登录名"` // 用户登录名
Password string `json:"-" gorm:"comment:用户登录密码"` // 用户登录密码
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
SideMode string `json:"sideMode" gorm:"default:dark;comment:用户侧边主题"` // 用户侧边主题
HeaderImg string `json:"headerImg" gorm:"default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像"` // 用户头像
BaseColor string `json:"baseColor" gorm:"default:#fff;comment:基础颜色"` // 基础颜色
AuthorityId uint `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID
Authority SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"` // 用户角色
Authorities []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"` // 多用户角色
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户手机号
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
Enable int `json:"enable" gorm:"default:1;comment:用户是否被冻结 1正常 2冻结"` //用户是否被冻结 1正常 2冻结
OriginSetting datatypes.JSON `json:"originSetting" form:"originSetting" gorm:"default:null;column:origin_setting;comment:配置;"` //配置
}

func (SysUser) TableName() string {
Expand Down
1 change: 1 addition & 0 deletions server/router/example/exa_file_upload_and_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ func (e *FileUploadAndDownloadRouter) InitFileUploadAndDownloadRouter(Router *gi
fileUploadAndDownloadRouter.GET("findFile", exaFileUploadAndDownloadApi.FindFile) // 查询当前文件成功的切片
fileUploadAndDownloadRouter.POST("breakpointContinueFinish", exaFileUploadAndDownloadApi.BreakpointContinueFinish) // 切片传输完成
fileUploadAndDownloadRouter.POST("removeChunk", exaFileUploadAndDownloadApi.RemoveChunk) // 删除切片
fileUploadAndDownloadRouter.POST("importURL", exaFileUploadAndDownloadApi.ImportURL) // 导入URL
}
}
1 change: 1 addition & 0 deletions server/router/system/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (s *UserRouter) InitUserRouter(Router *gin.RouterGroup) {
userRouter.PUT("setSelfInfo", baseApi.SetSelfInfo) // 设置自身信息
userRouter.POST("setUserAuthorities", baseApi.SetUserAuthorities) // 设置用户权限组
userRouter.POST("resetPassword", baseApi.ResetPassword) // 设置用户权限组
userRouter.PUT("setSelfSetting", baseApi.SetSelfSetting) // 用户界面配置
}
{
userRouterWithoutRecord.POST("getUserList", baseApi.GetUserList) // 分页获取用户列表
Expand Down
10 changes: 10 additions & 0 deletions server/service/example/exa_file_upload_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@ func (e *FileUploadAndDownloadService) UploadFile(header *multipart.FileHeader,
}
return f, nil
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: ImportURL
//@description: 导入URL
//@param: file model.ExaFileUploadAndDownload
//@return: error

func (e *FileUploadAndDownloadService) ImportURL(file *[]example.ExaFileUploadAndDownload) error {
return global.GVA_DB.Create(&file).Error
}
11 changes: 11 additions & 0 deletions server/service/system/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package system
import (
"errors"
"fmt"
"gorm.io/datatypes"
"time"

"github.com/flipped-aurora/gin-vue-admin/server/global"
Expand Down Expand Up @@ -238,6 +239,16 @@ func (userService *UserService) SetSelfInfo(req system.SysUser) error {
Updates(req).Error
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetSelfSetting
//@description: 设置用户配置
//@param: req datatypes.JSON, uid uint
//@return: err error

func (userService *UserService) SetSelfSetting(req *datatypes.JSON, uid uint) error {
return global.GVA_DB.Model(&system.SysUser{}).Where("id = ?", uid).Update("origin_setting", req).Error
}

//@author: [piexlmax](https://github.com/piexlmax)
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: GetUserInfo
Expand Down
2 changes: 2 additions & 0 deletions server/source/system/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (i *initApi) InitializeData(ctx context.Context) (context.Context, error) {
{ApiGroup: "系统用户", Method: "POST", Path: "/user/changePassword", Description: "修改密码(建议选择)"},
{ApiGroup: "系统用户", Method: "POST", Path: "/user/setUserAuthority", Description: "修改用户角色(必选)"},
{ApiGroup: "系统用户", Method: "POST", Path: "/user/resetPassword", Description: "重置用户密码"},
{ApiGroup: "系统用户", Method: "PUT", Path: "/user/setSelfSetting", Description: "用户界面配置"},

{ApiGroup: "api", Method: "POST", Path: "/api/createApi", Description: "创建api"},
{ApiGroup: "api", Method: "POST", Path: "/api/deleteApi", Description: "删除Api"},
Expand Down Expand Up @@ -97,6 +98,7 @@ func (i *initApi) InitializeData(ctx context.Context) (context.Context, error) {
{ApiGroup: "文件上传与下载", Method: "POST", Path: "/fileUploadAndDownload/deleteFile", Description: "删除文件"},
{ApiGroup: "文件上传与下载", Method: "POST", Path: "/fileUploadAndDownload/editFileName", Description: "文件名或者备注编辑"},
{ApiGroup: "文件上传与下载", Method: "POST", Path: "/fileUploadAndDownload/getFileList", Description: "获取上传文件列表"},
{ApiGroup: "文件上传与下载", Method: "POST", Path: "/fileUploadAndDownload/importURL", Description: "导入URL"},

{ApiGroup: "系统服务", Method: "POST", Path: "/system/getServerInfo", Description: "获取服务器信息"},
{ApiGroup: "系统服务", Method: "POST", Path: "/system/getSystemConfig", Description: "获取配置文件内容"},
Expand Down
4 changes: 4 additions & 0 deletions server/source/system/casbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (i *initCasbin) InitializeData(ctx context.Context) (context.Context, error
{Ptype: "p", V0: "888", V1: "/user/setUserAuthority", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/user/setUserAuthorities", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/user/resetPassword", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/user/setSelfSetting", V2: "PUT"},

{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/findFile", V2: "GET"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/breakpointContinueFinish", V2: "POST"},
Expand All @@ -95,6 +96,7 @@ func (i *initCasbin) InitializeData(ctx context.Context) (context.Context, error
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/editFileName", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/fileUploadAndDownload/importURL", V2: "POST"},

{Ptype: "p", V0: "888", V1: "/casbin/updateCasbin", V2: "POST"},
{Ptype: "p", V0: "888", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
Expand Down Expand Up @@ -203,6 +205,7 @@ func (i *initCasbin) InitializeData(ctx context.Context) (context.Context, error
{Ptype: "p", V0: "8881", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/fileUploadAndDownload/editFileName", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/fileUploadAndDownload/importURL", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/casbin/updateCasbin", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
{Ptype: "p", V0: "8881", V1: "/jwt/jsonInBlacklist", V2: "POST"},
Expand Down Expand Up @@ -244,6 +247,7 @@ func (i *initCasbin) InitializeData(ctx context.Context) (context.Context, error
{Ptype: "p", V0: "9528", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/fileUploadAndDownload/editFileName", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/fileUploadAndDownload/importURL", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/casbin/updateCasbin", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
{Ptype: "p", V0: "9528", V1: "/jwt/jsonInBlacklist", V2: "POST"},
Expand Down
13 changes: 13 additions & 0 deletions web/src/api/fileUploadAndDownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,16 @@ export const editFileName = (data) => {
data
})
}

/**
* 导入URL
* @param data
* @returns {*}
*/
export const importURL = (data) => {
return service({
url: '/fileUploadAndDownload/importURL',
method: 'post',
data
})
}
16 changes: 16 additions & 0 deletions web/src/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ export const setSelfInfo = (data) => {
})
}

// @Tags SysUser
// @Summary 设置自身界面配置
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysUser true "设置自身界面配置"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/setSelfSetting [put]
export const setSelfSetting = (data) => {
return service({
url: '/user/setSelfSetting',
method: 'put',
data: data
})
}

// @Tags User
// @Summary 设置用户权限
// @Security ApiKeyAuth
Expand Down
1 change: 1 addition & 0 deletions web/src/components/upload/common.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:on-error="uploadError"
:on-success="uploadSuccess"
:show-file-list="false"
multiple
class="upload-btn"
>
<el-button type="primary">普通上传</el-button>
Expand Down
37 changes: 24 additions & 13 deletions web/src/pinia/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { ref, watchEffect, reactive } from 'vue'
import originSetting from "@/config.json"
import { setBodyPrimaryColor } from '@/utils/format'
export const useAppStore = defineStore('app', () => {
const theme = ref(localStorage.getItem('theme') || originSetting.darkMode || 'auto')

let selfOriginSetting = originSetting
const localOriginSetting = localStorage.getItem('originSetting')
if (localOriginSetting) {
selfOriginSetting = JSON.parse(localOriginSetting)
}

const theme = ref(localStorage.getItem('theme') || selfOriginSetting.darkMode || 'auto')
const device = ref("")
const config = reactive({
weakness: false,
Expand All @@ -20,18 +27,6 @@ export const useAppStore = defineStore('app', () => {
side_mode : 'normal'
})

// 初始化配置
Object.keys(originSetting).forEach(key => {
config[key] = originSetting[key]
if(key === 'primaryColor'){
setBodyPrimaryColor(originSetting[key],config.darkMode)
}
})

if (localStorage.getItem('darkMode')) {
config.darkMode = localStorage.getItem('darkMode')
}


watchEffect(() =>{
if (theme.value === 'dark'){
Expand Down Expand Up @@ -124,6 +119,22 @@ export const useAppStore = defineStore('app', () => {
config.side_mode = e
}

// 初始化配置
Object.keys(selfOriginSetting).forEach(key => {
config[key] = selfOriginSetting[key]
if(key === 'primaryColor'){
setBodyPrimaryColor(selfOriginSetting[key],config.darkMode)
}
if(key === 'darkMode'){
toggleDarkMode(config.darkMode)
}
})

const darkMode = localStorage.getItem('darkMode')
if (darkMode) {
config.darkMode = darkMode
}

if(config.darkMode === 'auto'){
toggleDarkModeAuto()
}
Expand Down
8 changes: 6 additions & 2 deletions web/src/pinia/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ export const useUserStore = defineStore('user', () => {
const token = ref(window.localStorage.getItem('token') || cookie.get('x-token') || '')
const setUserInfo = (val) => {
userInfo.value = val
if(val.originSetting){
localStorage.setItem('originSetting', JSON.stringify(val.originSetting))
}
}

const setToken = (val) => {
token.value = val
}

const NeedInit = () => {
const NeedInit = async () => {
token.value = ''
window.localStorage.removeItem('token')
router.push({ name: 'Init', replace: true })
await router.push({name: 'Init', replace: true})
}

const ResetUserInfo = (value = {}) => {
Expand Down Expand Up @@ -89,6 +92,7 @@ export const useUserStore = defineStore('user', () => {
window.localStorage.setItem('osType', 'MAC')
}


// 全部操作均结束,关闭loading并返回
loadingInstance.value.close()
return true
Expand Down
14 changes: 13 additions & 1 deletion web/src/utils/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,16 @@ const baseUrl = ref(import.meta.env.VITE_BASE_API)

export const getBaseUrl = () => {
return baseUrl.value === "/" ? "" : baseUrl.value
}
}

export const CreateUUID = () => {
let d = new Date().getTime()
if (window.performance && typeof window.performance.now === 'function') {
d += performance.now()
}
return '00000000-0000-0000-0000-000000000000'.replace(/0/g, (c) => {
const r = (d + Math.random() * 16) % 16 | 0 // d是随机种子
d = Math.floor(d / 16)
return (c === '0' ? r : (r & 0x3 | 0x8)).toString(16)
})
}
Loading
Loading