更改企业微信发送方式
This commit is contained in:
@@ -236,7 +236,10 @@ export default {
|
|||||||
// 创建一个临时div来提取纯文本
|
// 创建一个临时div来提取纯文本
|
||||||
const tempDiv = document.createElement('div')
|
const tempDiv = document.createElement('div')
|
||||||
tempDiv.innerHTML = this.form.content
|
tempDiv.innerHTML = this.form.content
|
||||||
const plainText = tempDiv.textContent || tempDiv.innerText || ''
|
// 将可能存在的 a 标签转换为 markdown 链接,其他标签去除
|
||||||
|
const html = this.form.content || ''
|
||||||
|
const md = this.convertHtmlLinkToMarkdown(html)
|
||||||
|
const plainText = md !== null ? md : (tempDiv.textContent || tempDiv.innerText || '')
|
||||||
|
|
||||||
// 提取标题的纯文本
|
// 提取标题的纯文本
|
||||||
const titleDiv = document.createElement('div')
|
const titleDiv = document.createElement('div')
|
||||||
@@ -244,8 +247,8 @@ export default {
|
|||||||
const plainTitle = titleDiv.textContent || titleDiv.innerText || ''
|
const plainTitle = titleDiv.textContent || titleDiv.innerText || ''
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
title: plainTitle, // 添加标题字段
|
title: plainTitle,
|
||||||
content: plainText, // 使用纯文本
|
content: plainText,
|
||||||
selectedGrades: this.form.selectedGrades
|
selectedGrades: this.form.selectedGrades
|
||||||
}
|
}
|
||||||
sendNotificationByGrades(data).then(response => {
|
sendNotificationByGrades(data).then(response => {
|
||||||
@@ -268,6 +271,32 @@ export default {
|
|||||||
this.$modal.msgSuccess('删除成功')
|
this.$modal.msgSuccess('删除成功')
|
||||||
}).catch(() => { })
|
}).catch(() => { })
|
||||||
},
|
},
|
||||||
|
convertHtmlLinkToMarkdown(html){
|
||||||
|
const lower = (html || '').toLowerCase()
|
||||||
|
if (!lower.includes('<a')) return null
|
||||||
|
try{
|
||||||
|
const aStart = lower.indexOf('<a')
|
||||||
|
const hrefStart = lower.indexOf('href', aStart)
|
||||||
|
if (hrefStart < 0) return null
|
||||||
|
const dq = lower.indexOf('"', hrefStart)
|
||||||
|
const sq = lower.indexOf("'", hrefStart)
|
||||||
|
let qs=-1, qe=-1
|
||||||
|
if (dq>=0 && (sq<0 || dq<sq)) { qs=dq; qe=lower.indexOf('"', dq+1) }
|
||||||
|
else if (sq>=0) { qs=sq; qe=lower.indexOf("'", sq+1) }
|
||||||
|
if (qs<0 || qe<0) return null
|
||||||
|
const url = html.substring(qs+1, qe).trim()
|
||||||
|
const textStart = lower.indexOf('>', qe)+1
|
||||||
|
const textEnd = lower.indexOf('</a>', textStart)
|
||||||
|
if (textStart<=0 || textEnd<=textStart) return null
|
||||||
|
const text = html.substring(textStart, textEnd).trim()
|
||||||
|
const before = html.substring(0, aStart).replace(/<[^>]+>/g, '')
|
||||||
|
const after = html.substring(textEnd+4).replace(/<[^>]+>/g, '')
|
||||||
|
const mdLink = `[${text || url}](${url})`
|
||||||
|
return before + mdLink + after
|
||||||
|
}catch(e){
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
},
|
||||||
/** 导出按钮操作 */
|
/** 导出按钮操作 */
|
||||||
handleExport() {
|
handleExport() {
|
||||||
this.download('NotificationManagement/NotificationManagement/export', {
|
this.download('NotificationManagement/NotificationManagement/export', {
|
||||||
|
|||||||
Reference in New Issue
Block a user