Authored by htoooth

format js

... ... @@ -13,7 +13,9 @@ function index(req, res, next) {
req.ctx(YoLuckService).index(type, uid).then(result => {
if (result.error) {
if (type === YOLUCK_LIST_TYPE.joined && result.error === 401) {
return res.redirect(`/signin.html?refer=//m.yohobuy.com/activity/yoluck/index.html?type=${YOLUCK_LIST_TYPE.joined}`);
return res.redirect(
`/signin.html?refer=//m.yohobuy.com/activity/yoluck/index.html?type=${YOLUCK_LIST_TYPE.joined}`
);
} else {
return next(result.error);
}
... ... @@ -63,7 +65,7 @@ function detail(req, res, next) {
req.ctx(YoLuckService).getDetail(id, uid).then(result => {
if (result.error) {
return next(error);
return next(result.error);
}
res.render('yoluck/detail', {
... ... @@ -84,7 +86,7 @@ function getCode(req, res, next) {
if (!actPrizeId) {
return {
error: '活动参数错误'
}
};
}
req.ctx(YoLuckService).getCode({shareUid, uid, actPrizeId}).then(result => {
... ...
function getDateList(date) {
if (!date) {
return []
return [];
}
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
return [year, month, day];
}
function formatN(format, num) {
var n = num + '';
var nList = n.split('')
var l = nList.length;
var fl = format.length;
let n = num + '';
let nList = n.split('');
let l = nList.length;
let fl = format.length;
if (format.length < nList.length) {
return nList;
}
var el = fl - l;
let el = fl - l;
for(var i = 0; i < el; i++) {
for (let i = 0; i < el; i++) {
nList.splice(0, 0, '0');
}
... ... @@ -30,17 +30,17 @@ function formatN(format, num) {
}
function formatTime(start, end) {
var startTime = new Date(start * 1000);
var endTime = new Date(end * 1000);
let startTime = new Date(start * 1000);
let endTime = new Date(end * 1000);
var startDate = getDateList(startTime);
var endDate = getDateList(endTime);
let startDate = getDateList(startTime);
let endDate = getDateList(endTime);
var startDateFormat = startDate[0] + '.' + formatN('00', startDate[1]) + '.' + formatN('00', startDate[2])
var endDateFormat = '-' + formatN('00', endDate[1]) + '.' + formatN('00', endDate[2]);
let startDateFormat = startDate[0] + '.' + formatN('00', startDate[1]) + '.' + formatN('00', startDate[2]);
let endDateFormat = '-' + formatN('00', endDate[1]) + '.' + formatN('00', endDate[2]);
if (!end) {
return "即将上线:" + startDateFormat;
return '即将上线:' + startDateFormat;
}
return startDateFormat + endDateFormat;
... ...
module.exports = function(v1, operator, v2, options) {
switch (operator) {
case '==':
return (v1 == v2) ? options.fn(this) : options.inverse(this);
return (v1 == v2) ? options.fn(this) : options.inverse(this); // eslint-disable-line
case '===':
return (v1 === v2) ? options.fn(this) : options.inverse(this);
case '!=':
return (v1 != v2) ? options.fn(this) : options.inverse(this);
return (v1 != v2) ? options.fn(this) : options.inverse(this); // eslint-disable-line
case '!==':
return (v1 !== v2) ? options.fn(this) : options.inverse(this);
case '<':
... ...
... ... @@ -328,7 +328,7 @@ class YoLuckService extends global.yoho.BaseModel {
step = STEP.ZERO;
} else {
if (activityStatus === ACTIVITY.START) {
let myPrizeCount = result.myPrizeCount;
myPrizeCount = result.myPrizeCount;
if (myPrizeCount === 0) {
step = STEP.ZERO;
... ... @@ -372,6 +372,7 @@ class YoLuckService extends global.yoho.BaseModel {
async getResourceCode(params) {
const result = await this.api._getResourceCode(params);
return _.get(result, '[0].data.list[0]', '');
}
... ... @@ -381,11 +382,11 @@ class YoLuckService extends global.yoho.BaseModel {
contentCode: 'ccc32dbedf164a52b4efa34383878860'
});
return result
return result;
} catch (e) {
return {
error: '出错了'
}
};
}
}
... ... @@ -395,12 +396,11 @@ class YoLuckService extends global.yoho.BaseModel {
contentCode: '5a2203f5656fbc9788bd8af70f2823d3'
});
return result
return result;
} catch (e) {
console.log(e);
return {
error: '出错了'
}
};
}
}
... ... @@ -420,17 +420,19 @@ class YoLuckService extends global.yoho.BaseModel {
if (result.code !== 200) {
logger.error(result);
return {
error: '错误'
}
};
}
return result.data;
} catch (e) {
logger.error(e);
return {
error: '出错了'
}
};
}
}
}
... ...
... ... @@ -10,12 +10,17 @@ let api = new YolukcApi();
let tip = require('js/plugin/tip');
let yoSdk = require('yoho-activity-sdk');
let Clipboard = require('clipboard');
let shareData = require('./yoluck/share');
let makeShareData = require('./yoluck/share');
function reload() {
location = location; //eslint-disable-line
}
require('js/plugin/modal.alert');
let store = {
running: false,
shareUid: window.queryString['shareUid'] || ''
shareUid: window.queryString.shareUid || ''
};
new Swiper('.swiper-container', {
... ... @@ -26,7 +31,44 @@ new Swiper('.swiper-container', {
autoplay: 3000
});
var luckAlert = {
function share() {
let $product = $('.product-name');
let name = $product.data('name');
let img = $product.data('img');
let price = $product.data('price');
let id = $product.data('id');
yoSdk.getUser().then(user => {
let shareData = makeShareData({
name: name,
imgUrl: img,
price: price,
shareUid: user.uid,
actPrizeId: id
});
if (yoho.isApp) {
yoho.invokeMethod('go.showshareaction', shareData.app);
} else {
yoSdk.wxShare({
...shareData.h5,
success() {
tip.show('分享成功', 3500);
}
});
}
});
}
function fellow() {
$.yAlert({
content: `<div>公众号
<span style="font-weight: bolder">“潮流有货”</span>已经复制成功,</div>
<div>打开微信搜索去添加吧~</div>` // eslint-disable-line
});
}
let luckAlert = {
$el: $('.js-luck-alert'),
init() {
this.bindEvent();
... ... @@ -67,10 +109,6 @@ clipboard.on('success', function(e) {
e.clearSelection();
});
function reload() {
location = location;
}
luckAlert.init();
yoSdk.auth();
... ... @@ -85,41 +123,6 @@ setInterval(() => {
}));
}, 1000);
function share() {
let $product= $('.product-name');
let name = $product.data('name');
let img = $product.data('img');
let price = $product.data('price');
let id = $product.data('id');
yoSdk.getUser().then(user => {
let share = shareData({
name: name,
imgUrl: img,
price: price,
shareUid: user.uid,
actPrizeId: id
});
if (yoho.isApp) {
yoho.invokeMethod('go.showshareaction', share.app);
} else {
yoSdk.wxShare({
...share.h5,
success() {
tip.show('分享成功', 3500);
}
});
}
});
}
function fellow() {
$.yAlert({
content: `<div>公众号<span style="font-weight: bolder">“潮流有货”</span>已经复制成功,</div><div>打开微信搜索去添加吧~</div>`
});
}
// 助力
$('.action-bar-comp').on('click', '.js-join', function() {
if (store.running) {
... ...
... ... @@ -8,13 +8,14 @@ let timeCountDownTpl = require('hbs/activity/yoluck/time-countdown.hbs');
let formatCountDown = require('./yoluck/formatCountDown');
let yoSdk = require('yoho-activity-sdk');
let yoho = require('js/yoho-app');
require('js/plugin/modal.alert');
const tip = require('js/plugin/tip');
const shareData = require('./yoluck/share');
const makeShareData = require('./yoluck/share');
require('js/plugin/modal.alert');
var footerText = ['内容加载中...', '暂无更多内容'];
let footerText = ['内容加载中...', '暂无更多内容'];
var store = {
let store = {
list: [{
page: 0,
}, {
... ... @@ -31,10 +32,10 @@ var store = {
countDown: [],
};
var api = new Api();
var bus$ = $.Callbacks();
var $tabpanel = $('.js-tab-comp');
var tabpanelStore = {
let api = new Api();
let bus$ = $.Callbacks(); // eslint-disable-line
let $tabpanel = $('.js-tab-comp');
let tabpanelStore = {
tabs: [],
key: 0,
nodes: [],
... ... @@ -45,6 +46,7 @@ var tabpanelStore = {
function initStore() {
// 初始化为
let tabIndex = +$tabpanel.data('type');
store.list[tabIndex].page = 1;
store.tabIndex = tabIndex;
tabpanelStore.currentKey = tabIndex;
... ... @@ -60,7 +62,7 @@ function updateFooter(msg) {
}
function updateTabs() {
tabpanelStore.nodes.map(function(index) {
tabpanelStore.nodes.each(function(index) {
let $this = $(this);
let active = index === tabpanelStore.key;
... ... @@ -72,7 +74,7 @@ function updateTabs() {
}
});
tabpanelStore.tabs.map(function() {
tabpanelStore.tabs.each(function() {
let $this = $(this);
let active = $this.data('index') === tabpanelStore.key;
... ... @@ -166,8 +168,8 @@ function onReachBottom(type) {
function fellow() {
$.yAlert({
content: `<div>微信搜索公众号</div>
<div><span style="font-weight: bolder;">“潮流有货”</span>并关注,发送</div>
<div>关键词<span style="font-weight: bolder;">“开奖”</span>查询中奖信息</div>`
<div><span style="font-weight: bolder;">“潮流有货”</span>并关注,发送</div>
<div>关键词<span style="font-weight: bolder;">“开奖”</span>查询中奖信息</div>`
});
}
... ... @@ -178,7 +180,7 @@ function share($el) {
let id = $el.data('id');
yoSdk.getUser().then(user => {
let share = shareData({
let shareData = makeShareData({
name,
imgUrl: img,
price: price,
... ... @@ -187,16 +189,16 @@ function share($el) {
});
if (yoho.isApp) {
yoho.invokeMethod('go.showshareaction', share.app);
yoho.invokeMethod('go.showshareaction', shareData.app);
} else {
yoSdk.wxShare({
...share.h5,
...shareData.h5,
success() {
tip.show('分享成功', 3500);
}
});
}
})
});
}
bus$.add(onTabClick);
... ... @@ -216,19 +218,19 @@ $tabpanel.on('click', '.js-tab', function() {
});
$tabpanel
.find('.prize-item-comp')
.on('click', '.js-prizeitem', function() {
let id = $(this).data('id');
yoho.goH5(`/activity/yoluck/${id}.html`);
return true;
return false;
})
.on('click', '.js-share', function() {
share($(this));
return true;
return false;
})
.on('click', '.js-fellow', function() {
fellow();
return true;
return false;
});
$(window).on('scroll', function() {
... ...
... ... @@ -16,7 +16,7 @@ class Api {
}
getCode(shareUid) {
return $.post('', {shareUid})
return $.post('', {shareUid});
}
}
... ...
... ... @@ -28,7 +28,7 @@ function shareData({name, imgUrl, price, shareUid, actPrizeId}) {
desc: '限时抽奖活动',
link: h5Path(shareUid, actPrizeId),
}
}
};
}
module.exports = shareData;
... ...
function getDateList(date) {
if (!date) {
return []
return [];
}
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
return [year, month, day];
}
function formatN(format, num) {
var n = num + '';
var nList = n.split('')
var l = nList.length;
var fl = format.length;
let n = num + '';
let nList = n.split('');
let l = nList.length;
let fl = format.length;
if (format.length < nList.length) {
return nList;
}
var el = fl - l;
let el = fl - l;
for(var i = 0; i < el; i++) {
for (let i = 0; i < el; i++) {
nList.splice(0, 0, '0');
}
... ... @@ -30,17 +30,17 @@ function formatN(format, num) {
}
function formatTime(start, end) {
var startTime = new Date(start * 1000);
var endTime = new Date(end * 1000);
let startTime = new Date(start * 1000);
let endTime = new Date(end * 1000);
var startDate = getDateList(startTime);
var endDate = getDateList(endTime);
let startDate = getDateList(startTime);
let endDate = getDateList(endTime);
var startDateFormat = startDate[0] + '.' + formatN('00', startDate[1]) + '.' + formatN('00', startDate[2])
var endDateFormat = '-' + formatN('00', endDate[1]) + '.' + formatN('00', endDate[2]);
let startDateFormat = startDate[0] + '.' + formatN('00', startDate[1]) + '.' + formatN('00', startDate[2]);
let endDateFormat = '-' + formatN('00', endDate[1]) + '.' + formatN('00', endDate[2]);
if (!end) {
return "即将上线:" + startDateFormat;
return '即将上线:' + startDateFormat;
}
return startDateFormat + endDateFormat;
... ...
module.exports = function(v1, operator, v2, options) {
switch (operator) {
case '==':
return (v1 == v2) ? options.fn(this) : options.inverse(this);
return (v1 == v2) ? options.fn(this) : options.inverse(this); // eslint-disable-line
case '===':
return (v1 === v2) ? options.fn(this) : options.inverse(this);
case '!=':
return (v1 != v2) ? options.fn(this) : options.inverse(this);
return (v1 != v2) ? options.fn(this) : options.inverse(this); // eslint-disable-line
case '!==':
return (v1 !== v2) ? options.fn(this) : options.inverse(this);
case '<':
... ...