Authored by 陈峰

products

... ... @@ -20,5 +20,13 @@ module.exports = {
id: {type: Number},
uid: {type: Number}
}
},
'/resource/get': {
api: 'operations/api/v5/resource/get',
cache: true,
service: true,
params: {
content_code: {type: String},
}
}
};
... ...
const api = global.yoho.API;
const service = global.yoho.ServiceAPI;
const checkParams = require('../../utils/check-params');
const apiMaps = require('../../config/api-map');
... ... @@ -9,22 +10,31 @@ module.exports = () => {
if (!apiInfo) {
return next();
}
const baseParams = {
let baseParams;
if (!apiInfo.service) {
baseParams = {
uid: req.yoho.uid || void 0,
method: apiInfo.api
};
}
try {
const reqParams = Object.assign({}, req.query, req.body, baseParams);
const params = checkParams.getParams(reqParams, apiInfo);
const cache = req.method.toLowerCase() !== 'get' ? false : apiInfo.cache;
if (apiInfo.service) {
return service.get(apiInfo.api, params, {
cache: cache,
code: 200
});
} else {
return api[req.method]('', params, {
code: 200,
cache: cache
}).then(result => {
return result;
});
}
} catch (e) {
return res.json({
code: 400,
... ...
const api = global.yoho.API;
const service = global.yoho.ServiceAPI;
const checkParams = require('../../utils/check-params');
const apiMaps = require('../../config/api-map');
const _ = require('lodash');
... ... @@ -17,10 +18,12 @@ const request = ({url, method, reqParams, context}) => {
return Promise.reject(NOT_FOUND_API_MAP);
}
try {
if (!apiInfo.service) {
Object.assign(reqParams, {
uid: context.user.uid || 0,
method: apiInfo.api
});
}
if (_.has(apiInfo, 'params.uid') &&
apiInfo.params.uid.require !== false &&
reqParams.uid === 0) { // 如果接口uid是必须的但是有没有传入uid则直接返回空对象
... ... @@ -29,10 +32,17 @@ const request = ({url, method, reqParams, context}) => {
const params = checkParams.getParams(reqParams, apiInfo);
const cache = method.toLowerCase() !== 'get' ? false : apiInfo.cache;
if (apiInfo.service) {
return service.get(apiInfo.api, params, {
cache: cache,
code: 200
});
} else {
return api[method]('', params, {
code: 200,
cache: cache
});
}
} catch (e) {
return Promise.reject({
code: 400,
... ...
import ResourceTwoImage from './resource-two-image';
import ResourceSingleImage from './resource-single-image';
import ResourceProductList from './resource-product-list';
export default {
ResourceTwoImage,
ResourceSingleImage
ResourceSingleImage,
ResourceProductList,
};
... ...
<template>
<resource>
<ul class="resource-products">
<li class="product-item" v-for="(item, index) in value" :key="index">
<img-format :src="item.src" :w="94" :h="125"></img-format>
<p class="title">{{item.title}}</p>
<p class="price">{{item.price}}</p>
</li>
</ul>
</resource>
</template>
<script>
import Resource from './resource';
export default {
name: 'ResourceSingleImage',
props: {
value: Array
},
computed: {
},
components: {Resource}
};
</script>
<style lang="scss">
.resource-products {
width: 100%;
overflow-x: scroll;
-webkit-overflow-scrolling: touch;
white-space: nowrap;
li.product-item {
display: inline-block;
padding-right: 20px;
text-align: center;
line-height: 40px;
img {
width: 188px;
height: 250px;
}
}
}
</style>
... ...
<template>
<resource class="single-image">
<resource class="resource-single-image">
<img-format :src="value.src" :w="250" :h="250"></img-format>
</resource>
</template>
... ... @@ -17,7 +17,7 @@ export default {
</script>
<style lang="scss">
.single-image {
.resource-single-image {
img {
width: 100%;
display: block;
... ...
<template>
<resource class="ti-image">
<div class="ti-image-item">
<resource class="resource-ti-image">
<div class="resource-ti-image-item">
<img-format :src="value[0].src" :w="250" :h="250"></img-format>
</div>
<div class="split"></div>
<div class="ti-image-item">
<div class="resource-ti-image-item">
<img-format :src="value[1].src" :w="250" :h="250"></img-format>
</div>
</resource>
... ... @@ -23,12 +23,12 @@ export default {
</script>
<style lang="scss">
.ti-image {
.resource-ti-image {
display: flex;
.split {
width: 20px;
}
.ti-image-item {
.resource-ti-image-item {
width: 50%;
img {
... ...
... ... @@ -14,18 +14,15 @@
<div class="resources">
<resource-two-image v-if="twoImages" :value="twoImages"></resource-two-image>
<resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image>
<resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image>
<resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image>
<resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image>
<resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image>
<resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image>
<resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image>
<resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image>
<resource-product-list v-if="products" :value="products"></resource-product-list>
</div>
</layout-body>
</template>
<script>
import {
FETCH_HOME_REQUEST
} from 'store/channel/types';
import components from 'components/resources';
export default {
... ... @@ -39,8 +36,52 @@ export default {
}],
singleImages: {
src: '//img11.static.yhbimg.com/yhb-img01/2017/07/26/09/01496efd7e853c2aaa1e38035d788eaa8e.jpg?imageView2/2/w/750/h/364/interlace/1'
}
}
},
products: [{
src: '//img11.static.yhbimg.com/goodsimg/2017/05/04/12/019698fcd41f21403a12e603ae64dc23f0.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1',
title: 'HBA',
price: '¥1399'
}, {
src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1',
title: 'HBA',
price: '¥1399'
}, {
src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1',
title: 'HBA',
price: '¥1399'
}, {
src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1',
title: 'HBA',
price: '¥1399'
}, {
src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1',
title: 'HBA',
price: '¥1399'
}, {
src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1',
title: 'HBA',
price: '¥1399'
}, {
src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1',
title: 'HBA',
price: '¥1399'
}, {
src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1',
title: 'HBA',
price: '¥1399'
}, {
src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1',
title: 'HBA',
price: '¥1399'
}, {
src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1',
title: 'HBA',
price: '¥1399'
}]
};
},
asyncData({store}) {
return store.dispatch(FETCH_HOME_REQUEST);
},
components: {...components}
};
... ...
import {
FETCH_HOME_REQUEST,
FETCH_HOME_FAILURE,
FETCH_HOME_SUCCESS
} from './types';
import {
HOME_CONTENT_CODE
} from '../content-code';
import _ from 'lodash';
export default {
state: {
home: {},
fethingHome: false
},
mutations: {
[FETCH_HOME_REQUEST](state) {
state.fethingHome = true;
},
[FETCH_HOME_FAILURE](state) {
state.fethingHome = false;
},
[FETCH_HOME_SUCCESS](state, {data}) {
state.fethingHome = false;
state.home = data;
},
},
actions: {
async [FETCH_HOME_REQUEST]({commit, state}) {
// if (!_.isEmpty(state.home)) {
// return Promise.resolve(state.home);
// }
commit(FETCH_HOME_REQUEST);
try {
const result = await this.$api.get('/resource/get', {content_code: HOME_CONTENT_CODE});
commit(FETCH_HOME_SUCCESS, result);
return result;
} catch (e) {
console.error(e);
commit(FETCH_HOME_FAILURE);
}
}
}
};
... ...
export const FETCH_HOME_REQUEST = 'FETCH_HOME_REQUEST';
export const FETCH_HOME_SUCCESS = 'FETCH_HOME_SUCCESS';
export const FETCH_HOME_FAILURE = 'FETCH_HOME_FAILURE';
\ No newline at end of file
... ...
export const HOME_CONTENT_CODE = 'd1d01d9f56067651cacf2d938a526747';
export const CHANNEL_MAN_CONTENT_CODE = '08b0662963ea75bf821bcf6b828f7c78';
export const CHANNEL_WOMEN_CONTENT_CODE = '085b349c0336373d7ea408960347e450';
export const ABOUT_CONTENT_CODE = 'f4a568a4ba170136c39122626bd6201c';
export const SLIDER_CONTENT_CODE = 'b433d62c8e0e2d9d903bcc4755ac88f7';
... ...
... ... @@ -3,6 +3,8 @@ import Vuex from 'vuex';
import yoho from './yoho';
import product from './product';
import channel from './channel';
import {createApi} from 'create-api';
Vue.use(Vuex);
... ... @@ -11,7 +13,8 @@ export function createStore(context) {
const store = new Vuex.Store({
modules: {
product,
yoho
yoho,
channel
},
strict: process.env.NODE_ENV !== 'production'
});
... ...