diff --git a/mayfly_go_web/package.json b/mayfly_go_web/package.json index 53a22a50..ee438291 100644 --- a/mayfly_go_web/package.json +++ b/mayfly_go_web/package.json @@ -50,7 +50,7 @@ "sass": "^1.62.0", "sass-loader": "^13.2.0", "typescript": "^5.0.2", - "vite": "^4.4.2", + "vite": "^4.4.7", "vue-eslint-parser": "^9.1.1" }, "browserslist": [ diff --git a/mayfly_go_web/src/views/login/component/AccountLogin.vue b/mayfly_go_web/src/views/login/component/AccountLogin.vue index 5390991b..5fd35804 100644 --- a/mayfly_go_web/src/views/login/component/AccountLogin.vue +++ b/mayfly_go_web/src/views/login/component/AccountLogin.vue @@ -106,7 +106,7 @@ - + @@ -117,7 +117,6 @@ @@ -152,6 +151,7 @@ const loginFormRef: any = ref(null); const changePwdFormRef: any = ref(null); const otpFormRef: any = ref(null); const otpCodeInputRef: any = ref(null); +const baseInfoFormRef: any = ref(null); const state = reactive({ accountLoginSecurity: { @@ -301,12 +301,22 @@ const onSignIn = async () => { }; const updateUserInfo = async () => { - const form = state.baseInfoDialog.form; - await personApi.updateAccount.request(state.baseInfoDialog.form); - state.baseInfoDialog.visible = false; - useUserInfo().userInfo.username = form.username; - useUserInfo().userInfo.name = form.name; - await toIndex(); + baseInfoFormRef.value.validate(async (valid: boolean) => { + if (!valid) { + return false; + } + try { + state.loading.updateUserConfirm = true; + const form = state.baseInfoDialog.form; + await personApi.updateAccount.request(state.baseInfoDialog.form); + state.baseInfoDialog.visible = false; + useUserInfo().userInfo.username = form.username; + useUserInfo().userInfo.name = form.name; + await toIndex(); + } finally { + state.loading.updateUserConfirm = false; + } + }); }; const loginResDeal = (loginRes: any) => { diff --git a/mayfly_go_web/src/views/login/index.vue b/mayfly_go_web/src/views/login/index.vue index 7deca7ec..229365cd 100644 --- a/mayfly_go_web/src/views/login/index.vue +++ b/mayfly_go_web/src/views/login/index.vue @@ -18,9 +18,9 @@ --> -
+
第三方登录: - + @@ -50,13 +50,14 @@ const state = reactive({ tabsActiveName: 'account', isTabPaneShow: true, oauth2LoginConfig: { + name: 'OAuth2登录', enable: false, }, }); const loginForm = ref<{ loginResDeal: (data: any) => void } | null>(null); -const { isTabPaneShow, tabsActiveName, oauth2LoginConfig: authConfig } = toRefs(state); +const { isTabPaneShow, tabsActiveName, oauth2LoginConfig: oauth2LoginConfig } = toRefs(state); // 切换密码、手机登录 const onTabsClick = () => { diff --git a/mayfly_go_web/yarn.lock b/mayfly_go_web/yarn.lock index 772d80af..c4d66d7d 100644 --- a/mayfly_go_web/yarn.lock +++ b/mayfly_go_web/yarn.lock @@ -1575,10 +1575,10 @@ postcss@^8.1.10: picocolors "^1.0.0" source-map-js "^1.0.1" -postcss@^8.4.24: - version "8.4.25" - resolved "https://registry.npmmirror.com/postcss/-/postcss-8.4.25.tgz#4a133f5e379eda7f61e906c3b1aaa9b81292726f" - integrity sha512-7taJ/8t2av0Z+sQEvNzCkpDynl0tX3uJMCODi6nT3PfASC7dYCWV9aQ+uiCf+KBD4SEFcu+GvJdGdwzQ6OSjCw== +postcss@^8.4.26: + version "8.4.27" + resolved "https://registry.npmmirror.com/postcss/-/postcss-8.4.27.tgz#234d7e4b72e34ba5a92c29636734349e0d9c3057" + integrity sha512-gY/ACJtJPSmUFPDCHtX78+01fHa64FaU4zaaWfuh1MhGJISufJAH4cun6k/8fwsHYeK4UQmENQK+tRLCFJE8JQ== dependencies: nanoid "^3.3.6" picocolors "^1.0.0" @@ -1855,13 +1855,13 @@ uri-js@^4.2.2: dependencies: punycode "^2.1.0" -vite@^4.4.2: - version "4.4.2" - resolved "https://registry.npmmirror.com/vite/-/vite-4.4.2.tgz#acd47de771c498aec80e4900f30133d9529b278a" - integrity sha512-zUcsJN+UvdSyHhYa277UHhiJ3iq4hUBwHavOpsNUGsTgjBeoBlK8eDt+iT09pBq0h9/knhG/SPrZiM7cGmg7NA== +vite@^4.4.7: + version "4.4.7" + resolved "https://registry.npmmirror.com/vite/-/vite-4.4.7.tgz#71b8a37abaf8d50561aca084dbb77fa342824154" + integrity sha512-6pYf9QJ1mHylfVh39HpuSfMPojPSKVxZvnclX1K1FyZ1PXDOcLBibdq5t1qxJSnL63ca8Wf4zts6mD8u8oc9Fw== dependencies: esbuild "^0.18.10" - postcss "^8.4.24" + postcss "^8.4.26" rollup "^3.25.2" optionalDependencies: fsevents "~2.3.2" diff --git a/server/internal/constant/constant.go b/server/internal/common/consts/consts.go similarity index 95% rename from server/internal/constant/constant.go rename to server/internal/common/consts/consts.go index b0925b1e..c2ec1110 100644 --- a/server/internal/constant/constant.go +++ b/server/internal/common/consts/consts.go @@ -1,4 +1,4 @@ -package constant +package consts import "time" diff --git a/server/internal/db/application/db.go b/server/internal/db/application/db.go index cfd4c2c7..f6efd3bd 100644 --- a/server/internal/db/application/db.go +++ b/server/internal/db/application/db.go @@ -3,7 +3,7 @@ package application import ( "database/sql" "fmt" - "mayfly-go/internal/constant" + "mayfly-go/internal/common/consts" "mayfly-go/internal/db/domain/entity" "mayfly-go/internal/db/domain/repository" "mayfly-go/internal/machine/infrastructure/machine" @@ -294,7 +294,7 @@ func (d *DbInstance) Close() { //------------------------------------------------------------------------------ // 客户端连接缓存,指定时间内没有访问则会被关闭, key为数据库实例id:数据库 -var dbCache = cache.NewTimedCache(constant.DbConnExpireTime, 5*time.Second). +var dbCache = cache.NewTimedCache(consts.DbConnExpireTime, 5*time.Second). WithUpdateAccessTime(true). OnEvicted(func(key any, value any) { global.Log.Info(fmt.Sprintf("删除db连接缓存 id = %s", key)) diff --git a/server/internal/machine/infrastructure/machine/machine.go b/server/internal/machine/infrastructure/machine/machine.go index e371d6bf..4e0f03a2 100644 --- a/server/internal/machine/infrastructure/machine/machine.go +++ b/server/internal/machine/infrastructure/machine/machine.go @@ -3,7 +3,7 @@ package machine import ( "errors" "fmt" - "mayfly-go/internal/constant" + "mayfly-go/internal/common/consts" "mayfly-go/internal/machine/domain/entity" "mayfly-go/pkg/biz" "mayfly-go/pkg/cache" @@ -139,7 +139,7 @@ func (c *Cli) GetMachine() *Info { } // 机器客户端连接缓存,指定时间内没有访问则会被关闭 -var cliCache = cache.NewTimedCache(constant.MachineConnExpireTime, 5*time.Second). +var cliCache = cache.NewTimedCache(consts.MachineConnExpireTime, 5*time.Second). WithUpdateAccessTime(true). OnEvicted(func(_, value any) { value.(*Cli).Close() diff --git a/server/internal/mongo/application/mongo.go b/server/internal/mongo/application/mongo.go index a2e4e104..bd718e6e 100644 --- a/server/internal/mongo/application/mongo.go +++ b/server/internal/mongo/application/mongo.go @@ -3,7 +3,7 @@ package application import ( "context" "fmt" - "mayfly-go/internal/constant" + "mayfly-go/internal/common/consts" machineapp "mayfly-go/internal/machine/application" "mayfly-go/internal/machine/infrastructure/machine" "mayfly-go/internal/mongo/domain/entity" @@ -101,7 +101,7 @@ func (d *mongoAppImpl) GetMongoCli(id uint64) *mongo.Client { // ----------------------------------------------------------- // mongo客户端连接缓存,指定时间内没有访问则会被关闭 -var mongoCliCache = cache.NewTimedCache(constant.MongoConnExpireTime, 5*time.Second). +var mongoCliCache = cache.NewTimedCache(consts.MongoConnExpireTime, 5*time.Second). WithUpdateAccessTime(true). OnEvicted(func(key any, value any) { global.Log.Info("删除mongo连接缓存: id = ", key) diff --git a/server/internal/redis/application/redis.go b/server/internal/redis/application/redis.go index 52991ff3..d8291ac4 100644 --- a/server/internal/redis/application/redis.go +++ b/server/internal/redis/application/redis.go @@ -3,7 +3,7 @@ package application import ( "context" "fmt" - "mayfly-go/internal/constant" + "mayfly-go/internal/common/consts" machineapp "mayfly-go/internal/machine/application" "mayfly-go/internal/machine/infrastructure/machine" "mayfly-go/internal/redis/domain/entity" @@ -254,7 +254,7 @@ func getRedisDialer(machineId int) func(ctx context.Context, network, addr strin //------------------------------------------------------------------------------ // redis客户端连接缓存,指定时间内没有访问则会被关闭 -var redisCache = cache.NewTimedCache(constant.RedisConnExpireTime, 5*time.Second). +var redisCache = cache.NewTimedCache(consts.RedisConnExpireTime, 5*time.Second). WithUpdateAccessTime(true). OnEvicted(func(key any, value any) { global.Log.Info(fmt.Sprintf("删除redis连接缓存 id = %s", key)) diff --git a/server/internal/sys/api/config.go b/server/internal/sys/api/config.go index 159d9daa..27a73307 100644 --- a/server/internal/sys/api/config.go +++ b/server/internal/sys/api/config.go @@ -53,5 +53,6 @@ func (c *Config) Oauth2Config(rc *req.Ctx) { oauth2LoginConfig := c.ConfigApp.GetConfig(entity.ConfigKeyOauth2Login).ToOauth2Login() rc.ResData = map[string]any{ "enable": oauth2LoginConfig.Enable, + "name": oauth2LoginConfig.Name, } } diff --git a/server/internal/sys/domain/entity/config.go b/server/internal/sys/domain/entity/config.go index 36bab420..46ff01b1 100644 --- a/server/internal/sys/domain/entity/config.go +++ b/server/internal/sys/domain/entity/config.go @@ -33,7 +33,7 @@ func (c *Config) BoolValue(defaultValue bool) bool { if c.Id == 0 { return defaultValue } - return convertBool(c.Value, defaultValue) + return c.ConvBool(c.Value, defaultValue) } // 值返回json map @@ -52,7 +52,7 @@ func (c *Config) IntValue(defaultValue int) int { if c.Id == 0 { return defaultValue } - return convertInt(c.Value, defaultValue) + return c.ConvInt(c.Value, defaultValue) } type AccountLoginSecurity struct { @@ -67,10 +67,10 @@ type AccountLoginSecurity struct { func (c *Config) ToAccountLoginSecurity() *AccountLoginSecurity { jm := c.GetJsonMap() als := new(AccountLoginSecurity) - als.UseCaptcha = convertBool(jm["useCaptcha"], true) - als.UseOtp = convertBool(jm["useOtp"], false) - als.LoginFailCount = convertInt(jm["loginFailCount"], 5) - als.LoginFailMin = convertInt(jm["loginFailMin"], 10) + als.UseCaptcha = c.ConvBool(jm["useCaptcha"], true) + als.UseOtp = c.ConvBool(jm["useOtp"], false) + als.LoginFailCount = c.ConvInt(jm["loginFailCount"], 5) + als.LoginFailMin = c.ConvInt(jm["loginFailMin"], 10) otpIssuer := jm["otpIssuer"] if otpIssuer == "" { otpIssuer = "mayfly-go" @@ -80,7 +80,8 @@ func (c *Config) ToAccountLoginSecurity() *AccountLoginSecurity { } type ConfigOauth2Login struct { - Enable bool // 是否启用 + Enable bool // 是否启用 + Name string ClientId string `json:"clientId"` ClientSecret string `json:"clientSecret"` AuthorizationURL string `json:"authorizationURL"` @@ -96,7 +97,8 @@ type ConfigOauth2Login struct { func (c *Config) ToOauth2Login() *ConfigOauth2Login { jm := c.GetJsonMap() ol := new(ConfigOauth2Login) - ol.Enable = convertBool(jm["enable"], false) + ol.Enable = c.ConvBool(jm["enable"], false) + ol.Name = jm["name"] ol.ClientId = jm["clientId"] ol.ClientSecret = jm["clientSecret"] ol.AuthorizationURL = jm["authorizationURL"] @@ -105,12 +107,12 @@ func (c *Config) ToOauth2Login() *ConfigOauth2Login { ol.Scopes = jm["scopes"] ol.ResourceURL = jm["resourceURL"] ol.UserIdentifier = jm["userIdentifier"] - ol.AutoRegister = convertBool(jm["autoRegister"], true) + ol.AutoRegister = c.ConvBool(jm["autoRegister"], true) return ol } // 转换配置中的值为bool类型(默认"1"或"true"为true,其他为false) -func convertBool(value string, defaultValue bool) bool { +func (c *Config) ConvBool(value string, defaultValue bool) bool { if value == "" { return defaultValue } @@ -118,7 +120,7 @@ func convertBool(value string, defaultValue bool) bool { } // 转换配置值中的值为int -func convertInt(value string, defaultValue int) int { +func (c *Config) ConvInt(value string, defaultValue int) int { if value == "" { return defaultValue } diff --git a/server/mayfly-go.sql b/server/mayfly-go.sql index 37001fab..3a4d392c 100644 --- a/server/mayfly-go.sql +++ b/server/mayfly-go.sql @@ -439,7 +439,7 @@ CREATE TABLE `t_sys_config` ( -- ---------------------------- BEGIN; INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier) VALUES('账号登录安全设置', 'AccountLoginSecurity', '[{"name":"登录验证码","model":"useCaptcha","placeholder":"是否启用登录验证码","options":"true,false"},{"name":"双因素校验(OTP)","model":"useOtp","placeholder":"是否启用双因素(OTP)校验","options":"true,false"},{"name":"OTP签发人","model":"otpIssuer","placeholder":"otp签发人"},{"name":"允许失败次数","model":"loginFailCount","placeholder":"登录失败n次后禁止登录"},{"name":"禁止登录时间","model":"loginFailMin","placeholder":"登录失败指定次数后禁止m分钟内再次登录"}]', '{"useCaptcha":"true","useOtp":"false","loginFailCount":"5","loginFailMin":"10","otpIssuer":"mayfly-go"}', '系统账号登录相关安全设置', '2023-06-17 11:02:11', 1, 'admin', '2023-06-17 14:18:07', 1, 'admin'); -INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier, is_deleted, delete_time) VALUES('oauth2登录配置', 'Oauth2Login', '[{"name":"是否启用","model":"enable","placeholder":"是否启用oauth2登录","options":"true,false"},{"name":"Client ID","model":"clientId","placeholder":"Client ID"},{"name":"Client Secret","model":"clientSecret","placeholder":"Client Secret"},{"name":"Authorization URL","model":"authorizationURL","placeholder":"Authorization URL"},{"name":"AccessToken URL","model":"accessTokenURL","placeholder":"AccessToken URL"},{"name":"Redirect URL","model":"redirectURL","placeholder":"本系统地址"},{"name":"Scopes","model":"scopes","placeholder":"Scopes"},{"name":"Resource URL","model":"resourceURL","placeholder":"获取用户信息资源地址"},{"name":"UserIdentifier","model":"userIdentifier","placeholder":"用户唯一标识字段;格式为type:fieldPath(string:username)"},{"name":"是否自动注册","model":"autoRegister","placeholder":"","options":"true,false"}]', '', 'oauth2登录相关配置信息', '2023-07-22 13:58:51', 1, 'admin', '2023-07-22 19:34:37', 1, 'admin', 0, NULL); +INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier, is_deleted, delete_time) VALUES('oauth2登录配置', 'Oauth2Login', '[{"name":"是否启用","model":"enable","placeholder":"是否启用oauth2登录","options":"true,false"},{"name":"名称","model":"name","placeholder":"oauth2名称"},{"name":"Client ID","model":"clientId","placeholder":"Client ID"},{"name":"Client Secret","model":"clientSecret","placeholder":"Client Secret"},{"name":"Authorization URL","model":"authorizationURL","placeholder":"Authorization URL"},{"name":"AccessToken URL","model":"accessTokenURL","placeholder":"AccessToken URL"},{"name":"Redirect URL","model":"redirectURL","placeholder":"本系统地址"},{"name":"Scopes","model":"scopes","placeholder":"Scopes"},{"name":"Resource URL","model":"resourceURL","placeholder":"获取用户信息资源地址"},{"name":"UserIdentifier","model":"userIdentifier","placeholder":"用户唯一标识字段;格式为type:fieldPath(string:username)"},{"name":"是否自动注册","model":"autoRegister","placeholder":"","options":"true,false"}]', '', 'oauth2登录相关配置信息', '2023-07-22 13:58:51', 1, 'admin', '2023-07-22 19:34:37', 1, 'admin', 0, NULL); INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier)VALUES ('是否启用水印', 'UseWartermark', NULL, '1', '1: 启用、0: 不启用', '2022-08-25 23:36:35', 1, 'admin', '2022-08-26 10:02:52', 1, 'admin'); INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier)VALUES ('数据库查询最大结果集', 'DbQueryMaxCount', '[]', '200', '允许sql查询的最大结果集数。注: 0=不限制', '2023-02-11 14:29:03', 1, 'admin', '2023-02-11 14:40:56', 1, 'admin'); INSERT INTO `t_sys_config` (name, `key`, params, value, remark, create_time, creator_id, creator, update_time, modifier_id, modifier)VALUES ('数据库是否记录查询SQL', 'DbSaveQuerySQL', '[]', '0', '1: 记录、0:不记录', '2023-02-11 16:07:14', 1, 'admin', '2023-02-11 16:44:17', 1, 'admin'); diff --git a/server/pkg/utils/collx/array.go b/server/pkg/utils/collx/array.go index bbc06635..079c1e5c 100644 --- a/server/pkg/utils/collx/array.go +++ b/server/pkg/utils/collx/array.go @@ -1,7 +1,5 @@ package collx -import "fmt" - // 数组比较 // 依次返回,新增值,删除值,以及不变值 func ArrayCompare[T any](newArr []T, oldArr []T, compareFun func(T, T) bool) ([]T, []T, []T) { @@ -38,18 +36,6 @@ func ArrayCompare[T any](newArr []T, oldArr []T, compareFun func(T, T) bool) ([] return newArr, oldArr, unmodifierValue } -type NumT interface { - ~int | ~int32 | ~uint64 -} - -func NumberArr2StrArr[T NumT](numberArr []T) []string { - strArr := make([]string, 0) - for _, v := range numberArr { - strArr = append(strArr, fmt.Sprintf("%d", v)) - } - return strArr -} - // 判断数组中是否含有指定元素 func ArrayContains[T comparable](arr []T, el T) bool { for _, v := range arr {