fix: MML命令输入框shift+回车进行换行,回车直接发送

This commit is contained in:
TsMask
2024-02-19 10:44:47 +08:00
parent 883816c540
commit a75c89c451
4 changed files with 133 additions and 40 deletions

View File

@@ -1,5 +1,5 @@
<template> <template>
<codemirror <Codemirror
:model-value="modelValue" :model-value="modelValue"
:placeholder="props.placeholder" :placeholder="props.placeholder"
:style="props.editorStyle" :style="props.editorStyle"

View File

@@ -175,20 +175,28 @@ function fnSendMML() {
// 发送 // 发送
state.from.sendLoading = true; state.from.sendLoading = true;
const [neType, neId] = state.neType; const [neType, neId] = state.neType;
sendMMlByNE(neType, neId, cmdArr).then(res => { sendMMlByNE(neType, neId, cmdArr)
state.from.sendLoading = false; .then(res => {
if (res.code === RESULT_CODE_SUCCESS) { state.from.sendLoading = false;
let resultArr = res.data; if (res.code === RESULT_CODE_SUCCESS) {
for (let i = 0; i < resultArr.length; i++) { let resultArr = res.data;
const str = resultArr[i]; for (let i = 0; i < resultArr.length; i++) {
const logStr = str.replace(/(\r\n|\n)/g, '\n'); const str = resultArr[i];
const cmdStr = cmdArr[i]; const logStr = str.replace(/(\r\n|\n)/g, '\n');
state.mmlCmdLog += `${cmdStr}\n${logStr}\n`; const cmdStr = cmdArr[i];
state.mmlCmdLog += `${cmdStr}\n${logStr}\n`;
}
} else {
state.mmlCmdLog += `${res.msg}\n`;
} }
} else { })
state.mmlCmdLog += `${res.msg}\n`; .finally(() => {
} // 控制台滚动底部
}); const container = document.getElementsByClassName('cm-scroller')[0];
if (container) {
container.scrollTop = container.scrollHeight;
}
});
} }
/**上传变更 */ /**上传变更 */
@@ -475,6 +483,28 @@ function fnAutoCompleteChange(value: any, _: any) {
} }
} }
/**自动完成按键触发 */
function fnAutoCompleteKeydown(evt: any) {
if (evt.key === 'Enter') {
// 阻止默认的换行行为
evt.preventDefault();
// 按下 Shift + Enter 键时换行
if (evt.shiftKey) {
// 插入换行符
const textarea = evt.target;
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
const text = textarea.value;
textarea.value = text.substring(0, start) + '\n' + text.substring(end);
state.autoCompleteValue = textarea.value;
// 更新光标位置
textarea.selectionStart = textarea.selectionEnd = start + 1;
} else {
fnSendMML();
}
}
}
onMounted(() => { onMounted(() => {
// 获取网元网元列表 // 获取网元网元列表
neInfoStore.fnNelist().then(res => { neInfoStore.fnNelist().then(res => {
@@ -599,6 +629,7 @@ onMounted(() => {
@search="fnAutoCompleteSearch" @search="fnAutoCompleteSearch"
@select="fnAutoCompleteSelect" @select="fnAutoCompleteSelect"
@change="fnAutoCompleteChange" @change="fnAutoCompleteChange"
@keydown="fnAutoCompleteKeydown"
> >
<a-textarea :placeholder="t('common.inputPlease')" auto-size /> <a-textarea :placeholder="t('common.inputPlease')" auto-size />
</a-auto-complete> </a-auto-complete>

View File

@@ -170,20 +170,28 @@ function fnSendMML() {
// 发送 // 发送
state.from.sendLoading = true; state.from.sendLoading = true;
sendMMlByOMC(state.neId, cmdArr).then(res => { sendMMlByOMC(state.neId, cmdArr)
state.from.sendLoading = false; .then(res => {
if (res.code === RESULT_CODE_SUCCESS) { state.from.sendLoading = false;
let resultArr = res.data; if (res.code === RESULT_CODE_SUCCESS) {
for (let i = 0; i < resultArr.length; i++) { let resultArr = res.data;
const str = resultArr[i]; for (let i = 0; i < resultArr.length; i++) {
const logStr = str.replace(/(\r\n|\n)/g, '\n'); const str = resultArr[i];
const cmdStr = cmdArr[i]; const logStr = str.replace(/(\r\n|\n)/g, '\n');
state.mmlCmdLog += `${cmdStr}\n${logStr}\n`; const cmdStr = cmdArr[i];
state.mmlCmdLog += `${cmdStr}\n${logStr}\n`;
}
} else {
state.mmlCmdLog += `${res.msg}\n`;
} }
} else { })
state.mmlCmdLog += `${res.msg}\n`; .finally(() => {
} // 控制台滚动底部
}); const container = document.getElementsByClassName('cm-scroller')[0];
if (container) {
container.scrollTop = container.scrollHeight;
}
});
} }
/**上传变更 */ /**上传变更 */
@@ -449,6 +457,28 @@ function fnAutoCompleteChange(value: any, _: any) {
} }
} }
/**自动完成按键触发 */
function fnAutoCompleteKeydown(evt: any) {
if (evt.key === 'Enter') {
// 阻止默认的换行行为
evt.preventDefault();
// 按下 Shift + Enter 键时换行
if (evt.shiftKey) {
// 插入换行符
const textarea = evt.target;
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
const text = textarea.value;
textarea.value = text.substring(0, start) + '\n' + text.substring(end);
state.autoCompleteValue = textarea.value;
// 更新光标位置
textarea.selectionStart = textarea.selectionEnd = start + 1;
} else {
fnSendMML();
}
}
}
onMounted(() => { onMounted(() => {
// 获取网元网元列表 // 获取网元网元列表
useNeInfoStore() useNeInfoStore()
@@ -567,6 +597,7 @@ onMounted(() => {
@search="fnAutoCompleteSearch" @search="fnAutoCompleteSearch"
@select="fnAutoCompleteSelect" @select="fnAutoCompleteSelect"
@change="fnAutoCompleteChange" @change="fnAutoCompleteChange"
@keydown="fnAutoCompleteKeydown"
> >
<a-textarea :placeholder="t('common.inputPlease')" auto-size /> <a-textarea :placeholder="t('common.inputPlease')" auto-size />
</a-auto-complete> </a-auto-complete>

View File

@@ -170,20 +170,28 @@ function fnSendMML() {
// 发送 // 发送
state.from.sendLoading = true; state.from.sendLoading = true;
sendMMlByUDM(state.neId, cmdArr).then(res => { sendMMlByUDM(state.neId, cmdArr)
state.from.sendLoading = false; .then(res => {
if (res.code === RESULT_CODE_SUCCESS) { state.from.sendLoading = false;
let resultArr = res.data; if (res.code === RESULT_CODE_SUCCESS) {
for (let i = 0; i < resultArr.length; i++) { let resultArr = res.data;
const str = resultArr[i]; for (let i = 0; i < resultArr.length; i++) {
const logStr = str.replace(/(\r\n|\n)/g, '\n'); const str = resultArr[i];
const cmdStr = cmdArr[i]; const logStr = str.replace(/(\r\n|\n)/g, '\n');
state.mmlCmdLog += `${cmdStr}\n${logStr}\n`; const cmdStr = cmdArr[i];
state.mmlCmdLog += `${cmdStr}\n${logStr}\n`;
}
} else {
state.mmlCmdLog += `${res.msg}\n`;
} }
} else { })
state.mmlCmdLog += `${res.msg}\n`; .finally(() => {
} // 控制台滚动底部
}); const container = document.getElementsByClassName('cm-scroller')[0];
if (container) {
container.scrollTop = container.scrollHeight;
}
});
} }
/**上传变更 */ /**上传变更 */
@@ -449,6 +457,28 @@ function fnAutoCompleteChange(value: any, _: any) {
} }
} }
/**自动完成按键触发 */
function fnAutoCompleteKeydown(evt: any) {
if (evt.key === 'Enter') {
// 阻止默认的换行行为
evt.preventDefault();
// 按下 Shift + Enter 键时换行
if (evt.shiftKey) {
// 插入换行符
const textarea = evt.target;
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
const text = textarea.value;
textarea.value = text.substring(0, start) + '\n' + text.substring(end);
state.autoCompleteValue = textarea.value;
// 更新光标位置
textarea.selectionStart = textarea.selectionEnd = start + 1;
} else {
fnSendMML();
}
}
}
onMounted(() => { onMounted(() => {
// 获取网元网元列表 // 获取网元网元列表
useNeInfoStore() useNeInfoStore()
@@ -572,6 +602,7 @@ onMounted(() => {
@search="fnAutoCompleteSearch" @search="fnAutoCompleteSearch"
@select="fnAutoCompleteSelect" @select="fnAutoCompleteSelect"
@change="fnAutoCompleteChange" @change="fnAutoCompleteChange"
@keydown="fnAutoCompleteKeydown"
> >
<a-textarea :placeholder="t('common.inputPlease')" auto-size /> <a-textarea :placeholder="t('common.inputPlease')" auto-size />
</a-auto-complete> </a-auto-complete>