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/handler"
"chatplus/store/model" "chatplus/store/model"
"chatplus/store/vo" "chatplus/store/vo"
"chatplus/utils"
"chatplus/utils/resp" "chatplus/utils/resp"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gorm.io/gorm" "gorm.io/gorm"
@ -29,8 +30,18 @@ func (h *FunctionHandler) Save(c *gin.Context) {
return return
} }
logger.Info(data) var f = model.Function{
resp.SUCCESS(c) 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) { 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) { func NewBot(name string, proxy string, config *types.MidJourneyConfig, service *Service) (*Bot, error) {
discord, err := discordgo.New("Bot " + config.BotToken) discord, err := discordgo.New("Bot " + config.BotToken)
logger.Info(config.BotToken)
if err != nil { if err != nil {
logger.Error(err)
return nil, err return nil, err
} }

View File

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