Authored by yyq

fix init header top height

... ... @@ -20,10 +20,9 @@ Vue.mixin(titleMixin);
dayjs.locale('zh-cn');
dayjs.extend(relativeTime);
export function createApp(context) {
export function createApp(context, state = {}) {
const router = createRouter();
const store = createStore(context);
const store = createStore(context, state);
const app = new Vue({
router,
... ...
... ... @@ -13,7 +13,7 @@ import Lazy from 'vue-lazyload';
import yoho from 'common/yoho';
import sdk from 'common/sdk';
import links from 'utils/links';
import InitClient from 'utils/init-client';
import {initClient, getYohoState} from 'utils/init-client';
import 'statics/scss/common.scss';
import 'statics/scss/grass-prompt.scss';
import 'statics/font/iconfont.css';
... ... @@ -22,7 +22,7 @@ const $app = document.getElementById('app');
const isDegrade = Boolean(!($app && $app.attributes['data-server-rendered']));
const context = get(window, '__INITIAL_STATE__.yoho.context');
const {app, router, store} = createApp(context);
const {app, router, store} = createApp(context, {yoho: getYohoState()});
if (window.__INITIAL_STATE__) {
store.replaceState(window.__INITIAL_STATE__);
... ... @@ -51,7 +51,7 @@ Vue.use(ActionSheet);
Vue.prop('api', createApi(context, store));
Vue.use(Lazy, {error: ''});
InitClient(store);
initClient(store);
const trackPage = (path) => {
if (window._hmt) {
... ...
... ... @@ -9,11 +9,11 @@ import storeProduct from './product';
Vue.use(Vuex);
export function createStore(context) {
export function createStore(context, state = {}) {
const store = new Vuex.Store({
namespaced: true,
modules: {
yoho: storeYoho(),
yoho: storeYoho(state.yoho),
article: storeArticle(),
user: storeUser(),
comment: storeComment(),
... ...
import * as Types from './types';
import cookie from 'yoho-cookie';
import {merge} from 'lodash';
export default function() {
export default function(state = {}) {
return {
state: {
state: merge({
context: {
title: '',
env: {
... ... @@ -29,7 +30,7 @@ export default function() {
historys: [],
direction: 'forword',
homePage: true
},
}, state),
mutations: {
[Types.SET_SERVER_INFO](state, {context}) {
state.context.title = context.title;
... ...
... ... @@ -3,11 +3,34 @@ import cookie from 'yoho-cookie';
import yoho from 'common/yoho';
import version from 'utils/version';
export default store => {
const setStatusBar = (width, height, store) => {
const statusBar = {
statusBarStatus: false,
statusBarHeight: 0,
};
// 仅支持ios
if (yoho.isYohoBuy && yoho.isiOS) {
statusBar.statusBarHeight = (height / width) > 2.1 ? 44 : 22;
store && store.commit('SET_STATUS_BAR_HEIGHT', {
height: statusBar.statusBarHeight
});
if (version(cookie.get('app_version'),' 6.9.2') >= 0) {
statusBar.statusBarStatus = true;
store && store.commit('SET_STATUS_BAR_STATUS', {status: true});
}
}
return statusBar;
};
const initClient = (store) => {
window.onresize = () => {
const {clientWidth, clientHeight} = document.body;
store.commit('SET_WINDOW_SIZE', {clientWidth, clientHeight});
setStatusBar(clientWidth, clientHeight);
setStatusBar(clientWidth, clientHeight, store);
};
const {clientWidth, clientHeight} = document.body;
... ... @@ -34,20 +57,7 @@ export default store => {
}
});
function setStatusBar(width, height) {
// 仅支持ios
if (yoho.isYohoBuy && yoho.isiOS) {
store.commit('SET_STATUS_BAR_HEIGHT', {
height: (height / width) > 2.1 ? 44 : 22
});
if (version(cookie.get('app_version'),' 6.9.2') >= 0) {
store.commit('SET_STATUS_BAR_STATUS', {status: true});
}
}
}
setStatusBar(clientWidth, clientHeight);
setStatusBar(clientWidth, clientHeight, store);
if (/yoho/i.test(navigator.userAgent) && /supportWebp/i.test(navigator.userAgent)) {
store.commit('SET_SUPPORT_WEBP', {supportWebp: true});
... ... @@ -74,3 +84,24 @@ export default store => {
});
});
};
const getYohoState = () => {
const {clientWidth, clientHeight} = document.body;
return {
context: {
env: {
isApp: yoho.isApp,
isiOS: yoho.isiOS,
isAndroid: yoho.isAndroid,
isYohoBuy: yoho.isYohoBuy
}
},
window: setStatusBar(clientWidth, clientHeight)
}
};
export {
initClient,
getYohoState
};
... ...