Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
菜鸟程序猿_c
uni-app
提交
d2181186
U
uni-app
项目概览
菜鸟程序猿_c
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d2181186
编写于
4月 22, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(h5): web-view
上级
a3b5033a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
107 addition
and
70 deletion
+107
-70
packages/uni-h5/src/view/components/index.ts
packages/uni-h5/src/view/components/index.ts
+2
-1
packages/uni-h5/src/view/components/web-view/index.tsx
packages/uni-h5/src/view/components/web-view/index.tsx
+98
-0
packages/uni-h5/src/view/components/web-view/index.vue
packages/uni-h5/src/view/components/web-view/index.vue
+0
-69
packages/uni-h5/style/web-view.css
packages/uni-h5/style/web-view.css
+7
-0
未找到文件。
packages/uni-h5/src/view/components/index.ts
浏览文件 @
d2181186
import
Video
from
'
./video/index
'
import
WebView
from
'
./web-view/index
'
export
{
Video
}
export
{
Video
,
WebView
}
packages/uni-h5/src/view/components/web-view/index.tsx
0 → 100644
浏览文件 @
d2181186
import
{
defineComponent
,
watch
,
ref
,
ExtractPropTypes
,
onMounted
,
Ref
,
onActivated
,
onDeactivated
,
onUnmounted
,
}
from
'
vue
'
import
{
ResizeSensor
}
from
'
@dcloudio/uni-components
'
import
{
getRealPath
}
from
'
@dcloudio/uni-platform
'
import
{
updateElementStyle
}
from
'
@dcloudio/uni-shared
'
const
props
=
{
src
:
{
type
:
String
,
default
:
''
,
},
allow
:
String
,
sandbox
:
String
,
}
type
WebViewProps
=
ExtractPropTypes
<
typeof
props
>
type
RootRef
=
Ref
<
HTMLElement
|
null
>
type
ReSize
=
ReturnType
<
typeof
useWebViewSize
>
[
'
_resize
'
]
export
default
/*#__PURE__*/
defineComponent
({
name
:
'
WebView
'
,
props
,
setup
(
props
)
{
const
rootRef
:
RootRef
=
ref
(
null
)
const
iframe
=
document
.
createElement
(
'
iframe
'
)
const
{
_resize
}
=
useWebViewSize
(
rootRef
,
iframe
)
useWebViewLoader
(
iframe
,
props
,
_resize
)
return
()
=>
(
<
uni
-
web
-
view
ref
=
{
rootRef
}
>
<
ResizeSensor
onResize
=
{
_resize
}
/>
</
uni
-
web
-
view
>
)
},
})
function
useWebViewLoader
(
iframe
:
HTMLIFrameElement
,
props
:
WebViewProps
,
_resize
:
ReSize
)
{
props
.
allow
&&
iframe
.
setAttribute
(
'
allow
'
,
props
.
allow
)
props
.
sandbox
&&
iframe
.
setAttribute
(
'
sandbox
'
,
props
.
sandbox
)
iframe
.
src
=
getRealPath
(
props
.
src
)
document
.
body
.
appendChild
(
iframe
)
onMounted
(()
=>
{
_resize
()
})
onActivated
(()
=>
{
iframe
.
style
.
display
=
'
block
'
})
onDeactivated
(()
=>
{
iframe
.
style
.
display
=
'
none
'
})
onUnmounted
(()
=>
{
document
.
body
.
removeChild
(
iframe
)
})
watch
(
()
=>
props
.
src
,
(
val
)
=>
{
iframe
.
src
=
getRealPath
(
val
)
}
)
}
function
useWebViewSize
(
rootRef
:
RootRef
,
iframe
:
HTMLIFrameElement
)
{
const
_resize
=
()
=>
{
const
{
top
,
left
,
width
,
height
}
=
rootRef
.
value
!
.
getBoundingClientRect
()
updateElementStyle
(
iframe
,
{
position
:
'
absolute
'
,
display
:
'
block
'
,
border
:
'
0
'
,
top
:
top
+
'
px
'
,
left
:
left
+
'
px
'
,
width
:
width
+
'
px
'
,
height
:
height
+
'
px
'
,
})
}
return
{
_resize
,
}
}
packages/uni-h5/src/view/components/web-view/index.vue
已删除
100644 → 0
浏览文件 @
a3b5033a
<
template
>
<uni-web-view
v-on=
"$listeners"
>
<v-uni-resize-sensor
ref=
"sensor"
@
resize=
"_resize"
/>
</uni-web-view>
</
template
>
<
script
>
export
default
{
name
:
'
WebView
'
,
props
:
{
src
:
{
type
:
String
,
default
:
''
}
},
watch
:
{
src
(
val
,
oldVal
)
{
this
.
iframe
&&
(
this
.
iframe
.
src
=
this
.
$getRealPath
(
this
.
src
))
}
},
mounted
()
{
this
.
iframe
=
document
.
createElement
(
'
iframe
'
)
Object
.
keys
(
this
.
$attrs
).
forEach
(
key
=>
{
this
.
iframe
[
key
]
=
this
.
$attrs
[
key
]
})
this
.
iframe
.
src
=
this
.
$getRealPath
(
this
.
src
)
document
.
body
.
appendChild
(
this
.
iframe
)
this
.
_resize
()
},
activated
()
{
this
.
iframe
.
style
.
display
=
'
block
'
},
deactivated
()
{
this
.
iframe
.
style
.
display
=
'
none
'
},
beforeDestroy
()
{
document
.
body
.
removeChild
(
this
.
iframe
)
},
methods
:
{
_resize
()
{
const
{
top
,
left
,
width
,
height
}
=
this
.
$el
.
getBoundingClientRect
()
this
.
iframe
.
style
.
position
=
'
absolute
'
this
.
iframe
.
style
.
display
=
'
block
'
this
.
iframe
.
style
.
border
=
0
this
.
iframe
.
style
.
top
=
top
+
'
px
'
this
.
iframe
.
style
.
left
=
left
+
'
px
'
this
.
iframe
.
style
.
width
=
width
+
'
px
'
this
.
iframe
.
style
.
height
=
height
+
'
px
'
}
}
}
</
script
>
<
style
>
uni-web-view
{
position
:
absolute
;
left
:
0
;
right
:
0
;
top
:
0
;
bottom
:
0
;
}
</
style
>
packages/uni-h5/style/web-view.css
0 → 100644
浏览文件 @
d2181186
uni-web-view
{
position
:
absolute
;
left
:
0
;
right
:
0
;
top
:
0
;
bottom
:
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录