当前位置:网站首页>便利贴--48{再次,适配屏幕宽高class}
便利贴--48{再次,适配屏幕宽高class}
2022-08-08 10:11:00 【轻动琴弦】
便利贴--48{再次,适配屏幕宽高class}
监听resize事件
export function addEventListen(
target: Window | HTMLElement, event: string, handler: EventListenerOrEventListenerObject, capture = false
) {
if (
target.addEventListener &&
typeof target.addEventListener === 'function'
) {
target.addEventListener(event, handler, capture);
}
}
export function removeEventListen(
target: Window | HTMLElement, event: string, handler: EventListenerOrEventListenerObject, capture = false
) {
if (
target.removeEventListener &&
typeof target.removeEventListener === 'function'
) {
target.removeEventListener(event, handler, capture);
}
}
监听主要class
import {
addEventListen, removeEventListen } from "@/utils/event";
class changeTabelSize {
constructor(arg) {
console.log(arg, 'see111')
this.time = null;
this.timeNum = arg.time || 320;
this.tabelWidth = arg?.tabelWidth || '300px';
this.otherWidthClass = arg?.otherWidthClass || null;
this.otherHeightClass = arg?.otherHeightClass || null;
this.value = arg?.value || null;
this.minWidth = arg?.minWidth || 0;
this.fn = arg?.fn || null;
this.init()
}
listener(tag) {
let methods = addEventListen;
if (tag === false) methods = removeEventListen;
// window[methods](
// "resize",
// this.init.bind(this),
// false
// );
methods(window, "resize", this.init.bind(this))
}
// getPad
init() {
clearTimeout(this.time);
this.time = setTimeout(() => {
//判断除去menu的宽度
let pinWidth = document.body.clientWidth; //屏幕可见宽度
let menuWidth = document.getElementsByClassName("layout-sider")?.[0]?.clientWidth;
//获取其他影响宽度的dom
let otherClassWidth = 0;
for (let k in this.otherWidthClass) {
let other = this.otherWidthClass[k];
if (typeof this.otherWidthClass[k] == 'string')
other = document.getElementsByClassName(this.otherWidthClass[k])?.[0]?.clientWidth;
otherClassWidth += other;
}
let lastWidth = pinWidth - menuWidth - otherClassWidth;
lastWidth = lastWidth < this.minWidth ? this.minWidth : lastWidth;
// 判断高度
let pinHeight = document.body.clientHeight; //屏幕可见高
//活动高度
let heardHeight = document.getElementsByClassName("layout-navbar")?.[0]?.clientHeight;
//获取其他影响高度的dom
let otherClassHeight = 0;
for (let k in this.otherHeightClass) {
let other = this.otherHeightClass[k];
if (typeof this.otherHeightClass[k] == 'string')
other = document.getElementsByClassName(this.otherHeightClass[k])?.[0]?.clientHeight;
// console.log(this.otherHeightClass[k], other)
otherClassHeight += +other;
}
// console.log(otherClassHeight)
let pageSize = document.getElementsByClassName('arco-pagination')?.[0]?.clientHeight || 0;
let lastHeight = pinHeight - heardHeight - otherClassHeight;
this.value.value = {
width: lastWidth,
height: lastHeight,
tabelHeight: lastHeight - (pageSize + 80)
}
if (this.fn) {
this.fn(this.value.value)
}
}, this.timeNum);
}
}
export default changeTabelSize
使用
无需再次通过watch监听,利用对象的引用特性,进行引用值的更改
也可以自己添加回调函数进行监听并使用
import changeTabelSize from "@/utils/asset/changeTabelSize";
const tabelSize = reactive({
value: {
},
});
const tabelVO = ref(null);
onMounted((res) => {
tabelVO.value = new changeTabelSize({
value: tabelSize,
otherWidthClass: ["left_box", 30],
otherHeightClass: ["title", "searchFrom", "searchTabs", 160],
minWidth: 600,
fn: (res) => {
// console.log(res.height);
tableData.option.height = res.height + "px";
},
});
tabelVO.value.listener();
});
onBeforeUnmount(() => {
tabelVO.value.listener(false);
});
边栏推荐
- FreeSql 将 Saas 租户方案精简到极致[.NET ORM SAAS]
- 嵌入式C编程中错误异常该如何统一处理?
- Web optimization experience (6) - optimization closed-loop practice
- A small test of basic grammar, Go lang1.18 introductory refining tutorial, from Bai Ding to Hongru, basic grammar of go lang and the use of variables EP02
- Multi-scalar multiplication: state of the art & new ideas
- 「控制反转」和「依赖倒置」,傻傻分不清楚?
- String equals hashcode
- vs2019+boost库(boost_1_67_0)安装
- Loadrunner12.0.2 installation and Chinese language pack installation (Chinese)
- go web之响应用户
猜你喜欢
功夫再高也怕菜刀,产品经理的那些事
COMSOL Multiphysics 6.0 software installation package and installation tutorial
业务缓存之体系化设计与开发
Jingkai Safety Supervision App technical service support
01-MQ介绍以及产品比较
Mysql数据库架构介绍
字节与字符与常见编码方式
以技术御风险,护航云原生 | 同创永益 X 博云举办产品联合发布会
Web optimization experience (6) - optimization closed-loop practice
经开安监App技术服务支持
随机推荐
移动端/嵌入式-CV模型-2019:MobelNets-v3
Classification of software testing
Jingkai Safety Supervision App technical service support
Mobile/Embedded-CV Model-2017: MobelNets-v1
Is it safe to buy stocks with a straight flush?Will the funds be transferred?
关系型数据库的优缺点是什么?
MySQL学习第一部分:认识MySQL
列存储数据库是通过什么来定位的呢?
以技术御风险,护航云原生 | 同创永益 X 博云举办产品联合发布会
centos 安装redis
go调度原理
.net开发中,C# DateTime.Now 取出的时间含有星期解决办法
NoSQL数据库有哪些优势吗?又有哪些劣势呢?
A concise tutorial on expanding (increasing capacity) of VMWare Esxi virtual system data storage
STM32F103ZE+SHT30检测环境温度与湿度(IIC模拟时序)
"Inversion of Control" and "Dependency Inversion", can't you tell the difference?
Detailed Explanation of Gradient Vanishing and Gradient Explosion Problems
市面上有哪些经典的文档数据库呀?
分门别类输入输出,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang基本数据类型和输入输出EP03
Dubins curve study notes and related thinking