This commit is contained in:
saplf
2019-09-08 13:03:43 +08:00
parent b004908af9
commit 5351afaae3
25 changed files with 263 additions and 14 deletions

View File

@@ -1,8 +1,10 @@
import { Model } from 'dva';
import { delay } from 'dva/saga';
import _ from 'lodash';
import { getLocale, setLocale } from 'umi-plugin-locale'
import { loadUser, storeUser, clearUser, clearMineList, clearCoins, clearDrawCoins } from '@/utils/storage';
import { User } from '@/types/common';
import { isApp, restart } from '@/utils/h5plus';
const initState = () => {
const user = loadUser();
@@ -55,7 +57,7 @@ const model: Model = {
},
*changeLang({ payload: lang }, { put }) {
setLocale(lang);
setLocale(lang, false);
yield put({ type: 'onUpdateState', payload: { lang } });
},
},

View File

@@ -1,6 +1,6 @@
import React, { useEffect } from 'react';
import { connect, DispatchProp, routerRedux } from 'dva';
import { Spin, Icon } from 'antd';
import _ from 'lodash';
import { formatMessage } from 'umi-plugin-locale';
import FittedImage from 'react-fitted-image';
import { HomeCommunityModelState } from './model';
@@ -10,6 +10,7 @@ import List from '@/components/List';
import { dispatch } from '@/utils/utils';
import styles from './style.less';
import { displayPhone } from '@/utils/transform';
const CommunityPage: React.FC<HomeCommunityModelState & DispatchProp> = ({
dispatch,
@@ -79,10 +80,10 @@ const CommunityPage: React.FC<HomeCommunityModelState & DispatchProp> = ({
{it.avatar ? <FittedImage
src={it.avatar}
fit="cover"
/> : <div className="fake">{(it.nickname && it.nickname[0]) || 'F'}</div>}
/> : <div className="fake">{(it.nickname && it.nickname[0]) || _.last(it.phone) || 'F'}</div>}
</div>
<div className="line">
<span>{it.nickname || it.phone}</span>
<span>{it.nickname || displayPhone(it.phone)}</span>
<span className="time">{formatMessage({ id: 'home.community.time' })}{it.createdAt}</span>
</div>
</div>

View File

@@ -1,6 +1,7 @@
import React from 'react';
import FittedImage from 'react-fitted-image';
import { connect, DispatchProp, routerRedux } from 'dva';
import _ from 'lodash';
import { UserModelState } from '@/models/user';
import SettingItem from '@/components/SettingItem';
import logoAccount from '@/assets/p_account.png';
@@ -24,7 +25,7 @@ const ProfilePage: React.FC<UserModelState & DispatchProp> = ({
<div className="avatar">
{user.avatar ?
<FittedImage src={user.avatar} fit="cover" /> :
<span>{user.nickname ? user.nickname[0] : user.phone[0]}</span>
<span>{user.nickname ? user.nickname[0] : _.last(user.phone)}</span>
}
</div>
<span className="name">{user.nickname || user.phone}</span>

View File

@@ -1,15 +1,17 @@
import { dispatch, getState } from './utils';
import { routerRedux } from 'dva';
const plus = window.plus;
const isApp = () => typeof plus !== 'undefined';
const isApp = () => {
const r = typeof window.plus !== 'undefined';
// console.log(r);
return r;
};
const barcodeId = 'barcode'
const scan = () => {
if (!isApp()) return Promise.resolve('');
return new Promise<string>(resolve => {
const { barcode, webview } = plus;
const { barcode, webview } = window.plus;
const bc = barcode.create(barcodeId, [barcode.QR], {
position: 'absolute',
left: '0px',
@@ -38,42 +40,48 @@ const firstPaths = [
'/home/profile',
];
const backButtonHandler = () => {
const barcode = plus.barcode.getBarcodeById(barcodeId);
const barcode = window.plus.barcode.getBarcodeById(barcodeId);
if (barcode) {
barcode.close();
return;
}
const { pathname } = getState().router.location;
if (firstPaths.includes(pathname)) {
plus.runtime.quit();
window.plus.runtime.quit();
} else {
dispatch(routerRedux.goBack());
}
};
const init = () => {
if (!isApp()) return;
plus.key.addEventListener('backbutton', backButtonHandler);
window.plus.key.addEventListener('backbutton', backButtonHandler);
};
const destory = () => {
if (!isApp()) return;
plus.key.removeEventListener('backbutton', backButtonHandler);
window.plus.key.removeEventListener('backbutton', backButtonHandler);
};
const share = (content: string) => {
if (!isApp()) return;
plus.share.sendWithSystem({
window.plus.share.sendWithSystem({
type: 'text',
content,
}, () => { });
};
const restart = () => {
if (!isApp()) return;
window.plus.runtime.restart();
}
export {
init,
isApp,
scan,
share,
destory,
restart,
};
export default {
@@ -82,4 +90,5 @@ export default {
scan,
share,
destory,
restart,
};

View File

@@ -46,3 +46,7 @@ export function fromLangToText(lang: string) {
export function encryptPwd(pwd: string): string {
return md5(pwd);
}
export function displayPhone(phone: string): string {
return `1******${_.takeRight(phone, 4).join('')}`;
}