diff --git a/server/initialize/gorm_mysql.go b/server/initialize/gorm_mysql.go index 6e496a4d..61e50ba2 100644 --- a/server/initialize/gorm_mysql.go +++ b/server/initialize/gorm_mysql.go @@ -12,18 +12,31 @@ import ( // GormMysql 初始化Mysql数据库 // Author [piexlmax](https://github.com/piexlmax) // Author [SliverHorn](https://github.com/SliverHorn) +// Author [ByteZhou-2018](https://github.com/ByteZhou-2018) func GormMysql() *gorm.DB { m := global.GVA_CONFIG.Mysql + return initMysqlDatabase(m) +} + +// GormMysqlByConfig 通过传入配置初始化Mysql数据库 +func GormMysqlByConfig(m config.Mysql) *gorm.DB { + return initMysqlDatabase(m) +} + +// initMysqlDatabase 初始化Mysql数据库的辅助函数 +func initMysqlDatabase(m config.Mysql) *gorm.DB { if m.Dbname == "" { return nil } + mysqlConfig := mysql.Config{ DSN: m.Dsn(), // DSN data source name DefaultStringSize: 191, // string 类型字段的默认长度 SkipInitializeWithVersion: false, // 根据版本自动配置 } + if db, err := gorm.Open(mysql.New(mysqlConfig), internal.Gorm.Config(m.Prefix, m.Singular)); err != nil { - return nil + panic(err) } else { db.InstanceSet("gorm:table_options", "ENGINE="+m.Engine) sqlDB, _ := db.DB() @@ -32,24 +45,3 @@ func GormMysql() *gorm.DB { return db } } - -// GormMysqlByConfig 初始化Mysql数据库用过传入配置 -func GormMysqlByConfig(m config.Mysql) *gorm.DB { - if m.Dbname == "" { - return nil - } - mysqlConfig := mysql.Config{ - DSN: m.Dsn(), // DSN data source name - DefaultStringSize: 191, // string 类型字段的默认长度 - SkipInitializeWithVersion: false, // 根据版本自动配置 - } - if db, err := gorm.Open(mysql.New(mysqlConfig), internal.Gorm.Config(m.Prefix, m.Singular)); err != nil { - panic(err) - } else { - db.InstanceSet("gorm:table_options", "ENGINE=InnoDB") - sqlDB, _ := db.DB() - sqlDB.SetMaxIdleConns(m.MaxIdleConns) - sqlDB.SetMaxOpenConns(m.MaxOpenConns) - return db - } -} diff --git a/server/initialize/gorm_oracle.go b/server/initialize/gorm_oracle.go index 4d18c8a8..513359f0 100644 --- a/server/initialize/gorm_oracle.go +++ b/server/initialize/gorm_oracle.go @@ -15,32 +15,25 @@ import ( // 如果需要Oracle库 放开import里的注释 把下方 mysql.Config 改为 oracle.Config ; mysql.New 改为 oracle.New func GormOracle() *gorm.DB { m := global.GVA_CONFIG.Oracle - if m.Dbname == "" { - return nil - } - oracleConfig := mysql.Config{ - DSN: m.Dsn(), // DSN data source name - DefaultStringSize: 191, // string 类型字段的默认长度 - } - if db, err := gorm.Open(mysql.New(oracleConfig), internal.Gorm.Config(m.Prefix, m.Singular)); err != nil { - panic(err) - } else { - sqlDB, _ := db.DB() - sqlDB.SetMaxIdleConns(m.MaxIdleConns) - sqlDB.SetMaxOpenConns(m.MaxOpenConns) - return db - } + return initOracleDatabase(m) } // GormOracleByConfig 初始化Oracle数据库用过传入配置 func GormOracleByConfig(m config.Oracle) *gorm.DB { + return initOracleDatabase(m) +} + +// initOracleDatabase 初始化Oracle数据库的辅助函数 +func initOracleDatabase(m config.Oracle) *gorm.DB { if m.Dbname == "" { return nil } + oracleConfig := mysql.Config{ DSN: m.Dsn(), // DSN data source name DefaultStringSize: 191, // string 类型字段的默认长度 } + if db, err := gorm.Open(mysql.New(oracleConfig), internal.Gorm.Config(m.Prefix, m.Singular)); err != nil { panic(err) } else { diff --git a/server/initialize/gorm_pgsql.go b/server/initialize/gorm_pgsql.go index 625c8738..6abde589 100644 --- a/server/initialize/gorm_pgsql.go +++ b/server/initialize/gorm_pgsql.go @@ -13,25 +13,16 @@ import ( // Author [SliverHorn](https://github.com/SliverHorn) func GormPgSql() *gorm.DB { p := global.GVA_CONFIG.Pgsql - if p.Dbname == "" { - return nil - } - pgsqlConfig := postgres.Config{ - DSN: p.Dsn(), // DSN data source name - PreferSimpleProtocol: false, - } - if db, err := gorm.Open(postgres.New(pgsqlConfig), internal.Gorm.Config(p.Prefix, p.Singular)); err != nil { - return nil - } else { - sqlDB, _ := db.DB() - sqlDB.SetMaxIdleConns(p.MaxIdleConns) - sqlDB.SetMaxOpenConns(p.MaxOpenConns) - return db - } + return initPgSqlDatabase(p) } -// GormPgSqlByConfig 初始化 Postgresql 数据库 通过参数 +// GormPgSqlByConfig 初始化 Postgresql 数据库 通过指定参数 func GormPgSqlByConfig(p config.Pgsql) *gorm.DB { + return initPgSqlDatabase(p) +} + +// initPgSqlDatabase 初始化 Postgresql 数据库的辅助函数 +func initPgSqlDatabase(p config.Pgsql) *gorm.DB { if p.Dbname == "" { return nil } diff --git a/server/initialize/gorm_sqlite.go b/server/initialize/gorm_sqlite.go index 04126410..9d158bf1 100644 --- a/server/initialize/gorm_sqlite.go +++ b/server/initialize/gorm_sqlite.go @@ -11,22 +11,16 @@ import ( // GormSqlite 初始化Sqlite数据库 func GormSqlite() *gorm.DB { s := global.GVA_CONFIG.Sqlite - if s.Dbname == "" { - return nil - } - - if db, err := gorm.Open(sqlite.Open(s.Dsn()), internal.Gorm.Config(s.Prefix, s.Singular)); err != nil { - panic(err) - } else { - sqlDB, _ := db.DB() - sqlDB.SetMaxIdleConns(s.MaxIdleConns) - sqlDB.SetMaxOpenConns(s.MaxOpenConns) - return db - } + return initSqliteDatabase(s) } // GormSqliteByConfig 初始化Sqlite数据库用过传入配置 func GormSqliteByConfig(s config.Sqlite) *gorm.DB { + return initSqliteDatabase(s) +} + +// initSqliteDatabase 初始化Sqlite数据库辅助函数 +func initSqliteDatabase(s config.Sqlite) *gorm.DB { if s.Dbname == "" { return nil } diff --git a/server/service/system/auto_code_package_test.go b/server/service/system/auto_code_package_test.go index 94285e97..d2a54739 100644 --- a/server/service/system/auto_code_package_test.go +++ b/server/service/system/auto_code_package_test.go @@ -2,10 +2,11 @@ package system import ( "context" - model "github.com/flipped-aurora/gin-vue-admin/server/model/system" - "github.com/flipped-aurora/gin-vue-admin/server/model/system/request" "reflect" "testing" + + model "github.com/flipped-aurora/gin-vue-admin/server/model/system" + "github.com/flipped-aurora/gin-vue-admin/server/model/system/request" ) func Test_autoCodePackage_Create(t *testing.T) { @@ -53,9 +54,10 @@ func Test_autoCodePackage_Create(t *testing.T) { func Test_autoCodePackage_templates(t *testing.T) { type args struct { - ctx context.Context - entity model.SysAutoCodePackage - info request.AutoCode + ctx context.Context + entity model.SysAutoCodePackage + info request.AutoCode + isPackage bool } tests := []struct { name string @@ -78,6 +80,7 @@ func Test_autoCodePackage_templates(t *testing.T) { Abbreviation: "user", HumpPackageName: "user", }, + isPackage: false, }, wantErr: false, }, @@ -85,7 +88,7 @@ func Test_autoCodePackage_templates(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { s := &autoCodePackage{} - gotCode, gotEnter, gotCreates, err := s.templates(tt.args.ctx, tt.args.entity, tt.args.info) + gotCode, gotEnter, gotCreates, err := s.templates(tt.args.ctx, tt.args.entity, tt.args.info, tt.args.isPackage) if (err != nil) != tt.wantErr { t.Errorf("templates() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/server/source/system/menu.go b/server/source/system/menu.go index 30b177fd..100a2cfd 100644 --- a/server/source/system/menu.go +++ b/server/source/system/menu.go @@ -82,6 +82,7 @@ func (i *initMenu) InitializeData(ctx context.Context) (next context.Context, er {MenuLevel: 0, Hidden: false, ParentId: 15, Path: "exportTemplate", Name: "exportTemplate", Component: "view/systemTools/exportTemplate/exportTemplate.vue", Sort: 5, Meta: Meta{Title: "导出模板", Icon: "reading"}}, {MenuLevel: 0, Hidden: false, ParentId: 24, Path: "anInfo", Name: "anInfo", Component: "plugin/announcement/view/info.vue", Sort: 5, Meta: Meta{Title: "公告管理[示例]", Icon: "scaleToOriginal"}}, {MenuLevel: 0, Hidden: false, ParentId: 3, Path: "sysParams", Name: "sysParams", Component: "view/superAdmin/params/sysParams.vue", Sort: 7, Meta: Meta{Title: "参数管理", Icon: "compass"}}, + {MenuLevel: 0, Hidden: false, ParentId: 15, Path: "picture", Name: "picture", Component: "view/systemTools/autoCode/picture.vue", Sort: 6, Meta: Meta{Title: "AI页面绘制", Icon: "picture-filled"}}, } if err = db.Create(&entities).Error; err != nil { return ctx, errors.Wrap(err, SysBaseMenu{}.TableName()+"表数据初始化失败!") diff --git a/server/utils/captcha/redis.go b/server/utils/captcha/redis.go index a13b7cc1..ffb4dbf7 100644 --- a/server/utils/captcha/redis.go +++ b/server/utils/captcha/redis.go @@ -5,7 +5,6 @@ import ( "time" "github.com/flipped-aurora/gin-vue-admin/server/global" - "github.com/mojocn/base64Captcha" "go.uber.org/zap" ) @@ -23,8 +22,10 @@ type RedisStore struct { Context context.Context } -func (rs *RedisStore) UseWithCtx(ctx context.Context) base64Captcha.Store { - rs.Context = ctx +func (rs *RedisStore) UseWithCtx(ctx context.Context) *RedisStore { + if ctx == nil { + rs.Context = ctx + } return rs } diff --git a/web/src/api/autoCode.js b/web/src/api/autoCode.js index 8994b3c6..7fe1af98 100644 --- a/web/src/api/autoCode.js +++ b/web/src/api/autoCode.js @@ -173,6 +173,17 @@ export const eye = (data) => { } +export const createWeb = (data) => { + return service({ + url: '/autoCode/llmAuto', + method: 'post', + data: { ...data, mode: 'painter' }, + timeout: 1000 * 60 * 10 + }) +} + + + export const addFunc = (data) => { return service({ url: '/autoCode/addFunc', diff --git a/web/src/pathInfo.json b/web/src/pathInfo.json index 29da8415..05c02a6c 100644 --- a/web/src/pathInfo.json +++ b/web/src/pathInfo.json @@ -16,6 +16,7 @@ "/src/view/example/breakpoint/breakpoint.vue": "BreakPoint", "/src/view/example/customer/customer.vue": "Customer", "/src/view/example/index.vue": "Example", + "/src/view/example/upload/scanUpload.vue": "scanUpload", "/src/view/example/upload/upload.vue": "Upload", "/src/view/init/index.vue": "Init", "/src/view/layout/aside/asideComponent/asyncSubmenu.vue": "AsyncSubmenu", @@ -53,8 +54,10 @@ "/src/view/superAdmin/user/user.vue": "User", "/src/view/system/state.vue": "State", "/src/view/systemTools/autoCode/component/fieldDialog.vue": "FieldDialog", + "/src/view/systemTools/autoCode/component/iframeRenderer.vue": "IframeRenderer", "/src/view/systemTools/autoCode/component/previewCodeDialog.vue": "PreviewCodeDialog", "/src/view/systemTools/autoCode/index.vue": "AutoCode", + "/src/view/systemTools/autoCode/picture.vue": "Picture", "/src/view/systemTools/autoCodeAdmin/index.vue": "AutoCodeAdmin", "/src/view/systemTools/autoPkg/autoPkg.vue": "AutoPkg", "/src/view/systemTools/exportTemplate/exportTemplate.vue": "ExportTemplate", diff --git a/web/src/pinia/modules/app.js b/web/src/pinia/modules/app.js index 8b322353..9eb9dea1 100644 --- a/web/src/pinia/modules/app.js +++ b/web/src/pinia/modules/app.js @@ -99,6 +99,27 @@ export const useAppStore = defineStore('app', () => { config.transition_type = e } + const baseCoinfg = { + weakness: false, + grey: false, + primaryColor: '#3b82f6', + showTabs: true, + darkMode: 'auto', + layout_side_width: 256, + layout_side_collapsed_width: 80, + layout_side_item_height: 48, + show_watermark: true, + side_mode: 'normal', + // 页面过渡动画配置 + transition_type: 'slide' + } + + const resetConfig = () => { + for (let baseCoinfgKey in baseCoinfg) { + config[baseCoinfgKey] = baseCoinfg[baseCoinfgKey] + } + } + // 监听色弱模式和灰色模式 watchEffect(() => { document.documentElement.classList.toggle('html-weakenss', config.weakness) @@ -128,6 +149,7 @@ export const useAppStore = defineStore('app', () => { toggleConfigSideItemHeight, toggleConfigWatermark, toggleSideMode, - toggleTransition + toggleTransition, + resetConfig } }) diff --git a/web/src/view/layout/setting/index.vue b/web/src/view/layout/setting/index.vue index 12a7f2aa..5bbd33cd 100644 --- a/web/src/view/layout/setting/index.vue +++ b/web/src/view/layout/setting/index.vue @@ -9,7 +9,7 @@
@@ -144,6 +144,8 @@ import { ElMessage } from 'element-plus' import { setSelfSetting } from '@/api/user' import Title from './title.vue' + import { watch } from 'vue'; + const appStore = useAppStore() const { config, device } = storeToRefs(appStore) defineOptions({ @@ -185,24 +187,24 @@ ] const saveConfig = async () => { - /*const input = document.createElement("textarea"); - input.value = JSON.stringify(config.value); - // 添加回车 - input.value = input.value.replace(/,/g, ",\n"); - document.body.appendChild(input); - input.select(); - document.execCommand("copy"); - document.body.removeChild(input); - ElMessage.success("复制成功, 请自行保存到本地文件中");*/ const res = await setSelfSetting(config.value) + console.log(config.value) if (res.code === 0) { localStorage.setItem('originSetting', JSON.stringify(config.value)) ElMessage.success('保存成功') - drawer.value = false } } const customColor = ref('') + + const resetConfig = () => { + appStore.resetConfig() + } + + + watch(config, async () => { + await saveConfig(); + }, { deep: true }); + + +
+ diff --git a/web/src/view/systemTools/autoCode/picture.vue b/web/src/view/systemTools/autoCode/picture.vue new file mode 100644 index 00000000..9ad55755 --- /dev/null +++ b/web/src/view/systemTools/autoCode/picture.vue @@ -0,0 +1,141 @@ + + +