From 71a14cca67b0063a31b3550bda0efc99c7030aa1 Mon Sep 17 00:00:00 2001 From: engigu Date: Sun, 21 Jan 2024 00:54:02 +0800 Subject: [PATCH] feat: adjust add task --- models/send_ways.go | 9 +++ routers/api/v1/send_ways.go | 2 +- service/send_way_service/send_way.go | 7 +++ .../tabsTools/sendTasks/view/addTaskPopUp.vue | 60 ++++++++++++------- 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/models/send_ways.go b/models/send_ways.go index 1367864..4d00b6a 100644 --- a/models/send_ways.go +++ b/models/send_ways.go @@ -92,6 +92,15 @@ func GetWayByID(id string) (SendWays, error) { return way, nil } +func GetWayByName(name string) (SendWays, error) { + var way SendWays + err := db.Where("name = ? ", name).Find(&way).Error + if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { + return way, err + } + return way, nil +} + func DeleteMsgWay(id string) error { if err := db.Where("id = ?", id).Delete(&SendWays{}).Error; err != nil { return err diff --git a/routers/api/v1/send_ways.go b/routers/api/v1/send_ways.go index 66f1435..1abb9f5 100644 --- a/routers/api/v1/send_ways.go +++ b/routers/api/v1/send_ways.go @@ -129,7 +129,7 @@ func AddMsgSendWay(c *gin.Context) { err := sendWayService.Add() if err != nil { - appG.CResponse(http.StatusBadRequest, "添加渠道失败!", nil) + appG.CResponse(http.StatusBadRequest, fmt.Sprintf("添加渠道失败!原因:%s", err), nil) return } diff --git a/service/send_way_service/send_way.go b/service/send_way_service/send_way.go index 05ebe8f..70b4ff3 100644 --- a/service/send_way_service/send_way.go +++ b/service/send_way_service/send_way.go @@ -54,6 +54,13 @@ func (sw *SendWay) GetByID() (interface{}, error) { } func (sw *SendWay) Add() error { + way, err := models.GetWayByName(sw.Name) + if err != nil { + return err + } + if len(way.ID) > 0 { + return errors.New(fmt.Sprintf("已经存在同名的渠道名:%s", way.Name)) + } return models.AddSendWay(sw.Name, sw.Auth, sw.Type, sw.CreatedBy, sw.ModifiedBy) } diff --git a/web/src/views/tabsTools/sendTasks/view/addTaskPopUp.vue b/web/src/views/tabsTools/sendTasks/view/addTaskPopUp.vue index 43a14b0..8591c12 100644 --- a/web/src/views/tabsTools/sendTasks/view/addTaskPopUp.vue +++ b/web/src/views/tabsTools/sendTasks/view/addTaskPopUp.vue @@ -25,9 +25,8 @@
- - 查询 +
@@ -47,7 +46,7 @@
+ style="width: 200px; margin: 10px 40px 5px 0;">
@@ -114,6 +113,8 @@ export default defineComponent({ const pageState = usePageState(); const state = reactive({ insTableData: [], + currSearchWaysData: [], + currSearchInputText: '', isShow: false, isShowAddBox: false, searchWayID: '', @@ -173,19 +174,40 @@ export default defineComponent({ state.insTableData.push(insData); } - const searchID = async () => { - const rsp = await request.get('/sendways/get', { params: { id: state.searchWayID } }); - let data = await rsp.data; - state.isShowAddBox = Boolean(data.data); - if (data.data) { - state.currWayTmp = data.data; + // 匹配出当前搜索的渠道数据 + const matchSearchData = (way_name) => { + let result = {}; + state.currSearchWaysData.forEach(element => { + if (element.name == way_name) { + result = element; + } + }); + return result; + } + + const handleSearchSelect = async () => { + let currWay = matchSearchData(state.currSearchInputText) + state.isShowAddBox = Boolean(currWay); + if (currWay) { + state.currWayTmp = currWay; // 初始化currInsInput - CONSTANT.WAYS_DATA_MAP[data.data.type].taskInsInputs.forEach(element => { + CONSTANT.WAYS_DATA_MAP[currWay.type].taskInsInputs.forEach(element => { state.currInsInput[element.col] = "" }); } } + const querySearchWayAsync = async (query, cb) => { + let params = { name: query }; + const rsp = await request.get('/sendways/list', { params: params }); + let tableData = await rsp.data.data.lists; + tableData.forEach(element => { + element.value = element.name + }); + cb(tableData); + state.currSearchWaysData = tableData; + } + const getFinalData = () => { let postData = { id: state.currTaskInput.taskId, name: state.currTaskInput.taskName } postData.ins_data = state.insTableData @@ -201,13 +223,9 @@ export default defineComponent({ } } - // const formatExtraInfo = (scope) => { - // return CommonUtils.formatInsConfigDisplay(scope); - // } - return { - ...toRefs(state), handleCancer, handleSubmit, - searchID, CONSTANT, CommonUtils, + ...toRefs(state), handleCancer, handleSubmit, querySearchWayAsync, + handleSearchSelect, CONSTANT, CommonUtils, clickStore, insRowStyle }; }, @@ -241,16 +259,12 @@ export default defineComponent({ flex: 55%; } -.searchInput { - max-width: 200px; +:deep(.el-autocomplete) { + width: 200px; } -.wayTitleInput { - max-width: 200px; -} .taskNameInput { - /* width: 80%; */ max-width: 200px; }