提交 34a21b30f6be1d8048cce356e64d3f3f821e9c3e

作者 愚道
1 个父辈 b21df70d

init pro block advanced form

  1 +/yarn.lock
  2 +/package-lock.json
  3 +/dist
  4 +/node_modules
  5 +
  6 +.umi
  7 +.umi-production
  1 +export default {
  2 + plugins: [
  3 + ['umi-plugin-block-dev', {}],
  4 + ['umi-plugin-react', {
  5 + dva: true,
  6 + locale: true,
  7 + antd: true,
  8 + }]
  9 + ],
  10 +}
  1 +import React, { PureComponent } from 'react';
  2 +import { connect } from 'dva';
  3 +import styles from './GridContent.less';
  4 +
  5 +class GridContent extends PureComponent {
  6 + render() {
  7 + const { contentWidth, children } = this.props;
  8 + let className = `${styles.main}`;
  9 + if (contentWidth === 'Fixed') {
  10 + className = `${styles.main} ${styles.wide}`;
  11 + }
  12 + return <div className={className}>{children}</div>;
  13 + }
  14 +}
  15 +
  16 +export default connect(({ setting }) => ({
  17 + contentWidth: setting.contentWidth,
  18 +}))(GridContent);
  1 +.main {
  2 + width: 100%;
  3 + height: 100%;
  4 + min-height: 100%;
  5 + transition: 0.3s;
  6 + &.wide {
  7 + max-width: 1200px;
  8 + margin: 0 auto;
  9 + }
  10 +}
  1 +import React from 'react';
  2 +import { FormattedMessage } from 'umi/locale';
  3 +import Link from 'umi/link';
  4 +import PageHeader from 'ant-design-pro/lib/PageHeader';
  5 +import { connect } from 'dva';
  6 +import GridContent from './GridContent';
  7 +import styles from './index.less';
  8 +import MenuContext from '@/layouts/MenuContext';
  9 +
  10 +const PageHeaderWrapper = ({ children, contentWidth, wrapperClassName, top, ...restProps }) => (
  11 + <div style={{ margin: '-24px -24px 0' }} className={wrapperClassName}>
  12 + {top}
  13 + <MenuContext.Consumer>
  14 + {value => (
  15 + <PageHeader
  16 + wide={contentWidth === 'Fixed'}
  17 + home={<FormattedMessage id="menu.home" defaultMessage="Home" />}
  18 + {...value}
  19 + key="pageheader"
  20 + {...restProps}
  21 + linkElement={Link}
  22 + itemRender={item => {
  23 + if (item.locale) {
  24 + return <FormattedMessage id={item.locale} defaultMessage={item.title} />;
  25 + }
  26 + return item.title;
  27 + }}
  28 + />
  29 + )}
  30 + </MenuContext.Consumer>
  31 + {children ? (
  32 + <div className={styles.content}>
  33 + <GridContent>{children}</GridContent>
  34 + </div>
  35 + ) : null}
  36 + </div>
  37 +);
  38 +
  39 +export default connect(({ setting }) => ({
  40 + contentWidth: setting.contentWidth,
  41 +}))(PageHeaderWrapper);
  1 +@import '~antd/lib/style/themes/default.less';
  2 +
  3 +.content {
  4 + margin: 24px 24px 0;
  5 +}
  6 +
  7 +@media screen and (max-width: @screen-sm) {
  8 + .content {
  9 + margin: 24px 0 0;
  10 + }
  11 +}
  1 +import { createContext } from 'react';
  2 +
  3 +export default createContext();
  1 +import { stringify } from 'qs';
  2 +import request from '@/utils/request';
  3 +
  4 +export async function queryProjectNotice() {
  5 + return request('/api/project/notice');
  6 +}
  7 +
  8 +export async function queryActivities() {
  9 + return request('/api/activities');
  10 +}
  11 +
  12 +export async function queryRule(params) {
  13 + return request(`/api/rule?${stringify(params)}`);
  14 +}
  15 +
  16 +export async function removeRule(params) {
  17 + return request('/api/rule', {
  18 + method: 'POST',
  19 + body: {
  20 + ...params,
  21 + method: 'delete',
  22 + },
  23 + });
  24 +}
  25 +
  26 +export async function addRule(params) {
  27 + return request('/api/rule', {
  28 + method: 'POST',
  29 + body: {
  30 + ...params,
  31 + method: 'post',
  32 + },
  33 + });
  34 +}
  35 +
  36 +export async function updateRule(params) {
  37 + return request('/api/rule', {
  38 + method: 'POST',
  39 + body: {
  40 + ...params,
  41 + method: 'update',
  42 + },
  43 + });
  44 +}
  45 +
  46 +export async function fakeSubmitForm(params) {
  47 + return request('/api/forms', {
  48 + method: 'POST',
  49 + body: params,
  50 + });
  51 +}
  52 +
  53 +export async function fakeChartData() {
  54 + return request('/api/fake_chart_data');
  55 +}
  56 +
  57 +export async function queryTags() {
  58 + return request('/api/tags');
  59 +}
  60 +
  61 +export async function queryBasicProfile() {
  62 + return request('/api/profile/basic');
  63 +}
  64 +
  65 +export async function queryAdvancedProfile() {
  66 + return request('/api/profile/advanced');
  67 +}
  68 +
  69 +export async function queryFakeList(params) {
  70 + return request(`/api/fake_list?${stringify(params)}`);
  71 +}
  72 +
  73 +export async function removeFakeList(params) {
  74 + const { count = 5, ...restParams } = params;
  75 + return request(`/api/fake_list?count=${count}`, {
  76 + method: 'POST',
  77 + body: {
  78 + ...restParams,
  79 + method: 'delete',
  80 + },
  81 + });
  82 +}
  83 +
  84 +export async function addFakeList(params) {
  85 + const { count = 5, ...restParams } = params;
  86 + return request(`/api/fake_list?count=${count}`, {
  87 + method: 'POST',
  88 + body: {
  89 + ...restParams,
  90 + method: 'post',
  91 + },
  92 + });
  93 +}
  94 +
  95 +export async function updateFakeList(params) {
  96 + const { count = 5, ...restParams } = params;
  97 + return request(`/api/fake_list?count=${count}`, {
  98 + method: 'POST',
  99 + body: {
  100 + ...restParams,
  101 + method: 'update',
  102 + },
  103 + });
  104 +}
  105 +
  106 +export async function fakeAccountLogin(params) {
  107 + return request('/api/login/account', {
  108 + method: 'POST',
  109 + body: params,
  110 + });
  111 +}
  112 +
  113 +export async function fakeRegister(params) {
  114 + return request('/api/register', {
  115 + method: 'POST',
  116 + body: params,
  117 + });
  118 +}
  119 +
  120 +export async function queryNotices() {
  121 + return request('/api/notices');
  122 +}
  123 +
  124 +export async function getFakeCaptcha(mobile) {
  125 + return request(`/api/captcha?mobile=${mobile}`);
  126 +}
  1 +import fetch from 'dva/fetch';
  2 +import { notification } from 'antd';
  3 +import router from 'umi/router';
  4 +import hash from 'hash.js';
  5 +import { isAntdPro } from './utils';
  6 +
  7 +const codeMessage = {
  8 + 200: '服务器成功返回请求的数据。',
  9 + 201: '新建或修改数据成功。',
  10 + 202: '一个请求已经进入后台排队(异步任务)。',
  11 + 204: '删除数据成功。',
  12 + 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
  13 + 401: '用户没有权限(令牌、用户名、密码错误)。',
  14 + 403: '用户得到授权,但是访问是被禁止的。',
  15 + 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
  16 + 406: '请求的格式不可得。',
  17 + 410: '请求的资源被永久删除,且不会再得到的。',
  18 + 422: '当创建一个对象时,发生一个验证错误。',
  19 + 500: '服务器发生错误,请检查服务器。',
  20 + 502: '网关错误。',
  21 + 503: '服务不可用,服务器暂时过载或维护。',
  22 + 504: '网关超时。',
  23 +};
  24 +
  25 +const checkStatus = response => {
  26 + if (response.status >= 200 && response.status < 300) {
  27 + return response;
  28 + }
  29 + const errortext = codeMessage[response.status] || response.statusText;
  30 + notification.error({
  31 + message: `请求错误 ${response.status}: ${response.url}`,
  32 + description: errortext,
  33 + });
  34 + const error = new Error(errortext);
  35 + error.name = response.status;
  36 + error.response = response;
  37 + throw error;
  38 +};
  39 +
  40 +const cachedSave = (response, hashcode) => {
  41 + /**
  42 + * Clone a response data and store it in sessionStorage
  43 + * Does not support data other than json, Cache only json
  44 + */
  45 + const contentType = response.headers.get('Content-Type');
  46 + if (contentType && contentType.match(/application\/json/i)) {
  47 + // All data is saved as text
  48 + response
  49 + .clone()
  50 + .text()
  51 + .then(content => {
  52 + sessionStorage.setItem(hashcode, content);
  53 + sessionStorage.setItem(`${hashcode}:timestamp`, Date.now());
  54 + });
  55 + }
  56 + return response;
  57 +};
  58 +
  59 +/**
  60 + * Requests a URL, returning a promise.
  61 + *
  62 + * @param {string} url The URL we want to request
  63 + * @param {object} [option] The options we want to pass to "fetch"
  64 + * @return {object} An object containing either "data" or "err"
  65 + */
  66 +export default function request(url, option) {
  67 + const options = {
  68 + expirys: isAntdPro(),
  69 + ...option,
  70 + };
  71 + /**
  72 + * Produce fingerprints based on url and parameters
  73 + * Maybe url has the same parameters
  74 + */
  75 + const fingerprint = url + (options.body ? JSON.stringify(options.body) : '');
  76 + const hashcode = hash
  77 + .sha256()
  78 + .update(fingerprint)
  79 + .digest('hex');
  80 +
  81 + const defaultOptions = {
  82 + credentials: 'include',
  83 + };
  84 + const newOptions = { ...defaultOptions, ...options };
  85 + if (
  86 + newOptions.method === 'POST' ||
  87 + newOptions.method === 'PUT' ||
  88 + newOptions.method === 'DELETE'
  89 + ) {
  90 + if (!(newOptions.body instanceof FormData)) {
  91 + newOptions.headers = {
  92 + Accept: 'application/json',
  93 + 'Content-Type': 'application/json; charset=utf-8',
  94 + ...newOptions.headers,
  95 + };
  96 + newOptions.body = JSON.stringify(newOptions.body);
  97 + } else {
  98 + // newOptions.body is FormData
  99 + newOptions.headers = {
  100 + Accept: 'application/json',
  101 + ...newOptions.headers,
  102 + };
  103 + }
  104 + }
  105 +
  106 + const expirys = options.expirys && 60;
  107 + // options.expirys !== false, return the cache,
  108 + if (options.expirys !== false) {
  109 + const cached = sessionStorage.getItem(hashcode);
  110 + const whenCached = sessionStorage.getItem(`${hashcode}:timestamp`);
  111 + if (cached !== null && whenCached !== null) {
  112 + const age = (Date.now() - whenCached) / 1000;
  113 + if (age < expirys) {
  114 + const response = new Response(new Blob([cached]));
  115 + return response.json();
  116 + }
  117 + sessionStorage.removeItem(hashcode);
  118 + sessionStorage.removeItem(`${hashcode}:timestamp`);
  119 + }
  120 + }
  121 + return fetch(url, newOptions)
  122 + .then(checkStatus)
  123 + .then(response => cachedSave(response, hashcode))
  124 + .then(response => {
  125 + // DELETE and 204 do not return data by default
  126 + // using .json will report an error.
  127 + if (newOptions.method === 'DELETE' || response.status === 204) {
  128 + return response.text();
  129 + }
  130 + return response.json();
  131 + })
  132 + .catch(e => {
  133 + const status = e.name;
  134 + if (status === 401) {
  135 + // @HACK
  136 + /* eslint-disable no-underscore-dangle */
  137 + window.g_app._store.dispatch({
  138 + type: 'login/logout',
  139 + });
  140 + return;
  141 + }
  142 + // environment should not be used
  143 + if (status === 403) {
  144 + router.push('/exception/403');
  145 + return;
  146 + }
  147 + if (status <= 504 && status >= 500) {
  148 + router.push('/exception/500');
  149 + return;
  150 + }
  151 + if (status >= 404 && status < 422) {
  152 + router.push('/exception/404');
  153 + }
  154 + });
  155 +}
  1 +import moment from 'moment';
  2 +import React from 'react';
  3 +import nzh from 'nzh/cn';
  4 +import { parse, stringify } from 'qs';
  5 +
  6 +export function fixedZero(val) {
  7 + return val * 1 < 10 ? `0${val}` : val;
  8 +}
  9 +
  10 +export function getTimeDistance(type) {
  11 + const now = new Date();
  12 + const oneDay = 1000 * 60 * 60 * 24;
  13 +
  14 + if (type === 'today') {
  15 + now.setHours(0);
  16 + now.setMinutes(0);
  17 + now.setSeconds(0);
  18 + return [moment(now), moment(now.getTime() + (oneDay - 1000))];
  19 + }
  20 +
  21 + if (type === 'week') {
  22 + let day = now.getDay();
  23 + now.setHours(0);
  24 + now.setMinutes(0);
  25 + now.setSeconds(0);
  26 +
  27 + if (day === 0) {
  28 + day = 6;
  29 + } else {
  30 + day -= 1;
  31 + }
  32 +
  33 + const beginTime = now.getTime() - day * oneDay;
  34 +
  35 + return [moment(beginTime), moment(beginTime + (7 * oneDay - 1000))];
  36 + }
  37 +
  38 + if (type === 'month') {
  39 + const year = now.getFullYear();
  40 + const month = now.getMonth();
  41 + const nextDate = moment(now).add(1, 'months');
  42 + const nextYear = nextDate.year();
  43 + const nextMonth = nextDate.month();
  44 +
  45 + return [
  46 + moment(`${year}-${fixedZero(month + 1)}-01 00:00:00`),
  47 + moment(moment(`${nextYear}-${fixedZero(nextMonth + 1)}-01 00:00:00`).valueOf() - 1000),
  48 + ];
  49 + }
  50 +
  51 + const year = now.getFullYear();
  52 + return [moment(`${year}-01-01 00:00:00`), moment(`${year}-12-31 23:59:59`)];
  53 +}
  54 +
  55 +export function getPlainNode(nodeList, parentPath = '') {
  56 + const arr = [];
  57 + nodeList.forEach(node => {
  58 + const item = node;
  59 + item.path = `${parentPath}/${item.path || ''}`.replace(/\/+/g, '/');
  60 + item.exact = true;
  61 + if (item.children && !item.component) {
  62 + arr.push(...getPlainNode(item.children, item.path));
  63 + } else {
  64 + if (item.children && item.component) {
  65 + item.exact = false;
  66 + }
  67 + arr.push(item);
  68 + }
  69 + });
  70 + return arr;
  71 +}
  72 +
  73 +export function digitUppercase(n) {
  74 + return nzh.toMoney(n);
  75 +}
  76 +
  77 +function getRelation(str1, str2) {
  78 + if (str1 === str2) {
  79 + console.warn('Two path are equal!'); // eslint-disable-line
  80 + }
  81 + const arr1 = str1.split('/');
  82 + const arr2 = str2.split('/');
  83 + if (arr2.every((item, index) => item === arr1[index])) {
  84 + return 1;
  85 + }
  86 + if (arr1.every((item, index) => item === arr2[index])) {
  87 + return 2;
  88 + }
  89 + return 3;
  90 +}
  91 +
  92 +function getRenderArr(routes) {
  93 + let renderArr = [];
  94 + renderArr.push(routes[0]);
  95 + for (let i = 1; i < routes.length; i += 1) {
  96 + // 去重
  97 + renderArr = renderArr.filter(item => getRelation(item, routes[i]) !== 1);
  98 + // 是否包含
  99 + const isAdd = renderArr.every(item => getRelation(item, routes[i]) === 3);
  100 + if (isAdd) {
  101 + renderArr.push(routes[i]);
  102 + }
  103 + }
  104 + return renderArr;
  105 +}
  106 +
  107 +/**
  108 + * Get router routing configuration
  109 + * { path:{name,...param}}=>Array<{name,path ...param}>
  110 + * @param {string} path
  111 + * @param {routerData} routerData
  112 + */
  113 +export function getRoutes(path, routerData) {
  114 + let routes = Object.keys(routerData).filter(
  115 + routePath => routePath.indexOf(path) === 0 && routePath !== path
  116 + );
  117 + // Replace path to '' eg. path='user' /user/name => name
  118 + routes = routes.map(item => item.replace(path, ''));
  119 + // Get the route to be rendered to remove the deep rendering
  120 + const renderArr = getRenderArr(routes);
  121 + // Conversion and stitching parameters
  122 + const renderRoutes = renderArr.map(item => {
  123 + const exact = !routes.some(route => route !== item && getRelation(route, item) === 1);
  124 + return {
  125 + exact,
  126 + ...routerData[`${path}${item}`],
  127 + key: `${path}${item}`,
  128 + path: `${path}${item}`,
  129 + };
  130 + });
  131 + return renderRoutes;
  132 +}
  133 +
  134 +export function getPageQuery() {
  135 + return parse(window.location.href.split('?')[1]);
  136 +}
  137 +
  138 +export function getQueryPath(path = '', query = {}) {
  139 + const search = stringify(query);
  140 + if (search.length) {
  141 + return `${path}?${search}`;
  142 + }
  143 + return path;
  144 +}
  145 +
  146 +/* eslint no-useless-escape:0 */
  147 +const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
  148 +
  149 +export function isUrl(path) {
  150 + return reg.test(path);
  151 +}
  152 +
  153 +export function formatWan(val) {
  154 + const v = val * 1;
  155 + if (!v || Number.isNaN(v)) return '';
  156 +
  157 + let result = val;
  158 + if (val > 10000) {
  159 + result = Math.floor(val / 10000);
  160 + result = (
  161 + <span>
  162 + {result}
  163 + <span
  164 + style={{
  165 + position: 'relative',
  166 + top: -2,
  167 + fontSize: 14,
  168 + fontStyle: 'normal',
  169 + marginLeft: 2,
  170 + }}
  171 + >
  172 +
  173 + </span>
  174 + </span>
  175 + );
  176 + }
  177 + return result;
  178 +}
  179 +
  180 +// 给官方演示站点用,用于关闭真实开发环境不需要使用的特性
  181 +export function isAntdPro() {
  182 + return window.location.hostname === 'preview.pro.ant.design';
  183 +}
  1 +# @umi-material/advancedform
  2 +
  3 +AdvancedForm
  4 +
  5 +## Usage
  6 +
  7 +```sh
  8 +umi block https://github.com/umijs/umi-blocks/tree/master/advancedform
  9 +```
  10 +
  11 +## LICENSE
  12 +
  13 +MIT
  1 +{
  2 + "name": "@umi-block/advancedform",
  3 + "version": "0.0.1",
  4 + "description": "AdvancedForm",
  5 + "main": "src/index.js",
  6 + "scripts": {
  7 + "dev": "umi dev"
  8 + },
  9 + "repository": {
  10 + "type": "git",
  11 + "url": "https://github.com/umijs/umi-blocks/advancedform"
  12 + },
  13 + "dependencies": {
  14 + "react": "^16.6.3",
  15 + "dva": "^2.4.0",
  16 + "ant-design-pro": "^2.1.1",
  17 + "antd": "^3.10.9",
  18 + "lodash": "^4.17.10",
  19 + "qs": "^6.6.0",
  20 + "hash.js": "^1.1.5",
  21 + "moment": "^2.22.2",
  22 + "nzh": "^1.0.3",
  23 + "mockjs": "*"
  24 + },
  25 + "devDependencies": {
  26 + "umi": "^2.3.0-beta.1",
  27 + "umi-plugin-react": "^1.3.0-beta.1",
  28 + "umi-plugin-block-dev": "^1.0.0"
  29 + },
  30 + "license": "ISC"
  31 +}
  1 +import React, { PureComponent, Fragment } from 'react';
  2 +import { Table, Button, Input, message, Popconfirm, Divider } from 'antd';
  3 +import isEqual from 'lodash/isEqual';
  4 +import styles from './style.less';
  5 +
  6 +class TableForm extends PureComponent {
  7 + index = 0;
  8 +
  9 + cacheOriginData = {};
  10 +
  11 + constructor(props) {
  12 + super(props);
  13 +
  14 + this.state = {
  15 + data: props.value,
  16 + loading: false,
  17 + /* eslint-disable-next-line react/no-unused-state */
  18 + value: props.value,
  19 + };
  20 + }
  21 +
  22 + static getDerivedStateFromProps(nextProps, preState) {
  23 + if (isEqual(nextProps.value, preState.value)) {
  24 + return null;
  25 + }
  26 + return {
  27 + data: nextProps.value,
  28 + value: nextProps.value,
  29 + };
  30 + }
  31 +
  32 + getRowByKey(key, newData) {
  33 + const { data } = this.state;
  34 + return (newData || data).filter(item => item.key === key)[0];
  35 + }
  36 +
  37 + toggleEditable = (e, key) => {
  38 + e.preventDefault();
  39 + const { data } = this.state;
  40 + const newData = data.map(item => ({ ...item }));
  41 + const target = this.getRowByKey(key, newData);
  42 + if (target) {
  43 + // 进入编辑状态时保存原始数据
  44 + if (!target.editable) {
  45 + this.cacheOriginData[key] = { ...target };
  46 + }
  47 + target.editable = !target.editable;
  48 + this.setState({ data: newData });
  49 + }
  50 + };
  51 +
  52 + newMember = () => {
  53 + const { data } = this.state;
  54 + const newData = data.map(item => ({ ...item }));
  55 + newData.push({
  56 + key: `NEW_TEMP_ID_${this.index}`,
  57 + workId: '',
  58 + name: '',
  59 + department: '',
  60 + editable: true,
  61 + isNew: true,
  62 + });
  63 + this.index += 1;
  64 + this.setState({ data: newData });
  65 + };
  66 +
  67 + remove(key) {
  68 + const { data } = this.state;
  69 + const { onChange } = this.props;
  70 + const newData = data.filter(item => item.key !== key);
  71 + this.setState({ data: newData });
  72 + onChange(newData);
  73 + }
  74 +
  75 + handleKeyPress(e, key) {
  76 + if (e.key === 'Enter') {
  77 + this.saveRow(e, key);
  78 + }
  79 + }
  80 +
  81 + handleFieldChange(e, fieldName, key) {
  82 + const { data } = this.state;
  83 + const newData = data.map(item => ({ ...item }));
  84 + const target = this.getRowByKey(key, newData);
  85 + if (target) {
  86 + target[fieldName] = e.target.value;
  87 + this.setState({ data: newData });
  88 + }
  89 + }
  90 +
  91 + saveRow(e, key) {
  92 + e.persist();
  93 + this.setState({
  94 + loading: true,
  95 + });
  96 + setTimeout(() => {
  97 + if (this.clickedCancel) {
  98 + this.clickedCancel = false;
  99 + return;
  100 + }
  101 + const target = this.getRowByKey(key) || {};
  102 + if (!target.workId || !target.name || !target.department) {
  103 + message.error('请填写完整成员信息。');
  104 + e.target.focus();
  105 + this.setState({
  106 + loading: false,
  107 + });
  108 + return;
  109 + }
  110 + delete target.isNew;
  111 + this.toggleEditable(e, key);
  112 + const { data } = this.state;
  113 + const { onChange } = this.props;
  114 + onChange(data);
  115 + this.setState({
  116 + loading: false,
  117 + });
  118 + }, 500);
  119 + }
  120 +
  121 + cancel(e, key) {
  122 + this.clickedCancel = true;
  123 + e.preventDefault();
  124 + const { data } = this.state;
  125 + const newData = data.map(item => ({ ...item }));
  126 + const target = this.getRowByKey(key, newData);
  127 + if (this.cacheOriginData[key]) {
  128 + Object.assign(target, this.cacheOriginData[key]);
  129 + delete this.cacheOriginData[key];
  130 + }
  131 + target.editable = false;
  132 + this.setState({ data: newData });
  133 + this.clickedCancel = false;
  134 + }
  135 +
  136 + render() {
  137 + const columns = [
  138 + {
  139 + title: '成员姓名',
  140 + dataIndex: 'name',
  141 + key: 'name',
  142 + width: '20%',
  143 + render: (text, record) => {
  144 + if (record.editable) {
  145 + return (
  146 + <Input
  147 + value={text}
  148 + autoFocus
  149 + onChange={e => this.handleFieldChange(e, 'name', record.key)}
  150 + onKeyPress={e => this.handleKeyPress(e, record.key)}
  151 + placeholder="成员姓名"
  152 + />
  153 + );
  154 + }
  155 + return text;
  156 + },
  157 + },
  158 + {
  159 + title: '工号',
  160 + dataIndex: 'workId',
  161 + key: 'workId',
  162 + width: '20%',
  163 + render: (text, record) => {
  164 + if (record.editable) {
  165 + return (
  166 + <Input
  167 + value={text}
  168 + onChange={e => this.handleFieldChange(e, 'workId', record.key)}
  169 + onKeyPress={e => this.handleKeyPress(e, record.key)}
  170 + placeholder="工号"
  171 + />
  172 + );
  173 + }
  174 + return text;
  175 + },
  176 + },
  177 + {
  178 + title: '所属部门',
  179 + dataIndex: 'department',
  180 + key: 'department',
  181 + width: '40%',
  182 + render: (text, record) => {
  183 + if (record.editable) {
  184 + return (
  185 + <Input
  186 + value={text}
  187 + onChange={e => this.handleFieldChange(e, 'department', record.key)}
  188 + onKeyPress={e => this.handleKeyPress(e, record.key)}
  189 + placeholder="所属部门"
  190 + />
  191 + );
  192 + }
  193 + return text;
  194 + },
  195 + },
  196 + {
  197 + title: '操作',
  198 + key: 'action',
  199 + render: (text, record) => {
  200 + const { loading } = this.state;
  201 + if (!!record.editable && loading) {
  202 + return null;
  203 + }
  204 + if (record.editable) {
  205 + if (record.isNew) {
  206 + return (
  207 + <span>
  208 + <a onClick={e => this.saveRow(e, record.key)}>添加</a>
  209 + <Divider type="vertical" />
  210 + <Popconfirm title="是否要删除此行?" onConfirm={() => this.remove(record.key)}>
  211 + <a>删除</a>
  212 + </Popconfirm>
  213 + </span>
  214 + );
  215 + }
  216 + return (
  217 + <span>
  218 + <a onClick={e => this.saveRow(e, record.key)}>保存</a>
  219 + <Divider type="vertical" />
  220 + <a onClick={e => this.cancel(e, record.key)}>取消</a>
  221 + </span>
  222 + );
  223 + }
  224 + return (
  225 + <span>
  226 + <a onClick={e => this.toggleEditable(e, record.key)}>编辑</a>
  227 + <Divider type="vertical" />
  228 + <Popconfirm title="是否要删除此行?" onConfirm={() => this.remove(record.key)}>
  229 + <a>删除</a>
  230 + </Popconfirm>
  231 + </span>
  232 + );
  233 + },
  234 + },
  235 + ];
  236 +
  237 + const { loading, data } = this.state;
  238 +
  239 + return (
  240 + <Fragment>
  241 + <Table
  242 + loading={loading}
  243 + columns={columns}
  244 + dataSource={data}
  245 + pagination={false}
  246 + rowClassName={record => (record.editable ? styles.editable : '')}
  247 + />
  248 + <Button
  249 + style={{ width: '100%', marginTop: 16, marginBottom: 8 }}
  250 + type="dashed"
  251 + onClick={this.newMember}
  252 + icon="plus"
  253 + >
  254 + 新增成员
  255 + </Button>
  256 + </Fragment>
  257 + );
  258 + }
  259 +}
  260 +
  261 +export default TableForm;
  1 +import mockjs from 'mockjs';
  2 +
  3 +const titles = [
  4 + 'Alipay',
  5 + 'Angular',
  6 + 'Ant Design',
  7 + 'Ant Design Pro',
  8 + 'Bootstrap',
  9 + 'React',
  10 + 'Vue',
  11 + 'Webpack',
  12 +];
  13 +const avatars = [
  14 + 'https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png', // Alipay
  15 + 'https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png', // Angular
  16 + 'https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png', // Ant Design
  17 + 'https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png', // Ant Design Pro
  18 + 'https://gw.alipayobjects.com/zos/rmsportal/siCrBXXhmvTQGWPNLBow.png', // Bootstrap
  19 + 'https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png', // React
  20 + 'https://gw.alipayobjects.com/zos/rmsportal/ComBAopevLwENQdKWiIn.png', // Vue
  21 + 'https://gw.alipayobjects.com/zos/rmsportal/nxkuOJlFJuAUhzlMTCEe.png', // Webpack
  22 +];
  23 +
  24 +const avatars2 = [
  25 + 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
  26 + 'https://gw.alipayobjects.com/zos/rmsportal/cnrhVkzwxjPwAaCfPbdc.png',
  27 + 'https://gw.alipayobjects.com/zos/rmsportal/gaOngJwsRYRaVAuXXcmB.png',
  28 + 'https://gw.alipayobjects.com/zos/rmsportal/ubnKSIfAJTxIgXOKlciN.png',
  29 + 'https://gw.alipayobjects.com/zos/rmsportal/WhxKECPNujWoWEFNdnJE.png',
  30 + 'https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png',
  31 + 'https://gw.alipayobjects.com/zos/rmsportal/psOgztMplJMGpVEqfcgF.png',
  32 + 'https://gw.alipayobjects.com/zos/rmsportal/ZpBqSxLxVEXfcUNoPKrz.png',
  33 + 'https://gw.alipayobjects.com/zos/rmsportal/laiEnJdGHVOhJrUShBaJ.png',
  34 + 'https://gw.alipayobjects.com/zos/rmsportal/UrQsqscbKEpNuJcvBZBu.png',
  35 +];
  36 +
  37 +const covers = [
  38 + 'https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png',
  39 + 'https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png',
  40 + 'https://gw.alipayobjects.com/zos/rmsportal/iXjVmWVHbCJAyqvDxdtx.png',
  41 + 'https://gw.alipayobjects.com/zos/rmsportal/gLaIAoVWTtLbBWZNYEMg.png',
  42 +];
  43 +const desc = [
  44 + '那是一种内在的东西, 他们到达不了,也无法触及的',
  45 + '希望是一个好东西,也许是最好的,好东西是不会消亡的',
  46 + '生命就像一盒巧克力,结果往往出人意料',
  47 + '城镇中有那么多的酒馆,她却偏偏走进了我的酒馆',
  48 + '那时候我只会想自己想要什么,从不想自己拥有什么',
  49 +];
  50 +
  51 +const user = [
  52 + '付小小',
  53 + '曲丽丽',
  54 + '林东东',
  55 + '周星星',
  56 + '吴加好',
  57 + '朱偏右',
  58 + '鱼酱',
  59 + '乐哥',
  60 + '谭小仪',
  61 + '仲尼',
  62 +];
  63 +
  64 +function fakeList(count) {
  65 + const list = [];
  66 + for (let i = 0; i < count; i += 1) {
  67 + list.push({
  68 + id: `fake-list-${i}`,
  69 + owner: user[i % 10],
  70 + title: titles[i % 8],
  71 + avatar: avatars[i % 8],
  72 + cover: parseInt(i / 4, 10) % 2 === 0 ? covers[i % 4] : covers[3 - (i % 4)],
  73 + status: ['active', 'exception', 'normal'][i % 3],
  74 + percent: Math.ceil(Math.random() * 50) + 50,
  75 + logo: avatars[i % 8],
  76 + href: 'https://ant.design',
  77 + updatedAt: new Date(new Date().getTime() - 1000 * 60 * 60 * 2 * i),
  78 + createdAt: new Date(new Date().getTime() - 1000 * 60 * 60 * 2 * i),
  79 + subDescription: desc[i % 5],
  80 + description:
  81 + '在中台产品的研发过程中,会出现不同的设计规范和实现方式,但其中往往存在很多类似的页面和组件,这些类似的组件会被抽离成一套标准规范。',
  82 + activeUser: Math.ceil(Math.random() * 100000) + 100000,
  83 + newUser: Math.ceil(Math.random() * 1000) + 1000,
  84 + star: Math.ceil(Math.random() * 100) + 100,
  85 + like: Math.ceil(Math.random() * 100) + 100,
  86 + message: Math.ceil(Math.random() * 10) + 10,
  87 + content:
  88 + '段落示意:蚂蚁金服设计平台 ant.design,用最小的工作量,无缝接入蚂蚁金服生态,提供跨越设计与开发的体验解决方案。蚂蚁金服设计平台 ant.design,用最小的工作量,无缝接入蚂蚁金服生态,提供跨越设计与开发的体验解决方案。',
  89 + members: [
  90 + {
  91 + avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ZiESqWwCXBRQoaPONSJe.png',
  92 + name: '曲丽丽',
  93 + id: 'member1',
  94 + },
  95 + {
  96 + avatar: 'https://gw.alipayobjects.com/zos/rmsportal/tBOxZPlITHqwlGjsJWaF.png',
  97 + name: '王昭君',
  98 + id: 'member2',
  99 + },
  100 + {
  101 + avatar: 'https://gw.alipayobjects.com/zos/rmsportal/sBxjgqiuHMGRkIjqlQCd.png',
  102 + name: '董娜娜',
  103 + id: 'member3',
  104 + },
  105 + ],
  106 + });
  107 + }
  108 +
  109 + return list;
  110 +}
  111 +
  112 +let sourceData;
  113 +
  114 +function getFakeList(req, res) {
  115 + const params = req.query;
  116 +
  117 + const count = params.count * 1 || 20;
  118 +
  119 + const result = fakeList(count);
  120 + sourceData = result;
  121 + return res.json(result);
  122 +}
  123 +
  124 +function postFakeList(req, res) {
  125 + const { /* url = '', */ body } = req;
  126 + // const params = getUrlParams(url);
  127 + const { method, id } = body;
  128 + // const count = (params.count * 1) || 20;
  129 + let result = sourceData;
  130 +
  131 + switch (method) {
  132 + case 'delete':
  133 + result = result.filter(item => item.id !== id);
  134 + break;
  135 + case 'update':
  136 + result.forEach((item, i) => {
  137 + if (item.id === id) {
  138 + result[i] = Object.assign(item, body);
  139 + }
  140 + });
  141 + break;
  142 + case 'post':
  143 + result.unshift({
  144 + body,
  145 + id: `fake-list-${result.length}`,
  146 + createdAt: new Date().getTime(),
  147 + });
  148 + break;
  149 + default:
  150 + break;
  151 + }
  152 +
  153 + return res.json(result);
  154 +}
  155 +
  156 +const getNotice = [
  157 + {
  158 + id: 'xxx1',
  159 + title: titles[0],
  160 + logo: avatars[0],
  161 + description: '那是一种内在的东西,他们到达不了,也无法触及的',
  162 + updatedAt: new Date(),
  163 + member: '科学搬砖组',
  164 + href: '',
  165 + memberLink: '',
  166 + },
  167 + {
  168 + id: 'xxx2',
  169 + title: titles[1],
  170 + logo: avatars[1],
  171 + description: '希望是一个好东西,也许是最好的,好东西是不会消亡的',
  172 + updatedAt: new Date('2017-07-24'),
  173 + member: '全组都是吴彦祖',
  174 + href: '',
  175 + memberLink: '',
  176 + },
  177 + {
  178 + id: 'xxx3',
  179 + title: titles[2],
  180 + logo: avatars[2],
  181 + description: '城镇中有那么多的酒馆,她却偏偏走进了我的酒馆',
  182 + updatedAt: new Date(),
  183 + member: '中二少女团',
  184 + href: '',
  185 + memberLink: '',
  186 + },
  187 + {
  188 + id: 'xxx4',
  189 + title: titles[3],
  190 + logo: avatars[3],
  191 + description: '那时候我只会想自己想要什么,从不想自己拥有什么',
  192 + updatedAt: new Date('2017-07-23'),
  193 + member: '程序员日常',
  194 + href: '',
  195 + memberLink: '',
  196 + },
  197 + {
  198 + id: 'xxx5',
  199 + title: titles[4],
  200 + logo: avatars[4],
  201 + description: '凛冬将至',
  202 + updatedAt: new Date('2017-07-23'),
  203 + member: '高逼格设计天团',
  204 + href: '',
  205 + memberLink: '',
  206 + },
  207 + {
  208 + id: 'xxx6',
  209 + title: titles[5],
  210 + logo: avatars[5],
  211 + description: '生命就像一盒巧克力,结果往往出人意料',
  212 + updatedAt: new Date('2017-07-23'),
  213 + member: '骗你来学计算机',
  214 + href: '',
  215 + memberLink: '',
  216 + },
  217 +];
  218 +
  219 +const getActivities = [
  220 + {
  221 + id: 'trend-1',
  222 + updatedAt: new Date(),
  223 + user: {
  224 + name: '曲丽丽',
  225 + avatar: avatars2[0],
  226 + },
  227 + group: {
  228 + name: '高逼格设计天团',
  229 + link: 'http://github.com/',
  230 + },
  231 + project: {
  232 + name: '六月迭代',
  233 + link: 'http://github.com/',
  234 + },
  235 + template: '在 @{group} 新建项目 @{project}',
  236 + },
  237 + {
  238 + id: 'trend-2',
  239 + updatedAt: new Date(),
  240 + user: {
  241 + name: '付小小',
  242 + avatar: avatars2[1],
  243 + },
  244 + group: {
  245 + name: '高逼格设计天团',
  246 + link: 'http://github.com/',
  247 + },
  248 + project: {
  249 + name: '六月迭代',
  250 + link: 'http://github.com/',
  251 + },
  252 + template: '在 @{group} 新建项目 @{project}',
  253 + },
  254 + {
  255 + id: 'trend-3',
  256 + updatedAt: new Date(),
  257 + user: {
  258 + name: '林东东',
  259 + avatar: avatars2[2],
  260 + },
  261 + group: {
  262 + name: '中二少女团',
  263 + link: 'http://github.com/',
  264 + },
  265 + project: {
  266 + name: '六月迭代',
  267 + link: 'http://github.com/',
  268 + },
  269 + template: '在 @{group} 新建项目 @{project}',
  270 + },
  271 + {
  272 + id: 'trend-4',
  273 + updatedAt: new Date(),
  274 + user: {
  275 + name: '周星星',
  276 + avatar: avatars2[4],
  277 + },
  278 + project: {
  279 + name: '5 月日常迭代',
  280 + link: 'http://github.com/',
  281 + },
  282 + template: '将 @{project} 更新至已发布状态',
  283 + },
  284 + {
  285 + id: 'trend-5',
  286 + updatedAt: new Date(),
  287 + user: {
  288 + name: '朱偏右',
  289 + avatar: avatars2[3],
  290 + },
  291 + project: {
  292 + name: '工程效能',
  293 + link: 'http://github.com/',
  294 + },
  295 + comment: {
  296 + name: '留言',
  297 + link: 'http://github.com/',
  298 + },
  299 + template: '在 @{project} 发布了 @{comment}',
  300 + },
  301 + {
  302 + id: 'trend-6',
  303 + updatedAt: new Date(),
  304 + user: {
  305 + name: '乐哥',
  306 + avatar: avatars2[5],
  307 + },
  308 + group: {
  309 + name: '程序员日常',
  310 + link: 'http://github.com/',
  311 + },
  312 + project: {
  313 + name: '品牌迭代',
  314 + link: 'http://github.com/',
  315 + },
  316 + template: '在 @{group} 新建项目 @{project}',
  317 + },
  318 +];
  319 +
  320 +function getFakeCaptcha(req, res) {
  321 + return res.json('captcha-xxx');
  322 +}
  323 +
  324 +export default {
  325 + 'GET /api/project/notice': getNotice,
  326 + 'GET /api/activities': getActivities,
  327 + 'POST /api/forms': (req, res) => {
  328 + res.send({ message: 'Ok' });
  329 + },
  330 + 'GET /api/tags': mockjs.mock({
  331 + 'list|100': [{ name: '@city', 'value|1-100': 150, 'type|0-2': 1 }],
  332 + }),
  333 + 'GET /api/fake_list': getFakeList,
  334 + 'POST /api/fake_list': postFakeList,
  335 + 'GET /api/captcha': getFakeCaptcha,
  336 +};
  1 +module.exports = {
  2 + navTheme: 'dark', // theme for nav menu
  3 + primaryColor: '#1890FF', // primary color of ant design
  4 + layout: 'sidemenu', // nav menu position: sidemenu or topmenu
  5 + contentWidth: 'Fluid', // layout of content: Fluid or Fixed, only works when layout is topmenu
  6 + fixedHeader: false, // sticky header
  7 + autoHideHeader: false, // auto hide header
  8 + fixSiderbar: false, // sticky siderbar
  9 +};
  1 +import React, { PureComponent } from 'react';
  2 +import {
  3 + Card,
  4 + Button,
  5 + Form,
  6 + Icon,
  7 + Col,
  8 + Row,
  9 + DatePicker,
  10 + TimePicker,
  11 + Input,
  12 + Select,
  13 + Popover,
  14 +} from 'antd';
  15 +import { connect } from 'dva';
  16 +import FooterToolbar from 'ant-design-pro/lib/FooterToolbar';
  17 +import PageHeaderWrapper from '@/components/PageHeaderWrapper';
  18 +import TableForm from './TableForm';
  19 +import styles from './style.less';
  20 +
  21 +const { Option } = Select;
  22 +const { RangePicker } = DatePicker;
  23 +
  24 +const fieldLabels = {
  25 + name: '仓库名',
  26 + url: '仓库域名',
  27 + owner: '仓库管理员',
  28 + approver: '审批人',
  29 + dateRange: '生效日期',
  30 + type: '仓库类型',
  31 + name2: '任务名',
  32 + url2: '任务描述',
  33 + owner2: '执行人',
  34 + approver2: '责任人',
  35 + dateRange2: '生效日期',
  36 + type2: '任务类型',
  37 +};
  38 +
  39 +const tableData = [
  40 + {
  41 + key: '1',
  42 + workId: '00001',
  43 + name: 'John Brown',
  44 + department: 'New York No. 1 Lake Park',
  45 + },
  46 + {
  47 + key: '2',
  48 + workId: '00002',
  49 + name: 'Jim Green',
  50 + department: 'London No. 1 Lake Park',
  51 + },
  52 + {
  53 + key: '3',
  54 + workId: '00003',
  55 + name: 'Joe Black',
  56 + department: 'Sidney No. 1 Lake Park',
  57 + },
  58 +];
  59 +
  60 +@connect(({ loading }) => ({
  61 + submitting: loading.effects['form/submitAdvancedForm'],
  62 +}))
  63 +@Form.create()
  64 +class AdvancedForm extends PureComponent {
  65 + state = {
  66 + width: '100%',
  67 + };
  68 +
  69 + componentDidMount() {
  70 + window.addEventListener('resize', this.resizeFooterToolbar, { passive: true });
  71 + }
  72 +
  73 + componentWillUnmount() {
  74 + window.removeEventListener('resize', this.resizeFooterToolbar);
  75 + }
  76 +
  77 + getErrorInfo = () => {
  78 + const {
  79 + form: { getFieldsError },
  80 + } = this.props;
  81 + const errors = getFieldsError();
  82 + const errorCount = Object.keys(errors).filter(key => errors[key]).length;
  83 + if (!errors || errorCount === 0) {
  84 + return null;
  85 + }
  86 + const scrollToField = fieldKey => {
  87 + const labelNode = document.querySelector(`label[for="${fieldKey}"]`);
  88 + if (labelNode) {
  89 + labelNode.scrollIntoView(true);
  90 + }
  91 + };
  92 + const errorList = Object.keys(errors).map(key => {
  93 + if (!errors[key]) {
  94 + return null;
  95 + }
  96 + return (
  97 + <li key={key} className={styles.errorListItem} onClick={() => scrollToField(key)}>
  98 + <Icon type="cross-circle-o" className={styles.errorIcon} />
  99 + <div className={styles.errorMessage}>{errors[key][0]}</div>
  100 + <div className={styles.errorField}>{fieldLabels[key]}</div>
  101 + </li>
  102 + );
  103 + });
  104 + return (
  105 + <span className={styles.errorIcon}>
  106 + <Popover
  107 + title="表单校验信息"
  108 + content={errorList}
  109 + overlayClassName={styles.errorPopover}
  110 + trigger="click"
  111 + getPopupContainer={trigger => trigger.parentNode}
  112 + >
  113 + <Icon type="exclamation-circle" />
  114 + </Popover>
  115 + {errorCount}
  116 + </span>
  117 + );
  118 + };
  119 +
  120 + resizeFooterToolbar = () => {
  121 + requestAnimationFrame(() => {
  122 + const sider = document.querySelectorAll('.ant-layout-sider')[0];
  123 + if (sider) {
  124 + const width = `calc(100% - ${sider.style.width})`;
  125 + const { width: stateWidth } = this.state;
  126 + if (stateWidth !== width) {
  127 + this.setState({ width });
  128 + }
  129 + }
  130 + });
  131 + };
  132 +
  133 + validate = () => {
  134 + const {
  135 + form: { validateFieldsAndScroll },
  136 + dispatch,
  137 + } = this.props;
  138 + validateFieldsAndScroll((error, values) => {
  139 + if (!error) {
  140 + // submit the values
  141 + dispatch({
  142 + type: 'form/submitAdvancedForm',
  143 + payload: values,
  144 + });
  145 + }
  146 + });
  147 + };
  148 +
  149 + render() {
  150 + const {
  151 + form: { getFieldDecorator },
  152 + submitting,
  153 + } = this.props;
  154 + const { width } = this.state;
  155 +
  156 + return (
  157 + <PageHeaderWrapper
  158 + title="高级表单"
  159 + content="高级表单常见于一次性输入和提交大批量数据的场景。"
  160 + wrapperClassName={styles.advancedForm}
  161 + >
  162 + <Card title="仓库管理" className={styles.card} bordered={false}>
  163 + <Form layout="vertical" hideRequiredMark>
  164 + <Row gutter={16}>
  165 + <Col lg={6} md={12} sm={24}>
  166 + <Form.Item label={fieldLabels.name}>
  167 + {getFieldDecorator('name', {
  168 + rules: [{ required: true, message: '请输入仓库名称' }],
  169 + })(<Input placeholder="请输入仓库名称" />)}
  170 + </Form.Item>
  171 + </Col>
  172 + <Col xl={{ span: 6, offset: 2 }} lg={{ span: 8 }} md={{ span: 12 }} sm={24}>
  173 + <Form.Item label={fieldLabels.url}>
  174 + {getFieldDecorator('url', {
  175 + rules: [{ required: true, message: '请选择' }],
  176 + })(
  177 + <Input
  178 + style={{ width: '100%' }}
  179 + addonBefore="http://"
  180 + addonAfter=".com"
  181 + placeholder="请输入"
  182 + />
  183 + )}
  184 + </Form.Item>
  185 + </Col>
  186 + <Col xl={{ span: 8, offset: 2 }} lg={{ span: 10 }} md={{ span: 24 }} sm={24}>
  187 + <Form.Item label={fieldLabels.owner}>
  188 + {getFieldDecorator('owner', {
  189 + rules: [{ required: true, message: '请选择管理员' }],
  190 + })(
  191 + <Select placeholder="请选择管理员">
  192 + <Option value="xiao">付晓晓</Option>
  193 + <Option value="mao">周毛毛</Option>
  194 + </Select>
  195 + )}
  196 + </Form.Item>
  197 + </Col>
  198 + </Row>
  199 + <Row gutter={16}>
  200 + <Col lg={6} md={12} sm={24}>
  201 + <Form.Item label={fieldLabels.approver}>
  202 + {getFieldDecorator('approver', {
  203 + rules: [{ required: true, message: '请选择审批员' }],
  204 + })(
  205 + <Select placeholder="请选择审批员">
  206 + <Option value="xiao">付晓晓</Option>
  207 + <Option value="mao">周毛毛</Option>
  208 + </Select>
  209 + )}
  210 + </Form.Item>
  211 + </Col>
  212 + <Col xl={{ span: 6, offset: 2 }} lg={{ span: 8 }} md={{ span: 12 }} sm={24}>
  213 + <Form.Item label={fieldLabels.dateRange}>
  214 + {getFieldDecorator('dateRange', {
  215 + rules: [{ required: true, message: '请选择生效日期' }],
  216 + })(
  217 + <RangePicker placeholder={['开始日期', '结束日期']} style={{ width: '100%' }} />
  218 + )}
  219 + </Form.Item>
  220 + </Col>
  221 + <Col xl={{ span: 8, offset: 2 }} lg={{ span: 10 }} md={{ span: 24 }} sm={24}>
  222 + <Form.Item label={fieldLabels.type}>
  223 + {getFieldDecorator('type', {
  224 + rules: [{ required: true, message: '请选择仓库类型' }],
  225 + })(
  226 + <Select placeholder="请选择仓库类型">
  227 + <Option value="private">私密</Option>
  228 + <Option value="public">公开</Option>
  229 + </Select>
  230 + )}
  231 + </Form.Item>
  232 + </Col>
  233 + </Row>
  234 + </Form>
  235 + </Card>
  236 + <Card title="任务管理" className={styles.card} bordered={false}>
  237 + <Form layout="vertical" hideRequiredMark>
  238 + <Row gutter={16}>
  239 + <Col lg={6} md={12} sm={24}>
  240 + <Form.Item label={fieldLabels.name2}>
  241 + {getFieldDecorator('name2', {
  242 + rules: [{ required: true, message: '请输入' }],
  243 + })(<Input placeholder="请输入" />)}
  244 + </Form.Item>
  245 + </Col>
  246 + <Col xl={{ span: 6, offset: 2 }} lg={{ span: 8 }} md={{ span: 12 }} sm={24}>
  247 + <Form.Item label={fieldLabels.url2}>
  248 + {getFieldDecorator('url2', {
  249 + rules: [{ required: true, message: '请选择' }],
  250 + })(<Input placeholder="请输入" />)}
  251 + </Form.Item>
  252 + </Col>
  253 + <Col xl={{ span: 8, offset: 2 }} lg={{ span: 10 }} md={{ span: 24 }} sm={24}>
  254 + <Form.Item label={fieldLabels.owner2}>
  255 + {getFieldDecorator('owner2', {
  256 + rules: [{ required: true, message: '请选择管理员' }],
  257 + })(
  258 + <Select placeholder="请选择管理员">
  259 + <Option value="xiao">付晓晓</Option>
  260 + <Option value="mao">周毛毛</Option>
  261 + </Select>
  262 + )}
  263 + </Form.Item>
  264 + </Col>
  265 + </Row>
  266 + <Row gutter={16}>
  267 + <Col lg={6} md={12} sm={24}>
  268 + <Form.Item label={fieldLabels.approver2}>
  269 + {getFieldDecorator('approver2', {
  270 + rules: [{ required: true, message: '请选择审批员' }],
  271 + })(
  272 + <Select placeholder="请选择审批员">
  273 + <Option value="xiao">付晓晓</Option>
  274 + <Option value="mao">周毛毛</Option>
  275 + </Select>
  276 + )}
  277 + </Form.Item>
  278 + </Col>
  279 + <Col xl={{ span: 6, offset: 2 }} lg={{ span: 8 }} md={{ span: 12 }} sm={24}>
  280 + <Form.Item label={fieldLabels.dateRange2}>
  281 + {getFieldDecorator('dateRange2', {
  282 + rules: [{ required: true, message: '请输入' }],
  283 + })(
  284 + <TimePicker
  285 + placeholder="提醒时间"
  286 + style={{ width: '100%' }}
  287 + getPopupContainer={trigger => trigger.parentNode}
  288 + />
  289 + )}
  290 + </Form.Item>
  291 + </Col>
  292 + <Col xl={{ span: 8, offset: 2 }} lg={{ span: 10 }} md={{ span: 24 }} sm={24}>
  293 + <Form.Item label={fieldLabels.type2}>
  294 + {getFieldDecorator('type2', {
  295 + rules: [{ required: true, message: '请选择仓库类型' }],
  296 + })(
  297 + <Select placeholder="请选择仓库类型">
  298 + <Option value="private">私密</Option>
  299 + <Option value="public">公开</Option>
  300 + </Select>
  301 + )}
  302 + </Form.Item>
  303 + </Col>
  304 + </Row>
  305 + </Form>
  306 + </Card>
  307 + <Card title="成员管理" bordered={false}>
  308 + {getFieldDecorator('members', {
  309 + initialValue: tableData,
  310 + })(<TableForm />)}
  311 + </Card>
  312 + <FooterToolbar style={{ width }}>
  313 + {this.getErrorInfo()}
  314 + <Button type="primary" onClick={this.validate} loading={submitting}>
  315 + 提交
  316 + </Button>
  317 + </FooterToolbar>
  318 + </PageHeaderWrapper>
  319 + );
  320 + }
  321 +}
  322 +
  323 +export default AdvancedForm;
  1 +export default {
  2 + 'form.get-captcha': 'Get Captcha',
  3 + 'form.captcha.second': 'sec',
  4 + 'form.optional': ' (optional) ',
  5 + 'form.submit': 'Submit',
  6 + 'form.save': 'Save',
  7 + 'form.email.placeholder': 'Email',
  8 + 'form.password.placeholder': 'Password',
  9 + 'form.confirm-password.placeholder': 'Confirm password',
  10 + 'form.phone-number.placeholder': 'Phone number',
  11 + 'form.verification-code.placeholder': 'Verification code',
  12 + 'form.title.label': 'Title',
  13 + 'form.title.placeholder': 'Give the target a name',
  14 + 'form.date.label': 'Start and end date',
  15 + 'form.date.placeholder.start': 'Start date',
  16 + 'form.date.placeholder.end': 'End date',
  17 + 'form.goal.label': 'Goal description',
  18 + 'form.goal.placeholder': 'Please enter your work goals',
  19 + 'form.standard.label': 'Metrics',
  20 + 'form.standard.placeholder': 'Please enter a metric',
  21 + 'form.client.label': 'Client',
  22 + 'form.client.label.tooltip': 'Target service object',
  23 + 'form.client.placeholder':
  24 + 'Please describe your customer service, internal customers directly @ Name / job number',
  25 + 'form.invites.label': 'Inviting critics',
  26 + 'form.invites.placeholder': 'Please direct @ Name / job number, you can invite up to 5 people',
  27 + 'form.weight.label': 'Weight',
  28 + 'form.weight.placeholder': 'Please enter weight',
  29 + 'form.public.label': 'Target disclosure',
  30 + 'form.public.label.help': 'Customers and invitees are shared by default',
  31 + 'form.public.radio.public': 'Public',
  32 + 'form.public.radio.partially-public': 'Partially public',
  33 + 'form.public.radio.private': 'Private',
  34 + 'form.publicUsers.placeholder': 'Open to',
  35 + 'form.publicUsers.option.A': 'Colleague A',
  36 + 'form.publicUsers.option.B': 'Colleague B',
  37 + 'form.publicUsers.option.C': 'Colleague C',
  38 +};
  1 +export default {
  2 + 'form.get-captcha': '获取验证码',
  3 + 'form.captcha.second': '秒',
  4 + 'form.optional': '(选填)',
  5 + 'form.submit': '提交',
  6 + 'form.save': '保存',
  7 + 'form.email.placeholder': '邮箱',
  8 + 'form.password.placeholder': '至少6位密码,区分大小写',
  9 + 'form.confirm-password.placeholder': '确认密码',
  10 + 'form.phone-number.placeholder': '手机号',
  11 + 'form.verification-code.placeholder': '验证码',
  12 + 'form.title.label': '标题',
  13 + 'form.title.placeholder': '给目标起个名字',
  14 + 'form.date.label': '起止日期',
  15 + 'form.date.placeholder.start': '开始日期',
  16 + 'form.date.placeholder.end': '结束日期',
  17 + 'form.goal.label': '目标描述',
  18 + 'form.goal.placeholder': '请输入你的阶段性工作目标',
  19 + 'form.standard.label': '衡量标准',
  20 + 'form.standard.placeholder': '请输入衡量标准',
  21 + 'form.client.label': '客户',
  22 + 'form.client.label.tooltip': '目标的服务对象',
  23 + 'form.client.placeholder': '请描述你服务的客户,内部客户直接 @姓名/工号',
  24 + 'form.invites.label': '邀评人',
  25 + 'form.invites.placeholder': '请直接 @姓名/工号,最多可邀请 5 人',
  26 + 'form.weight.label': '权重',
  27 + 'form.weight.placeholder': '请输入',
  28 + 'form.public.label': '目标公开',
  29 + 'form.public.label.help': '客户、邀评人默认被分享',
  30 + 'form.public.radio.public': '公开',
  31 + 'form.public.radio.partially-public': '部分公开',
  32 + 'form.public.radio.private': '不公开',
  33 + 'form.publicUsers.placeholder': '公开给',
  34 + 'form.publicUsers.option.A': '同事甲',
  35 + 'form.publicUsers.option.B': '同事乙',
  36 + 'form.publicUsers.option.C': '同事丙',
  37 +};
  1 +export default {
  2 + 'form.get-captcha': '獲取驗證碼',
  3 + 'form.captcha.second': '秒',
  4 + 'form.optional': '(選填)',
  5 + 'form.submit': '提交',
  6 + 'form.save': '保存',
  7 + 'form.email.placeholder': '郵箱',
  8 + 'form.password.placeholder': '至少6位密碼,區分大小寫',
  9 + 'form.confirm-password.placeholder': '確認密碼',
  10 + 'form.phone-number.placeholder': '手機號',
  11 + 'form.verification-code.placeholder': '驗證碼',
  12 + 'form.title.label': '標題',
  13 + 'form.title.placeholder': '給目標起個名字',
  14 + 'form.date.label': '起止日期',
  15 + 'form.date.placeholder.start': '開始日期',
  16 + 'form.date.placeholder.end': '結束日期',
  17 + 'form.goal.label': '目標描述',
  18 + 'form.goal.placeholder': '請輸入妳的階段性工作目標',
  19 + 'form.standard.label': '衡量標淮',
  20 + 'form.standard.placeholder': '請輸入衡量標淮',
  21 + 'form.client.label': '客戶',
  22 + 'form.client.label.tooltip': '目標的服務對象',
  23 + 'form.client.placeholder': '請描述妳服務的客戶,內部客戶直接 @姓名/工號',
  24 + 'form.invites.label': '邀評人',
  25 + 'form.invites.placeholder': '請直接 @姓名/工號,最多可邀請 5 人',
  26 + 'form.weight.label': '權重',
  27 + 'form.weight.placeholder': '請輸入',
  28 + 'form.public.label': '目標公開',
  29 + 'form.public.label.help': '客戶、邀評人默認被分享',
  30 + 'form.public.radio.public': '公開',
  31 + 'form.public.radio.partially-public': '部分公開',
  32 + 'form.public.radio.private': '不公開',
  33 + 'form.publicUsers.placeholder': '公開給',
  34 + 'form.publicUsers.option.A': '同事甲',
  35 + 'form.publicUsers.option.B': '同事乙',
  36 + 'form.publicUsers.option.C': '同事丙',
  37 +};
  1 +import { routerRedux } from 'dva/router';
  2 +import { message } from 'antd';
  3 +import { fakeSubmitForm } from '@/services/api';
  4 +
  5 +export default {
  6 + namespace: 'form',
  7 +
  8 + state: {
  9 + step: {
  10 + payAccount: 'ant-design@alipay.com',
  11 + receiverAccount: 'test@example.com',
  12 + receiverName: 'Alex',
  13 + amount: '500',
  14 + },
  15 + },
  16 +
  17 + effects: {
  18 + *submitRegularForm({ payload }, { call }) {
  19 + yield call(fakeSubmitForm, payload);
  20 + message.success('提交成功');
  21 + },
  22 + *submitStepForm({ payload }, { call, put }) {
  23 + yield call(fakeSubmitForm, payload);
  24 + yield put({
  25 + type: 'saveStepFormData',
  26 + payload,
  27 + });
  28 + yield put(routerRedux.push('/form/step-form/result'));
  29 + },
  30 + *submitAdvancedForm({ payload }, { call }) {
  31 + yield call(fakeSubmitForm, payload);
  32 + message.success('提交成功');
  33 + },
  34 + },
  35 +
  36 + reducers: {
  37 + saveStepFormData(state, { payload }) {
  38 + return {
  39 + ...state,
  40 + step: {
  41 + ...state.step,
  42 + ...payload,
  43 + },
  44 + };
  45 + },
  46 + },
  47 +};
  1 +import { message } from 'antd';
  2 +import defaultSettings from '../defaultSettings';
  3 +
  4 +let lessNodesAppended;
  5 +const updateTheme = primaryColor => {
  6 + // Don't compile less in production!
  7 + if (APP_TYPE !== 'site') {
  8 + return;
  9 + }
  10 + // Determine if the component is remounted
  11 + if (!primaryColor) {
  12 + return;
  13 + }
  14 + const hideMessage = message.loading('正在编译主题!', 0);
  15 + function buildIt() {
  16 + if (!window.less) {
  17 + return;
  18 + }
  19 + setTimeout(() => {
  20 + window.less
  21 + .modifyVars({
  22 + '@primary-color': primaryColor,
  23 + })
  24 + .then(() => {
  25 + hideMessage();
  26 + })
  27 + .catch(() => {
  28 + message.error('Failed to update theme');
  29 + hideMessage();
  30 + });
  31 + }, 200);
  32 + }
  33 + if (!lessNodesAppended) {
  34 + // insert less.js and color.less
  35 + const lessStyleNode = document.createElement('link');
  36 + const lessConfigNode = document.createElement('script');
  37 + const lessScriptNode = document.createElement('script');
  38 + lessStyleNode.setAttribute('rel', 'stylesheet/less');
  39 + lessStyleNode.setAttribute('href', '/color.less');
  40 + lessConfigNode.innerHTML = `
  41 + window.less = {
  42 + async: true,
  43 + env: 'production',
  44 + javascriptEnabled: true
  45 + };
  46 + `;
  47 + lessScriptNode.src = 'https://gw.alipayobjects.com/os/lib/less.js/3.8.1/less.min.js';
  48 + lessScriptNode.async = true;
  49 + lessScriptNode.onload = () => {
  50 + buildIt();
  51 + lessScriptNode.onload = null;
  52 + };
  53 + document.body.appendChild(lessStyleNode);
  54 + document.body.appendChild(lessConfigNode);
  55 + document.body.appendChild(lessScriptNode);
  56 + lessNodesAppended = true;
  57 + } else {
  58 + buildIt();
  59 + }
  60 +};
  61 +
  62 +const updateColorWeak = colorWeak => {
  63 + document.body.className = colorWeak ? 'colorWeak' : '';
  64 +};
  65 +
  66 +export default {
  67 + namespace: 'setting',
  68 + state: defaultSettings,
  69 + reducers: {
  70 + getSetting(state) {
  71 + const setting = {};
  72 + const urlParams = new URL(window.location.href);
  73 + Object.keys(state).forEach(key => {
  74 + if (urlParams.searchParams.has(key)) {
  75 + const value = urlParams.searchParams.get(key);
  76 + setting[key] = value === '1' ? true : value;
  77 + }
  78 + });
  79 + const { primaryColor, colorWeak } = setting;
  80 + if (state.primaryColor !== primaryColor) {
  81 + updateTheme(primaryColor);
  82 + }
  83 + updateColorWeak(colorWeak);
  84 + return {
  85 + ...state,
  86 + ...setting,
  87 + };
  88 + },
  89 + changeSetting(state, { payload }) {
  90 + const urlParams = new URL(window.location.href);
  91 + Object.keys(defaultSettings).forEach(key => {
  92 + if (urlParams.searchParams.has(key)) {
  93 + urlParams.searchParams.delete(key);
  94 + }
  95 + });
  96 + Object.keys(payload).forEach(key => {
  97 + if (key === 'collapse') {
  98 + return;
  99 + }
  100 + let value = payload[key];
  101 + if (value === true) {
  102 + value = 1;
  103 + }
  104 + if (defaultSettings[key] !== value) {
  105 + urlParams.searchParams.set(key, value);
  106 + }
  107 + });
  108 + const { primaryColor, colorWeak, contentWidth } = payload;
  109 + if (state.primaryColor !== primaryColor) {
  110 + updateTheme(primaryColor);
  111 + }
  112 + if (state.contentWidth !== contentWidth && window.dispatchEvent) {
  113 + window.dispatchEvent(new Event('resize'));
  114 + }
  115 + updateColorWeak(colorWeak);
  116 + window.history.replaceState(null, 'setting', urlParams.href);
  117 + return {
  118 + ...state,
  119 + ...payload,
  120 + };
  121 + },
  122 + },
  123 +};
  1 +@import '~antd/lib/style/themes/default.less';
  2 +
  3 +.card {
  4 + margin-bottom: 24px;
  5 +}
  6 +
  7 +.heading {
  8 + font-size: 14px;
  9 + line-height: 22px;
  10 + margin: 0 0 16px 0;
  11 +}
  12 +
  13 +.steps:global(.ant-steps) {
  14 + max-width: 750px;
  15 + margin: 16px auto;
  16 +}
  17 +
  18 +.errorIcon {
  19 + cursor: pointer;
  20 + color: @error-color;
  21 + margin-right: 24px;
  22 + i {
  23 + margin-right: 4px;
  24 + }
  25 +}
  26 +
  27 +.errorPopover {
  28 + :global {
  29 + .ant-popover-inner-content {
  30 + padding: 0;
  31 + max-height: 290px;
  32 + overflow: auto;
  33 + min-width: 256px;
  34 + }
  35 + }
  36 +}
  37 +
  38 +.errorListItem {
  39 + list-style: none;
  40 + border-bottom: 1px solid @border-color-split;
  41 + padding: 8px 16px;
  42 + cursor: pointer;
  43 + transition: all 0.3s;
  44 + &:hover {
  45 + background: @primary-1;
  46 + }
  47 + &:last-child {
  48 + border: 0;
  49 + }
  50 + .errorIcon {
  51 + color: @error-color;
  52 + float: left;
  53 + margin-top: 4px;
  54 + margin-right: 12px;
  55 + padding-bottom: 22px;
  56 + }
  57 + .errorField {
  58 + font-size: 12px;
  59 + color: @text-color-secondary;
  60 + margin-top: 2px;
  61 + }
  62 +}
  63 +
  64 +.editable {
  65 + td {
  66 + padding-top: 13px !important;
  67 + padding-bottom: 12.5px !important;
  68 + }
  69 +}
  70 +
  71 +// custom footer for fixed footer toolbar
  72 +.advancedForm + div {
  73 + padding-bottom: 64px;
  74 +}
  75 +
  76 +.advancedForm {
  77 + :global {
  78 + .ant-form .ant-row:last-child .ant-form-item {
  79 + margin-bottom: 24px;
  80 + }
  81 + .ant-table td {
  82 + transition: none !important;
  83 + }
  84 + }
  85 +}
  86 +
  87 +.optional {
  88 + color: @text-color-secondary;
  89 + font-style: normal;
  90 +}
注册登录 后发表评论