提交 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 @@
## 常见疑问
- 问:不同端有不同的需求、不同的特色,登支付也不一样,如何统一?
- 答:差异部分使用条件编译。uni-app提供了灵活强大的[条件编译](https://uniapp.dcloud.io/platform)。可以完美处理复用部分和差异部分。真正一套工程源码。当业务升级时,不再需要多端维护。如果多端维护,经常会因为某些端的流量不大,就一直拖延无法让那些用户享受到最新服务。另外登支付在客户端部分,已经被uni-app统一成一样的api了。
- 问:不同端有不同的需求、不同的特色,登支付也不一样,如何统一?
- 答:差异部分使用条件编译。uni-app提供了灵活强大的[条件编译](https://uniapp.dcloud.io/platform)。可以完美处理复用部分和差异部分。真正一套工程源码。当业务升级时,不再需要多端维护。如果多端维护,经常会因为某些端的流量不大,就一直拖延无法让那些用户享受到最新服务。另外登支付在客户端部分,已经被uni-app统一成一样的api了。
- 问:多端是不是一种妥协,是否会造成性能下降?
......
......@@ -2,6 +2,15 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"uni-shared": [
"./src/shared/index.js"
],
"uni-helpers/*": [
"./src/core/helpers/*"
],
"uni-mixins/*": [
"./src/core/view/mixins/*"
],
"uni-core/*": [
"./src/core/*"
],
......
......@@ -248,7 +248,9 @@ const third = [
'unPreloadPage',
'loadSubPackage',
'sendHostEvent',
'navigateToMiniProgram'
'navigateToMiniProgram',
'getLaunchOptionsSync',
'getEnterOptionsSync'
]
const ad = [
......
......@@ -213,6 +213,7 @@ class AdHelper {
const ad = this.get(options)
if (ad.isLoad) {
this._lastWaterfallIndex = -1
ad.show((e) => {
onclose && onclose(e)
}, () => {
......@@ -220,6 +221,7 @@ class AdHelper {
})
} else {
ad.load(() => {
this._lastWaterfallIndex = -1
onload && onload()
ad.show((e) => {
onclose && onclose(e)
......@@ -242,16 +244,14 @@ class AdHelper {
return
}
if (index === 0) {
this._lastWaterfallIndex = -1
}
const options2 = {
adpid: adpid[index],
urlCallback,
retry: false
}
console.log('ad.loadWaterfall::index=' + index)
this.load(options2, (res) => {
this._lastWaterfallIndex = index
onload(options2)
......@@ -260,7 +260,6 @@ class AdHelper {
if (index >= adpid.length) {
onfail(err)
} else {
console.log('loadWaterfall::index=' + index)
this.loadWaterfall(options, onload, onfail, index)
}
})
......@@ -276,17 +275,18 @@ class AdHelper {
return
}
let idx = index
if (this._lastWaterfallIndex > -1) {
idx = this._lastWaterfallIndex
index = this._lastWaterfallIndex
}
const options2 = {
adpid: adpid[idx],
adpid: adpid[index],
urlCallback,
retry: false
}
console.log('ad.showWaterfall::index=' + index)
this.show(options2, () => {
onload()
}, (err) => {
......@@ -444,6 +444,9 @@ export default {
},
methods: {
load () {
if (this.isLoading) {
return
}
this._startLoading()
const invoke = this._isWaterfall() ? 'loadWaterfall' : 'load'
this._adHelper[invoke](this._getAdOptions(), () => {
......@@ -454,6 +457,9 @@ export default {
},
show () {
if (this.isLoading) {
return
}
this._startLoading()
const invoke = this._isWaterfall() ? 'showWaterfall' : 'show'
this._adHelper[invoke](this._getAdOptions(), () => {
......
......@@ -6,7 +6,7 @@
const sys = uni.getSystemInfoSync();
// 访问开始即启动小程序,访问结束结分为:进入后台超过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_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s
......@@ -202,21 +202,10 @@ const get_scene = (options) => {
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,不包含参数
*/
const get_route = (pageVm) => {
const get_route$1 = (pageVm) => {
let _self = pageVm || get_page_vm();
if (get_platform_name() === 'bd') {
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
......@@ -290,7 +279,10 @@ const handle_data = (statData) => {
for (let i in statData) {
const rd = statData[i];
rd.forEach((elm) => {
const newData = get_splicing(elm);
let newData = '';
{
newData = elm;
}
if (i === 0) {
firstArr.push(newData);
} else if (i === 3) {
......@@ -506,18 +498,21 @@ const log = (data) => {
}
};
let data = uni.getStorageSync('$$STAT__DBDATA') || {};
const appid = process.env.UNI_APP_ID; // 做应用隔离
const dbSet = (name, value) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data) {
data = {};
}
data[name] = value;
uni.setStorageSync('$$STAT__DBDATA', data);
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
};
const dbGet = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data[name]) {
let dbdata = uni.getStorageSync('$$STAT__DBDATA');
let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (!dbdata) {
dbdata = {};
}
......@@ -530,14 +525,15 @@ const dbGet = (name) => {
};
const dbRemove = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (data[name]) {
delete data[name];
uni.setStorageSync('$$STAT__DBDATA', data);
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
} else {
data = uni.getStorageSync('$$STAT__DBDATA');
data = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (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 = () => {
return count
};
let Set__First__Time = 0;
let Set__Last__Time = 0;
const FIRST_TIME = '__first_time';
/**
* 获取第一次时间
* 设置页面首次访问时间,用户获取页面/应用停留时常
*/
const get_first_time = () => {
let time = new Date().getTime();
Set__First__Time = time;
Set__Last__Time = 0;
return time
const set_first_time = () => {
const time = new Date().getTime();
const timeStorge = dbSet(FIRST_TIME,time);
return timeStorge
};
/**
* 获取最后一次时间
* 获取最后一次时间 ,暂时用不到,直接获取当前时间即可
*/
const get_last_time = () => {
let time = new Date().getTime();
Set__Last__Time = time;
return time
};
// export const get_last_time = () => {
// let time = new Date().getTime()
// Set__Last__Time = time
// return time
// }
/**
* 获取页面 \ 应用停留时间
*/
const get_residence_time = (type) => {
let residenceTime = 0;
if (Set__First__Time !== 0) {
residenceTime = Set__Last__Time - Set__First__Time;
const first_time = dbGet(FIRST_TIME);
const last_time = get_time();
if (first_time !== 0) {
residenceTime = last_time - first_time;
}
residenceTime = parseInt(residenceTime / 1000);
......@@ -811,7 +807,6 @@ class Report {
applicationShow() {
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if (this.__licationHide) {
get_last_time();
const time = get_residence_time('app');
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if (time.overtime) {
......@@ -839,7 +834,6 @@ class Report {
}
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this.__licationHide = true;
get_last_time();
const time = get_residence_time();
const route = get_page_route(self);
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
......@@ -850,8 +844,8 @@ class Report {
},
type
);
// 重置时间
get_first_time();
// 更新页面首次访问时间
set_first_time();
}
/**
......@@ -867,20 +861,19 @@ class Report {
};
const route = get_page_route(self);
const routepath = get_route(self);
const routepath = get_route$1(self);
this._navigationBarTitle.config = get_page_name(routepath);
// 表示应用触发 ,页面切换不触发之后的逻辑
if (this.__licationShow) {
get_first_time();
// 更新页面首次访问时间
set_first_time();
// this._lastPageRoute = route
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
this.__licationShow = false;
return
}
get_last_time();
const time = get_residence_time('page');
// 停留时间
if (time.overtime) {
......@@ -890,8 +883,8 @@ class Report {
};
this.sendReportRequest(options);
}
// 重置时间
get_first_time();
// 更新页面首次访问时间
set_first_time();
}
/**
......@@ -899,7 +892,6 @@ class Report {
*/
pageHide(self) {
if (!this.__licationHide) {
get_last_time();
const time = get_residence_time('page');
let route = get_page_route(self);
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
......@@ -992,8 +984,16 @@ class Report {
* 自定义事件上报
*/
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.lt = '21';
let options = {
......@@ -1227,6 +1227,7 @@ class Stat extends Report {
// 初始化页面停留时间 start
set_page_residence_time();
this.__licationShow = true;
dbSet('__launch_options', options);
this.sendReportRequest(options, true);
}
load(options, self) {
......@@ -1249,7 +1250,7 @@ class Stat extends Report {
}
// #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') {
this.appShow();
}
......@@ -1270,7 +1271,7 @@ class Stat extends Report {
}
// #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') {
this.appHide();
}
......@@ -1286,23 +1287,33 @@ class Stat extends Report {
error(em) {
// 开发工具内不上报错误
if (this._platform === 'devtools') {
if (process.env.NODE_ENV === 'development') {
console.info('当前运行环境为开发者工具,不上报数据。');
return
}
}
// if (this._platform === 'devtools') {
// if (process.env.NODE_ENV === 'development') {
// console.info('当前运行环境为开发者工具,不上报数据。')
// return
// }
// }
let emVal = '';
if (!em.message) {
emVal = JSON.stringify(em);
} else {
emVal = em.stack;
}
let route = '';
try {
route = get_route();
}catch(e){
// 未获取到页面路径
route = '';
}
let options = {
ak: this.statData.ak,
uuid: this.statData.uuid,
p: this.statData.p,
lt: '31',
url:route,
ut: this.statData.ut,
ch: this.statData.ch,
mpsdk: this.statData.mpsdk,
......
......@@ -4,7 +4,7 @@
const sys = uni.getSystemInfoSync();
// 访问开始即启动小程序,访问结束结分为:进入后台超过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_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s
......@@ -200,21 +200,10 @@ const get_scene = (options) => {
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,不包含参数
*/
const get_route = (pageVm) => {
const get_route$1 = (pageVm) => {
let _self = pageVm || get_page_vm();
if (get_platform_name() === 'bd') {
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
......@@ -288,7 +277,10 @@ const handle_data = (statData) => {
for (let i in statData) {
const rd = statData[i];
rd.forEach((elm) => {
const newData = get_splicing(elm);
let newData = '';
{
newData = elm;
}
if (i === 0) {
firstArr.push(newData);
} else if (i === 3) {
......@@ -504,18 +496,21 @@ const log = (data) => {
}
};
let data = uni.getStorageSync('$$STAT__DBDATA') || {};
const appid = process.env.UNI_APP_ID; // 做应用隔离
const dbSet = (name, value) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data) {
data = {};
}
data[name] = value;
uni.setStorageSync('$$STAT__DBDATA', data);
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
};
const dbGet = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data[name]) {
let dbdata = uni.getStorageSync('$$STAT__DBDATA');
let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (!dbdata) {
dbdata = {};
}
......@@ -528,14 +523,15 @@ const dbGet = (name) => {
};
const dbRemove = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (data[name]) {
delete data[name];
uni.setStorageSync('$$STAT__DBDATA', data);
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
} else {
data = uni.getStorageSync('$$STAT__DBDATA');
data = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (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 = () => {
return count
};
let Set__First__Time = 0;
let Set__Last__Time = 0;
const FIRST_TIME = '__first_time';
/**
* 获取第一次时间
* 设置页面首次访问时间,用户获取页面/应用停留时常
*/
const get_first_time = () => {
let time = new Date().getTime();
Set__First__Time = time;
Set__Last__Time = 0;
return time
const set_first_time = () => {
const time = new Date().getTime();
const timeStorge = dbSet(FIRST_TIME,time);
return timeStorge
};
/**
* 获取最后一次时间
* 获取最后一次时间 ,暂时用不到,直接获取当前时间即可
*/
const get_last_time = () => {
let time = new Date().getTime();
Set__Last__Time = time;
return time
};
// export const get_last_time = () => {
// let time = new Date().getTime()
// Set__Last__Time = time
// return time
// }
/**
* 获取页面 \ 应用停留时间
*/
const get_residence_time = (type) => {
let residenceTime = 0;
if (Set__First__Time !== 0) {
residenceTime = Set__Last__Time - Set__First__Time;
const first_time = dbGet(FIRST_TIME);
const last_time = get_time();
if (first_time !== 0) {
residenceTime = last_time - first_time;
}
residenceTime = parseInt(residenceTime / 1000);
......@@ -809,7 +805,6 @@ class Report {
applicationShow() {
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if (this.__licationHide) {
get_last_time();
const time = get_residence_time('app');
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if (time.overtime) {
......@@ -837,7 +832,6 @@ class Report {
}
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this.__licationHide = true;
get_last_time();
const time = get_residence_time();
const route = get_page_route(self);
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
......@@ -848,8 +842,8 @@ class Report {
},
type
);
// 重置时间
get_first_time();
// 更新页面首次访问时间
set_first_time();
}
/**
......@@ -865,20 +859,19 @@ class Report {
};
const route = get_page_route(self);
const routepath = get_route(self);
const routepath = get_route$1(self);
this._navigationBarTitle.config = get_page_name(routepath);
// 表示应用触发 ,页面切换不触发之后的逻辑
if (this.__licationShow) {
get_first_time();
// 更新页面首次访问时间
set_first_time();
// this._lastPageRoute = route
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
this.__licationShow = false;
return
}
get_last_time();
const time = get_residence_time('page');
// 停留时间
if (time.overtime) {
......@@ -888,8 +881,8 @@ class Report {
};
this.sendReportRequest(options);
}
// 重置时间
get_first_time();
// 更新页面首次访问时间
set_first_time();
}
/**
......@@ -897,7 +890,6 @@ class Report {
*/
pageHide(self) {
if (!this.__licationHide) {
get_last_time();
const time = get_residence_time('page');
let route = get_page_route(self);
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
......@@ -990,8 +982,16 @@ class Report {
* 自定义事件上报
*/
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.lt = '21';
let options = {
......@@ -1225,6 +1225,7 @@ class Stat extends Report {
// 初始化页面停留时间 start
set_page_residence_time();
this.__licationShow = true;
dbSet('__launch_options', options);
this.sendReportRequest(options, true);
}
load(options, self) {
......@@ -1247,7 +1248,7 @@ class Stat extends Report {
}
// #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') {
this.appShow();
}
......@@ -1268,7 +1269,7 @@ class Stat extends Report {
}
// #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') {
this.appHide();
}
......@@ -1284,23 +1285,33 @@ class Stat extends Report {
error(em) {
// 开发工具内不上报错误
if (this._platform === 'devtools') {
if (process.env.NODE_ENV === 'development') {
console.info('当前运行环境为开发者工具,不上报数据。');
return
}
}
// if (this._platform === 'devtools') {
// if (process.env.NODE_ENV === 'development') {
// console.info('当前运行环境为开发者工具,不上报数据。')
// return
// }
// }
let emVal = '';
if (!em.message) {
emVal = JSON.stringify(em);
} else {
emVal = em.stack;
}
let route = '';
try {
route = get_route();
}catch(e){
// 未获取到页面路径
route = '';
}
let options = {
ak: this.statData.ak,
uuid: this.statData.uuid,
p: this.statData.p,
lt: '31',
url:route,
ut: this.statData.ut,
ch: this.statData.ch,
mpsdk: this.statData.mpsdk,
......
......@@ -6,7 +6,7 @@
const sys = uni.getSystemInfoSync();
// 访问开始即启动小程序,访问结束结分为:进入后台超过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_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s
......@@ -216,7 +216,7 @@ const get_splicing = (data) => {
/**
* 获取页面url,不包含参数
*/
const get_route = (pageVm) => {
const get_route$1 = (pageVm) => {
let _self = pageVm || get_page_vm();
if (get_platform_name() === 'bd') {
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
......@@ -290,7 +290,10 @@ const handle_data = (statData) => {
for (let i in statData) {
const rd = statData[i];
rd.forEach((elm) => {
const newData = get_splicing(elm);
let newData = '';
{
newData = get_splicing(elm);
}
if (i === 0) {
firstArr.push(newData);
} else if (i === 3) {
......@@ -474,18 +477,21 @@ const log = (data) => {
}
};
let data = uni.getStorageSync('$$STAT__DBDATA') || {};
const appid = process.env.UNI_APP_ID; // 做应用隔离
const dbSet = (name, value) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data) {
data = {};
}
data[name] = value;
uni.setStorageSync('$$STAT__DBDATA', data);
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
};
const dbGet = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data[name]) {
let dbdata = uni.getStorageSync('$$STAT__DBDATA');
let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (!dbdata) {
dbdata = {};
}
......@@ -498,14 +504,15 @@ const dbGet = (name) => {
};
const dbRemove = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (data[name]) {
delete data[name];
uni.setStorageSync('$$STAT__DBDATA', data);
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
} else {
data = uni.getStorageSync('$$STAT__DBDATA');
data = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (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 = () => {
return count
};
let Set__First__Time = 0;
let Set__Last__Time = 0;
const FIRST_TIME = '__first_time';
/**
* 获取第一次时间
* 设置页面首次访问时间,用户获取页面/应用停留时常
*/
const get_first_time = () => {
let time = new Date().getTime();
Set__First__Time = time;
Set__Last__Time = 0;
return time
const set_first_time = () => {
const time = new Date().getTime();
const timeStorge = dbSet(FIRST_TIME,time);
return timeStorge
};
/**
* 获取最后一次时间
* 获取最后一次时间 ,暂时用不到,直接获取当前时间即可
*/
const get_last_time = () => {
let time = new Date().getTime();
Set__Last__Time = time;
return time
};
// export const get_last_time = () => {
// let time = new Date().getTime()
// Set__Last__Time = time
// return time
// }
/**
* 获取页面 \ 应用停留时间
*/
const get_residence_time = (type) => {
let residenceTime = 0;
if (Set__First__Time !== 0) {
residenceTime = Set__Last__Time - Set__First__Time;
const first_time = dbGet(FIRST_TIME);
const last_time = get_time();
if (first_time !== 0) {
residenceTime = last_time - first_time;
}
residenceTime = parseInt(residenceTime / 1000);
......@@ -779,7 +786,6 @@ class Report {
applicationShow() {
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if (this.__licationHide) {
get_last_time();
const time = get_residence_time('app');
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if (time.overtime) {
......@@ -807,7 +813,6 @@ class Report {
}
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this.__licationHide = true;
get_last_time();
const time = get_residence_time();
const route = get_page_route(self);
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
......@@ -818,8 +823,8 @@ class Report {
},
type
);
// 重置时间
get_first_time();
// 更新页面首次访问时间
set_first_time();
}
/**
......@@ -835,20 +840,19 @@ class Report {
};
const route = get_page_route(self);
const routepath = get_route(self);
const routepath = get_route$1(self);
this._navigationBarTitle.config = get_page_name(routepath);
// 表示应用触发 ,页面切换不触发之后的逻辑
if (this.__licationShow) {
get_first_time();
// 更新页面首次访问时间
set_first_time();
// this._lastPageRoute = route
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
this.__licationShow = false;
return
}
get_last_time();
const time = get_residence_time('page');
// 停留时间
if (time.overtime) {
......@@ -858,8 +862,8 @@ class Report {
};
this.sendReportRequest(options);
}
// 重置时间
get_first_time();
// 更新页面首次访问时间
set_first_time();
}
/**
......@@ -867,7 +871,6 @@ class Report {
*/
pageHide(self) {
if (!this.__licationHide) {
get_last_time();
const time = get_residence_time('page');
let route = get_page_route(self);
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
......@@ -960,8 +963,16 @@ class Report {
* 自定义事件上报
*/
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.lt = '21';
let options = {
......@@ -1183,6 +1194,7 @@ class Stat extends Report {
// 初始化页面停留时间 start
set_page_residence_time();
this.__licationShow = true;
dbSet('__launch_options', options);
this.sendReportRequest(options, true);
}
load(options, self) {
......@@ -1205,7 +1217,7 @@ class Stat extends Report {
}
// #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') {
this.appShow();
}
......@@ -1226,7 +1238,7 @@ class Stat extends Report {
}
// #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') {
this.appHide();
}
......@@ -1242,23 +1254,33 @@ class Stat extends Report {
error(em) {
// 开发工具内不上报错误
if (this._platform === 'devtools') {
if (process.env.NODE_ENV === 'development') {
console.info('当前运行环境为开发者工具,不上报数据。');
return
}
}
// if (this._platform === 'devtools') {
// if (process.env.NODE_ENV === 'development') {
// console.info('当前运行环境为开发者工具,不上报数据。')
// return
// }
// }
let emVal = '';
if (!em.message) {
emVal = JSON.stringify(em);
} else {
emVal = em.stack;
}
let route = '';
try {
route = get_route();
}catch(e){
// 未获取到页面路径
route = '';
}
let options = {
ak: this.statData.ak,
uuid: this.statData.uuid,
p: this.statData.p,
lt: '31',
url:route,
ut: this.statData.ut,
ch: this.statData.ch,
mpsdk: this.statData.mpsdk,
......
......@@ -4,7 +4,7 @@
const sys = uni.getSystemInfoSync();
// 访问开始即启动小程序,访问结束结分为:进入后台超过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_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s
......@@ -214,7 +214,7 @@ const get_splicing = (data) => {
/**
* 获取页面url,不包含参数
*/
const get_route = (pageVm) => {
const get_route$1 = (pageVm) => {
let _self = pageVm || get_page_vm();
if (get_platform_name() === 'bd') {
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
......@@ -288,7 +288,10 @@ const handle_data = (statData) => {
for (let i in statData) {
const rd = statData[i];
rd.forEach((elm) => {
const newData = get_splicing(elm);
let newData = '';
{
newData = get_splicing(elm);
}
if (i === 0) {
firstArr.push(newData);
} else if (i === 3) {
......@@ -472,18 +475,21 @@ const log = (data) => {
}
};
let data = uni.getStorageSync('$$STAT__DBDATA') || {};
const appid = process.env.UNI_APP_ID; // 做应用隔离
const dbSet = (name, value) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data) {
data = {};
}
data[name] = value;
uni.setStorageSync('$$STAT__DBDATA', data);
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
};
const dbGet = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (!data[name]) {
let dbdata = uni.getStorageSync('$$STAT__DBDATA');
let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (!dbdata) {
dbdata = {};
}
......@@ -496,14 +502,15 @@ const dbGet = (name) => {
};
const dbRemove = (name) => {
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
if (data[name]) {
delete data[name];
uni.setStorageSync('$$STAT__DBDATA', data);
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
} else {
data = uni.getStorageSync('$$STAT__DBDATA');
data = uni.getStorageSync('$$STAT__DBDATA:'+appid);
if (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 = () => {
return count
};
let Set__First__Time = 0;
let Set__Last__Time = 0;
const FIRST_TIME = '__first_time';
/**
* 获取第一次时间
* 设置页面首次访问时间,用户获取页面/应用停留时常
*/
const get_first_time = () => {
let time = new Date().getTime();
Set__First__Time = time;
Set__Last__Time = 0;
return time
const set_first_time = () => {
const time = new Date().getTime();
const timeStorge = dbSet(FIRST_TIME,time);
return timeStorge
};
/**
* 获取最后一次时间
* 获取最后一次时间 ,暂时用不到,直接获取当前时间即可
*/
const get_last_time = () => {
let time = new Date().getTime();
Set__Last__Time = time;
return time
};
// export const get_last_time = () => {
// let time = new Date().getTime()
// Set__Last__Time = time
// return time
// }
/**
* 获取页面 \ 应用停留时间
*/
const get_residence_time = (type) => {
let residenceTime = 0;
if (Set__First__Time !== 0) {
residenceTime = Set__Last__Time - Set__First__Time;
const first_time = dbGet(FIRST_TIME);
const last_time = get_time();
if (first_time !== 0) {
residenceTime = last_time - first_time;
}
residenceTime = parseInt(residenceTime / 1000);
......@@ -777,7 +784,6 @@ class Report {
applicationShow() {
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if (this.__licationHide) {
get_last_time();
const time = get_residence_time('app');
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if (time.overtime) {
......@@ -805,7 +811,6 @@ class Report {
}
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this.__licationHide = true;
get_last_time();
const time = get_residence_time();
const route = get_page_route(self);
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
......@@ -816,8 +821,8 @@ class Report {
},
type
);
// 重置时间
get_first_time();
// 更新页面首次访问时间
set_first_time();
}
/**
......@@ -833,20 +838,19 @@ class Report {
};
const route = get_page_route(self);
const routepath = get_route(self);
const routepath = get_route$1(self);
this._navigationBarTitle.config = get_page_name(routepath);
// 表示应用触发 ,页面切换不触发之后的逻辑
if (this.__licationShow) {
get_first_time();
// 更新页面首次访问时间
set_first_time();
// this._lastPageRoute = route
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
this.__licationShow = false;
return
}
get_last_time();
const time = get_residence_time('page');
// 停留时间
if (time.overtime) {
......@@ -856,8 +860,8 @@ class Report {
};
this.sendReportRequest(options);
}
// 重置时间
get_first_time();
// 更新页面首次访问时间
set_first_time();
}
/**
......@@ -865,7 +869,6 @@ class Report {
*/
pageHide(self) {
if (!this.__licationHide) {
get_last_time();
const time = get_residence_time('page');
let route = get_page_route(self);
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
......@@ -958,8 +961,16 @@ class Report {
* 自定义事件上报
*/
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.lt = '21';
let options = {
......@@ -1181,6 +1192,7 @@ class Stat extends Report {
// 初始化页面停留时间 start
set_page_residence_time();
this.__licationShow = true;
dbSet('__launch_options', options);
this.sendReportRequest(options, true);
}
load(options, self) {
......@@ -1203,7 +1215,7 @@ class Stat extends Report {
}
// #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') {
this.appShow();
}
......@@ -1224,7 +1236,7 @@ class Stat extends Report {
}
// #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') {
this.appHide();
}
......@@ -1240,23 +1252,33 @@ class Stat extends Report {
error(em) {
// 开发工具内不上报错误
if (this._platform === 'devtools') {
if (process.env.NODE_ENV === 'development') {
console.info('当前运行环境为开发者工具,不上报数据。');
return
}
}
// if (this._platform === 'devtools') {
// if (process.env.NODE_ENV === 'development') {
// console.info('当前运行环境为开发者工具,不上报数据。')
// return
// }
// }
let emVal = '';
if (!em.message) {
emVal = JSON.stringify(em);
} else {
emVal = em.stack;
}
let route = '';
try {
route = get_route();
}catch(e){
// 未获取到页面路径
route = '';
}
let options = {
ak: this.statData.ak,
uuid: this.statData.uuid,
p: this.statData.p,
lt: '31',
url:route,
ut: this.statData.ut,
ch: this.statData.ch,
mpsdk: this.statData.mpsdk,
......
......@@ -44,7 +44,7 @@ describe('codegen', () => {
it('generate text with multiple statements', () => {
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>`,
`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', () => {
......@@ -68,18 +68,18 @@ describe('codegen', () => {
'<p :change:prop="swipe.sizeReady" :prop="pos" @touchstart="swipe.touchstart" @touchmove="swipe.touchmove" @touchend="swipe.touchend" @change="change"></p>',
`with(this){return _c('p',{wxsProps:{"change:prop":"pos"},attrs:{"change:prop":swipe.sizeReady,"prop":_$gc(0,'change:pos'),"_i":0},on:{"touchstart":function($event){$event = $handleWxsEvent($event);swipe.touchstart($event, $getComponentDescriptor())},"touchmove":function($event){$event = $handleWxsEvent($event);swipe.touchmove($event, $getComponentDescriptor())},"touchend":function($event){$event = $handleWxsEvent($event);swipe.touchend($event, $getComponentDescriptor())},"change":function($event){return $handleViewEvent($event)}}})}`
)
})
it('generate staticClass and id', () => {
assertCodegen(
'<custom id="id"></custom>',
`with(this){return _c('custom',{attrs:{"id":"id","_i":0}})}`
)
assertCodegen(
'<custom :id="id"></custom>',
`with(this){return _c('custom',{attrs:{"id":_$g(0,'a-id'),"_i":0}})}`
)
})
})
it('generate staticClass and id', () => {
assertCodegen(
'<custom id="id"></custom>',
`with(this){return _c('custom',{attrs:{"id":"id","_i":0}})}`
)
assertCodegen(
'<custom :id="id"></custom>',
`with(this){return _c('custom',{attrs:{"id":_$g(0,'a-id'),"_i":0}})}`
)
})
// TODO 后续优化dataset
// it('generate dataset', () => {
......@@ -91,11 +91,11 @@ describe('codegen', () => {
it('generate dataset', () => {
assertCodegen(
'<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}})}`
)
assertCodegen(
'<custom data-a="1" :data-b="b"></custom>',
`with(this){return _c('custom',{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(
'<custom data-a="1" :data-b="b"></custom>',
`with(this){return _c('custom',{attrs:{"data-a":"1","data-b":_$g(0,'a-data-b'),"_i":0}})}`
)
})
it('generate v-if directive', () => {
......@@ -141,12 +141,12 @@ describe('codegen', () => {
it('generate text trim', () => {
assertCodegen(
'<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(
'<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(
......@@ -179,42 +179,42 @@ describe('codegen', () => {
assertCodegen(
'<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(
'<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(
'<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(
'<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(
'<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(
'<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(
'<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')))])}`
)
})
it('generate bool attr', () => {
assertCodegen(
'<video controls/>',
`with(this){return _c('v-uni-video',{attrs:{"controls":true,"_i":0}})}`
)
assertCodegen(
'<video controls=""/>',
`with(this){return _c('v-uni-video',{attrs:{"controls":"","_i":0}})}`
)
`with(this){return _c('uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text "+(_$g(0,'t0-1')))])}`
)
})
it('generate bool attr', () => {
assertCodegen(
'<video controls/>',
`with(this){return _c('v-uni-video',{attrs:{"controls":true,"_i":0}})}`
)
assertCodegen(
'<video controls=""/>',
`with(this){return _c('v-uni-video',{attrs:{"controls":"","_i":0}})}`
)
})
})
/* eslint-enable quotes */
/* eslint-enable quotes */
......@@ -4,8 +4,17 @@ const {
const tags = require('@dcloudio/uni-cli-shared/lib/tags')
// web components
const elements = ['uni-view']
// 仅限 view 层
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)) {
el.tag = 'v-uni-' + el.tag
}
......
......@@ -210,7 +210,7 @@ function isComponent (tagName) {
return false
}
}
return !hasOwn(tags, getTagName(tagName.replace('v-uni-', '')))
return !hasOwn(tags, getTagName(tagName.replace(/^(v-)?uni-/, '')))
}
function makeMap (str, expectsLowerCase) {
......
......@@ -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_NAME': JSON.stringify(process.env.UNI_APP_NAME),
'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.UNICLOUD_DEBUG': process.env.UNICLOUD_DEBUG,
'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_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) {
Object.assign(defines, {
......
......@@ -31,6 +31,8 @@ const manifestJsonObj = getManifestJson()
process.env.UNI_APP_ID = manifestJsonObj.appid || ''
process.env.UNI_APP_NAME = manifestJsonObj.name || ''
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 标记
if (process.env.UNI_PLATFORM.indexOf('mp-') === 0) {
......@@ -341,11 +343,11 @@ if (
console.log()
} else {
if (!uniStatistics.version) {
// console.log()
// console.warn(uniI18n.__('pluginUni.uniStatisticsNoVersion', {
// 0: 'https://uniapp.dcloud.io/uni-stat-v2.html'
// }))
// console.log()
console.log()
console.warn(uniI18n.__('pluginUni.uniStatisticsNoVersion', {
0: 'https://uniapp.dcloud.io/uni-stat-v2.html'
}))
console.log()
} else {
console.log()
console.warn(`已开启 uni统计${uniStatistics.version}.0 版本`)
......@@ -354,11 +356,11 @@ if (
}
} else {
if (!uniStatistics.version) {
// console.log()
// console.warn(uniI18n.__('pluginUni.uniStatisticsNoVersion', {
// 0: 'https://uniapp.dcloud.io/uni-stat-v2.html'
// }))
// console.log()
console.log()
console.warn(uniI18n.__('pluginUni.uniStatisticsNoVersion', {
0: 'https://uniapp.dcloud.io/uni-stat-v2.html'
}))
console.log()
} else {
console.log()
console.warn(`已开启 uni统计${uniStatistics.version}.0 版本`)
......@@ -388,6 +390,11 @@ const warningMsg =
const needWarning = !platformOptions.usingComponents || usingComponentsAbsent
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'
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')
......@@ -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') {
try {
let info = ''
let info = process.env.UNI_COMPILER_VERSION
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) {
console.log(info)
} else {
......
......@@ -443,6 +443,11 @@ global['____${h5.appid}____'] = true;
delete global['____${h5.appid}____'];
global.__uniConfig = ${JSON.stringify(pagesJson)};
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.publicPath = ${JSON.stringify(h5.publicPath)};
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 = {
translate: 'all',
createRadialGradient: 'all',
createLinearGradient: 'all',
transform: [4, 5],
setTransform: [4, 5]
}
......
......@@ -63,7 +63,7 @@ export function getTargetDataset (target) {
$parent = $parent.$parent
}
} else {
dataset = target.dataset || {}
dataset = Object.assign({}, target.dataset, target.__uniDataset)
}
return normalizeDataset(dataset)
}
......
......@@ -4,11 +4,6 @@
ref="content"
:style="style"
/>
<img
v-if="contentPath"
:src="contentPath"
:draggable="draggable"
>
<v-uni-resize-sensor
v-if="mode === 'widthFix' || mode === 'heightFix'"
ref="sensor"
......@@ -128,6 +123,12 @@ export default {
if (newValue === 'widthFix' || newValue === 'heightFix') {
this._fixSize()
}
},
contentPath (val) {
if (!val && this.__img) {
this.__img.remove()
delete this.__img
}
}
},
mounted () {
......@@ -177,6 +178,12 @@ export default {
this._fixSize()
this.contentPath = realImagePath
img.draggable = this.draggable
if (this.__img) {
this.__img.remove()
}
this.__img = img
this.$el.appendChild(img)
this.$trigger('load', $event, {
width: img.width,
......@@ -224,12 +231,12 @@ uni-image[hidden] {
display: none;
}
uni-image > div {
uni-image>div {
width: 100%;
height: 100%;
}
uni-image > img {
uni-image>img {
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
......@@ -242,7 +249,7 @@ uni-image > img {
opacity: 0;
}
uni-image > .uni-image-will-change {
uni-image>.uni-image-will-change {
will-change: transform;
}
</style>
......@@ -9,6 +9,19 @@ const requireComponents = [
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) => {
components.keys().forEach(fileName => {
// 获取组件配置
......@@ -18,10 +31,12 @@ requireComponents.forEach((components, index) => {
componentConfig.mixins = componentConfig.mixins ? [].concat(baseMixin, componentConfig.mixins) : [baseMixin]
componentConfig.mixins.push(animation)
if (!componentConfig.functional) {
componentConfig.mixins.push(animation)
}
componentConfig.name = 'VUni' + componentConfig.name
componentConfig.name = 'VUni' + componentConfig.name
componentConfig.isReserved = true
// 全局注册组件
......
......@@ -120,6 +120,7 @@ export default function parseNodes (nodes, parentNode, scopeId, triggerItemClick
return
}
const attrs = node.attrs
scopeId && elem.setAttribute(scopeId, '')
if (isPlainObject(attrs)) {
const tagAttrs = TAGS[tagName] || []
Object.keys(attrs).forEach(function (name) {
......@@ -130,7 +131,6 @@ export default function parseNodes (nodes, parentNode, scopeId, triggerItemClick
Array.isArray(value) && (value = value.join(' '))
case 'style':
elem.setAttribute(name, value)
scopeId && elem.setAttribute(scopeId, '')
break
default:
if (tagAttrs.indexOf(name) !== -1) {
......
......@@ -72,6 +72,7 @@ import {
field
} from 'uni-mixins'
const DARK_TEST_STRING = '(prefers-color-scheme: dark)'
const ConfirmTypes = ['done', 'go', 'next', 'search', 'send'] // 'return'
export default {
name: 'Textarea',
mixins: [field],
......@@ -106,7 +107,10 @@ export default {
},
confirmType: {
type: String,
default: ''
default: 'return',
validator (val) {
return ConfirmTypes.concat('return').includes(val)
}
}
},
data () {
......@@ -127,7 +131,7 @@ export default {
return (this.composing ? this.valueComposition : this.valueSync).split('\n')
},
isDone () {
return ['done', 'go', 'next', 'search', 'send'].includes(this.confirmType)
return ConfirmTypes.includes(this.confirmType)
}
},
watch: {
......@@ -208,7 +212,6 @@ export default {
!this.ignoreCompositionEvent &&
this.$trigger($event.type, $event, { data: $event.data })
},
// 暂无完成按钮,此功能未实现
_confirm ($event) {
this.$trigger('confirm', $event, {
value: this.valueSync
......
......@@ -51,7 +51,7 @@ function getStyle (action) {
return style
}
function startAnimation (context) {
export function startAnimation (context) {
const animation = context.animation
if (!animation || !animation.actions || !animation.actions.length) {
return
......
......@@ -18,9 +18,12 @@ export function getSystemInfoSync () {
}
export function getSystemInfo () {
const platform = plus.os.name.toLowerCase()
const ios = platform === 'ios'
const isAndroid = platform === 'android'
const { getSystemInfoSync } = weex.requireModule('plus')
const info = getSystemInfoSync()
const { deviceBrand, deviceModel, osName, osVersion, osLanguage } = info
const brand = deviceBrand.toLowerCase()
const _osName = osName.toLowerCase()
const ios = _osName === 'ios'
const {
screenWidth,
screenHeight
......@@ -76,21 +79,21 @@ export function getSystemInfo () {
height: windowHeightReal - safeAreaInsets.top - safeAreaInsets.bottom
}
return {
return Object.assign({
errMsg: 'getSystemInfo:ok',
brand: plus.device.vendor,
model: plus.device.model,
brand: brand,
model: deviceModel,
pixelRatio: plus.screen.scale,
screenWidth,
screenHeight,
windowWidth,
windowHeight,
statusBarHeight,
language: plus.os.language,
system: `${ios ? 'iOS' : isAndroid ? 'Android' : ''} ${plus.os.version}`,
language: osLanguage,
system: `${osName} ${osVersion}`,
version: plus.runtime.innerVersion,
fontSizeSetting: '',
platform,
platform: _osName,
SDKVersion: '',
windowTop,
windowBottom,
......@@ -102,5 +105,8 @@ export function getSystemInfo () {
left: safeAreaInsets.left
},
deviceId: deviceId()
}
}
}, info, {
deviceBrand: brand,
osName: _osName
})
}
......@@ -56,6 +56,7 @@ export * from './plugin/on-native-event-receive'
export * from './plugin/send-native-event'
export * from './plugin/load-sub-package'
export * from './plugin/sdk'
export * from './plugin/get-launch-options-sync'
export * from './route/navigate-back'
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 ({
extend(launchOptions, {
path,
query: query ? parseQuery(query) : {},
referrerInfo: referrerInfo || {}
referrerInfo: referrerInfo || {},
channel: plus.runtime.channel,
launcher: plus.runtime.launcher
})
extend(enterOptions, launchOptions)
return launchOptions
......@@ -62,7 +64,7 @@ export function parseRedirectInfo () {
userAction,
fromAppid
} =
weexPlus.getRedirectInfo() || {}
weexPlus.getRedirectInfo() || {}
const referrerInfo = {
appId: fromAppid,
extraData: {}
......@@ -77,4 +79,4 @@ export function parseRedirectInfo () {
userAction
}
}
}
}
<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 @@
:style="{height:height}"
>
<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"
: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
v-if="!item.isMidButton"
v-else-if="!item.isMidButton"
:src="_getRealPath(getIconPath(item,index))"
>
<div
......@@ -166,6 +176,10 @@
uni-tabbar .uni-tabbar__icon img {
width: 100%;
height: 100%;
}
uni-tabbar .uni-tabbar__iconfont {
font-family: 'UniTabbarIconFont';
}
uni-tabbar .uni-tabbar__label {
......@@ -219,10 +233,12 @@
<script>
import getRealPath from 'uni-platform/helpers/get-real-path'
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) {
return window.CSS && CSS.supports && (CSS.supports(css) || CSS.supports.apply(CSS, css.split(':')))
}
}
const UNI_TABBAR_ICON_FONT = 'UniTabbarIconFont'
export default {
name: 'TabBar',
props: {
......@@ -247,6 +263,10 @@ export default {
borderStyle: {
type: String,
default: 'black'
},
iconfontSrc: {
type: String,
default: ''
},
list: {
type: Array,
......@@ -339,7 +359,16 @@ export default {
if (item.visible === undefined) {
this.$set(item, 'visible', true)
}
})
})
if (this.iconfontSrc) {
loadFontFace({
options: {
family: UNI_TABBAR_ICON_FONT,
source: `url("${this.iconfontSrc}")`
}
})
}
},
beforeCreate () {
this.__path__ = this.$route.path
......
......@@ -2,6 +2,34 @@ import getWindowOffset from 'uni-platform/helpers/get-window-offset'
import deviceId from 'uni-platform/helpers/uuid'
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
/**
* 是否安卓设备
......@@ -45,6 +73,7 @@ export function getSystemInfoSync () {
var osname
var osversion
var model
let deviceType = 'phone'
if (isIOS) {
osname = 'iOS'
......@@ -89,8 +118,11 @@ export function getSystemInfoSync () {
model = 'iPad'
osname = 'iOS'
osversion = typeof window.BigInt === 'function' ? '14.0' : '13.0'
deviceType = 'pad'
} else if (isWindows || isMac || isLinux) {
model = 'PC'
osname = 'PC'
deviceType = 'pc'
const osversionFind = ua.match(/\((.+?)\)/)[1]
if (isWindows) {
......@@ -147,6 +179,7 @@ export function getSystemInfoSync () {
} else {
osname = 'Other'
osversion = '0'
deviceType = 'other'
}
var system = `${osname} ${osversion}`
......@@ -168,6 +201,30 @@ export function getSystemInfoSync () {
windowHeight -= windowTop
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 {
windowTop,
windowBottom,
......@@ -180,7 +237,10 @@ export function getSystemInfoSync () {
statusBarHeight,
system,
platform,
deviceBrand,
deviceType,
model,
deviceModel: model,
safeArea,
safeAreaInsets: {
top: safeAreaInsets.top,
......@@ -188,7 +248,28 @@ export function getSystemInfoSync () {
bottom: safeAreaInsets.bottom,
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 {
setProperties
} from 'uni-shared'
const setTabBarItemProps = ['text', 'iconPath', 'selectedIconPath', 'visible']
const setTabBarItemProps = ['text', 'iconPath', 'iconfont', 'selectedIconPath', 'visible']
const setTabBarStyleProps = ['color', 'selectedColor', 'backgroundColor', 'borderStyle']
const setTabBarBadgeProps = ['badge', 'redDot']
const setTabBarIconfontStyles = ['text', 'selectedText', 'fontSize', 'color', 'selectedColor']
function setTabBar (type, args = {}) {
const app = getApp()
......@@ -43,7 +45,11 @@ function setTabBar (type, args = {}) {
case 'hideTabBar':
app.$children[0].hideTabBar = true
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)
const pagePath = args.pagePath
const route = pagePath && __uniRoutes.find(({ path }) => path === pagePath)
......
import { getStorageSync } from './storage'
import { addSafeAreaInsets, populateParameters } from '../../mp-weixin/helpers/enhance-system-info'
const UUID_KEY = '__DC_STAT_UUID'
let deviceId
......@@ -14,18 +15,6 @@ function addUuid (result) {
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) {
let platform = result.platform ? result.platform.toLowerCase() : 'devtools'
if (!~['android', 'ios'].indexOf(platform)) {
......@@ -39,5 +28,6 @@ export default {
addUuid(result)
addSafeAreaInsets(result)
normalizePlatform(result)
populateParameters(result)
}
}
// import navigateTo from 'uni-helpers/navigate-to'
// import redirectTo from '../../../mp-weixin/helpers/redirect-to'
// 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'
// 需要做转换的 API 列表
......@@ -9,8 +9,8 @@ export const protocols = {
// navigateTo,
// redirectTo,
// previewImage,
// getSystemInfo,
// getSystemInfoSync: getSystemInfo,
getSystemInfo,
getSystemInfoSync: getSystemInfo
// 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'
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)
}
}
}
import { useDeviceId, addSafeAreaInsets, populateParameters } from './enhance-system-info'
export default {
returnValue: function (result) {
addUuid(result)
useDeviceId(result)
addSafeAreaInsets(result)
populateParameters(result)
}
}
// import navigateTo from 'uni-helpers/navigate-to'
// import redirectTo from '../../../mp-weixin/helpers/redirect-to'
// 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'
// 需要做转换的 API 列表
......@@ -9,8 +9,8 @@ export const protocols = {
// navigateTo,
// redirectTo,
// previewImage,
// getSystemInfo,
// getSystemInfoSync: getSystemInfo,
getSystemInfo,
getSystemInfoSync: getSystemInfo
// getUserProfile
}
......
import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import getSystemInfo from '../../../mp-weixin/helpers/system-info'
export const protocols = {
navigateTo,
redirectTo,
previewImage
previewImage,
getSystemInfo,
getSystemInfoSync: getSystemInfo
}
export const todos = [
'preloadPage',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册