From f63803529af536ec14ee1cd6cd80557442b3a1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=92=E8=8F=9C=E7=99=BD=E7=8E=89=E6=B1=A4?= <79054161+Azir-11@users.noreply.github.com> Date: Sun, 10 Nov 2024 17:02:31 +0800 Subject: [PATCH 01/28] =?UTF-8?q?perf(projects):=20=E5=A2=9E=E5=BC=BA?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=A0=A1=E9=AA=8C=E7=9A=84=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7=20(#1931)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/office/index.vue | 2 +- .../components/selectImage/selectImage.vue | 2 +- web/src/components/upload/image.vue | 4 +-- web/src/utils/image.js | 28 +++++++++++-------- web/src/view/example/upload/upload.vue | 2 +- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/web/src/components/office/index.vue b/web/src/components/office/index.vue index fa503be85..d22d6da4d 100644 --- a/web/src/components/office/index.vue +++ b/web/src/components/office/index.vue @@ -39,7 +39,7 @@ fileUrl.value = val const fileExt = val.split('.')[1] || '' const image = ['png', 'jpg', 'jpeg', 'gif'] - ext.value = image.includes(fileExt) ? 'image' : fileExt + ext.value = image.includes(fileExt?.toLowerCase()) ? 'image' : fileExt }, { immediate: true } ) diff --git a/web/src/components/selectImage/selectImage.vue b/web/src/components/selectImage/selectImage.vue index 3be279db0..2c08d88e5 100644 --- a/web/src/components/selectImage/selectImage.vue +++ b/web/src/components/selectImage/selectImage.vue @@ -218,7 +218,7 @@ const chooseImg = (url) => { if (props.fileType) { const typeSuccess = listObj[props.fileType].some((item) => { - if (url.includes(item)) { + if (url?.toLowerCase().includes(item)) { return true } }) diff --git a/web/src/components/upload/image.vue b/web/src/components/upload/image.vue index d7f021ca9..7423cc7de 100644 --- a/web/src/components/upload/image.vue +++ b/web/src/components/upload/image.vue @@ -38,8 +38,8 @@ }) const beforeImageUpload = (file) => { - const isJPG = file.type === 'image/jpeg' - const isPng = file.type === 'image/png' + const isJPG = file.type?.toLowerCase() === 'image/jpeg' + const isPng = file.type?.toLowerCase() === 'image/png' if (!isJPG && !isPng) { ElMessage.error('上传头像图片只能是 jpg或png 格式!') return false diff --git a/web/src/utils/image.js b/web/src/utils/image.js index a2d3241e8..8b6523295 100644 --- a/web/src/utils/image.js +++ b/web/src/utils/image.js @@ -106,17 +106,21 @@ export const getUrl = (url) => { } } -export const isVideoExt = (url) => - url.endsWith('.mp4') || - url.endsWith('.mov') || - url.endsWith('.webm') || - url.endsWith('.ogg') +const VIDEO_EXTENSIONS = ['.mp4', '.mov', '.webm', '.ogg'] +const VIDEO_MIME_TYPES = ['video/mp4', 'video/webm', 'video/ogg'] +const IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/webp', 'image/svg+xml'] -export const isVideoMime = (type) => - type == 'video/mp4' || type == 'video/webm' || type == 'video/ogg' +export const isVideoExt = (url) => { + const urlLower = url?.toLowerCase() || '' + return urlLower !== '' && VIDEO_EXTENSIONS.some(ext => urlLower.endsWith(ext)) +} -export const isImageMime = (type) => - type == 'image/jpeg' || - type == 'image/png' || - type == 'image/webp' || - type == 'image/svg+xml' +export const isVideoMime = (type) => { + const typeLower = type?.toLowerCase() || '' + return typeLower !== '' && VIDEO_MIME_TYPES.includes(typeLower) +} + +export const isImageMime = (type) => { + const typeLower = type?.toLowerCase() || '' + return typeLower !== '' && IMAGE_MIME_TYPES.includes(typeLower) +} diff --git a/web/src/view/example/upload/upload.vue b/web/src/view/example/upload/upload.vue index 8e85613f8..42a4c9161 100644 --- a/web/src/view/example/upload/upload.vue +++ b/web/src/view/example/upload/upload.vue @@ -50,7 +50,7 @@ import { reactive } from 'vue' + import config from "@/core/config"; defineOptions({ name: 'Icon' From a9894acd51479ca830375836580c7595d722ef46 Mon Sep 17 00:00:00 2001 From: pixelmaxQM Date: Thu, 14 Nov 2024 23:15:55 +0800 Subject: [PATCH 06/28] =?UTF-8?q?feat:=20=E5=85=81=E8=AE=B8=E6=B8=85?= =?UTF-8?q?=E9=99=A4=E5=85=B3=E8=81=94=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/package/web/view/table.vue.tpl | 38 ++++++++++++++----- .../plugin/web/view/view.vue.template | 38 ++++++++++++++----- .../autoCode/component/fieldDialog.vue | 19 +++++++--- 3 files changed, 72 insertions(+), 23 deletions(-) diff --git a/server/resource/package/web/view/table.vue.tpl b/server/resource/package/web/view/table.vue.tpl index ccc64851f..cf65ed2e2 100644 --- a/server/resource/package/web/view/table.vue.tpl +++ b/server/resource/package/web/view/table.vue.tpl @@ -74,13 +74,13 @@ {{- if .CheckDataSource }} {{- else if .DictType}} @@ -232,7 +232,17 @@ {{- range .Fields}} {{- if .Desc }} - {{- if and (ne .FieldType "picture" ) (ne .FieldType "pictures" ) (ne .FieldType "file" ) (ne .FieldType "array" ) }} +{{- if .CheckDataSource }} + + {{- else if and (ne .FieldType "picture" ) (ne .FieldType "pictures" ) (ne .FieldType "file" ) (ne .FieldType "array" ) }} {{"{{"}} detailFrom.{{.FieldJson}} {{"}}"}} {{- else }} {{- if eq .FieldType "picture" }} @@ -338,7 +348,7 @@ const {{ $element }}Options = ref([]) get{{.StructName}}DataSource, // 获取数据源 -const dataSource = ref([]) +const dataSource = ref({}) const getDataSourceFunc = async()=>{ const res = await get{{.StructName}}DataSource() if (res.code === 0) { @@ -537,13 +547,13 @@ getDataSourceFunc() {{- if .CheckDataSource }} {{- else if .DictType}} @@ -727,7 +737,17 @@ getDataSourceFunc() {{- range .Fields}} {{- if .Desc }} - {{- if and (ne .FieldType "picture" ) (ne .FieldType "pictures" ) (ne .FieldType "file" ) (ne .FieldType "array" ) }} + {{- if .CheckDataSource }} + + {{- else if and (ne .FieldType "picture" ) (ne .FieldType "pictures" ) (ne .FieldType "file" ) (ne .FieldType "array" ) }} {{"{{"}} detailFrom.{{.FieldJson}} {{"}}"}} {{- else }} {{- if eq .FieldType "picture" }} diff --git a/server/resource/plugin/web/view/view.vue.template b/server/resource/plugin/web/view/view.vue.template index 88f0e9a9d..b76fdd8ec 100644 --- a/server/resource/plugin/web/view/view.vue.template +++ b/server/resource/plugin/web/view/view.vue.template @@ -75,13 +75,13 @@ {{- if .CheckDataSource }} {{- else if .DictType}} @@ -233,7 +233,17 @@ {{- range .Fields}} {{- if .Desc }} - {{- if and (ne .FieldType "picture" ) (ne .FieldType "pictures" ) (ne .FieldType "file" ) (ne .FieldType "array" ) }} +{{- if .CheckDataSource }} + + {{- else if and (ne .FieldType "picture" ) (ne .FieldType "pictures" ) (ne .FieldType "file" ) (ne .FieldType "array" ) }} {{"{{"}} detailFrom.{{.FieldJson}} {{"}}"}} {{- else }} {{- if eq .FieldType "picture" }} @@ -335,7 +345,7 @@ const {{ $element }}Options = ref([]) // 请引用 get{{.StructName}}DataSource, // 获取数据源 -const dataSource = ref([]) +const dataSource = ref({}) const getDataSourceFunc = async()=>{ const res = await get{{.StructName}}DataSource() if (res.code === 0) { @@ -535,13 +545,13 @@ getDataSourceFunc() {{- if .CheckDataSource }} {{- else if .DictType}} @@ -727,7 +737,17 @@ getDataSourceFunc() {{- range .Fields}} {{- if .Desc }} - {{- if and (ne .FieldType "picture" ) (ne .FieldType "pictures" ) (ne .FieldType "file" ) (ne .FieldType "array" ) }} + {{- if .CheckDataSource }} + + {{- else if and (ne .FieldType "picture" ) (ne .FieldType "pictures" ) (ne .FieldType "file" ) (ne .FieldType "array" ) }} {{"{{"}} detailFrom.{{.FieldJson}} {{"}}"}} {{- else }} {{- if eq .FieldType "picture" }} diff --git a/web/src/view/systemTools/autoCode/component/fieldDialog.vue b/web/src/view/systemTools/autoCode/component/fieldDialog.vue index ea303a96d..11db11ed1 100644 --- a/web/src/view/systemTools/autoCode/component/fieldDialog.vue +++ b/web/src/view/systemTools/autoCode/component/fieldDialog.vue @@ -198,8 +198,10 @@ placeholder="请选择数据源表" filterable allow-create + clearable @focus="getDBTableList" @change="selectDB" + @clear="clearAccress" > { - getDBTableList() - middleDate.value.dataSource.table = '' + const clearAccress = () => { middleDate.value.dataSource.value = '' middleDate.value.dataSource.label = '' } + const clearDataSourceTable = () => { + middleDate.value.dataSource.table = '' + } + + const dbNameChange = () => { + getDBTableList() + clearDataSourceTable() + clearAccress() + } + const dbTableList = ref([]) const getDBTableList = async () => { @@ -445,8 +455,7 @@ value: item.tableName // 这里假设 value 也是 tableName,如果不同请调整 })) } - middleDate.value.dataSource.value = '' - middleDate.value.dataSource.label = '' + clearAccress() } const dbColumnList = ref([]) From f7889b9709a4f99e91f2602b5626c61e0341da02 Mon Sep 17 00:00:00 2001 From: zayn <972858472@qq.com> Date: Thu, 14 Nov 2024 18:38:53 -0800 Subject: [PATCH 07/28] Update format.js (#1935) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在关闭详情弹窗后 detailFrom为空对象,arr为undefined 使用slice控制台会报错 --- web/src/utils/format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/utils/format.js b/web/src/utils/format.js index c0f6fabfb..f5062e762 100644 --- a/web/src/utils/format.js +++ b/web/src/utils/format.js @@ -54,7 +54,7 @@ export const ReturnArrImg = (arr) => { } } else { // 如果不是数组类型 - if (arr.slice(0, 4) !== 'http') { + if (arr?.slice(0, 4) !== 'http') { imgArr.push(path + arr) } else { imgArr.push(arr) From b954457ae4a49bbf46d1981e5c0e2000597f4b20 Mon Sep 17 00:00:00 2001 From: task Date: Sat, 16 Nov 2024 13:24:19 +0800 Subject: [PATCH 08/28] Update date.js (#1937) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 替换被弃用的RegExp.$1、substr --- web/src/utils/date.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/web/src/utils/date.js b/web/src/utils/date.js index 0744cfb83..987a40d15 100644 --- a/web/src/utils/date.js +++ b/web/src/utils/date.js @@ -3,7 +3,8 @@ // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 -Date.prototype.Format = function (fmt) { +// eslint-disable-next-line no-extend-native +Date.prototype.Format = function(fmt) { const o = { 'M+': this.getMonth() + 1, // 月份 'd+': this.getDate(), // 日 @@ -11,19 +12,23 @@ Date.prototype.Format = function (fmt) { 'm+': this.getMinutes(), // 分 's+': this.getSeconds(), // 秒 'q+': Math.floor((this.getMonth() + 3) / 3), // 季度 - S: this.getMilliseconds() // 毫秒 + 'S': this.getMilliseconds() // 毫秒 } - if (/(y+)/.test(fmt)) { + const reg = /(y+)/ + if (reg.test(fmt)) { + const t = reg.exec(fmt)[1] fmt = fmt.replace( - RegExp.$1, - (this.getFullYear() + '').substr(4 - RegExp.$1.length) + t, + (this.getFullYear() + '').substring(4 - t.length) ) } - for (const k in o) { - if (new RegExp('(' + k + ')').test(fmt)) { + for (let k in o) { + const regx = new RegExp('(' + k + ')') + if (regx.test(fmt)) { + const t = regx.exec(fmt)[1] fmt = fmt.replace( - RegExp.$1, - RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length) + t, + t.length === 1 ? o[k] : ('00' + o[k]).substring(('' + o[k]).length) ) } } From 4671013ea6bce077654965a5dc3f46931af61354 Mon Sep 17 00:00:00 2001 From: pixelmaxQM Date: Sun, 17 Nov 2024 11:58:56 +0800 Subject: [PATCH 09/28] =?UTF-8?q?fix:=20=E8=87=AA=E5=8A=A8=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=9B=9E=E6=BB=9A=E5=90=8E=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E5=A4=8D=E7=94=A8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/system/auto_code_history.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/service/system/auto_code_history.go b/server/service/system/auto_code_history.go index 399f1a973..d9d16760f 100644 --- a/server/service/system/auto_code_history.go +++ b/server/service/system/auto_code_history.go @@ -54,7 +54,7 @@ func (s *autoCodeHistory) First(ctx context.Context, info common.GetById) (strin // Author [songzhibin97](https://github.com/songzhibin97) func (s *autoCodeHistory) Repeat(businessDB, structName, abbreviation, Package string) bool { var count int64 - global.GVA_DB.Model(&model.SysAutoCodeHistory{}).Where("business_db = ? and (struct_name = ? OR abbreviation = ?) and package = ?", businessDB, structName, abbreviation, Package).Count(&count).Debug() + global.GVA_DB.Model(&model.SysAutoCodeHistory{}).Where("business_db = ? and (struct_name = ? OR abbreviation = ?) and package = ? and flag = ?", businessDB, structName, abbreviation, Package, 0).Count(&count).Debug() return count > 0 } From 8073e989f515ac9bf190a7137a7e5d9921ddadf5 Mon Sep 17 00:00:00 2001 From: zayn <972858472@qq.com> Date: Mon, 18 Nov 2024 02:07:38 -0800 Subject: [PATCH 10/28] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=B8=8D=E9=87=8D?= =?UTF-8?q?=E7=BD=AEpageSize=20(#1940)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 查询不重置pageSize --- server/resource/package/web/view/table.vue.tpl | 1 - server/resource/plugin/web/view/view.vue.template | 1 - web/src/plugin/announcement/view/info.vue | 1 - web/src/view/superAdmin/api/api.vue | 1 - web/src/view/superAdmin/operation/sysOperationRecord.vue | 1 - web/src/view/superAdmin/params/sysParams.vue | 1 - web/src/view/systemTools/exportTemplate/exportTemplate.vue | 1 - 7 files changed, 7 deletions(-) diff --git a/server/resource/package/web/view/table.vue.tpl b/server/resource/package/web/view/table.vue.tpl index cf65ed2e2..7b4ca4199 100644 --- a/server/resource/package/web/view/table.vue.tpl +++ b/server/resource/package/web/view/table.vue.tpl @@ -1010,7 +1010,6 @@ const onSubmit = () => { elSearchFormRef.value?.validate(async(valid) => { if (!valid) return page.value = 1 - pageSize.value = 10 {{- range .Fields}}{{- if eq .FieldType "bool" }} if (searchInfo.value.{{.FieldJson}} === ""){ searchInfo.value.{{.FieldJson}}=null diff --git a/server/resource/plugin/web/view/view.vue.template b/server/resource/plugin/web/view/view.vue.template index b76fdd8ec..eb43bfaa7 100644 --- a/server/resource/plugin/web/view/view.vue.template +++ b/server/resource/plugin/web/view/view.vue.template @@ -1010,7 +1010,6 @@ const onSubmit = () => { elSearchFormRef.value?.validate(async(valid) => { if (!valid) return page.value = 1 - pageSize.value = 10 {{- range .Fields}}{{- if eq .FieldType "bool" }} if (searchInfo.value.{{.FieldJson}} === ""){ searchInfo.value.{{.FieldJson}}=null diff --git a/web/src/plugin/announcement/view/info.vue b/web/src/plugin/announcement/view/info.vue index 7c317d409..a684e9770 100644 --- a/web/src/plugin/announcement/view/info.vue +++ b/web/src/plugin/announcement/view/info.vue @@ -322,7 +322,6 @@ elSearchFormRef.value?.validate(async (valid) => { if (!valid) return page.value = 1 - pageSize.value = 10 getTableData() }) } diff --git a/web/src/view/superAdmin/api/api.vue b/web/src/view/superAdmin/api/api.vue index af9318e52..70bb0b583 100644 --- a/web/src/view/superAdmin/api/api.vue +++ b/web/src/view/superAdmin/api/api.vue @@ -579,7 +579,6 @@ const onSubmit = () => { page.value = 1 - pageSize.value = 10 getTableData() } diff --git a/web/src/view/superAdmin/operation/sysOperationRecord.vue b/web/src/view/superAdmin/operation/sysOperationRecord.vue index 90300413c..27764c121 100644 --- a/web/src/view/superAdmin/operation/sysOperationRecord.vue +++ b/web/src/view/superAdmin/operation/sysOperationRecord.vue @@ -160,7 +160,6 @@ // 条件搜索前端看此方法 const onSubmit = () => { page.value = 1 - pageSize.value = 10 if (searchInfo.value.status === '') { searchInfo.value.status = null } diff --git a/web/src/view/superAdmin/params/sysParams.vue b/web/src/view/superAdmin/params/sysParams.vue index c84ae9ad3..1feeda1e6 100644 --- a/web/src/view/superAdmin/params/sysParams.vue +++ b/web/src/view/superAdmin/params/sysParams.vue @@ -406,7 +406,6 @@ elSearchFormRef.value?.validate(async (valid) => { if (!valid) return page.value = 1 - pageSize.value = 10 getTableData() }) } diff --git a/web/src/view/systemTools/exportTemplate/exportTemplate.vue b/web/src/view/systemTools/exportTemplate/exportTemplate.vue index 74dc9be0c..f4ab74a6e 100644 --- a/web/src/view/systemTools/exportTemplate/exportTemplate.vue +++ b/web/src/view/systemTools/exportTemplate/exportTemplate.vue @@ -739,7 +739,6 @@ JOINS模式下不支持导入 elSearchFormRef.value?.validate(async (valid) => { if (!valid) return page.value = 1 - pageSize.value = 10 getTableData() }) } From c909d32c56abf404924f9ff99e1b0694edfe3f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?PiexlMax=28=E5=A5=87=E6=B7=BC?= <165128580+pixelmaxQm@users.noreply.github.com> Date: Tue, 19 Nov 2024 16:31:43 +0800 Subject: [PATCH 11/28] =?UTF-8?q?fix:=20=E6=97=A0=E6=B3=95=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96=E6=96=B0=E5=A2=9E=E5=AD=97=E6=AE=B5=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/system/auto_code_template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/service/system/auto_code_template.go b/server/service/system/auto_code_template.go index f35526389..8d52e3172 100644 --- a/server/service/system/auto_code_template.go +++ b/server/service/system/auto_code_template.go @@ -191,7 +191,7 @@ func (s *autoCodeTemplate) Preview(ctx context.Context, info request.AutoCode) ( return nil, errors.Wrap(err, "查询包失败!") } // 增加判断: 重复创建struct 或者重复的简称 - if AutocodeHistory.Repeat(info.BusinessDB, info.StructName, info.Abbreviation, info.Package) { + if AutocodeHistory.Repeat(info.BusinessDB, info.StructName, info.Abbreviation, info.Package) && !info.IsAdd { return nil, errors.New("已经创建过此数据结构或重复简称,请勿重复创建!") } From 39212666c5843ca56ad4e73bcf852314e95b3d5c Mon Sep 17 00:00:00 2001 From: pixelmaxQM Date: Thu, 21 Nov 2024 20:00:14 +0800 Subject: [PATCH 12/28] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=9C=A8baseApi=E9=85=8D=E7=BD=AE=E4=B8=BA/=E6=97=B6?= =?UTF-8?q?=E5=80=99=E7=9A=84=E8=B7=AF=E5=BE=84=E6=8B=BC=E6=8E=A5=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/exportExcel/exportExcel.vue | 8 +++++++- web/src/components/exportExcel/exportTemplate.vue | 5 ++++- web/src/components/exportExcel/importExcel.vue | 5 ++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/web/src/components/exportExcel/exportExcel.vue b/web/src/components/exportExcel/exportExcel.vue index bad794f35..23f380605 100644 --- a/web/src/components/exportExcel/exportExcel.vue +++ b/web/src/components/exportExcel/exportExcel.vue @@ -5,6 +5,8 @@ -{{- end}} -{{- end}} +{{- end }} + +{{- end }} diff --git a/server/service/example/exa_breakpoint_continue.go b/server/service/example/exa_breakpoint_continue.go index d0363bb5d..d2a85a338 100644 --- a/server/service/example/exa_breakpoint_continue.go +++ b/server/service/example/exa_breakpoint_continue.go @@ -58,7 +58,7 @@ func (e *FileUploadAndDownloadService) CreateFileChunk(id uint, fileChunkPath st func (e *FileUploadAndDownloadService) DeleteFileChunk(fileMd5 string, filePath string) error { var chunks []example.ExaFileChunk var file example.ExaFile - err := global.GVA_DB.Where("file_md5 = ? ", fileMd5).First(&file). + err := global.GVA_DB.Where("file_md5 = ?", fileMd5).First(&file). Updates(map[string]interface{}{ "IsFinish": true, "file_path": filePath, diff --git a/server/service/system/sys_casbin.go b/server/service/system/sys_casbin.go index 32edc579e..3a315efba 100644 --- a/server/service/system/sys_casbin.go +++ b/server/service/system/sys_casbin.go @@ -169,8 +169,8 @@ func (casbinService *CasbinService) AddPolicies(db *gorm.DB, rules [][]string) e return db.Create(&casbinRules).Error } -func (CasbinService *CasbinService) FreshCasbin() (err error) { - e := CasbinService.Casbin() +func (casbinService *CasbinService) FreshCasbin() (err error) { + e := casbinService.Casbin() err = e.LoadPolicy() return err } diff --git a/server/service/system/sys_initdb_pgsql.go b/server/service/system/sys_initdb_pgsql.go index f1a482f0c..468fadd37 100644 --- a/server/service/system/sys_initdb_pgsql.go +++ b/server/service/system/sys_initdb_pgsql.go @@ -54,7 +54,12 @@ func (h PgsqlInitHandler) EnsureDB(ctx context.Context, conf *request.InitDB) (n } // 如果没有数据库名, 则跳出初始化数据 dsn := conf.PgsqlEmptyDsn() - createSql := fmt.Sprintf("CREATE DATABASE %s;", c.Dbname) + var createSql string + if conf.Template != "" { + createSql = fmt.Sprintf("CREATE DATABASE %s WITH TEMPLATE %s;", c.Dbname, conf.Template) + } else { + createSql = fmt.Sprintf("CREATE DATABASE %s;", c.Dbname) + } if err = createDatabase(dsn, "pgx", createSql); err != nil { return nil, err } // 创建数据库 diff --git a/server/source/example/file_upload_download.go b/server/source/example/file_upload_download.go index f39dcf2e5..0f6f7a7fa 100644 --- a/server/source/example/file_upload_download.go +++ b/server/source/example/file_upload_download.go @@ -33,7 +33,7 @@ func (i *initExaFileMysql) TableCreated(ctx context.Context) bool { return db.Migrator().HasTable(&example.ExaFileUploadAndDownload{}) } -func (i initExaFileMysql) InitializerName() string { +func (i *initExaFileMysql) InitializerName() string { return example.ExaFileUploadAndDownload{}.TableName() } diff --git a/server/source/system/api.go b/server/source/system/api.go index 3dc211d00..e657f34f5 100644 --- a/server/source/system/api.go +++ b/server/source/system/api.go @@ -17,7 +17,7 @@ func init() { system.RegisterInit(initOrderApi, &initApi{}) } -func (i initApi) InitializerName() string { +func (i *initApi) InitializerName() string { return sysModel.SysApi{}.TableName() } diff --git a/server/source/system/api_ignore.go b/server/source/system/api_ignore.go index 284a1cc0c..c0fab5650 100644 --- a/server/source/system/api_ignore.go +++ b/server/source/system/api_ignore.go @@ -17,7 +17,7 @@ func init() { system.RegisterInit(initOrderApiIgnore, &initApiIgnore{}) } -func (i initApiIgnore) InitializerName() string { +func (i *initApiIgnore) InitializerName() string { return sysModel.SysIgnoreApi{}.TableName() } diff --git a/server/source/system/authorities_menus.go b/server/source/system/authorities_menus.go index 1c9058b88..e6799bc33 100644 --- a/server/source/system/authorities_menus.go +++ b/server/source/system/authorities_menus.go @@ -26,7 +26,7 @@ func (i *initMenuAuthority) TableCreated(ctx context.Context) bool { return false // always replace } -func (i initMenuAuthority) InitializerName() string { +func (i *initMenuAuthority) InitializerName() string { return "sys_menu_authorities" } @@ -35,11 +35,12 @@ func (i *initMenuAuthority) InitializeData(ctx context.Context) (next context.Co if !ok { return ctx, system.ErrMissingDBContext } - authorities, ok := ctx.Value(initAuthority{}.InitializerName()).([]sysModel.SysAuthority) + initAuth := &initAuthority{} + authorities, ok := ctx.Value(initAuth.InitializerName()).([]sysModel.SysAuthority) if !ok { return ctx, errors.Wrap(system.ErrMissingDependentContext, "创建 [菜单-权限] 关联失败, 未找到权限表初始化数据") } - menus, ok := ctx.Value(initMenu{}.InitializerName()).([]sysModel.SysBaseMenu) + menus, ok := ctx.Value(new(initMenu).InitializerName()).([]sysModel.SysBaseMenu) if !ok { return next, errors.Wrap(errors.New(""), "创建 [菜单-权限] 关联失败, 未找到菜单表初始化数据") } diff --git a/server/source/system/authority.go b/server/source/system/authority.go index 0426f2a4f..1157a1922 100644 --- a/server/source/system/authority.go +++ b/server/source/system/authority.go @@ -34,7 +34,7 @@ func (i *initAuthority) TableCreated(ctx context.Context) bool { return db.Migrator().HasTable(&sysModel.SysAuthority{}) } -func (i initAuthority) InitializerName() string { +func (i *initAuthority) InitializerName() string { return sysModel.SysAuthority{}.TableName() } diff --git a/server/source/system/casbin.go b/server/source/system/casbin.go index 5a9cdbec1..c4528336d 100644 --- a/server/source/system/casbin.go +++ b/server/source/system/casbin.go @@ -34,7 +34,7 @@ func (i *initCasbin) TableCreated(ctx context.Context) bool { return db.Migrator().HasTable(&adapter.CasbinRule{}) } -func (i initCasbin) InitializerName() string { +func (i *initCasbin) InitializerName() string { var entity adapter.CasbinRule return entity.TableName() } diff --git a/server/source/system/dictionary.go b/server/source/system/dictionary.go index 001496327..a0cf8e0cb 100644 --- a/server/source/system/dictionary.go +++ b/server/source/system/dictionary.go @@ -33,7 +33,7 @@ func (i *initDict) TableCreated(ctx context.Context) bool { return db.Migrator().HasTable(&sysModel.SysDictionary{}) } -func (i initDict) InitializerName() string { +func (i *initDict) InitializerName() string { return sysModel.SysDictionary{}.TableName() } diff --git a/server/source/system/dictionary_detail.go b/server/source/system/dictionary_detail.go index 3dea8b70f..938cbc23e 100644 --- a/server/source/system/dictionary_detail.go +++ b/server/source/system/dictionary_detail.go @@ -34,7 +34,7 @@ func (i *initDictDetail) TableCreated(ctx context.Context) bool { return db.Migrator().HasTable(&sysModel.SysDictionaryDetail{}) } -func (i initDictDetail) InitializerName() string { +func (i *initDictDetail) InitializerName() string { return sysModel.SysDictionaryDetail{}.TableName() } @@ -43,7 +43,7 @@ func (i *initDictDetail) InitializeData(ctx context.Context) (context.Context, e if !ok { return ctx, system.ErrMissingDBContext } - dicts, ok := ctx.Value(initDict{}.InitializerName()).([]sysModel.SysDictionary) + dicts, ok := ctx.Value(new(initDict).InitializerName()).([]sysModel.SysDictionary) if !ok { return ctx, errors.Wrap(system.ErrMissingDependentContext, fmt.Sprintf("未找到 %s 表初始化数据", sysModel.SysDictionary{}.TableName())) diff --git a/server/source/system/excel_template.go b/server/source/system/excel_template.go index 00f3ed5f1..20bf16dd4 100644 --- a/server/source/system/excel_template.go +++ b/server/source/system/excel_template.go @@ -17,7 +17,7 @@ func init() { system.RegisterInit(initOrderExcelTemplate, &initExcelTemplate{}) } -func (i initExcelTemplate) InitializerName() string { +func (i *initExcelTemplate) InitializerName() string { return "sys_export_templates" } diff --git a/server/source/system/menu.go b/server/source/system/menu.go index 5b8ff0bdf..30b177fde 100644 --- a/server/source/system/menu.go +++ b/server/source/system/menu.go @@ -18,7 +18,7 @@ func init() { system.RegisterInit(initOrderMenu, &initMenu{}) } -func (i initMenu) InitializerName() string { +func (i *initMenu) InitializerName() string { return SysBaseMenu{}.TableName() } diff --git a/server/source/system/user.go b/server/source/system/user.go index b51c2fd44..eb9ddfc47 100644 --- a/server/source/system/user.go +++ b/server/source/system/user.go @@ -35,7 +35,7 @@ func (i *initUser) TableCreated(ctx context.Context) bool { return db.Migrator().HasTable(&sysModel.SysUser{}) } -func (i initUser) InitializerName() string { +func (i *initUser) InitializerName() string { return sysModel.SysUser{}.TableName() } @@ -79,7 +79,7 @@ func (i *initUser) InitializeData(ctx context.Context) (next context.Context, er return ctx, errors.Wrap(err, sysModel.SysUser{}.TableName()+"表数据初始化失败!") } next = context.WithValue(ctx, i.InitializerName(), entities) - authorityEntities, ok := ctx.Value(initAuthority{}.InitializerName()).([]sysModel.SysAuthority) + authorityEntities, ok := ctx.Value(new(initAuthority).InitializerName()).([]sysModel.SysAuthority) if !ok { return next, errors.Wrap(system.ErrMissingDependentContext, "创建 [用户-权限] 关联失败, 未找到权限表初始化数据") } diff --git a/server/utils/ast/ast.go b/server/utils/ast/ast.go index b6f85d6d0..1cdfa4c1e 100644 --- a/server/utils/ast/ast.go +++ b/server/utils/ast/ast.go @@ -158,7 +158,7 @@ func CreateApiStructAst(apis []system.SysApi) *[]ast.Expr { return &apiElts } -// 检查是否存在Import +// CheckImport 检查是否存在Import func CheckImport(file *ast.File, importPath string) bool { for _, imp := range file.Imports { // Remove quotes around the import path diff --git a/server/utils/ast/ast_gorm.go b/server/utils/ast/ast_gorm.go index d9c1beb3e..4340721fe 100644 --- a/server/utils/ast/ast_gorm.go +++ b/server/utils/ast/ast_gorm.go @@ -10,7 +10,7 @@ import ( "os" ) -// 自动为 gorm.go 注册一个自动迁移 +// AddRegisterTablesAst 自动为 gorm.go 注册一个自动迁移 func AddRegisterTablesAst(path, funcName, pk, varName, dbName, model string) { modelPk := fmt.Sprintf("github.com/flipped-aurora/gin-vue-admin/server/model/%s", pk) src, err := os.ReadFile(path) @@ -147,7 +147,7 @@ func addAutoMigrate(astBody *ast.BlockStmt, dbname string, pk string, model stri } } -// 为automigrate增加实参 +// NeedAppendModel 为automigrate增加实参 func NeedAppendModel(callNode ast.Node, pk string, model string) bool { flag := true ast.Inspect(callNode, func(node ast.Node) bool { diff --git a/server/utils/fmt_plus.go b/server/utils/fmt_plus.go index 8b77d4f26..6f34cb47c 100644 --- a/server/utils/fmt_plus.go +++ b/server/utils/fmt_plus.go @@ -2,6 +2,7 @@ package utils import ( "fmt" + "github.com/flipped-aurora/gin-vue-admin/server/model/common" "math/rand" "reflect" "strings" @@ -67,7 +68,7 @@ func MaheHump(s string) string { return strings.Join(words, "") } -// 随机字符串 +// RandomString 随机字符串 func RandomString(n int) string { var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") b := make([]rune, n) @@ -80,3 +81,28 @@ func RandomString(n int) string { func RandomInt(min, max int) int { return min + rand.Intn(max-min) } + +// BuildTree 用于构建一个树形结构 +func BuildTree[T common.TreeNode[T]](nodes []T) []T { + nodeMap := make(map[int]T) + // 创建一个基本map + for i := range nodes { + nodeMap[nodes[i].GetID()] = nodes[i] + } + + for i := range nodes { + if nodes[i].GetParentID() != 0 { + parent := nodeMap[nodes[i].GetParentID()] + parent.SetChildren(nodes[i]) + } + } + + var rootNodes []T + + for i := range nodeMap { + if nodeMap[i].GetParentID() == 0 { + rootNodes = append(rootNodes, nodeMap[i]) + } + } + return rootNodes +} diff --git a/server/utils/jwt.go b/server/utils/jwt.go index c1298a870..e8eb9721d 100644 --- a/server/utils/jwt.go +++ b/server/utils/jwt.go @@ -43,7 +43,7 @@ func (j *JWT) CreateClaims(baseClaims request.BaseClaims) request.CustomClaims { return claims } -// 创建一个token +// CreateToken 创建一个token func (j *JWT) CreateToken(claims request.CustomClaims) (string, error) { token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) return token.SignedString(j.SigningKey) @@ -57,7 +57,7 @@ func (j *JWT) CreateTokenByOldToken(oldToken string, claims request.CustomClaims return v.(string), err } -// 解析 token +// ParseToken 解析 token func (j *JWT) ParseToken(tokenString string) (*request.CustomClaims, error) { token, err := jwt.ParseWithClaims(tokenString, &request.CustomClaims{}, func(token *jwt.Token) (i interface{}, e error) { return j.SigningKey, nil diff --git a/server/utils/timer/timed_task.go b/server/utils/timer/timed_task.go index 9f761436f..06865d25d 100644 --- a/server/utils/timer/timed_task.go +++ b/server/utils/timer/timed_task.go @@ -72,7 +72,7 @@ func (t *timer) AddTaskByFunc(cronName string, spec string, fun func(), taskName return id, err } -// AddTaskByFuncWithSeconds 通过函数的方法使用WithSeconds添加任务 +// AddTaskByFuncWithSecond 通过函数的方法使用WithSeconds添加任务 func (t *timer) AddTaskByFuncWithSecond(cronName string, spec string, fun func(), taskName string, option ...cron.Option) (cron.EntryID, error) { t.Lock() defer t.Unlock() @@ -186,7 +186,7 @@ func (t *timer) StopCron(cronName string) { } } -// Remove 从cronName 删除指定任务 +// RemoveTask 从cronName 删除指定任务 func (t *timer) RemoveTask(cronName string, id int) { t.Lock() defer t.Unlock() diff --git a/web/package.json b/web/package.json index a12994ac0..02180cbb3 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "gin-vue-admin", - "version": "2.7.7", + "version": "2.7.8-beta1", "private": true, "scripts": { "serve": "node openDocument.js && vite --host --mode development", @@ -17,6 +17,7 @@ "@vue-office/excel": "^1.7.11", "@vue-office/pdf": "^2.0.2", "@vueuse/core": "^11.0.3", + "@vueuse/integrations": "^12.0.0", "@wangeditor/editor": "^5.1.23", "@wangeditor/editor-for-vue": "^5.1.12", "ace-builds": "^1.36.4", @@ -27,7 +28,6 @@ "echarts": "5.5.1", "element-plus": "^2.8.5", "highlight.js": "^11.10.0", - "js-cookie": "^3.0.5", "marked": "14.1.1", "marked-highlight": "^2.1.4", "mitt": "^3.0.1", @@ -39,6 +39,7 @@ "sortablejs": "^1.15.3", "spark-md5": "^3.0.2", "tailwindcss": "^3.4.10", + "universal-cookie": "^7", "vform3-builds": "^3.0.10", "vite-auto-import-svg": "^1.1.0", "vue": "^3.5.7", diff --git a/web/src/components/commandMenu/index.vue b/web/src/components/commandMenu/index.vue index 3d3b72395..eb403d4a1 100644 --- a/web/src/components/commandMenu/index.vue +++ b/web/src/components/commandMenu/index.vue @@ -90,11 +90,11 @@ const quickArr = [ { label: '亮色主题', - func: () => changeMode('light') + func: () => changeMode(false) }, { label: '暗色主题', - func: () => changeMode('dark') + func: () => changeMode(true) }, { label: '退出登录', @@ -135,12 +135,8 @@ dialogVisible.value = false } - const changeMode = (e) => { - if (e === null) { - appStore.toggleTheme(false) - return - } - appStore.toggleTheme(true) + const changeMode = (darkMode) => { + appStore.toggleTheme(darkMode) } const close = () => { diff --git a/web/src/components/selectImage/selectImage.vue b/web/src/components/selectImage/selectImage.vue index 2c08d88e5..d8960254f 100644 --- a/web/src/components/selectImage/selectImage.vue +++ b/web/src/components/selectImage/selectImage.vue @@ -23,7 +23,7 @@ /> - +
@@ -124,6 +124,9 @@ import { ElMessage, ElMessageBox } from 'element-plus' import { Picture as IconPicture } from '@element-plus/icons-vue' import selectComponent from '@/components/selectImage/selectComponent.vue' + import { useAppStore } from "@/pinia"; + + const appStore = useAppStore() const imageUrl = ref('') const imageCommon = ref('') diff --git a/web/src/core/config.js b/web/src/core/config.js index 847b68dc9..9a03f26b0 100644 --- a/web/src/core/config.js +++ b/web/src/core/config.js @@ -17,7 +17,7 @@ export const viteLogo = (env) => { `> 欢迎使用Gin-Vue-Admin,开源地址:https://github.com/flipped-aurora/gin-vue-admin` ) ) - console.log(greenText(`> 当前版本:v2.7.7`)) + console.log(greenText(`> 当前版本:vv2.7.8-beta1`)) console.log(greenText(`> 加群方式:微信:shouzi_1994 QQ群:470239250`)) console.log( greenText(`> 项目地址:https://github.com/flipped-aurora/gin-vue-admin`) diff --git a/web/src/core/gin-vue-admin.js b/web/src/core/gin-vue-admin.js index 615ed30e5..ae71f1b7f 100644 --- a/web/src/core/gin-vue-admin.js +++ b/web/src/core/gin-vue-admin.js @@ -10,7 +10,7 @@ export default { register(app) console.log(` 欢迎使用 Gin-Vue-Admin - 当前版本:v2.7.7 + 当前版本:v2.7.8-beta1 加群方式:微信:shouzi_1994 QQ群:622360840 项目地址:https://github.com/flipped-aurora/gin-vue-admin 插件市场:https://plugin.gin-vue-admin.com diff --git a/web/src/hooks/charts.js b/web/src/hooks/charts.js index 9f03b0e6a..b7f7bb3bb 100644 --- a/web/src/hooks/charts.js +++ b/web/src/hooks/charts.js @@ -7,7 +7,7 @@ import { useAppStore } from '@/pinia' export default function useChartOption(sourceOption) { const appStore = useAppStore() const isDark = computed(() => { - return appStore.theme === 'dark' + return appStore.isDark }) const chartOption = computed(() => { return sourceOption(isDark.value) diff --git a/web/src/pathInfo.json b/web/src/pathInfo.json index 889d02a33..e08798c04 100644 --- a/web/src/pathInfo.json +++ b/web/src/pathInfo.json @@ -64,4 +64,4 @@ "/src/plugin/announcement/form/info.vue": "InfoForm", "/src/plugin/announcement/view/info.vue": "Info", "/src/plugin/email/view/index.vue": "Email" -} +} \ No newline at end of file diff --git a/web/src/pinia/modules/app.js b/web/src/pinia/modules/app.js index 2a37f4d4d..45b22227a 100644 --- a/web/src/pinia/modules/app.js +++ b/web/src/pinia/modules/app.js @@ -1,8 +1,12 @@ import { defineStore } from 'pinia' import { ref, watchEffect, reactive } from 'vue' import { setBodyPrimaryColor } from '@/utils/format' +import { useDark, usePreferredDark } from '@vueuse/core' + export const useAppStore = defineStore('app', () => { const device = ref('') + const drawerSize = ref('') + const operateMinWith = ref('240') const config = reactive({ weakness: false, grey: false, @@ -16,14 +20,17 @@ export const useAppStore = defineStore('app', () => { side_mode: 'normal' }) - const theme = ref('auto') + const isDark = useDark({ + selector: 'html', + attribute: 'class', + valueDark: 'dark', + valueLight: 'light', + }) - const toggleTheme = (dark) => { - if (dark) { - theme.value = 'dark' - } else { - theme.value = 'light' - } + const preferredDark = usePreferredDark() + + const toggleTheme = (darkMode) => { + isDark.value = darkMode } const toggleWeakness = (e) => { @@ -43,6 +50,13 @@ export const useAppStore = defineStore('app', () => { } const toggleDevice = (e) => { + if(e === 'mobile'){ + drawerSize.value = '100%' + operateMinWith.value = '80' + }else { + drawerSize.value = '800' + operateMinWith.value = '240' + } device.value = e } @@ -50,15 +64,14 @@ export const useAppStore = defineStore('app', () => { config.darkMode = e } - const toggleDarkModeAuto = () => { - // 处理浏览器主题 - const darkQuery = window.matchMedia('(prefers-color-scheme: dark)') - const dark = darkQuery.matches - toggleTheme(dark) - darkQuery.addEventListener('change', (e) => { - toggleTheme(e.matches) - }) - } + // 监听系统主题变化 + watchEffect(() => { + if (config.darkMode === 'auto') { + isDark.value = preferredDark.value + return + } + isDark.value = config.darkMode === 'dark' + }) const toggleConfigSideWidth = (e) => { config.layout_side_width = e @@ -76,55 +89,26 @@ export const useAppStore = defineStore('app', () => { config.show_watermark = e } - const toggleSideModel = (e) => { + const toggleSideMode = (e) => { config.side_mode = e } + // 监听色弱模式和灰色模式 watchEffect(() => { - if (theme.value === 'dark') { - document.documentElement.classList.add('dark') - document.documentElement.classList.remove('light') - } else { - document.documentElement.classList.add('light') - document.documentElement.classList.remove('dark') - } - }) - watchEffect(() => { - // 色弱模式监听处理 - if (config.weakness) { - document.documentElement.classList.add('html-weakenss') - } else { - document.documentElement.classList.remove('html-weakenss') - } - }) - watchEffect(() => { - // 灰色模式监听处理 - if (config.grey) { - document.documentElement.classList.add('html-grey') - } else { - document.documentElement.classList.remove('html-grey') - } + document.documentElement.classList.toggle('html-weakenss', config.weakness) + document.documentElement.classList.toggle('html-grey', config.grey) }) + // 监听主题色 watchEffect(() => { - if (config.darkMode === 'auto') { - toggleDarkModeAuto() - } - - if (config.darkMode === 'dark') { - toggleTheme(true) - } else { - toggleTheme(false) - } - }) - - watchEffect(() => { - setBodyPrimaryColor(config.primaryColor, theme.value) + setBodyPrimaryColor(config.primaryColor, isDark.value ? 'dark' : 'light') }) return { - theme, + isDark, device, + drawerSize, + operateMinWith, config, toggleTheme, toggleDevice, @@ -137,6 +121,6 @@ export const useAppStore = defineStore('app', () => { toggleConfigSideCollapsedWidth, toggleConfigSideItemHeight, toggleConfigWatermark, - toggleSideModel + toggleSideMode } }) diff --git a/web/src/pinia/modules/user.js b/web/src/pinia/modules/user.js index 82d1cb08e..2bcb7257b 100644 --- a/web/src/pinia/modules/user.js +++ b/web/src/pinia/modules/user.js @@ -3,9 +3,10 @@ import { jsonInBlacklist } from '@/api/jwt' import router from '@/router/index' import { ElLoading, ElMessage } from 'element-plus' import { defineStore } from 'pinia' -import { ref, watch } from 'vue' +import { ref, computed } from 'vue' import { useRouterStore } from './router' -import cookie from 'js-cookie' +import { useCookies } from '@vueuse/integrations/useCookies' +import { useStorage } from '@vueuse/core' import { useAppStore } from '@/pinia' @@ -19,9 +20,10 @@ export const useUserStore = defineStore('user', () => { headerImg: '', authority: {} }) - const token = ref( - window.localStorage.getItem('token') || cookie.get('x-token') || '' - ) + const token = useStorage('token', '') + const xToken = useCookies('x-token') + const currentToken = computed(() => token.value || xToken.value || '') + const setUserInfo = (val) => { userInfo.value = val if (val.originSetting) { @@ -33,11 +35,11 @@ export const useUserStore = defineStore('user', () => { const setToken = (val) => { token.value = val + xToken.value = val } const NeedInit = async () => { - token.value = '' - window.localStorage.removeItem('token') + await ClearStorage() await router.push({ name: 'Init', replace: true }) } @@ -57,49 +59,49 @@ export const useUserStore = defineStore('user', () => { } /* 登录*/ const LoginIn = async (loginInfo) => { - loadingInstance.value = ElLoading.service({ - fullscreen: true, - text: '登录中,请稍候...' - }) + try { + loadingInstance.value = ElLoading.service({ + fullscreen: true, + text: '登录中,请稍候...' + }) - const res = await login(loginInfo) + const res = await login(loginInfo) + + if (res.code !== 0) { + ElMessage.error(res.message || '登录失败') + return false + } + // 登陆成功,设置用户信息和权限相关信息 + setUserInfo(res.data.user) + setToken(res.data.token) - // 登陆失败,直接返回 - if (res.code !== 0) { - loadingInstance.value.close() + // 初始化路由信息 + const routerStore = useRouterStore() + await routerStore.SetAsyncRouter() + const asyncRouters = routerStore.asyncRouters + + // 注册到路由表里 + asyncRouters.forEach((asyncRouter) => { + router.addRoute(asyncRouter) + }) + + if (!router.hasRoute(userInfo.value.authority.defaultRouter)) { + ElMessage.error('请联系管理员进行授权') + } else { + await router.replace({ name: userInfo.value.authority.defaultRouter }) + } + + const isWindows = /windows/i.test(navigator.userAgent) + window.localStorage.setItem('osType', isWindows ? 'WIN' : 'MAC') + + // 全部操作均结束,关闭loading并返回 + return true + } catch (error) { + console.error('LoginIn error:', error) return false + } finally { + loadingInstance.value?.close() } - - // 登陆成功,设置用户信息和权限相关信息 - setUserInfo(res.data.user) - setToken(res.data.token) - - // 初始化路由信息 - const routerStore = useRouterStore() - await routerStore.SetAsyncRouter() - const asyncRouters = routerStore.asyncRouters - - // 注册到路由表里 - asyncRouters.forEach((asyncRouter) => { - router.addRoute(asyncRouter) - }) - - if (!router.hasRoute(userInfo.value.authority.defaultRouter)) { - ElMessage.error('请联系管理员进行授权') - } else { - await router.replace({ name: userInfo.value.authority.defaultRouter }) - } - - const isWin = ref(/windows/i.test(navigator.userAgent)) - if (isWin.value) { - window.localStorage.setItem('osType', 'WIN') - } else { - window.localStorage.setItem('osType', 'MAC') - } - - // 全部操作均结束,关闭loading并返回 - loadingInstance.value.close() - return true } /* 登出*/ const LoginOut = async () => { @@ -119,22 +121,14 @@ export const useUserStore = defineStore('user', () => { /* 清理数据 */ const ClearStorage = async () => { token.value = '' + xToken.value = '' sessionStorage.clear() - window.localStorage.removeItem('token') - cookie.remove('x-token') localStorage.removeItem('originSetting') } - watch( - () => token.value, - () => { - window.localStorage.setItem('token', token.value) - } - ) - return { userInfo, - token, + token: currentToken, NeedInit, ResetUserInfo, GetUserInfo, diff --git a/web/src/view/dashboard/components/charts-content-numbers.vue b/web/src/view/dashboard/components/charts-content-numbers.vue index 950b3b416..4d7fb9e85 100644 --- a/web/src/view/dashboard/components/charts-content-numbers.vue +++ b/web/src/view/dashboard/components/charts-content-numbers.vue @@ -25,8 +25,7 @@ } }) const dotColor = computed(() => { - console.log(appStore.theme) - return appStore.theme === 'dark' ? '#333' : '#E5E8EF' + return appStore.isDark ? '#333' : '#E5E8EF' }) const graphicFactory = (side) => { return { diff --git a/web/src/view/init/index.vue b/web/src/view/init/index.vue index c8b0155cf..211ec4a88 100644 --- a/web/src/view/init/index.vue +++ b/web/src/view/init/index.vue @@ -111,6 +111,12 @@ placeholder="请输入sqlite数据库文件存放路径" /> + + +
立即初始化 @@ -192,7 +198,8 @@ userName: 'postgres', password: '', dbName: 'gva', - dbPath: '' + dbPath: '', + template: 'template0' }) break case 'oracle': diff --git a/web/src/view/layout/header/index.vue b/web/src/view/layout/header/index.vue index 858d2c6fd..bf7b5be1c 100644 --- a/web/src/view/layout/header/index.vue +++ b/web/src/view/layout/header/index.vue @@ -9,7 +9,8 @@ >
diff --git a/web/src/view/layout/index.vue b/web/src/view/layout/index.vue index 12d93260c..c5d26fc8f 100644 --- a/web/src/view/layout/index.vue +++ b/web/src/view/layout/index.vue @@ -62,7 +62,7 @@ import { useAppStore } from '@/pinia' import { storeToRefs } from 'pinia' const appStore = useAppStore() - const { config, theme, device } = storeToRefs(appStore) + const { config, isDark, device } = storeToRefs(appStore) defineOptions({ name: 'GvaLayout' @@ -75,7 +75,7 @@ watchEffect(() => { font.color = - theme.value === 'dark' ? 'rgba(255,255,255, .15)' : 'rgba(0, 0, 0, .15)' + isDark.value ? 'rgba(255,255,255, .15)' : 'rgba(0, 0, 0, .15)' }) const router = useRouter() diff --git a/web/src/view/layout/setting/index.vue b/web/src/view/layout/setting/index.vue index c2ed06cee..2e5f5c795 100644 --- a/web/src/view/layout/setting/index.vue +++ b/web/src/view/layout/setting/index.vue @@ -71,7 +71,7 @@ v-model="config.side_mode" :options="sideModes" size="default" - @change="appStore.toggleSideModel" + @change="appStore.toggleSideMode" /> - +