mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-28 13:31:04 +00:00
fix(通知日志): 发送记录写入渲染后的标题与正文,详情展示可读文案
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
0b253b6058
commit
9f476fd7c2
@ -13,6 +13,7 @@ use app\services\message\admin\NoticeLogServices;
|
||||
use app\services\message\pipeline\SendNoticeService;
|
||||
use crmeb\exceptions\NoticeSendException;
|
||||
use crmeb\plugin\ModuleStateChecker;
|
||||
use crmeb\services\notice\AbstractNoticeChannel;
|
||||
use crmeb\services\notice\NoticeChannelInterface;
|
||||
use crmeb\services\notice\NoticeMessage;
|
||||
use think\facade\Log;
|
||||
@ -311,13 +312,16 @@ class Notice
|
||||
{
|
||||
try {
|
||||
$message = $target['message'];
|
||||
// 日志展示实际发出的文案,写入前用业务变量渲染模板占位符
|
||||
$title = AbstractNoticeChannel::renderTemplate($message->title, $message->variables);
|
||||
$content = AbstractNoticeChannel::renderTemplate($message->content, $message->variables);
|
||||
$logId = $this->logServices()->createLog(
|
||||
$message->mark,
|
||||
$message->uid,
|
||||
$target['channel_key'],
|
||||
$target['channel_name'],
|
||||
$message->title,
|
||||
$message->content
|
||||
$title,
|
||||
$content
|
||||
);
|
||||
if ($ok) {
|
||||
$this->logServices()->logSuccess($logId);
|
||||
|
||||
@ -69,12 +69,13 @@ abstract class AbstractNoticeChannel implements NoticeChannelInterface
|
||||
*
|
||||
* 值统一转 string,避免 int 参数触发 str_replace TypeError;
|
||||
* 非标量值(数组/对象)跳过不参与替换。
|
||||
* 静态入口供写发送日志等非渠道场景复用,与实例方法行为一致。
|
||||
*
|
||||
* @param string $text 模板文本(含 {key} 占位符)
|
||||
* @param array $variables 扁平业务变量
|
||||
* @return string
|
||||
*/
|
||||
protected function renderPlaceholders(string $text, array $variables): string
|
||||
public static function renderTemplate(string $text, array $variables): string
|
||||
{
|
||||
if ($text === '' || empty($variables)) {
|
||||
return $text;
|
||||
@ -87,4 +88,16 @@ abstract class AbstractNoticeChannel implements NoticeChannelInterface
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实例侧占位符渲染(委托静态实现,保持子类调用习惯)
|
||||
*
|
||||
* @param string $text 模板文本(含 {key} 占位符)
|
||||
* @param array $variables 扁平业务变量
|
||||
* @return string
|
||||
*/
|
||||
protected function renderPlaceholders(string $text, array $variables): string
|
||||
{
|
||||
return static::renderTemplate($text, $variables);
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,44 +152,34 @@
|
||||
</el-row>
|
||||
</el-card>
|
||||
|
||||
<el-dialog title="发送记录详情" v-model="dialogVisible" width="700px">
|
||||
<el-form :model="detailData" label-width="100px" disabled>
|
||||
<el-form-item label="ID">
|
||||
<span>{{ detailData.id }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="消息标识">
|
||||
<span>{{ detailData.mark }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="用户ID">
|
||||
<span>{{ detailData.uid || '-' }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="渠道">
|
||||
<span>{{ detailData.channel_name || detailData.channel_key }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="标题">
|
||||
<span>{{ detailData.title || '-' }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="内容">
|
||||
<textarea :value="detailData.content || ''" :rows="6" readonly class="detail-textarea" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-tag :type="detailData.status === 1 ? 'success' : detailData.status === 2 ? 'danger' : 'warning'">
|
||||
<el-dialog title="发送记录详情" v-model="dialogVisible" width="640px" destroy-on-close>
|
||||
<el-descriptions v-if="detailData.id" :column="2" border>
|
||||
<el-descriptions-item label="ID">{{ detailData.id }}</el-descriptions-item>
|
||||
<el-descriptions-item label="用户ID">{{ detailData.uid || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="消息标识">{{ detailData.mark || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="渠道">{{ detailData.channel_name || detailData.channel_key || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="标题" :span="2">{{ detailData.title || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="内容" :span="2">
|
||||
<div class="detail-content">{{ detailData.content || '-' }}</div>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag :type="detailData.status === 1 ? 'success' : detailData.status === 2 ? 'danger' : 'warning'" size="small">
|
||||
{{ detailData.status === 1 ? '成功' : detailData.status === 2 ? '失败' : '待发送' }}
|
||||
</el-tag>
|
||||
</el-form-item>
|
||||
<el-form-item label="发送时间">
|
||||
<span>{{ detailData.send_time ? formatDate(detailData.send_time) : '-' }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="错误信息">
|
||||
<span class="error-msg" v-if="detailData.error_msg">{{ detailData.error_msg }}</span>
|
||||
<span v-else>-</span>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer
|
||||
><div class="dialog-footer">
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="发送时间">
|
||||
{{ detailData.send_time ? formatDate(detailData.send_time) : '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="错误信息" :span="2">
|
||||
<span v-if="detailData.error_msg" class="error-msg">{{ detailData.error_msg }}</span>
|
||||
<span v-else>—</span>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="dialogVisible = false">关闭</el-button>
|
||||
</div></template
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog title="清理日志" v-model="cleanVisible" width="400px">
|
||||
@ -374,17 +364,17 @@ getStatistics();
|
||||
}
|
||||
}
|
||||
.error-msg {
|
||||
color: #f56c6c;
|
||||
color: var(--prev-color-danger, #f56c6c);
|
||||
font-size: 12px;
|
||||
word-break: break-all;
|
||||
}
|
||||
.detail-textarea {
|
||||
width: 100%;
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 4px;
|
||||
padding: 10px;
|
||||
resize: none;
|
||||
.detail-content {
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
line-height: 1.6;
|
||||
color: var(--prev-color-text-regular);
|
||||
}
|
||||
.warning-text {
|
||||
color: #f56c6c;
|
||||
color: var(--prev-color-danger, #f56c6c);
|
||||
}
|
||||
</style>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user