提交 6f77d014 编写于 作者: Q qiang

Merge branch 'dev' into alpha

......@@ -474,7 +474,6 @@ const is_debug = debug;
* @param {*} data
*/
const log = (data, type) => {
let msg_type = '';
switch (data.lt) {
case '1':
......@@ -500,7 +499,7 @@ const log = (data, type) => {
// #ifdef APP
// 在 app 中,日志转为 字符串
if(typeof data === 'object') {
if (typeof data === 'object') {
data = JSON.stringify(data);
}
// #endif
......@@ -532,6 +531,17 @@ const get_report_Interval = (defaultTime) => {
// 如果不是整数,则默认为上报间隔时间
if (!reg.test(time)) return defaultTime
return Number(time)
};
/**
* 获取隐私协议配置
*/
const is_push_clientid = () => {
if (uniStatisticsConfig.collectItems) {
const ClientID = uniStatisticsConfig.collectItems.uniPushClientID;
return typeof ClientID === 'boolean' ? ClientID : false
}
return false
};
const appid = process.env.UNI_APP_ID; // 做应用隔离
......@@ -1304,7 +1314,8 @@ class Stat extends Report {
* 获取推送id
*/
pushEvent(options) {
if (uni.getPushClientId) {
const ClientID = is_push_clientid();
if (uni.getPushClientId && ClientID) {
uni.getPushClientId({
success: (res) => {
const cid = res.cid || false;
......
......@@ -472,7 +472,6 @@ const is_debug = debug;
* @param {*} data
*/
const log = (data, type) => {
let msg_type = '';
switch (data.lt) {
case '1':
......@@ -498,7 +497,7 @@ const log = (data, type) => {
// #ifdef APP
// 在 app 中,日志转为 字符串
if(typeof data === 'object') {
if (typeof data === 'object') {
data = JSON.stringify(data);
}
// #endif
......@@ -530,6 +529,17 @@ const get_report_Interval = (defaultTime) => {
// 如果不是整数,则默认为上报间隔时间
if (!reg.test(time)) return defaultTime
return Number(time)
};
/**
* 获取隐私协议配置
*/
const is_push_clientid = () => {
if (uniStatisticsConfig.collectItems) {
const ClientID = uniStatisticsConfig.collectItems.uniPushClientID;
return typeof ClientID === 'boolean' ? ClientID : false
}
return false
};
const appid = process.env.UNI_APP_ID; // 做应用隔离
......@@ -1302,7 +1312,8 @@ class Stat extends Report {
* 获取推送id
*/
pushEvent(options) {
if (uni.getPushClientId) {
const ClientID = is_push_clientid();
if (uni.getPushClientId && ClientID) {
uni.getPushClientId({
success: (res) => {
const cid = res.cid || false;
......
......@@ -453,7 +453,6 @@ const is_debug = debug;
* @param {*} data
*/
const log = (data, type) => {
let msg_type = '';
switch (data.lt) {
case '1':
......@@ -479,7 +478,7 @@ const log = (data, type) => {
// #ifdef APP
// 在 app 中,日志转为 字符串
if(typeof data === 'object') {
if (typeof data === 'object') {
data = JSON.stringify(data);
}
// #endif
......@@ -511,6 +510,17 @@ const get_report_Interval = (defaultTime) => {
// 如果不是整数,则默认为上报间隔时间
if (!reg.test(time)) return defaultTime
return Number(time)
};
/**
* 获取隐私协议配置
*/
const is_push_clientid = () => {
if (uniStatisticsConfig.collectItems) {
const ClientID = uniStatisticsConfig.collectItems.uniPushClientID;
return typeof ClientID === 'boolean' ? ClientID : false
}
return false
};
const appid = process.env.UNI_APP_ID; // 做应用隔离
......@@ -1268,7 +1278,8 @@ class Stat extends Report {
* 获取推送id
*/
pushEvent(options) {
if (uni.getPushClientId) {
const ClientID = is_push_clientid();
if (uni.getPushClientId && ClientID) {
uni.getPushClientId({
success: (res) => {
const cid = res.cid || false;
......
......@@ -451,7 +451,6 @@ const is_debug = debug;
* @param {*} data
*/
const log = (data, type) => {
let msg_type = '';
switch (data.lt) {
case '1':
......@@ -477,7 +476,7 @@ const log = (data, type) => {
// #ifdef APP
// 在 app 中,日志转为 字符串
if(typeof data === 'object') {
if (typeof data === 'object') {
data = JSON.stringify(data);
}
// #endif
......@@ -509,6 +508,17 @@ const get_report_Interval = (defaultTime) => {
// 如果不是整数,则默认为上报间隔时间
if (!reg.test(time)) return defaultTime
return Number(time)
};
/**
* 获取隐私协议配置
*/
const is_push_clientid = () => {
if (uniStatisticsConfig.collectItems) {
const ClientID = uniStatisticsConfig.collectItems.uniPushClientID;
return typeof ClientID === 'boolean' ? ClientID : false
}
return false
};
const appid = process.env.UNI_APP_ID; // 做应用隔离
......@@ -1266,7 +1276,8 @@ class Stat extends Report {
* 获取推送id
*/
pushEvent(options) {
if (uni.getPushClientId) {
const ClientID = is_push_clientid();
if (uni.getPushClientId && ClientID) {
uni.getPushClientId({
success: (res) => {
const cid = res.cid || false;
......
......@@ -103,6 +103,36 @@ var GtPush = /*@__PURE__*/getDefaultExportFromCjs(gtpushMin);
function initPushNotification() {
// 仅 App 端
if (typeof plus !== 'undefined' && plus.push) {
plus.globalEvent.addEventListener('newPath', ({ path }) => {
if (!path) {
return;
}
// 指定的页面为当前页面
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
if (currentPage &&
currentPage.$page &&
currentPage.$page.fullPath === path) {
return;
}
// 简单起见,先尝试 navigateTo 跳转,失败后,再尝试 tabBar 跳转
uni.navigateTo({
url: path,
fail(res) {
if (res.errMsg.indexOf('tabbar') > -1) {
uni.switchTab({
url: path,
fail(res) {
console.error(res.errMsg);
},
});
}
else {
console.error(res.errMsg);
}
},
});
});
plus.push.addEventListener('click', (result) => {
// @ts-expect-error
uni.invokePushCallback({
......@@ -141,7 +171,9 @@ if (!appid) {
});
}
else {
// #ifdef APP
initPushNotification();
// #endif
GtPush.init({
appid,
onError: (res) => {
......
function initPushNotification() {
// 仅 App 端
if (typeof plus !== 'undefined' && plus.push) {
plus.globalEvent.addEventListener('newPath', ({ path }) => {
if (!path) {
return;
}
// 指定的页面为当前页面
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
if (currentPage &&
currentPage.$page &&
currentPage.$page.fullPath === path) {
return;
}
// 简单起见,先尝试 navigateTo 跳转,失败后,再尝试 tabBar 跳转
uni.navigateTo({
url: path,
fail(res) {
if (res.errMsg.indexOf('tabbar') > -1) {
uni.switchTab({
url: path,
fail(res) {
console.error(res.errMsg);
},
});
}
else {
console.error(res.errMsg);
}
},
});
});
plus.push.addEventListener('click', (result) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'click',
message: result,
});
});
uni.onPushMessage((res) => {
if (res.type === 'receive' &&
res.data &&
res.data.force_notification) {
// 创建通知栏
uni.createPushMessage(res.data);
res.stopped = true;
}
});
}
}
// @ts-expect-error
uni.invokePushCallback({
type: 'enabled',
offline: true,
});
Promise.resolve().then(() => {
initPushNotification();
plus.push.setAutoNotification && plus.push.setAutoNotification(false);
plus.push.addEventListener('click', (result) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'click',
message: result,
});
});
plus.push.addEventListener('receive', (result) => {
// @ts-expect-error
uni.invokePushCallback({
......
......@@ -9,6 +9,7 @@ import {
let cid
let cidErrMsg
let enabled
let offline
function normalizePushMessage (message) {
try {
......@@ -22,6 +23,9 @@ export function invokePushCallback (
) {
if (args.type === 'enabled') {
enabled = true
if (__PLATFORM__ === 'app') {
offline = args.offline
}
} else if (args.type === 'clientId') {
cid = args.cid
cidErrMsg = args.errMsg
......@@ -70,11 +74,34 @@ export function getPushClientId (args) {
const hasSuccess = isFn(success)
const hasFail = isFn(fail)
const hasComplete = isFn(complete)
// App 端且启用离线时,使用 getClientInfoAsync 来调用
if (__PLATFORM__ === 'app' && offline) {
plus.push.getClientInfoAsync(
(info) => {
const res = {
errMsg: 'getPushClientId:ok',
cid
}
hasSuccess && success(res)
hasComplete && complete(res)
},
(res) => {
res = {
errMsg: 'getPushClientId:fail ' + (res.code + ': ' + res.message)
}
hasFail && fail(res)
hasComplete && complete(res)
}
)
return
}
Promise.resolve().then(() => {
if (typeof enabled === 'undefined') {
enabled = false
cid = ''
cidErrMsg = 'unipush is not enabled'
cidErrMsg = 'uniPush is not enabled'
}
getPushCidCallbacks.push((cid, errMsg) => {
let res
......
......@@ -54,5 +54,18 @@ uni-cover-view .uni-cover-view {
width: 100%;
height: 100%;
visibility: hidden;
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>
<template>
<uni-tabbar
v-if="hasTabBar"
v-show="showTabBar"
<uni-tabbar
v-if="hasTabBar"
v-show="showTabBar"
>
<div
<div
:style="{'flex-direction':direction==='vertical'?'column':'row',backgroundColor:tabBarOptions.backgroundColor}"
class="uni-tabbar"
class="uni-tabbar"
>
<div
v-for="(item,index) in tabBarOptions.list"
:key="item.pagePath"
class="uni-tabbar__item"
@click="_switchTab(item,index)"
>
<div class="uni-tabbar__bd">
<div
v-if="showIcon && item.iconPath"
:class="{'uni-tabbar__icon__diff':!item.text}"
class="uni-tabbar__icon"
>
<img :src="_getRealPath(selectedIndex===index?item.selectedIconPath:item.iconPath)">
<div
v-if="item.redDot"
:class="{'uni-tabbar__badge':!!item.badge}"
class="uni-tabbar__reddot"
<template v-for="(item,index) in tabBarOptions.list">
<div
v-if="item.visible !== false"
:key="item.pagePath"
class="uni-tabbar__item"
@click="_switchTab(item,index)"
>
<div class="uni-tabbar__bd">
<div
v-if="showIcon && item.iconPath"
:class="{'uni-tabbar__icon__diff':!item.text}"
class="uni-tabbar__icon"
>
{{ item.badge }}
<img :src="_getRealPath(selectedIndex===index?item.selectedIconPath:item.iconPath)">
<div
v-if="item.redDot"
:class="{'uni-tabbar__badge':!!item.badge}"
class="uni-tabbar__reddot"
>
{{ item.badge }}
</div>
</div>
</div>
<div
v-if="item.text"
:style="{color:selectedIndex===index?tabBarOptions.selectedColor:tabBarOptions.color,fontSize:showIcon&&item.iconPath?'10px':'14px'}"
class="uni-tabbar__label"
>
{{ item.text }}
<div
v-if="item.redDot&&(!showIcon || !item.iconPath)"
:class="{'uni-tabbar__badge':!!item.badge}"
class="uni-tabbar__reddot"
<div
v-if="item.text"
:style="{color:selectedIndex===index?tabBarOptions.selectedColor:tabBarOptions.color,fontSize:showIcon&&item.iconPath?'10px':'14px'}"
class="uni-tabbar__label"
>
{{ item.badge }}
{{ item.text }}
<div
v-if="item.redDot&&(!showIcon || !item.iconPath)"
:class="{'uni-tabbar__badge':!!item.badge}"
class="uni-tabbar__reddot"
>
{{ item.badge }}
</div>
</div>
</div>
</div>
</div>
</template>
</div>
</uni-tabbar>
</template>
......@@ -140,4 +142,4 @@ export default {
</script>
<style>
</style>
</style>
import {
isPage,
initRelation,
handleLink
handleLink,
components
} from './util'
import {
......@@ -11,17 +12,26 @@ import {
import parseBaseComponent from '../../../mp-weixin/runtime/wrapper/component-base-parser'
const components = []
function currentComponents (mpInstance, callback) {
const webviewId = mpInstance.__webviewId__
const currentComponents = components[webviewId]
if (currentComponents) {
callback(currentComponents)
}
}
export default function parseComponent (vueOptions) {
const [componentOptions, VueComponent] = parseBaseComponent(vueOptions)
const lifetimes = componentOptions.lifetimes
// 基础库 2.0 以上 attached 顺序错乱,按照 created 顺序强制纠正
componentOptions.lifetimes.created = function created () {
components.push(this)
lifetimes.created = function created () {
currentComponents(this, components => {
components.push(this)
})
}
componentOptions.lifetimes.attached = function attached () {
lifetimes.attached = function attached () {
this.__lifetimes_attached = function () {
const properties = this.properties
......@@ -48,17 +58,28 @@ export default function parseComponent (vueOptions) {
// 触发首次 setData
this.$vm.$mount()
}
let component = this
while (component && component.__lifetimes_attached && components[0] && component === components[0]) {
components.shift()
component.__lifetimes_attached()
delete component.__lifetimes_attached
component = components[0]
}
currentComponents(this, components => {
let component = this
while (component && component.__lifetimes_attached && components[0] && component === components[0]) {
components.shift()
component.__lifetimes_attached()
delete component.__lifetimes_attached
component = components[0]
}
})
}
lifetimes.detached = function detached () {
currentComponents(this, components => {
const index = components.indexOf(this)
if (index >= 0) {
components.splice(index, 1)
}
})
}
// ready 比 handleLink 还早,初始化逻辑放到 handleLink 中
delete componentOptions.lifetimes.ready
delete lifetimes.ready
componentOptions.methods.__l = handleLink
......
import {
isPage,
isPage,
instances,
components,
initRelation
} from './util'
......@@ -11,8 +12,17 @@ export default function parsePage (vuePageOptions) {
isPage,
initRelation
})
const lifetimes = pageOptions.lifetimes
const oldCreated = lifetimes.created
lifetimes.created = function created () {
const webviewId = this.__webviewId__
components[webviewId] = []
if (typeof oldCreated === 'function') {
oldCreated.call(this)
}
}
// 页面需要在 ready 中触发,其他组件是在 handleLink 中触发
pageOptions.lifetimes.ready = function ready () {
lifetimes.ready = function ready () {
if (this.$vm && this.$vm.mpType === 'page') {
this.$vm.__call_hook('created')
this.$vm.__call_hook('beforeMount')
......@@ -22,18 +32,22 @@ export default function parsePage (vuePageOptions) {
} else {
this.is && console.warn(this.is + ' is not ready')
}
}
pageOptions.lifetimes.detached = function detached () {
this.$vm && this.$vm.$destroy()
// 清理
const webviewId = this.__webviewId__
webviewId && Object.keys(instances).forEach(key => {
if (key.indexOf(webviewId + '_') === 0) {
delete instances[key]
}
})
}
const oldDetached = lifetimes.detached
lifetimes.detached = function detached () {
if (typeof oldDetached === 'function') {
oldDetached.call(this)
}
this.$vm && this.$vm.$destroy()
// 清理
const webviewId = this.__webviewId__
webviewId && Object.keys(instances).forEach(key => {
if (key.indexOf(webviewId + '_') === 0) {
delete instances[key]
}
})
delete components[webviewId]
}
return pageOptions
}
}
......@@ -52,6 +52,7 @@ export function initRefs (vm) {
}
export const instances = Object.create(null)
export const components = Object.create(null)
export function initRelation ({
vuePid,
......@@ -101,4 +102,4 @@ export function handleLink ({
vm._isMounted = true
vm.__call_hook('mounted')
vm.__call_hook('onReady')
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册