浏览代码

配置页面 添加光标插入内容

jiayufei 4 年之前
父节点
当前提交
9008a6e01f

+ 1 - 12
src/views/modules/account-config/account-config.vue

@@ -144,18 +144,7 @@ export default {
                 page: 1,
                 size: 10
             },
-            dataSource: [
-                {
-                    orientationName: false,
-                    accountName: '新仇旧恨',
-                    populationType: '123',
-                    typeStr: '北京市',
-                    statDate: '2019-08-12',
-                    coverNum: 765,
-                    statusStr: '已解决',
-                    chujia: 5654
-                }
-            ],
+            dataSource: [],
             columns: [
                 {
                     title: '开关',

+ 12 - 1
src/views/modules/account-config/components/configuration-modal.vue

@@ -997,9 +997,20 @@ export default {
                 console.log(error, 'eeee');
             });
         },
+        // 点击获取光标位置进行字段插入
         handleGetChangeAll(item, field) {
             let node = document.getElementById(field);
-            this.configForm.adName += '-{{' + item + '}}-';
+            let startPos = node.selectionStart; // input 第0个字符到选中的字符
+            let endPos = node.selectionEnd; // 选中的字符到最后的字符
+            let txt = node.value;
+            if (startPos === 0 || endPos === 0) {
+                this.configForm.adName += '-{{' + item + '}}-';
+            }
+            else {
+                this.configForm.adName = txt.substring(0, startPos) + '-{{' + item + '}}-' + txt.substring(endPos);
+                node.selectionStart = startPos + item.length + 6;
+                node.selectionEnd = startPos + item.length + 6;
+            }
             node.focus();
             node.blur();
         },