|
@@ -115,12 +115,17 @@
|
|
|
|
|
|
<div
|
|
|
class="border-grey sele-ele-box1"
|
|
|
- @keydown.shift.187="handleShiftPlus"
|
|
|
+
|
|
|
tabindex="0"
|
|
|
@keydown.left="handleLeftArrow"
|
|
|
@keydown.right="handleRightArrow"
|
|
|
@keydown.delete="handleDelete"
|
|
|
-
|
|
|
+ @keydown.shift.189="addOperator('-')"
|
|
|
+ @keydown.shift.191="addOperator('/')"
|
|
|
+ @keydown.shift.57="addBrackets('(')"
|
|
|
+ @keydown.shift.48="addBrackets(')')"
|
|
|
+ @keydown.shift.187="addOperator('+')"
|
|
|
+ @keydown.shift.56="addOperator('*')"
|
|
|
@focus="containerFocused = true"
|
|
|
@blur="containerFocused = false"
|
|
|
>
|
|
@@ -656,6 +661,9 @@ export default {
|
|
|
selectEleFormula: {
|
|
|
handler() {
|
|
|
this.checkDefaultSelection();
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$el.querySelector('.sele-ele-box1').focus();
|
|
|
+ });
|
|
|
},
|
|
|
deep: true
|
|
|
}
|
|
@@ -923,25 +931,57 @@ export default {
|
|
|
}
|
|
|
|
|
|
},
|
|
|
- addOperator(operator){
|
|
|
- if( this.itemList.length>0){
|
|
|
- this.itemList.forEach(e => {
|
|
|
- let lastEle = this.selectEleFormula[this.selectEleFormula.length-1];
|
|
|
- if(this.selectEleFormula.length != 0 && lastEle.type != 'Operator' && lastEle.type != 'Brackets' && lastEle.name != '('){ /* 不存在运算符 */
|
|
|
- this.eleAddFormulaHandle(this.formulaMap[operator]);
|
|
|
- }
|
|
|
- this.eleAddFormulaHandle(e);
|
|
|
- })
|
|
|
- }else{
|
|
|
+ addOperator(operator) {
|
|
|
+ // 保存添加前的长度用于计算新索引
|
|
|
+ const initialLength = this.selectEleFormula.length;
|
|
|
+
|
|
|
+ if (this.itemList.length > 0) {
|
|
|
+ this.itemList.forEach(e => {
|
|
|
+ let lastEle = this.selectEleFormula[this.selectEleFormula.length - 1];
|
|
|
+ if (this.selectEleFormula.length != 0 &&
|
|
|
+ lastEle.type != 'Operator' &&
|
|
|
+ lastEle.type != 'Brackets' &&
|
|
|
+ lastEle.name != '(') {
|
|
|
+ // 添加运算符并记录位置
|
|
|
+ this.eleAddFormulaHandle(this.formulaMap[operator]);
|
|
|
+ }
|
|
|
+ this.eleAddFormulaHandle(e);
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ if (this.curSeleEleIndex === -1 || this.curSeleEleIndex === this.selectEleFormula.length - 1) {
|
|
|
+ // 直接添加符号
|
|
|
+ this.eleAddFormulaHandle(this.formulaMap[operator]);
|
|
|
+ } else {
|
|
|
+ // 在指定位置添加符号
|
|
|
+ this.randomaddOperator(this.formulaMap[operator])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.itemList = [];
|
|
|
+
|
|
|
+ // 计算新添加运算符的索引并选中它
|
|
|
+ this.$nextTick(() => {
|
|
|
+ // 计算新添加元素的索引
|
|
|
+ const newIndex = this.selectEleFormula.length > initialLength
|
|
|
+ ? this.selectEleFormula.length - 1
|
|
|
+ : this.curSeleEleIndex + 1; // 处理替换情况
|
|
|
+
|
|
|
+ // 取消所有选中状态
|
|
|
+ this.selectEleFormula.forEach(item => {
|
|
|
+ item.selected = false;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 选中新添加的运算符
|
|
|
+ if (this.selectEleFormula[newIndex]) {
|
|
|
+ this.selectEleFormula[newIndex].selected = true;
|
|
|
+ this.curSeleEleIndex = newIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保容器保持焦点
|
|
|
+ this.$el.querySelector('.sele-ele-box1').focus();
|
|
|
+ });
|
|
|
+},
|
|
|
|
|
|
- if(this.curSeleEleIndex===-1 || this.curSeleEleIndex === this.selectEleFormula.length - 1){ /* 没选择值或者选择最后一个的时候直接添加符号 */
|
|
|
- this.eleAddFormulaHandle(this.formulaMap[operator]);
|
|
|
- }else{ /* 选择中间的值,如果下一个是符号这替换,反之则在指定的位置添加 */
|
|
|
- this.randomaddOperator(this.formulaMap[operator])
|
|
|
- }
|
|
|
- }
|
|
|
- this.itemList=[];
|
|
|
- },
|
|
|
canceloperationVisible(){
|
|
|
this.operationVisible=false;
|
|
|
this.allTreeShow=false;
|