From da565883282eef093129052324e9a81865de6525 Mon Sep 17 00:00:00 2001 From: task <121913992@qq.com> Date: Thu, 29 Aug 2024 14:22:16 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AA=92=E4=BD=93=E5=BA=93=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=89=B9=E9=87=8F=E5=AF=BC=E5=85=A5URL=EF=BC=9B=20?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=EF=BC=9A=E6=96=87=E4=BB=B6=E5=90=8D|?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E6=88=96=E8=80=85=E4=BB=85=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 示例: 我的图片|https://my-oss.com/my.png https://my-oss.com/my_1.png --- .../v1/example/exa_file_upload_download.go | 23 +++++++ .../example/exa_file_upload_and_download.go | 1 + .../example/exa_file_upload_download.go | 10 +++ server/source/system/api.go | 1 + server/source/system/casbin.go | 3 + web/src/api/fileUploadAndDownload.js | 13 ++++ web/src/components/upload/common.vue | 1 + web/src/utils/format.js | 14 +++- web/src/view/example/upload/upload.vue | 67 +++++++++++++++++-- web/src/view/systemTools/system/system.vue | 19 ++---- 10 files changed, 133 insertions(+), 19 deletions(-) diff --git a/server/api/v1/example/exa_file_upload_download.go b/server/api/v1/example/exa_file_upload_download.go index 18d1251240..330c8a7982 100644 --- a/server/api/v1/example/exa_file_upload_download.go +++ b/server/api/v1/example/exa_file_upload_download.go @@ -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) +} diff --git a/server/router/example/exa_file_upload_and_download.go b/server/router/example/exa_file_upload_and_download.go index 19d983c317..84f6ecdb08 100644 --- a/server/router/example/exa_file_upload_and_download.go +++ b/server/router/example/exa_file_upload_and_download.go @@ -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 } } diff --git a/server/service/example/exa_file_upload_download.go b/server/service/example/exa_file_upload_download.go index 15e2d70cb4..abd4accad1 100644 --- a/server/service/example/exa_file_upload_download.go +++ b/server/service/example/exa_file_upload_download.go @@ -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.SysAttachment +//@return: error + +func (e *FileUploadAndDownloadService) ImportURL(file *[]example.ExaFileUploadAndDownload) error { + return global.GVA_DB.Create(&file).Error +} diff --git a/server/source/system/api.go b/server/source/system/api.go index 30e59e38b7..757f98cf26 100644 --- a/server/source/system/api.go +++ b/server/source/system/api.go @@ -97,6 +97,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: "c"}, {ApiGroup: "系统服务", Method: "POST", Path: "/system/getServerInfo", Description: "获取服务器信息"}, {ApiGroup: "系统服务", Method: "POST", Path: "/system/getSystemConfig", Description: "获取配置文件内容"}, diff --git a/server/source/system/casbin.go b/server/source/system/casbin.go index 92b83c1f0d..a9db0047a3 100644 --- a/server/source/system/casbin.go +++ b/server/source/system/casbin.go @@ -95,6 +95,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"}, @@ -203,6 +204,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"}, @@ -244,6 +246,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"}, diff --git a/web/src/api/fileUploadAndDownload.js b/web/src/api/fileUploadAndDownload.js index 0a5d0211db..2bff5bb47e 100644 --- a/web/src/api/fileUploadAndDownload.js +++ b/web/src/api/fileUploadAndDownload.js @@ -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 + }) +} diff --git a/web/src/components/upload/common.vue b/web/src/components/upload/common.vue index a010e2cd9f..94d30d00a9 100644 --- a/web/src/components/upload/common.vue +++ b/web/src/components/upload/common.vue @@ -6,6 +6,7 @@ :on-error="uploadError" :on-success="uploadSuccess" :show-file-list="false" + multiple class="upload-btn" > 普通上传 diff --git a/web/src/utils/format.js b/web/src/utils/format.js index cf3f1a05a8..4fd9ad80df 100644 --- a/web/src/utils/format.js +++ b/web/src/utils/format.js @@ -124,4 +124,16 @@ const baseUrl = ref(import.meta.env.VITE_BASE_API) export const getBaseUrl = () => { return baseUrl.value === "/" ? "" : baseUrl.value -} \ No newline at end of file +} + +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) + }) +} diff --git a/web/src/view/example/upload/upload.vue b/web/src/view/example/upload/upload.vue index 727cc5645c..1b08a837d7 100644 --- a/web/src/view/example/upload/upload.vue +++ b/web/src/view/example/upload/upload.vue @@ -15,9 +15,16 @@ :max-w-h="1080" @on-success="getTableData" /> + + 导入URL + diff --git a/web/src/view/systemTools/system/system.vue b/web/src/view/systemTools/system/system.vue index 634df9e35d..83b370feb9 100644 --- a/web/src/view/systemTools/system/system.vue +++ b/web/src/view/systemTools/system/system.vue @@ -13,7 +13,7 @@ class="mt-3.5" > - + - 开启 + @@ -75,7 +75,7 @@ @@ -682,6 +682,7 @@ import { ref } from 'vue' import { ElMessage, ElMessageBox } from 'element-plus' import { Minus, Plus } from '@element-plus/icons-vue' import { emailTest } from '@/api/email' +import {CreateUUID} from "@/utils/format"; defineOptions({ name: 'Config', @@ -795,16 +796,8 @@ const email = async() => { } } -const CreateUUID = () => { - let d = new Date().getTime() - if (window.performance && typeof window.performance.now === 'function') { - d += performance.now() - } - config.value.jwt['signing-key'] = '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) - }) +const getUUID = () => { + config.value.jwt['signing-key'] = CreateUUID() } const addNode = () => { From c1d5e9535025860e258f7ea69aba8333e146ab58 Mon Sep 17 00:00:00 2001 From: task <121913992@qq.com> Date: Thu, 29 Aug 2024 15:09:43 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix=20=E6=8F=8F=E8=BF=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/example/exa_file_upload_download.go | 2 +- server/source/system/api.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/service/example/exa_file_upload_download.go b/server/service/example/exa_file_upload_download.go index abd4accad1..85b7d3387e 100644 --- a/server/service/example/exa_file_upload_download.go +++ b/server/service/example/exa_file_upload_download.go @@ -110,7 +110,7 @@ func (e *FileUploadAndDownloadService) UploadFile(header *multipart.FileHeader, //@author: [piexlmax](https://github.com/piexlmax) //@function: ImportURL //@description: 导入URL -//@param: file model.SysAttachment +//@param: file model.ExaFileUploadAndDownload //@return: error func (e *FileUploadAndDownloadService) ImportURL(file *[]example.ExaFileUploadAndDownload) error { diff --git a/server/source/system/api.go b/server/source/system/api.go index 757f98cf26..a5f198fb29 100644 --- a/server/source/system/api.go +++ b/server/source/system/api.go @@ -97,7 +97,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: "c"}, + {ApiGroup: "文件上传与下载", Method: "POST", Path: "/fileUploadAndDownload/importURL", Description: "导入URL"}, {ApiGroup: "系统服务", Method: "POST", Path: "/system/getServerInfo", Description: "获取服务器信息"}, {ApiGroup: "系统服务", Method: "POST", Path: "/system/getSystemConfig", Description: "获取配置文件内容"}, From f6dbdd13dfc72682904740d7912a29d35a2f6f5f Mon Sep 17 00:00:00 2001 From: task <121913992@qq.com> Date: Fri, 6 Sep 2024 18:29:50 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=B0=86=E7=94=A8=E6=88=B7=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=BF=9D=E5=AD=98=E5=88=B0=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=EF=BC=8C=E5=88=B7=E6=96=B0=E6=88=96=E8=80=85=E5=BC=82=E5=9C=B0?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=85=8D=E7=BD=AE=E4=B8=8D=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/system/sys_user.go | 27 +++++++++++++++++++ server/model/system/sys_user.go | 28 ++++++++++---------- server/router/system/sys_user.go | 1 + server/service/system/sys_user.go | 11 ++++++++ server/source/system/api.go | 1 + server/source/system/casbin.go | 1 + web/src/api/user.js | 16 ++++++++++++ web/src/pinia/modules/app.js | 37 +++++++++++++++++---------- web/src/pinia/modules/user.js | 8 ++++-- web/src/view/layout/setting/index.vue | 25 +++++++++--------- web/src/view/login/index.vue | 6 ++--- 11 files changed, 118 insertions(+), 43 deletions(-) diff --git a/server/api/v1/system/sys_user.go b/server/api/v1/system/sys_user.go index 2dc83d3676..edc7caa5f2 100644 --- a/server/api/v1/system/sys_user.go +++ b/server/api/v1/system/sys_user.go @@ -1,6 +1,7 @@ package system import ( + "gorm.io/datatypes" "strconv" "time" @@ -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 获取用户信息 diff --git a/server/model/system/sys_user.go b/server/model/system/sys_user.go index 9a6892abc4..1af7027e1e 100644 --- a/server/model/system/sys_user.go +++ b/server/model/system/sys_user.go @@ -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 { @@ -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 { diff --git a/server/router/system/sys_user.go b/server/router/system/sys_user.go index 35fc741aaf..6c14b82001 100644 --- a/server/router/system/sys_user.go +++ b/server/router/system/sys_user.go @@ -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) // 分页获取用户列表 diff --git a/server/service/system/sys_user.go b/server/service/system/sys_user.go index 221209f92b..3484766d1f 100644 --- a/server/service/system/sys_user.go +++ b/server/service/system/sys_user.go @@ -3,6 +3,7 @@ package system import ( "errors" "fmt" + "gorm.io/datatypes" "time" "github.com/flipped-aurora/gin-vue-admin/server/global" @@ -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 diff --git a/server/source/system/api.go b/server/source/system/api.go index a5f198fb29..f3affb211a 100644 --- a/server/source/system/api.go +++ b/server/source/system/api.go @@ -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"}, diff --git a/server/source/system/casbin.go b/server/source/system/casbin.go index a9db0047a3..bafd9ec123 100644 --- a/server/source/system/casbin.go +++ b/server/source/system/casbin.go @@ -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"}, diff --git a/web/src/api/user.js b/web/src/api/user.js index f1f3638ab9..2b357d031e 100644 --- a/web/src/api/user.js +++ b/web/src/api/user.js @@ -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 diff --git a/web/src/pinia/modules/app.js b/web/src/pinia/modules/app.js index ddeb7f7fad..10a4b2e4af 100644 --- a/web/src/pinia/modules/app.js +++ b/web/src/pinia/modules/app.js @@ -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, @@ -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'){ @@ -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() } diff --git a/web/src/pinia/modules/user.js b/web/src/pinia/modules/user.js index 9f20fd7cb5..7370c44586 100644 --- a/web/src/pinia/modules/user.js +++ b/web/src/pinia/modules/user.js @@ -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 = {}) => { @@ -89,6 +92,7 @@ export const useUserStore = defineStore('user', () => { window.localStorage.setItem('osType', 'MAC') } + // 全部操作均结束,关闭loading并返回 loadingInstance.value.close() return true diff --git a/web/src/view/layout/setting/index.vue b/web/src/view/layout/setting/index.vue index 8ab84c1165..6269171e41 100644 --- a/web/src/view/layout/setting/index.vue +++ b/web/src/view/layout/setting/index.vue @@ -112,14 +112,12 @@ - + - 复制配置json + 保存配置 @@ -129,6 +127,7 @@ import { useAppStore } from "@/pinia"; import { storeToRefs } from "pinia"; import { ref, computed } from "vue"; import { ElMessage } from "element-plus"; +import {setSelfSetting} from "@/api/user"; const appStore = useAppStore(); const { config, device } = storeToRefs(appStore); defineOptions({ @@ -169,8 +168,8 @@ const sideModes = [ } ]; -const copyConfig = () => { - const input = document.createElement("textarea"); +const saveConfig = async () => { + /*const input = document.createElement("textarea"); input.value = JSON.stringify(config.value); // 添加回车 input.value = input.value.replace(/,/g, ",\n"); @@ -178,14 +177,16 @@ const copyConfig = () => { input.select(); document.execCommand("copy"); document.body.removeChild(input); - ElMessage.success("复制成功, 请自行保存到本地文件中"); + ElMessage.success("复制成功, 请自行保存到本地文件中");*/ + const res = await setSelfSetting(config.value) + if(res.code === 0){ + localStorage.setItem('originSetting', JSON.stringify(config.value)) + ElMessage.success('保存成功') + drawer.value = false + } }; const customColor = ref(""); - -const handleSideModelChange = (e) => { - console.log(e); -};