feat: add function list page in admin console

This commit is contained in:
RockYang 2023-12-21 18:06:09 +08:00
parent 113cfae2dc
commit de512a5ea2
4 changed files with 32 additions and 15 deletions

View File

@ -6,6 +6,7 @@ import (
"chatplus/handler"
"chatplus/store/model"
"chatplus/store/vo"
"chatplus/utils"
"chatplus/utils/resp"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
@ -29,8 +30,18 @@ func (h *FunctionHandler) Save(c *gin.Context) {
return
}
logger.Info(data)
resp.SUCCESS(c)
var f = model.Function{
Id: data.Id,
Name: data.Name,
Description: data.Description,
Parameters: utils.JsonEncode(data.Parameters),
Required: utils.JsonEncode(data.Required),
Action: data.Action,
Enabled: false,
}
logger.Info(f)
resp.SUCCESS(c, data)
}
func (h *FunctionHandler) List(c *gin.Context) {

View File

@ -25,7 +25,9 @@ type Bot struct {
func NewBot(name string, proxy string, config *types.MidJourneyConfig, service *Service) (*Bot, error) {
discord, err := discordgo.New("Bot " + config.BotToken)
logger.Info(config.BotToken)
if err != nil {
logger.Error(err)
return nil, err
}

View File

@ -21,7 +21,6 @@ func NewClient(config types.MidJourneyConfig, proxy string) *Client {
if proxy != "" {
client.SetProxyURL(proxy)
}
logger.Info(config)
return &Client{client: client, config: config}
}

View File

@ -10,11 +10,10 @@
<span class="sort" :data-id="scope.row.id">{{ scope.row.name }}</span>
</template>
</el-table-column>
<el-table-column label="功能描述" prop="key"/>
<el-table-column label="">
<el-table-column label="功能描述" prop="description"/>
<el-table-column label="启用状态">
<template #default="scope">
<el-tag v-if="scope.row.enable" type="success">启用</el-tag>
<el-tag type="danger" v-else>禁用</el-tag>
<el-switch v-model="scope.row.enabled" @change="functionSet(scope.row)"/>
</template>
</el-table-column>
@ -163,7 +162,9 @@ onMounted(() => {
const fetch = () => {
httpGet('/api/admin/function/list').then((res) => {
tableData.value = res.data
if (res.data) {
tableData.value = res.data
}
loading.value = false
}).catch(() => {
ElMessage.error("获取数据失败");
@ -199,12 +200,12 @@ const save = function () {
item.value.parameters = {type: "object", "properties": properties, "required": required}
httpPost('/api/admin/function/save', item.value).then((res) => {
ElMessage.success('操作成功')
//
// if (item.value.id) {
// tableData.value[curIndex.value] = item.value
// } else {
// tableData.value.push(res.data)
// }
console.log(res.data)
if (item.value.id > 0) {
tableData.value[curIndex.value] = item.value
} else {
tableData.value.push(res.data)
}
}).catch((e) => {
ElMessage.error('操作失败,' + e.message)
})
@ -225,13 +226,17 @@ const addParam = function () {
if (!params.value) {
item.value = []
}
params.value.push({name: "", type: "", desc: "", required: false})
params.value.push({name: "", type: "string", desc: "", required: false})
}
const removeParam = function (index) {
params.value.splice(index, 1);
}
const functionSet = (row) => {
}
</script>
<style lang="stylus" scoped>