Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dsk-operate-sys-cscec
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fulixin
dsk-operate-sys-cscec
Commits
103b8e9d
Commit
103b8e9d
authored
Mar 21, 2024
by
tianhongyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
屏幕缩放率 浏览器跟随适配
parent
c38f9b95
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
0 deletions
+106
-0
main.js
dsk-operate-ui/src/main.js
+5
-0
screenScal.js
dsk-operate-ui/src/utils/screenScal.js
+99
-0
Sidebar.vue
...operate-ui/src/views/detail/party-a/component/Sidebar.vue
+2
-0
No files found.
dsk-operate-ui/src/main.js
View file @
103b8e9d
...
...
@@ -52,6 +52,9 @@ import VueMeta from 'vue-meta';
// 字典数据组件
import
DictData
from
'@/components/DictData'
;
// 全局缩放
import
ScreenScal
from
"@/utils/screenScal"
;
// 全局方法挂载
Vue
.
prototype
.
getDicts
=
getDicts
;
Vue
.
prototype
.
getConfigKey
=
getConfigKey
;
...
...
@@ -105,3 +108,5 @@ new Vue({
store
,
render
:
h
=>
h
(
App
)
});
new
ScreenScal
();
dsk-operate-ui/src/utils/screenScal.js
0 → 100644
View file @
103b8e9d
import
{
add
,
multiply
,
divide
}
from
"@/utils/decimal.js"
;
/**
* 根据屏幕缩放率 来进行样式缩放
*/
export
default
class
ScreenScal
{
// 需要缩放适配的倍率
resultCalcZoom
=
null
;
// 总缩放倍数
zoom
=
null
;
// 浏览器缩放倍数
browserZoom
=
null
;
// 系统缩放倍数
systemZoom
=
null
;
// 系统分辨率
systemResolution
=
null
;
constructor
()
{
this
.
setUserScreenScal
();
window
.
addEventListener
(
"resize"
,
this
.
setUserScreenScal
.
bind
(
this
),
false
);
}
setDefaultOptions
()
{
const
{
zoom
,
resultCalcZoom
,
browserZoom
,
systemResolution
,
systemZoom
}
=
this
.
getUserScreenInfo
();
this
.
zoom
=
zoom
;
this
.
resultCalcZoom
=
resultCalcZoom
;
this
.
browserZoom
=
browserZoom
;
this
.
systemZoom
=
systemZoom
;
this
.
systemResolution
=
systemResolution
;
}
/**
* 设置用户缩放
*/
setUserScreenScal
()
{
this
.
setDefaultOptions
();
document
.
body
.
style
.
setProperty
(
"zoom"
,
this
.
resultCalcZoom
);
}
/**
* 参数转换浮点
* @param {*} num
* @returns
*/
getDecimal
=
(
num
)
=>
{
return
parseFloat
(
divide
(
multiply
(
num
,
100
),
100
));
};
/**
* 获取用户屏幕信息
*/
getUserScreenInfo
()
{
// 总缩放倍数
const
zoom
=
this
.
getZoom
();
// 屏幕分辨率
const
screenResolution
=
window
.
screen
.
width
;
// 获取浏览器内部宽度
const
browserWidth
=
window
.
innerWidth
||
document
.
documentElement
.
clientWidth
||
document
.
body
.
clientWidth
;
// 浏览器缩放倍数
// 浏览器外部宽度不受浏览器缩放影响,浏览器内部宽度受影响,所以根据这个可以计算出浏览器缩放倍数(F12调试工具的占位会影响该值)
const
browserZoom
=
this
.
getDecimal
(
window
.
outerWidth
/
browserWidth
);
// 系统缩放倍数
const
systemZoom
=
this
.
getDecimal
(
zoom
/
browserZoom
);
// 系统分辨率
const
systemResolution
=
Math
.
round
(
screenResolution
*
systemZoom
);
// 屏幕最终需要适配结果
const
resultCalcZoom
=
1
/
zoom
;
console
.
log
(
'系统分辨率'
,
systemResolution
,
'屏幕分辨率'
,
screenResolution
,
'浏览器外部宽度'
,
window
.
outerWidth
,
'浏览器内部宽度'
,
browserWidth
,
'总缩放倍数'
,
zoom
,
"系统最终适配倍数"
,
resultCalcZoom
,
'浏览器缩放倍数'
,
browserZoom
,
'系统缩放倍数'
,
systemZoom
);
return
{
zoom
,
resultCalcZoom
,
browserZoom
,
systemZoom
,
systemResolution
};
}
/**
* 获取用户屏幕缩放倍数
* @returns
*/
getZoom
()
{
let
zoom
=
1
;
const
screen
=
window
.
screen
,
ua
=
navigator
.
userAgent
.
toLowerCase
();
if
(
window
.
devicePixelRatio
!==
undefined
)
{
zoom
=
window
.
devicePixelRatio
;
}
else
if
(
~
ua
.
indexOf
(
'msie'
))
{
if
(
screen
.
deviceXDPI
&&
screen
.
logicalXDPI
)
{
zoom
=
screen
.
deviceXDPI
/
screen
.
logicalXDPI
;
}
}
else
if
(
window
.
outerWidth
!==
undefined
&&
window
.
innerWidth
!==
undefined
)
{
zoom
=
window
.
outerWidth
/
window
.
innerWidth
;
}
return
this
.
getDecimal
(
zoom
);
}
}
\ No newline at end of file
dsk-operate-ui/src/views/detail/party-a/component/Sidebar.vue
View file @
103b8e9d
...
...
@@ -548,6 +548,8 @@ export default {
.detail-menu
{
margin-top
:
9px
;
border-right
:
0
;
max-height
:
calc
(
100%
-
50px
);
overflow
:
auto
;
::v-deep
.el-menu-item
,
::v-deep
.el-submenu__title
{
height
:
30px
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment