Commit e08dd4d53e4e6da92459818929a5b804d5500d25
1 parent
4ff15794
颜色添加拖住
添加shift键盘时候能够多选 添加防抖动
Showing
5 changed files
with
124 additions
and
20 deletions
config/dev.env.js
| ... | ... | @@ -4,7 +4,7 @@ const prodEnv = require('./prod.env') |
| 4 | 4 | |
| 5 | 5 | module.exports = merge(prodEnv, { |
| 6 | 6 | NODE_ENV: '"development"', |
| 7 | - //BASE_API: '"http://127.0.0.1:8080/xlyReport"', | |
| 7 | +// BASE_API: '"http://127.0.0.1:8080/xlyReport"', | |
| 8 | 8 | BASE_API: '"http://weberp.xlyprint.cn/xlyReport"', |
| 9 | 9 | //API_WS: '"ws://127.0.0.1:8080/api/websocket"' |
| 10 | 10 | }) | ... | ... |
src/utils/debounce.js
0 → 100644
| 1 | +/** | |
| 2 | + * 防抖函数 | |
| 3 | + * @param func 用户传入的防抖函数 | |
| 4 | + * @param wait 等待的时间 | |
| 5 | + * @param immediate 是否立即执行 | |
| 6 | + */ | |
| 7 | +export const debounce = function(func, wait = 50, immediate = false) { | |
| 8 | + // 缓存一个定时器id | |
| 9 | + let timer = null | |
| 10 | + let result | |
| 11 | + const debounced = function(...args) { | |
| 12 | + // 如果已经设定过定时器了就清空上一次的定时器 | |
| 13 | + if (timer) { | |
| 14 | + clearTimeout(timer) | |
| 15 | + } | |
| 16 | + if (immediate) { | |
| 17 | + const callNow = !timer | |
| 18 | + // 等待wait的时间间隔后,timer为null的时候,函数才可以继续执行 | |
| 19 | + timer = setTimeout(() => { | |
| 20 | + timer = null | |
| 21 | + }, wait) | |
| 22 | + // 未执行过,执行 | |
| 23 | + if (callNow) result = func.apply(this, args) | |
| 24 | + } else { | |
| 25 | + // 开始一个定时器,延迟执行用户传入的方法 | |
| 26 | + timer = setTimeout(() => { | |
| 27 | + // 将实际的this和参数传入用户实际调用的函数 | |
| 28 | + func.apply(this, args) | |
| 29 | + }, wait) | |
| 30 | + } | |
| 31 | + return result | |
| 32 | + } | |
| 33 | + debounced.cancel = function() { | |
| 34 | + clearTimeout(timer) | |
| 35 | + timer = null | |
| 36 | + } | |
| 37 | + // 这里返回的函数时每次用户实际调用的防抖函数 | |
| 38 | + return debounced | |
| 39 | +} | ... | ... |
src/views/bigscreenDesigner/designer/components/customColorComponents.vue
| ... | ... | @@ -8,7 +8,7 @@ |
| 8 | 8 | @click="handleAddClick" |
| 9 | 9 | >新增</el-button |
| 10 | 10 | > |
| 11 | - <el-table :data="formData" style="width: 100%"> | |
| 11 | + <el-table :data="formData" style="width: 100%" row-key="color"> | |
| 12 | 12 | <el-table-column prop="color" label="颜色" align="center"> |
| 13 | 13 | <template slot-scope="scope"> |
| 14 | 14 | <span class="color-box" :style="{ background: scope.row.color }" /> |
| ... | ... | @@ -70,6 +70,7 @@ |
| 70 | 70 | </div> |
| 71 | 71 | </template> |
| 72 | 72 | <script> |
| 73 | +import Sortable from 'sortablejs'//引入拖拽插件 | |
| 73 | 74 | export default { |
| 74 | 75 | name: "CustomColorComponents", |
| 75 | 76 | model: { |
| ... | ... | @@ -96,6 +97,11 @@ export default { |
| 96 | 97 | indexEditor: -1 // 编辑第几个数据 |
| 97 | 98 | }; |
| 98 | 99 | }, |
| 100 | + created() { | |
| 101 | + this.$nextTick(() => { | |
| 102 | + this.rowDrop() | |
| 103 | + }); | |
| 104 | + }, | |
| 99 | 105 | mounted() {}, |
| 100 | 106 | methods: { |
| 101 | 107 | // 弹出框关闭 |
| ... | ... | @@ -138,7 +144,24 @@ export default { |
| 138 | 144 | this.formData.splice(index, 1); |
| 139 | 145 | this.$emit("input", this.formData); |
| 140 | 146 | this.$emit("change", this.formData); |
| 141 | - } | |
| 147 | + }, | |
| 148 | + //行拖拽 | |
| 149 | + rowDrop () { | |
| 150 | + // 此时找到的元素是要拖拽元素的父容器 | |
| 151 | + const tbody = document.querySelector('.el-table__body-wrapper tbody'); | |
| 152 | + const _this = this; | |
| 153 | + Sortable.create(tbody, { | |
| 154 | + //指定父元素下可被拖拽的子元素 | |
| 155 | + draggable: ".el-table__row", | |
| 156 | + onEnd ({ newIndex, oldIndex }) { | |
| 157 | + const currRow = _this.formData.splice(oldIndex, 1)[0]; | |
| 158 | + _this.formData.splice(newIndex, 0, currRow); | |
| 159 | + //渲染父页面 | |
| 160 | + _this.$emit("input", _this.formData); | |
| 161 | + _this.$emit("change", _this.formData); | |
| 162 | + } | |
| 163 | + }); | |
| 164 | + }, | |
| 142 | 165 | } |
| 143 | 166 | }; |
| 144 | 167 | </script> | ... | ... |
src/views/bigscreenDesigner/designer/index.vue
| ... | ... | @@ -314,6 +314,7 @@ import { getToken } from "@/utils/auth"; |
| 314 | 314 | import { Revoke } from "@/utils/revoke"; |
| 315 | 315 | import { mapMutations } from 'vuex'; |
| 316 | 316 | import process from "process"; |
| 317 | +import { debounce } from '@/utils/debounce'; // 引入防抖函数 | |
| 317 | 318 | |
| 318 | 319 | export default { |
| 319 | 320 | name: "Login", |
| ... | ... | @@ -378,7 +379,6 @@ export default { |
| 378 | 379 | options: [], |
| 379 | 380 | }, |
| 380 | 381 | ], // 工作区中拖放的组件 |
| 381 | - | |
| 382 | 382 | // 当前激活组件 |
| 383 | 383 | widgetIndex: 0, |
| 384 | 384 | // 当前激活组件右侧配置属性 |
| ... | ... | @@ -395,6 +395,8 @@ export default { |
| 395 | 395 | visibleContentMenu: false, |
| 396 | 396 | rightClickIndex: -1, |
| 397 | 397 | activeName: "first", |
| 398 | + selectMore:[],//按住shift多选的图层 | |
| 399 | + shiftEnt:false,//shift键盘是否按住 | |
| 398 | 400 | }; |
| 399 | 401 | }, |
| 400 | 402 | computed: { |
| ... | ... | @@ -467,6 +469,15 @@ export default { |
| 467 | 469 | window.addEventListener("mouseup", () => { |
| 468 | 470 | this.grade = false; |
| 469 | 471 | }); |
| 472 | + window.addEventListener('keydown', code => this.handleKeyDown(code)); // 监听键盘按下事件 | |
| 473 | + window.addEventListener('keyup', code => this.handleKeyUp(code)); // 监听键盘松开事件 | |
| 474 | + | |
| 475 | + }, | |
| 476 | + // 在beforeDestroy中 | |
| 477 | + beforeDestroy() { | |
| 478 | + // 销毁监听键盘事件 | |
| 479 | + window.removeEventListener('keydown', code => this.handleKeyDown(code)); | |
| 480 | + window.removeEventListener('keyup', code => this.handleKeyUp(code)); | |
| 470 | 481 | }, |
| 471 | 482 | methods: { |
| 472 | 483 | ...mapMutations('dataSource', ['SET_STATIC_DATA']), |
| ... | ... | @@ -482,6 +493,19 @@ export default { |
| 482 | 493 | } |
| 483 | 494 | this.widgets = record; |
| 484 | 495 | }, |
| 496 | + // 监听按下键盘事件 | |
| 497 | + handleKeyDown: debounce(function(code) { | |
| 498 | + // 判断是否按住shift键,是就把pin赋值为true | |
| 499 | + if (code.keyCode === 16 && code.shiftKey) { | |
| 500 | + this.shiftEnt = true; | |
| 501 | + } | |
| 502 | + }, 500, true), | |
| 503 | + handleKeyUp: debounce(function(code) { | |
| 504 | + // 判断是否松开shift键,是就把pin赋值为false | |
| 505 | + if (code.keyCode === 16) { | |
| 506 | + this.shiftEnt = false; | |
| 507 | + } | |
| 508 | + }, 500, true), | |
| 485 | 509 | /** |
| 486 | 510 | * @description: 重做 |
| 487 | 511 | * @param {*} |
| ... | ... | @@ -866,10 +890,12 @@ export default { |
| 866 | 890 | }, |
| 867 | 891 | // 如果是点击大屏设计器中的底层,加载大屏底层属性 |
| 868 | 892 | setOptionsOnClickScreen() { |
| 869 | - this.screenCode = "screen"; | |
| 870 | - // 选中不同的组件 右侧都显示第一栏 | |
| 871 | - this.activeName = "first"; | |
| 872 | - this.widgetOptions = getToolByCode("screen")["options"]; | |
| 893 | + if(!this.shiftEnt) { | |
| 894 | + this.screenCode = "screen"; | |
| 895 | + // 选中不同的组件 右侧都显示第一栏 | |
| 896 | + this.activeName = "first"; | |
| 897 | + this.widgetOptions = getToolByCode("screen")["options"]; | |
| 898 | + } | |
| 873 | 899 | }, |
| 874 | 900 | getScreenData(data){ |
| 875 | 901 | const screenData = {}; |
| ... | ... | @@ -909,23 +935,37 @@ export default { |
| 909 | 935 | }, |
| 910 | 936 | widgetsClick(index) { |
| 911 | 937 | const draggableArr = this.$refs.widgets; |
| 912 | - for (let i = 0; i < draggableArr.length; i++) { | |
| 913 | - if (i == index) { | |
| 914 | - this.$refs.widgets[i].$refs.draggable.setActive(true); | |
| 915 | - } else { | |
| 916 | - this.$refs.widgets[i].$refs.draggable.setActive(false); | |
| 938 | + //判断是否按住了shift键盘 | |
| 939 | + if(this.shiftEnt){ | |
| 940 | + for (let i = 0; i < draggableArr.length; i++) { | |
| 941 | + if (i == index) { | |
| 942 | + this.$refs.widgets[i].$refs.draggable.setActive(true); | |
| 943 | + } | |
| 944 | + } | |
| 945 | + this.setOptionsOnClickWidget(index); | |
| 946 | + this.grade = true; | |
| 947 | + }else{ | |
| 948 | + //没有按住shift键标识编辑单个 | |
| 949 | + for (let i = 0; i < draggableArr.length; i++) { | |
| 950 | + if (i == index) { | |
| 951 | + this.$refs.widgets[i].$refs.draggable.setActive(true); | |
| 952 | + } else { | |
| 953 | + this.$refs.widgets[i].$refs.draggable.setActive(false); | |
| 954 | + } | |
| 917 | 955 | } |
| 956 | + this.setOptionsOnClickWidget(index); | |
| 957 | + this.grade = true; | |
| 918 | 958 | } |
| 919 | - this.setOptionsOnClickWidget(index); | |
| 920 | - this.grade = true; | |
| 921 | 959 | }, |
| 922 | 960 | widgetsMouseup(e) { |
| 923 | 961 | this.grade = false; |
| 924 | 962 | }, |
| 925 | 963 | handleMouseDown() { |
| 926 | - const draggableArr = this.$refs.widgets; | |
| 927 | - for (let i = 0; i < draggableArr.length; i++) { | |
| 928 | - this.$refs.widgets[i].$refs.draggable.setActive(false); | |
| 964 | + if(!this.shiftEnt){ | |
| 965 | + const draggableArr = this.$refs.widgets; | |
| 966 | + for (let i = 0; i < draggableArr.length; i++) { | |
| 967 | + this.$refs.widgets[i].$refs.draggable.setActive(false); | |
| 968 | + } | |
| 929 | 969 | } |
| 930 | 970 | }, |
| 931 | 971 | setWidgetOptionsData(val){ |
| ... | ... | @@ -1086,8 +1126,9 @@ export default { |
| 1086 | 1126 | this.widgets.splice(index, 1); |
| 1087 | 1127 | }, |
| 1088 | 1128 | //输入ctrl+c |
| 1089 | - entryCopy(){ | |
| 1090 | - this.copylayer(); | |
| 1129 | + entryCopy(index){ | |
| 1130 | + const obj = this.deepClone(this.widgets[index]); | |
| 1131 | + this.widgets.splice(this.widgets.length, 0, obj); | |
| 1091 | 1132 | } |
| 1092 | 1133 | }, |
| 1093 | 1134 | }; | ... | ... |