mirror of
				https://github.com/yangjian102621/geekai.git
				synced 2025-11-04 08:13:43 +08:00 
			
		
		
		
	feat: function CRUD operation is ready
This commit is contained in:
		@@ -14,13 +14,12 @@ var logger = logger2.GetLogger()
 | 
			
		||||
 | 
			
		||||
func NewDefaultConfig() *types.AppConfig {
 | 
			
		||||
	return &types.AppConfig{
 | 
			
		||||
		Listen:        "0.0.0.0:5678",
 | 
			
		||||
		ProxyURL:      "",
 | 
			
		||||
		Manager:       types.Manager{Username: "admin", Password: "admin123"},
 | 
			
		||||
		StaticDir:     "./static",
 | 
			
		||||
		StaticUrl:     "http://localhost/5678/static",
 | 
			
		||||
		Redis:         types.RedisConfig{Host: "localhost", Port: 6379, Password: ""},
 | 
			
		||||
		AesEncryptKey: utils.RandString(24),
 | 
			
		||||
		Listen:    "0.0.0.0:5678",
 | 
			
		||||
		ProxyURL:  "",
 | 
			
		||||
		Manager:   types.Manager{Username: "admin", Password: "admin123"},
 | 
			
		||||
		StaticDir: "./static",
 | 
			
		||||
		StaticUrl: "http://localhost/5678/static",
 | 
			
		||||
		Redis:     types.RedisConfig{Host: "localhost", Port: 6379, Password: ""},
 | 
			
		||||
		Session: types.Session{
 | 
			
		||||
			SecretKey: utils.RandString(64),
 | 
			
		||||
			MaxAge:    86400,
 | 
			
		||||
 
 | 
			
		||||
@@ -5,22 +5,21 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type AppConfig struct {
 | 
			
		||||
	Path          string `toml:"-"`
 | 
			
		||||
	Listen        string
 | 
			
		||||
	Session       Session
 | 
			
		||||
	ProxyURL      string
 | 
			
		||||
	MysqlDns      string            // mysql 连接地址
 | 
			
		||||
	Manager       Manager           // 后台管理员账户信息
 | 
			
		||||
	StaticDir     string            // 静态资源目录
 | 
			
		||||
	StaticUrl     string            // 静态资源 URL
 | 
			
		||||
	Redis         RedisConfig       // redis 连接信息
 | 
			
		||||
	ApiConfig     ChatPlusApiConfig // ChatPlus API authorization configs
 | 
			
		||||
	AesEncryptKey string
 | 
			
		||||
	SmsConfig     AliYunSmsConfig         // AliYun send message service config
 | 
			
		||||
	OSS           OSSConfig               // OSS config
 | 
			
		||||
	MjConfigs     []MidJourneyConfig      // mj AI draw service pool
 | 
			
		||||
	WeChatBot     bool                    // 是否启用微信机器人
 | 
			
		||||
	SdConfigs     []StableDiffusionConfig // sd AI draw service pool
 | 
			
		||||
	Path      string `toml:"-"`
 | 
			
		||||
	Listen    string
 | 
			
		||||
	Session   Session
 | 
			
		||||
	ProxyURL  string
 | 
			
		||||
	MysqlDns  string                  // mysql 连接地址
 | 
			
		||||
	Manager   Manager                 // 后台管理员账户信息
 | 
			
		||||
	StaticDir string                  // 静态资源目录
 | 
			
		||||
	StaticUrl string                  // 静态资源 URL
 | 
			
		||||
	Redis     RedisConfig             // redis 连接信息
 | 
			
		||||
	ApiConfig ChatPlusApiConfig       // ChatPlus API authorization configs
 | 
			
		||||
	SmsConfig AliYunSmsConfig         // AliYun send message service config
 | 
			
		||||
	OSS       OSSConfig               // OSS config
 | 
			
		||||
	MjConfigs []MidJourneyConfig      // mj AI draw service pool
 | 
			
		||||
	WeChatBot bool                    // 是否启用微信机器人
 | 
			
		||||
	SdConfigs []StableDiffusionConfig // sd AI draw service pool
 | 
			
		||||
 | 
			
		||||
	XXLConfig     XXLConfig
 | 
			
		||||
	AlipayConfig  AlipayConfig
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,8 @@ import (
 | 
			
		||||
	"chatplus/utils"
 | 
			
		||||
	"chatplus/utils/resp"
 | 
			
		||||
 | 
			
		||||
	"github.com/golang-jwt/jwt/v5"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
@@ -104,3 +106,20 @@ func (h *FunctionHandler) Remove(c *gin.Context) {
 | 
			
		||||
	}
 | 
			
		||||
	resp.SUCCESS(c)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GenToken generate function api access token
 | 
			
		||||
func (h *FunctionHandler) GenToken(c *gin.Context) {
 | 
			
		||||
	// 创建 token
 | 
			
		||||
	token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
 | 
			
		||||
		"user_id": 0,
 | 
			
		||||
		"expired": 0,
 | 
			
		||||
	})
 | 
			
		||||
	tokenString, err := token.SignedString([]byte(h.App.Config.Session.SecretKey))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logger.Error("error with generate token", err)
 | 
			
		||||
		resp.ERROR(c)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	resp.SUCCESS(c, tokenString)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -355,6 +355,7 @@ func main() {
 | 
			
		||||
			group.POST("set", h.Set)
 | 
			
		||||
			group.GET("list", h.List)
 | 
			
		||||
			group.GET("remove", h.Remove)
 | 
			
		||||
			group.GET("token", h.GenToken)
 | 
			
		||||
		}),
 | 
			
		||||
 | 
			
		||||
		fx.Provide(handler.NewTestHandler),
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,7 @@
 | 
			
		||||
        <el-table-column label="操作" width="180">
 | 
			
		||||
          <template #default="scope">
 | 
			
		||||
            <el-button size="small" type="primary" @click="edit(scope.row)">编辑</el-button>
 | 
			
		||||
            <el-popconfirm title="确定要删除当前记录吗?" @confirm="remove(scope.row)">
 | 
			
		||||
            <el-popconfirm title="确定要删除当前记录吗?" @confirm="remove(scope.row)" :width="200">
 | 
			
		||||
              <template #reference>
 | 
			
		||||
                <el-button size="small" type="danger">删除</el-button>
 | 
			
		||||
              </template>
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,7 @@
 | 
			
		||||
        <el-table-column label="操作" width="180">
 | 
			
		||||
          <template #default="scope">
 | 
			
		||||
            <el-button size="small" type="primary" @click="edit(scope.row)">编辑</el-button>
 | 
			
		||||
            <el-popconfirm title="确定要删除当前记录吗?" @confirm="remove(scope.row)">
 | 
			
		||||
            <el-popconfirm title="确定要删除当前记录吗?" @confirm="remove(scope.row)" :width="200">
 | 
			
		||||
              <template #reference>
 | 
			
		||||
                <el-button size="small" type="danger">删除</el-button>
 | 
			
		||||
              </template>
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@
 | 
			
		||||
        <el-table-column label="操作" width="150" align="right">
 | 
			
		||||
          <template #default="scope">
 | 
			
		||||
            <el-button size="small" type="primary" @click="rowEdit(scope.$index, scope.row)">编辑</el-button>
 | 
			
		||||
            <el-popconfirm title="确定要删除当前函数吗?" @confirm="remove(scope.row)">
 | 
			
		||||
            <el-popconfirm title="确定要删除当前函数吗?" @confirm="remove(scope.row)" :width="200">
 | 
			
		||||
              <template #reference>
 | 
			
		||||
                <el-button size="small" type="danger">删除</el-button>
 | 
			
		||||
              </template>
 | 
			
		||||
@@ -119,6 +119,7 @@
 | 
			
		||||
          <el-input
 | 
			
		||||
              v-model="item.action"
 | 
			
		||||
              autocomplete="off"
 | 
			
		||||
              placeholder="该函数实现的API地址,可以是第三方服务API"
 | 
			
		||||
          />
 | 
			
		||||
        </el-form-item>
 | 
			
		||||
 | 
			
		||||
@@ -126,7 +127,20 @@
 | 
			
		||||
          <el-input
 | 
			
		||||
              v-model="item.token"
 | 
			
		||||
              autocomplete="off"
 | 
			
		||||
          />
 | 
			
		||||
              placeholder="API授权Token"
 | 
			
		||||
          >
 | 
			
		||||
            <template #append>
 | 
			
		||||
              <el-tooltip
 | 
			
		||||
                  class="box-item"
 | 
			
		||||
                  effect="dark"
 | 
			
		||||
                  content="只有本地服务才可以使用自动生成Token<br/>第三方服务请填写第三方服务API Token"
 | 
			
		||||
                  placement="top-end"
 | 
			
		||||
                  raw-content
 | 
			
		||||
              >
 | 
			
		||||
                <el-button @click="generateToken">生成Token</el-button>
 | 
			
		||||
              </el-tooltip>
 | 
			
		||||
            </template>
 | 
			
		||||
          </el-input>
 | 
			
		||||
        </el-form-item>
 | 
			
		||||
        <el-form-item label="启用状态">
 | 
			
		||||
          <el-switch v-model="item.enabled"/>
 | 
			
		||||
@@ -207,6 +221,7 @@ const rowEdit = function (index, row) {
 | 
			
		||||
 | 
			
		||||
const addRow = function () {
 | 
			
		||||
  item.value = {enabled:true}
 | 
			
		||||
  params.value = []
 | 
			
		||||
  showDialog.value = true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -240,7 +255,7 @@ const save = function () {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const remove = function (row) {
 | 
			
		||||
  httpGet('/api/admin/role/remove?id=' + row.id).then(() => {
 | 
			
		||||
  httpGet('/api/admin/function/remove?id=' + row.id).then(() => {
 | 
			
		||||
    ElMessage.success("删除成功!")
 | 
			
		||||
    fetch()
 | 
			
		||||
  }).catch(() => {
 | 
			
		||||
@@ -267,6 +282,14 @@ const functionSet = (filed,row) => {
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const generateToken = () => {
 | 
			
		||||
  httpGet('/api/admin/function/token').then(res => {
 | 
			
		||||
    item.value.token = res.data
 | 
			
		||||
  }).catch(() => {
 | 
			
		||||
    ElMessage.error("生成 Token 失败")
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="stylus" scoped>
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@
 | 
			
		||||
        <el-table-column label="操作" width="180">
 | 
			
		||||
          <template #default="scope">
 | 
			
		||||
            <el-button size="small" type="primary" @click="edit(scope.row)">编辑</el-button>
 | 
			
		||||
            <el-popconfirm title="确定要删除当前记录吗?" @confirm="remove(scope.row)">
 | 
			
		||||
            <el-popconfirm title="确定要删除当前记录吗?" @confirm="remove(scope.row)" :width="200">
 | 
			
		||||
              <template #reference>
 | 
			
		||||
                <el-button size="small" type="danger">删除</el-button>
 | 
			
		||||
              </template>
 | 
			
		||||
 
 | 
			
		||||
@@ -36,7 +36,7 @@
 | 
			
		||||
        <el-table-column label="操作" width="150" align="right">
 | 
			
		||||
          <template #default="scope">
 | 
			
		||||
            <el-button size="small" type="primary" @click="rowEdit(scope.$index, scope.row)">编辑</el-button>
 | 
			
		||||
            <el-popconfirm title="确定要删除当前角色吗?" @confirm="removeRole(scope.row)">
 | 
			
		||||
            <el-popconfirm title="确定要删除当前角色吗?" @confirm="removeRole(scope.row)" :width="200">
 | 
			
		||||
              <template #reference>
 | 
			
		||||
                <el-button size="small" type="danger">删除</el-button>
 | 
			
		||||
              </template>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user