Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
18ac357d
U
uni-app
项目概览
DCloud
/
uni-app
2 个月 前同步成功
通知
717
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
18ac357d
编写于
5月 18, 2021
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: set contextInfo to element
上级
2940c38c
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
56 addition
and
9 deletion
+56
-9
packages/uni-components/src/components/canvas/index.vue
packages/uni-components/src/components/canvas/index.vue
+3
-2
packages/uni-components/src/components/editor/index.tsx
packages/uni-components/src/components/editor/index.tsx
+3
-2
packages/uni-components/src/helpers/useContextInfo.ts
packages/uni-components/src/helpers/useContextInfo.ts
+37
-0
packages/uni-components/src/helpers/useSubscribe.ts
packages/uni-components/src/helpers/useSubscribe.ts
+4
-3
packages/uni-components/src/index.ts
packages/uni-components/src/index.ts
+1
-0
packages/uni-h5/src/view/components/map/index.tsx
packages/uni-h5/src/view/components/map/index.tsx
+3
-1
packages/uni-h5/src/view/components/video/index.tsx
packages/uni-h5/src/view/components/video/index.tsx
+5
-1
未找到文件。
packages/uni-components/src/components/canvas/index.vue
浏览文件 @
18ac357d
...
...
@@ -23,7 +23,7 @@
</
template
>
<
script
lang=
"ts"
>
import
{
ref
}
from
"
vue
"
;
import
{
useAttrs
,
useSubscribe
,
withWebEvent
}
from
"
@dcloudio/uni-components
"
;
import
{
useAttrs
,
use
ContextInfo
,
use
Subscribe
,
withWebEvent
}
from
"
@dcloudio/uni-components
"
;
import
{
getCurrentPageVm
,
getCurrentPageId
,
onEventPrevent
}
from
"
@dcloudio/uni-core
"
;
import
{
saveImage
,
getSameOriginUrl
}
from
"
@dcloudio/uni-platform
"
;
import
ResizeSensor
from
"
../resize-sensor
"
;
...
...
@@ -144,7 +144,8 @@ export default {
created
()
{
this
.
_actionsDefer
=
[];
this
.
_images
=
{};
useSubscribe
(
this
.
_handleSubscribe
);
const
id
=
useContextInfo
();
useSubscribe
(
this
.
_handleSubscribe
,
id
,
true
);
},
mounted
()
{
this
.
$trigger
=
useNativeEvent
(
this
.
$emit
);
...
...
packages/uni-components/src/components/editor/index.tsx
浏览文件 @
18ac357d
...
...
@@ -5,7 +5,7 @@ import QuillClass, {
RangeStatic
,
StringMap
,
}
from
'
quill
'
import
{
useSubscribe
}
from
'
@dcloudio/uni-components
'
import
{
use
ContextInfo
,
use
Subscribe
}
from
'
@dcloudio/uni-components
'
import
{
getRealPath
}
from
'
@dcloudio/uni-platform
'
import
{
defineBuiltInComponent
}
from
'
../../helpers/component
'
import
{
CustomEventTrigger
,
useCustomEvent
}
from
'
../../helpers/useEvent
'
...
...
@@ -256,6 +256,7 @@ function useQuill(
}
})
})
const
id
=
useContextInfo
()
useSubscribe
((
type
:
string
,
data
:
any
)
=>
{
const
{
options
,
callbackId
}
=
data
let
res
...
...
@@ -412,7 +413,7 @@ function useQuill(
}),
})
}
})
}
,
id
,
true
)
}
const
props
=
/*#__PURE__*/
Object
.
assign
({},
keyboardProps
,
{
...
...
packages/uni-components/src/helpers/useContextInfo.ts
0 → 100644
浏览文件 @
18ac357d
import
{
onMounted
,
getCurrentInstance
,
}
from
'
vue
'
import
{
useCurrentPageId
}
from
'
@dcloudio/uni-core
'
type
ContextType
=
'
canvas
'
|
'
map
'
|
'
video
'
|
'
editor
'
export
interface
ContextInfo
{
id
:
string
,
type
:
ContextType
page
:
number
}
export
interface
HTMLElementWithContextInfo
extends
HTMLElement
{
__uniContextInfo
?:
ContextInfo
}
let
index
=
0
export
function
useContextInfo
()
{
const
page
=
useCurrentPageId
()
const
instance
=
getCurrentInstance
()
!
const
vm
=
instance
.
proxy
!
const
type
=
vm
.
$options
.
name
!
.
toLowerCase
()
as
ContextType
const
id
=
(
vm
as
any
).
id
||
`context
${
index
++
}
`
onMounted
(()
=>
{
const
el
=
vm
.
$el
as
HTMLElementWithContextInfo
el
.
__uniContextInfo
=
{
id
,
type
,
page
}
})
return
`
${
page
}
.
${
type
}
.
${
id
}
`
}
export
function
getContextInfo
(
el
:
HTMLElement
|
HTMLElementWithContextInfo
)
{
return
(
el
as
HTMLElementWithContextInfo
).
__uniContextInfo
}
\ No newline at end of file
packages/uni-components/src/helpers/useSubscribe.ts
浏览文件 @
18ac357d
...
...
@@ -42,14 +42,15 @@ function removeSubscribe(name: string) {
export
function
useSubscribe
(
callback
:
(
type
:
string
,
data
:
unknown
)
=>
void
,
name
?:
string
name
?:
string
,
multiple
?:
boolean
)
{
const
instance
=
getCurrentInstance
()
!
const
vm
=
instance
.
proxy
!
const
pageId
=
name
?
0
:
useCurrentPageId
()
const
pageId
=
multiple
||
!
name
?
useCurrentPageId
()
:
0
onMounted
(()
=>
{
addSubscribe
(
name
||
normalizeEvent
(
pageId
,
vm
)
!
,
callback
)
if
(
!
name
)
{
if
(
multiple
||
!
name
)
{
watch
(
()
=>
(
vm
as
any
).
id
,
(
value
,
oldValue
)
=>
{
...
...
packages/uni-components/src/index.ts
浏览文件 @
18ac357d
export
*
from
'
./components
'
export
{
useOn
,
useSubscribe
}
from
'
./helpers/useSubscribe
'
export
{
useContextInfo
,
getContextInfo
}
from
'
./helpers/useContextInfo
'
export
{
withWebEvent
,
useCustomEvent
,
...
...
packages/uni-h5/src/view/components/map/index.tsx
浏览文件 @
18ac357d
...
...
@@ -10,6 +10,7 @@ import {
}
from
'
vue
'
import
{
defineBuiltInComponent
,
useContextInfo
,
useSubscribe
,
useCustomEvent
,
}
from
'
@dcloudio/uni-components
'
...
...
@@ -299,6 +300,7 @@ function useMap(
}
try
{
// TODO 支持在页面外使用
const
id
=
useContextInfo
()
useSubscribe
((
type
,
data
:
any
=
{})
=>
{
switch
(
type
)
{
case
'
getCenterLocation
'
:
...
...
@@ -391,7 +393,7 @@ function useMap(
})
break
}
})
}
,
id
,
true
)
}
catch
(
error
)
{}
onMounted
(()
=>
{
loadMaps
((
result
)
=>
{
...
...
packages/uni-h5/src/view/components/video/index.tsx
浏览文件 @
18ac357d
...
...
@@ -14,6 +14,7 @@ import { useI18n, initI18nVideoMsgsOnce } from '@dcloudio/uni-core'
import
{
getRealPath
}
from
'
@dcloudio/uni-platform
'
import
{
defineBuiltInComponent
,
useContextInfo
,
useSubscribe
,
useCustomEvent
,
EmitEvent
,
...
...
@@ -683,6 +684,7 @@ function useContext(
requestFullScreen
,
exitFullScreen
,
}
const
id
=
useContextInfo
()
useSubscribe
((
type
:
string
,
data
:
any
)
=>
{
let
options
switch
(
type
)
{
...
...
@@ -699,7 +701,7 @@ function useContext(
if
(
type
in
methods
)
{
methods
[
type
as
keyof
typeof
methods
](
options
)
}
})
}
,
id
,
true
)
}
const
props
=
{
...
...
@@ -875,6 +877,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
onTouchstart
=
{
onTouchstart
}
onTouchend
=
{
onTouchend
}
onTouchmove
=
{
onTouchmove
}
// @ts-ignore
onFullscreenchange
=
{
withModifiers
(
onFullscreenChange
,
[
'
stop
'
])
}
onWebkitfullscreenchange
=
{
withModifiers
(
(
$event
:
Event
)
=>
onFullscreenChange
(
$event
,
true
),
...
...
@@ -883,6 +886,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
>
<
video
ref
=
{
videoRef
}
// @ts-ignore
style
=
{
{
'
object-fit
'
:
props
.
objectFit
}
}
muted
=
{
!!
props
.
muted
}
loop
=
{
!!
props
.
loop
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录