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>
<codemirror
<Codemirror
:model-value="modelValue"
:placeholder="props.placeholder"
:style="props.editorStyle"

View File

@@ -175,20 +175,28 @@ function fnSendMML() {
// 发送
state.from.sendLoading = true;
const [neType, neId] = state.neType;
sendMMlByNE(neType, neId, cmdArr).then(res => {
state.from.sendLoading = false;
if (res.code === RESULT_CODE_SUCCESS) {
let resultArr = res.data;
for (let i = 0; i < resultArr.length; i++) {
const str = resultArr[i];
const logStr = str.replace(/(\r\n|\n)/g, '\n');
const cmdStr = cmdArr[i];
state.mmlCmdLog += `${cmdStr}\n${logStr}\n`;
sendMMlByNE(neType, neId, cmdArr)
.then(res => {
state.from.sendLoading = false;
if (res.code === RESULT_CODE_SUCCESS) {
let resultArr = res.data;
for (let i = 0; i < resultArr.length; i++) {
const str = resultArr[i];
const logStr = str.replace(/(\r\n|\n)/g, '\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(() => {
// 获取网元网元列表
neInfoStore.fnNelist().then(res => {
@@ -599,6 +629,7 @@ onMounted(() => {
@search="fnAutoCompleteSearch"
@select="fnAutoCompleteSelect"
@change="fnAutoCompleteChange"
@keydown="fnAutoCompleteKeydown"
>
<a-textarea :placeholder="t('common.inputPlease')" auto-size />
</a-auto-complete>

View File

@@ -170,20 +170,28 @@ function fnSendMML() {
// 发送
state.from.sendLoading = true;
sendMMlByOMC(state.neId, cmdArr).then(res => {
state.from.sendLoading = false;
if (res.code === RESULT_CODE_SUCCESS) {
let resultArr = res.data;
for (let i = 0; i < resultArr.length; i++) {
const str = resultArr[i];
const logStr = str.replace(/(\r\n|\n)/g, '\n');
const cmdStr = cmdArr[i];
state.mmlCmdLog += `${cmdStr}\n${logStr}\n`;
sendMMlByOMC(state.neId, cmdArr)
.then(res => {
state.from.sendLoading = false;
if (res.code === RESULT_CODE_SUCCESS) {
let resultArr = res.data;
for (let i = 0; i < resultArr.length; i++) {
const str = resultArr[i];
const logStr = str.replace(/(\r\n|\n)/g, '\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(() => {
// 获取网元网元列表
useNeInfoStore()
@@ -567,6 +597,7 @@ onMounted(() => {
@search="fnAutoCompleteSearch"
@select="fnAutoCompleteSelect"
@change="fnAutoCompleteChange"
@keydown="fnAutoCompleteKeydown"
>
<a-textarea :placeholder="t('common.inputPlease')" auto-size />
</a-auto-complete>

View File

@@ -170,20 +170,28 @@ function fnSendMML() {
// 发送
state.from.sendLoading = true;
sendMMlByUDM(state.neId, cmdArr).then(res => {
state.from.sendLoading = false;
if (res.code === RESULT_CODE_SUCCESS) {
let resultArr = res.data;
for (let i = 0; i < resultArr.length; i++) {
const str = resultArr[i];
const logStr = str.replace(/(\r\n|\n)/g, '\n');
const cmdStr = cmdArr[i];
state.mmlCmdLog += `${cmdStr}\n${logStr}\n`;
sendMMlByUDM(state.neId, cmdArr)
.then(res => {
state.from.sendLoading = false;
if (res.code === RESULT_CODE_SUCCESS) {
let resultArr = res.data;
for (let i = 0; i < resultArr.length; i++) {
const str = resultArr[i];
const logStr = str.replace(/(\r\n|\n)/g, '\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(() => {
// 获取网元网元列表
useNeInfoStore()
@@ -572,6 +602,7 @@ onMounted(() => {
@search="fnAutoCompleteSearch"
@select="fnAutoCompleteSelect"
@change="fnAutoCompleteChange"
@keydown="fnAutoCompleteKeydown"
>
<a-textarea :placeholder="t('common.inputPlease')" auto-size />
</a-auto-complete>