fix:bug
This commit is contained in:
@@ -127,6 +127,11 @@
|
||||
</div>
|
||||
<script>
|
||||
const $ = (id) => document.getElementById(id);
|
||||
const escapeHtml = (s) => {
|
||||
if (s == null) return '';
|
||||
const t = String(s);
|
||||
return t.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
};
|
||||
// 相对路径,由 Node 代理到后端,适配 -p/-b 任意端口
|
||||
const API_BASE = '';
|
||||
const KEY_STORAGE = 'wechat_key';
|
||||
@@ -171,13 +176,16 @@
|
||||
const isUrl = (s) => typeof s === 'string' && /^https?:\/\//i.test(s.trim());
|
||||
const isBase64Like = (s) => typeof s === 'string' && /^[A-Za-z0-9+/=\s]+$/.test(s) && s.replace(/\s+/g, '').length > 60;
|
||||
|
||||
// 图片:上游通常提供 ImageContent(base64)或 Content 为图片链接
|
||||
// 图片:上游通常提供 ImageContent(base64)或 Content 为图片链接;无法解读时保留原样
|
||||
if (imageContent || (msgType === 3) || (msgType === 0 && imageContent)) {
|
||||
const src = isUrl(imageContent) ? imageContent :
|
||||
(imageContent ? ('data:image/png;base64,' + imageContent.replace(/\s+/g, '')) :
|
||||
(isUrl(rawContent) ? rawContent : ''));
|
||||
if (src) {
|
||||
return `<div class="content"><div>${rawContent ? String(rawContent) : ''}</div><img src="${src}" alt="图片消息" /></div>`;
|
||||
const fallback = escapeHtml(rawContent ? String(rawContent).slice(0, 200) : '[图片无法显示]');
|
||||
return '<div class="content">' + (rawContent ? '<div>' + escapeHtml(rawContent) + '</div>' : '') +
|
||||
'<img src="' + src.replace(/"/g, '"') + '" alt="图片消息" onerror="this.style.display=\'none\';var s=this.nextElementSibling;if(s)s.style.display=\'\';" />' +
|
||||
'<span class="img-fallback small-label" style="display:none">' + fallback + '</span></div>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,15 +205,16 @@
|
||||
return `<div class="content"><a href="${safe}" target="_blank" rel="noopener noreferrer">${safe}</a></div>`;
|
||||
}
|
||||
|
||||
// 若内容看起来是图片 base64,则按图片渲染
|
||||
if (isBase64Like(rawContent) && (msgType === 3 || msgType === 0)) {
|
||||
// 若内容看起来是图片 base64,则按图片渲染;无法解读时维持原样
|
||||
if (isBase64Like(rawContent) && (msgType === 3 || msgType === 0 || !msgType)) {
|
||||
const src = 'data:image/png;base64,' + String(rawContent).replace(/\s+/g, '');
|
||||
return `<div class="content"><img src="${src}" alt="图片消息" /></div>`;
|
||||
const fallback = escapeHtml(String(rawContent).slice(0, 80) + (rawContent.length > 80 ? '…' : ''));
|
||||
return '<div class="content"><img src="' + src.replace(/"/g, '"') + '" alt="图片消息" onerror="this.style.display=\'none\';var s=this.nextElementSibling;if(s)s.style.display=\'\';" /><span class="img-fallback small-label" style="display:none">' + fallback + '</span></div>';
|
||||
}
|
||||
|
||||
// 兜底为纯文本(含 MsgType 提示)
|
||||
const text = rawContent ? String(rawContent) : (msgType != null ? `MsgType=${msgType}` : '');
|
||||
return `<div class="content">${text}</div>`;
|
||||
const text = rawContent ? String(rawContent) : (msgType != null ? 'MsgType=' + msgType : '');
|
||||
return '<div class="content">' + escapeHtml(text) + '</div>';
|
||||
}
|
||||
|
||||
async function loadMessages() {
|
||||
@@ -235,11 +244,13 @@
|
||||
});
|
||||
$('message-list').innerHTML = list.length ? list.map(m => {
|
||||
const isOut = m.direction === 'out';
|
||||
const fromLabel = isOut ? ('我 → ' + (m.ToUserName || '')) : (m.FromUserName || m.from || m.MsgId || '-').toString().slice(0, 32);
|
||||
const toDisplay = m.ToDisplayName || m.ToUserName || '';
|
||||
const fromDisplay = m.FromDisplayName || m.FromUserName || m.from || m.MsgId || '-';
|
||||
const fromLabel = isOut ? ('我 → ' + toDisplay) : String(fromDisplay).slice(0, 48);
|
||||
const time = m.CreateTime ? (typeof m.CreateTime === 'number'
|
||||
? new Date(m.CreateTime * 1000).toLocaleTimeString('zh-CN', { hour12: false })
|
||||
: m.CreateTime) : '';
|
||||
const meta = '<div class="meta"><span class="from">' + fromLabel + '</span>' + (time ? '<span class="time">' + time + '</span>' : '') + '</div>';
|
||||
const meta = '<div class="meta"><span class="from">' + escapeHtml(fromLabel) + '</span>' + (time ? '<span class="time">' + time + '</span>' : '') + '</div>';
|
||||
const body = renderMessageContent(m);
|
||||
return '<div class="msg-item' + (isOut ? ' out' : '') + '">' + meta + body + '</div>';
|
||||
}).join('') : '<p class="small-label">暂无对话。请确保已登录且后端 WS 已连接 GetSyncMsg;发送的消息(含图片、音视频等)也会在此展示。</p>';
|
||||
|
||||
@@ -93,6 +93,11 @@
|
||||
.tags-chips .chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); border: 1px solid var(--accent); font-size: 12px; color: var(--accent); }
|
||||
.tags-chips .chip button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 14px; line-height: 1; }
|
||||
.tags-chips .chip button:hover { color: var(--text); }
|
||||
.img-send-progress .img-send-bar { height: 10px; background: var(--border); border-radius: 6px; overflow: hidden; }
|
||||
.img-send-progress .img-send-fill { height: 100%; background: var(--accent); border-radius: 6px; width: 0%; transition: width 0.25s ease; }
|
||||
.img-send-progress .img-send-text { font-size: 12px; color: var(--muted); margin-top: 6px; }
|
||||
.img-send-progress.is-error .img-send-text { color: #f87171; }
|
||||
.img-send-progress.is-done .img-send-text { color: var(--accent); }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -165,7 +170,7 @@
|
||||
<label>选择接收人(从好友/客户列表)</label>
|
||||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap;">
|
||||
<button type="button" class="secondary" id="btn-load-friends" style="padding:4px 10px;font-size:12px">加载联系人</button>
|
||||
<button type="button" class="secondary" id="btn-load-customers-mass" style="padding:4px 10px;font-size:12px" title="从客户档案加载,与联系人合并去重">加载客户</button>
|
||||
<button type="button" class="secondary" id="btn-load-customers-mass" style="padding:4px 10px;font-size:12px" title="从客户档案加载,替换为仅客户列表">加载客户</button>
|
||||
<span id="mass-selected-count" class="small-label">已选 0 人</span>
|
||||
</div>
|
||||
<div id="mass-friend-list" style="max-height:200px;overflow-y:auto;border:1px solid var(--border);border-radius:8px;padding:8px;margin-top:6px;background:rgba(15,23,42,0.6)"></div>
|
||||
@@ -174,8 +179,9 @@
|
||||
<button type="button" class="primary" id="btn-mass-send">一键群发</button>
|
||||
</div>
|
||||
<div class="small-label" style="margin-top:16px;margin-bottom:8px">发送图片消息(快捷方式)</div>
|
||||
<p class="small-label" style="margin-bottom:8px">接收人:可从上方「选择接收人」勾选联系人/客户,或在下框填写 wxid(多人用逗号或换行分隔)</p>
|
||||
<div class="mgmt-form-grid">
|
||||
<div class="field"><label>接收人 wxid</label><input id="img-to-user" placeholder="zhang499142409" /></div>
|
||||
<div class="field full"><label>接收人 wxid(可选,与上方勾选合并)</label><input id="img-to-user" placeholder="zhang499142409 或 多人逗号/换行分隔" /></div>
|
||||
<div class="field full">
|
||||
<label>图片内容(base64 / URL / 本地图片)</label>
|
||||
<input id="img-content" placeholder="粘贴 base64、图片 URL,或从下方选择本地图片" />
|
||||
@@ -186,6 +192,10 @@
|
||||
</div>
|
||||
<div class="field full"><label>附带文字(可选)</label><input id="img-text" placeholder="可选" /></div>
|
||||
<button type="button" class="primary" id="btn-send-image">发送图片</button>
|
||||
<div id="img-send-progress" class="img-send-progress" style="display:none;margin-top:12px;">
|
||||
<div class="img-send-bar"><div class="img-send-fill" id="img-send-fill"></div></div>
|
||||
<div class="img-send-text small-label" id="img-send-text"></div>
|
||||
</div>
|
||||
</div>
|
||||
<hr style="border:0;border-top:1px solid var(--border);margin:20px 0" />
|
||||
<div class="small-label">商品标签</div>
|
||||
@@ -206,7 +216,7 @@
|
||||
<div id="push-task-list"></div>
|
||||
</div>
|
||||
<div id="panel-ai-reply" class="mgmt-panel">
|
||||
<p class="small-label" style="margin-bottom:12px">分级处理:仅<strong>超级管理员</strong>与<strong>白名单</strong>中的联系人会收到 AI 自动回复,其他消息一律不回复。</p>
|
||||
<p class="small-label" style="margin-bottom:12px">分级处理:仅<strong>超级管理员</strong>与<strong>白名单</strong>中的联系人会收到 AI 自动回复,其他消息一律不回复。<br />白名单<strong>不能</strong>调用 function call(如代发消息);<strong>仅超级管理员</strong>可使用代发消息等操作。</p>
|
||||
<div class="field full" style="margin-bottom:12px">
|
||||
<span class="small-label">AI 接管状态:</span>
|
||||
<span id="ai-reply-status-text">—</span>
|
||||
@@ -216,10 +226,12 @@
|
||||
<div class="field full">
|
||||
<label>超级管理员 wxid(每行一个或逗号分隔)</label>
|
||||
<textarea id="ai-super-admin" rows="3" placeholder="zhang499142409 wxid_xxx"></textarea>
|
||||
<span class="small-label" style="display:block;margin-top:4px">可收到 AI 回复且可调用代发消息等 function call</span>
|
||||
</div>
|
||||
<div class="field full">
|
||||
<label>白名单 wxid(可收到 AI 回复的联系人,每行一个或逗号分隔)</label>
|
||||
<textarea id="ai-whitelist" rows="4" placeholder="wxid_abc wxid_def"></textarea>
|
||||
<span class="small-label" style="display:block;margin-top:4px">仅可正常聊天获得回复,不能调用代发消息等 function call</span>
|
||||
</div>
|
||||
<button type="button" class="primary" id="btn-ai-reply-save">保存配置</button>
|
||||
</div>
|
||||
@@ -667,6 +679,7 @@
|
||||
const name = (f.remark_name || f.RemarkName || f.nick_name || f.NickName || wxid).toString();
|
||||
return { wxid, name, source: 'friend' };
|
||||
}).filter(f => f.wxid);
|
||||
massSelectedWxids = [];
|
||||
if (!massContactList.length) {
|
||||
el.innerHTML = '<span class="small-label">暂无联系人。可点击「加载客户」从客户档案选择。</span>';
|
||||
return;
|
||||
@@ -681,31 +694,22 @@
|
||||
const key = $('key').value.trim();
|
||||
if (!key) { alert('请先登录'); return; }
|
||||
const el = $('mass-friend-list');
|
||||
const wasEmpty = !massContactList.length;
|
||||
if (wasEmpty) el.innerHTML = '<span class="small-label">加载中…</span>';
|
||||
el.innerHTML = '<span class="small-label">加载中…</span>';
|
||||
try {
|
||||
const data = await callApi('/api/customers?key=' + encodeURIComponent(key));
|
||||
const list = data.items || [];
|
||||
const existingWxids = new Set(massContactList.map(f => f.wxid));
|
||||
list.forEach(c => {
|
||||
massContactList = list.map(c => {
|
||||
const wxid = (c.wxid || '').toString();
|
||||
if (!wxid) return;
|
||||
if (existingWxids.has(wxid)) return;
|
||||
existingWxids.add(wxid);
|
||||
massContactList.push({
|
||||
wxid,
|
||||
name: (c.remark_name || c.wxid || wxid).toString(),
|
||||
source: 'customer'
|
||||
});
|
||||
});
|
||||
return { wxid, name: (c.remark_name || c.wxid || wxid).toString(), source: 'customer' };
|
||||
}).filter(f => f.wxid);
|
||||
if (!massContactList.length) {
|
||||
el.innerHTML = '<span class="small-label">暂无客户。请先在「客户档案」添加客户,或点击「加载联系人」获取好友列表。</span>';
|
||||
return;
|
||||
}
|
||||
massSelectedWxids = [];
|
||||
renderMassContactList();
|
||||
} catch (e) {
|
||||
if (wasEmpty) el.innerHTML = '<span class="small-label">加载失败: ' + escapeHtml(e.message) + '</span>';
|
||||
else alert('加载客户失败: ' + e.message);
|
||||
el.innerHTML = '<span class="small-label">加载失败: ' + escapeHtml(e.message) + '</span>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -769,35 +773,74 @@
|
||||
if (isImageUrl(textInput)) return await urlToBase64(textInput);
|
||||
return stripDataUrlPrefix(textInput);
|
||||
}
|
||||
function parseWxidsFromInput(raw) {
|
||||
return (raw || '').trim().split(/[\n,,\s]+/).map(s => s.trim()).filter(Boolean);
|
||||
}
|
||||
function showImgSendProgress(visible, current, total, text, isError, isDone) {
|
||||
const wrap = $('img-send-progress');
|
||||
const fill = $('img-send-fill');
|
||||
const txt = $('img-send-text');
|
||||
if (!wrap || !fill || !txt) return;
|
||||
wrap.style.display = visible ? 'block' : 'none';
|
||||
wrap.classList.remove('is-error', 'is-done');
|
||||
if (isError) wrap.classList.add('is-error');
|
||||
if (isDone) wrap.classList.add('is-done');
|
||||
const pct = total ? Math.round((current / total) * 100) : 0;
|
||||
fill.style.width = pct + '%';
|
||||
txt.textContent = text || (total ? '已发送 ' + current + ' / ' + total : '');
|
||||
}
|
||||
async function doSendImage() {
|
||||
const key = getKey();
|
||||
if (!key) return;
|
||||
const toUser = $('img-to-user').value.trim();
|
||||
if (!toUser) { alert('请填写接收人 wxid'); return; }
|
||||
let imageContent;
|
||||
try {
|
||||
imageContent = await resolveImageContentToBase64();
|
||||
} catch (e) {
|
||||
alert('解析图片失败: ' + (e.message || e));
|
||||
if (!key) {
|
||||
showImgSendProgress(true, 0, 0, '请先登录', true, false);
|
||||
return;
|
||||
}
|
||||
if (!imageContent) { alert('请填写或选择图片内容(base64、URL 或本地图片)'); return; }
|
||||
const manualWxids = parseWxidsFromInput($('img-to-user') && $('img-to-user').value);
|
||||
const wxids = [...new Set([...massSelectedWxids, ...manualWxids])].filter(Boolean);
|
||||
if (!wxids.length) {
|
||||
showImgSendProgress(true, 0, 0, '请在上方勾选接收人,或填写接收人 wxid(多人逗号/换行分隔)', true, false);
|
||||
return;
|
||||
}
|
||||
let imageContent;
|
||||
try {
|
||||
await callApi('/api/send-image', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
key,
|
||||
to_user_name: toUser,
|
||||
image_content: imageContent,
|
||||
text_content: ($('img-text').value || '').trim()
|
||||
})
|
||||
});
|
||||
alert('图片已发送');
|
||||
showImgSendProgress(true, 0, wxids.length, '正在解析图片…', false, false);
|
||||
imageContent = await resolveImageContentToBase64();
|
||||
} catch (e) {
|
||||
showImgSendProgress(true, 0, wxids.length, '解析图片失败: ' + (e.message || e), true, false);
|
||||
return;
|
||||
}
|
||||
if (!imageContent) {
|
||||
showImgSendProgress(true, 0, 0, '请填写或选择图片内容(base64、URL 或本地图片)', true, false);
|
||||
return;
|
||||
}
|
||||
const textContent = ($('img-text').value || '').trim();
|
||||
const total = wxids.length;
|
||||
let sent = 0;
|
||||
try {
|
||||
for (let i = 0; i < wxids.length; i++) {
|
||||
showImgSendProgress(true, i, total, '发送中 ' + (i + 1) + ' / ' + total + '…', false, false);
|
||||
if (i > 0) await new Promise(r => setTimeout(r, 1000));
|
||||
await callApi('/api/send-image', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
key,
|
||||
to_user_name: wxids[i],
|
||||
image_content: imageContent,
|
||||
text_content: textContent
|
||||
})
|
||||
});
|
||||
sent = i + 1;
|
||||
showImgSendProgress(true, sent, total, '已发送 ' + sent + ' / ' + total, false, false);
|
||||
}
|
||||
showImgSendProgress(true, total, total, '已发送至 ' + total + ' 人', false, true);
|
||||
$('img-content').value = '';
|
||||
if ($('img-file')) $('img-file').value = '';
|
||||
if ($('img-file-name')) $('img-file-name').textContent = '';
|
||||
$('img-text').value = '';
|
||||
} catch (e) { alert('发送图片失败: ' + (e.message || e)); }
|
||||
setTimeout(function() { showImgSendProgress(false); }, 3000);
|
||||
} catch (e) {
|
||||
showImgSendProgress(true, sent, total, '发送失败(已发送 ' + sent + ' / ' + total + '): ' + (e.message || e), true, false);
|
||||
}
|
||||
}
|
||||
|
||||
async function doPushSend() {
|
||||
|
||||
Reference in New Issue
Block a user