Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohoblk-wap
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
陈轩
9 years ago
Commit
69a2363f497a0c8f1c49d44c16e5deb906f3058a
1 parent
f4b8bbc9
处理后台数据
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
144 additions
and
15 deletions
apps/channel/models/channel.js
apps/product/controllers/list.js
apps/product/models/list.js
config/common.js
public/vue/product/filter/brand.vue
public/vue/product/filter/filter-detail.vue
utils/beautify/filters.js
utils/product-process.js → utils/beautify/product.js
utils/resources-process.js → utils/beautify/resources.js
utils/time-process.js → utils/beautify/time.js
apps/channel/models/channel.js
View file @
69a2363
'use strict'
;
const
api
=
global
.
yoho
.
ServiceAPI
;
const
resourcesProcess
=
require
(
'../../../utils/
resources-proces
s'
);
const
resourcesProcess
=
require
(
'../../../utils/
beautify/resource
s'
);
let
channel
=
{
getResourcesData
(
params
)
{
...
...
apps/product/controllers/list.js
View file @
69a2363
...
...
@@ -18,3 +18,8 @@ exports.getProducts = (req, res, next)=>{
})
.
catch
(
next
);
};
// 进入某分类下的商品列表 页
exports
.
entryProducts
=
(
req
,
res
,
next
)
=>
{
// TODO
};
...
...
apps/product/models/list.js
View file @
69a2363
...
...
@@ -2,10 +2,11 @@
* product list Model
*/
'use strict'
;
const
path
=
require
(
'path'
);
const
api
=
global
.
yoho
.
API
;
const
camelCase
=
global
.
yoho
.
camelCase
;
const
path
=
require
(
'path'
);
const
processProductList
=
require
(
path
.
join
(
global
.
utils
,
'/product-process'
)).
processProductList
;
const
prettyFilter
=
require
(
path
.
join
(
global
.
utils
,
'/beautify/filters'
));
const
processProductList
=
require
(
path
.
join
(
global
.
utils
,
'/beautify/product'
)).
processProductList
;
let
list
=
{
...
...
@@ -26,10 +27,24 @@ let list = {
code
:
200
})
.
then
(
result
=>
{
result
=
camelCase
(
result
);
prettyFilter
(
result
.
data
.
filter
);
result
.
data
.
productList
=
processProductList
(
result
.
data
.
productList
);
result
=
camelCase
(
result
);
return
result
;
});
},
getFilters
(
params
)
{
return
api
.
post
(
''
,
{
method
:
'app.search.sales'
},
{
cache
:
true
,
code
:
200
})
.
then
(
result
=>
{
});
}
};
...
...
config/common.js
View file @
69a2363
...
...
@@ -15,8 +15,8 @@ module.exports = {
port
:
6004
,
siteUrl
:
'//m.yohoblk.com'
,
domains
:
{
api
:
'http://devapi.yoho.cn:58078/'
,
service
:
'http://devservice.yoho.cn:58077/'
api
:
'http://api.yoho.cn/'
,
service
:
'http://service.yoho.cn/'
},
subDomains
:
{
host
:
'.m.yohoblk.com'
,
...
...
public/vue/product/filter/brand.vue
View file @
69a2363
...
...
@@ -24,7 +24,6 @@ module.exports = {
methods: {
select: function(val) {
this.val = val;
this.$parent.select(val);
}
}
};
...
...
public/vue/product/filter/filter-detail.vue
View file @
69a2363
<template>
<div>
<brand-filter v-if="type === 'brand'" :data="data" :val="val"></brand-filter>
<normal-filter v-else :data="data" :val="val">
<brand-filter v-if="type === 'brand'" :data="data" :val.sync="val"></brand-filter>
<normal-filter v-else :data="data" :val.sync="val">
<slot></slot>
</normal-filter>
</div>
...
...
@@ -16,12 +16,10 @@ module.exports = {
brandFilter,
normalFilter
},
methods: {
selected: function(val) {
let type = this.type;
console.log(`type:${type}, val:${val}`);
}
watch: {
val: function(newV, oldV) {
console.log(`type: ${this.type}, value: ${newV}`);
}
}
};
</script>
...
...
utils/beautify/filters.js
0 → 100644
View file @
69a2363
/**
* 格式化 后台 返回的 filters 数据
* @author chenxuan <xuan.chen@yoho.cn>
*/
'use strict'
;
const
_
=
require
(
'lodash'
);
/**
* 处理 以风格的数据
* [
* {filter_attribute: value}
* ]
*
* 处理结果
* [
* {attribute:value,......}
* ]
*
*/
let
verboseAttrHandler
=
(
filterField
,
dataArr
)
=>
{
let
result
=
[];
let
re
=
new
RegExp
(
`
^
$
{
filterField
}
_
`
);
dataArr
.
forEach
(
obj
=>
{
let
item
=
{};
let
keys
=
Object
.
keys
(
obj
);
keys
.
forEach
(
key
=>
{
let
newKey
=
key
.
replace
(
re
,
''
);
item
[
newKey
]
=
obj
[
key
];
});
result
.
push
(
item
);
});
return
result
;
};
/*
* 处理 以下风格:
* {
"340,99999": "¥339以上",
"0,149": "¥0-149",
"150,179": "¥150-179",
"180,339": "¥180-339"
* },
*
* 处理结果:
* [
* {id: '0,149', value: '0,149', name: '¥0-149'},
* {id: '150, 179', value: '150,179', name: '¥150-179'}
* .....
* ]
* 按照字符串顺序
*/
let
keyIdHandler
=
(
filterField
,
obj
)
=>
{
const
result
=
[];
const
keys
=
Object
.
keys
(
obj
);
keys
.
sort
();
keys
.
forEach
(
key
=>
{
let
item
=
{};
item
.
id
=
key
;
let
t
=
obj
[
key
];
let
isObject
=
Object
.
prototype
.
toString
.
apply
(
t
)
===
'[object Object]'
;
if
(
isObject
)
{
item
=
Object
.
assign
(
item
,
t
);
}
else
{
item
.
name
=
t
;
}
result
.
push
(
item
);
});
return
result
;
};
function
prettyFilter
(
filters
)
{
let
keys
=
_
.
keys
(
filters
);
_
.
forEach
(
keys
,
key
=>
{
let
process
;
// 相同规律的 使用 相同的处理规则
switch
(
key
)
{
case
'color'
:
case
'size'
:
case
'brand'
:
process
=
verboseAttrHandler
;
break
;
case
'gender'
:
case
'priceRange'
:
case
'discount'
:
process
=
keyIdHandler
;
break
;
// 其他不做处理
default
:
process
=
_
.
noop
;
}
filters
[
key
]
=
process
(
key
,
filters
[
key
])
||
filters
[
key
];
});
}
module
.
exports
=
prettyFilter
;
...
...
utils/
product-process
.js → utils/
beautify/product
.js
View file @
69a2363
utils/
resources-proces
s.js → utils/
beautify/resource
s.js
View file @
69a2363
utils/
time-process
.js → utils/
beautify/time
.js
View file @
69a2363
Please
register
or
login
to post a comment