From 858b4e81a5298a00d10c648891b81f1149b65818 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 12 Jan 2023 20:25:00 +0800 Subject: [PATCH] =?UTF-8?q?mp=EF=BC=9A=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=8F=91=E9=80=81=E7=9A=84=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/mp/enums/ErrorCodeConstants.java | 3 + .../service/message/MpMessageServiceImpl.java | 5 +- .../src/views/mp/components/wx-msg/main.vue | 4 - .../src/views/mp/components/wx-reply/main.vue | 83 ++++++++++++------- 4 files changed, 59 insertions(+), 36 deletions(-) diff --git a/yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java b/yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java index 1d5c0962e..5587c2482 100644 --- a/yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java +++ b/yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java @@ -34,6 +34,9 @@ public interface ErrorCodeConstants { // ========== 公众号素材 1006004000============ ErrorCode MATERIAL_UPLOAD_FAIL = new ErrorCode(1006004000, "上传素材失败,原因:{}"); + // ========== 公众号素材 1006005000============ + ErrorCode MESSAGE_SEND_FAIL = new ErrorCode(1006005000, "发送消息失败,原因:{}"); + // TODO 要处理下 ErrorCode MENU_NOT_EXISTS = new ErrorCode(1006001002, "菜单不存在"); diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/message/MpMessageServiceImpl.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/message/MpMessageServiceImpl.java index 0bd547c65..3eae66418 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/message/MpMessageServiceImpl.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/message/MpMessageServiceImpl.java @@ -31,6 +31,9 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import javax.validation.Validator; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.MESSAGE_SEND_FAIL; + /** * 粉丝消息表 Service 实现类 * @@ -115,7 +118,7 @@ public class MpMessageServiceImpl implements MpMessageService { try { mpService.getKefuService().sendKefuMessageWithResponse(wxMessage); } catch (WxErrorException e) { - throw new RuntimeException(e); + throw exception(MESSAGE_SEND_FAIL, e.getError().getErrorMsg()); } // 记录消息 diff --git a/yudao-ui-admin/src/views/mp/components/wx-msg/main.vue b/yudao-ui-admin/src/views/mp/components/wx-msg/main.vue index e932644b2..383731d40 100644 --- a/yudao-ui-admin/src/views/mp/components/wx-msg/main.vue +++ b/yudao-ui-admin/src/views/mp/components/wx-msg/main.vue @@ -177,10 +177,6 @@ import { getUser } from "@/api/mp/user"; this.scrollToBottom() // 重置 objData 状态 this.$refs['replySelect'].deleteObj(); // 重置,避免 tab 的数据未清理 - this.objData = { - type: 'text', - content: '', - } }).catch(() => { this.sendLoading = false }) diff --git a/yudao-ui-admin/src/views/mp/components/wx-reply/main.vue b/yudao-ui-admin/src/views/mp/components/wx-reply/main.vue index a085fa389..81e52947a 100644 --- a/yudao-ui-admin/src/views/mp/components/wx-reply/main.vue +++ b/yudao-ui-admin/src/views/mp/components/wx-reply/main.vue @@ -85,9 +85,9 @@ 视频 - +
- +
@@ -149,9 +149,9 @@
- +
- + @@ -309,27 +309,20 @@ // 从 tempObj 临时缓存中,获取对应的数据,并设置回 objData let tempObjItem = this.tempObj.get(this.objData.type) - // console.log(this.objData.type) - // console.log(tempObjItem) - // console.log(this.objData) - // console.log(this.tempObj) if (tempObjItem) { - console.log(this.tempObj) this.objData.content = tempObjItem.content ? tempObjItem.content : null this.objData.mediaId = tempObjItem.mediaId ? tempObjItem.mediaId : null this.objData.url = tempObjItem.url ? tempObjItem.url : null this.objData.name = tempObjItem.url ? tempObjItem.name : null - - // TODO 芋艿:临时注释掉,看看有没用 - // this.objData.repDesc = tempObjItem.repDesc ? tempObjItem.repDesc : null + this.objData.title = tempObjItem.title ? tempObjItem.title : null + this.objData.description = tempObjItem.description ? tempObjItem.description : null return; } // 如果获取不到,需要把 objData 复原 - this.objData.content = undefined; - this.objData.mediaId = undefined; - this.objData.url = undefined; - this.objData.name = undefined; - // this.$delete(this.objData,'repDesc') + // 必须使用 $set 赋值,不然 input 无法输入内容 + this.$set(this.objData, 'content', ''); + this.$set(this.objData, 'title', ''); + this.$set(this.objData, 'description', ''); }, /** * 选择素材,将设置设置到 objData 变量 @@ -348,11 +341,11 @@ this.objData.thumbMediaId = item.mediaId tempObjItem.thumbMediaUrl = item.url this.objData.thumbMediaUrl = item.url - // title、introduction、musicUrl、hqMusicUrl - tempObjItem.title = this.objData.title - tempObjItem.introduction = this.objData.introduction - tempObjItem.musicUrl = this.objData.musicUrl - tempObjItem.hqMusicUrl = this.objData.hqMusicUrl + // title、introduction、musicUrl、hqMusicUrl:从 objData 到 tempObjItem,避免上传素材后,被覆盖掉 + tempObjItem.title = this.objData.title || '' + tempObjItem.introduction = this.objData.introduction || '' + tempObjItem.musicUrl = this.objData.musicUrl || '' + tempObjItem.hqMusicUrl = this.objData.hqMusicUrl || '' } else if (this.objData.type === 'image' || this.objData.type === 'voice') { tempObjItem.mediaId = item.mediaId @@ -368,11 +361,13 @@ this.objData.url = item.url; tempObjItem.name = item.name this.objData.name = item.name - // title、introduction - this.objData.title = item.title - tempObjItem.title = this.objData.title - this.objData.description = item.introduction // 消息使用的是 description,素材使用的是 introduction,所以转换下 - tempObjItem.description = this.objData.introduction + // title、introduction:从 item 到 tempObjItem,因为素材里有 title、introduction + this.objData.title = item.title || '' + tempObjItem.title = item.title || '' + this.objData.description = item.introduction || '' // 消息使用的是 description,素材使用的是 introduction,所以转换下 + tempObjItem.description = item.introduction || '' + } else if (this.objData.type === 'text') { + this.objData.content = item.content || '' } // 最终设置到临时缓存 this.tempObj.set(this.objData.type, tempObjItem) @@ -398,8 +393,34 @@ this.dialogThumbVisible = false }, deleteObj() { - // this.$delete(this.objData, 'url'); TODO 芋艿:重新实现清空;还有 reset - this.selectMaterial({}) // 选择一个空的素材 + if (this.objData.type === 'news') { + this.objData.articles = [] + } else if(this.objData.type === 'image') { + this.objData.mediaId = null + this.objData.url = null + this.objData.name = null + } else if(this.objData.type === 'voice') { + this.objData.mediaId = null + this.objData.url = null + this.objData.name = null + } else if(this.objData.type === 'video') { + this.objData.mediaId = null + this.objData.url = null + this.objData.name = null + this.objData.title = null + this.objData.description = null + } else if(this.objData.type === 'music') { + this.objData.thumbMediaId = null + this.objData.thumbMediaUrl = null + this.objData.title = null + this.objData.description = null + this.objData.musicUrl = null + this.objData.hqMusicUrl = null + } else if(this.objData.type === 'text') { + this.objData.content = null + } + // 覆盖缓存 + this.tempObj.set(this.objData.type, Object.assign({}, this.objData)); }, getPage(page, params) { this.tableLoading = true @@ -426,8 +447,8 @@ * why?不确定为什么 v-model="objData.content" 不能自动缓存,所以通过这样的方式 */ inputContent(str) { - let tempObjItem = {...this.objData}; - this.tempObj.set(this.objData.type, tempObjItem); + // 覆盖缓存 + this.tempObj.set(this.objData.type, Object.assign({}, this.objData)); } } };