1. 设备详情拆分
2. 修改bug
3. 处理未读消息
4. 处理退出销毁ws
5. 限制输入内容
6. 限制修改用户名称 长度
7. 会话列表中 添加等待时间变化
This commit is contained in:
Zy
2026-10-26 16:55:44 +08:00
parent 485759747c
commit 155ec57b30
27 changed files with 1003 additions and 169 deletions

View File

@@ -16,18 +16,38 @@
@onCreated="handleCreated"
/>
</div>
<!-- 底部提示、示例、字数统计 -->
<div v-if="simpleToolbar" class="editor-tip">
<p>请输入标准回复话术,可使用「有序步骤」插入分步指引,例如:</p>
<div class="demo-box">
<ol>
<li>确认设备已通电并处于配网模式(指示灯橙色快闪)</li>
<li>打开APP「我的设备」→ 添加设备,选择对应型号</li>
<li>输入2.4G Wi-Fi密码并等待约30秒完成连接</li>
</ol>
<div class="editor-footer">
<div v-if="simpleToolbar" class="editor-tip">
<p>请输入标准回复话术,可使用「有序步骤」插入分步指引,例如:</p>
<div class="demo-box">
<ol>
<li>确认设备已通电并处于配网模式(指示灯橙色快闪)</li>
<li>打开APP「我的设备」→ 添加设备,选择对应型号</li>
<li>输入2.4G Wi-Fi密码并等待约30秒完成连接</li>
</ol>
</div>
<p>以上为示例格式</p>
<p>支持插入图片与链接;回复中可引用设备型号,帮助用户快速对号入座</p>
</div>
<div class="counter-bar">
<span
:class="{ warn: textCount >= props.maxTextLength, danger: textCount > props.maxTextLength }"
>
纯文本 {{ textCount }}/{{ props.maxTextLength }}
</span>
<span class="divider">|</span>
<span
:class="{ warn: imageCount >= props.maxImageCount, danger: imageCount > props.maxImageCount }"
>
图片 {{ imageCount }}/{{ props.maxImageCount }}
</span>
<span class="divider">|</span>
<span
:class="{ warn: linkCount >= props.maxLinkCount, danger: linkCount > props.maxLinkCount }"
>
链接 {{ linkCount }}/{{ props.maxLinkCount }}
</span>
</div>
<p>以上为示例格式</p>
<p>支持插入图片与链接;回复中可引用设备型号,帮助用户快速对号入座</p>
</div>
</div>
</template>
@@ -39,32 +59,34 @@ import {Editor as WangEditor, Toolbar as EditorToolbar} from '@wangeditor-next/e
import modal from '@/plugins/modal';
import {propTypes} from '@/utils/propTypes';
import {globalHeaders} from '@/utils/request';
import {html2Text} from '@/utils';
import {shallowRef, ref, computed, watch, onBeforeUnmount} from 'vue';
const props = defineProps({
/* 编辑器的内容 */
modelValue: propTypes.string,
/* 高度 */
height: propTypes.number.def(400),
/* 最小高度 */
minHeight: propTypes.number.def(400),
/* 只读 */
readOnly: propTypes.bool.def(false),
/* 图片上传文件大小限制(MB) */
fileSize: propTypes.number.def(5),
/* 视频上传文件大小限制(MB) */
videoSize: propTypes.number.def(100),
/* 类型(base64格式、url格式) */
type: propTypes.string.def('url'),
/* 精简工具栏(仅加粗/有序步骤/图片/链接/清除格式) */
simpleToolbar: propTypes.bool.def(false)
simpleToolbar: propTypes.bool.def(false),
maxTextLength: propTypes.number.def(1000),
maxImageCount: propTypes.number.def(3),
maxLinkCount: propTypes.number.def(5)
});
const emit = defineEmits(['update:modelValue']);
const emit = defineEmits(['update:modelValue', 'countChange']);
const editorRef = shallowRef<IDomEditor>();
const content = ref('');
const wordCount = ref(0);
const textCount = ref(0);
const imageCount = ref(0);
const linkCount = ref(0);
const lastValidHtml = ref('');
const IMG_REGEX = /<img\b[^>]*>/gi;
const A_TAG_REGEX = /<a\b[^>]*>.*?<\/a>/gi;
const baseUrl = import.meta.env.VITE_APP_BASE_API;
const uploadOssUrl = baseUrl + '/resource/oss/upload';
@@ -102,6 +124,19 @@ const toolbarConfig = computed<Partial<IToolbarConfig>>(() => {
}
});
/* ==================== 内容度量 ==================== */
function measureHtml(html: string) {
const textLen = html2Text(html).length;
const imgMatch = html.match(IMG_REGEX);
const linkMatch = html.match(A_TAG_REGEX);
return {
textLen,
imgNum: imgMatch ? imgMatch.length : 0,
linkNum: linkMatch ? linkMatch.length : 0
};
}
/* ==================== OSS 上传 ==================== */
const uploadToOss = async (file: File): Promise<{ url: string; fileName: string }> => {
@@ -161,12 +196,24 @@ const validateVideoFile = (file: File) => {
/* ==================== wangeditor 菜单配置 ==================== */
function checkImageQuotaBeforeUpload(): boolean {
if (!editorRef.value) return false;
const html = editorRef.value.getHtml();
const {imgNum} = measureHtml(html);
if (imgNum >= props.maxImageCount) {
modal.msgError(`图片数量不能超过 ${props.maxImageCount} 张,请先删除已插入的图片`);
return false;
}
return true;
}
const getUploadImageMenuConfig = () => {
if (props.type === 'base64') {
return {
allowedFileTypes: ['image/jpeg', 'image/jpg', 'image/png', 'image/svg+xml'],
customUpload(file: File, insertFn: (url: string, alt?: string, href?: string) => void) {
if (!validateImageFile(file)) return;
if (!checkImageQuotaBeforeUpload()) return;
modal.loading('正在上传图片,请稍候...');
const reader = new FileReader();
@@ -190,11 +237,12 @@ const getUploadImageMenuConfig = () => {
allowedFileTypes: ['image/jpeg', 'image/jpg', 'image/png', 'image/svg+xml'],
async customUpload(file: File, insertFn: (url: string, alt?: string, href?: string) => void) {
if (!validateImageFile(file)) return;
if (!checkImageQuotaBeforeUpload()) return;
modal.loading('正在上传图片,请稍候...');
try {
const result = await uploadToOss(file);
insertFn(result.url, file.name, result.url);
insertFn(result.url, file.name);
} catch {
modal.msgError('图片上传失败');
} finally {
@@ -224,7 +272,6 @@ const getUploadVideoMenuConfig = () => ({
const editorConfig = computed<Partial<IEditorConfig>>(() => ({
placeholder: props.simpleToolbar ? '请输入标准回复话术...' : '请输入内容',
autoFocus: false,
maxLength: 2000,
MENU_CONF: {
uploadImage: getUploadImageMenuConfig() as any,
uploadVideo: getUploadVideoMenuConfig() as any
@@ -239,9 +286,37 @@ const editorConfig = computed<Partial<IEditorConfig>>(() => ({
/* ==================== 事件处理 ==================== */
function updateCounts(html: string) {
const {textLen, imgNum, linkNum} = measureHtml(html);
textCount.value = textLen;
imageCount.value = imgNum;
linkCount.value = linkNum;
emit('countChange', {textLength: textLen, imageCount: imgNum, linkCount: linkNum, htmlLength: html.length});
}
const handleChange = () => {
if (!editorRef.value) return;
wordCount.value = editorRef.value.getText().length;
const html = editorRef.value.getHtml();
console.log(html)
const {textLen, imgNum, linkNum} = measureHtml(html);
updateCounts(html);
const textOver = textLen > props.maxTextLength;
const imgOver = imgNum > props.maxImageCount;
const linkOver = linkNum > props.maxLinkCount;
if (textOver || imgOver || linkOver) {
const msgs: string[] = [];
if (textOver) msgs.push(`纯文本超过 ${props.maxTextLength} 字`);
if (imgOver) msgs.push(`图片超过 ${props.maxImageCount} 张`);
if (linkOver) msgs.push(`链接超过 ${props.maxLinkCount} 条`);
modal.msgError(msgs.join(';') + ',已自动恢复');
editorRef.value.setHtml(lastValidHtml.value);
updateCounts(lastValidHtml.value);
return;
}
lastValidHtml.value = html;
};
const syncReadOnly = () => {
@@ -258,7 +333,9 @@ const syncReadOnly = () => {
const handleCreated = (editor: IDomEditor) => {
editorRef.value = editor;
syncReadOnly();
wordCount.value = editor.getText().length;
const html = editor.getHtml();
updateCounts(html);
lastValidHtml.value = html;
};
/* ==================== 双向数据绑定(直接透传HTML) ==================== */
@@ -324,6 +401,11 @@ onBeforeUnmount(() => {
min-height: inherit;
}
.editor-footer {
display: flex;
flex-direction: column;
}
.editor-tip {
padding: 12px 16px;
font-size: 13px;
@@ -338,8 +420,27 @@ onBeforeUnmount(() => {
border-radius: 4px;
}
.word-count {
text-align: right;
margin-top: 4px;
.counter-bar {
display: flex;
justify-content: flex-end;
align-items: center;
gap: 8px;
padding: 6px 12px;
font-size: 12px;
color: #999;
border-top: 1px solid var(--el-border-color);
background: #fafafa;
}
.counter-bar .warn {
color: #e6a23c;
}
.counter-bar .danger {
color: #f56c6c;
}
.counter-bar .divider {
color: #dcdfe6;
}
</style>