diff --git a/src/directives/drag-height/index.ts b/src/directives/drag-height/index.ts new file mode 100644 index 0000000..e281ece --- /dev/null +++ b/src/directives/drag-height/index.ts @@ -0,0 +1,64 @@ +// 拖拽元素 改变高度 自定义指令 +export const dragHeight = (el: any, binding: any) => { + el.style.position = 'relative' + let isPress = false + // 最小宽度 + let minHeight = 50 + // 获取 drag-min-height 的值 + if (binding.value) { + minHeight = parseInt(binding.value, 10) + } + + // 拖拽触发元素 + const dragItem = document.createElement('div') + dragItem.id = 'dragItem-height' + // 将元素放置到抽屉的左边边缘 + dragItem.style.cssText + = 'height: 6px;width: 100%;cursor: n-resize;position: absolute;right: 0;bottom: 0;background-color: #ddd; display: none;' + el.append(dragItem) + + // el 鼠标完全进入时,显示dragItem + el.addEventListener('mouseenter', () => { + if (isPress) { return } + dragItem.style.display = 'block' + }) + + // el 鼠标完全离开时,隐藏dragItem + el.addEventListener('mouseleave', () => { + if (isPress) { return } + dragItem.style.display = 'none' + }) + + // 鼠标按下时,开始拖拽 + dragItem.onmousedown = () => { + document.body.style.userSelect = 'none' + // 获取el距离浏览器顶部的距离 + const elTop = el.offsetTop + isPress = true + console.log('鼠标摁下') + // 鼠标移动时,计算出拖拽的距离 + document.onmousemove = (moveEvent) => { + console.log('鼠标移动') + let height = moveEvent.pageY - elTop - (binding.value || 1) + if (height < minHeight) { + height = minHeight + } + el.style.height = `${height}px` + // 将width赋值到CSS自定义属性 + el.style.setProperty('--el-height', `${height}px`) + + // 阻止默认行为 + return false + } + // 鼠标抬起时,结束拖拽 + document.onmouseup = () => { + console.log('鼠标抬起') + document.onmousemove = null + document.onmouseup = null + document.body.style.userSelect = 'auto' + isPress = false + } + // 阻止默认行为 + return false + } +} diff --git a/src/directives/drag-height/index.ts b/src/directives/drag-height/index.ts new file mode 100644 index 0000000..e281ece --- /dev/null +++ b/src/directives/drag-height/index.ts @@ -0,0 +1,64 @@ +// 拖拽元素 改变高度 自定义指令 +export const dragHeight = (el: any, binding: any) => { + el.style.position = 'relative' + let isPress = false + // 最小宽度 + let minHeight = 50 + // 获取 drag-min-height 的值 + if (binding.value) { + minHeight = parseInt(binding.value, 10) + } + + // 拖拽触发元素 + const dragItem = document.createElement('div') + dragItem.id = 'dragItem-height' + // 将元素放置到抽屉的左边边缘 + dragItem.style.cssText + = 'height: 6px;width: 100%;cursor: n-resize;position: absolute;right: 0;bottom: 0;background-color: #ddd; display: none;' + el.append(dragItem) + + // el 鼠标完全进入时,显示dragItem + el.addEventListener('mouseenter', () => { + if (isPress) { return } + dragItem.style.display = 'block' + }) + + // el 鼠标完全离开时,隐藏dragItem + el.addEventListener('mouseleave', () => { + if (isPress) { return } + dragItem.style.display = 'none' + }) + + // 鼠标按下时,开始拖拽 + dragItem.onmousedown = () => { + document.body.style.userSelect = 'none' + // 获取el距离浏览器顶部的距离 + const elTop = el.offsetTop + isPress = true + console.log('鼠标摁下') + // 鼠标移动时,计算出拖拽的距离 + document.onmousemove = (moveEvent) => { + console.log('鼠标移动') + let height = moveEvent.pageY - elTop - (binding.value || 1) + if (height < minHeight) { + height = minHeight + } + el.style.height = `${height}px` + // 将width赋值到CSS自定义属性 + el.style.setProperty('--el-height', `${height}px`) + + // 阻止默认行为 + return false + } + // 鼠标抬起时,结束拖拽 + document.onmouseup = () => { + console.log('鼠标抬起') + document.onmousemove = null + document.onmouseup = null + document.body.style.userSelect = 'auto' + isPress = false + } + // 阻止默认行为 + return false + } +} diff --git a/src/directives/drag-width/index.ts b/src/directives/drag-width/index.ts new file mode 100644 index 0000000..08de84b --- /dev/null +++ b/src/directives/drag-width/index.ts @@ -0,0 +1,62 @@ +// 拖拽元素 改变宽度 自定义指令 +export const dragWidth = (el: any, binding: any) => { + el.style.position = 'relative' + let isPress = false + + // 最小宽度 + let minWidth = 50 + // 获取 drag-min-width 的值 + if (binding.value) { + minWidth = parseInt(binding.value, 10) + } + + // 拖拽触发元素 + const dragItem = document.createElement('div') + dragItem.id = 'dragItem-width' + // 将元素放置到抽屉的左边边缘 + dragItem.style.cssText = 'height: 100%;width: 5px;cursor: w-resize;position: absolute;top: 0;right: 0;background-color: #ddd; display: none;z-index:99;' + el.append(dragItem) + + // el 鼠标完全进入时,显示dragItem + el.addEventListener('mouseenter', () => { + if (isPress) { return } + dragItem.style.display = 'block' + }) + + // el 鼠标完全离开时,隐藏dragItem + el.addEventListener('mouseleave', () => { + if (isPress) { return } + dragItem.style.display = 'none' + }) + + // 鼠标按下时,开始拖拽 + dragItem.onmousedown = () => { + document.body.style.userSelect = 'none' + // 获取el左边距离浏览器左侧的距离 + const elLeft = el.offsetLeft + isPress = true + + // 鼠标移动时,计算出拖拽的距离 + document.onmousemove = (moveEvent) => { + let width = moveEvent.pageX - elLeft - (binding.value || 1) + if (width < minWidth) { + width = minWidth + } + el.style.width = `${width}px` + // 将width赋值到CSS自定义属性 + el.style.setProperty('--el-width', `${width}px`) + + // 阻止默认行为 + return false + } + // 鼠标抬起时,结束拖拽 + document.onmouseup = () => { + document.onmousemove = null + document.onmouseup = null + document.body.style.userSelect = 'auto' + isPress = false + } + // 阻止默认行为 + return false + } +} diff --git a/src/directives/drag-height/index.ts b/src/directives/drag-height/index.ts new file mode 100644 index 0000000..e281ece --- /dev/null +++ b/src/directives/drag-height/index.ts @@ -0,0 +1,64 @@ +// 拖拽元素 改变高度 自定义指令 +export const dragHeight = (el: any, binding: any) => { + el.style.position = 'relative' + let isPress = false + // 最小宽度 + let minHeight = 50 + // 获取 drag-min-height 的值 + if (binding.value) { + minHeight = parseInt(binding.value, 10) + } + + // 拖拽触发元素 + const dragItem = document.createElement('div') + dragItem.id = 'dragItem-height' + // 将元素放置到抽屉的左边边缘 + dragItem.style.cssText + = 'height: 6px;width: 100%;cursor: n-resize;position: absolute;right: 0;bottom: 0;background-color: #ddd; display: none;' + el.append(dragItem) + + // el 鼠标完全进入时,显示dragItem + el.addEventListener('mouseenter', () => { + if (isPress) { return } + dragItem.style.display = 'block' + }) + + // el 鼠标完全离开时,隐藏dragItem + el.addEventListener('mouseleave', () => { + if (isPress) { return } + dragItem.style.display = 'none' + }) + + // 鼠标按下时,开始拖拽 + dragItem.onmousedown = () => { + document.body.style.userSelect = 'none' + // 获取el距离浏览器顶部的距离 + const elTop = el.offsetTop + isPress = true + console.log('鼠标摁下') + // 鼠标移动时,计算出拖拽的距离 + document.onmousemove = (moveEvent) => { + console.log('鼠标移动') + let height = moveEvent.pageY - elTop - (binding.value || 1) + if (height < minHeight) { + height = minHeight + } + el.style.height = `${height}px` + // 将width赋值到CSS自定义属性 + el.style.setProperty('--el-height', `${height}px`) + + // 阻止默认行为 + return false + } + // 鼠标抬起时,结束拖拽 + document.onmouseup = () => { + console.log('鼠标抬起') + document.onmousemove = null + document.onmouseup = null + document.body.style.userSelect = 'auto' + isPress = false + } + // 阻止默认行为 + return false + } +} diff --git a/src/directives/drag-width/index.ts b/src/directives/drag-width/index.ts new file mode 100644 index 0000000..08de84b --- /dev/null +++ b/src/directives/drag-width/index.ts @@ -0,0 +1,62 @@ +// 拖拽元素 改变宽度 自定义指令 +export const dragWidth = (el: any, binding: any) => { + el.style.position = 'relative' + let isPress = false + + // 最小宽度 + let minWidth = 50 + // 获取 drag-min-width 的值 + if (binding.value) { + minWidth = parseInt(binding.value, 10) + } + + // 拖拽触发元素 + const dragItem = document.createElement('div') + dragItem.id = 'dragItem-width' + // 将元素放置到抽屉的左边边缘 + dragItem.style.cssText = 'height: 100%;width: 5px;cursor: w-resize;position: absolute;top: 0;right: 0;background-color: #ddd; display: none;z-index:99;' + el.append(dragItem) + + // el 鼠标完全进入时,显示dragItem + el.addEventListener('mouseenter', () => { + if (isPress) { return } + dragItem.style.display = 'block' + }) + + // el 鼠标完全离开时,隐藏dragItem + el.addEventListener('mouseleave', () => { + if (isPress) { return } + dragItem.style.display = 'none' + }) + + // 鼠标按下时,开始拖拽 + dragItem.onmousedown = () => { + document.body.style.userSelect = 'none' + // 获取el左边距离浏览器左侧的距离 + const elLeft = el.offsetLeft + isPress = true + + // 鼠标移动时,计算出拖拽的距离 + document.onmousemove = (moveEvent) => { + let width = moveEvent.pageX - elLeft - (binding.value || 1) + if (width < minWidth) { + width = minWidth + } + el.style.width = `${width}px` + // 将width赋值到CSS自定义属性 + el.style.setProperty('--el-width', `${width}px`) + + // 阻止默认行为 + return false + } + // 鼠标抬起时,结束拖拽 + document.onmouseup = () => { + document.onmousemove = null + document.onmouseup = null + document.body.style.userSelect = 'auto' + isPress = false + } + // 阻止默认行为 + return false + } +} diff --git a/src/main.ts b/src/main.ts index c0ae2c9..3627be3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,6 +10,9 @@ import useSettingsStore from './store/modules/settings' import request from '@/api/index' import '@/utils/getLocation' +// 自定义指令 +import { dragHeight } from '@/directives/drag-height/index' +import { dragWidth } from '@/directives/drag-width/index' // 引入音频文件 import alarmAudio from '@/assets/audio/alarm.mp3' // 自定义指令 @@ -83,6 +86,13 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) { app.component(key, component) } + // 加载自定义指令 + app.directive('drag-height', (el, binding) => { + dragHeight(el, binding) + }) + app.directive('drag-width', (el, binding) => { + dragWidth(el, binding) + }) directive(app) app.mount('#app') }).catch((error) => { diff --git a/src/directives/drag-height/index.ts b/src/directives/drag-height/index.ts new file mode 100644 index 0000000..e281ece --- /dev/null +++ b/src/directives/drag-height/index.ts @@ -0,0 +1,64 @@ +// 拖拽元素 改变高度 自定义指令 +export const dragHeight = (el: any, binding: any) => { + el.style.position = 'relative' + let isPress = false + // 最小宽度 + let minHeight = 50 + // 获取 drag-min-height 的值 + if (binding.value) { + minHeight = parseInt(binding.value, 10) + } + + // 拖拽触发元素 + const dragItem = document.createElement('div') + dragItem.id = 'dragItem-height' + // 将元素放置到抽屉的左边边缘 + dragItem.style.cssText + = 'height: 6px;width: 100%;cursor: n-resize;position: absolute;right: 0;bottom: 0;background-color: #ddd; display: none;' + el.append(dragItem) + + // el 鼠标完全进入时,显示dragItem + el.addEventListener('mouseenter', () => { + if (isPress) { return } + dragItem.style.display = 'block' + }) + + // el 鼠标完全离开时,隐藏dragItem + el.addEventListener('mouseleave', () => { + if (isPress) { return } + dragItem.style.display = 'none' + }) + + // 鼠标按下时,开始拖拽 + dragItem.onmousedown = () => { + document.body.style.userSelect = 'none' + // 获取el距离浏览器顶部的距离 + const elTop = el.offsetTop + isPress = true + console.log('鼠标摁下') + // 鼠标移动时,计算出拖拽的距离 + document.onmousemove = (moveEvent) => { + console.log('鼠标移动') + let height = moveEvent.pageY - elTop - (binding.value || 1) + if (height < minHeight) { + height = minHeight + } + el.style.height = `${height}px` + // 将width赋值到CSS自定义属性 + el.style.setProperty('--el-height', `${height}px`) + + // 阻止默认行为 + return false + } + // 鼠标抬起时,结束拖拽 + document.onmouseup = () => { + console.log('鼠标抬起') + document.onmousemove = null + document.onmouseup = null + document.body.style.userSelect = 'auto' + isPress = false + } + // 阻止默认行为 + return false + } +} diff --git a/src/directives/drag-width/index.ts b/src/directives/drag-width/index.ts new file mode 100644 index 0000000..08de84b --- /dev/null +++ b/src/directives/drag-width/index.ts @@ -0,0 +1,62 @@ +// 拖拽元素 改变宽度 自定义指令 +export const dragWidth = (el: any, binding: any) => { + el.style.position = 'relative' + let isPress = false + + // 最小宽度 + let minWidth = 50 + // 获取 drag-min-width 的值 + if (binding.value) { + minWidth = parseInt(binding.value, 10) + } + + // 拖拽触发元素 + const dragItem = document.createElement('div') + dragItem.id = 'dragItem-width' + // 将元素放置到抽屉的左边边缘 + dragItem.style.cssText = 'height: 100%;width: 5px;cursor: w-resize;position: absolute;top: 0;right: 0;background-color: #ddd; display: none;z-index:99;' + el.append(dragItem) + + // el 鼠标完全进入时,显示dragItem + el.addEventListener('mouseenter', () => { + if (isPress) { return } + dragItem.style.display = 'block' + }) + + // el 鼠标完全离开时,隐藏dragItem + el.addEventListener('mouseleave', () => { + if (isPress) { return } + dragItem.style.display = 'none' + }) + + // 鼠标按下时,开始拖拽 + dragItem.onmousedown = () => { + document.body.style.userSelect = 'none' + // 获取el左边距离浏览器左侧的距离 + const elLeft = el.offsetLeft + isPress = true + + // 鼠标移动时,计算出拖拽的距离 + document.onmousemove = (moveEvent) => { + let width = moveEvent.pageX - elLeft - (binding.value || 1) + if (width < minWidth) { + width = minWidth + } + el.style.width = `${width}px` + // 将width赋值到CSS自定义属性 + el.style.setProperty('--el-width', `${width}px`) + + // 阻止默认行为 + return false + } + // 鼠标抬起时,结束拖拽 + document.onmouseup = () => { + document.onmousemove = null + document.onmouseup = null + document.body.style.userSelect = 'auto' + isPress = false + } + // 阻止默认行为 + return false + } +} diff --git a/src/main.ts b/src/main.ts index c0ae2c9..3627be3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,6 +10,9 @@ import useSettingsStore from './store/modules/settings' import request from '@/api/index' import '@/utils/getLocation' +// 自定义指令 +import { dragHeight } from '@/directives/drag-height/index' +import { dragWidth } from '@/directives/drag-width/index' // 引入音频文件 import alarmAudio from '@/assets/audio/alarm.mp3' // 自定义指令 @@ -83,6 +86,13 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) { app.component(key, component) } + // 加载自定义指令 + app.directive('drag-height', (el, binding) => { + dragHeight(el, binding) + }) + app.directive('drag-width', (el, binding) => { + dragWidth(el, binding) + }) directive(app) app.mount('#app') }).catch((error) => { diff --git a/src/views/home/alarm/count/components/alarmStatistics.vue b/src/views/home/alarm/count/components/alarmStatistics.vue index ba7cc9d..cdff362 100644 --- a/src/views/home/alarm/count/components/alarmStatistics.vue +++ b/src/views/home/alarm/count/components/alarmStatistics.vue @@ -8,7 +8,7 @@ import { getAlarmType, getAlarmTypeList } from '@/api/home/alarm/count' import { shortcuts } from '@/utils/common' const listQuery = ref({ - timeType: '2', + timeType: '1', ledgerType: '', deptid: '', begTime: '', @@ -101,6 +101,12 @@