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============
ErrorCode MATERIAL_UPLOAD_FAIL = new ErrorCode(1006004000, "上传素材失败,原因:{}");
// ========== 公众号素材 1006005000============
ErrorCode MESSAGE_SEND_FAIL = new ErrorCode(1006005000, "发送消息失败,原因:{}");
// TODO 要处理下
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.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());
}
// 记录消息

View File

@ -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
})

View File

@ -85,9 +85,9 @@
<el-tab-pane name="video">
<span slot="label"><i class="el-icon-share"></i> 视频</span>
<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>
<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="text-align: center;">
<wx-video-player v-if="objData.url" :url="objData.url" />
@ -149,9 +149,9 @@
</el-col>
</el-row>
<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>
<el-input v-model="objData.hqMusicUrl" placeholder="请输入高质量音乐链接"></el-input>
<el-input v-model="objData.hqMusicUrl" placeholder="请输入高质量音乐链接" @input="inputContent" />
</el-tab-pane>
</el-tabs>
</template>
@ -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
// titleintroductionmusicUrlhqMusicUrl
tempObjItem.title = this.objData.title
tempObjItem.introduction = this.objData.introduction
tempObjItem.musicUrl = this.objData.musicUrl
tempObjItem.hqMusicUrl = this.objData.hqMusicUrl
// titleintroductionmusicUrlhqMusicUrl 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
// titleintroduction
this.objData.title = item.title
tempObjItem.title = this.objData.title
this.objData.description = item.introduction // 使 description使 introduction
tempObjItem.description = this.objData.introduction
// titleintroduction item tempObjItem titleintroduction
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));
}
}
};