Showing
12 changed files
with
212 additions
and
36 deletions
@@ -20,5 +20,13 @@ module.exports = { | @@ -20,5 +20,13 @@ module.exports = { | ||
20 | id: {type: Number}, | 20 | id: {type: Number}, |
21 | uid: {type: Number} | 21 | uid: {type: Number} |
22 | } | 22 | } |
23 | + }, | ||
24 | + '/resource/get': { | ||
25 | + api: 'operations/api/v5/resource/get', | ||
26 | + cache: true, | ||
27 | + service: true, | ||
28 | + params: { | ||
29 | + content_code: {type: String}, | ||
30 | + } | ||
23 | } | 31 | } |
24 | }; | 32 | }; |
1 | const api = global.yoho.API; | 1 | const api = global.yoho.API; |
2 | +const service = global.yoho.ServiceAPI; | ||
2 | const checkParams = require('../../utils/check-params'); | 3 | const checkParams = require('../../utils/check-params'); |
3 | const apiMaps = require('../../config/api-map'); | 4 | const apiMaps = require('../../config/api-map'); |
4 | 5 | ||
@@ -9,22 +10,31 @@ module.exports = () => { | @@ -9,22 +10,31 @@ module.exports = () => { | ||
9 | if (!apiInfo) { | 10 | if (!apiInfo) { |
10 | return next(); | 11 | return next(); |
11 | } | 12 | } |
12 | - const baseParams = { | ||
13 | - uid: req.yoho.uid || void 0, | ||
14 | - method: apiInfo.api | ||
15 | - }; | 13 | + let baseParams; |
14 | + | ||
15 | + if (!apiInfo.service) { | ||
16 | + baseParams = { | ||
17 | + uid: req.yoho.uid || void 0, | ||
18 | + method: apiInfo.api | ||
19 | + }; | ||
20 | + } | ||
16 | 21 | ||
17 | try { | 22 | try { |
18 | const reqParams = Object.assign({}, req.query, req.body, baseParams); | 23 | const reqParams = Object.assign({}, req.query, req.body, baseParams); |
19 | const params = checkParams.getParams(reqParams, apiInfo); | 24 | const params = checkParams.getParams(reqParams, apiInfo); |
20 | const cache = req.method.toLowerCase() !== 'get' ? false : apiInfo.cache; | 25 | const cache = req.method.toLowerCase() !== 'get' ? false : apiInfo.cache; |
21 | 26 | ||
22 | - return api[req.method]('', params, { | ||
23 | - code: 200, | ||
24 | - cache: cache | ||
25 | - }).then(result => { | ||
26 | - return result; | ||
27 | - }); | 27 | + if (apiInfo.service) { |
28 | + return service.get(apiInfo.api, params, { | ||
29 | + cache: cache, | ||
30 | + code: 200 | ||
31 | + }); | ||
32 | + } else { | ||
33 | + return api[req.method]('', params, { | ||
34 | + code: 200, | ||
35 | + cache: cache | ||
36 | + }); | ||
37 | + } | ||
28 | } catch (e) { | 38 | } catch (e) { |
29 | return res.json({ | 39 | return res.json({ |
30 | code: 400, | 40 | code: 400, |
1 | const api = global.yoho.API; | 1 | const api = global.yoho.API; |
2 | +const service = global.yoho.ServiceAPI; | ||
2 | const checkParams = require('../../utils/check-params'); | 3 | const checkParams = require('../../utils/check-params'); |
3 | const apiMaps = require('../../config/api-map'); | 4 | const apiMaps = require('../../config/api-map'); |
4 | const _ = require('lodash'); | 5 | const _ = require('lodash'); |
@@ -17,10 +18,12 @@ const request = ({url, method, reqParams, context}) => { | @@ -17,10 +18,12 @@ const request = ({url, method, reqParams, context}) => { | ||
17 | return Promise.reject(NOT_FOUND_API_MAP); | 18 | return Promise.reject(NOT_FOUND_API_MAP); |
18 | } | 19 | } |
19 | try { | 20 | try { |
20 | - Object.assign(reqParams, { | ||
21 | - uid: context.user.uid || 0, | ||
22 | - method: apiInfo.api | ||
23 | - }); | 21 | + if (!apiInfo.service) { |
22 | + Object.assign(reqParams, { | ||
23 | + uid: context.user.uid || 0, | ||
24 | + method: apiInfo.api | ||
25 | + }); | ||
26 | + } | ||
24 | if (_.has(apiInfo, 'params.uid') && | 27 | if (_.has(apiInfo, 'params.uid') && |
25 | apiInfo.params.uid.require !== false && | 28 | apiInfo.params.uid.require !== false && |
26 | reqParams.uid === 0) { // 如果接口uid是必须的但是有没有传入uid则直接返回空对象 | 29 | reqParams.uid === 0) { // 如果接口uid是必须的但是有没有传入uid则直接返回空对象 |
@@ -29,10 +32,17 @@ const request = ({url, method, reqParams, context}) => { | @@ -29,10 +32,17 @@ const request = ({url, method, reqParams, context}) => { | ||
29 | const params = checkParams.getParams(reqParams, apiInfo); | 32 | const params = checkParams.getParams(reqParams, apiInfo); |
30 | const cache = method.toLowerCase() !== 'get' ? false : apiInfo.cache; | 33 | const cache = method.toLowerCase() !== 'get' ? false : apiInfo.cache; |
31 | 34 | ||
32 | - return api[method]('', params, { | ||
33 | - code: 200, | ||
34 | - cache: cache | ||
35 | - }); | 35 | + if (apiInfo.service) { |
36 | + return service.get(apiInfo.api, params, { | ||
37 | + cache: cache, | ||
38 | + code: 200 | ||
39 | + }); | ||
40 | + } else { | ||
41 | + return api[method]('', params, { | ||
42 | + code: 200, | ||
43 | + cache: cache | ||
44 | + }); | ||
45 | + } | ||
36 | } catch (e) { | 46 | } catch (e) { |
37 | return Promise.reject({ | 47 | return Promise.reject({ |
38 | code: 400, | 48 | code: 400, |
1 | import ResourceTwoImage from './resource-two-image'; | 1 | import ResourceTwoImage from './resource-two-image'; |
2 | import ResourceSingleImage from './resource-single-image'; | 2 | import ResourceSingleImage from './resource-single-image'; |
3 | +import ResourceProductList from './resource-product-list'; | ||
3 | 4 | ||
4 | export default { | 5 | export default { |
5 | ResourceTwoImage, | 6 | ResourceTwoImage, |
6 | - ResourceSingleImage | 7 | + ResourceSingleImage, |
8 | + ResourceProductList, | ||
7 | }; | 9 | }; |
1 | +<template> | ||
2 | + <resource> | ||
3 | + <ul class="resource-products"> | ||
4 | + <li class="product-item" v-for="(item, index) in value" :key="index"> | ||
5 | + <img-format :src="item.src" :w="94" :h="125"></img-format> | ||
6 | + <p class="title">{{item.title}}</p> | ||
7 | + <p class="price">{{item.price}}</p> | ||
8 | + </li> | ||
9 | + </ul> | ||
10 | + </resource> | ||
11 | +</template> | ||
12 | + | ||
13 | +<script> | ||
14 | +import Resource from './resource'; | ||
15 | + | ||
16 | +export default { | ||
17 | + name: 'ResourceSingleImage', | ||
18 | + props: { | ||
19 | + value: Array | ||
20 | + }, | ||
21 | + computed: { | ||
22 | + }, | ||
23 | + components: {Resource} | ||
24 | +}; | ||
25 | +</script> | ||
26 | + | ||
27 | +<style lang="scss"> | ||
28 | +.resource-products { | ||
29 | + width: 100%; | ||
30 | + overflow-x: scroll; | ||
31 | + -webkit-overflow-scrolling: touch; | ||
32 | + white-space: nowrap; | ||
33 | + | ||
34 | + li.product-item { | ||
35 | + display: inline-block; | ||
36 | + padding-right: 20px; | ||
37 | + text-align: center; | ||
38 | + line-height: 40px; | ||
39 | + | ||
40 | + img { | ||
41 | + width: 188px; | ||
42 | + height: 250px; | ||
43 | + } | ||
44 | + } | ||
45 | +} | ||
46 | +</style> |
1 | <template> | 1 | <template> |
2 | - <resource class="single-image"> | 2 | + <resource class="resource-single-image"> |
3 | <img-format :src="value.src" :w="250" :h="250"></img-format> | 3 | <img-format :src="value.src" :w="250" :h="250"></img-format> |
4 | </resource> | 4 | </resource> |
5 | </template> | 5 | </template> |
@@ -17,7 +17,7 @@ export default { | @@ -17,7 +17,7 @@ export default { | ||
17 | </script> | 17 | </script> |
18 | 18 | ||
19 | <style lang="scss"> | 19 | <style lang="scss"> |
20 | -.single-image { | 20 | +.resource-single-image { |
21 | img { | 21 | img { |
22 | width: 100%; | 22 | width: 100%; |
23 | display: block; | 23 | display: block; |
1 | <template> | 1 | <template> |
2 | - <resource class="ti-image"> | ||
3 | - <div class="ti-image-item"> | 2 | + <resource class="resource-ti-image"> |
3 | + <div class="resource-ti-image-item"> | ||
4 | <img-format :src="value[0].src" :w="250" :h="250"></img-format> | 4 | <img-format :src="value[0].src" :w="250" :h="250"></img-format> |
5 | </div> | 5 | </div> |
6 | <div class="split"></div> | 6 | <div class="split"></div> |
7 | - <div class="ti-image-item"> | 7 | + <div class="resource-ti-image-item"> |
8 | <img-format :src="value[1].src" :w="250" :h="250"></img-format> | 8 | <img-format :src="value[1].src" :w="250" :h="250"></img-format> |
9 | </div> | 9 | </div> |
10 | </resource> | 10 | </resource> |
@@ -23,12 +23,12 @@ export default { | @@ -23,12 +23,12 @@ export default { | ||
23 | </script> | 23 | </script> |
24 | 24 | ||
25 | <style lang="scss"> | 25 | <style lang="scss"> |
26 | -.ti-image { | 26 | +.resource-ti-image { |
27 | display: flex; | 27 | display: flex; |
28 | .split { | 28 | .split { |
29 | width: 20px; | 29 | width: 20px; |
30 | } | 30 | } |
31 | - .ti-image-item { | 31 | + .resource-ti-image-item { |
32 | width: 50%; | 32 | width: 50%; |
33 | 33 | ||
34 | img { | 34 | img { |
@@ -14,18 +14,15 @@ | @@ -14,18 +14,15 @@ | ||
14 | <div class="resources"> | 14 | <div class="resources"> |
15 | <resource-two-image v-if="twoImages" :value="twoImages"></resource-two-image> | 15 | <resource-two-image v-if="twoImages" :value="twoImages"></resource-two-image> |
16 | <resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image> | 16 | <resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image> |
17 | - <resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image> | ||
18 | - <resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image> | ||
19 | - <resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image> | ||
20 | - <resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image> | ||
21 | - <resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image> | ||
22 | - <resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image> | ||
23 | - <resource-single-image v-if="singleImages" :value="singleImages"></resource-single-image> | 17 | + <resource-product-list v-if="products" :value="products"></resource-product-list> |
24 | </div> | 18 | </div> |
25 | </layout-body> | 19 | </layout-body> |
26 | </template> | 20 | </template> |
27 | 21 | ||
28 | <script> | 22 | <script> |
23 | +import { | ||
24 | + FETCH_HOME_REQUEST | ||
25 | +} from 'store/channel/types'; | ||
29 | import components from 'components/resources'; | 26 | import components from 'components/resources'; |
30 | 27 | ||
31 | export default { | 28 | export default { |
@@ -39,8 +36,52 @@ export default { | @@ -39,8 +36,52 @@ export default { | ||
39 | }], | 36 | }], |
40 | singleImages: { | 37 | singleImages: { |
41 | src: '//img11.static.yhbimg.com/yhb-img01/2017/07/26/09/01496efd7e853c2aaa1e38035d788eaa8e.jpg?imageView2/2/w/750/h/364/interlace/1' | 38 | src: '//img11.static.yhbimg.com/yhb-img01/2017/07/26/09/01496efd7e853c2aaa1e38035d788eaa8e.jpg?imageView2/2/w/750/h/364/interlace/1' |
42 | - } | ||
43 | - } | 39 | + }, |
40 | + products: [{ | ||
41 | + src: '//img11.static.yhbimg.com/goodsimg/2017/05/04/12/019698fcd41f21403a12e603ae64dc23f0.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1', | ||
42 | + title: 'HBA', | ||
43 | + price: '¥1399' | ||
44 | + }, { | ||
45 | + src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1', | ||
46 | + title: 'HBA', | ||
47 | + price: '¥1399' | ||
48 | + }, { | ||
49 | + src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1', | ||
50 | + title: 'HBA', | ||
51 | + price: '¥1399' | ||
52 | + }, { | ||
53 | + src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1', | ||
54 | + title: 'HBA', | ||
55 | + price: '¥1399' | ||
56 | + }, { | ||
57 | + src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1', | ||
58 | + title: 'HBA', | ||
59 | + price: '¥1399' | ||
60 | + }, { | ||
61 | + src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1', | ||
62 | + title: 'HBA', | ||
63 | + price: '¥1399' | ||
64 | + }, { | ||
65 | + src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1', | ||
66 | + title: 'HBA', | ||
67 | + price: '¥1399' | ||
68 | + }, { | ||
69 | + src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1', | ||
70 | + title: 'HBA', | ||
71 | + price: '¥1399' | ||
72 | + }, { | ||
73 | + src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1', | ||
74 | + title: 'HBA', | ||
75 | + price: '¥1399' | ||
76 | + }, { | ||
77 | + src: '//img12.static.yhbimg.com/goodsimg/2017/05/21/13/0221fbe4559a7033058b84c898fa59d18a.jpg?imageMogr2/thumbnail/330x440/background/d2hpdGU=/position/center/quality/80/interlace/1', | ||
78 | + title: 'HBA', | ||
79 | + price: '¥1399' | ||
80 | + }] | ||
81 | + }; | ||
82 | + }, | ||
83 | + asyncData({store}) { | ||
84 | + return store.dispatch(FETCH_HOME_REQUEST); | ||
44 | }, | 85 | }, |
45 | components: {...components} | 86 | components: {...components} |
46 | }; | 87 | }; |
src/store/channel/index.js
0 → 100644
1 | +import { | ||
2 | + FETCH_HOME_REQUEST, | ||
3 | + FETCH_HOME_FAILURE, | ||
4 | + FETCH_HOME_SUCCESS | ||
5 | +} from './types'; | ||
6 | +import { | ||
7 | + HOME_CONTENT_CODE | ||
8 | +} from '../content-code'; | ||
9 | +import _ from 'lodash'; | ||
10 | + | ||
11 | +export default { | ||
12 | + state: { | ||
13 | + home: {}, | ||
14 | + fethingHome: false | ||
15 | + }, | ||
16 | + mutations: { | ||
17 | + [FETCH_HOME_REQUEST](state) { | ||
18 | + state.fethingHome = true; | ||
19 | + }, | ||
20 | + [FETCH_HOME_FAILURE](state) { | ||
21 | + state.fethingHome = false; | ||
22 | + }, | ||
23 | + [FETCH_HOME_SUCCESS](state, {data}) { | ||
24 | + state.fethingHome = false; | ||
25 | + state.home = data; | ||
26 | + }, | ||
27 | + }, | ||
28 | + actions: { | ||
29 | + async [FETCH_HOME_REQUEST]({commit, state}) { | ||
30 | + // if (!_.isEmpty(state.home)) { | ||
31 | + // return Promise.resolve(state.home); | ||
32 | + // } | ||
33 | + commit(FETCH_HOME_REQUEST); | ||
34 | + try { | ||
35 | + const result = await this.$api.get('/resource/get', {content_code: HOME_CONTENT_CODE}); | ||
36 | + | ||
37 | + commit(FETCH_HOME_SUCCESS, result); | ||
38 | + return result; | ||
39 | + } catch (e) { | ||
40 | + console.error(e); | ||
41 | + commit(FETCH_HOME_FAILURE); | ||
42 | + } | ||
43 | + } | ||
44 | + } | ||
45 | +}; |
src/store/channel/types.js
0 → 100644
src/store/content-code.js
0 → 100644
1 | +export const HOME_CONTENT_CODE = 'd1d01d9f56067651cacf2d938a526747'; | ||
2 | +export const CHANNEL_MAN_CONTENT_CODE = '08b0662963ea75bf821bcf6b828f7c78'; | ||
3 | +export const CHANNEL_WOMEN_CONTENT_CODE = '085b349c0336373d7ea408960347e450'; | ||
4 | +export const ABOUT_CONTENT_CODE = 'f4a568a4ba170136c39122626bd6201c'; | ||
5 | +export const SLIDER_CONTENT_CODE = 'b433d62c8e0e2d9d903bcc4755ac88f7'; | ||
6 | + | ||
7 | + | ||
8 | + |
@@ -3,6 +3,8 @@ import Vuex from 'vuex'; | @@ -3,6 +3,8 @@ import Vuex from 'vuex'; | ||
3 | 3 | ||
4 | import yoho from './yoho'; | 4 | import yoho from './yoho'; |
5 | import product from './product'; | 5 | import product from './product'; |
6 | +import channel from './channel'; | ||
7 | + | ||
6 | import {createApi} from 'create-api'; | 8 | import {createApi} from 'create-api'; |
7 | 9 | ||
8 | Vue.use(Vuex); | 10 | Vue.use(Vuex); |
@@ -11,7 +13,8 @@ export function createStore(context) { | @@ -11,7 +13,8 @@ export function createStore(context) { | ||
11 | const store = new Vuex.Store({ | 13 | const store = new Vuex.Store({ |
12 | modules: { | 14 | modules: { |
13 | product, | 15 | product, |
14 | - yoho | 16 | + yoho, |
17 | + channel | ||
15 | }, | 18 | }, |
16 | strict: process.env.NODE_ENV !== 'production' | 19 | strict: process.env.NODE_ENV !== 'production' |
17 | }); | 20 | }); |
-
Please register or login to post a comment