feat(token): 添加备注功能和相关接口
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 1m41s

This commit is contained in:
2025-09-06 17:43:20 +08:00
parent 333882c9e0
commit b6ce840400
3 changed files with 57 additions and 8 deletions

View File

@@ -18,6 +18,7 @@ func CreateTokenHandler(c *gin.Context) {
Token string `form:"token" binding:"required"`
DedupObject string `form:"dedup_object" binding:"required"`
DataFormat string `form:"data_format" binding:"required"`
Notes string `form:"notes" binding:"required"`
}{}
if err := c.ShouldBindQuery(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
@@ -25,7 +26,7 @@ func CreateTokenHandler(c *gin.Context) {
}
//创建Token
err := db.CreateToken(input.Token, input.DedupObject, input.DataFormat)
err := db.CreateToken(input.Token, input.DedupObject, input.DataFormat, input.Notes)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
@@ -40,13 +41,14 @@ func UpdateTokenHandler(c *gin.Context) {
Token string `form:"token" binding:"required"`
DedupObject string `form:"dedup_object" binding:"required"`
DataFormat string `form:"data_format" binding:"required"`
Notes string `form:"notes" binding:"required"`
}{}
if err := c.ShouldBindQuery(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
return
}
err := db.UpdateToken(input.Token, input.DedupObject, input.DataFormat)
err := db.UpdateToken(input.Token, input.DedupObject, input.DataFormat, input.Notes)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return

View File

@@ -13,6 +13,7 @@ type Token struct {
Token string `json:"token"`
DedupObject string `json:"dedup_object"`
DataFormat string `json:"data_format"`
Notes string `json:"notes"`
}
func InitLocalDB() {
@@ -36,7 +37,7 @@ func ListToken() []Token {
return localDB
}
func CreateToken(token string, dedupObject string, dataFormat string) error {
func CreateToken(token string, dedupObject string, dataFormat string, Notes string) error {
InitLocalDB()
for _, t := range localDB {
if t.Token == token {
@@ -44,7 +45,7 @@ func CreateToken(token string, dedupObject string, dataFormat string) error {
}
}
a := append(localDB, Token{token, dedupObject, dataFormat})
a := append(localDB, Token{token, dedupObject, dataFormat, Notes})
marshal, err := json.Marshal(a)
if err != nil {
return err
@@ -56,13 +57,14 @@ func CreateToken(token string, dedupObject string, dataFormat string) error {
return nil
}
func UpdateToken(token string, dedupObject string, dataFormat string) error {
func UpdateToken(token string, dedupObject string, dataFormat string, Notes string) error {
InitLocalDB()
for i, t := range localDB {
if t.Token == token {
localDB[i].DedupObject = dedupObject
localDB[i].DataFormat = dataFormat
localDB[i].Notes = Notes
marshal, err := json.Marshal(localDB)
if err != nil {

View File

@@ -45,7 +45,8 @@ const addToken = () => {
params: {
token: input.value,
dedup_object: value.value,
data_format: dataFormat.value
data_format: dataFormat.value,
notes: inputNotes.value,
}
}).then(response => {
if (response.data.result == "ok") {
@@ -84,7 +85,8 @@ const updateDedupObject = () => {
params: {
token: rowOut.token,
dedup_object: value.value,
data_format: rowOut.data_format
data_format: rowOut.data_format,
notes: rowOut.notes,
}
}).then(res => {
if (res.data.result == "ok") {
@@ -112,7 +114,38 @@ const updateDataFormat = () => {
params: {
token: rowOut.token,
dedup_object: rowOut.dedup_object,
data_format: dataFormat.value
data_format: dataFormat.value,
notes: rowOut.notes,
}
}).then(res => {
if (res.data.result == "ok") {
ElMessage({
message: '更改成功',
type: 'success',
})
axios.get('/api/token').then(res => {
tableData.value = res.data.result
})
}
}).catch(error => {
ElMessage.error(error.response?.data?.error)
})
}
const inputNotes = ref("")
const NotesVisible = ref(false)
const dialogNotesVisible = (row: any) => {
rowOut = row
NotesVisible.value = true
}
const updateNotes = () => {
NotesVisible.value = false
axios.put('/api/token', {}, {
params: {
token: rowOut.token,
dedup_object: rowOut.dedup_object,
data_format: rowOut.data_format,
notes: inputNotes.value
}
}).then(res => {
if (res.data.result == "ok") {
@@ -191,6 +224,7 @@ const checkPassword = () => {
:value="item.value"
/>
</el-select>
<el-input v-model="inputNotes" style="width: 200px" placeholder="请输入备注"/>
<el-button type="primary" @click="addToken">添加Token</el-button>
<!--Token列表-->
@@ -198,11 +232,13 @@ const checkPassword = () => {
<el-table-column prop="token" label="Token" width="150"/>
<el-table-column prop="dedup_object" label="去重对象" width="150"/>
<el-table-column prop="data_format" label="上传数据格式" width="280"/>
<el-table-column prop="notes" label="备注" width="200"/>
<el-table-column label="操作">
<template #default="scope">
<el-button @click="viewDetails(scope.row)">查看详细</el-button>
<el-button @click="dialogDedupObjectVisible(scope.row)" type="primary">更改去重对象</el-button>
<el-button @click="dialogDataFormatVisible(scope.row)" type="primary">更改数据格式</el-button>
<el-button @click="dialogNotesVisible(scope.row)" type="primary">更改备注</el-button>
<el-popconfirm
width="180"
title="确认删除此Token吗"
@@ -248,6 +284,15 @@ const checkPassword = () => {
</el-button>
</template>
</el-dialog>
<el-dialog v-model="NotesVisible" title="更改备注" width="400">
<el-input v-model="inputNotes" style="width: 200px" placeholder="请输入备注"/>
<template #footer>
<el-button type="primary" @click="updateNotes">
确定
</el-button>
</template>
</el-dialog>
</div>
</template>