Skip to content

Instantly share code, notes, and snippets.

@temberature
Created May 28, 2018 03:36
Show Gist options
  • Save temberature/1dd973b7589285e653e4fa42132205ad to your computer and use it in GitHub Desktop.
Save temberature/1dd973b7589285e653e4fa42132205ad to your computer and use it in GitHub Desktop.
require(['jquery', 'core', 'pj.appcore'], function($, Core, AppCore) {
'use strict';
var aop = {
before: function(fn, beforeFn) {
return function () {
beforeFn.apply(this, arguments);
fn.apply(this, arguments);
}
},
check: function(fn, beforeFn) {
return function () {
if (beforeFn.apply(this, arguments)) {
fn.apply(this, arguments);
}
}
}
};
var GAStat = {
report: function (e) {
var actionInfo = $(e.target).data('onclick');
var $mountNode = $(e.target).parents('[class^=m-]');
var eventDispatcher = '';
eventDispatcher += $mountNode.length > 0 ? '.' + $mountNode.attr('class') : '';
var targetClass = $(e.target).attr('class');
if (targetClass) {
eventDispatcher += '.' + targetClass
} else {
eventDispatcher += ' ' + $(e.target).prop("tagName");
}
Core.ga.event(eventDispatcher, 'click', actionInfo);
}
};
var generalClickManger = {
ca: {},
options: {},
init: function (options) {
var me = this;
$.extend(me.options, options);
$(document).on('click', function (e) {
me.handleClick(e);
});
if (me.options.shareConfig) {
AppCore.share(me.options.shareConfig, function (ok) {
me.options.shareConfig.callback&&me.options.shareConfig.callback(ok);
});
AppCore.lmlc.setActionButton({
title: "分享"
}, function () {
me.share();
});
}
},
open: function () {
var me = this;
var pageMap = {
mainCreditor: {
activity: 'cf163://www.lmlc.com/mainCreditor?transfer=0',
url: 'https://www.lmlc.com'
},
bindCard: {
activity: 'cf163://www.lmlc.com/bindCard?tag_bind=1',
url: Core.sys.urlMap.bindCard
}
};
if (arguments[0] === 'd') {
if ($.os.android&&arguments[1]) {
me.openPage('https://www.lmlc.com/static/client/lima_' + arguments[1] + '.apk');
} else {
me.openPage('http://itunes.apple.com/app/id1040726468?mt=8');
}
return;
}
if (arguments.length === 2) {
var destination = arguments[0];
var page = pageMap[destination];
if (page) {
Core.client.open(page.activity, page.url);
} else {
me.openPage(destination);
}
} else if (arguments.length > 2) {
if (arguments[1].indexOf('//') != -1) {
Core.client.open(arguments[0], arguments[1]);
} else {
me.openPage(arguments[0]);
}
}
},
openPage: function (destination) {
if (destination.indexOf('cf163') != -1) {
Core.client.open(destination);
} else {
window.location.href = destination;
}
},
share: function () {
var me = this;
if (window.__data.shareContent && window.__data.shareContent.url) {
AppCore.shareNow();
} else {
Core.alert('err',function(){
location.reload();
})
}
},
login: function () {
if (arguments[0] !== '') {
window.location.href = Core.biz.getLoginUrl(arguments[0], arguments[1]);
} else {
Core.user.login(arguments[1]);
}
},
handleClick: function (e) {
var me = this;
var handled = false;
var actionInfo = $(e.target).data('onclick');
if (!handled && actionInfo) {
var matches = /([^()]*)(?:\(([^()]*)\))?/.exec(actionInfo);
var actionType = matches[1];
if (matches[2]) {
var actionArgs = matches[2].split(',');
}
if (actionArgs && actionArgs.length !== 0) {
actionArgs.push(e);
} else {
actionArgs = [e];
}
var freeInfo = actionArgs[actionArgs.length - 2] && actionArgs[actionArgs.length - 2].toLowerCase();
if (!handled && (!freeInfo || freeInfo.indexOf('activity') === -1 || freeInfo.indexOf('free') === -1)) {
if (window.__data.isOnline != undefined && !window.__data.isOnline) {
Core.alert('金主,下次记得早点来!');
handled = true;
}
}
if (!handled && actionType !== 'login' && (!freeInfo || freeInfo.indexOf('user') === -1 || freeInfo.indexOf('free') === -1)) {
if (!window.__isLogin) {
Core.user.login();
handled = true;
}
}
var action = me[actionType];
if (!handled && action) {
action.apply(me, actionArgs);
handled = true;
}
if (handled) {
e.preventDefault();
e.stopPropagation();
}
}
}
};
generalClickManger.init(window.__data.shareContent && window.__data.shareContent.url&&{
shareConfig: {
title: (window.__data.__name || '') + "送你一个神秘大红包!",
desc: "偷偷告诉你,这是我的赚钱法宝!推荐你也来试试!",
img: "./img/tx.jpg#url",
link: window.__data.shareContent && window.__data.shareContent.url,
wbTitle: (window.__data.__name || '') + '送你一个神秘大红包!偷偷告诉你,这是我的赚钱法宝!推荐你也来试试!戳 https://lmlc.com/rr 立即领取!',
wbDesc: (window.__data.__name || '') + '送你一个神秘大红包!偷偷告诉你,这是我的赚钱法宝!推荐你也来试试!戳 https://lmlc.com/rr 立即领取!',
wbImg: window.location.protocol + '//' + window.location.host + "./img/weibo.jpg#url",
callback: function (ok) {
var me = this;
if (ok) {
Core.postJSON("/wap/activity/inviteFriends/share", function(hasError, rs) {
if (hasError || !rs) {
Core.alert("err");
return;
}
switch (+rs.retcode) {
case 200:
if (rs.data.couponAmount !== 0) {
Core.alert('恭喜获得'+ rs.data.couponAmount +'元红包!稍后可以去我的→红包丨加息券页面查看');
}
break;
case 410:
Core.user.login(function() {
me.callback();
});
break;
default:
Core.alert(rs.retdesc || "err");
}
}, "shareBackLock");
}
}
}
});
generalClickManger.handleClick = aop.before(generalClickManger.handleClick, GAStat.report);
Core.page.extend({
cache: {},
init: function() {
var me = this;
var ca = this.cache;
ca.$main = $('#main');
},
initEvent: function() {
var me = this,
ca = me.cache;
},
initDialog: function(options) {
var me = this,
ca = me.cache;
ca.dialog = $.dialog({
content: Core.format($('#m-breakPopup').html(), options),
button: [],
css: 'm-breakPopup',
width: '26rem',
height: '12.256rem'
}).onCreate(function(dialog) {
dialog.wrap.delegate('.closeBtn', 'click', function(event) {
ca.dialog.close();
return false;
});
});
},
testUser: function() {
var me = this;
if (window.__data.isBind) {
if (window.__data.userType !== 2&&window.__data.inviteCnt >= 5) {
me.initDialog({
tip: '请您继续投资定期产品至1万以上<br>即可解锁人数限制!',
btnText: '前往投资',
btnOnClick: 'open(mainCreditor)'
});
return false;
}
} else {
me.initDialog({
tip: '本活动仅限已绑卡用户参与哦~<br>立即绑卡即可邀请新朋友',
btnText: '前往绑卡',
btnOnClick: 'open(bindCard)'
});
return false;
}
return true;
}
});
generalClickManger.share = aop.check(generalClickManger.share, Core.page.testUser.bind(Core.page));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment