mirror of
https://github.com/yangjian102621/geekai.git
synced 2026-04-30 15:04:30 +08:00
即梦视频后台管理页面初始化
This commit is contained in:
@@ -60,13 +60,28 @@ func (s *AppServer) Init(debug bool, client *redis.Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *AppServer) Run(db *gorm.DB) error {
|
func (s *AppServer) Run(db *gorm.DB) error {
|
||||||
|
|
||||||
|
// 重命名 config 表字段
|
||||||
|
if db.Migrator().HasColumn(&model.Config{}, "config_json") {
|
||||||
|
db.Migrator().RenameColumn(&model.Config{}, "config_json", "value")
|
||||||
|
}
|
||||||
|
if db.Migrator().HasColumn(&model.Config{}, "marker") {
|
||||||
|
db.Migrator().RenameColumn(&model.Config{}, "marker", "name")
|
||||||
|
}
|
||||||
|
if db.Migrator().HasIndex(&model.Config{}, "idx_chatgpt_configs_key") {
|
||||||
|
db.Migrator().DropIndex(&model.Config{}, "idx_chatgpt_configs_key")
|
||||||
|
}
|
||||||
|
if db.Migrator().HasIndex(&model.Config{}, "marker") {
|
||||||
|
db.Migrator().DropIndex(&model.Config{}, "marker")
|
||||||
|
}
|
||||||
|
|
||||||
// load system configs
|
// load system configs
|
||||||
var sysConfig model.Config
|
var sysConfig model.Config
|
||||||
err := db.Where("marker", "system").First(&sysConfig).Error
|
err := db.Where("name", "system").First(&sysConfig).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to load system config: %v", err)
|
return fmt.Errorf("failed to load system config: %v", err)
|
||||||
}
|
}
|
||||||
err = utils.JsonDecode(sysConfig.Config, &s.SysConfig)
|
err = utils.JsonDecode(sysConfig.Value, &s.SysConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to decode system config: %v", err)
|
return fmt.Errorf("failed to decode system config: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,15 +66,15 @@ func (h *ConfigHandler) Update(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
value := utils.JsonEncode(&data.Config)
|
value := utils.JsonEncode(&data.Config)
|
||||||
config := model.Config{Key: data.Key, Config: value}
|
config := model.Config{Name: data.Key, Value: value}
|
||||||
res := h.DB.FirstOrCreate(&config, model.Config{Key: data.Key})
|
res := h.DB.FirstOrCreate(&config, model.Config{Name: data.Key})
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
resp.ERROR(c, res.Error.Error())
|
resp.ERROR(c, res.Error.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Id > 0 {
|
if config.Id > 0 {
|
||||||
config.Config = value
|
config.Value = value
|
||||||
res := h.DB.Updates(&config)
|
res := h.DB.Updates(&config)
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
resp.ERROR(c, res.Error.Error())
|
resp.ERROR(c, res.Error.Error())
|
||||||
@@ -83,16 +83,16 @@ func (h *ConfigHandler) Update(c *gin.Context) {
|
|||||||
|
|
||||||
// update config cache for AppServer
|
// update config cache for AppServer
|
||||||
var cfg model.Config
|
var cfg model.Config
|
||||||
h.DB.Where("marker", data.Key).First(&cfg)
|
h.DB.Where("name", data.Key).First(&cfg)
|
||||||
var err error
|
var err error
|
||||||
if data.Key == "system" {
|
if data.Key == "system" {
|
||||||
err = utils.JsonDecode(cfg.Config, &h.App.SysConfig)
|
err = utils.JsonDecode(cfg.Value, &h.App.SysConfig)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.ERROR(c, "Failed to update config cache: "+err.Error())
|
resp.ERROR(c, "Failed to update config cache: "+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Infof("Update AppServer's config successfully: %v", config.Config)
|
logger.Infof("Update AppServer's config successfully: %v", config.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.SUCCESS(c, config)
|
resp.SUCCESS(c, config)
|
||||||
@@ -102,14 +102,14 @@ func (h *ConfigHandler) Update(c *gin.Context) {
|
|||||||
func (h *ConfigHandler) Get(c *gin.Context) {
|
func (h *ConfigHandler) Get(c *gin.Context) {
|
||||||
key := c.Query("key")
|
key := c.Query("key")
|
||||||
var config model.Config
|
var config model.Config
|
||||||
res := h.DB.Where("marker", key).First(&config)
|
res := h.DB.Where("name", key).First(&config)
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
resp.ERROR(c, res.Error.Error())
|
resp.ERROR(c, res.Error.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var value map[string]interface{}
|
var value map[string]interface{}
|
||||||
err := utils.JsonDecode(config.Config, &value)
|
err := utils.JsonDecode(config.Value, &value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.ERROR(c, err.Error())
|
resp.ERROR(c, err.Error())
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -31,14 +31,14 @@ func NewConfigHandler(app *core.AppServer, db *gorm.DB, licenseService *service.
|
|||||||
func (h *ConfigHandler) Get(c *gin.Context) {
|
func (h *ConfigHandler) Get(c *gin.Context) {
|
||||||
key := c.Query("key")
|
key := c.Query("key")
|
||||||
var config model.Config
|
var config model.Config
|
||||||
res := h.DB.Where("marker", key).First(&config)
|
res := h.DB.Where("name", key).First(&config)
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
resp.ERROR(c, res.Error.Error())
|
resp.ERROR(c, res.Error.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var value map[string]interface{}
|
var value map[string]any
|
||||||
err := utils.JsonDecode(config.Config, &value)
|
err := utils.JsonDecode(config.Value, &value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.ERROR(c, err.Error())
|
resp.ERROR(c, err.Error())
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
Id uint `gorm:"column:id;primaryKey;autoIncrement"`
|
||||||
Key string `gorm:"column:marker;type:varchar(20);uniqueIndex;not null;comment:标识" json:"marker"`
|
Name string `gorm:"column:name;type:varchar(20);uniqueIndex;not null;comment:配置名称"`
|
||||||
Config string `gorm:"column:config_json;type:text;not null" json:"config_json"`
|
Value string `gorm:"column:value;type:text;not null"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Config) TableName() string {
|
func (m *Config) TableName() string {
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package vo
|
|
||||||
|
|
||||||
import "geekai/core/types"
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
Id uint `json:"id"`
|
|
||||||
Key string `json:"key"`
|
|
||||||
SystemConfig types.SystemConfig `json:"system_config"`
|
|
||||||
}
|
|
||||||
@@ -184,21 +184,7 @@ body {
|
|||||||
.w-100 {
|
.w-100 {
|
||||||
width 100%
|
width 100%
|
||||||
}
|
}
|
||||||
.mr-1 {
|
|
||||||
margin-right 0.5rem
|
|
||||||
}
|
|
||||||
|
|
||||||
.mr-2 {
|
|
||||||
margin-right 1rem
|
|
||||||
}
|
|
||||||
|
|
||||||
.ml-1 {
|
|
||||||
margin-left 0.5rem
|
|
||||||
}
|
|
||||||
|
|
||||||
.ml-2 {
|
|
||||||
margin-left 1rem
|
|
||||||
}
|
|
||||||
|
|
||||||
.d-flex {
|
.d-flex {
|
||||||
display flex !important
|
display flex !important
|
||||||
@@ -218,21 +204,3 @@ body {
|
|||||||
.align-center {
|
.align-center {
|
||||||
align-items center
|
align-items center
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.p-1 {
|
|
||||||
padding 0.5rem
|
|
||||||
}
|
|
||||||
|
|
||||||
.p-2 {
|
|
||||||
padding 1rem
|
|
||||||
}
|
|
||||||
|
|
||||||
.m-1 {
|
|
||||||
margin 0.5rem
|
|
||||||
}
|
|
||||||
|
|
||||||
.m-2 {
|
|
||||||
margin 1rem
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -159,10 +159,23 @@ const items = [
|
|||||||
index: '/admin/medias',
|
index: '/admin/medias',
|
||||||
title: '音视频记录',
|
title: '音视频记录',
|
||||||
},
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'jimeng',
|
||||||
|
index: '/admin/jimeng',
|
||||||
|
title: '即梦AI',
|
||||||
|
subs: [
|
||||||
{
|
{
|
||||||
icon: 'image',
|
icon: 'list',
|
||||||
index: '/admin/jimeng',
|
index: '/admin/jimeng/jobs',
|
||||||
title: '即梦AI任务',
|
title: '任务列表',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
icon: 'config',
|
||||||
|
index: '/admin/jimeng/config',
|
||||||
|
title: '即梦设置',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -259,10 +259,16 @@ const routes = [
|
|||||||
component: () => import('@/views/admin/records/Medias.vue'),
|
component: () => import('@/views/admin/records/Medias.vue'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/admin/jimeng',
|
path: '/admin/jimeng/jobs',
|
||||||
name: 'admin-jimeng',
|
name: 'admin-jimeng-jobs',
|
||||||
meta: { title: '即梦AI管理' },
|
meta: { title: '即梦AI任务' },
|
||||||
component: () => import('@/views/admin/JimengJobs.vue'),
|
component: () => import('@/views/admin/jimeng/JimengJobs.vue'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/admin/jimeng/config',
|
||||||
|
name: 'admin-jimeng-config',
|
||||||
|
meta: { title: '即梦设置' },
|
||||||
|
component: () => import('@/views/admin/jimeng/JimengSetting.vue'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/admin/powerLog',
|
path: '/admin/powerLog',
|
||||||
@@ -364,4 +370,4 @@ router.beforeEach((to, from, next) => {
|
|||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
export { router, prevRoute }
|
export { prevRoute, router }
|
||||||
|
|||||||
114
web/src/views/admin/jimeng/JimengSetting.vue
Normal file
114
web/src/views/admin/jimeng/JimengSetting.vue
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
<template>
|
||||||
|
<div class="system-config form" v-loading="loading">
|
||||||
|
<div class="container">
|
||||||
|
<el-form
|
||||||
|
:model="system"
|
||||||
|
label-width="150px"
|
||||||
|
label-position="right"
|
||||||
|
ref="systemFormRef"
|
||||||
|
:rules="rules"
|
||||||
|
>
|
||||||
|
<el-tabs type="border-card">
|
||||||
|
<el-tab-pane>
|
||||||
|
<template #label>
|
||||||
|
<i class="iconfont icon-token mr-1"></i>
|
||||||
|
<span>秘钥配置</span>
|
||||||
|
</template>
|
||||||
|
<el-form-item label="网站标题" prop="title">
|
||||||
|
<el-input v-model="system['title']" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-tab-pane>
|
||||||
|
|
||||||
|
<el-tab-pane>
|
||||||
|
<template #label>
|
||||||
|
<i class="iconfont icon-logout mr-1"></i>
|
||||||
|
<span>算力配置</span>
|
||||||
|
</template>
|
||||||
|
<el-form-item label="注册赠送算力" prop="init_power">
|
||||||
|
<el-input v-model.number="system['init_power']" placeholder="新用户注册赠送算力" />
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item>
|
||||||
|
<template #label>
|
||||||
|
<div class="label-title">
|
||||||
|
提示词算力
|
||||||
|
<el-tooltip
|
||||||
|
effect="dark"
|
||||||
|
content="生成AI绘图提示词,歌词,视频描述消耗的算力"
|
||||||
|
raw-content
|
||||||
|
placement="right"
|
||||||
|
>
|
||||||
|
<el-icon>
|
||||||
|
<InfoFilled />
|
||||||
|
</el-icon>
|
||||||
|
</el-tooltip>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<el-input v-model.number="system['prompt_power']" placeholder="" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-tab-pane>
|
||||||
|
</el-tabs>
|
||||||
|
|
||||||
|
<div style="padding: 10px">
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" @click="save('system')">保存</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</div>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { httpGet, httpPost } from '@/utils/http'
|
||||||
|
import { InfoFilled } from '@element-plus/icons-vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import 'md-editor-v3/lib/style.css'
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
const system = ref({ models: [] })
|
||||||
|
const loading = ref(true)
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
// 加载系统配置
|
||||||
|
httpGet('/api/admin/config/get?key=system')
|
||||||
|
.then((res) => {
|
||||||
|
system.value = res.data
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
ElMessage.error('加载系统配置失败: ' + e.message)
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const save = function (key) {
|
||||||
|
httpPost('/api/admin/config/update', {
|
||||||
|
key: key,
|
||||||
|
config: { content: notice.value, updated: true },
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
ElMessage.success('操作成功!')
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
ElMessage.error('操作失败:' + e.message)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="stylus" scoped>
|
||||||
|
@import '../../../assets/css/admin/form.styl'
|
||||||
|
@import '../../../assets/css/main.styl'
|
||||||
|
.system-config {
|
||||||
|
display flex
|
||||||
|
justify-content center
|
||||||
|
|
||||||
|
.sys-tabs {
|
||||||
|
width 100%
|
||||||
|
background-color var(--el-bg-color)
|
||||||
|
padding 10px 20px 40px 20px
|
||||||
|
//border: 1px solid var(--el-border-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user