mp:优化前端消息发送的缓存逻辑

This commit is contained in:
YunaiV 2023-01-12 20:25:00 +08:00
parent 7ba6a2e385
commit 858b4e81a5
4 changed files with 59 additions and 36 deletions

View File

@ -34,6 +34,9 @@ public interface ErrorCodeConstants {
// ========== 公众号素材 1006004000============ // ========== 公众号素材 1006004000============
ErrorCode MATERIAL_UPLOAD_FAIL = new ErrorCode(1006004000, "上传素材失败,原因:{}"); ErrorCode MATERIAL_UPLOAD_FAIL = new ErrorCode(1006004000, "上传素材失败,原因:{}");
// ========== 公众号素材 1006005000============
ErrorCode MESSAGE_SEND_FAIL = new ErrorCode(1006005000, "发送消息失败,原因:{}");
// TODO 要处理下 // TODO 要处理下
ErrorCode MENU_NOT_EXISTS = new ErrorCode(1006001002, "菜单不存在"); ErrorCode MENU_NOT_EXISTS = new ErrorCode(1006001002, "菜单不存在");

View File

@ -31,6 +31,9 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Validator; 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 实现类 * 粉丝消息表 Service 实现类
* *
@ -115,7 +118,7 @@ public class MpMessageServiceImpl implements MpMessageService {
try { try {
mpService.getKefuService().sendKefuMessageWithResponse(wxMessage); mpService.getKefuService().sendKefuMessageWithResponse(wxMessage);
} catch (WxErrorException e) { } catch (WxErrorException e) {
throw new RuntimeException(e); throw exception(MESSAGE_SEND_FAIL, e.getError().getErrorMsg());
} }
// 记录消息 // 记录消息

View File

@ -177,10 +177,6 @@ import { getUser } from "@/api/mp/user";
this.scrollToBottom() this.scrollToBottom()
// objData // objData
this.$refs['replySelect'].deleteObj(); // tab this.$refs['replySelect'].deleteObj(); // tab
this.objData = {
type: 'text',
content: '',
}
}).catch(() => { }).catch(() => {
this.sendLoading = false this.sendLoading = false
}) })

View File

