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

Merge branch 'dev' into alpha

# Conflicts:
#	packages/uni-cli-shared/components/ad.mixin.js
#	packages/uni-stat/dist/uni-cloud-stat.cjs.js
#	packages/uni-stat/dist/uni-cloud-stat.es.js
#	packages/uni-stat/dist/uni-stat.cjs.js
#	packages/uni-stat/dist/uni-stat.es.js
#	packages/vue-cli-plugin-uni/lib/env.js
#	src/platforms/mp-weixin/helpers/system-info.js
...@@ -61,8 +61,8 @@ ...@@ -61,8 +61,8 @@
## 常见疑问 ## 常见疑问
- 问:不同端有不同的需求、不同的特色,登支付也不一样,如何统一? - 问:不同端有不同的需求、不同的特色,登支付也不一样,如何统一?
- 答:差异部分使用条件编译。uni-app提供了灵活强大的[条件编译](https://uniapp.dcloud.io/platform)。可以完美处理复用部分和差异部分。真正一套工程源码。当业务升级时,不再需要多端维护。如果多端维护,经常会因为某些端的流量不大,就一直拖延无法让那些用户享受到最新服务。另外登支付在客户端部分,已经被uni-app统一成一样的api了。 - 答:差异部分使用条件编译。uni-app提供了灵活强大的[条件编译](https://uniapp.dcloud.io/platform)。可以完美处理复用部分和差异部分。真正一套工程源码。当业务升级时,不再需要多端维护。如果多端维护,经常会因为某些端的流量不大,就一直拖延无法让那些用户享受到最新服务。另外登支付在客户端部分,已经被uni-app统一成一样的api了。
- 问:多端是不是一种妥协,是否会造成性能下降? - 问:多端是不是一种妥协,是否会造成性能下降?
......
...@@ -2,6 +2,15 @@ ...@@ -2,6 +2,15 @@
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"uni-shared": [
"./src/shared/index.js"
],
"uni-helpers/*": [
"./src/core/helpers/*"
],
"uni-mixins/*": [
"./src/core/view/mixins/*"
],
"uni-core/*": [ "uni-core/*": [
"./src/core/*" "./src/core/*"
], ],
......
...@@ -248,7 +248,9 @@ const third = [ ...@@ -248,7 +248,9 @@ const third = [
'unPreloadPage', 'unPreloadPage',
'loadSubPackage', 'loadSubPackage',
'sendHostEvent', 'sendHostEvent',
'navigateToMiniProgram' 'navigateToMiniProgram',
'getLaunchOptionsSync',
'getEnterOptionsSync'
] ]
const ad = [ const ad = [
......
...@@ -213,6 +213,7 @@ class AdHelper { ...@@ -213,6 +213,7 @@ class AdHelper {
const ad = this.get(options) const ad = this.get(options)
if (ad.isLoad) { if (ad.isLoad) {
this._lastWaterfallIndex = -1
ad.show((e) => { ad.show((e) => {
onclose && onclose(e) onclose && onclose(e)
}, () => { }, () => {
...@@ -220,6 +221,7 @@ class AdHelper { ...@@ -220,6 +221,7 @@ class AdHelper {
}) })
} else { } else {
ad.load(() => { ad.load(() => {
this._lastWaterfallIndex = -1
onload && onload() onload && onload()
ad.show((e) => { ad.show((e) => {
onclose && onclose(e) onclose && onclose(e)
...@@ -242,16 +244,14 @@ class AdHelper { ...@@ -242,16 +244,14 @@ class AdHelper {
return return
} }
if (index === 0) {
this._lastWaterfallIndex = -1
}
const options2 = { const options2 = {
adpid: adpid[index], adpid: adpid[index],
urlCallback, urlCallback,
retry: false retry: false
} }
console.log('ad.loadWaterfall::index=' + index)
this.load(options2, (res) => { this.load(options2, (res) => {
this._lastWaterfallIndex = index this._lastWaterfallIndex = index
onload(options2) onload(options2)
...@@ -260,7 +260,6 @@ class AdHelper { ...@@ -260,7 +260,6 @@ class AdHelper {
if (index >= adpid.length) { if (index >= adpid.length) {
onfail(err) onfail(err)
} else { } else {
console.log('loadWaterfall::index=' + index)
this.loadWaterfall(options, onload, onfail, index) this.loadWaterfall(options, onload, onfail, index)
} }
}) })
...@@ -276,17 +275,18 @@ class AdHelper { ...@@ -276,17 +275,18 @@ class AdHelper {
return return
} }
let idx = index
if (this._lastWaterfallIndex > -1) { if (this._lastWaterfallIndex > -1) {
idx = this._lastWaterfallIndex index = this._lastWaterfallIndex
} }
const options2 = { const options2 = {
adpid: adpid[idx], adpid: adpid[index],
urlCallback, urlCallback,
retry: false retry: false
} }
console.log('ad.showWaterfall::index=' + index)
this.show(options2, () => { this.show(options2, () => {
onload() onload()
}, (err) => { }, (err) => {
...@@ -444,6 +444,9 @@ export default { ...@@ -444,6 +444,9 @@ export default {
}, },
methods: { methods: {
load () { load () {
if (this.isLoading) {
return
}
this._startLoading() this._startLoading()
const invoke = this._isWaterfall() ? 'loadWaterfall' : 'load' const invoke = this._isWaterfall() ? 'loadWaterfall' : 'load'
this._adHelper[invoke](this._getAdOptions(), () => { this._adHelper[invoke](this._getAdOptions(), () => {
...@@ -454,6 +457,9 @@ export default { ...@@ -454,6 +457,9 @@ export default {
}, },
show () { show () {
if (this.isLoading) {
return
}
this._startLoading() this._startLoading()
const invoke = this._isWaterfall() ? 'showWaterfall' : 'show' const invoke = this._isWaterfall() ? 'showWaterfall' : 'show'
this._adHelper[invoke](this._getAdOptions(), () => { this._adHelper[invoke](this._getAdOptions(), () => {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
const sys = uni.getSystemInfoSync(); const sys = uni.getSystemInfoSync();
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序; // 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
const STAT_VERSION = '0.0.1'; const STAT_VERSION = process.env.UNI_COMPILER_VERSION;
const STAT_URL = 'https://tongji.dcloud.io/uni/stat'; const STAT_URL = 'https://tongji.dcloud.io/uni/stat';
const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif'; const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s
...@@ -202,21 +202,10 @@ const get_scene = (options) => { ...@@ -202,21 +202,10 @@ const get_scene = (options) => {
return scene return scene
}; };
/**
* 获取拼接参数
*/
const get_splicing = (data) => {
let str = '';
for (var i in data) {
str += i + '=' + data[i] + '&';
}
return str.substr(0, str.length - 1)
};
/** /**
* 获取页面url,不包含参数 * 获取页面url,不包含参数
*/ */
const get_route = (pageVm) => { const get_route$1 = (pageVm) => {
let _self = pageVm || get_page_vm(); let _self = pageVm || get_page_vm();
if (get_platform_name() === 'bd') { if (get_platform_name() === 'bd') {
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is; let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
...@@ -290,7 +279,10 @@ const handle_data = (statData) => { ...@@ -290,7 +279,10 @@ const handle_data = (statData) => {
for (let i in statData) { for (let i in statData) {
const rd = statData[i]; const rd = statData[i];
rd.forEach((elm) => { rd.forEach((elm) => {
const newData = get_splicing(elm); let newData = '';
{
newData = elm;
}
if (i === 0) { if (i === 0) {
firstArr.push(newData); firstArr.push(newData);
} else if (i === 3) { } else if (i === 3) {
...@@ -506,18 +498,21 @@ const log = (data) => { ...@@ -506,18 +498,21 @@ const log = (data) => {
} }
}; };
let data = uni.getStorageSync('$$STAT__DBDATA') || {}; const appid = process.env.UNI_APP_ID; // 做应用隔离
const dbSet = (name, value) => { const dbSet = (name, value) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data) { if (!data) {
data = {}; data = {};
} }
data[name] = value; data[name] = value;
uni.setStorageSync('$$STAT__DBDATA', data); uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
}; };
const dbGet = (name) => { const dbGet = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data[name]) { if (!data[name]) {
let dbdata = uni.getStorageSync('$$STAT__DBDATA'); let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (!dbdata) { if (!dbdata) {
dbdata = {}; dbdata = {};
} }
...@@ -530,14 +525,15 @@ const dbGet = (name) => { ...@@ -530,14 +525,15 @@ const dbGet = (name) => {
}; };
const dbRemove = (name) => { const dbRemove = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (data[name]) { if (data[name]) {
delete data[name]; delete data[name];
uni.setStorageSync('$$STAT__DBDATA', data); uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
} else { } else {
data = uni.getStorageSync('$$STAT__DBDATA'); data = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (data[name]) { if (data[name]) {
delete data[name]; delete data[name];
uni.setStorageSync('$$STAT__DBDATA', data); uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
} }
} }
}; };
...@@ -621,35 +617,35 @@ const get_total_visit_count = () => { ...@@ -621,35 +617,35 @@ const get_total_visit_count = () => {
return count return count
}; };
let Set__First__Time = 0;
let Set__Last__Time = 0;
const FIRST_TIME = '__first_time';
/** /**
* 获取第一次时间 * 设置页面首次访问时间,用户获取页面/应用停留时常
*/ */
const get_first_time = () => { const set_first_time = () => {
let time = new Date().getTime(); const time = new Date().getTime();
Set__First__Time = time; const timeStorge = dbSet(FIRST_TIME,time);
Set__Last__Time = 0; return timeStorge
return time
}; };
/** /**
* 获取最后一次时间 * 获取最后一次时间 ,暂时用不到,直接获取当前时间即可
*/ */
const get_last_time = () => { // export const get_last_time = () => {
let time = new Date().getTime(); // let time = new Date().getTime()
Set__Last__Time = time; // Set__Last__Time = time
return time // return time
}; // }
/** /**
* 获取页面 \ 应用停留时间 * 获取页面 \ 应用停留时间
*/ */
const get_residence_time = (type) => { const get_residence_time = (type) => {
let residenceTime = 0; let residenceTime = 0;
if (Set__First__Time !== 0) { const first_time = dbGet(FIRST_TIME);
residenceTime = Set__Last__Time - Set__First__Time; const last_time = get_time();
if (first_time !== 0) {
residenceTime = last_time - first_time;
} }
residenceTime = parseInt(residenceTime / 1000); residenceTime = parseInt(residenceTime / 1000);
...@@ -811,7 +807,6 @@ class Report { ...@@ -811,7 +807,6 @@ class Report {
applicationShow() { applicationShow() {
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据 // 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if (this.__licationHide) { if (this.__licationHide) {
get_last_time();
const time = get_residence_time('app'); const time = get_residence_time('app');
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报 // 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if (time.overtime) { if (time.overtime) {
...@@ -839,7 +834,6 @@ class Report { ...@@ -839,7 +834,6 @@ class Report {
} }
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据 // 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this.__licationHide = true; this.__licationHide = true;
get_last_time();
const time = get_residence_time(); const time = get_residence_time();
const route = get_page_route(self); const route = get_page_route(self);
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route); uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
...@@ -850,8 +844,8 @@ class Report { ...@@ -850,8 +844,8 @@ class Report {
}, },
type type
); );
// 重置时间 // 更新页面首次访问时间
get_first_time(); set_first_time();
} }
/** /**
...@@ -867,20 +861,19 @@ class Report { ...@@ -867,20 +861,19 @@ class Report {
}; };
const route = get_page_route(self); const route = get_page_route(self);
const routepath = get_route(self); const routepath = get_route$1(self);
this._navigationBarTitle.config = get_page_name(routepath); this._navigationBarTitle.config = get_page_name(routepath);
// 表示应用触发 ,页面切换不触发之后的逻辑 // 表示应用触发 ,页面切换不触发之后的逻辑
if (this.__licationShow) { if (this.__licationShow) {
get_first_time(); // 更新页面首次访问时间
set_first_time();
// this._lastPageRoute = route // this._lastPageRoute = route
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route); uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
this.__licationShow = false; this.__licationShow = false;
return return
} }
get_last_time();
const time = get_residence_time('page'); const time = get_residence_time('page');
// 停留时间 // 停留时间
if (time.overtime) { if (time.overtime) {
...@@ -890,8 +883,8 @@ class Report { ...@@ -890,8 +883,8 @@ class Report {
}; };
this.sendReportRequest(options); this.sendReportRequest(options);
} }
// 重置时间 // 更新页面首次访问时间
get_first_time(); set_first_time();
} }
/** /**
...@@ -899,7 +892,6 @@ class Report { ...@@ -899,7 +892,6 @@ class Report {
*/ */
pageHide(self) { pageHide(self) {
if (!this.__licationHide) { if (!this.__licationHide) {
get_last_time();
const time = get_residence_time('page'); const time = get_residence_time('page');
let route = get_page_route(self); let route = get_page_route(self);
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE'); let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
...@@ -992,8 +984,16 @@ class Report { ...@@ -992,8 +984,16 @@ class Report {
* 自定义事件上报 * 自定义事件上报
*/ */
sendEventRequest({ key = '', value = '' } = {}) { sendEventRequest({ key = '', value = '' } = {}) {
// const route = this._lastPageRoute
const routepath = get_route(); let routepath = '';
try {
routepath = get_route$1();
} catch (error) {
const launch_options = dbGet('__launch_options');
routepath = launch_options.path;
}
this._navigationBarTitle.config = get_page_name(routepath); this._navigationBarTitle.config = get_page_name(routepath);
this._navigationBarTitle.lt = '21'; this._navigationBarTitle.lt = '21';
let options = { let options = {
...@@ -1227,6 +1227,7 @@ class Stat extends Report { ...@@ -1227,6 +1227,7 @@ class Stat extends Report {
// 初始化页面停留时间 start // 初始化页面停留时间 start
set_page_residence_time(); set_page_residence_time();
this.__licationShow = true; this.__licationShow = true;
dbSet('__launch_options', options);
this.sendReportRequest(options, true); this.sendReportRequest(options, true);
} }
load(options, self) { load(options, self) {
...@@ -1249,7 +1250,7 @@ class Stat extends Report { ...@@ -1249,7 +1250,7 @@ class Stat extends Report {
} }
// #ifdef VUE3 // #ifdef VUE3
if (get_platform_name() !== 'h5' && get_platform_name() !== 'n') { if (get_platform_name() === 'h5' || get_platform_name() === 'n') {
if (get_page_types(self) === 'app') { if (get_page_types(self) === 'app') {
this.appShow(); this.appShow();
} }
...@@ -1270,7 +1271,7 @@ class Stat extends Report { ...@@ -1270,7 +1271,7 @@ class Stat extends Report {
} }
// #ifdef VUE3 // #ifdef VUE3
if (get_platform_name() !== 'h5' && get_platform_name() !== 'n') { if (get_platform_name() === 'h5' || get_platform_name() === 'n') {
if (get_page_types(self) === 'app') { if (get_page_types(self) === 'app') {
this.appHide(); this.appHide();
} }
...@@ -1286,23 +1287,33 @@ class Stat extends Report { ...@@ -1286,23 +1287,33 @@ class Stat extends Report {
error(em) { error(em) {
// 开发工具内不上报错误 // 开发工具内不上报错误
if (this._platform === 'devtools') { // if (this._platform === 'devtools') {
if (process.env.NODE_ENV === 'development') { // if (process.env.NODE_ENV === 'development') {
console.info('当前运行环境为开发者工具,不上报数据。'); // console.info('当前运行环境为开发者工具,不上报数据。')
return // return
} // }
} // }
let emVal = ''; let emVal = '';
if (!em.message) { if (!em.message) {
emVal = JSON.stringify(em); emVal = JSON.stringify(em);
} else { } else {
emVal = em.stack; emVal = em.stack;
} }
let route = '';
try {
route = get_route();
}catch(e){
// 未获取到页面路径
route = '';
}
let options = { let options = {
ak: this.statData.ak, ak: this.statData.ak,
uuid: this.statData.uuid, uuid: this.statData.uuid,
p: this.statData.p, p: this.statData.p,
lt: '31', lt: '31',
url:route,
ut: this.statData.ut, ut: this.statData.ut,
ch: this.statData.ch, ch: this.statData.ch,
mpsdk: this.statData.mpsdk, mpsdk: this.statData.mpsdk,
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
const sys = uni.getSystemInfoSync(); const sys = uni.getSystemInfoSync();
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序; // 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
const STAT_VERSION = '0.0.1'; const STAT_VERSION = process.env.UNI_COMPILER_VERSION;
const STAT_URL = 'https://tongji.dcloud.io/uni/stat'; const STAT_URL = 'https://tongji.dcloud.io/uni/stat';
const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif'; const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s
...@@ -200,21 +200,10 @@ const get_scene = (options) => { ...@@ -200,21 +200,10 @@ const get_scene = (options) => {
return scene return scene
}; };
/**
* 获取拼接参数
*/
const get_splicing = (data) => {
let str = '';
for (var i in data) {
str += i + '=' + data[i] + '&';
}
return str.substr(0, str.length - 1)
};
/** /**
* 获取页面url,不包含参数 * 获取页面url,不包含参数
*/ */
const get_route = (pageVm) => { const get_route$1 = (pageVm) => {
let _self = pageVm || get_page_vm(); let _self = pageVm || get_page_vm();
if (get_platform_name() === 'bd') { if (get_platform_name() === 'bd') {
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is; let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
...@@ -288,7 +277,10 @@ const handle_data = (statData) => { ...@@ -288,7 +277,10 @@ const handle_data = (statData) => {
for (let i in statData) { for (let i in statData) {
const rd = statData[i]; const rd = statData[i];
rd.forEach((elm) => { rd.forEach((elm) => {
const newData = get_splicing(elm); let newData = '';
{
newData = elm;
}
if (i === 0) { if (i === 0) {
firstArr.push(newData); firstArr.push(newData);
} else if (i === 3) { } else if (i === 3) {
...@@ -504,18 +496,21 @@ const log = (data) => { ...@@ -504,18 +496,21 @@ const log = (data) => {
} }
}; };
let data = uni.getStorageSync('$$STAT__DBDATA') || {}; const appid = process.env.UNI_APP_ID; // 做应用隔离
const dbSet = (name, value) => { const dbSet = (name, value) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data) { if (!data) {
data = {}; data = {};
} }
data[name] = value; data[name] = value;
uni.setStorageSync('$$STAT__DBDATA', data); uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
}; };
const dbGet = (name) => { const dbGet = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data[name]) { if (!data[name]) {
let dbdata = uni.getStorageSync('$$STAT__DBDATA'); let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (!dbdata) { if (!dbdata) {
dbdata = {}; dbdata = {};
} }
...@@ -528,14 +523,15 @@ const dbGet = (name) => { ...@@ -528,14 +523,15 @@ const dbGet = (name) => {
}; };
const dbRemove = (name) => { const dbRemove = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (data[name]) { if (data[name]) {
delete data[name]; delete data[name];
uni.setStorageSync('$$STAT__DBDATA', data); uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
} else { } else {
data = uni.getStorageSync('$$STAT__DBDATA'); data = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (data[name]) { if (data[name]) {
delete data[name]; delete data[name];
uni.setStorageSync('$$STAT__DBDATA', data); uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
} }
} }
}; };
...@@ -619,35 +615,35 @@ const get_total_visit_count = () => { ...@@ -619,35 +615,35 @@ const get_total_visit_count = () => {
return count return count
}; };
let Set__First__Time = 0;
let Set__Last__Time = 0;
const FIRST_TIME = '__first_time';
/** /**
* 获取第一次时间 * 设置页面首次访问时间,用户获取页面/应用停留时常
*/ */
const get_first_time = () => { const set_first_time = () => {
let time = new Date().getTime(); const time = new Date().getTime();
Set__First__Time = time; const timeStorge = dbSet(FIRST_TIME,time);
Set__Last__Time = 0; return timeStorge
return time
}; };
/** /**
* 获取最后一次时间 * 获取最后一次时间 ,暂时用不到,直接获取当前时间即可
*/ */
const get_last_time = () => { // export const get_last_time = () => {
let time = new Date().getTime(); // let time = new Date().getTime()
Set__Last__Time = time; // Set__Last__Time = time
return time // return time
}; // }
/** /**
* 获取页面 \ 应用停留时间 * 获取页面 \ 应用停留时间
*/ */
const get_residence_time = (type) => { const get_residence_time = (type) => {
let residenceTime = 0; let residenceTime = 0;
if (Set__First__Time !== 0) { const first_time = dbGet(FIRST_TIME);
residenceTime = Set__Last__Time - Set__First__Time; const last_time = get_time();
if (first_time !== 0) {
residenceTime = last_time - first_time;
} }
residenceTime = parseInt(residenceTime / 1000); residenceTime = parseInt(residenceTime / 1000);
...@@ -809,7 +805,6 @@ class Report { ...@@ -809,7 +805,6 @@ class Report {
applicationShow() { applicationShow() {
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据 // 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if (this.__licationHide) { if (this.__licationHide) {
get_last_time();
const time = get_residence_time('app'); const time = get_residence_time('app');
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报 // 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if (time.overtime) { if (time.overtime) {
...@@ -837,7 +832,6 @@ class Report { ...@@ -837,7 +832,6 @@ class Report {
} }
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据 // 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this.__licationHide = true; this.__licationHide = true;
get_last_time();
const time = get_residence_time(); const time = get_residence_time();
const route = get_page_route(self); const route = get_page_route(self);
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route); uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
...@@ -848,8 +842,8 @@ class Report { ...@@ -848,8 +842,8 @@ class Report {
}, },
type type
); );
// 重置时间 // 更新页面首次访问时间
get_first_time(); set_first_time();
} }
/** /**
...@@ -865,20 +859,19 @@ class Report { ...@@ -865,20 +859,19 @@ class Report {
}; };
const route = get_page_route(self); const route = get_page_route(self);
const routepath = get_route(self); const routepath = get_route$1(self);
this._navigationBarTitle.config = get_page_name(routepath); this._navigationBarTitle.config = get_page_name(routepath);
// 表示应用触发 ,页面切换不触发之后的逻辑 // 表示应用触发 ,页面切换不触发之后的逻辑
if (this.__licationShow) { if (this.__licationShow) {
get_first_time(); // 更新页面首次访问时间
set_first_time();
// this._lastPageRoute = route // this._lastPageRoute = route
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route); uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
this.__licationShow = false; this.__licationShow = false;
return return
} }
get_last_time();
const time = get_residence_time('page'); const time = get_residence_time('page');
// 停留时间 // 停留时间
if (time.overtime) { if (time.overtime) {
...@@ -888,8 +881,8 @@ class Report { ...@@ -888,8 +881,8 @@ class Report {
}; };
this.sendReportRequest(options); this.sendReportRequest(options);
} }
// 重置时间 // 更新页面首次访问时间
get_first_time(); set_first_time();
} }
/** /**
...@@ -897,7 +890,6 @@ class Report { ...@@ -897,7 +890,6 @@ class Report {
*/ */
pageHide(self) { pageHide(self) {
if (!this.__licationHide) { if (!this.__licationHide) {
get_last_time();
const time = get_residence_time('page'); const time = get_residence_time('page');
let route = get_page_route(self); let route = get_page_route(self);
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE'); let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
...@@ -990,8 +982,16 @@ class Report { ...@@ -990,8 +982,16 @@ class Report {
* 自定义事件上报 * 自定义事件上报
*/ */
sendEventRequest({ key = '', value = '' } = {}) { sendEventRequest({ key = '', value = '' } = {}) {
// const route = this._lastPageRoute
const routepath = get_route(); let routepath = '';
try {
routepath = get_route$1();
} catch (error) {
const launch_options = dbGet('__launch_options');
routepath = launch_options.path;
}
this._navigationBarTitle.config = get_page_name(routepath); this._navigationBarTitle.config = get_page_name(routepath);
this._navigationBarTitle.lt = '21'; this._navigationBarTitle.lt = '21';
let options = { let options = {
...@@ -1225,6 +1225,7 @@ class Stat extends Report { ...@@ -1225,6 +1225,7 @@ class Stat extends Report {
// 初始化页面停留时间 start // 初始化页面停留时间 start
set_page_residence_time(); set_page_residence_time();
this.__licationShow = true; this.__licationShow = true;
dbSet('__launch_options', options);
this.sendReportRequest(options, true); this.sendReportRequest(options, true);
} }
load(options, self) { load(options, self) {
...@@ -1247,7 +1248,7 @@ class Stat extends Report { ...@@ -1247,7 +1248,7 @@ class Stat extends Report {
} }
// #ifdef VUE3 // #ifdef VUE3
if (get_platform_name() !== 'h5' && get_platform_name() !== 'n') { if (get_platform_name() === 'h5' || get_platform_name() === 'n') {
if (get_page_types(self) === 'app') { if (get_page_types(self) === 'app') {
this.appShow(); this.appShow();
} }
...@@ -1268,7 +1269,7 @@ class Stat extends Report { ...@@ -1268,7 +1269,7 @@ class Stat extends Report {
} }
// #ifdef VUE3 // #ifdef VUE3
if (get_platform_name() !== 'h5' && get_platform_name() !== 'n') { if (get_platform_name() === 'h5' || get_platform_name() === 'n') {
if (get_page_types(self) === 'app') { if (get_page_types(self) === 'app') {
this.appHide(); this.appHide();
} }
...@@ -1284,23 +1285,33 @@ class Stat extends Report { ...@@ -1284,23 +1285,33 @@ class Stat extends Report {
error(em) { error(em) {
// 开发工具内不上报错误 // 开发工具内不上报错误
if (this._platform === 'devtools') { // if (this._platform === 'devtools') {
if (process.env.NODE_ENV === 'development') { // if (process.env.NODE_ENV === 'development') {
console.info('当前运行环境为开发者工具,不上报数据。'); // console.info('当前运行环境为开发者工具,不上报数据。')
return // return
} // }
} // }
let emVal = ''; let emVal = '';
if (!em.message) { if (!em.message) {
emVal = JSON.stringify(em); emVal = JSON.stringify(em);
} else { } else {
emVal = em.stack; emVal = em.stack;
} }
let route = '';
try {
route = get_route();
}catch(e){
// 未获取到页面路径
route = '';
}
let options = { let options = {
ak: this.statData.ak, ak: this.statData.ak,
uuid: this.statData.uuid, uuid: this.statData.uuid,
p: this.statData.p, p: this.statData.p,
lt: '31', lt: '31',
url:route,
ut: this.statData.ut, ut: this.statData.ut,
ch: this.statData.ch, ch: this.statData.ch,
mpsdk: this.statData.mpsdk, mpsdk: this.statData.mpsdk,
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
const sys = uni.getSystemInfoSync(); const sys = uni.getSystemInfoSync();
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序; // 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
const STAT_VERSION = '0.0.1'; const STAT_VERSION = process.env.UNI_COMPILER_VERSION;
const STAT_URL = 'https://tongji.dcloud.io/uni/stat'; const STAT_URL = 'https://tongji.dcloud.io/uni/stat';
const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif'; const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s
...@@ -216,7 +216,7 @@ const get_splicing = (data) => { ...@@ -216,7 +216,7 @@ const get_splicing = (data) => {
/** /**
* 获取页面url,不包含参数 * 获取页面url,不包含参数
*/ */
const get_route = (pageVm) => { const get_route$1 = (pageVm) => {
let _self = pageVm || get_page_vm(); let _self = pageVm || get_page_vm();
if (get_platform_name() === 'bd') { if (get_platform_name() === 'bd') {
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is; let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
...@@ -290,7 +290,10 @@ const handle_data = (statData) => { ...@@ -290,7 +290,10 @@ const handle_data = (statData) => {
for (let i in statData) { for (let i in statData) {
const rd = statData[i]; const rd = statData[i];
rd.forEach((elm) => { rd.forEach((elm) => {
const newData = get_splicing(elm); let newData = '';
{
newData = get_splicing(elm);
}
if (i === 0) { if (i === 0) {
firstArr.push(newData); firstArr.push(newData);
} else if (i === 3) { } else if (i === 3) {
...@@ -474,18 +477,21 @@ const log = (data) => { ...@@ -474,18 +477,21 @@ const log = (data) => {
} }
}; };
let data = uni.getStorageSync('$$STAT__DBDATA') || {}; const appid = process.env.UNI_APP_ID; // 做应用隔离
const dbSet = (name, value) => { const dbSet = (name, value) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data) { if (!data) {
data = {}; data = {};
} }
data[name] = value; data[name] = value;
uni.setStorageSync('$$STAT__DBDATA', data); uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
}; };
const dbGet = (name) => { const dbGet = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data[name]) { if (!data[name]) {
let dbdata = uni.getStorageSync('$$STAT__DBDATA'); let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (!dbdata) { if (!dbdata) {
dbdata = {}; dbdata = {};
} }
...@@ -498,14 +504,15 @@ const dbGet = (name) => { ...@@ -498,14 +504,15 @@ const dbGet = (name) => {
}; };
const dbRemove = (name) => { const dbRemove = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (data[name]) { if (data[name]) {
delete data[name]; delete data[name];
uni.setStorageSync('$$STAT__DBDATA', data); uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
} else { } else {
data = uni.getStorageSync('$$STAT__DBDATA'); data = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (data[name]) { if (data[name]) {
delete data[name]; delete data[name];
uni.setStorageSync('$$STAT__DBDATA', data); uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
} }
} }
}; };
...@@ -589,35 +596,35 @@ const get_total_visit_count = () => { ...@@ -589,35 +596,35 @@ const get_total_visit_count = () => {
return count return count
}; };
let Set__First__Time = 0;
let Set__Last__Time = 0;
const FIRST_TIME = '__first_time';
/** /**
* 获取第一次时间 * 设置页面首次访问时间,用户获取页面/应用停留时常
*/ */
const get_first_time = () => { const set_first_time = () => {
let time = new Date().getTime(); const time = new Date().getTime();
Set__First__Time = time; const timeStorge = dbSet(FIRST_TIME,time);
Set__Last__Time = 0; return timeStorge
return time
}; };
/** /**
* 获取最后一次时间 * 获取最后一次时间 ,暂时用不到,直接获取当前时间即可
*/ */
const get_last_time = () => { // export const get_last_time = () => {
let time = new Date().getTime(); // let time = new Date().getTime()
Set__Last__Time = time; // Set__Last__Time = time
return time // return time
}; // }
/** /**
* 获取页面 \ 应用停留时间 * 获取页面 \ 应用停留时间
*/ */
const get_residence_time = (type) => { const get_residence_time = (type) => {
let residenceTime = 0; let residenceTime = 0;
if (Set__First__Time !== 0) { const first_time = dbGet(FIRST_TIME);
residenceTime = Set__Last__Time - Set__First__Time; const last_time = get_time();
if (first_time !== 0) {
residenceTime = last_time - first_time;
} }
residenceTime = parseInt(residenceTime / 1000); residenceTime = parseInt(residenceTime / 1000);
...@@ -779,7 +786,6 @@ class Report { ...@@ -779,7 +786,6 @@ class Report {
applicationShow() { applicationShow() {
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据 // 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if (this.__licationHide) { if (this.__licationHide) {
get_last_time();
const time = get_residence_time('app'); const time = get_residence_time('app');
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报 // 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if (time.overtime) { if (time.overtime) {
...@@ -807,7 +813,6 @@ class Report { ...@@ -807,7 +813,6 @@ class Report {
} }
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据 // 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this.__licationHide = true; this.__licationHide = true;
get_last_time();
const time = get_residence_time(); const time = get_residence_time();
const route = get_page_route(self); const route = get_page_route(self);
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route); uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
...@@ -818,8 +823,8 @@ class Report { ...@@ -818,8 +823,8 @@ class Report {
}, },
type type
); );
// 重置时间 // 更新页面首次访问时间
get_first_time(); set_first_time();
} }
/** /**
...@@ -835,20 +840,19 @@ class Report { ...@@ -835,20 +840,19 @@ class Report {
}; };
const route = get_page_route(self); const route = get_page_route(self);
const routepath = get_route(self); const routepath = get_route$1(self);
this._navigationBarTitle.config = get_page_name(routepath); this._navigationBarTitle.config = get_page_name(routepath);
// 表示应用触发 ,页面切换不触发之后的逻辑 // 表示应用触发 ,页面切换不触发之后的逻辑
if (this.__licationShow) { if (this.__licationShow) {
get_first_time(); // 更新页面首次访问时间
set_first_time();
// this._lastPageRoute = route // this._lastPageRoute = route
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route); uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
this.__licationShow = false; this.__licationShow = false;
return return
} }
get_last_time();
const time = get_residence_time('page'); const time = get_residence_time('page');
// 停留时间 // 停留时间
if (time.overtime) { if (time.overtime) {
...@@ -858,8 +862,8 @@ class Report { ...@@ -858,8 +862,8 @@ class Report {
}; };
this.sendReportRequest(options); this.sendReportRequest(options);
} }
// 重置时间 // 更新页面首次访问时间
get_first_time(); set_first_time();
} }
/** /**
...@@ -867,7 +871,6 @@ class Report { ...@@ -867,7 +871,6 @@ class Report {
*/ */
pageHide(self) { pageHide(self) {
if (!this.__licationHide) { if (!this.__licationHide) {
get_last_time();
const time = get_residence_time('page'); const time = get_residence_time('page');
let route = get_page_route(self); let route = get_page_route(self);
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE'); let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
...@@ -960,8 +963,16 @@ class Report { ...@@ -960,8 +963,16 @@ class Report {
* 自定义事件上报 * 自定义事件上报
*/ */
sendEventRequest({ key = '', value = '' } = {}) { sendEventRequest({ key = '', value = '' } = {}) {
// const route = this._lastPageRoute
const routepath = get_route(); let routepath = '';
try {
routepath = get_route$1();
} catch (error) {
const launch_options = dbGet('__launch_options');
routepath = launch_options.path;
}
this._navigationBarTitle.config = get_page_name(routepath); this._navigationBarTitle.config = get_page_name(routepath);
this._navigationBarTitle.lt = '21'; this._navigationBarTitle.lt = '21';
let options = { let options = {
...@@ -1183,6 +1194,7 @@ class Stat extends Report { ...@@ -1183,6 +1194,7 @@ class Stat extends Report {
// 初始化页面停留时间 start // 初始化页面停留时间 start
set_page_residence_time(); set_page_residence_time();
this.__licationShow = true; this.__licationShow = true;
dbSet('__launch_options', options);
this.sendReportRequest(options, true); this.sendReportRequest(options, true);
} }
load(options, self) { load(options, self) {
...@@ -1205,7 +1217,7 @@ class Stat extends Report { ...@@ -1205,7 +1217,7 @@ class Stat extends Report {
} }
// #ifdef VUE3 // #ifdef VUE3
if (get_platform_name() !== 'h5' && get_platform_name() !== 'n') { if (get_platform_name() === 'h5' || get_platform_name() === 'n') {
if (get_page_types(self) === 'app') { if (get_page_types(self) === 'app') {
this.appShow(); this.appShow();
} }
...@@ -1226,7 +1238,7 @@ class Stat extends Report { ...@@ -1226,7 +1238,7 @@ class Stat extends Report {
} }
// #ifdef VUE3 // #ifdef VUE3
if (get_platform_name() !== 'h5' && get_platform_name() !== 'n') { if (get_platform_name() === 'h5' || get_platform_name() === 'n') {
if (get_page_types(self) === 'app') { if (get_page_types(self) === 'app') {
this.appHide(); this.appHide();
} }
...@@ -1242,23 +1254,33 @@ class Stat extends Report { ...@@ -1242,23 +1254,33 @@ class Stat extends Report {
error(em) { error(em) {
// 开发工具内不上报错误 // 开发工具内不上报错误
if (this._platform === 'devtools') { // if (this._platform === 'devtools') {
if (process.env.NODE_ENV === 'development') { // if (process.env.NODE_ENV === 'development') {
console.info('当前运行环境为开发者工具,不上报数据。'); // console.info('当前运行环境为开发者工具,不上报数据。')
return // return
} // }
} // }
let emVal = ''; let emVal = '';
if (!em.message) { if (!em.message) {
emVal = JSON.stringify(em); emVal = JSON.stringify(em);
} else { } else {
emVal = em.stack; emVal = em.stack;
} }
let route = '';
try {
route = get_route();
}catch(e){
// 未获取到页面路径
route = '';
}
let options = { let options = {
ak: this.statData.ak, ak: this.statData.ak,
uuid: this.statData.uuid, uuid: this.statData.uuid,
p: this.statData.p, p: this.statData.p,
lt: '31', lt: '31',
url:route,
ut: this.statData.ut, ut: this.statData.ut,
ch: this.statData.ch, ch: this.statData.ch,
mpsdk: this.statData.mpsdk, mpsdk: this.statData.mpsdk,
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
const sys = uni.getSystemInfoSync(); const sys = uni.getSystemInfoSync();
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序; // 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
const STAT_VERSION = '0.0.1'; const STAT_VERSION = process.env.UNI_COMPILER_VERSION;
const STAT_URL = 'https://tongji.dcloud.io/uni/stat'; const STAT_URL = 'https://tongji.dcloud.io/uni/stat';
const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif'; const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s
...@@ -214,7 +214,7 @@ const get_splicing = (data) => { ...@@ -214,7 +214,7 @@ const get_splicing = (data) => {
/** /**
* 获取页面url,不包含参数 * 获取页面url,不包含参数
*/ */
const get_route = (pageVm) => { const get_route$1 = (pageVm) => {
let _self = pageVm || get_page_vm(); let _self = pageVm || get_page_vm();
if (get_platform_name() === 'bd') { if (get_platform_name() === 'bd') {
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is; let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
...@@ -288,7 +288,10 @@ const handle_data = (statData) => { ...@@ -288,7 +288,10 @@ const handle_data = (statData) => {
for (let i in statData) { for (let i in statData) {
const rd = statData[i]; const rd = statData[i];
rd.forEach((elm) => { rd.forEach((elm) => {
const newData = get_splicing(elm); let newData = '';
{
newData = get_splicing(elm);
}
if (i === 0) { if (i === 0) {
firstArr.push(newData); firstArr.push(newData);
} else if (i === 3) { } else if (i === 3) {
...@@ -472,18 +475,21 @@ const log = (data) => { ...@@ -472,18 +475,21 @@ const log = (data) => {
} }
}; };
let data = uni.getStorageSync('$$STAT__DBDATA') || {}; const appid = process.env.UNI_APP_ID; // 做应用隔离
const dbSet = (name, value) => { const dbSet = (name, value) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data) { if (!data) {
data = {}; data = {};
} }
data[name] = value; data[name] = value;
uni.setStorageSync('$$STAT__DBDATA', data); uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
}; };
const dbGet = (name) => { const dbGet = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data[name]) { if (!data[name]) {
let dbdata = uni.getStorageSync('$$STAT__DBDATA'); let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (!dbdata) { if (!dbdata) {
dbdata = {}; dbdata = {};
} }
...@@ -496,14 +502,15 @@ const dbGet = (name) => { ...@@ -496,14 +502,15 @@ const dbGet = (name) => {
}; };
const dbRemove = (name) => { const dbRemove = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (data[name]) { if (data[name]) {
delete data[name]; delete data[name];
uni.setStorageSync('$$STAT__DBDATA', data); uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
} else { } else {
data = uni.getStorageSync('$$STAT__DBDATA'); data = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (data[name]) { if (data[name]) {
delete data[name]; delete data[name];
uni.setStorageSync('$$STAT__DBDATA', data); uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
} }
} }
}; };
...@@ -587,35 +594,35 @@ const get_total_visit_count = () => { ...@@ -587,35 +594,35 @@ const get_total_visit_count = () => {
return count return count
}; };
let Set__First__Time = 0;
let Set__Last__Time = 0;
const FIRST_TIME = '__first_time';
/** /**
* 获取第一次时间 * 设置页面首次访问时间,用户获取页面/应用停留时常
*/ */
const get_first_time = () => { const set_first_time = () => {
let time = new Date().getTime(); const time = new Date().getTime();
Set__First__Time = time; const timeStorge = dbSet(FIRST_TIME,time);
Set__Last__Time = 0; return timeStorge
return time
}; };
/** /**
* 获取最后一次时间 * 获取最后一次时间 ,暂时用不到,直接获取当前时间即可
*/ */
const get_last_time = () => { // export const get_last_time = () => {
let time = new Date().getTime(); // let time = new Date().getTime()
Set__Last__Time = time; // Set__Last__Time = time
return time // return time
}; // }
/** /**
* 获取页面 \ 应用停留时间 * 获取页面 \ 应用停留时间
*/ */
const get_residence_time = (type) => { const get_residence_time = (type) => {
let residenceTime = 0; let residenceTime = 0;
if (Set__First__Time !== 0) { const first_time = dbGet(FIRST_TIME);
residenceTime = Set__Last__Time - Set__First__Time; const last_time = get_time();
if (first_time !== 0) {
residenceTime = last_time - first_time;
} }
residenceTime = parseInt(residenceTime / 1000); residenceTime = parseInt(residenceTime / 1000);
...@@ -777,7 +784,6 @@ class Report { ...@@ -777,7 +784,6 @@ class Report {
applicationShow() { applicationShow() {
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据 // 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if (this.__licationHide) { if (this.__licationHide) {
get_last_time();
const time = get_residence_time('app'); const time = get_residence_time('app');
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报 // 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if (time.overtime) { if (time.overtime) {
...@@ -805,7 +811,6 @@ class Report { ...@@ -805,7 +811,6 @@ class Report {
} }
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据 // 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this.__licationHide = true; this.__licationHide = true;
get_last_time();
const time = get_residence_time(); const time = get_residence_time();
const route = get_page_route(self); const route = get_page_route(self);
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route); uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
...@@ -816,8 +821,8 @@ class Report { ...@@ -816,8 +821,8 @@ class Report {
}, },
type type
); );
// 重置时间 // 更新页面首次访问时间
get_first_time(); set_first_time();
} }
/** /**
...@@ -833,20 +838,19 @@ class Report { ...@@ -833,20 +838,19 @@ class Report {
}; };
const route = get_page_route(self); const route = get_page_route(self);
const routepath = get_route(self); const routepath = get_route$1(self);
this._navigationBarTitle.config = get_page_name(routepath); this._navigationBarTitle.config = get_page_name(routepath);
// 表示应用触发 ,页面切换不触发之后的逻辑 // 表示应用触发 ,页面切换不触发之后的逻辑
if (this.__licationShow) { if (this.__licationShow) {
get_first_time(); // 更新页面首次访问时间
set_first_time();
// this._lastPageRoute = route // this._lastPageRoute = route
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route); uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
this.__licationShow = false; this.__licationShow = false;
return return
} }
get_last_time();
const time = get_residence_time('page'); const time = get_residence_time('page');
// 停留时间 // 停留时间
if (time.overtime) { if (time.overtime) {
...@@ -856,8 +860,8 @@ class Report { ...@@ -856,8 +860,8 @@ class Report {
}; };
this.sendReportRequest(options); this.sendReportRequest(options);
} }
// 重置时间 // 更新页面首次访问时间
get_first_time(); set_first_time();
} }
/** /**
...@@ -865,7 +869,6 @@ class Report { ...@@ -865,7 +869,6 @@ class Report {
*/ */
pageHide(self) { pageHide(self) {
if (!this.__licationHide) { if (!this.__licationHide) {
get_last_time();
const time = get_residence_time('page'); const time = get_residence_time('page');
let route = get_page_route(self); let route = get_page_route(self);
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE'); let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
...@@ -958,8 +961,16 @@ class Report { ...@@ -958,8 +961,16 @@ class Report {
* 自定义事件上报 * 自定义事件上报
*/ */
sendEventRequest({ key = '', value = '' } = {}) { sendEventRequest({ key = '', value = '' } = {}) {
// const route = this._lastPageRoute
const routepath = get_route(); let routepath = '';
try {
routepath = get_route$1();
} catch (error) {
const launch_options = dbGet('__launch_options');
routepath = launch_options.path;
}
this._navigationBarTitle.config = get_page_name(routepath); this._navigationBarTitle.config = get_page_name(routepath);
this._navigationBarTitle.lt = '21'; this._navigationBarTitle.lt = '21';
let options = { let options = {
...@@ -1181,6 +1192,7 @@ class Stat extends Report { ...@@ -1181,6 +1192,7 @@ class Stat extends Report {
// 初始化页面停留时间 start // 初始化页面停留时间 start
set_page_residence_time(); set_page_residence_time();
this.__licationShow = true; this.__licationShow = true;
dbSet('__launch_options', options);
this.sendReportRequest(options, true); this.sendReportRequest(options, true);
} }
load(options, self) { load(options, self) {
...@@ -1203,7 +1215,7 @@ class Stat extends Report { ...@@ -1203,7 +1215,7 @@ class Stat extends Report {
} }
// #ifdef VUE3 // #ifdef VUE3
if (get_platform_name() !== 'h5' && get_platform_name() !== 'n') { if (get_platform_name() === 'h5' || get_platform_name() === 'n') {
if (get_page_types(self) === 'app') { if (get_page_types(self) === 'app') {
this.appShow(); this.appShow();
} }
...@@ -1224,7 +1236,7 @@ class Stat extends Report { ...@@ -1224,7 +1236,7 @@ class Stat extends Report {
} }
// #ifdef VUE3 // #ifdef VUE3
if (get_platform_name() !== 'h5' && get_platform_name() !== 'n') { if (get_platform_name() === 'h5' || get_platform_name() === 'n') {
if (get_page_types(self) === 'app') { if (get_page_types(self) === 'app') {
this.appHide(); this.appHide();
} }
...@@ -1240,23 +1252,33 @@ class Stat extends Report { ...@@ -1240,23 +1252,33 @@ class Stat extends Report {
error(em) { error(em) {
// 开发工具内不上报错误 // 开发工具内不上报错误
if (this._platform === 'devtools') { // if (this._platform === 'devtools') {
if (process.env.NODE_ENV === 'development') { // if (process.env.NODE_ENV === 'development') {
console.info('当前运行环境为开发者工具,不上报数据。'); // console.info('当前运行环境为开发者工具,不上报数据。')
return // return
} // }
} // }
let emVal = ''; let emVal = '';
if (!em.message) { if (!em.message) {
emVal = JSON.stringify(em); emVal = JSON.stringify(em);
} else { } else {
emVal = em.stack; emVal = em.stack;
} }
let route = '';
try {
route = get_route();
}catch(e){
// 未获取到页面路径
route = '';
}
let options = { let options = {
ak: this.statData.ak, ak: this.statData.ak,
uuid: this.statData.uuid, uuid: this.statData.uuid,
p: this.statData.p, p: this.statData.p,
lt: '31', lt: '31',
url:route,
ut: this.statData.ut, ut: this.statData.ut,
ch: this.statData.ch, ch: this.statData.ch,
mpsdk: this.statData.mpsdk, mpsdk: this.statData.mpsdk,
......
...@@ -44,7 +44,7 @@ describe('codegen', () => { ...@@ -44,7 +44,7 @@ describe('codegen', () => {
it('generate text with multiple statements', () => { it('generate text with multiple statements', () => {
assertCodegen( assertCodegen(
`<view>{{obj.param1}}123123{{obj.param1}}123123{{obj.param1}}<text> -{{obj.param3}}---{{obj.param3}} </text>{{obj.param2}}aaaa{{obj.param2}}aaaa{{obj.param2}}</view>`, `<view>{{obj.param1}}123123{{obj.param1}}123123{{obj.param1}}<text> -{{obj.param3}}---{{obj.param3}} </text>{{obj.param2}}aaaa{{obj.param2}}aaaa{{obj.param2}}</view>`,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+"123123"+(_$g(0,'t0-1'))+"123123"+(_$g(0,'t0-2'))),_c('v-uni-text',{attrs:{"_i":1}},[_v("-"+(_$g(1,'t0-0'))+"---"+(_$g(1,'t0-1')))]),_v((_$g(0,'t2-0'))+"aaaa"+(_$g(0,'t2-1'))+"aaaa"+(_$g(0,'t2-2')))],1)}` `with(this){return _c('uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+"123123"+(_$g(0,'t0-1'))+"123123"+(_$g(0,'t0-2'))),_c('v-uni-text',{attrs:{"_i":1}},[_v("-"+(_$g(1,'t0-0'))+"---"+(_$g(1,'t0-1')))]),_v((_$g(0,'t2-0'))+"aaaa"+(_$g(0,'t2-1'))+"aaaa"+(_$g(0,'t2-2')))],1)}`
) )
}) })
it('generate v-slot', () => { it('generate v-slot', () => {
...@@ -91,7 +91,7 @@ describe('codegen', () => { ...@@ -91,7 +91,7 @@ describe('codegen', () => {
it('generate dataset', () => { it('generate dataset', () => {
assertCodegen( assertCodegen(
'<view data-a="1" :data-b="b"></view>', '<view data-a="1" :data-b="b"></view>',
`with(this){return _c('v-uni-view',{attrs:{"data-a":"1","data-b":_$g(0,'a-data-b'),"_i":0}})}` `with(this){return _c('uni-view',{attrs:{"data-a":"1","data-b":_$g(0,'a-data-b'),"_i":0}})}`
) )
assertCodegen( assertCodegen(
'<custom data-a="1" :data-b="b"></custom>', '<custom data-a="1" :data-b="b"></custom>',
...@@ -141,12 +141,12 @@ describe('codegen', () => { ...@@ -141,12 +141,12 @@ describe('codegen', () => {
it('generate text trim', () => { it('generate text trim', () => {
assertCodegen( assertCodegen(
'<view>text</view>', '<view>text</view>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("text")])}` `with(this){return _c('uni-view',{attrs:{"_i":0}},[_v("text")])}`
) )
assertCodegen( assertCodegen(
'<view> text </view>', '<view> text </view>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("text")])}` `with(this){return _c('uni-view',{attrs:{"_i":0}},[_v("text")])}`
) )
assertCodegen( assertCodegen(
...@@ -179,31 +179,31 @@ describe('codegen', () => { ...@@ -179,31 +179,31 @@ describe('codegen', () => {
assertCodegen( assertCodegen(
'<view> text text </view>', '<view> text text </view>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("text text")])}` `with(this){return _c('uni-view',{attrs:{"_i":0}},[_v("text text")])}`
) )
assertCodegen( assertCodegen(
'<view>text {{text}} text</view>', '<view>text {{text}} text</view>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("text "+(_$g(0,'t0-0'))+" text")])}` `with(this){return _c('uni-view',{attrs:{"_i":0}},[_v("text "+(_$g(0,'t0-0'))+" text")])}`
) )
assertCodegen( assertCodegen(
'<view> text {{text}} 文本 </view>', '<view> text {{text}} 文本 </view>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("text "+(_$g(0,'t0-0'))+" 文本")])}` `with(this){return _c('uni-view',{attrs:{"_i":0}},[_v("text "+(_$g(0,'t0-0'))+" 文本")])}`
) )
assertCodegen( assertCodegen(
'<view>{{text}} text text </view>', '<view>{{text}} text text </view>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text")])}` `with(this){return _c('uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text")])}`
) )
assertCodegen( assertCodegen(
'<view> {{text}} text text </view>', '<view> {{text}} text text </view>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text")])}` `with(this){return _c('uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text")])}`
) )
assertCodegen( assertCodegen(
'<view>{{text}} text text {{text}}</view>', '<view>{{text}} text text {{text}}</view>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text "+(_$g(0,'t0-1')))])}` `with(this){return _c('uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text "+(_$g(0,'t0-1')))])}`
) )
assertCodegen( assertCodegen(
'<view> {{text}} text text {{text}} </view>', '<view> {{text}} text text {{text}} </view>',
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text "+(_$g(0,'t0-1')))])}` `with(this){return _c('uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text "+(_$g(0,'t0-1')))])}`
) )
}) })
it('generate bool attr', () => { it('generate bool attr', () => {
......
...@@ -4,8 +4,17 @@ const { ...@@ -4,8 +4,17 @@ const {
const tags = require('@dcloudio/uni-cli-shared/lib/tags') const tags = require('@dcloudio/uni-cli-shared/lib/tags')
// web components
const elements = ['uni-view']
// 仅限 view 层 // 仅限 view 层
module.exports = function parseTag (el) { module.exports = function parseTag (el) {
const tag = el.tag
const element = elements.find(element => tag === element || 'uni-' + tag === element)
if (element) {
el.tag = element
return
}
if (el.tag.indexOf('v-uni-') !== 0 && hasOwn(tags, el.tag)) { if (el.tag.indexOf('v-uni-') !== 0 && hasOwn(tags, el.tag)) {
el.tag = 'v-uni-' + el.tag el.tag = 'v-uni-' + el.tag
} }
......
...@@ -210,7 +210,7 @@ function isComponent (tagName) { ...@@ -210,7 +210,7 @@ function isComponent (tagName) {
return false return false
} }
} }
return !hasOwn(tags, getTagName(tagName.replace('v-uni-', ''))) return !hasOwn(tags, getTagName(tagName.replace(/^(v-)?uni-/, '')))
} }
function makeMap (str, expectsLowerCase) { function makeMap (str, expectsLowerCase) {
......
...@@ -99,12 +99,16 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) { ...@@ -99,12 +99,16 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
'process.env.UNI_APP_ID': JSON.stringify(process.env.UNI_APP_ID), 'process.env.UNI_APP_ID': JSON.stringify(process.env.UNI_APP_ID),
'process.env.UNI_APP_NAME': JSON.stringify(process.env.UNI_APP_NAME), 'process.env.UNI_APP_NAME': JSON.stringify(process.env.UNI_APP_NAME),
'process.env.UNI_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM), 'process.env.UNI_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM),
'process.env.UNI_SUB_PLATFORM': JSON.stringify(process.env.UNI_SUB_PLATFORM),
'process.env.UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER, 'process.env.UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER,
'process.env.UNICLOUD_DEBUG': process.env.UNICLOUD_DEBUG, 'process.env.UNICLOUD_DEBUG': process.env.UNICLOUD_DEBUG,
'process.env.RUN_BY_HBUILDERX': process.env.RUN_BY_HBUILDERX, 'process.env.RUN_BY_HBUILDERX': process.env.RUN_BY_HBUILDERX,
'process.env.UNI_AUTOMATOR_WS_ENDPOINT': JSON.stringify(process.env.UNI_AUTOMATOR_WS_ENDPOINT), 'process.env.UNI_AUTOMATOR_WS_ENDPOINT': JSON.stringify(process.env.UNI_AUTOMATOR_WS_ENDPOINT),
'process.env.UNI_STAT_UNI_CLOUD': process.env.UNI_STAT_UNI_CLOUD || '', 'process.env.UNI_STAT_UNI_CLOUD': process.env.UNI_STAT_UNI_CLOUD || '',
'process.env.UNI_STAT_DEBUG': process.env.UNI_STAT_DEBUG || '' 'process.env.UNI_STAT_DEBUG': process.env.UNI_STAT_DEBUG || '',
'process.env.UNI_COMPILER_VERSION': JSON.stringify(process.env.UNI_COMPILER_VERSION),
'process.env.UNI_APP_VERSION_NAME': JSON.stringify(process.env.UNI_APP_VERSION_NAME),
'process.env.UNI_APP_VERSION_CODE': JSON.stringify(process.env.UNI_APP_VERSION_CODE)
} }
if (process.env.UNI_USING_VUE3) { if (process.env.UNI_USING_VUE3) {
Object.assign(defines, { Object.assign(defines, {
......
...@@ -31,6 +31,8 @@ const manifestJsonObj = getManifestJson() ...@@ -31,6 +31,8 @@ const manifestJsonObj = getManifestJson()
process.env.UNI_APP_ID = manifestJsonObj.appid || '' process.env.UNI_APP_ID = manifestJsonObj.appid || ''
process.env.UNI_APP_NAME = manifestJsonObj.name || '' process.env.UNI_APP_NAME = manifestJsonObj.name || ''
process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5' process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5'
process.env.UNI_APP_VERSION_NAME = manifestJsonObj.versionName
process.env.UNI_APP_VERSION_CODE = manifestJsonObj.versionCode
// 小程序 vue3 标记 // 小程序 vue3 标记
if (process.env.UNI_PLATFORM.indexOf('mp-') === 0) { if (process.env.UNI_PLATFORM.indexOf('mp-') === 0) {
...@@ -341,11 +343,11 @@ if ( ...@@ -341,11 +343,11 @@ if (
console.log() console.log()
} else { } else {
if (!uniStatistics.version) { if (!uniStatistics.version) {
// console.log() console.log()
// console.warn(uniI18n.__('pluginUni.uniStatisticsNoVersion', { console.warn(uniI18n.__('pluginUni.uniStatisticsNoVersion', {
// 0: 'https://uniapp.dcloud.io/uni-stat-v2.html' 0: 'https://uniapp.dcloud.io/uni-stat-v2.html'
// })) }))
// console.log() console.log()
} else { } else {
console.log() console.log()
console.warn(`已开启 uni统计${uniStatistics.version}.0 版本`) console.warn(`已开启 uni统计${uniStatistics.version}.0 版本`)
...@@ -354,11 +356,11 @@ if ( ...@@ -354,11 +356,11 @@ if (
} }
} else { } else {
if (!uniStatistics.version) { if (!uniStatistics.version) {
// console.log() console.log()
// console.warn(uniI18n.__('pluginUni.uniStatisticsNoVersion', { console.warn(uniI18n.__('pluginUni.uniStatisticsNoVersion', {
// 0: 'https://uniapp.dcloud.io/uni-stat-v2.html' 0: 'https://uniapp.dcloud.io/uni-stat-v2.html'
// })) }))
// console.log() console.log()
} else { } else {
console.log() console.log()
console.warn(`已开启 uni统计${uniStatistics.version}.0 版本`) console.warn(`已开启 uni统计${uniStatistics.version}.0 版本`)
...@@ -388,6 +390,11 @@ const warningMsg = ...@@ -388,6 +390,11 @@ const warningMsg =
const needWarning = !platformOptions.usingComponents || usingComponentsAbsent const needWarning = !platformOptions.usingComponents || usingComponentsAbsent
let hasNVue = false let hasNVue = false
// 输出编译器版本等信息 // 输出编译器版本等信息
const pagesPkg = require('@dcloudio/webpack-uni-pages-loader/package.json')
process.env.UNI_COMPILER_VERSION = ''
if (pagesPkg) {
process.env.UNI_COMPILER_VERSION = pagesPkg['uni-app'].compilerVersion
}
const compileModeUrl = 'https://ask.dcloud.net.cn/article/36074' const compileModeUrl = 'https://ask.dcloud.net.cn/article/36074'
if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
const compileMode = (process.env.UNI_USING_V3_NATIVE ? '(v3)' : '') + '' + (isNVueCompiler ? 'uni-app' : 'weex') const compileMode = (process.env.UNI_USING_V3_NATIVE ? '(v3)' : '') + '' + (isNVueCompiler ? 'uni-app' : 'weex')
...@@ -397,12 +404,8 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { ...@@ -397,12 +404,8 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
})) }))
} else if (process.env.UNI_PLATFORM !== 'h5' && process.env.UNI_PLATFORM !== 'quickapp-native') { } else if (process.env.UNI_PLATFORM !== 'h5' && process.env.UNI_PLATFORM !== 'quickapp-native') {
try { try {
let info = '' let info = process.env.UNI_COMPILER_VERSION
if (process.env.UNI_PLATFORM === 'app-plus') { if (process.env.UNI_PLATFORM === 'app-plus') {
const pagesPkg = require('@dcloudio/webpack-uni-pages-loader/package.json')
if (pagesPkg) {
info = uniI18n.__('compilerVersion') + '' + pagesPkg['uni-app'].compilerVersion
}
if (process.env.UNI_USING_V3) { if (process.env.UNI_USING_V3) {
console.log(info) console.log(info)
} else { } else {
......
...@@ -443,6 +443,11 @@ global['____${h5.appid}____'] = true; ...@@ -443,6 +443,11 @@ global['____${h5.appid}____'] = true;
delete global['____${h5.appid}____']; delete global['____${h5.appid}____'];
global.__uniConfig = ${JSON.stringify(pagesJson)}; global.__uniConfig = ${JSON.stringify(pagesJson)};
global.__uniConfig.compilerVersion = '${compilerVersion}'; global.__uniConfig.compilerVersion = '${compilerVersion}';
global.__uniConfig.uniPlatform = '${process.env.UNI_PLATFORM}';
global.__uniConfig.appId = '${process.env.UNI_APP_ID}';
global.__uniConfig.appName = '${process.env.UNI_APP_NAME}';
global.__uniConfig.appVersion = '${process.env.UNI_APP_VERSION_NAME}';
global.__uniConfig.appVersionCode = '${process.env.UNI_APP_VERSION_CODE}';
global.__uniConfig.router = ${JSON.stringify(h5.router)}; global.__uniConfig.router = ${JSON.stringify(h5.router)};
global.__uniConfig.publicPath = ${JSON.stringify(h5.publicPath)}; global.__uniConfig.publicPath = ${JSON.stringify(h5.publicPath)};
global.__uniConfig['async'] = ${JSON.stringify(h5.async)}; global.__uniConfig['async'] = ${JSON.stringify(h5.async)};
......
/**
* customElements.define
*/
(function () {
const defineProperty = Object.defineProperty
const createElement = document.createElement
const classes = new Map()
const registry = new Map()
if ('customElements' in window && customElements && customElements.define) {
return
}
function HTMLBuiltIn () {
const constructor = this.constructor
if (!classes.has(constructor)) {
throw new TypeError('Illegal constructor')
}
const is = classes.get(constructor)
const element = createElement.call(document, is)
return Object.setPrototypeOf(element, constructor.prototype)
}
defineProperty(HTMLBuiltIn.prototype = HTMLElement.prototype, 'constructor', {
value: HTMLBuiltIn
})
defineProperty(window, 'HTMLElement', {
configurable: true,
value: HTMLBuiltIn
})
defineProperty(document, 'createElement', {
configurable: true,
value: function value (name, options) {
const is = options && options.is
const Class = is ? registry.get(is) : registry.get(name)
return Class ? new Class() : createElement.call(document, name)
}
})
defineProperty(window, 'customElements', {
configurable: true,
value: {
define: function define (is, Class) {
if (registry.has(is)) {
throw new Error('the name "'.concat(is, '" has already been used with this registry'))
}
classes.set(Class, is)
registry.set(is, Class)
}
}
})
})()
...@@ -39,6 +39,7 @@ const ratioArgs = { ...@@ -39,6 +39,7 @@ const ratioArgs = {
translate: 'all', translate: 'all',
createRadialGradient: 'all', createRadialGradient: 'all',
createLinearGradient: 'all', createLinearGradient: 'all',
transform: [4, 5],
setTransform: [4, 5] setTransform: [4, 5]
} }
......
...@@ -63,7 +63,7 @@ export function getTargetDataset (target) { ...@@ -63,7 +63,7 @@ export function getTargetDataset (target) {
$parent = $parent.$parent $parent = $parent.$parent
} }
} else { } else {
dataset = target.dataset || {} dataset = Object.assign({}, target.dataset, target.__uniDataset)
} }
return normalizeDataset(dataset) return normalizeDataset(dataset)
} }
......
...@@ -4,11 +4,6 @@ ...@@ -4,11 +4,6 @@
ref="content" ref="content"
:style="style" :style="style"
/> />
<img
v-if="contentPath"
:src="contentPath"
:draggable="draggable"
>
<v-uni-resize-sensor <v-uni-resize-sensor
v-if="mode === 'widthFix' || mode === 'heightFix'" v-if="mode === 'widthFix' || mode === 'heightFix'"
ref="sensor" ref="sensor"
...@@ -128,6 +123,12 @@ export default { ...@@ -128,6 +123,12 @@ export default {
if (newValue === 'widthFix' || newValue === 'heightFix') { if (newValue === 'widthFix' || newValue === 'heightFix') {
this._fixSize() this._fixSize()
} }
},
contentPath (val) {
if (!val && this.__img) {
this.__img.remove()
delete this.__img
}
} }
}, },
mounted () { mounted () {
...@@ -177,6 +178,12 @@ export default { ...@@ -177,6 +178,12 @@ export default {
this._fixSize() this._fixSize()
this.contentPath = realImagePath this.contentPath = realImagePath
img.draggable = this.draggable
if (this.__img) {
this.__img.remove()
}
this.__img = img
this.$el.appendChild(img)
this.$trigger('load', $event, { this.$trigger('load', $event, {
width: img.width, width: img.width,
...@@ -224,12 +231,12 @@ uni-image[hidden] { ...@@ -224,12 +231,12 @@ uni-image[hidden] {
display: none; display: none;
} }
uni-image > div { uni-image>div {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
uni-image > img { uni-image>img {
-webkit-touch-callout: none; -webkit-touch-callout: none;
-webkit-user-select: none; -webkit-user-select: none;
-moz-user-select: none; -moz-user-select: none;
...@@ -242,7 +249,7 @@ uni-image > img { ...@@ -242,7 +249,7 @@ uni-image > img {
opacity: 0; opacity: 0;
} }
uni-image > .uni-image-will-change { uni-image>.uni-image-will-change {
will-change: transform; will-change: transform;
} }
</style> </style>
...@@ -9,6 +9,19 @@ const requireComponents = [ ...@@ -9,6 +9,19 @@ const requireComponents = [
require.context('../../../platforms/' + __PLATFORM__ + '/view/components', true, /index\.vue$/) require.context('../../../platforms/' + __PLATFORM__ + '/view/components', true, /index\.vue$/)
] ]
let elements = {}
if (__PLATFORM__ === 'app-plus') {
// TODO use full polyfill
require('uni-core/helpers/custom-elements-define')
const module = require('../../../platforms/app-plus/view/elements/index.js')
elements = module.default || module
for (const key in elements) {
// TODO use kebabCase
customElements.define(`uni-${key.toLowerCase()}`, elements[key])
}
}
requireComponents.forEach((components, index) => { requireComponents.forEach((components, index) => {
components.keys().forEach(fileName => { components.keys().forEach(fileName => {
// 获取组件配置 // 获取组件配置
...@@ -18,7 +31,9 @@ requireComponents.forEach((components, index) => { ...@@ -18,7 +31,9 @@ requireComponents.forEach((components, index) => {
componentConfig.mixins = componentConfig.mixins ? [].concat(baseMixin, componentConfig.mixins) : [baseMixin] componentConfig.mixins = componentConfig.mixins ? [].concat(baseMixin, componentConfig.mixins) : [baseMixin]
if (!componentConfig.functional) {
componentConfig.mixins.push(animation) componentConfig.mixins.push(animation)
}
componentConfig.name = 'VUni' + componentConfig.name componentConfig.name = 'VUni' + componentConfig.name
......
...@@ -120,6 +120,7 @@ export default function parseNodes (nodes, parentNode, scopeId, triggerItemClick ...@@ -120,6 +120,7 @@ export default function parseNodes (nodes, parentNode, scopeId, triggerItemClick
return return
} }
const attrs = node.attrs const attrs = node.attrs
scopeId && elem.setAttribute(scopeId, '')
if (isPlainObject(attrs)) { if (isPlainObject(attrs)) {
const tagAttrs = TAGS[tagName] || [] const tagAttrs = TAGS[tagName] || []
Object.keys(attrs).forEach(function (name) { Object.keys(attrs).forEach(function (name) {
...@@ -130,7 +131,6 @@ export default function parseNodes (nodes, parentNode, scopeId, triggerItemClick ...@@ -130,7 +131,6 @@ export default function parseNodes (nodes, parentNode, scopeId, triggerItemClick
Array.isArray(value) && (value = value.join(' ')) Array.isArray(value) && (value = value.join(' '))
case 'style': case 'style':
elem.setAttribute(name, value) elem.setAttribute(name, value)
scopeId && elem.setAttribute(scopeId, '')
break break
default: default:
if (tagAttrs.indexOf(name) !== -1) { if (tagAttrs.indexOf(name) !== -1) {
......
...@@ -72,6 +72,7 @@ import { ...@@ -72,6 +72,7 @@ import {
field field
} from 'uni-mixins' } from 'uni-mixins'
const DARK_TEST_STRING = '(prefers-color-scheme: dark)' const DARK_TEST_STRING = '(prefers-color-scheme: dark)'
const ConfirmTypes = ['done', 'go', 'next', 'search', 'send'] // 'return'
export default { export default {
name: 'Textarea', name: 'Textarea',
mixins: [field], mixins: [field],
...@@ -106,7 +107,10 @@ export default { ...@@ -106,7 +107,10 @@ export default {
}, },
confirmType: { confirmType: {
type: String, type: String,
default: '' default: 'return',
validator (val) {
return ConfirmTypes.concat('return').includes(val)
}
} }
}, },
data () { data () {
...@@ -127,7 +131,7 @@ export default { ...@@ -127,7 +131,7 @@ export default {
return (this.composing ? this.valueComposition : this.valueSync).split('\n') return (this.composing ? this.valueComposition : this.valueSync).split('\n')
}, },
isDone () { isDone () {
return ['done', 'go', 'next', 'search', 'send'].includes(this.confirmType) return ConfirmTypes.includes(this.confirmType)
} }
}, },
watch: { watch: {
...@@ -208,7 +212,6 @@ export default { ...@@ -208,7 +212,6 @@ export default {
!this.ignoreCompositionEvent && !this.ignoreCompositionEvent &&
this.$trigger($event.type, $event, { data: $event.data }) this.$trigger($event.type, $event, { data: $event.data })
}, },
// 暂无完成按钮,此功能未实现
_confirm ($event) { _confirm ($event) {
this.$trigger('confirm', $event, { this.$trigger('confirm', $event, {
value: this.valueSync value: this.valueSync
......
...@@ -51,7 +51,7 @@ function getStyle (action) { ...@@ -51,7 +51,7 @@ function getStyle (action) {
return style return style
} }
function startAnimation (context) { export function startAnimation (context) {
const animation = context.animation const animation = context.animation
if (!animation || !animation.actions || !animation.actions.length) { if (!animation || !animation.actions || !animation.actions.length) {
return return
......
...@@ -18,9 +18,12 @@ export function getSystemInfoSync () { ...@@ -18,9 +18,12 @@ export function getSystemInfoSync () {
} }
export function getSystemInfo () { export function getSystemInfo () {
const platform = plus.os.name.toLowerCase() const { getSystemInfoSync } = weex.requireModule('plus')
const ios = platform === 'ios' const info = getSystemInfoSync()
const isAndroid = platform === 'android' const { deviceBrand, deviceModel, osName, osVersion, osLanguage } = info
const brand = deviceBrand.toLowerCase()
const _osName = osName.toLowerCase()
const ios = _osName === 'ios'
const { const {
screenWidth, screenWidth,
screenHeight screenHeight
...@@ -76,21 +79,21 @@ export function getSystemInfo () { ...@@ -76,21 +79,21 @@ export function getSystemInfo () {
height: windowHeightReal - safeAreaInsets.top - safeAreaInsets.bottom height: windowHeightReal - safeAreaInsets.top - safeAreaInsets.bottom
} }
return { return Object.assign({
errMsg: 'getSystemInfo:ok', errMsg: 'getSystemInfo:ok',
brand: plus.device.vendor, brand: brand,
model: plus.device.model, model: deviceModel,
pixelRatio: plus.screen.scale, pixelRatio: plus.screen.scale,
screenWidth, screenWidth,
screenHeight, screenHeight,
windowWidth, windowWidth,
windowHeight, windowHeight,
statusBarHeight, statusBarHeight,
language: plus.os.language, language: osLanguage,
system: `${ios ? 'iOS' : isAndroid ? 'Android' : ''} ${plus.os.version}`, system: `${osName} ${osVersion}`,
version: plus.runtime.innerVersion, version: plus.runtime.innerVersion,
fontSizeSetting: '', fontSizeSetting: '',
platform, platform: _osName,
SDKVersion: '', SDKVersion: '',
windowTop, windowTop,
windowBottom, windowBottom,
...@@ -102,5 +105,8 @@ export function getSystemInfo () { ...@@ -102,5 +105,8 @@ export function getSystemInfo () {
left: safeAreaInsets.left left: safeAreaInsets.left
}, },
deviceId: deviceId() deviceId: deviceId()
} }, info, {
deviceBrand: brand,
osName: _osName
})
} }
...@@ -56,6 +56,7 @@ export * from './plugin/on-native-event-receive' ...@@ -56,6 +56,7 @@ export * from './plugin/on-native-event-receive'
export * from './plugin/send-native-event' export * from './plugin/send-native-event'
export * from './plugin/load-sub-package' export * from './plugin/load-sub-package'
export * from './plugin/sdk' export * from './plugin/sdk'
export * from './plugin/get-launch-options-sync'
export * from './route/navigate-back' export * from './route/navigate-back'
export * from './route/navigate-to' export * from './route/navigate-to'
......
import {
getEnterOptions,
getLaunchOptions
} from '../../framework/utils'
export function getLaunchOptionsSync () {
return getLaunchOptions()
}
export function getEnterOptionsSync () {
return getEnterOptions()
}
...@@ -46,7 +46,9 @@ export function initLaunchOptions ({ ...@@ -46,7 +46,9 @@ export function initLaunchOptions ({
extend(launchOptions, { extend(launchOptions, {
path, path,
query: query ? parseQuery(query) : {}, query: query ? parseQuery(query) : {},
referrerInfo: referrerInfo || {} referrerInfo: referrerInfo || {},
channel: plus.runtime.channel,
launcher: plus.runtime.launcher
}) })
extend(enterOptions, launchOptions) extend(enterOptions, launchOptions)
return launchOptions return launchOptions
......
<script>
export default {
name: 'View',
functional: true,
render (createElement, context) {
return createElement('uni-view', context.data, context.children)
}
}
</script>
<style>
uni-view {
display: block;
}
uni-view[hidden] {
display: none;
}
</style>
import UniElement from './element'
import { startAnimation } from 'uni-core/view/mixins/animation'
export default class UniAnimationElement extends UniElement {
setAttribute (key, value) {
if (key === 'animation') {
startAnimation({
$el: this,
animation: value
})
}
super.setAttribute(key, value)
}
}
import {
camelize
} from 'uni-shared'
function formatKey (key) {
return camelize(key.substring(5))
}
export default class UniElement extends HTMLElement {
setAttribute (key, value) {
if (key.startsWith('data-')) {
const dataset = this.__uniDataset || (this.__uniDataset = {})
dataset[formatKey(key)] = value
}
super.setAttribute(key, value)
}
removeAttribute (key) {
if (this.__uniDataset && key.startsWith('data-')) {
delete this.__uniDataset[formatKey(key)]
}
super.removeAttribute(key)
}
}
import UniAnimationElement from './animation'
export default class UniHoverElement extends UniAnimationElement {
setAttribute (key, value) {
console.log('setAttribute:', key, value)
if (key === 'hover-class') {
this._updateHoverClass(value)
}
super.setAttribute(key, value)
}
removeAttribute (key) {
if (key === 'hover-class') {
this._updateHoverClass()
}
super.removeAttribute(key)
}
get hovering () {
return this._hovering
}
set hovering (hovering) {
this._hovering = hovering
const hoverClass = this.getAttribute('hover-class')
if (hovering) {
this.classList.add(hoverClass)
} else {
this.classList.remove(hoverClass)
}
}
_updateHoverClass (hoverClass) {
hoverClass = hoverClass || 'none'
if (hoverClass === 'none') {
this._removeEventListener()
} else {
this._addEventListener()
}
}
_addEventListener () {
if (!this.__hoverTouchStart) {
this.addEventListener('touchstart', this.__hoverTouchStart = this._hoverTouchStart.bind(this))
this.addEventListener('touchend', this.__hoverTouchEnd = this._hoverTouchEnd.bind(this))
this.addEventListener('touchcancel', this.__hoverTouchCancel = this._hoverTouchCancel.bind(this))
}
}
_removeEventListener () {
if (this.__hoverTouchStart) {
this.removeEventListener('touchstart', this.__hoverTouchStart)
delete this.__hoverTouchStart
this.removeEventListener('touchend', this.__hoverTouchEnd)
delete this.__hoverTouchEnd
this.removeEventListener('touchcancel', this.__hoverTouchCancel)
delete this.__hoverTouchCancel
}
}
_hoverTouchStart (evt) {
if (evt._hoverPropagationStopped) {
return
}
if (this.disabled) {
return
}
if (evt.touches.length > 1) {
return
}
if (this.getAttribute('hover-stop-propagation')) {
evt._hoverPropagationStopped = true
}
this._hoverTouch = true
const hoverStartTimeDefault = 50
const hoverStartTime = Number(this.getAttribute('hover-start-time') || hoverStartTimeDefault)
this._hoverStartTimer = setTimeout(() => {
this.hovering = true
if (!this._hoverTouch) {
// 防止在hoverStartTime时间内触发了 touchend 或 touchcancel
this._hoverReset()
}
}, isNaN(hoverStartTime) ? hoverStartTimeDefault : hoverStartTime)
}
_hoverTouchEnd () {
this._hoverTouch = false
if (this.hovering) {
this._hoverReset()
}
}
_hoverReset () {
requestAnimationFrame(() => {
clearTimeout(this._hoverStayTimer)
const hoverStayTimeDefault = 400
const hoverStayTime = Number(this.getAttribute('hover-stay-time') || hoverStayTimeDefault)
this._hoverStayTimer = setTimeout(() => {
this.hovering = false
}, isNaN(hoverStayTime) ? hoverStayTimeDefault : hoverStayTime)
})
}
_hoverTouchCancel () {
this._hoverTouch = false
this.hovering = false
clearTimeout(this._hoverStartTimer)
}
}
import View from './view'
export default {
View
}
import UniHoverElement from './hover'
export default class UniView extends UniHoverElement {
}
...@@ -36,13 +36,23 @@ ...@@ -36,13 +36,23 @@
:style="{height:height}" :style="{height:height}"
> >
<div <div
v-if="getIconPath(item,index) || item.iconPath || item.isMidButton" v-if="getIconPath(item,index) || item.iconfont || item.iconPath || item.isMidButton"
:class="{'uni-tabbar__icon__diff':!item.text}" :class="{'uni-tabbar__icon__diff':!item.text}"
class="uni-tabbar__icon" class="uni-tabbar__icon"
:style="{width: iconWidth,height:iconWidth}" :style="{width: iconWidth,height:iconWidth}"
> >
<div
v-if="item.iconfont"
:style="{
color:selectedIndex === index ? item.iconfont.selectedColor : item.iconfont.color,
fontSize: item.iconfont.fontSize || iconWidth
}"
class="uni-tabbar__iconfont"
>
{{ selectedIndex === index ? item.iconfont.selectedText : item.iconfont.text }}
</div>
<img <img
v-if="!item.isMidButton" v-else-if="!item.isMidButton"
:src="_getRealPath(getIconPath(item,index))" :src="_getRealPath(getIconPath(item,index))"
> >
<div <div
...@@ -168,6 +178,10 @@ ...@@ -168,6 +178,10 @@
height: 100%; height: 100%;
} }
uni-tabbar .uni-tabbar__iconfont {
font-family: 'UniTabbarIconFont';
}
uni-tabbar .uni-tabbar__label { uni-tabbar .uni-tabbar__label {
position: relative; position: relative;
text-align: center; text-align: center;
...@@ -220,9 +234,11 @@ ...@@ -220,9 +234,11 @@
import getRealPath from 'uni-platform/helpers/get-real-path' import getRealPath from 'uni-platform/helpers/get-real-path'
import { isPlainObject } from 'uni-shared' import { isPlainObject } from 'uni-shared'
import { publish } from 'uni-platform/service/bridge' import { publish } from 'uni-platform/service/bridge'
import { loadFontFace } from 'uni-core/view/bridge/subscribe/font'
function cssSupports (css) { function cssSupports (css) {
return window.CSS && CSS.supports && (CSS.supports(css) || CSS.supports.apply(CSS, css.split(':'))) return window.CSS && CSS.supports && (CSS.supports(css) || CSS.supports.apply(CSS, css.split(':')))
} }
const UNI_TABBAR_ICON_FONT = 'UniTabbarIconFont'
export default { export default {
name: 'TabBar', name: 'TabBar',
props: { props: {
...@@ -248,6 +264,10 @@ export default { ...@@ -248,6 +264,10 @@ export default {
type: String, type: String,
default: 'black' default: 'black'
}, },
iconfontSrc: {
type: String,
default: ''
},
list: { list: {
type: Array, type: Array,
default: function () { default: function () {
...@@ -340,6 +360,15 @@ export default { ...@@ -340,6 +360,15 @@ export default {
this.$set(item, 'visible', true) this.$set(item, 'visible', true)
} }
}) })
if (this.iconfontSrc) {
loadFontFace({
options: {
family: UNI_TABBAR_ICON_FONT,
source: `url("${this.iconfontSrc}")`
}
})
}
}, },
beforeCreate () { beforeCreate () {
this.__path__ = this.$route.path this.__path__ = this.$route.path
......
...@@ -2,6 +2,34 @@ import getWindowOffset from 'uni-platform/helpers/get-window-offset' ...@@ -2,6 +2,34 @@ import getWindowOffset from 'uni-platform/helpers/get-window-offset'
import deviceId from 'uni-platform/helpers/uuid' import deviceId from 'uni-platform/helpers/uuid'
import safeAreaInsets from 'safe-area-insets' import safeAreaInsets from 'safe-area-insets'
function IEVersion () {
const userAgent = navigator.userAgent
const isIE = userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1
const isEdge = userAgent.indexOf('Edge') > -1 && !isIE
const isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf('rv:11.0') > -1
if (isIE) {
const reIE = new RegExp('MSIE (\\d+\\.\\d+);')
reIE.test(userAgent)
const fIEVersion = parseFloat(RegExp.$1)
if (fIEVersion > 6) {
return fIEVersion
} else {
return 6
}
} else if (isEdge) {
return -1
} else if (isIE11) {
return 11
} else {
return -1
}
}
function getDeviceBrand (model) {
if (/iphone/gi.test(model) || /ipad/gi.test(model) || /mac/gi.test(model)) { return 'apple' }
if (/windows/gi.test(model)) { return 'microsoft' }
}
const ua = navigator.userAgent const ua = navigator.userAgent
/** /**
* 是否安卓设备 * 是否安卓设备
...@@ -45,6 +73,7 @@ export function getSystemInfoSync () { ...@@ -45,6 +73,7 @@ export function getSystemInfoSync () {
var osname var osname
var osversion var osversion
var model var model
let deviceType = 'phone'
if (isIOS) { if (isIOS) {
osname = 'iOS' osname = 'iOS'
...@@ -89,8 +118,11 @@ export function getSystemInfoSync () { ...@@ -89,8 +118,11 @@ export function getSystemInfoSync () {
model = 'iPad' model = 'iPad'
osname = 'iOS' osname = 'iOS'
osversion = typeof window.BigInt === 'function' ? '14.0' : '13.0' osversion = typeof window.BigInt === 'function' ? '14.0' : '13.0'
deviceType = 'pad'
} else if (isWindows || isMac || isLinux) { } else if (isWindows || isMac || isLinux) {
model = 'PC' model = 'PC'
osname = 'PC'
deviceType = 'pc'
const osversionFind = ua.match(/\((.+?)\)/)[1] const osversionFind = ua.match(/\((.+?)\)/)[1]
if (isWindows) { if (isWindows) {
...@@ -147,6 +179,7 @@ export function getSystemInfoSync () { ...@@ -147,6 +179,7 @@ export function getSystemInfoSync () {
} else { } else {
osname = 'Other' osname = 'Other'
osversion = '0' osversion = '0'
deviceType = 'other'
} }
var system = `${osname} ${osversion}` var system = `${osname} ${osversion}`
...@@ -168,6 +201,30 @@ export function getSystemInfoSync () { ...@@ -168,6 +201,30 @@ export function getSystemInfoSync () {
windowHeight -= windowTop windowHeight -= windowTop
windowHeight -= windowBottom windowHeight -= windowBottom
let browserName
let browseVersion = String(IEVersion())
if (browseVersion !== '-1') { browserName = 'IE' } else {
const browseVendors = ['Version', 'Firefox', 'Chrome', 'Edge{0,1}']
const vendors = ['Safari', 'Firefox', 'Chrome', 'Edge']
for (let index = 0; index < browseVendors.length; index++) {
const vendor = browseVendors[index]
const reg = new RegExp(`(${vendor})/(\\S*)\\b`)
if (reg.test(ua)) {
browserName = vendors[index]
browseVersion = ua.match(reg)[2]
}
}
}
// deviceBrand
let deviceBrand = ''
if (model) {
const _model = model.toLocaleLowerCase()
deviceBrand = getDeviceBrand(_model) ||
getDeviceBrand(osname.toLocaleLowerCase()) ||
_model.split(' ')[0]
}
return { return {
windowTop, windowTop,
windowBottom, windowBottom,
...@@ -180,7 +237,10 @@ export function getSystemInfoSync () { ...@@ -180,7 +237,10 @@ export function getSystemInfoSync () {
statusBarHeight, statusBarHeight,
system, system,
platform, platform,
deviceBrand,
deviceType,
model, model,
deviceModel: model,
safeArea, safeArea,
safeAreaInsets: { safeAreaInsets: {
top: safeAreaInsets.top, top: safeAreaInsets.top,
...@@ -188,7 +248,28 @@ export function getSystemInfoSync () { ...@@ -188,7 +248,28 @@ export function getSystemInfoSync () {
bottom: safeAreaInsets.bottom, bottom: safeAreaInsets.bottom,
left: safeAreaInsets.left left: safeAreaInsets.left
}, },
deviceId: deviceId() deviceId: deviceId(),
SDKVersion: '',
ua,
uniPlatform: 'web',
browserName,
browseVersion,
osLanguage: language,
osName: osname.toLocaleLowerCase(),
osVersion: osversion,
hostLanguage: language,
version: __uniConfig.appVersion,
uniCompileVersion: __uniConfig.compilerVersion,
uniRuntimeVersion: __uniConfig.compilerVersion,
appId: __uniConfig.appId,
appName: __uniConfig.appName,
appVersion: __uniConfig.appVersion,
appVersionCode: __uniConfig.appVersionCode,
hostName: browserName,
hostVersion: browseVersion,
osTheme: '',
hostTheme: '',
hostPackageName: ''
} }
} }
/** /**
......
...@@ -2,12 +2,14 @@ import { ...@@ -2,12 +2,14 @@ import {
setProperties setProperties
} from 'uni-shared' } from 'uni-shared'
const setTabBarItemProps = ['text', 'iconPath', 'selectedIconPath', 'visible'] const setTabBarItemProps = ['text', 'iconPath', 'iconfont', 'selectedIconPath', 'visible']
const setTabBarStyleProps = ['color', 'selectedColor', 'backgroundColor', 'borderStyle'] const setTabBarStyleProps = ['color', 'selectedColor', 'backgroundColor', 'borderStyle']
const setTabBarBadgeProps = ['badge', 'redDot'] const setTabBarBadgeProps = ['badge', 'redDot']
const setTabBarIconfontStyles = ['text', 'selectedText', 'fontSize', 'color', 'selectedColor']
function setTabBar (type, args = {}) { function setTabBar (type, args = {}) {
const app = getApp() const app = getApp()
...@@ -44,6 +46,10 @@ function setTabBar (type, args = {}) { ...@@ -44,6 +46,10 @@ function setTabBar (type, args = {}) {
app.$children[0].hideTabBar = true app.$children[0].hideTabBar = true
break break
case 'setTabBarItem': { case 'setTabBarItem': {
if (args.iconfont) {
setProperties(tabBar.list[index].iconfont, setTabBarIconfontStyles, args.iconfont)
args.iconfont = tabBar.list[index].iconfont
}
setProperties(tabBar.list[index], setTabBarItemProps, args) setProperties(tabBar.list[index], setTabBarItemProps, args)
const pagePath = args.pagePath const pagePath = args.pagePath
const route = pagePath && __uniRoutes.find(({ path }) => path === pagePath) const route = pagePath && __uniRoutes.find(({ path }) => path === pagePath)
......
import { getStorageSync } from './storage' import { getStorageSync } from './storage'
import { addSafeAreaInsets, populateParameters } from '../../mp-weixin/helpers/enhance-system-info'
const UUID_KEY = '__DC_STAT_UUID' const UUID_KEY = '__DC_STAT_UUID'
let deviceId let deviceId
...@@ -14,18 +15,6 @@ function addUuid (result) { ...@@ -14,18 +15,6 @@ function addUuid (result) {
result.deviceId = deviceId result.deviceId = deviceId
} }
function addSafeAreaInsets (result) {
if (result.safeArea) {
const safeArea = result.safeArea
result.safeAreaInsets = {
top: safeArea.top,
left: safeArea.left,
right: result.windowWidth - safeArea.right,
bottom: result.windowHeight - safeArea.bottom
}
}
}
function normalizePlatform (result) { function normalizePlatform (result) {
let platform = result.platform ? result.platform.toLowerCase() : 'devtools' let platform = result.platform ? result.platform.toLowerCase() : 'devtools'
if (!~['android', 'ios'].indexOf(platform)) { if (!~['android', 'ios'].indexOf(platform)) {
...@@ -39,5 +28,6 @@ export default { ...@@ -39,5 +28,6 @@ export default {
addUuid(result) addUuid(result)
addSafeAreaInsets(result) addSafeAreaInsets(result)
normalizePlatform(result) normalizePlatform(result)
populateParameters(result)
} }
} }
// import navigateTo from 'uni-helpers/navigate-to' // import navigateTo from 'uni-helpers/navigate-to'
// import redirectTo from '../../../mp-weixin/helpers/redirect-to' // import redirectTo from '../../../mp-weixin/helpers/redirect-to'
// import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' // import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
// import getSystemInfo from '../../../mp-weixin/helpers/system-info' import getSystemInfo from '../../../mp-weixin/helpers/system-info'
// import getUserProfile from '../../../mp-weixin/helpers/get-user-profile' // import getUserProfile from '../../../mp-weixin/helpers/get-user-profile'
// 需要做转换的 API 列表 // 需要做转换的 API 列表
...@@ -9,8 +9,8 @@ export const protocols = { ...@@ -9,8 +9,8 @@ export const protocols = {
// navigateTo, // navigateTo,
// redirectTo, // redirectTo,
// previewImage, // previewImage,
// getSystemInfo, getSystemInfo,
// getSystemInfoSync: getSystemInfo, getSystemInfoSync: getSystemInfo
// getUserProfile // getUserProfile
} }
......
function getDeviceBrand (model) {
if (/iphone/gi.test(model) || /ipad/gi.test(model) || /mac/gi.test(model)) { return 'apple' }
if (/windows/gi.test(model)) { return 'microsoft' }
}
const UUID_KEY = '__DC_STAT_UUID'
let deviceId
export function useDeviceId (result) {
deviceId = deviceId || __GLOBAL__.getStorageSync(UUID_KEY)
if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7)
__GLOBAL__.setStorage({
key: UUID_KEY,
data: deviceId
})
}
result.deviceId = deviceId
}
export function addSafeAreaInsets (result) {
if (result.safeArea) {
const safeArea = result.safeArea
result.safeAreaInsets = {
top: safeArea.top,
left: safeArea.left,
right: result.windowWidth - safeArea.right,
bottom: result.screenHeight - safeArea.bottom
}
}
}
export function populateParameters (result) {
const { brand, model, system, language, theme, version, hostName = '', platform } = result
const isQuickApp = __PLATFORM__.indexOf('quickapp-webview') !== -1
// osName osVersion
let osName = ''
let osVersion = ''
if (__PLATFORM__ === 'mp-alipay') {
osName = platform
osVersion = system
} else {
osName = system.split(' ')[0] || ''
osVersion = system.split(' ')[1] || ''
}
let hostVersion = version
// host 枚举值 https://smartprogram.baidu.com/docs/develop/api/device_sys/hostlist/
if (__PLATFORM__ === 'mp-baidu') {
hostVersion = result.swanNativeVersion || version
}
// deviceType
let deviceType = result.deviceType || 'phone'
if (__PLATFORM__ !== 'mp-baidu') {
const deviceTypeMaps = {
ipad: 'pad',
windows: 'pc',
mac: 'pc'
}
const deviceTypeMapsKeys = Object.keys(deviceTypeMaps)
const _model = model.toLocaleLowerCase()
for (let index = 0; index < deviceTypeMapsKeys.length; index++) {
const _m = deviceTypeMapsKeys[index]
if (_model.indexOf(_m) !== -1) {
deviceType = deviceTypeMaps[_m]
break
}
}
}
// deviceModel
let deviceBrand = model.split(' ')[0].toLocaleLowerCase()
if (__PLATFORM__ === 'mp-toutiao' || __PLATFORM__ === 'mp-lark' || isQuickApp) {
deviceBrand = brand.toLocaleLowerCase()
} else {
deviceBrand = getDeviceBrand(deviceBrand)
}
// hostName
let _hostName = hostName // mp-jd
if (__PLATFORM__ === 'mp-weixin') _hostName = (result.host || {}).env
if (__PLATFORM__ === 'mp-baidu' || __PLATFORM__ === 'mp-kuaishou') { _hostName = result.host }
if (__PLATFORM__ === 'mp-qq') _hostName = result.AppPlatform
if (__PLATFORM__ === 'mp-toutiao' || __PLATFORM__ === 'mp-lark') { _hostName = result.appName }
if (__PLATFORM__ === 'mp-alipay') _hostName = result.app
// wx.getAccountInfoSync
const parameters = {
appId: process.env.UNI_APP_ID,
appName: process.env.UNI_APP_NAME,
appVersion: process.env.UNI_APP_VERSION_NAME,
appVersionCode: process.env.UNI_APP_VERSION_CODE,
uniCompileVersion: process.env.UNI_COMPILER_VERSION,
uniRuntimeVersion: process.env.UNI_COMPILER_VERSION,
uniPlatform: process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM,
deviceBrand,
deviceModel: model,
deviceType,
osName: osName.toLocaleLowerCase(),
osVersion,
osLanguage: language,
osTheme: theme,
hostTheme: theme,
hostVersion,
hostLanguage: language,
hostName: _hostName,
// TODO
ua: '',
hostPackageName: '',
browserName: '',
browseVersion: ''
}
Object.assign(result, parameters)
}
const UUID_KEY = '__DC_STAT_UUID' import { useDeviceId, addSafeAreaInsets, populateParameters } from './enhance-system-info'
let deviceId
function addUuid (result) {
deviceId = deviceId || __GLOBAL__.getStorageSync(UUID_KEY)
if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7)
__GLOBAL__.setStorage({
key: UUID_KEY,
data: deviceId
})
}
result.deviceId = deviceId
}
function addSafeAreaInsets (result) {
if (result.safeArea) {
const safeArea = result.safeArea
result.safeAreaInsets = {
top: safeArea.top,
left: safeArea.left,
right: result.windowWidth - safeArea.right,
bottom: Math.abs(result.screenHeight - safeArea.bottom)
}
}
}
export default { export default {
returnValue: function (result) { returnValue: function (result) {
addUuid(result) useDeviceId(result)
addSafeAreaInsets(result) addSafeAreaInsets(result)
populateParameters(result)
} }
} }
// import navigateTo from 'uni-helpers/navigate-to' // import navigateTo from 'uni-helpers/navigate-to'
// import redirectTo from '../../../mp-weixin/helpers/redirect-to' // import redirectTo from '../../../mp-weixin/helpers/redirect-to'
// import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' // import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
// import getSystemInfo from '../../../mp-weixin/helpers/system-info' import getSystemInfo from '../../../mp-weixin/helpers/system-info'
// import getUserProfile from '../../../mp-weixin/helpers/get-user-profile' // import getUserProfile from '../../../mp-weixin/helpers/get-user-profile'
// 需要做转换的 API 列表 // 需要做转换的 API 列表
...@@ -9,8 +9,8 @@ export const protocols = { ...@@ -9,8 +9,8 @@ export const protocols = {
// navigateTo, // navigateTo,
// redirectTo, // redirectTo,
// previewImage, // previewImage,
// getSystemInfo, getSystemInfo,
// getSystemInfoSync: getSystemInfo, getSystemInfoSync: getSystemInfo
// getUserProfile // getUserProfile
} }
......
import navigateTo from 'uni-helpers/navigate-to' import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to' import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import getSystemInfo from '../../../mp-weixin/helpers/system-info'
export const protocols = { export const protocols = {
navigateTo, navigateTo,
redirectTo, redirectTo,
previewImage previewImage,
getSystemInfo,
getSystemInfoSync: getSystemInfo
} }
export const todos = [ export const todos = [
'preloadPage', 'preloadPage',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册