tida
Version:
tida
1,410 lines (1,256 loc) • 49.5 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("tida", [], factory);
else if(typeof exports === 'object')
exports["tida"] = factory();
else
root["tida"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 3);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WV = WV;
__webpack_require__(4);
var _goldlog = __webpack_require__(5);
var _goldlog2 = _interopRequireDefault(_goldlog);
var _bat = __webpack_require__(1);
var Bat = _interopRequireWildcard(_bat);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
window.setBatSpm('tida-nrt-rop');
Bat.batTrack('windvane');
var pkg = __webpack_require__(2);
function WV(obj, method, params, success, failure, timeout) {
// 最后一个参数如果为number,则为超时时间
if (typeof arguments[arguments.length - 1] === 'number') {
timeout = arguments[arguments.length - 1];
}
if (typeof success !== 'function') {
success = null;
}
if (typeof failure !== 'function') {
failure = null;
}
return lib.windvane.call(obj, method, params, success, failure, timeout).then(function (res) {
// TODO此处做一些监控
return new Promise(function (resolve, reject) {
resolve(res);
});
}, function (res) {
// Bat.batTrack('windvane.fail','windvane', {
// msg: JSON.stringify(res), // 埋点附带信息
// module: 'tida/tida', // 当前代码仓库名称,若接入@ali/gulp-bat会自动补充无需填写
// type: 'error',
// version: pkg.version, // 当前代码仓库版本,若接入@ali/gulp-bat会自动补充无需填写
// });
// glog('/ighw.ihapi.error_record','EXP','apiname='+obj+'&methodname='+method+
// '&domain='+encodeURIComponent(window.location.href)+'&error='+JSON.stringify(res),'H1480571952');
return Promise.reject(res);
});
}
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
;
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
(function () {
if (typeof window.batTrack === 'function') return;
var SAMPLING_FILE = window.batSamplingFile || '';
var USE_POST = !!window.batUsePost;
var INTERVAL_AFTER_ONLOAD = window.batIntervalAfterOnload || 1500;
var PROXY = window.batProxy || '';
var SUPPORT_LOCALSTORAGE = false;
try {
localStorage.batLocalTest = 0;
if (localStorage.batLocalTest === '0') {
SUPPORT_LOCALSTORAGE = true;
localStorage.removeItem('batLocalTest');
}
} catch (e) {}
var URL_LIMIT = 1700;
var URL = window.location.host + window.location.pathname;
var URL_BASE = (window.location.protocol === 'file:' ? 'http:' : window.location.protocol) + '//gm.mmstat.com';
var EUC = encodeURIComponent;
var PAGE_START_TIME = +new Date();
var firstName = '';
var trackMap = {};
var DAY = 24 * 60 * 60 * 1000;
var gid = 0;
var IS_MOBILE = /(iPhone|iPad|iPod|iOS|Android)/i.test(window.navigator.userAgent);
var TOKEN = randStr(20);
var customSpm = '';
var samplingCallbacks = [];
var sampling = null;
var localCache = {};
initStore();
if (SAMPLING_FILE) {
var samplingNames = SAMPLING_FILE.split('/');
window[samplingNames[samplingNames.length - 1]] = function (response) {
sampling = response || null;
for (var i = 0; i < samplingCallbacks.length; i++) {
samplingCallbacks[i]();
}
delete window[samplingNames[samplingNames.length - 1]];
};
requestJSONP(SAMPLING_FILE + '?wh_callback=true');
}
window.setCtkSpm = window.setBatSpm = function (spmId) {
customSpm = spmId;
};
window.setCtkProxy = window.setBatProxy = function (proxy) {
PROXY = proxy;
};
function onPageload(callback) {
var run = function run() {
setTimeout(callback, 10);
};
if (window.__windvane__) {
if (window._WindVaneReady) {
callback();
} else {
var handle = function handle() {
window._WindVaneReady = true;
document.removeEventListener('WindVaneReady', handle);
callback();
};
document.addEventListener('WindVaneReady', handle);
}
} else {
if (document.readyState === 'complete') {
run();
} else {
window.addEventListener('load', run);
}
}
}
function batSender(name, parentName, config) {
if (typeof name !== 'string') return;
if ((typeof parentName === 'undefined' ? 'undefined' : _typeof(parentName)) === 'object') {
config = parentName;
parentName = 'bat';
}
parentName = name === 'bat' ? '' : parentName || 'bat';
config = config || {};
config.module = config.module || '';
config.type = config.type || 'normal';
config.msg = config.msg || '';
config.version = config.version || '';
if (!firstName) firstName = name;
var now = +new Date();
trackMap[name] = now;
var t = name === firstName ? 0 : now - (trackMap[parentName || firstName] || trackMap[firstName]);
if (config.type === 'error') {
this.pushFull([name + '_' + config.module, name, parentName, config.module, config.version, config.msg, Math.max(t, 0), 1]);
} else {
this.push([name + '_' + config.module, name, parentName, config.module, config.version, config.msg, Math.max(t, 0), 0]);
}
}
function mergeObj(obj1, obj2) {
var obj3 = {};
for (var attrname in obj1) {
obj3[attrname] = obj1[attrname];
}
for (var attrname in obj2) {
obj3[attrname] = obj2[attrname];
}
return obj3;
}
function randStr(length, current) {
current = current ? current : '';
return length ? randStr(--length, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.charAt(Math.floor(Math.random() * 60)) + current) : current;
}
function replaceAll(string, search, replacement) {
return string.split(search).join(replacement);
}
function forOwn(obj, cb) {
for (var key in obj) {
obj.hasOwnProperty(key) && cb.call(obj, obj[key], key);
}
}
function getSpm() {
if (customSpm) return customSpm;
var pageSpm = '';
var bodySpm = '';
if (window.goldlog && window.goldlog.spm_ab) {
pageSpm = window.goldlog.spm_ab.join('.').split('/')[0];
pageSpm = pageSpm.split('-')[0];
return pageSpm;
}
pageSpm = document.getElementsByTagName('meta');
for (var i = pageSpm.length; i--;) {
if (pageSpm[i].name === 'spm-id' || pageSpm[i].name === 'data-spm') break;
}if (!(pageSpm = pageSpm[i])) return;
pageSpm = pageSpm.content.split('/')[0];
pageSpm = pageSpm.split('-')[0];
if (!pageSpm) return '';
bodySpm = document.body && document.body.getAttribute('data-spm');
bodySpm = bodySpm ? '.' + bodySpm : '';
return pageSpm + bodySpm;
}
function convertToString(data) {
var rst = [];
var i;
var m;
var item;
for (i = 0, m = data.length; i < m; i++) {
item = data[i];
if ((typeof item === 'undefined' ? 'undefined' : _typeof(item)) === 'object') rst.push(JSON.stringify(item));else if (item === null || item === undefined) rst.push('');else rst.push(item + '');
}
for (i = rst.length; i--;) {
rst[i] = replaceAll(replaceAll(rst[i], '|', '丨'), ';', ';');
}return rst;
}
function signed_crc_table() {
var c = 0;
var table = new Array(256);
for (var n = 0; n !== 256; ++n) {
c = n;
for (var i = 8; i--;) {
c = c & 1 ? -306674912 ^ c >>> 1 : c >>> 1;
}table[n] = c;
}
return typeof Int32Array !== 'undefined' ? new Int32Array(table) : table;
}
var T = signed_crc_table();
function hash(str) {
var C = -1;
for (var i = 0, L = str.length, c, d; i < L;) {
c = str.charCodeAt(i++);
if (c < 0x80) {
C = C >>> 8 ^ T[(C ^ c) & 0xFF];
} else if (c < 0x800) {
C = C >>> 8 ^ T[(C ^ (192 | c >> 6 & 31)) & 0xFF];
C = C >>> 8 ^ T[(C ^ (128 | c & 63)) & 0xFF];
} else if (c >= 0xD800 && c < 0xE000) {
c = (c & 1023) + 64;
d = str.charCodeAt(i++) & 1023;
C = C >>> 8 ^ T[(C ^ (240 | c >> 8 & 7)) & 0xFF];
C = C >>> 8 ^ T[(C ^ (128 | c >> 2 & 63)) & 0xFF];
C = C >>> 8 ^ T[(C ^ (128 | d >> 6 & 15 | (c & 3) << 4)) & 0xFF];
C = C >>> 8 ^ T[(C ^ (128 | d & 63)) & 0xFF];
} else {
C = C >>> 8 ^ T[(C ^ (224 | c >> 12 & 15)) & 0xFF];
C = C >>> 8 ^ T[(C ^ (128 | c >> 6 & 63)) & 0xFF];
C = C >>> 8 ^ T[(C ^ (128 | c & 63)) & 0xFF];
}
}
return C ^ -1;
}
function initStore() {
try {
if (!SUPPORT_LOCALSTORAGE) return [];
localCache = window.localStorage.getItem('bat');
localCache = localCache ? JSON.parse(localCache) : {};
var urls = [];
forOwn(localCache, function (value, url) {
if (PAGE_START_TIME - value.time > DAY) {
urls.push(url);
}
});
for (var i = urls.length; i--;) {
delete localCache[urls[i]];
}
window.localStorage.setItem('bat', JSON.stringify(localCache));
} catch (e) {
// console.log('ctk:localStorage写入失败');
localCache = {};
}
}
function getStore(name) {
var urlCache = localCache[URL] || {};
return urlCache[name] || [];
}
function setStore(name, value) {
try {
if (!SUPPORT_LOCALSTORAGE) return [];
var urlCache = localCache[URL] = localCache[URL] || {};
urlCache[name] = value;
urlCache.time = +new Date();
window.localStorage.setItem('bat', JSON.stringify(localCache));
} catch (e) {
// console.log('ctk:localStorage写入失败');
}
}
function requestJSONP(url) {
var script = document.createElement('script');
script.src = url;
script.onload = function () {
this.remove();
};
var head = document.getElementsByTagName('head')[0];
head.appendChild(script);
}
function Bat(config) {
var that = this;
this.version = '4.2.0';
this.api = config.api || '';
this.chksum = config.chksum || '';
this.name = config.name || 'none';
this.sender = config.sender || function () {};
this.windowOnloaded = false;
this.queueName = config.name + '_queue';
this.fullQueueName = config.name + '_full_queue';
this.sendingTask = null;
this.extra = {};
this.onloadFns = [];
this.unloadFns = [];
this.bindEvent();
this.setQueue(window[this.queueName] || []);
try {
this.setFullQueue([].concat(getStore(this.fullQueueName)).concat(window[this.fullQueueName] || []));
} catch (e) {
this.setFullQueue([].concat(window[this.fullQueueName] || []));
}
window[config.name + 'Track'] = function () {
that.sender.apply(that, Array.prototype.slice.call(arguments));
};
window[config.name + 'TrackIme'] = function () {
that.sender.apply(that, Array.prototype.slice.call(arguments));
if (that.sendingTask) clearTimeout(that.sendingTask);
that.sendQueue();
};
}
Bat.prototype.mergeExtra = function (extra) {
extra = extra || {};
this.extra = mergeObj(this.extra, extra);
};
Bat.prototype.replaceExtra = function (extra) {
extra = extra || {};
this.extra = mergeObj(extra, {});
};
Bat.prototype.push = function (data) {
this.queue.push(data);
};
Bat.prototype.pushFull = function (data) {
this.fullQueue.push(data);
};
Bat.prototype.setQueue = function (queue) {
window[this.queueName] = this.queue = queue;
};
Bat.prototype.setFullQueue = function (fullQueue, local) {
window[this.fullQueueName] = this.fullQueue = fullQueue;
local && setStore(this.fullQueueName, fullQueue);
};
Bat.prototype.addOnloadListener = function (fn) {
this.onloadFns.push(fn);
};
Bat.prototype.removeOnloadListener = function (fn) {
var idx = this.onloadFns.indexOf(fn);
if (idx !== -1) {
this.onloadFns.splice(idx, 1);
}
};
Bat.prototype.addUnloadListener = function (fn) {
this.unloadFns.push(fn);
};
Bat.prototype.removeUnloadListener = function (fn) {
var idx = this.unloadFns.indexOf(fn);
if (idx !== -1) {
this.unloadFns.splice(idx, 1);
}
};
Bat.prototype.bindEvent = function () {
var that = this;
var i;
function windowOnload() {
var i, m, fn;
for (i = 0, m = that.onloadFns.length; i < m; i++) {
fn = that.onloadFns[i];
fn();
}
that.onloadFns = [];
that.windowOnloaded = true;
setTimeout(function () {
that.waitSendStart();
}, INTERVAL_AFTER_ONLOAD);
}
function windowUnload() {
var i, m, fn;
for (i = 0, m = that.unloadFns.length; i < m; i++) {
fn = that.unloadFns[i];
fn();
}
that.unloadFns = [];
that.sendQueue();
}
onPageload(windowOnload);
if (window.addEventListener) {
var windowEvents = ['blur', 'beforeunload', 'unload'];
for (i = windowEvents.length; i--;) {
window.addEventListener(windowEvents[i], windowUnload);
}
var events = ['WV.Event.APP.Background', 'pause', 'mozvisibilitychange', 'msvisibilitychange', 'visibilitychange', 'webkitvisibilitychange'];
for (i = events.length; i--;) {
document.addEventListener(events[i], windowUnload);
}
} else if (window.attachEvent) {
window.attachEvent('onload', windowOnload);
window.attachEvent('onbeforeunload', windowUnload);
}
};
Bat.prototype.sendStart = function () {
var that = this;
if (that.sendingTask) return;
that.sendingTask = setTimeout(function () {
that.sendQueue();
that.sendingTask = null;
if (that.queue.length > 0 || that.fullQueue.length > 0) {
that.waitSendStart();
}
}, INTERVAL_AFTER_ONLOAD);
};
Bat.prototype.waitSendStart = function () {
var that = this;
if (SAMPLING_FILE && !sampling) {
samplingCallbacks.push(function () {
that.sendStart();
});
} else {
that.sendStart();
}
};
Bat.prototype.sendQueue = function () {
this.setQueue(this.formatQueue(this.queue));
this.setFullQueue(this.formatQueue(this.fullQueue));
this.sendNormalQueue();
this.sendFullQueue();
};
Bat.prototype.formatQueue = function (queue) {
var rst = [];
for (var i = 0, m = queue.length; i < m; i++) {
var item = queue[i];
if (Object.prototype.toString.call(item).toLowerCase() === '[object array]') {
rst.push({ length: 1, point: item });
} else {
rst.push(item);
}
}
return rst;
};
Bat.prototype.mergeQueue = function (queue) {
var rst = [];
var i;
var m;
var tmp = {};
var key;
var item;
for (i = 0, m = queue.length; i < m; i++) {
item = queue[i];
try {
key = item.point[0];
tmp[key] = tmp[key] || {
point: null,
length: 0
};
tmp[key].length += item.length;
if (Math.random() * tmp[key].length <= item.length) {
tmp[key].point = item.point;
}
} catch (e) {
continue;
}
}
forOwn(tmp, function (data) {
rst.push(data);
});
return rst;
};
Bat.prototype.sendNormalQueue = function () {
var queue = [];
var i;
var candidate = [];
var candidateLength = 0;
queue = this.mergeQueue(this.queue);
queue.sort(function () {
return Math.random() - 0.5;
});
for (i = queue.length; i--;) {
try {
var strLength = EUC(convertToString([].concat(queue[i].point.slice(1)).concat([1000])).join('|')).length;
if (candidateLength + strLength > URL_LIMIT) break;
if (SAMPLING_FILE) {
var ratio = sampling && sampling.normal && sampling.normal[queue[i].point[0]] || 1;
if (Math.random() < 1 / ratio) {
queue[i].length = queue[i].length * ratio;
candidate.push(queue[i]);
candidateLength += strLength;
}
} else {
candidate.push(queue[i]);
candidateLength += strLength;
}
} catch (e) {
continue;
}
}
for (i = candidate.length; i--;) {
candidate[i] = convertToString([].concat(candidate[i].point.slice(1)).concat([candidate[i].length * Math.round(queue.length / candidate.length)])).join('|');
}this.send(candidate.join(';'));
this.setQueue([]);
};
Bat.prototype.sendFullQueue = function () {
var queue = [];
var i;
var candidate = [];
var candidateLength = 0;
queue = [].concat(this.fullQueue);
if (!queue.length) return;
while (queue.length) {
try {
var head = queue[0];
var strLength = EUC(convertToString([].concat(head.point.slice(1)).concat([head.length])).join('|')).length;
if (strLength > URL_LIMIT && !USE_POST) {
queue.shift();
continue;
}
if (candidateLength + strLength > URL_LIMIT && !USE_POST) break;
if (SAMPLING_FILE) {
var ratio = sampling && sampling.full && sampling.full[queue[0].point[0]] || 1;
if (Math.random() < 1 / ratio) {
queue[0].length = queue[0].length * ratio;
candidate.push(queue.shift());
candidateLength += strLength;
} else {
queue.shift();
}
} else {
candidate.push(queue.shift());
candidateLength += strLength;
}
} catch (e) {
queue.shift();
continue;
}
}
for (i = candidate.length; i--;) {
candidate[i] = convertToString([].concat(candidate[i].point.slice(1)).concat([candidate[i].length])).join('|');
}this.send(candidate.join(';'));
this.setFullQueue(queue, true);
};
Bat.prototype.send = function (data) {
if (!data) return;
var spm = getSpm();
if (!spm) return;
var dataQueue = ['msg=' + EUC(data), 'hash=' + hash(data), 'spm=' + spm, 'client=' + (IS_MOBILE ? 'h5' : 'pc'), 'token=' + TOKEN, 'proxy=' + PROXY];
for (var key in this.extra) {
this.extra.hasOwnProperty(key) && dataQueue.push(key + '=' + this.extra[key]);
}
var dataStr = dataQueue.join('&');
if (window.goldlog && window.goldlog.record && typeof window.goldlog.record === 'function') {
window.goldlog.record(this.api, 'EXP', dataStr, USE_POST ? 'POST' : 'GET');
} else {
var key = '__CT_image_' + gid++;
var img = window[key] = new Image();
img.onload = img.onerror = function () {
window[key] = null;
};
img.src = URL_BASE + this.api + '?' + dataStr;
}
};
var batIns = new Bat({ name: 'bat', sender: batSender, api: '/codetrack.1.1', chksum: 'H46836965' });
var tesIns = new Bat({
name: 'tes',
sender: function sender(key, args, full) {
args = args || [];
full = full || false;
if (!key) return;
if (full) {
this.pushFull([].concat([key]).concat(args));
} else {
this.push([].concat([key]).concat(args));
}
},
api: '/codetrack.1.3',
chksum: 'H46836988'
});
var domIns = new Bat({
name: 'dom',
sender: function sender(name, parent, module, version, full) {
parent = parent || '';
module = module || '';
version = version || '';
full = full || false;
var args = [name + '_' + parent + '_' + module + '_' + version, name, parent, module, version];
if (full) {
this.pushFull(args);
} else {
this.push(args);
}
},
api: '/codetrack.1.4',
chksum: 'H46836989'
});
function trim(val) {
return val.replace(/^\s+|\s+$/g, '');
}
function getLines(stack) {
stack = stack || '';
stack = stack.split('\n').slice(1, 3);
for (var i = stack.length; i--;) {
stack[i] = trim(stack[i]).replace(/\((.*)\)/, function (match, part) {
part = part.split(':');
return '(' + [Number(part[2]) || 0, Number(part[3]) || 0].join(':') + ')';
});
}
return stack.join('^');
}
function getShortUrl(url) {
url = url || '';
var parts = url.split(',');
if (parts.length <= 2) return url;
return [parts[0], '...', parts[parts.length - 1]].join(',');
}
function errorHandler(e, url, lineNo, columnNo, error) {
try {
if (typeof e === 'string') {
window.batTrack('jserror', 'bat', {
type: 'error',
msg: [e, getShortUrl(url), lineNo, columnNo, getLines(error && error.stack)].join('^')
});
} else {
window.batTrack('jserror', 'bat', {
type: 'error',
msg: [e.message, getShortUrl(e && e.filename), e && e.lineno, e && e.colno, getLines(e && e.error && e.error.stack)].join('^')
});
}
} catch (e) {
// console.log
}
}
if (window.addEventListener) {
window.addEventListener('error', errorHandler, false);
} else {
window.attachEvent('error', errorHandler);
}
window.batTrack('bat', '');
window.batIns = {
bat: batIns,
tes: tesIns,
dom: domIns
};
})();
(function (root, factory) {
if (true) {
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function () {
return root.bat = factory();
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
} else if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object' && module.exports) {
module.exports = factory();
} else {
root.bat = factory();
}
})(window, function () {
return {
domTrack: window.domTrack,
batTrack: window.batTrack,
tesTrack: window.tesTrack,
domTrackIme: window.domTrackIme,
batTrackIme: window.batTrackIme,
tesTrackIme: window.tesTrackIme,
setBatSpm: window.setBatSpm,
setBatProxy: window.setBatProxy
};
});
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = {"name":"tida","version":"1.0.1-alpha.13","description":"tida","main":"index.js","directories":{"example":"demo"},"scripts":{"build":"node scripts/build","watch":"node scripts/build -w","demo":"cd demo; tnpm i; cd ..; open http://127.0.0.1:3000/demo/public/; node scripts/demo","nginx":"sudo nginx -t -c ${PWD}/scripts/nginx.conf"},"publishConfig":{"registry":"http://registry.npm.alibaba-inc.com"},"repository":{"type":"git","url":"git@gitlab.alibaba-inc.com:tida/tida.git"},"keywords":["tida","rax","tmall","taobao"],"author":"chongyang.liucy <chongyang.liucy@alibaba-inc.com>","devDependencies":{"babel-core":"^6.26.0","babel-loader":"^7.1.2","babel-preset-es2015":"^6.24.1","babel-preset-rax":"^0.4.11","case-sensitive-paths-webpack-plugin":"^2.1.1","eslint":"^4.6.1","eslint-plugin-babel":"^4.1.2","eslint-plugin-react":"^7.3.0","gutil":"^1.6.4","image-source-loader":"^0.4.11","json-loader":"^0.5.7","rax-webpack-plugin":"^0.4.11","stylesheet-loader":"^0.4.11","uglifyjs-webpack-plugin":"^0.4.6","watch-missing-node-modules-webpack-plugin":"^0.0.1","webpack":"^3.5.5","webpack-dev-server":"^2.7.1"},"license":"ISC","dependencies":{"@ali/bat":"^5.0.3","@ali/lib-windvane":"^3.0.0","@ali/goldlog":"1.0.0-alpha.1","babel-plugin-import":"^1.8.0","babel-preset-env":"^1.7.0","universal-env":"^0.4.11","universal-jsonp":"^0.4.12","universal-toast":"^0.4.12"}}
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
;
var _windvane = __webpack_require__(0);
var _mtop = __webpack_require__(6);
var _error = __webpack_require__(7);
var _error2 = _interopRequireDefault(_error);
var _fns = __webpack_require__(8);
var _fns2 = _interopRequireDefault(_fns);
var _bat = __webpack_require__(1);
var Bat = _interopRequireWildcard(_bat);
var _utils = __webpack_require__(9);
var _utils2 = _interopRequireDefault(_utils);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
// import glog from '../common/aplus';
var pkg = __webpack_require__(2);
var ROP = {
/**
* rop.call
* @param {string} className classname
* @param {string} method method
* @param {string} data data
* @param {function} successCallback success callback
* @param {function} failCallback fail callback
* @param {Number} timeout timeout
*/
call: function call(apiname, data, successCallback, failCallback, t) {
// 01、判断是否是已存在的业务逻辑,如果为业务注册的插件,则直接走业务插件
// try {
// // 如果发现已存在以apiname为命名的function,则直接调用
// if(typeof(eval(apiname)) == "function") {
// return eval(apiname+"(data, successCallback, failCallback, t)");
// }
// } catch (e) {
// // TODO 异常处理
// }
var _faillCallback = null;
// 02、通过显示注册组件,判断组件是否存在的方式决定是否走插件逻辑
if (_fns2.default.hasOwnProperty(apiname) && typeof _fns2.default[apiname] == "function") {
var _argu = [].concat(Array.prototype.slice.call(arguments));
_argu.shift(); //删除apiname
//TODO打点,做非阻塞处理
// glog('/ighw.ihapi.api_fn_call','CLK','apiname='+apiname+'&domain='+encodeURIComponent(window.location.href),'GET');
return _fns2.default[apiname].apply(_fns2.default, _toConsumableArray(_argu));
}
// 最后一个参数为number的话,即为超时时间
var timeout = _utils2.default.getTimout([].concat(Array.prototype.slice.call(arguments)));
// 判断是否是Promise调用
if (typeof successCallback !== 'function') {
successCallback = null;
}
if (typeof failCallback !== 'function') {
failCallback = null;
_faillCallback = null;
}
// 判断是否是MTOP请求
var isMtop = apiname.indexOf("alibaba") != -1 || apiname.indexOf("mtop") != -1;
// 参数拆分,如拆分:TOpenDevice.onModuleStateChanged
// TODO MTOP 需要判断mtop前缀
var method = apiname.split(".")[1];
var className = apiname.split(".")[0];
//TODO打点,做非阻塞处理
// glog('/ighw.ihapi.api_record','CLK','apiname='+className+'&methodname='+method+'&domain='+
// encodeURIComponent(window.location.href),'H1478724910');
// 重构失败回调
if (failCallback) {
_faillCallback = function _faillCallback(res) {
failCallback && failCallback(res);
// glog('/ighw.ihapi.error_record','EXP','apiname='+className+'&methodname='+method+
// '&domain='+encodeURIComponent(window.location.href)+'&error='+JSON.stringify(res),'H1480571952');
// Bat.batTrack('windvane.fail','windvane', {
// msg: 'apiname='+className+'&methodname='+method+'&domain='+encodeURIComponent(window.location.href)+'&error='+JSON.stringify(res), // 埋点附带信息
// module: 'tida/tida', // 当前代码仓库名称,若接入@ali/gulp-bat会自动补充无需填写
// type: 'error',
// version: pkg.version, // 当前代码仓库版本,若接入@ali/gulp-bat会自动补充无需填写
// });
};
}
// 判断是否是Mtop调用
if (isMtop) {
(0, _mtop.Mtop)({
mtopApi: apiname,
businessParam: data
}, function (e) {
successCallback && successCallback(e);
}, function (e) {
_faillCallback && _faillCallback(e);
}, timeout);
} else {
return (0, _windvane.WV)(className, method, data, successCallback, _faillCallback, timeout);
}
},
version: function version() {
return pkg.version;
}
};
var FN = {
/**
* rop.register
* @param {string} apiname apiname
* @param {funciton} function function
*/
register: function register(apiname, func) {
// 如果注册过,则return false
// TODO 判断是否需要加不可重复注册逻辑
// if (this.fn.hasOwnProperty(apiname)) {
// // Duplicate
// throw new IHError("function "+ apiname +" has been registered, please unregister it firstly.", "reg01", "RegisterError");
// };
// glog('/ighw.ihapi.api_register','CLK','domain='+encodeURIComponent(window.location.href)+'&apiname='+apiname,'GET');
_fns2.default[apiname] = func;
return true;
},
call: function call(cls, method, options, succ, fail, timeout) {
return ROP.call(cls + "." + method, options, succ, fail, timeout);
}
};
window.Tida = window.Tida ? window.Tida : {};
window.Tida.rop = ROP;
module.exports = FN;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
typeof window === 'undefined' && (window = { ctrl: {}, lib: {} });!window.ctrl && (window.ctrl = {});!window.lib && (window.lib = {});!function (a, b) {
function c(a, b) {
a = a.toString().split("."), b = b.toString().split(".");for (var c = 0; c < a.length || c < b.length; c++) {
var d = parseInt(a[c], 10),
e = parseInt(b[c], 10);if (window.isNaN(d) && (d = 0), window.isNaN(e) && (e = 0), e > d) return -1;if (d > e) return 1;
}return 0;
}var d = a.Promise,
e = a.document,
f = a.navigator.userAgent,
g = /Windows\sPhone\s(?:OS\s)?[\d\.]+/i.test(f) || /Windows\sNT\s[\d\.]+/i.test(f),
h = g && a.WindVane_Win_Private && a.WindVane_Win_Private.call,
i = /iPhone|iPad|iPod/i.test(f),
j = /Android/i.test(f),
k = f.match(/WindVane[\/\s](\d+[._]\d+[._]\d+)/),
l = Object.prototype.hasOwnProperty,
m = b.windvane = a.WindVane || (a.WindVane = {}),
n = Math.floor(65536 * Math.random()),
o = 1,
p = [],
q = 3,
r = "hybrid",
s = "wv_hybrid",
t = "iframe_",
u = "param_",
v = 6e5,
w = 6e4;k = k ? (k[1] || "0.0.0").replace(/\_/g, ".") : "0.0.0";var x = { isAvailable: 1 === c(k, "0"), isNewBridgeAvailable: 1 === c(k, "8.2.0"), call2: function call2(a, b, c, d, e) {
var f = a.indexOf(".");return x.call(a.substr(0, f), a.substr(f + 1), b, c, d, e);
}, call: function call(b, c, e, f, g, h) {
var i, j;if ("number" == typeof arguments[arguments.length - 1] && (h = arguments[arguments.length - 1]), "function" != typeof f && (f = null), "function" != typeof g && (g = null), !d || f || g || (j = new d(function (a, b) {
f = a, g = b;
})), x.isNewBridgeAvailable && a.__windvane__ && a.__windvane__.call) return a.__windvane__.call(b + "." + c, e, f, g, h), j;i = y.getSid();var k = { success: f, failure: g };return h > 0 && (k.timeout = setTimeout(function () {
x.onFailure(i, { ret: "HY_TIMEOUT" });
}, h)), y.registerCall(i, k), y.registerGC(i, h), x.isAvailable ? y.callMethod(b, c, e, i) : x.onFailure(i, { ret: "HY_NOT_IN_WINDVANE" }), j;
}, fireEvent: function fireEvent(a, b, c) {
var d = e.createEvent("HTMLEvents");d.initEvent(a, !1, !0), d.param = y.parseData(b), e.dispatchEvent(d);
}, getParam: function getParam(a) {
return y.getParam(a);
}, setData: function setData(a, b) {}, find: function find(a, b) {
b || y.unregisterCall(a, !1);
}, onSuccess: function onSuccess(a, b, c) {
y.onComplete(a, b, "success", c);
}, onFailure: function onFailure(a, b) {
y.onComplete(a, b, "failure");
} };x.isNewBridgeAvailable && a.__windvane__ && a.__windvane__.callSync && (x.callSync = function (b, c) {
if (i) return a.__windvane__.callSync(b, c);if (j) {
var d = { name: b };c && (d.params = JSON.stringify(c));var e = a.__windvane__.callSync(d);if (e) try {
return JSON.parse(e);
} catch (f) {}
}
});var y = { params: {}, calls: {}, getSid: function getSid() {
return (n + o++) % 65536 + "";
}, buildParam: function buildParam(a) {
return a && "object" == (typeof a === "undefined" ? "undefined" : _typeof(a)) ? JSON.stringify(a) : a || "";
}, getParam: function getParam(a) {
return this.params[u + a] || "";
}, setParam: function setParam(a, b) {
this.params[u + a] = b;
}, parseData: function parseData(a) {
var b;if (a && "string" == typeof a) try {
b = JSON.parse(a);
} catch (c) {
b = { ret: "HY_RESULT_PARSE_ERROR", originValue: a };
} else b = a || {};return b;
}, registerCall: function registerCall(a, b) {
this.calls[a] = b;
}, unregisterCall: function unregisterCall(a, b) {
var c = this.calls[a] || {},
d = c.timeout;return d && clearTimeout(d), b || delete this.calls[a], c;
}, useIframe: function useIframe(a, b) {
var c = t + a,
d = p.pop();d || (d = e.createElement("iframe"), d.setAttribute("frameborder", "0"), d.style.cssText = "width:0;height:0;border:0;display:none;"), d.setAttribute("id", c), d.setAttribute("src", b), d.parentNode || setTimeout(function () {
e.body.appendChild(d);
}, 5);
}, retrieveIframe: function retrieveIframe(a) {
var b = t + a,
c = e.querySelector("#" + b);if (c) if (p.length >= q) try {
e.body.removeChild(c);
} catch (d) {} else p.indexOf(c) < 0 && p.push(c);
}, callMethod: function callMethod(b, c, d, e) {
if (d = y.buildParam(d), g) h ? a.WindVane_Win_Private.call(b, c, e, d) : this.onComplete(e, { ret: "HY_NO_HANDLER_ON_WP" }, "failure");else if (i) {
this.setParam(e, d);var f = r + "://" + b + ":" + e + "/" + c + "?" + encodeURIComponent(d);this.useIframe(e, f);
} else if (j) {
var f = r + "://" + b + ":" + e + "/" + c + "?" + d,
k = s + ":";window.prompt(f, k);
} else this.onComplete(e, { ret: "HY_NOT_SUPPORT_DEVICE" }, "failure");
}, registerGC: function registerGC(a, b) {
var c = this,
d = Math.max(b || 0, v),
e = Math.max(b || 0, w);setTimeout(function () {
c.unregisterCall(a);
}, d), i && setTimeout(function () {
c.params[u + a] && delete c.params[u + a];
}, e);
}, onComplete: function onComplete(a, b, c, d) {
var e = this.unregisterCall(a, d),
f = e.success,
g = e.failure;b = this.parseData(b);var h = b.ret;"string" == typeof h && (b = b.value || b, b.ret || (b.ret = [h])), "success" === c ? f && f(b) : "failure" === c && g && g(b), i && (this.retrieveIframe(a), this.params[u + a] && delete this.params[u + a]);
} };for (var z in x) {
l.call(m, z) || (m[z] = x[z]);
}
}(window, window.lib || (window.lib = {}));;module.exports = window.lib['windvane'];
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
;
/******/(function (modules) {
// webpackBootstrap
/******/ // The module cache
/******/var installedModules = {};
/******/
/******/ // The require function
/******/function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/if (installedModules[moduleId]) {
/******/return installedModules[moduleId].exports;
/******/
}
/******/ // Create a new module (and put it into the cache)
/******/var module = installedModules[moduleId] = {
/******/i: moduleId,
/******/l: false,
/******/exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/module.l = true;
/******/
/******/ // Return the exports of the module
/******/return module.exports;
/******/
}
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/__webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/__webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/__webpack_require__.d = function (exports, name, getter) {
/******/if (!__webpack_require__.o(exports, name)) {
/******/Object.defineProperty(exports, name, {
/******/configurable: false,
/******/enumerable: true,
/******/get: getter
/******/ });
/******/
}
/******/
};
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/__webpack_require__.n = function (module) {
/******/var getter = module && module.__esModule ?
/******/function getDefault() {
return module['default'];
} :
/******/function getModuleExports() {
return module;
};
/******/__webpack_require__.d(getter, 'a', getter);
/******/return getter;
/******/
};
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/__webpack_require__.o = function (object, property) {
return Object.prototype.hasOwnProperty.call(object, property);
};
/******/
/******/ // __webpack_public_path__
/******/__webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/return __webpack_require__(__webpack_require__.s = 0);
/******/
})(
/************************************************************************/
/******/[
/* 0 */
/***/function (module, exports) {
;(function () {
var aplus_script = document.createElement("script");
aplus_script.setAttribute("exparams", "aplus&sidx=aplusSidex");
aplus_script.setAttribute("id", "beacon-aplus");
aplus_script.setAttribute("src", (window.location > "https" ? "//g" : "//g") + ".alicdn.com/alilog/mlog/aplus_wap.js");
var doc = window.document;
var body = doc.body;
body.insertBefore(aplus_script, body.firstChild);
})();
function glog(logkey, gmkey, gokey, req_method) {
if (window.goldlog && window.goldlog.record) {
window.goldlog.record(logkey, gmkey, gokey, req_method);
} else {
var q = window.goldlog_queue || (window.goldlog_queue = []);
q.push({
action: 'goldlog.record',
arguments: [logkey, gmkey, gokey, gokey]
});
}
};
module.exports = { glog: glog };
/***/
}]
/******/);
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Mtop = Mtop;
var _windvane = __webpack_require__(0);
function Mtop(mtopParams, success, failure, timeout) {
if (failure && typeof failure == 'number') {
//兼容旧版本的api...
timeout = failure;
failure = null;
}
var businessParam = mtopParams.businessParam;
if (!businessParam.appKey) {
businessParam.appKey = mtopParams.appKey;
}
//windvnae 入参
var p = {
apiName: "Tida.server",
methodName: "getMtop",
isAsync: true,
eventName: mtopParams.eventName,
methodParam: {
mtopApi: mtopParams.mtopApi,
mtopParam: {
ua: "",
version: "1.0",
needLogin: true,
isSec: 1,
businessParam: businessParam,
appKey: mtopParams.appKey
}
},
appKey: mtopParams.appKey
};
lib.windvane.call('wopc', 'mtop', {
v: '1.0',
post: 'true',
ecode: '1',
isSec: 'true',
api: p.methodParam.mtopApi,
param: p.methodParam.mtopParam.businessParam,
appKey: p.appKey,
appkey: p.appKey
}, function (e) {
success && success(e);
}, function (e) {
failure && failure(e);
}, timeout);
}
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", {
value: true
});
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var IHError = function (_Error) {
_inherits(IHError, _Error);
function IHError(message, code) {
var name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'IHError';
_classCallCheck(this, IHError);
var _this = _possibleConstructorReturn(this, (IHError.__proto__ || Object.getPrototypeOf(IHError)).call(this, message));
if (message instanceof Error) {
_this.originalError = message;
message = message.message;
} else {
_this.originalError = new Error(message);
_this.originalError.stack = _this.stack;
}
_this.name = name;
_this.message = message;
_this.code = code;
return _this;
}
return IHError;
}(Error);
exports.default = IHError;
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
;
module.exports = {};
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
;
var _error = __webpack_require__(10);
var _error2 = _interopRequireDefault(_error);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var utils = {
/**
* @description 获取指定参数值
* @name getParam
* @memberOf Tida
* @function
* @param {String} key 参数名
* @param {String} url 地址
*/
getParam: function getParam(key, url) {
var paraStr = key;
url = url || location.href;
if (url.indexOf(paraStr + '=') == -1) {
return '';
}
url = url.split('#')[0];
var queryString = url.indexOf('?') > -1 ? url.substring(url.indexOf('?') + 1) : url;
var parameters = queryString.split('&');
var pos, paraName, paraValue;
for (var i = 0; i < parameters.length; i++) {
pos = parameters[i].indexOf('=');
if (pos == -1) {
continue;
}
paraName = parameters[i].substring(0, pos);
paraValue = parameters[i].substring(pos + 1);
if (paraName == paraStr) {
return decodeURIComponent(paraValue.replace(/\+/g, ' '));
}
}
return '';
},
addParama: function addParama(url, key, val) {
var search = url.split("?")[1];
var pathname = url.split("?")[0];
if (search) {
var search_arr = search.split('&');
var url_arr = [];
var exists = 0;
for (var i = 0; i < search_arr.length; i++) {
if (!search_arr[i]) continue;
var temp = search_arr[i].split('=');
if (key == temp[0]) {
exists = 1;
url_arr.push(key + '=' + val);
} else {
if (temp[0] != 'page' && temp[0] != 'token') {
url_arr.push(search_arr[i]);
}
}
}
if (!exists) url_arr.push(key + '=' + val);
url = pathname + '?' + url_arr.join('&');
} else {
url = pathname + '?' + key + '=' + val;
}
return url;
},
requiredParam: function requiredParam(options, required) {
function inRequired(item) {
return !Object.keys(options).includes(item);
}
var except = required.filter(inRequired);
if (except.length > 0) {
throw new _error2.default.paramException(except);
} else {
return except.length == 0;
}
},
getTimout: function getTimout(arg) {
if (arg[arg.length - 1] != undefined) {
return arg[arg.length - 1];
} else {
arg.pop();
return this.getTimout(arg);
}
}
};
module.exports = utils;
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
;
module.exports = {
paramException: function paramException(value) {
this.message = "param '" + value.join(", ") + "' should be required!";
this.name = "paramException";
}
};
/***/ })
/******/ ]);
});