Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
fab3f14d
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fab3f14d
编写于
8月 06, 2021
作者:
inkwalk
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(h5): mediaQueryObserver remove listeners
上级
0114e258
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
38 deletion
+43
-38
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+31
-27
packages/uni-h5/src/service/api/ui/mediaQueryObserver.ts
packages/uni-h5/src/service/api/ui/mediaQueryObserver.ts
+11
-6
packages/uni-mp-vue/dist/vue.runtime.esm.js
packages/uni-mp-vue/dist/vue.runtime.esm.js
+1
-5
未找到文件。
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
fab3f14d
...
...
@@ -1653,56 +1653,56 @@ function useProvideLabel() {
});
return handlers;
}
function useListeners$1(props2, listeners) {
_addListeners(props2.id, listeners);
function useListeners$1(props2, listeners
2
) {
_addListeners(props2.id, listeners
2
);
watch(() => props2.id, (newId, oldId) => {
_removeListeners(oldId, listeners, true);
_addListeners(newId, listeners, true);
_removeListeners(oldId, listeners
2
, true);
_addListeners(newId, listeners
2
, true);
});
onUnmounted(() => {
_removeListeners(props2.id, listeners);
_removeListeners(props2.id, listeners
2
);
});
}
function _addListeners(id2, listeners, watch2) {
function _addListeners(id2, listeners
2
, watch2) {
const pageId = useCurrentPageId();
if (watch2 && !id2) {
return;
}
if (!isPlainObject(listeners)) {
if (!isPlainObject(listeners
2
)) {
return;
}
Object.keys(listeners).forEach((name) => {
Object.keys(listeners
2
).forEach((name) => {
if (watch2) {
if (name.indexOf("@") !== 0 && name.indexOf("uni-") !== 0) {
UniViewJSBridge.on(`uni-${name}-${pageId}-${id2}`, listeners[name]);
UniViewJSBridge.on(`uni-${name}-${pageId}-${id2}`, listeners
2
[name]);
}
} else {
if (name.indexOf("uni-") === 0) {
UniViewJSBridge.on(name, listeners[name]);
UniViewJSBridge.on(name, listeners
2
[name]);
} else if (id2) {
UniViewJSBridge.on(`uni-${name}-${pageId}-${id2}`, listeners[name]);
UniViewJSBridge.on(`uni-${name}-${pageId}-${id2}`, listeners
2
[name]);
}
}
});
}
function _removeListeners(id2, listeners, watch2) {
function _removeListeners(id2, listeners
2
, watch2) {
const pageId = useCurrentPageId();
if (watch2 && !id2) {
return;
}
if (!isPlainObject(listeners)) {
if (!isPlainObject(listeners
2
)) {
return;
}
Object.keys(listeners).forEach((name) => {
Object.keys(listeners
2
).forEach((name) => {
if (watch2) {
if (name.indexOf("@") !== 0 && name.indexOf("uni-") !== 0) {
UniViewJSBridge.off(`uni-${name}-${pageId}-${id2}`, listeners[name]);
UniViewJSBridge.off(`uni-${name}-${pageId}-${id2}`, listeners
2
[name]);
}
} else {
if (name.indexOf("uni-") === 0) {
UniViewJSBridge.off(name, listeners[name]);
UniViewJSBridge.off(name, listeners
2
[name]);
} else if (id2) {
UniViewJSBridge.off(`uni-${name}-${pageId}-${id2}`, listeners[name]);
UniViewJSBridge.off(`uni-${name}-${pageId}-${id2}`, listeners
2
[name]);
}
}
});
...
...
@@ -5696,8 +5696,8 @@ function removeIntersectionObserver({ reqId, component }, _pageId) {
delete $el.__io[reqId];
}
}
let mediaQueryObserver;
let listener
$2
;
let mediaQueryObserver
s = {}
;
let listener
s = {}
;
function handleMediaQueryStr($props) {
const mediaQueryArr = [];
const propsMenu = [
...
...
@@ -5724,14 +5724,18 @@ function humpToLine(name) {
return name.replace(/([A-Z])/g, "-$1").toLowerCase();
}
function addMediaQueryObserver({ reqId, component, options, callback }, _pageId) {
mediaQueryObserver
= window.matchMedia(handleMediaQueryStr(options));
listener$2
= (observer) => callback(observer.matches);
listener
$
2(mediaQueryObserver);
mediaQueryObserver.addListener(listener
$
2);
const mediaQueryObserver = mediaQueryObservers[reqId]
= window.matchMedia(handleMediaQueryStr(options));
const listener2 = listeners[reqId]
= (observer) => callback(observer.matches);
listener2(mediaQueryObserver);
mediaQueryObserver.addListener(listener2);
}
function removeMediaQueryObserver({ reqId, component }, _pageId) {
const listener2 = listeners[reqId];
const mediaQueryObserver = mediaQueryObservers[reqId];
if (mediaQueryObserver) {
mediaQueryObserver.removeListener(listener$2);
mediaQueryObserver.removeListener(listener2);
delete listeners[reqId];
delete mediaQueryObservers[reqId];
}
}
function saveImage(base64, dirname, callback) {
...
...
@@ -8346,7 +8350,7 @@ const useAttrs = (params = {}) => {
const { excludeListeners = false, excludeKeys = [] } = params;
const instance2 = getCurrentInstance();
const attrs2 = shallowRef({});
const listeners = shallowRef({});
const listeners
2
= shallowRef({});
const excludeAttrs = shallowRef({});
const allExcludeKeys = excludeKeys.concat(DEFAULT_EXCLUDE_KEYS);
instance2.attrs = reactive(instance2.attrs);
...
...
@@ -8369,10 +8373,10 @@ const useAttrs = (params = {}) => {
listeners: {}
});
attrs2.value = res.attrs;
listeners.value = res.listeners;
listeners
2
.value = res.listeners;
excludeAttrs.value = res.exclude;
});
return { $attrs: attrs2, $listeners: listeners, $excludeAttrs: excludeAttrs };
return { $attrs: attrs2, $listeners: listeners
2
, $excludeAttrs: excludeAttrs };
};
function flatVNode(nodes) {
const array = [];
...
...
packages/uni-h5/src/service/api/ui/mediaQueryObserver.ts
浏览文件 @
fab3f14d
...
...
@@ -3,8 +3,8 @@ import {
RemoveMediaQueryObserverArgs
,
}
from
'
@dcloudio/uni-api
'
let
mediaQueryObserver
:
MediaQueryList
let
listener
:
(
e
:
MediaQueryList
)
=>
void
let
mediaQueryObserver
s
:
any
=
{}
let
listener
s
:
any
=
{}
// 拼接媒体查询条件
function
handleMediaQueryStr
(
$props
:
UniApp
.
DescriptorOptions
)
{
...
...
@@ -48,11 +48,12 @@ export function addMediaQueryObserver(
_pageId
:
number
)
{
// 创建一个媒体查询对象
mediaQueryObserver
=
window
.
matchMedia
(
handleMediaQueryStr
(
options
))
const
mediaQueryObserver
=
(
mediaQueryObservers
[
reqId
]
=
window
.
matchMedia
(
handleMediaQueryStr
(
options
)
))
// 创建一个监听器
listener
=
(
observer
)
=>
callback
(
observer
.
matches
as
any
)
const
listener
=
(
listeners
[
reqId
]
=
(
observer
:
any
)
=>
callback
(
observer
.
matches
as
any
))
listener
(
mediaQueryObserver
)
// 监听前执行一次媒体查询
mediaQueryObserver
.
addListener
(
listener
as
any
)
}
...
...
@@ -62,7 +63,11 @@ export function removeMediaQueryObserver(
{
reqId
,
component
}:
RemoveMediaQueryObserverArgs
,
_pageId
:
number
)
{
const
listener
=
listeners
[
reqId
]
const
mediaQueryObserver
=
mediaQueryObservers
[
reqId
]
if
(
mediaQueryObserver
)
{
mediaQueryObserver
.
removeListener
(
listener
as
any
)
// 移除监听
delete
listeners
[
reqId
]
delete
mediaQueryObservers
[
reqId
]
}
}
packages/uni-mp-vue/dist/vue.runtime.esm.js
浏览文件 @
fab3f14d
...
...
@@ -4044,7 +4044,7 @@ function createVueApp(rootComponent, rootProps = null) {
function
withModifiers
()
{
}
function
createVNode$1
()
{
}
function
initHook
s
(
options
,
instance
,
publicThis
)
{
function
applyOption
s
(
options
,
instance
,
publicThis
)
{
options
.
mpType
||
publicThis
.
$mpType
;
// 为了组件也可以监听部分生命周期,故不再判断mpType,统一添加on开头的生命周期
Object
.
keys
(
options
).
forEach
((
name
)
=>
{
...
...
@@ -4057,10 +4057,6 @@ function initHooks(options, instance, publicThis) {
});
}
function
applyOptions
(
options
,
instance
,
publicThis
)
{
initHooks
(
options
,
instance
,
publicThis
);
}
function
set
(
target
,
key
,
val
)
{
return
(
target
[
key
]
=
val
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录