Authored by 李奇

频道页区分男女

... ... @@ -98,5 +98,6 @@ const ssrRender = isDev ? (req, res, next) => {
module.exports = app => {
app.get(/product\/\d+/, ssrRender);
app.get('/channel', ssrRender);
app.get('/channel/home', ssrRender);
app.get('/channel/man', ssrRender);
app.get('/channel/woman', ssrRender);
};
... ...
... ... @@ -40,9 +40,6 @@
}
}
},
created(){
console.log(this.value)
},
components: {Resource}
};
</script>
... ...
... ... @@ -5,36 +5,47 @@
<i class="icon icon-nav"></i>
</span>
<span slot="title">
男士
{{title[gender]}}
</span>
<span slot="right">
<i class="icon icon-search"></i>
</span>
</header-box>
<div class="resources">
<resource-focus-image :value="channel.man[0].data"></resource-focus-image>
<resource-focus-image :value="data[0].data"></resource-focus-image>
</div>
</layout-body>
</template>
<script>
import {
FETCH_CHANNEL_MAN_REQUEST
FETCH_CHANNEL_REQUEST,
} from 'store/channel/types';
import {mapState} from 'vuex';
import components from 'components/resources';
export default {
name: 'Cate',
name: 'ChannelHome',
data() {
return {
title: {
man: '男士',
woman: '女士'
}
}
},
computed: {
...mapState(['channel']),
gender() {
return this.$store.state.channel.gender;
},
data() {
return this.$store.state.channel[this.gender].data;
}
},
asyncData({store}) {
return store.dispatch(FETCH_CHANNEL_MAN_REQUEST);
asyncData({store, router: to}) {
const gender = /\/channel\/man/.test(to.path) ? 'man' : 'woman';
return store.dispatch(FETCH_CHANNEL_REQUEST, gender);
},
components: {...components}
};
... ...
export default {
path: '/',
name: 'cate',
alias: '/channel/home',
export default [{
path: '/man',
name: 'channelMan',
alias: '/channel/man',
component: () => import(/* webpackChunkName: "cate" */ './channel-home')
};
}, {
path: '/woman',
name: 'channelWomen',
alias: '/channel/woman',
component: () => import(/* webpackChunkName: "cate" */ './channel-home')
}];
... ...
... ... @@ -2,9 +2,9 @@ import {
FETCH_HOME_REQUEST,
FETCH_HOME_FAILURE,
FETCH_HOME_SUCCESS,
FETCH_CHANNEL_MAN_REQUEST,
FETCH_CHANNEL_MAN_SUCCESS,
FETCH_CHANNEL_MAN_FAILURE
FETCH_CHANNEL_REQUEST,
FETCH_CHANNEL_SUCCESS,
FETCH_CHANNEL_FAILURE
} from './types';
import {
HOME_CONTENT_CODE,
... ... @@ -16,10 +16,16 @@ import _ from 'lodash';
export default {
state: {
home: {},
man: {},
gender: 'men',
man: {
data: {},
isFetching: false
},
woman: {
data: {},
isFetching: false
},
fethingHome: false,
fethingMan: false,
fethingWoman: false
},
mutations: {
[FETCH_HOME_REQUEST](state) {
... ... @@ -32,15 +38,16 @@ export default {
state.fethingHome = false;
state.home = data;
},
[FETCH_CHANNEL_MAN_REQUEST](state) {
state.fethingMan = true;
[FETCH_CHANNEL_REQUEST](state, gender) {
state.gender = gender;
state[gender].isFetching = true;
},
[FETCH_CHANNEL_MAN_FAILURE](state) {
state.fethingMan = false;
[FETCH_CHANNEL_FAILURE](state) {
state[state.gender].isFetching = false;
},
[FETCH_CHANNEL_MAN_SUCCESS](state, {data}) {
state.fethingMan = false;
state.man = data;
[FETCH_CHANNEL_SUCCESS](state, {data}) {
state[state.gender].isFetching = false;
state[state.gender].data = data;
},
},
actions: {
... ... @@ -59,17 +66,19 @@ export default {
commit(FETCH_HOME_FAILURE);
}
},
async [FETCH_CHANNEL_MAN_REQUEST]({commit, state}) {
commit(FETCH_CHANNEL_MAN_REQUEST);
async [FETCH_CHANNEL_REQUEST]({commit}, gender) {
commit(FETCH_CHANNEL_REQUEST, gender);
try {
const result = await this.$api.get('/resource/get', {content_code: CHANNEL_MAN_CONTENT_CODE});
const result = await this.$api.get('/resource/get', {
content_code: gender === 'man' ? CHANNEL_MAN_CONTENT_CODE : CHANNEL_WOMEN_CONTENT_CODE
});
console.log(result)
commit(FETCH_CHANNEL_MAN_SUCCESS, result);
commit(FETCH_CHANNEL_SUCCESS, result);
return result;
} catch (e) {
console.error(e);
commit(FETCH_CHANNEL_MAN_FAILURE);
commit(FETCH_CHANNEL_FAILURE);
}
}
}
... ...
... ... @@ -2,13 +2,9 @@ export const FETCH_HOME_REQUEST = 'FETCH_HOME_REQUEST';
export const FETCH_HOME_SUCCESS = 'FETCH_HOME_SUCCESS';
export const FETCH_HOME_FAILURE = 'FETCH_HOME_FAILURE';
export const FETCH_CHANNEL_MAN_REQUEST = 'FETCH_CHANNEL_MAN_REQUEST';
export const FETCH_CHANNEL_MAN_SUCCESS = 'FETCH_CHANNEL_MAN_SUCCESS';
export const FETCH_CHANNEL_MAN_FAILURE = 'FETCH_CHANNEL_MAN_FAILURE';
export const FETCH_CHANNEL_WOMEN_REQUEST = 'FETCH_CHANNEL_WOMEN_REQUEST';
export const FETCH_CHANNEL_WOMEN_SUCCESS = 'FETCH_CHANNEL_WOMEN_SUCCESS';
export const FETCH_CHANNEL_WOMEN_FAILURE = 'FETCH_CHANNEL_WOMEN_FAILURE';
export const FETCH_CHANNEL_REQUEST = 'FETCH_CHANNEL_REQUEST';
export const FETCH_CHANNEL_SUCCESS = 'FETCH_CHANNEL_SUCCESS';
export const FETCH_CHANNEL_FAILURE = 'FETCH_CHANNEL_FAILURE';
export const FETCH_ABOUT_REQUEST = 'FETCH_ABOUT_REQUEST';
export const FETCH_ABOUT_SUCCESS = 'FETCH_ABOUT_SUCCESS';
... ...