@ -85,9 +85,9 @@
<el-tab-pane name="video"> <el-tab-pane name="video">
<span slot="label"><i class="el-icon-share"></i> 视频</span> <span slot="label"><i class="el-icon-share"></i> 视频</span>
<el-row> <el-row>
<el-input v-model="objData.title" placeholder="请输入标题"></el-input> <el-input v-model="objData.title" placeholder="请输入标题" @input="inputContent" />
<div style="margin: 20px 0;"></div> <div style="margin: 20px 0;"></div>
<el-input v-model="objData.description" placeholder="请输入描述"></el-input> <el-input v-model="objData.description" placeholder="请输入描述" @input="inputContent" />
<div style="margin: 20px 0;"></div> <div style="margin: 20px 0;"></div>
<div style="text-align: center;"> <div style="text-align: center;">
<wx-video-player v-if="objData.url" :url="objData.url" /> <wx-video-player v-if="objData.url" :url="objData.url" />
@ -149,9 +149,9 @@
</el-col> </el-col>
</el-row> </el-row>
<div style="margin: 20px 0;"></div> <div style="margin: 20px 0;"></div>
<el-input v-model="objData.musicUrl" placeholder="请输入音乐链接"></el-input> <el-input v-model="objData.musicUrl" placeholder="请输入音乐链接" @input="inputContent" />
<div style="margin: 20px 0;"></div> <div style="margin: 20px 0;"></div>
<el-input v-model="objData.hqMusicUrl" placeholder="请输入高质量音乐链接"></el-input> <el-input v-model="objData.hqMusicUrl" placeholder="请输入高质量音乐链接" @input="inputContent" />
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</template> </template>
@ -309,27 +309,20 @@
// tempObj objData // tempObj objData
let tempObjItem = this.tempObj.get(this.objData.type) 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) { if (tempObjItem) {
console.log(this.tempObj)
this.objData.content = tempObjItem.content ? tempObjItem.content : null this.objData.content = tempObjItem.content ? tempObjItem.content : null
this.objData.mediaId = tempObjItem.mediaId ? tempObjItem.mediaId : null this.objData.mediaId = tempObjItem.mediaId ? tempObjItem.mediaId : null
this.objData.url = tempObjItem.url ? tempObjItem.url : null this.objData.url = tempObjItem.url ? tempObjItem.url : null
this.objData.name = tempObjItem.url ? tempObjItem.name : null this.objData.name = tempObjItem.url ? tempObjItem.name : null
this.objData.title = tempObjItem.title ? tempObjItem.title : null
// TODO this.objData.description = tempObjItem.description ? tempObjItem.description : null
// this.objData.repDesc = tempObjItem.repDesc ? tempObjItem.repDesc : null
return; return;
} }
// objData // objData
this.objData.content = undefined; // 使 $set input
this.objData.mediaId = undefined; this.$set(this.objData, 'content', '');
this.objData.url = undefined; this.$set(this.objData, 'title', '');
this.objData.name = undefined; this.$set(this.objData, 'description', '');
// this.$delete(this.objData,'repDesc')
}, },
/** /**
* 选择素材将设置设置到 objData 变量 * 选择素材将设置设置到 objData 变量
@ -348,11 +341,11 @@
this.objData.thumbMediaId = item.mediaId this.objData.thumbMediaId = item.mediaId
tempObjItem.thumbMediaUrl = item.url tempObjItem.thumbMediaUrl = item.url
this.objData.thumbMediaUrl = item.url this.objData.thumbMediaUrl = item.url
// titleintroductionmusicUrlhqMusicUrl // titleintroductionmusicUrlhqMusicUrl objData tempObjItem
tempObjItem.title = this.objData.title tempObjItem.title = this.objData.title || ''
tempObjItem.introduction = this.objData.introduction tempObjItem.introduction = this.objData.introduction || ''
tempObjItem.musicUrl = this.objData.musicUrl tempObjItem.musicUrl = this.objData.musicUrl || ''
tempObjItem.hqMusicUrl = this.objData.hqMusicUrl tempObjItem.hqMusicUrl = this.objData.hqMusicUrl || ''
} else if (this.objData.type === 'image' } else if (this.objData.type === 'image'
|| this.objData.type === 'voice') { || this.objData.type === 'voice') {
tempObjItem.mediaId = item.mediaId tempObjItem.mediaId = item.mediaId
@ -368,11 +361,13 @@
this.objData.url = item.url; this.objData.url = item.url;
tempObjItem.name = item.name tempObjItem.name = item.name
this.objData.name = item.name this.objData.name = item.name
// titleintroduction // titleintroduction item tempObjItem titleintroduction
this.objData.title = item.title this.objData.title = item.title || ''
tempObjItem.title = this.objData.title tempObjItem.title = item.title || ''
this.objData.description = item.introduction // 使 description使 introduction this.objData.description = item.introduction || '' // 使 description使 introduction
tempObjItem.description = this.objData.introduction tempObjItem.description = item.introduction || ''
} else if (this.objData.type === 'text') {
this.objData.content = item.content || ''
} }
// //
this.tempObj.set(this.objData.type, tempObjItem) this.tempObj.set(this.objData.type, tempObjItem)
@ -398,8 +393,34 @@
this.dialogThumbVisible = false this.dialogThumbVisible = false
}, },
deleteObj() { deleteObj() {
// this.$delete(this.objData, 'url'); TODO reset if (this.objData.type === 'news') {
this.selectMaterial({}) // 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) { getPage(page, params) {
this.tableLoading = true this.tableLoading = true
@ -426,8 +447,8 @@
* why不确定为什么 v-model="objData.content" 不能自动缓存所以通过这样的方式 * why不确定为什么 v-model="objData.content" 不能自动缓存所以通过这样的方式
*/ */
inputContent(str) { inputContent(str) {
let tempObjItem = {...this.objData}; //
this.tempObj.set(this.objData.type, tempObjItem); this.tempObj.set(this.objData.type, Object.assign({}, this.objData));
} }
} }
}; };