Commit a037aca0 authored by 陈帅's avatar 陈帅

feat:AccountCenter ts development completed

parent 0d6fba34
export interface ITag {
key: string;
label: string;
}
export interface Province {
label: string;
key: string;
}
export interface City {
label: string;
key: string;
}
export interface Geographic {
province: Province;
city: City;
}
export interface Notice {
id: string;
title: string;
logo: string;
description: string;
updatedAt: string;
member: string;
href: string;
memberLink: string;
}
export interface CurrentUser {
name: string;
avatar: string;
userid: string;
notice: Notice[];
email: string;
signature: string;
title: string;
group: string;
tags: ITag[];
notifyCount: number;
unreadCount: number;
country: string;
geographic: Geographic;
address: string;
phone: string;
}
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { connect } from 'dva'; import { connect } from 'dva';
import { Dispatch } from 'redux';
import Link from 'umi/link'; import Link from 'umi/link';
import { RouteChildrenProps } from 'react-router';
import { Card, Row, Col, Icon, Avatar, Tag, Divider, Input } from 'antd'; import { Card, Row, Col, Icon, Avatar, Tag, Divider, Input } from 'antd';
import styles from './Center.less'; import styles from './Center.less';
import { ITag, CurrentUser } from './data';
import { ModalState } from './model';
const operationTabList = [ const operationTabList = [
{ {
...@@ -31,24 +35,53 @@ const operationTabList = [ ...@@ -31,24 +35,53 @@ const operationTabList = [
}, },
]; ];
@connect(({ loading, BLOCK_NAME_CAMEL_CASE }) => ({ interface BLOCK_NAME_CAMEL_CASEProps extends RouteChildrenProps {
dispatch: Dispatch;
currentUser: CurrentUser;
currentUserLoading: boolean;
}
interface BLOCK_NAME_CAMEL_CASEState {
newTags: ITag[];
tabKey: string;
inputVisible: boolean;
inputValue: string;
}
@connect(
({
loading,
BLOCK_NAME_CAMEL_CASE,
}: {
loading: { effects: any };
BLOCK_NAME_CAMEL_CASE: ModalState;
}) => ({
currentUser: BLOCK_NAME_CAMEL_CASE.currentUser, currentUser: BLOCK_NAME_CAMEL_CASE.currentUser,
currentUserLoading: loading.effects['BLOCK_NAME_CAMEL_CASE/fetchCurrent'], currentUserLoading: loading.effects['BLOCK_NAME_CAMEL_CASE/fetchCurrent'],
})) })
class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent { )
static getDerivedStateFromProps(props, state) { class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent<
BLOCK_NAME_CAMEL_CASEProps,
BLOCK_NAME_CAMEL_CASEState
> {
static getDerivedStateFromProps(
props: BLOCK_NAME_CAMEL_CASEProps,
state: BLOCK_NAME_CAMEL_CASEState
) {
const { match, location } = props; const { match, location } = props;
const { tabKey } = state; const { tabKey } = state;
const urlTabKey = location.pathname.replace(`${match.path}/`, ''); const path = match && match.path;
const urlTabKey = location.pathname.replace(`${path}/`, '');
if (urlTabKey && urlTabKey !== '/' && tabKey !== urlTabKey) { if (urlTabKey && urlTabKey !== '/' && tabKey !== urlTabKey) {
return { return {
tabKey: urlTabKey, tabKey: urlTabKey,
}; };
} }
return null; return null;
} }
state = { state: BLOCK_NAME_CAMEL_CASEState = {
newTags: [], newTags: [],
inputVisible: false, inputVisible: false,
inputValue: '', inputValue: '',
...@@ -62,7 +95,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent { ...@@ -62,7 +95,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent {
}); });
} }
onTabChange = key => { onTabChange = (key: string) => {
// If you need to sync state to url // If you need to sync state to url
// const { match } = this.props; // const { match } = this.props;
// router.push(`${match.url}/${key}`); // router.push(`${match.url}/${key}`);
...@@ -72,14 +105,16 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent { ...@@ -72,14 +105,16 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent {
}; };
showInput = () => { showInput = () => {
this.setState({ inputVisible: true }, () => this.input.focus()); this.setState({ inputVisible: true }, () => this.input && this.input.focus());
}; };
saveInputRef = input => { input: Input | null | undefined;
saveInputRef = (input: Input | null) => {
this.input = input; this.input = input;
}; };
handleInputChange = e => { handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ inputValue: e.target.value }); this.setState({ inputValue: e.target.value });
}; };
...@@ -130,12 +165,12 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent { ...@@ -130,12 +165,12 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent {
<Divider dashed /> <Divider dashed />
<div className={styles.tags}> <div className={styles.tags}>
<div className={styles.tagsTitle}>标签</div> <div className={styles.tagsTitle}>标签</div>
{currentUser.tags.concat(newTags).map(item => ( {currentUser.tags.concat(newTags).map(item => {
<Tag key={item.key}>{item.label}</Tag> return <Tag key={item.key}>{item.label}</Tag>;
))} })}
{inputVisible && ( {inputVisible && (
<Input <Input
ref={this.saveInputRef} ref={ref => this.saveInputRef(ref)}
type="text" type="text"
size="small" size="small"
style={{ width: 78 }} style={{ width: 78 }}
......
import { query as queryUsers, queryCurrent } from './service'; import { queryCurrent } from './service';
import { Dispatch } from 'redux';
import { CurrentUser } from './data';
export interface ModalState {
currentUser: CurrentUser;
}
type callType<T, A extends any[], R> = (thisArg?: T, ...args: A) => R;
Function.call;
export default { export default {
namespace: 'BLOCK_NAME_CAMEL_CASE', namespace: 'BLOCK_NAME_CAMEL_CASE',
state: { state: {
list: [],
currentUser: {}, currentUser: {},
}, },
effects: { effects: {
*fetch(_, { call, put }) { *fetchCurrent(
const response = yield call(queryUsers); _: ModalState,
yield put({ {
type: 'save', call,
payload: response, put,
}); }: {
}, call: callType<Function, [], Promise<any>>;
*fetchCurrent(_, { call, put }) { put: Dispatch;
}
) {
const response = yield call(queryCurrent); const response = yield call(queryCurrent);
yield put({ yield put({
type: 'saveCurrentUser', type: 'saveCurrentUser',
...@@ -26,27 +35,16 @@ export default { ...@@ -26,27 +35,16 @@ export default {
}, },
reducers: { reducers: {
save(state, action) { saveCurrentUser(
return { state: ModalState,
...state, action: {
list: action.payload, payload: CurrentUser;
}; }
}, ) {
saveCurrentUser(state, action) {
return { return {
...state, ...state,
currentUser: action.payload || {}, currentUser: action.payload || {},
}; };
}, },
changeNotifyCount(state, action) {
return {
...state,
currentUser: {
...state.currentUser,
notifyCount: action.payload.totalCount,
unreadCount: action.payload.unreadCount,
},
};
},
}, },
}; };
import request from 'umi-request'; import request from 'umi-request';
export async function query() {
return request('/api/BLOCK_NAME/users');
}
export async function queryCurrent() { export async function queryCurrent() {
return request('/api/BLOCK_NAME/currentUser'); return request('/api/BLOCK_NAME/currentUser');
} }
{ {
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "PAGES_PATH='Exception500/src' umi dev", "dev": "PAGES_PATH='AccountCenter/src' umi dev",
"lint:style": "stylelint \"src/**/*.less\" --syntax less", "lint:style": "stylelint \"src/**/*.less\" --syntax less",
"lint": "eslint --ext .js src mock tests && npm run lint:style", "lint": "eslint --ext .js src mock tests && npm run lint:style",
"lint:fix": "eslint --fix --ext .js src mock tests && npm run lint:style", "lint:fix": "eslint --fix --ext .js src mock tests && npm run lint:style",
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
"stylelint-config-standard": "^18.0.0", "stylelint-config-standard": "^18.0.0",
"umi": "^2.3.0-0", "umi": "^2.3.0-0",
"umi-plugin-block-dev": "^1.3.1", "umi-plugin-block-dev": "^1.3.1",
"umi-plugin-react": "^1.3.0-0" "umi-plugin-react": "^1.3.0-0",
"umi-request": "^1.0.0"
}, },
"lint-staged": { "lint-staged": {
"x/**/*.{js,ts,tsx,json,jsx,less}": [ "x/**/*.{js,ts,tsx,json,jsx,less}": [
......
...@@ -9,4 +9,5 @@ declare module '*.jpeg'; ...@@ -9,4 +9,5 @@ declare module '*.jpeg';
declare module '*.gif'; declare module '*.gif';
declare module '*.bmp'; declare module '*.bmp';
declare module '*.tiff'; declare module '*.tiff';
declare var APP_TYPE: string; declare var APP_TYPE: string;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment