提交 313f1354 编写于 作者: fxy060608's avatar fxy060608

chore: allowJs

上级 4fb41fe8
import { ComponentPublicInstance } from 'vue'
import { operateVideoPlayer } from '@dcloudio/uni-platform'
import { getCurrentPageVm } from '../../helpers/utils'
const RATES = [0.5, 0.8, 1.0, 1.25, 1.5, 2.0]
export class VideoContext {
private id: string
private vm: ComponentPublicInstance
constructor(id: string, vm: ComponentPublicInstance) {
this.id = id
this.vm = vm
}
play() {
operateVideoPlayer(this.id, this.vm, 'play')
}
pause() {
operateVideoPlayer(this.id, this.vm, 'pause')
}
stop() {
operateVideoPlayer(this.id, this.vm, 'stop')
}
seek(position: number) {
operateVideoPlayer(this.id, this.vm, 'seek', {
position,
})
}
sendDanmu(args: WechatMiniprogram.Danmu) {
operateVideoPlayer(this.id, this.vm, 'sendDanmu', args)
}
playbackRate(rate: number) {
if (!~RATES.indexOf(rate)) {
rate = 1.0
}
operateVideoPlayer(this.id, this.vm, 'playbackRate', {
rate,
})
}
requestFullScreen(
args: WechatMiniprogram.VideoContextRequestFullScreenOption = {}
) {
operateVideoPlayer(this.id, this.vm, 'requestFullScreen', args)
}
exitFullScreen() {
operateVideoPlayer(this.id, this.vm, 'exitFullScreen')
}
showStatusBar() {
operateVideoPlayer(this.id, this.vm, 'showStatusBar')
}
hideStatusBar() {
operateVideoPlayer(this.id, this.vm, 'hideStatusBar')
}
}
export function createVideoContext(
id: string,
context: ComponentPublicInstance
) {
if (context) {
return new VideoContext(id, context)
}
return new VideoContext(id, getCurrentPageVm())
}
import { extend } from '@vue/shared'
import { ServiceJSBridge } from '@dcloudio/uni-core'
import { defineSyncApi } from '../../helpers/api'
import { getCurrentPageVm } from '../../helpers/utils'
......@@ -37,7 +35,7 @@ const reqComponentObserverCallbacks: Record<number, ObserveResultCallback> = {}
export const API_CREATE_INTERSECTION_OBSERVER = 'createIntersectionObserver'
ServiceJSBridge.subscribe(
UniServiceJSBridge.subscribe(
'requestComponentObserver',
({ reqId, reqEnd, res }: requestComponentObserver) => {
const callback = reqComponentObserverCallbacks[reqId]
......
import { extend } from '@vue/shared'
// @ts-ignore TODO 等待 vue3 的兼容模式自带emitter
// TODO 等待 vue3 的兼容模式自带emitter
import E from './TinyEmitter'
export function initBridge(
namespace: 'service' | 'view'
): UniApp.UniServiceJSBridge {
): Partial<UniApp.UniServiceJSBridge> {
// TODO vue3 compatibility builds
const emitter = new E()
return extend(emitter, {
subscribe(event: string, callback: Function): void {
return emitter.on(`${namespace}.${event}`, callback)
emitter.on(`${namespace}.${event}`, callback)
},
unsubscribe(event: string, callback: Function): void {
return emitter.off(`${namespace}.${event}`, callback)
emitter.off(`${namespace}.${event}`, callback)
},
subscribeHandler(event: string, args: unknown, pageId: number): void {
if (__DEV__) {
......@@ -22,7 +22,7 @@ export function initBridge(
)}, ${pageId}`
)
}
return emitter.emit(`${namespace}.${event}`, args, pageId)
emitter.emit(`${namespace}.${event}`, args, pageId)
},
})
}
......@@ -103,16 +103,16 @@ function initBridge(namespace) {
const emitter2 = new E();
return extend(emitter2, {
subscribe(event2, callback) {
return emitter2.on(`${namespace}.${event2}`, callback);
emitter2.on(`${namespace}.${event2}`, callback);
},
unsubscribe(event2, callback) {
return emitter2.off(`${namespace}.${event2}`, callback);
emitter2.off(`${namespace}.${event2}`, callback);
},
subscribeHandler(event2, args, pageId) {
if (process.env.NODE_ENV !== "production") {
console.log(`[${namespace}][subscribeHandler][${Date.now()}]:${event2}, ${JSON.stringify(args)}, ${pageId}`);
}
return emitter2.emit(`${namespace}.${event2}`, args, pageId);
emitter2.emit(`${namespace}.${event2}`, args, pageId);
}
});
}
......@@ -8024,7 +8024,7 @@ const defaultOptions = {
let reqComponentObserverId = 1;
const reqComponentObserverCallbacks = {};
const API_CREATE_INTERSECTION_OBSERVER = "createIntersectionObserver";
ServiceJSBridge.subscribe("requestComponentObserver", ({reqId, reqEnd, res}) => {
UniServiceJSBridge.subscribe("requestComponentObserver", ({reqId, reqEnd, res}) => {
const callback = reqComponentObserverCallbacks[reqId];
if (callback) {
if (reqEnd) {
......
export * from './getRealPath'
export { getBaseSystemInfo } from './getBaseSystemInfo'
export { getBaseSystemInfo } from '../service/api/base/getBaseSystemInfo'
export { operateVideoPlayer } from '../service/api/context/operateVideoPlayer'
import { ComponentPublicInstance } from 'vue'
export function operateVideoPlayer(
videoId: string,
vm: ComponentPublicInstance,
type: string,
data?: unknown
) {
const pageId = vm.$page.id
UniServiceJSBridge.publishHandler(
pageId + '-video-' + videoId,
{
videoId,
type,
data,
},
pageId
)
}
......@@ -13,7 +13,7 @@ import {
getScreenWidth,
getWindowWidth,
getScreenHeight,
} from '../../../platform/getBaseSystemInfo'
} from '../base/getBaseSystemInfo'
/**
* 获取系统信息-同步
......
<template>
<uni-ad
v-bind="attrs"
v-on="$listeners"
>
<div
ref="container"
class="uni-ad-container"
@click="_onhandle"
/>
</uni-ad>
</template>
<script>
import {
subscriber
} from 'uni-mixins'
class AdConfig {
static get instance () {
if (this._instance == null) {
this._instance = new AdConfig()
this._instance._init()
}
return this._instance
}
static IC = 0
static IS = 0
constructor () {
this._instance = null
this._adConfig = null
this._isLoading = false
this._lastError = null
this._callbacks = []
}
get adConfig () {
return this._adConfig
}
get isExpired () {
if (this._adConfig == null) {
return true
}
return (Math.abs(Date.now() - this._adConfig.last) > this.CACHE_TIME)
}
_init () {
var config = this._getConfig()
if (config === null || !config.last) {
return
}
if (!this.isExpired) {
this._adConfig = config.data
}
}
get (adpid, success, fail) {
AdConfig.IC++
if (this._adConfig != null) {
this._doCallback(adpid, success, fail)
if (this.isExpired) {
this._loadAdConfig(adpid)
}
return
}
this._callbacks.push({
adpid: adpid,
success: success,
fail: fail
})
this._loadAdConfig(adpid)
}
_doCallback (adpid, success, fail) {
AdConfig.IS++
var data = this._adConfig
if (data[adpid]) {
success(data[adpid])
} else {
fail(this.ERROR_INVALID_ADPID)
}
}
_loadAdConfig (adpid) {
if (this._isLoading === true) {
return
}
this._isLoading = true
uni.request({
url: this.URL,
method: 'GET',
timeout: 5000,
data: {
d: location.hostname,
a: adpid
},
dataType: 'json',
success: (res) => {
const rd = res.data
if (rd.ret === 0) {
const data = rd.data
this._adConfig = data
this._setConfig(data)
this._callbacks.forEach(({ adpid, success, fail }) => {
this._doCallback(adpid, success, fail)
})
} else {
this._callbacks.forEach((i) => {
i.fail({ errCode: rd.ret, errMsg: rd.msg })
})
}
this._callbacks = []
},
fail: (err) => {
this._callbacks.forEach((i) => {
i.fail(err)
})
this._callbacks = []
},
complete: (c) => {
this._isLoading = false
}
})
}
_getConfig () {
if (!navigator.cookieEnabled || !window.localStorage) {
return null
}
var data = localStorage.getItem(this.KEY)
return data ? JSON.parse(data) : null
}
_setConfig (data) {
if (!navigator.cookieEnabled || !window.localStorage) {
return null
}
localStorage.setItem(this.KEY, JSON.stringify({
last: Date.now(),
data: data
}))
}
}
Object.assign(AdConfig.prototype, {
URL: '//qy5y9ee9ch8r87pg72w5.dcloud.net.cn/hcs',
KEY: 'uni_app_ad_config',
CACHE_TIME: 1000 * 60 * 10,
ERROR_INVALID_ADPID: {
'-5002': '无效adpid'
}
})
class AdReport {
static get instance () {
if (this._instance == null) {
this._instance = new AdReport()
this._instance._init()
}
return this._instance
}
constructor () {
this._instance = null
this._adConfig = null
this._guid = null
}
_init () {
var config = this._getConfig()
if (config !== null && config.guid) {
this._guid = config.guid
return
}
this._guid = this._newGUID()
this._setConfig(this._guid)
}
get (data) {
this._process(Object.assign(data, {
d: location.hostname,
i: this._guid
}))
}
_process (data) {
uni.request({
url: this.URL,
method: 'GET',
data: data,
dataType: 'json',
success: () => {
}
})
}
_newGUID () {
let guid = ''
const format = 'xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx'
for (let i = 0; i < format.length; i++) {
if (format[i] === 'x') {
guid += (Math.random() * 16 | 0).toString(16)
} else {
guid += format[i]
}
}
return guid.toUpperCase()
}
_getConfig () {
if (!navigator.cookieEnabled || !window.localStorage) {
return null
}
var data = localStorage.getItem(this.KEY)
return data ? JSON.parse(data) : null
}
_setConfig (guid) {
if (!navigator.cookieEnabled || !window.localStorage) {
return null
}
localStorage.setItem(this.KEY, JSON.stringify({
last: Date.now(),
guid: guid
}))
}
}
Object.assign(AdReport.prototype, {
URL: '//hp66hwpyev7yx2hfughh.dcloud.net.cn/ahl',
KEY: 'uni_app_ad_guid'
})
const adProvider = {
hx: 'zswx_hx',
ky: 'zswx_ky'
}
const CHECK_RENDER_DELAY = 1000
const CHECK_RENDER_RETRY = 3
export default {
name: 'Ad',
mixins: [subscriber],
props: {
adpid: {
type: [Number, String],
default: ''
}
},
watch: {
adpid (val) {
if (val) {
this._loadData(val)
}
}
},
mounted () {
this._pl = []
this._pd = {}
this._pi = 0
this._checkTimer = null
this._checkTimerCount = 0
this._loadData()
AdReport.instance.get({
h: __uniConfig.compilerVersion,
a: this.adpid,
at: 30,
ic: AdConfig.IC,
is: AdConfig.IS
})
},
beforeDestroy () {
this._clearCheckTimer()
this.$refs.container.innerHTML = ''
},
methods: {
_onhandle (e) {
this._report(41)
},
_reset () {
this._pl = []
this._pd = {}
this._pi = 0
this._clearCheckTimer()
this.$refs.container.innerHTML = ''
},
_loadData (adpid) {
this._reset()
AdConfig.instance.get(adpid || this.adpid, (data) => {
this._pd = data
this._pl = data.psp.split(',')
this._renderAd()
}, (err) => {
this.$trigger('error', {}, err)
})
},
_renderAd () {
if (this._pi > this._pl.length - 1) {
return
}
var ap = this._pl[this._pi]
var data = this._pd[ap]
switch (ap) {
case adProvider.hx:
this._renderHX(data)
break
case adProvider.ky:
this._renderKY(data)
break
}
},
_renderNext () {
if (this._pi >= this._pl.length - 1) {
return
}
this._pi++
this._renderAd()
},
_renderHX (data) {
if (document.querySelector('#' + adProvider.hx)) {
this._renderNext()
return
}
var ad = document.createElement('script')
ad.src = data.src || data.url
var adView = document.createElement('div')
adView.setAttribute('id', adProvider.hx)
adView.appendChild(ad)
this.$refs.container.innerHTML = ''
this.$refs.container.append(adView)
this._startCheckTimer()
},
_renderKY (data) {
var randomId = this._randomId()
var ad = document.createElement('script')
ad.src = (data.src || data.url) + '&_ct=' + randomId
var adView = document.createElement('div')
adView.setAttribute('id', randomId)
adView.appendChild(ad)
this.$refs.container.innerHTML = ''
this.$refs.container.append(adView)
this._startCheckTimer()
},
_checkRender () {
var hasContent = (this.$refs.container.children.length > 0 && this.$refs.container.clientHeight > 40)
if (hasContent) {
this._report(40)
}
return hasContent
},
_startCheckTimer () {
this._clearCheckTimer()
this._checkTimer = setInterval(() => {
this._checkTimerCount++
if (this._checkTimerCount >= CHECK_RENDER_RETRY) {
this._clearCheckTimer()
this._renderNext()
return
}
if (this._checkRender()) {
this._clearCheckTimer()
}
}, CHECK_RENDER_DELAY)
},
_clearCheckTimer () {
this._checkTimerCount = 0
if (this._checkTimer != null) {
window.clearInterval(this._checkTimer)
this._checkTimer = null
}
},
_report (type) {
var taskId = ''
if (this._pl.length > 0 && this._pi < this._pl.length) {
var data = this._pd[this._pl[this._pi]]
if (data) {
taskId = data.task_id
}
}
AdReport.instance.get({
h: __uniConfig.compilerVersion,
a: this.adpid,
t: taskId,
at: type
})
},
_randomId () {
var result = ''
for (let i = 0; i < 2; i++) {
result += (65536 * (1 + Math.random()) | 0).toString(16).substring(1)
}
return result
}
}
}
</script>
<style>
uni-ad {
display: block;
overflow: hidden;
}
uni-ad[hidden] {
display: none;
}
</style>
<template>
<uni-cover-image
:src="src"
v-on="$listeners"
>
<div
class="uni-cover-image"
>
<img
v-if="src"
:src="$getRealPath(src)"
@load="_load"
@error="_error"
>
</div>
</uni-cover-image>
</template>
<script>
export default {
name: 'CoverImage',
props: {
src: {
type: String,
default: ''
}
},
methods: {
_load ($event) {
this.$trigger('load', $event)
},
_error ($event) {
this.$trigger('error', $event)
}
}
}
</script>
<style>
uni-cover-image {
display: block;
line-height: 1.2;
overflow: hidden;
height: 100%;
width: 100%;
pointer-events: auto;
}
uni-cover-image img {
width: 100%;
height: 100%;
}
uni-cover-image[hidden] {
display: none;
}
uni-cover-image .uni-cover-image {
width: 100%;
height: 100%;
text-overflow: inherit;
overflow: inherit;
white-space: nowrap;
-webkit-align-items: inherit;
align-items: inherit;
-webkit-justify-content: inherit;
justify-content: inherit;
-webkit-flex-direction: inherit;
flex-direction: inherit;
font-size: 0;
display: inherit;
}
</style>
<template>
<uni-cover-view
:scroll-top="scrollTop"
v-on="$listeners"
>
<div
ref="content"
class="uni-cover-view"
>
<slot />
</div>
</uni-cover-view>
</template>
<script>
export default {
name: 'CoverView',
props: {
scrollTop: {
type: [String, Number],
default: 0
}
},
watch: {
scrollTop (val) {
this.setScrollTop(val)
}
},
mounted () {
this.setScrollTop(this.scrollTop)
},
methods: {
setScrollTop (val) {
var content = this.$refs.content
if (getComputedStyle(content).overflowY === 'scroll') {
content.scrollTop = this._upx2pxNum(val)
}
},
_upx2pxNum (val) {
if (/\d+[ur]px$/i.test(val)) {
val.replace(/\d+[ur]px$/i, text => {
return uni.upx2px(parseFloat(text))
})
}
return parseFloat(val) || 0
}
}
}
</script>
<style>
uni-cover-view {
display: block;
line-height: 1.2;
overflow: hidden;
white-space: nowrap;
pointer-events: auto;
}
uni-cover-view[hidden] {
display: none;
}
uni-cover-view .uni-cover-view {
width: 100%;
height: 100%;
text-overflow: inherit;
overflow: hidden;
white-space: inherit;
-webkit-align-items: inherit;
align-items: inherit;
-webkit-justify-content: inherit;
justify-content: inherit;
-webkit-flex-direction: inherit;
flex-direction: inherit;
-webkit-flex-wrap: inherit;
flex-wrap: inherit;
display: inherit;
overflow: inherit;
}
</style>
此差异已折叠。
此差异已折叠。
此差异已折叠。
# web-view
|属性|完成度|
|:-|:-|
|src|√|
|@message|-|
|方法|完成度|
|:-|:-|
|navigateTo|√|
|redirectTo|√|
|reLaunch|√|
|switchTab|√|
|navigateBack|√|
|getEnv|√|
|postMessage|-|
<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>
......@@ -6,7 +6,7 @@
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"allowJs": false,
"allowJs": true,
"strict": true,
"noUnusedLocals": true,
"experimentalDecorators": true,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册