当前位置:网站首页>便利贴--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);
});
边栏推荐
- Practical Case: Building Churn Prediction Models with PySpark ML
- 「控制反转」和「依赖倒置」,傻傻分不清楚?
- How to uniformly handle error exceptions in embedded C programming?
- vs2019+boost库(boost_1_67_0)安装
- To make people's consumption safer, more assured and more satisfied
- Multi-scalar multiplication: state of the art & new ideas
- 高并发下秒杀商品,你必须知道的9个细节
- 语音聊天app开发——对用户更具吸引力的设计
- NoSQL的意思就是就是不使用SQL吗?
- Pinia(一)初体验快速安装与上手
猜你喜欢

idea安装步骤

高并发下秒杀商品,你必须知道的9个细节

Solutions and ideas for the problem that Loadrunner's recording event is 0

Multi-scalar multiplication: state of the art & new ideas

继承关系下构造方法的访问特点:

How to uniformly handle error exceptions in embedded C programming?

业务缓存之体系化设计与开发

字节与字符与常见编码方式

图像分割 总结

移动端/嵌入式-CV模型-2018:MobelNets-v2
随机推荐
功夫再高也怕菜刀,产品经理的那些事
列存储数据库是什么呢?
Tensorflow basic concepts
2万字50张图玩转Flink面试体系
梯度消失和梯度爆炸问题详解
移动端/嵌入式-CV模型-2019:MobelNets-v3
面试突击72:输入URL之后会执行什么流程?
语音聊天app开发——对用户更具吸引力的设计
MySQL源码解析之执行计划
「控制反转」和「依赖倒置」,傻傻分不清楚?
买股票用同花顺安全吗?资金会不会被转走?
NoSQL数据库有哪些优势吗?又有哪些劣势呢?
d实验新异常
移动端/嵌入式-CV模型-2018:MobileFaceNets
Categorized input and output, Go lang1.18 introductory refining tutorial, from Bai Ding to Hongru, go lang basic data types and input and output EP03
Service Mesh迁移原则
English token preprocessing, used to process English sentences into words
Feign应用及源码剖析
软件测试的分类
Dubins曲线学习笔记及相关思考