remove deplicute keys
Showing
3 changed files
with
43 additions
and
38 deletions
@@ -43,6 +43,7 @@ Handlebars.registerHelper('pager', function() { | @@ -43,6 +43,7 @@ Handlebars.registerHelper('pager', function() { | ||
43 | function getPageNums(ntype) { | 43 | function getPageNums(ntype) { |
44 | var pageNums = []; | 44 | var pageNums = []; |
45 | var num = showNum; | 45 | var num = showNum; |
46 | + | ||
46 | if (ntype === 'e') { | 47 | if (ntype === 'e') { |
47 | num = num - 2; | 48 | num = num - 2; |
48 | num = num > 2 ? num : 2; | 49 | num = num > 2 ? num : 2; |
@@ -97,6 +98,7 @@ Handlebars.registerHelper('pager', function() { | @@ -97,6 +98,7 @@ Handlebars.registerHelper('pager', function() { | ||
97 | function renderItem(arr) { | 98 | function renderItem(arr) { |
98 | /** 分页展示页码个数end **/ | 99 | /** 分页展示页码个数end **/ |
99 | let ret = ''; | 100 | let ret = ''; |
101 | + | ||
100 | if (_.isArray(arr) && arr.length) { | 102 | if (_.isArray(arr) && arr.length) { |
101 | 103 | ||
102 | arr.forEach((val) => { | 104 | arr.forEach((val) => { |
@@ -130,10 +132,12 @@ Handlebars.registerHelper('pager', function() { | @@ -130,10 +132,12 @@ Handlebars.registerHelper('pager', function() { | ||
130 | } | 132 | } |
131 | 133 | ||
132 | let items = ALL_TYPES[type] ? ALL_TYPES[type] : type; | 134 | let items = ALL_TYPES[type] ? ALL_TYPES[type] : type; |
135 | + | ||
133 | items = _.isArray(items) ? items : (items || ALL_TYPES.stand).split('-'); | 136 | items = _.isArray(items) ? items : (items || ALL_TYPES.stand).split('-'); |
134 | 137 | ||
135 | let hasPage = false; // 配置中如果配置了多次 page/pe 则将忽略,只第一次有效 | 138 | let hasPage = false; // 配置中如果配置了多次 page/pe 则将忽略,只第一次有效 |
136 | let ret = `<div class="pager ${theme}">`; | 139 | let ret = `<div class="pager ${theme}">`; |
140 | + | ||
137 | items.forEach(function(val) { | 141 | items.forEach(function(val) { |
138 | 142 | ||
139 | switch (val) { | 143 | switch (val) { |
@@ -144,12 +148,14 @@ Handlebars.registerHelper('pager', function() { | @@ -144,12 +148,14 @@ Handlebars.registerHelper('pager', function() { | ||
144 | break; | 148 | break; |
145 | case 'p' : | 149 | case 'p' : |
146 | if (page > 1) { | 150 | if (page > 1) { |
147 | - ret += `<a href="${base}` + (page - 1) + '" title="上一页"><span class="iconfont"></span>上一页</a>'; | 151 | + ret += `<a href="${base}` + (page - 1) + |
152 | + '" title="上一页"><span class="iconfont"></span>上一页</a>'; | ||
148 | } | 153 | } |
149 | break; | 154 | break; |
150 | case 'n' : | 155 | case 'n' : |
151 | if (page < totalPages) { | 156 | if (page < totalPages) { |
152 | - ret += `<a href="${base}` + (page + 1) + '" title="下一页">下一页<span class="iconfont"></span></a>'; | 157 | + ret += `<a href="${base}` + (page + 1) + |
158 | + '" title="下一页">下一页<span class="iconfont"></span></a>'; | ||
153 | } | 159 | } |
154 | break; | 160 | break; |
155 | case 'l' : | 161 | case 'l' : |
@@ -21,20 +21,20 @@ | @@ -21,20 +21,20 @@ | ||
21 | Object.assign(app.locals, parent.locals); | 21 | Object.assign(app.locals, parent.locals); |
22 | }); | 22 | }); |
23 | 23 | ||
24 | -app.set('views', path.join(__dirname, 'views/action')); | ||
25 | -app.engine('.hbs', hbs({ | ||
26 | - extname: '.hbs', | ||
27 | - defaultLayout: 'layout', | ||
28 | - layoutsDir: doraemon, | ||
29 | - partialsDir: [`${partials}/partial`, `${doraemon}/partial`], | ||
30 | - helpers: global.yoho.helpers | ||
31 | -})); | ||
32 | - | ||
33 | -require('./helpers/json'); | ||
34 | -require('./helpers/page'); | 24 | + app.set('views', path.join(__dirname, 'views/action')); |
25 | + app.engine('.hbs', hbs({ | ||
26 | + extname: '.hbs', | ||
27 | + defaultLayout: 'layout', | ||
28 | + layoutsDir: doraemon, | ||
29 | + partialsDir: [`${partials}/partial`, `${doraemon}/partial`], | ||
30 | + helpers: global.yoho.helpers | ||
31 | + })); | ||
32 | + | ||
33 | + require('./helpers/json'); | ||
34 | + require('./helpers/page'); | ||
35 | 35 | ||
36 | // router | 36 | // router |
37 | -app.use(require('./router')); | 37 | + app.use(require('./router')); |
38 | 38 | ||
39 | -module.exports = app; | 39 | + module.exports = app; |
40 | 40 |
@@ -105,6 +105,7 @@ const _formatArticle = (articleData, showTag, showAuthor) => { | @@ -105,6 +105,7 @@ const _formatArticle = (articleData, showTag, showAuthor) => { | ||
105 | height = 360, | 105 | height = 360, |
106 | isSquareImage = true; | 106 | isSquareImage = true; |
107 | 107 | ||
108 | + | ||
108 | if (articleData.conver_image_type === 2) { | 109 | if (articleData.conver_image_type === 2) { |
109 | width = 360; | 110 | width = 360; |
110 | height = 240; | 111 | height = 240; |
@@ -133,7 +134,7 @@ const _formatArticle = (articleData, showTag, showAuthor) => { | @@ -133,7 +134,7 @@ const _formatArticle = (articleData, showTag, showAuthor) => { | ||
133 | }; | 134 | }; |
134 | } | 135 | } |
135 | 136 | ||
136 | - // result.author = articleData.author.name; | 137 | + result.author = articleData.author.name; |
137 | 138 | ||
138 | let authorId = articleData.author.author_id; | 139 | let authorId = articleData.author.author_id; |
139 | 140 | ||
@@ -253,11 +254,11 @@ const getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, u | @@ -253,11 +254,11 @@ const getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, u | ||
253 | let list = res.data.list; | 254 | let list = res.data.list; |
254 | 255 | ||
255 | if (list.artList) { | 256 | if (list.artList) { |
256 | - artList = _.map(list.artList, it => _formatArticle(it, true, false, uid)); | 257 | + artList = _.map(list.artList, it => _formatArticle(it, true, false)); |
257 | } | 258 | } |
258 | 259 | ||
259 | if (list.adlist) { | 260 | if (list.adlist) { |
260 | - adsList = _.map(list.artList, it => _formatAd(it, uid)); | 261 | + adsList = _.map(list.artList, it => _formatAd(it)); |
261 | } | 262 | } |
262 | } | 263 | } |
263 | 264 | ||
@@ -438,7 +439,6 @@ const getArticleInfo = aid => { | @@ -438,7 +439,6 @@ const getArticleInfo = aid => { | ||
438 | }).then(res => { | 439 | }).then(res => { |
439 | if (res && res.code === 200 && res.data) { | 440 | if (res && res.code === 200 && res.data) { |
440 | let d = res.data; | 441 | let d = res.data; |
441 | - | ||
442 | let tags = []; | 442 | let tags = []; |
443 | 443 | ||
444 | if (d.tags) { | 444 | if (d.tags) { |
@@ -466,6 +466,7 @@ const _formatProduct = (products, arr) => { | @@ -466,6 +466,7 @@ const _formatProduct = (products, arr) => { | ||
466 | let result = []; | 466 | let result = []; |
467 | 467 | ||
468 | _.forEach(products, val => { | 468 | _.forEach(products, val => { |
469 | + | ||
469 | let goods = { | 470 | let goods = { |
470 | thumb: helpers.image(val.default_images, 235, 314), | 471 | thumb: helpers.image(val.default_images, 235, 314), |
471 | name: val.product_name, | 472 | name: val.product_name, |
@@ -738,30 +739,28 @@ const getArticleComments = (aid, page, pageSize) => { | @@ -738,30 +739,28 @@ const getArticleComments = (aid, page, pageSize) => { | ||
738 | pageSize: pageSize | 739 | pageSize: pageSize |
739 | }).then(res => { | 740 | }).then(res => { |
740 | 741 | ||
741 | - if (res && res.code === 200) { | ||
742 | - let num = (res.data && res.data.total) || 0; | ||
743 | - let list = []; | 742 | + let num = (res.data && res.data.total) || 0; |
743 | + let list = []; | ||
744 | 744 | ||
745 | - if (num > 0 && res.data.list) { | ||
746 | - let iList = res.data.list; | 745 | + if (num > 0 && res.data.list) { |
746 | + let iList = res.data.list; | ||
747 | 747 | ||
748 | - for (let i = 0; i < iList.length; i++) { | ||
749 | - let it = iList[i]; | 748 | + for (let i = 0; i < iList.length; i++) { |
749 | + let it = iList[i]; | ||
750 | 750 | ||
751 | - list.push({ | ||
752 | - avatar: helpers.image(it.avator, 100, 100), | ||
753 | - name: it.username, | ||
754 | - content: it.content, | ||
755 | - time: it.create_time | ||
756 | - }); | ||
757 | - } | 751 | + list.push({ |
752 | + avatar: helpers.image(it.avator, 100, 100), | ||
753 | + name: it.username, | ||
754 | + content: it.content, | ||
755 | + time: it.create_time | ||
756 | + }); | ||
758 | } | 757 | } |
759 | - | ||
760 | - return { | ||
761 | - commentNum: num, | ||
762 | - list: list | ||
763 | - }; | ||
764 | } | 758 | } |
759 | + | ||
760 | + return { | ||
761 | + commentNum: num, | ||
762 | + list: list | ||
763 | + }; | ||
765 | }); | 764 | }); |
766 | }; | 765 | }; |
767 | 766 |
-
Please register or login to post a comment