Authored by yyq

fix head ico

... ... @@ -22,7 +22,7 @@
:data="data.data"
:share="share"
:article-id="data.data.articleId"
:user-head-ico="userHeadIco"
:user-head-ico="yoho.context.userHeadIco"
:pos-id="posId"
@on-follow="follow => onFollow(data.data, follow)"
@on-resize="onResize"
... ... @@ -60,7 +60,7 @@ import ArticleItem from './article-item';
import ArticleActionSheet from '../detail/article-action-sheet';
import ArticleResource from './article-resource-item';
import MoreActionSheet from '../detail/more-action-sheet';
import {mapState, createNamespacedHelpers} from 'vuex';
import {mapState, mapActions, createNamespacedHelpers} from 'vuex';
const {mapMutations} = createNamespacedHelpers('article');
export default {
... ... @@ -84,8 +84,8 @@ export default {
userUid: Number
},
mounted() {
if (this.$cookie && this.$cookie.get) {
this.userHeadIco = this.$cookie.get('_head_ico');
if (!this.yoho.context.userHeadIco) {
this.fetchUserProfile();
}
this.scrollEvent = throttle(this.onDounceScroll.bind(this), 100);
this.reportShow = this.startReportShow();
... ... @@ -103,7 +103,6 @@ export default {
inx: 0,
scrollTop: 0,
showHeader: false,
userHeadIco: '',
currentId: 0,
currentAuthor: {
authorUid: 0,
... ... @@ -130,6 +129,7 @@ export default {
}
},
methods: {
...mapActions(['fetchUserProfile']),
...mapMutations(['ASYNC_ARTICLE_COMMENT', 'CHANGE_AUTHOR_FOLLOW']),
toUserPage() {
if (this.share) {
... ...
... ... @@ -35,7 +35,7 @@
:data="data.data"
:share="share"
:article-id="data.data.articleId"
:user-head-ico="userHeadIco"
:user-head-ico="yoho.context.userHeadIco"
:pos-id="posId"
@on-follow="follow => onFollow(data.data, follow)"
@on-resize="onResize"
... ... @@ -52,7 +52,7 @@
<a v-if="publishUrl && !share" class="publish-btn hover-opacity" :class="{'scroll-opacity': scrolling}" :href="publishUrl">
<span class="avatar-block">
<WidgetAvatar class="avatar" :src="userHeadIco" :width="70" :height="70"></WidgetAvatar>
<WidgetAvatar class="avatar" :src="yoho.context.userHeadIco" :width="70" :height="70"></WidgetAvatar>
</span>
立即参与
</a>
... ... @@ -82,7 +82,7 @@ import ArticleActionSheet from './components/detail/article-action-sheet';
import MoreActionSheet from './components/detail/more-action-sheet';
import TopicHeader from './components/topic/header';
import TopicBanner from './components/topic/banner';
import {createNamespacedHelpers} from 'vuex';
import {mapState as mapYohoState, mapActions as mapYohoActions, createNamespacedHelpers} from 'vuex';
const {mapState, mapMutations, mapActions} = createNamespacedHelpers('article');
const throttleTime = 40;
... ... @@ -121,8 +121,8 @@ export default {
}
}
if (this.$cookie && this.$cookie.get) {
this.userHeadIco = this.$cookie.get('_head_ico');
if (!this.yoho.context.userHeadIco) {
this.fetchUserProfile();
}
this.scrollEvent = throttle(this.onDounceScroll.bind(this), throttleTime);
this.reportShow = this.startReportShow();
... ... @@ -145,11 +145,11 @@ export default {
scrollTop: 0,
currentId: 0,
colWidthForTwo: 0,
userHeadIco: '',
scrolling: false
};
},
computed: {
...mapYohoState(['yoho']),
...mapState(['topicInfo']),
publishUrl() {
return this.topicId ? `?openby:yohobuy={"action":"go.grasspublish","params":{"topicId":"${this.topicId}","topicName":"${this.topicName}"}}` : '';
... ... @@ -162,6 +162,7 @@ export default {
}
},
methods: {
...mapYohoActions(['fetchUserProfile']),
...mapActions(['fetchTopicSimpleInfo', 'fetchTopicRelatedArticles', 'fetchArticleProductFavs']),
...mapMutations(['ASYNC_ARTICLE_COMMENT', 'CHANGE_AUTHOR_FOLLOW', 'CHANGE_TOPIC_FOLLOW']),
onShowComment({articleId, index}) {
... ...
... ... @@ -16,7 +16,8 @@ export default function(state = {}) {
route: '',
path: '',
needLogin: false,
isLogin: false
isLogin: false,
userHeadIco: ''
},
window: {
statusBarStatus: false,
... ... @@ -90,7 +91,13 @@ export default function(state = {}) {
if (state.context.env.isYohoBuy && state.context.env.isiOS && state.window.statusBarStatus) {
state.window.statusBarColor = color || 'black';
}
}
},
[Types.FETCH_USER_INFO_SUCCESS](state, {head_ico}) {
state.context.userHeadIco = head_ico;
},
[Types.FETCH_USER_INFO_FAILD](state) {
state.context.userHeadIco = '';
},
},
getters: {
getLogin(state) {
... ... @@ -98,6 +105,20 @@ export default function(state = {}) {
}
},
actions: {
async fetchUserProfile({commit}) {
const result = await this.$api.get('/api/grass/userProfile');
if (result && result.code === 200) {
if (!result.data) {
result.data = {};
}
commit(Types.FETCH_USER_INFO_SUCCESS, result.data);
return result.data;
} else {
commit(Types.FETCH_USER_INFO_FAILD);
return {};
}
},
reportYas(params, {params: {appop, param}, asyncindx = false}) {
try {
document.addEventListener('deviceready', () => {
... ...
... ... @@ -11,3 +11,6 @@ export const SET_SUPPORT_WEBP = 'SET_SUPPORT_WEBP';
export const SET_STATUS_BAR_STATUS = 'SET_STATUS_BAR_STATUS';
export const SET_STATUS_BAR_HEIGHT = 'SET_STATUS_BAR_HEIGHT';
export const SET_STATUS_BAR_COLOR = 'SET_STATUS_BAR_COLOR';
export const FETCH_USER_INFO_FAILD = 'FETCH_USER_INFO_FAILD';
export const FETCH_USER_INFO_SUCCESS = 'FETCH_USER_INFO_SUCCESS';
... ...
... ... @@ -7,6 +7,14 @@ const topicApis = require('./api-map/topic');
module.exports = {
...userPageApis,
...topicApis,
'/api/grass/userProfile': {
api: 'app.passport.profile',
auth: true,
params: {},
fields: {
head_ico: {default: ''}
}
},
'/api/grass/labelRealtedArticleDetail': {
api: 'app.grass.labelRealtedArticleDetail',
cache: true,
... ...
... ... @@ -2,6 +2,7 @@ const serviceApi = global.yoho.ServiceAPI;
const ufoAPI = global.yoho.UfoAPI;
const logger = global.yoho.logger;
const checkParams = require('../../utils/check-params');
const handleResult = require('../../utils/handle-result');
const apiMaps = require('../../config/api-map');
const errorHandler = require('./error-handler');
... ... @@ -71,7 +72,7 @@ module.exports = async(req, res, next) => {
});
}
if (result) {
return res.json(result);
return res.json(handleResult(result, apiInfo));
}
return res.json({
code: 400
... ...
... ... @@ -53,34 +53,6 @@ const asyncLoadScripts = (renderScripts) => {
return scripts;
};
const getUserProfile = async(req, res, next) => {
if (req.user && req.user.uid) {
if (!req.session.headIco) {
const apiCtx = req.ctx(global.yoho.BaseModel);
result = await apiCtx.get({
url: '',
data: {
method: 'app.passport.profile',
uid: {
toString: () => {
return req.user.uid;
},
sessionKey: req.user.sessionKey,
appSessionType: req.user.appSessionType
}
}
});
req.session.headIco = _.get(result, 'data.head_ico', '');
}
res.cookie('_head_ico', req.session.headIco);
}
next();
}
const versionToNumber = (str, len = 3) => {
let verNum = 0;
const ver = str.split('.').map(i => Number(i));
... ... @@ -310,7 +282,7 @@ const router = require('express').Router(); //eslint-disable-line
_.each(routes, r => {
if (!r.disable) {
router.get(r.route, getUserProfile, isDev ? devRender(r) : render(r));
router.get(r.route, isDev ? devRender(r) : render(r));
}
});
... ...
const _ = require('lodash');
module.exports = (result, apiInfo) => {
if (result.code === 200 && _.isObject(apiInfo.fields)) {
console.log(apiInfo.fields);
let resData = result.data || {};
let data = {};
_.forEach(apiInfo.fields, (v, k) => {
if (!_.has(resData, k) && _.has(v, 'default')) {
data[k] = v.default;
} else {
data[k] = resData[k]
}
});
result.data = data;
}
return result;
};
... ...