diff --git a/build/rollup.config.stat.js b/build/rollup.config.stat.js new file mode 100644 index 0000000000000000000000000000000000000000..d86468c821377a182edd782ab7baaa630f62c76c --- /dev/null +++ b/build/rollup.config.stat.js @@ -0,0 +1,9 @@ +module.exports = { + input: 'packages/uni-stat/src/index.js', + output: { + file: 'packages/uni-stat/dist/index.js', + format: 'es' + }, + external: ['vue', '@dcloudio/uni-stat/package.json'], + plugins: [] +} diff --git a/package.json b/package.json index becc645512951fc8d4846db6608fb2bcb69661b7..8ac1e13477bc096163aa8fe5fe81bff3962d6e54 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "build:mp-alipay": "cross-env UNI_PLATFORM=mp-alipay rollup -c build/rollup.config.mp.js", "build:mp-toutiao": "cross-env UNI_PLATFORM=mp-toutiao rollup -c build/rollup.config.mp.js", "build:runtime": "npm run lint && npm run build:mp-weixin && npm run build:mp-qq && npm run build:mp-alipay && npm run build:mp-baidu && npm run build:mp-toutiao && npm run build:app-plus", + "build:stat": "npm run lint && rollup -c build/rollup.config.stat.js", "test:unit": "cross-env NODE_ENV=test UNI_PLATFORM=h5 mocha-webpack --require tests/unit/setup.js --webpack-config build/webpack.config.test.js tests/unit/**/*.spec.js", "release": "npm run lint:cli && lerna publish --force-publish=*", "release:alpha": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=alpha" diff --git a/packages/uni-mp-alipay/dist/index.js b/packages/uni-mp-alipay/dist/index.js index 96723b57c3b68e9e40ba045eef5ef9f2d972404b..5d7773bb09386d0d776c180c5f6ff35cfa6c7e61 100644 --- a/packages/uni-mp-alipay/dist/index.js +++ b/packages/uni-mp-alipay/dist/index.js @@ -356,8 +356,6 @@ const todos = [ 'getRecorderManager', 'getBackgroundAudioManager', 'createInnerAudioContext', - 'chooseVideo', - 'saveVideoToPhotosAlbum', 'createVideoContext', 'createCameraContext', 'createLivePlayerContext', @@ -366,12 +364,7 @@ const todos = [ 'startAccelerometer', 'startCompass', 'addPhoneContact', - 'setBackgroundColor', - 'setBackgroundTextStyle', - 'createIntersectionObserver', 'authorize', - 'openSetting', - 'getSetting', 'chooseAddress', 'chooseInvoiceTitle', 'addTemplate', @@ -380,12 +373,12 @@ const todos = [ 'getTemplateLibraryList', 'getTemplateList', 'sendTemplateMessage', - 'getUpdateManager', 'setEnableDebug', 'getExtConfig', 'getExtConfigSync', 'onWindowResize', - 'offWindowResize' + 'offWindowResize', + 'saveVideoToPhotosAlbum' ]; // 存在兼容性的 API 列表 @@ -398,7 +391,13 @@ const canIUses = [ 'setTabBarBadge', 'removeTabBarBadge', 'showTabBarRedDot', - 'hideTabBarRedDot' + 'hideTabBarRedDot', + 'openSetting', + 'getSetting', + 'createIntersectionObserver', + 'getUpdateManager', + 'setBackgroundColor', + 'setBackgroundTextStyle' ]; function _handleNetworkInfo (result) { @@ -551,6 +550,12 @@ const protocols = { // 需要做转换的 API 列表 returnValue: { apFilePath: 'tempFilePath' } + }, + chooseVideo: { + // 支付宝小程序文档中未找到(仅在getSetting处提及),但实际可用 + returnValue: { + apFilePath: 'tempFilePath' + } }, connectSocket: { args: { @@ -686,6 +691,18 @@ const protocols = { // 需要做转换的 API 列表 item.uuid = item.serviceId; }); } + }, + createBLEConnection: { + name: 'connectBLEDevice', + args: { + timeout: false + } + }, + closeBLEConnection: { + name: 'disconnectBLEDevice' + }, + onBLEConnectionStateChange: { + name: 'onBLEConnectionStateChanged' }, makePhoneCall: { args: { @@ -717,6 +734,9 @@ const protocols = { // 需要做转换的 API 列表 returnValue: { brightness: 'value' } + }, + showShareMenu: { + name: 'showSharePanel' } }; @@ -936,7 +956,9 @@ function createExecCallback (execCallback) { callback(res[index]); }); }); - execCallback(res); + if (isFn(execCallback)) { + execCallback(res); + } } } diff --git a/packages/uni-mp-alipay/package.json b/packages/uni-mp-alipay/package.json index 92fce1c27ec54db0b1f14e27620dbc54df4a8f2a..a8bd4a34a014481519cc773f03b6c3c8fbbea6bf 100644 --- a/packages/uni-mp-alipay/package.json +++ b/packages/uni-mp-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-alipay", - "version": "1.0.0-alpha-22120190814002", + "version": "0.0.827", "description": "uni-app mp-alipay", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-qq/dist/index.js b/packages/uni-mp-qq/dist/index.js index 9b2c8477c6b5dea0dc90a9227cac490fa8451817..1a113713009181b3db219e2fde94508f1a31aa18 100644 --- a/packages/uni-mp-qq/dist/index.js +++ b/packages/uni-mp-qq/dist/index.js @@ -388,18 +388,9 @@ const protocols = { previewImage }; const todos = [ - 'connectSocket', - 'onSocketOpen', - 'onSocketError', - 'sendSocketMessage', - 'onSocketMessage', - 'closeSocket', - 'onSocketClose', 'createLivePlayerContext', 'createLivePusherContext', 'loadFontFace', - 'openDocument', - 'canIUse', 'onMemoryWarning', 'onNetworkStatusChange', 'startBeaconDiscovery', @@ -426,8 +417,6 @@ const todos = [ 'getExtConfig', 'getExtConfigSync', 'getPhoneNumber', - 'updateShareMenu', - 'getShareInfo', 'chooseAddress', 'addCard', 'openCard', @@ -454,7 +443,17 @@ const canIUses = [ 'onUserCaptureScreen', 'vibrateLong', 'vibrateShort', - 'createWorker' + 'createWorker', + 'connectSocket', + 'onSocketOpen', + 'onSocketError', + 'sendSocketMessage', + 'onSocketMessage', + 'closeSocket', + 'onSocketClose', + 'openDocument', + 'updateShareMenu', + 'getShareInfo' ]; const CALLBACKS = ['success', 'fail', 'cancel', 'complete']; diff --git a/packages/uni-mp-qq/package.json b/packages/uni-mp-qq/package.json index fbc5cf958cb8f784f786f7064cc286420defb827..c0d63aff5acf099728d97d85cca519eb88ba776d 100644 --- a/packages/uni-mp-qq/package.json +++ b/packages/uni-mp-qq/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-qq", - "version": "1.0.0-alpha-22120190814002", + "version": "0.0.111", "description": "uni-app mp-qq", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-toutiao/dist/index.js b/packages/uni-mp-toutiao/dist/index.js index 2d407f840b503fd25a4b8bed1d0c05961be3515c..bc98f75ed4b7f94cf63852f1101f66f5b4e256ca 100644 --- a/packages/uni-mp-toutiao/dist/index.js +++ b/packages/uni-mp-toutiao/dist/index.js @@ -386,22 +386,10 @@ var previewImage = { // 不支持的 API 列表 const todos = [ - 'hideKeyboard', - 'onSocketOpen', - 'onSocketError', - 'sendSocketMessage', - 'onSocketMessage', - 'closeSocket', - 'onSocketClose', - 'getImageInfo', 'getBackgroundAudioManager', - 'createVideoContext', 'createCameraContext', 'createLivePlayerContext', - 'getSavedFileList', 'getSavedFileInfo', - 'removeSavedFile', - 'getFileInfo', 'openDocument', 'chooseLocation', 'createMapContext', @@ -450,7 +438,6 @@ const todos = [ 'hideTabBarRedDot', 'setBackgroundColor', 'setBackgroundTextStyle', - 'createIntersectionObserver', 'chooseInvoiceTitle', 'navigateToMiniProgram', 'navigateBackMiniProgram', @@ -461,14 +448,30 @@ const todos = [ 'getTemplateList', 'sendTemplateMessage', 'setEnableDebug', - 'getExtConfig', - 'getExtConfigSync', 'onWindowResize', - 'offWindowResize' + 'offWindowResize', + 'compressImage', + 'createOffscreenCanvas' ]; // 存在兼容性的 API 列表 -const canIUses = []; +// 头条小程序不支持canIUses +const canIUses = [ + // 'createIntersectionObserver', + // 'getSavedFileList', + // 'removeSavedFile', + // 'hideKeyboard', + // 'getImageInfo', + // 'createVideoContext', + // 'onSocketOpen', + // 'onSocketError', + // 'sendSocketMessage', + // 'onSocketMessage', + // 'closeSocket', + // 'onSocketClose', + // 'getExtConfig', + // 'getExtConfigSync', +]; // 需要做转换的 API 列表 const protocols = { @@ -485,7 +488,7 @@ const protocols = { }, chooseVideo: { args: { - maxDuration: false + camera: false } }, scanCode: { @@ -534,7 +537,14 @@ const protocols = { } }, requestPayment: { - orderInfo: 'data' + args: { + orderInfo: 'data' + } + }, + getFileInfo: { + args: { + digestAlgorithm: false + } } }; diff --git a/packages/uni-mp-toutiao/package.json b/packages/uni-mp-toutiao/package.json index b625e8805b62bbfc4ea15d9963ca18686e482a44..3033c07cd5fd92ca4f9a3c0dacfb4b85fd8ae26e 100644 --- a/packages/uni-mp-toutiao/package.json +++ b/packages/uni-mp-toutiao/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-toutiao", - "version": "1.0.0-alpha-22120190814002", + "version": "0.0.351", "description": "uni-app mp-toutiao", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-stat/dist/index.js b/packages/uni-stat/dist/index.js new file mode 100644 index 0000000000000000000000000000000000000000..43d42304681f5a96fec6ff68150932d3baa818ed --- /dev/null +++ b/packages/uni-stat/dist/index.js @@ -0,0 +1,825 @@ +import { version } from '@dcloudio/uni-stat/package.json'; + +const STAT_VERSION = version; +const STAT_URL = 'https://tongji.dcloud.net.cn/uni/stat'; +const STAT_H5_URL = 'https://tongji.dcloud.net.cn/uni/stat.gif'; +const PAGE_PVER_TIME = 1800; +const APP_PVER_TIME = 300; +const OPERATING_TIME = 10; + +const UUID_KEY = '__DC_STAT_UUID'; +const UUID_VALUE = '__DC_UUID_VALUE'; + +function getUuid() { + let uuid = ''; + if (getPlatformName() === 'n') { + try { + uuid = plus.runtime.getDCloudId(); + } catch (e) { + uuid = ''; + } + uni.setStorageSync(UUID_KEY, uuid); + return uuid + } + + try { + uuid = uni.getStorageSync(UUID_KEY); + } catch (e) { + uuid = UUID_VALUE; + } + + if (!uuid) { + uuid = Date.now() + '' + Math.floor(Math.random() * 1e7); + try { + uni.setStorageSync(UUID_KEY, uuid); + } catch (e) { + uni.setStorageSync(UUID_KEY, UUID_VALUE); + } + } + return uuid; +} + +const getSgin = (statData) => { + let arr = Object.keys(statData); + let sortArr = arr.sort(); + let sgin = {}; + let sginStr = ''; + for (var i in sortArr) { + sgin[sortArr[i]] = statData[sortArr[i]]; + sginStr += sortArr[i] + '=' + statData[sortArr[i]] + '&'; + } + // const options = sginStr.substr(0, sginStr.length - 1) + // sginStr = sginStr.substr(0, sginStr.length - 1) + '&key=' + STAT_KEY; + // const si = crypto.createHash('md5').update(sginStr).digest('hex'); + return { + sign: '', + options: sginStr.substr(0, sginStr.length - 1) + }; +}; + +const getSplicing = (data) => { + let str = ''; + for (var i in data) { + str += i + '=' + data[i] + '&'; + } + return str.substr(0, str.length - 1) +}; + +const getTime = () => { + return parseInt(new Date().getTime() / 1000); +}; + +const getPlatformName = () => { + const platformList = { + 'app-plus': 'n', + 'h5': 'h5', + 'mp-weixin': 'wx', + 'mp-alipay': 'ali', + 'mp-baidu': 'bd', + 'mp-toutiao': 'tt', + 'mp-qq': 'qq' + }; + return platformList[process.env.VUE_APP_PLATFORM]; +}; + +const getPackName = () => { + let packName = ''; + if (getPlatformName() === 'wx' || getPlatformName() === 'qq') { + packName = uni.getAccountInfoSync().miniProgram.appId || ''; + } + return packName +}; + +const getVersion = () => { + return getPlatformName() === 'n' ? plus.runtime.version : ''; +}; + +const getChannel = () => { + const platformName = getPlatformName(); + let channel = ''; + if (platformName === 'n') { + channel = plus.runtime.channel; + } + return channel; +}; + +const getScene = (options) => { + const platformName = getPlatformName(); + let scene = ''; + if (options) { + return options; + } + if (platformName === 'wx') { + scene = uni.getLaunchOptionsSync().scene; + } + return scene; +}; +const First__Visit__Time__KEY = 'First__Visit__Time'; +const Last__Visit__Time__KEY = 'Last__Visit__Time'; + +const getFirstVisitTime = () => { + const timeStorge = uni.getStorageSync(First__Visit__Time__KEY); + let time = 0; + if (timeStorge) { + time = timeStorge; + } else { + time = getTime(); + uni.setStorageSync(First__Visit__Time__KEY, time); + uni.removeStorageSync(Last__Visit__Time__KEY); + } + return time; +}; + +const getLastVisitTime = () => { + const timeStorge = uni.getStorageSync(Last__Visit__Time__KEY); + let time = 0; + if (timeStorge) { + time = timeStorge; + } else { + time = ''; + } + uni.setStorageSync(Last__Visit__Time__KEY, getTime()); + return time; +}; + + +const PAGE_RESIDENCE_TIME = '__page__residence__time'; +let First_Page_residence_time = 0; +let Last_Page_residence_time = 0; + + +const setPageResidenceTime = () => { + First_Page_residence_time = getTime(); + if (getPlatformName() === 'n') { + uni.setStorageSync(PAGE_RESIDENCE_TIME, getTime()); + } + return First_Page_residence_time +}; + +const getPageResidenceTime = () => { + Last_Page_residence_time = getTime(); + if (getPlatformName() === 'n') { + First_Page_residence_time = uni.getStorageSync(PAGE_RESIDENCE_TIME); + } + return Last_Page_residence_time - First_Page_residence_time +}; +const TOTAL__VISIT__COUNT = 'Total__Visit__Count'; +const getTotalVisitCount = () => { + const timeStorge = uni.getStorageSync(TOTAL__VISIT__COUNT); + let count = 1; + if (timeStorge) { + count = timeStorge; + count++; + } + uni.setStorageSync(TOTAL__VISIT__COUNT, count); + return count; +}; + +const GetEncodeURIComponentOptions = (statData) => { + let data = {}; + for (let prop in statData) { + data[prop] = encodeURIComponent(statData[prop]); + } + return data; +}; + +let Set__First__Time = 0; +let Set__Last__Time = 0; + +const getFirstTime = () => { + let time = new Date().getTime(); + Set__First__Time = time; + Set__Last__Time = 0; + return time; +}; + + +const getLastTime = () => { + let time = new Date().getTime(); + Set__Last__Time = time; + return time; +}; + + +const getResidenceTime = (type) => { + let residenceTime = 0; + if (Set__First__Time !== 0) { + residenceTime = Set__Last__Time - Set__First__Time; + } + + residenceTime = parseInt(residenceTime / 1000); + residenceTime = residenceTime < 1 ? 1 : residenceTime; + if (type === 'app') { + let overtime = residenceTime > APP_PVER_TIME ? true : false; + return { + residenceTime, + overtime + }; + } + if (type === 'page') { + let overtime = residenceTime > PAGE_PVER_TIME ? true : false; + return { + residenceTime, + overtime + }; + } + + return { + residenceTime + }; + +}; + +const getRoute = () => { + var pages = getCurrentPages(); + var page = pages[pages.length - 1]; + let _self = page.$vm; + + if (getPlatformName() === 'bd') { + return _self.$mp && _self.$mp.page.is; + } else { + return _self.$scope && _self.$scope.route || _self.$mp && _self.$mp.page.route; + } +}; + +const getPageRoute = (self) => { + var pages = getCurrentPages(); + var page = pages[pages.length - 1]; + let _self = page.$vm; + let query = self._query; + let str = query && JSON.stringify(query) !== '{}' ? '?' + JSON.stringify(query) : ''; + // clear + self._query = ''; + if (getPlatformName() === 'bd') { + return _self.$mp && _self.$mp.page.is + str; + } else { + return _self.$scope && _self.$scope.route + str || _self.$mp && _self.$mp.page.route + str; + } +}; + +const getPageTypes = (self) => { + if (self.mpType === 'page' || self.$mp && self.$mp.mpType === 'page') { + return true; + } + return false; +}; + +const calibration = (eventName, options) => { + // login 、 share 、pay_success 、pay_fail 、register 、title + if(!eventName){ + console.error(`uni.report 缺少 [eventName] 参数`); + return true + } + if (typeof eventName !== 'string') { + console.error(`uni.report [eventName] 参数类型错误,只能为 String 类型`); + return true + } + if (eventName.length > 255) { + console.error(`uni.report [eventName] 参数长度不能大于 255`); + return true + } + + if (typeof options !== 'string' && typeof options !== 'object') { + console.error(`uni.report [options] 参数类型错误,只能为 String 或 Object 类型`); + return true + } + + if (typeof options === 'string' && options.length > 255) { + console.error(`uni.report [options] 参数长度不能大于 255`); + return true + } + + if (eventName === 'title' && typeof options !== 'string') { + console.error('uni.report [eventName] 参数为 title 时,[options] 参数只能为 String 类型'); + return true + } +}; + +const PagesJson = require('uni-pages?{"type":"style"}').default; +const statConfig = require('uni-stat-config').default || require('uni-stat-config'); + +const resultOptions = uni.getSystemInfoSync(); + +class Util { + constructor() { + this.self = ''; + this._retry = 0; + this._platform = ''; + this._query = {}; + this._navigationBarTitle = { + config: '', + page: '', + report: '', + lt: '' + }; + this._operatingTime = 0; + this._reportingRequestData = { + '1': [], + '11': [] + }; + this.__prevent_triggering = false; + + this.__licationHide = false; + this.__licationShow = false; + this._lastPageRoute = ''; + this.statData = { + uuid: getUuid(), + ut: getPlatformName(), + mpn: getPackName(), + ak: statConfig.appid, + usv: STAT_VERSION, + v: getVersion(), + ch: getChannel(), + cn: '', + pn: '', + ct: '', + t: getTime(), + tt: '', + p: resultOptions.platform === 'android' ? 'a' : 'i', + brand: resultOptions.brand || '', + md: resultOptions.model, + sv: resultOptions.system.replace(/(Android|iOS)\s/, ''), + mpsdk: resultOptions.SDKVersion || '', + mpv: resultOptions.version || '', + lang: resultOptions.language, + pr: resultOptions.pixelRatio, + ww: resultOptions.windowWidth, + wh: resultOptions.windowHeight, + sw: resultOptions.screenWidth, + sh: resultOptions.screenHeight + }; + + } + + _applicationShow() { + if (this.__licationHide) { + getLastTime(); + const time = getResidenceTime('app'); + if (time.overtime) { + let options = { + path: this._lastPageRoute, + scene: this.statData.sc + }; + this._sendReportRequest(options); + } + this.__licationHide = false; + } + } + + _applicationHide(self, type) { + + this.__licationHide = true; + getLastTime(); + const time = getResidenceTime(); + getFirstTime(); + this._sendHideRequest({ + urlref: this._lastPageRoute, + urlref_ts: time.residenceTime + }, type); + } + + _pageShow() { + const route = getPageRoute(this); + const routepath = getRoute(); + this._navigationBarTitle.config = PagesJson && + PagesJson.pages[routepath] && + PagesJson.pages[routepath].titleNView && + PagesJson.pages[routepath].titleNView.titleText || + PagesJson && + PagesJson.pages[routepath] && + PagesJson.pages[routepath].navigationBarTitleText || ''; + + if (this.__licationShow) { + getFirstTime(); + this.__licationShow = false; + // console.log('这是 onLauch 之后执行的第一次 pageShow ,为下次记录时间做准备'); + this._lastPageRoute = route; + return; + } + + getLastTime(); + this._lastPageRoute = route; + const time = getResidenceTime('page'); + if (time.overtime) { + let options = { + path: this._lastPageRoute, + scene: this.statData.sc + }; + this._sendReportRequest(options); + } + getFirstTime(); + } + + _pageHide() { + if (!this.__licationHide) { + getLastTime(); + const time = getResidenceTime('page'); + this._sendPageRequest({ + url: this._lastPageRoute, + urlref: this._lastPageRoute, + urlref_ts: time.residenceTime + }); + this._navigationBarTitle = { + config: '', + page: '', + report: '', + lt: '' + }; + return; + } + } + + _login() { + this._sendEventRequest({ + key: 'login' + }, 0); + } + + _share() { + this._sendEventRequest({ + key: 'share' + }, 0); + } + _payment(key) { + this._sendEventRequest({ + key + }, 0); + } + _sendReportRequest(options) { + this._navigationBarTitle.lt = '1'; + let query = options.query && JSON.stringify(options.query) !== '{}' ? '?' + JSON.stringify(options.query) : ''; + this.statData.lt = '1'; + this.statData.url = options.path + query; + this.statData.t = getTime(); + this.statData.sc = getScene(options.scene); + this.statData.fvts = getFirstVisitTime(); + this.statData.lvts = getLastVisitTime(); + this.statData.tvc = getTotalVisitCount(); + this.getNetworkInfo(); + } + + _sendPageRequest(opt) { + let { + url, + urlref, + urlref_ts + } = opt; + this._navigationBarTitle.lt = '11'; + let options = { + ak: this.statData.ak, + uuid: this.statData.uuid, + lt: '11', + ut: this.statData.ut, + url, + tt: this.statData.tt, + urlref, + urlref_ts, + ch: this.statData.ch, + usv: this.statData.usv, + t: getTime(), + p: this.statData.p + }; + this.request(options); + } + + _sendHideRequest(opt, type) { + let { + urlref, + urlref_ts + } = opt; + let options = { + ak: this.statData.ak, + uuid: this.statData.uuid, + lt: '3', + ut: this.statData.ut, + urlref, + urlref_ts, + ch: this.statData.ch, + usv: this.statData.usv, + t: getTime(), + p: this.statData.p + }; + this.request(options, type); + } + _sendEventRequest({ + key = '', + value = "" + } = {}) { + const route = getPageRoute(this); + let options = { + ak: this.statData.ak, + uuid: this.statData.uuid, + lt: '21', + ut: this.statData.ut, + url: route, + ch: this.statData.ch, + e_n: key, + e_v: typeof(value) === 'object' ? JSON.stringify(value) : value.toString(), + usv: this.statData.usv, + t: getTime(), + p: this.statData.p + }; + this.request(options); + } + + getNetworkInfo() { + uni.getNetworkType({ + success: (result) => { + this.statData.net = result.networkType; + this.getLocation(); + } + }); + } + + getLocation() { + if (statConfig.getLocation) { + uni.getLocation({ + type: 'wgs84', + geocode: true, + success: (result) => { + if (result.address) { + this.statData.cn = result.address.country; + this.statData.pn = result.address.province; + this.statData.ct = result.address.city; + } + + this.statData.lat = result.latitude; + this.statData.lng = result.longitude; + this.request(this.statData); + } + }); + } else { + this.statData.lat = 0; + this.statData.lng = 0; + this.request(this.statData); + } + } + + request(data, type) { + let time = getTime(); + const title = this._navigationBarTitle; + data.ttn = title.page; + data.ttpj = title.config; + data.ttc = title.report; + + let requestData = this._reportingRequestData; + if (!requestData[data.lt]) { + this._reportingRequestData[data.lt] = []; + } + this._reportingRequestData[data.lt].push(data); + if (getPageResidenceTime() < OPERATING_TIME && !type) { + return + } + // 时间超过,重新获取时间戳 + setPageResidenceTime(); + let firstArr = []; + let contentArr = []; + let lastArr = []; + for (let i in this._reportingRequestData) { + const rd = this._reportingRequestData[i]; + rd.forEach((elm) => { + const newData = getSplicing(elm); + if (i === 0) { + firstArr.push(newData); + } else if (i === 3) { + lastArr.push(newData); + } else { + contentArr.push(newData); + } + }); + } + + firstArr.push(...contentArr, ...lastArr); + let optionsData = { + usv: STAT_VERSION, //统计 SDK 版本号 + t: time, //发送请求时的时间戮 + requests: JSON.stringify(firstArr), + }; + this._reportingRequestData = {}; + + if (data.ut === 'h5') { + this.imageRequest(optionsData); + return + } + uni.request({ + url: STAT_URL, + method: 'POST', + data: optionsData, + success: () => { + if (process.env.NODE_ENV === 'development') { + console.log('stat request success'); + } + }, + fail: (e) => { + if (process.env.NODE_ENV === 'development') { + console.log('stat request fail', e); + } + if (++this._retry < 3) { + setTimeout(() => { + this.request(data); + }, 1000); + } + } + }); + } + /** + * h5 请求 + */ + imageRequest(data) { + let image = new Image(); + let options = getSgin(GetEncodeURIComponentOptions(data)).options; + image.src = STAT_H5_URL + '?' + options; + } + + sendEvent(key, value) { + // 校验 type 参数 + if (calibration(key, value)) return + + if (key === 'title') { + this._navigationBarTitle.report = value; + return + } + this._sendEventRequest({ + key, + value: typeof(value) === 'object' ? JSON.stringify(value) : value + }, 1); + } +} + + +class Stat extends Util { + static getInstance() { + if (!this.instance) { + this.instance = new Stat(); + } + return this.instance; + } + constructor() { + super(); + this.instance = null; + // 注册拦截器 + if (typeof uni.addInterceptor === 'function') { + this.addInterceptorInit(); + this.interceptLogin(); + this.interceptShare(true); + this.interceptRequestPayment(); + } + } + + addInterceptorInit() { + let self = this; + uni.addInterceptor('setNavigationBarTitle', { + invoke(args) { + self._navigationBarTitle.page = args.title; + } + }); + } + + interceptLogin() { + let self = this; + uni.addInterceptor('login', { + complete() { + self._login(); + } + }); + } + + interceptShare(type) { + let self = this; + if (!type) { + self._share(); + return + } + uni.addInterceptor('share', { + success() { + self._share(); + }, + fail() { + self._share(); + } + }); + } + + interceptRequestPayment() { + let self = this; + uni.addInterceptor('requestPayment', { + success() { + self._payment('pay_success'); + }, + fail() { + self._payment('pay_fail'); + } + }); + } + + report(options, self) { + this.self = self; + if (process.env.NODE_ENV === 'development') { + console.log('report init'); + } + setPageResidenceTime(); + this.__licationShow = true; + this._sendReportRequest(options, true); + } + + load(options, self) { + this.self = self; + this._query = options; + } + + show(self) { + this.self = self; + if (!getPageTypes(self)) { + this._applicationShow(self); + } + } + + ready(self) { + this.self = self; + if (getPageTypes(self)) { + this._pageShow(self); + } + } + hide(self) { + this.self = self; + if (getPageTypes(self)) { + this._pageHide(self); + } else { + this._applicationHide(self, true); + } + } + error(em) { + 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 options = { + ak: this.statData.ak, + uuid: this.statData.uuid, + lt: '31', + ut: this.statData.ut, + ch: this.statData.ch, + mpsdk: this.statData.mpsdk, + mpv: this.statData.mpv, + v: this.statData.v, + em: emVal, + usv: this.statData.usv, + t: getTime(), + p: this.statData.p + }; + this.request(options); + } +} + +const stat = Stat.getInstance(); +let isHide = false; +const lifecycle = { + onLaunch(options) { + stat.report(options, this); + }, + onReady() { + stat.ready(this); + }, + onLoad(options) { + stat.load(options, this); + }, + onShow() { + isHide = false; + stat.show(this); + }, + onHide() { + isHide = true; + stat.hide(this); + }, + onUnload() { + if (isHide) { + isHide = false; + return + } + stat.hide(this); + }, + onError(e) { + stat.error(e); + }, + onShareAppMessage() { + stat.interceptShare(false); + } +}; + +function main() { + const Vue = require('vue'); + (Vue.default || Vue).mixin(lifecycle); + uni.report = function(type, options) { + stat.sendEvent(type, options); + }; +} + +main(); diff --git a/packages/uni-stat/src/config.js b/packages/uni-stat/src/config.js index b3204423c07b150bbea363689b4d704a824c1ebc..7c41028b56c497dd8b8aa4bcac49d288445bddac 100644 --- a/packages/uni-stat/src/config.js +++ b/packages/uni-stat/src/config.js @@ -1,6 +1,6 @@ import { version -} from '../package.json' +} from '@dcloudio/uni-stat/package.json' export const STAT_VERSION = version export const STAT_URL = 'https://tongji.dcloud.net.cn/uni/stat' export const STAT_H5_URL = 'https://tongji.dcloud.net.cn/uni/stat.gif' diff --git a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js index c4cbcc83bebaf6b300a88cb0eee8af5413f93259..dcb318baaaf06cca4cf09a06745b2716637034fd 100644 --- a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js +++ b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js @@ -210,7 +210,8 @@ module.exports = function (entry) { extensions: ['.js', '.nvue', '.vue', '.json'], alias: { '@': process.env.UNI_INPUT_DIR, - 'uni-pages': path.resolve(process.env.UNI_INPUT_DIR, 'pages.json'), + 'uni-pages': path.resolve(process.env.UNI_INPUT_DIR, 'pages.json'), + '@dcloudio/uni-stat': require.resolve('@dcloudio/uni-stat'), 'uni-stat-config': path.resolve(process.env.UNI_INPUT_DIR, 'pages.json') + '?' + JSON.stringify({ diff --git a/packages/vue-cli-plugin-hbuilderx/package.json b/packages/vue-cli-plugin-hbuilderx/package.json index a9d557dddcd0c1043e21c4a46617a25830446d6f..7009427ea71a5bd5cfc6ef7361b3446089be1483 100644 --- a/packages/vue-cli-plugin-hbuilderx/package.json +++ b/packages/vue-cli-plugin-hbuilderx/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/vue-cli-plugin-hbuilderx", - "version": "1.0.0-alpha-22120190814002", + "version": "1.0.135", "description": "HBuilderX plugin for vue-cli 3", "main": "index.js", "scripts": { diff --git a/packages/vue-cli-plugin-uni/generator.js b/packages/vue-cli-plugin-uni/generator.js index d2a4d24f94371b24eb1c04ef265abf1bb1879754..31b6ac3dec856e2734aefc7d6480a836c556a994 100644 --- a/packages/vue-cli-plugin-uni/generator.js +++ b/packages/vue-cli-plugin-uni/generator.js @@ -1,5 +1,5 @@ module.exports = (api, options, rootOptions) => { - let version = '^1.0.0-22220190816001' + let version = '*' if (require('./package.json').version.indexOf('alpha') !== -1) { version = '^1.0.0-alpha-22120190814001' } diff --git a/packages/vue-cli-plugin-uni/lib/configure-webpack.js b/packages/vue-cli-plugin-uni/lib/configure-webpack.js index 78889829f2c517f9bd1a4f0b9ff58ea327776af0..5ee3e4991a9bb38081f8688073973f4bb1d5625f 100644 --- a/packages/vue-cli-plugin-uni/lib/configure-webpack.js +++ b/packages/vue-cli-plugin-uni/lib/configure-webpack.js @@ -261,6 +261,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt '@': path.resolve(process.env.UNI_INPUT_DIR), 'vue$': getPlatformVue(), 'uni-pages': path.resolve(process.env.UNI_INPUT_DIR, 'pages.json'), + '@dcloudio/uni-stat': require.resolve('@dcloudio/uni-stat'), 'uni-stat-config': path.resolve(process.env.UNI_INPUT_DIR, 'pages.json') + '?' + JSON.stringify({ diff --git a/packages/vue-cli-plugin-uni/lib/env.js b/packages/vue-cli-plugin-uni/lib/env.js index c5231e6c30d152495f50517fa246e846b3bc460e..01af2beeedf9705f4d8dd6adaaa9615f9a2052f7 100644 --- a/packages/vue-cli-plugin-uni/lib/env.js +++ b/packages/vue-cli-plugin-uni/lib/env.js @@ -70,13 +70,13 @@ const uniStatistics = Object.assign( platformOptions.uniStatistics || {} ) -if (uniStatistics.enable === true) { +if (uniStatistics.enable !== false) { if (process.UNI_STAT_CONFIG.appid) { process.env.UNI_USING_STAT = true } else { - // console.log() - // console.warn(``) - // console.log() + console.log() + console.warn(`当前应用未配置Appid,无法使用uni统计,详情参考:https://ask.dcloud.net.cn/article/36303`) + console.log() } } @@ -154,13 +154,15 @@ if (platformOptions.usingComponents === true) { } } -if (process.env.UNI_USING_COMPONENTS && isSupportSubPackages()) { // 是否启用分包优化 - if ( - platformOptions.optimization && - platformOptions.optimization.subPackages && - Object.keys(process.UNI_SUBPACKAGES).length - ) { - process.env.UNI_OPT_SUBPACKAGES = true +if (process.env.UNI_USING_COMPONENTS) { // 是否启用分包优化 + if (platformOptions.optimization) { + if ( + isSupportSubPackages() && + platformOptions.optimization.subPackages && + Object.keys(process.UNI_SUBPACKAGES).length + ) { + process.env.UNI_OPT_SUBPACKAGES = true + } } } diff --git a/packages/vue-cli-plugin-uni/package.json b/packages/vue-cli-plugin-uni/package.json index 4f17631fae4abde77b00c9303b94010540c1bbe1..aef6b56248e53bc4f027df8153363a0371fb62ac 100644 --- a/packages/vue-cli-plugin-uni/package.json +++ b/packages/vue-cli-plugin-uni/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/vue-cli-plugin-uni", - "version": "1.0.0-alpha-22120190814002", + "version": "0.9.524", "description": "uni-app plugin for vue-cli 3", "main": "index.js", "scripts": {