正在显示
22 个修改的文件
包含
2099 行增加
和
0 行删除
ant-design-pro/TableList/.gitignore
0 → 100644
ant-design-pro/TableList/.umirc.js
0 → 100644
| 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 | +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 React, { PureComponent, Fragment } from 'react'; | |
| 2 | +import { Table, Alert } from 'antd'; | |
| 3 | +import styles from './index.less'; | |
| 4 | + | |
| 5 | +function initTotalList(columns) { | |
| 6 | + const totalList = []; | |
| 7 | + columns.forEach(column => { | |
| 8 | + if (column.needTotal) { | |
| 9 | + totalList.push({ ...column, total: 0 }); | |
| 10 | + } | |
| 11 | + }); | |
| 12 | + return totalList; | |
| 13 | +} | |
| 14 | + | |
| 15 | +class StandardTable extends PureComponent { | |
| 16 | + constructor(props) { | |
| 17 | + super(props); | |
| 18 | + const { columns } = props; | |
| 19 | + const needTotalList = initTotalList(columns); | |
| 20 | + | |
| 21 | + this.state = { | |
| 22 | + selectedRowKeys: [], | |
| 23 | + needTotalList, | |
| 24 | + }; | |
| 25 | + } | |
| 26 | + | |
| 27 | + static getDerivedStateFromProps(nextProps) { | |
| 28 | + // clean state | |
| 29 | + if (nextProps.selectedRows.length === 0) { | |
| 30 | + const needTotalList = initTotalList(nextProps.columns); | |
| 31 | + return { | |
| 32 | + selectedRowKeys: [], | |
| 33 | + needTotalList, | |
| 34 | + }; | |
| 35 | + } | |
| 36 | + return null; | |
| 37 | + } | |
| 38 | + | |
| 39 | + handleRowSelectChange = (selectedRowKeys, selectedRows) => { | |
| 40 | + let { needTotalList } = this.state; | |
| 41 | + needTotalList = needTotalList.map(item => ({ | |
| 42 | + ...item, | |
| 43 | + total: selectedRows.reduce((sum, val) => sum + parseFloat(val[item.dataIndex], 10), 0), | |
| 44 | + })); | |
| 45 | + const { onSelectRow } = this.props; | |
| 46 | + if (onSelectRow) { | |
| 47 | + onSelectRow(selectedRows); | |
| 48 | + } | |
| 49 | + | |
| 50 | + this.setState({ selectedRowKeys, needTotalList }); | |
| 51 | + }; | |
| 52 | + | |
| 53 | + handleTableChange = (pagination, filters, sorter) => { | |
| 54 | + const { onChange } = this.props; | |
| 55 | + if (onChange) { | |
| 56 | + onChange(pagination, filters, sorter); | |
| 57 | + } | |
| 58 | + }; | |
| 59 | + | |
| 60 | + cleanSelectedKeys = () => { | |
| 61 | + this.handleRowSelectChange([], []); | |
| 62 | + }; | |
| 63 | + | |
| 64 | + render() { | |
| 65 | + const { selectedRowKeys, needTotalList } = this.state; | |
| 66 | + const { data = {}, rowKey, ...rest } = this.props; | |
| 67 | + const { list = [], pagination } = data; | |
| 68 | + | |
| 69 | + const paginationProps = { | |
| 70 | + showSizeChanger: true, | |
| 71 | + showQuickJumper: true, | |
| 72 | + ...pagination, | |
| 73 | + }; | |
| 74 | + | |
| 75 | + const rowSelection = { | |
| 76 | + selectedRowKeys, | |
| 77 | + onChange: this.handleRowSelectChange, | |
| 78 | + getCheckboxProps: record => ({ | |
| 79 | + disabled: record.disabled, | |
| 80 | + }), | |
| 81 | + }; | |
| 82 | + | |
| 83 | + return ( | |
| 84 | + <div className={styles.standardTable}> | |
| 85 | + <div className={styles.tableAlert}> | |
| 86 | + <Alert | |
| 87 | + message={ | |
| 88 | + <Fragment> | |
| 89 | + 已选择 <a style={{ fontWeight: 600 }}>{selectedRowKeys.length}</a> 项 | |
| 90 | + {needTotalList.map(item => ( | |
| 91 | + <span style={{ marginLeft: 8 }} key={item.dataIndex}> | |
| 92 | + {item.title} | |
| 93 | + 总计 | |
| 94 | + <span style={{ fontWeight: 600 }}> | |
| 95 | + {item.render ? item.render(item.total) : item.total} | |
| 96 | + </span> | |
| 97 | + </span> | |
| 98 | + ))} | |
| 99 | + <a onClick={this.cleanSelectedKeys} style={{ marginLeft: 24 }}> | |
| 100 | + 清空 | |
| 101 | + </a> | |
| 102 | + </Fragment> | |
| 103 | + } | |
| 104 | + type="info" | |
| 105 | + showIcon | |
| 106 | + /> | |
| 107 | + </div> | |
| 108 | + <Table | |
| 109 | + rowKey={rowKey || 'key'} | |
| 110 | + rowSelection={rowSelection} | |
| 111 | + dataSource={list} | |
| 112 | + pagination={paginationProps} | |
| 113 | + onChange={this.handleTableChange} | |
| 114 | + {...rest} | |
| 115 | + /> | |
| 116 | + </div> | |
| 117 | + ); | |
| 118 | + } | |
| 119 | +} | |
| 120 | + | |
| 121 | +export default StandardTable; | ... | ... |
ant-design-pro/TableList/@/services/api.js
0 → 100644
| 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 | +} | ... | ... |
ant-design-pro/TableList/@/utils/request.js
0 → 100644
| 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 | +} | ... | ... |
ant-design-pro/TableList/@/utils/utils.js
0 → 100644
| 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 | +} | ... | ... |
ant-design-pro/TableList/@/utils/utils.less
0 → 100644
| 1 | +.textOverflow() { | |
| 2 | + overflow: hidden; | |
| 3 | + text-overflow: ellipsis; | |
| 4 | + word-break: break-all; | |
| 5 | + white-space: nowrap; | |
| 6 | +} | |
| 7 | + | |
| 8 | +.textOverflowMulti(@line: 3, @bg: #fff) { | |
| 9 | + overflow: hidden; | |
| 10 | + position: relative; | |
| 11 | + line-height: 1.5em; | |
| 12 | + max-height: @line * 1.5em; | |
| 13 | + text-align: justify; | |
| 14 | + margin-right: -1em; | |
| 15 | + padding-right: 1em; | |
| 16 | + &:before { | |
| 17 | + background: @bg; | |
| 18 | + content: '...'; | |
| 19 | + padding: 0 1px; | |
| 20 | + position: absolute; | |
| 21 | + right: 14px; | |
| 22 | + bottom: 0; | |
| 23 | + } | |
| 24 | + &:after { | |
| 25 | + background: white; | |
| 26 | + content: ''; | |
| 27 | + margin-top: 0.2em; | |
| 28 | + position: absolute; | |
| 29 | + right: 14px; | |
| 30 | + width: 1em; | |
| 31 | + height: 1em; | |
| 32 | + } | |
| 33 | +} | |
| 34 | + | |
| 35 | +// mixins for clearfix | |
| 36 | +// ------------------------ | |
| 37 | +.clearfix() { | |
| 38 | + zoom: 1; | |
| 39 | + &:before, | |
| 40 | + &:after { | |
| 41 | + content: ' '; | |
| 42 | + display: table; | |
| 43 | + } | |
| 44 | + &:after { | |
| 45 | + clear: both; | |
| 46 | + visibility: hidden; | |
| 47 | + font-size: 0; | |
| 48 | + height: 0; | |
| 49 | + } | |
| 50 | +} | ... | ... |
ant-design-pro/TableList/README.md
0 → 100644
ant-design-pro/TableList/package.json
0 → 100644
| 1 | +{ | |
| 2 | + "name": "@umi-block/tablelist", | |
| 3 | + "version": "0.0.1", | |
| 4 | + "description": "TableList", | |
| 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/tablelist" | |
| 12 | + }, | |
| 13 | + "dependencies": { | |
| 14 | + "react": "^16.6.3", | |
| 15 | + "dva": "^2.4.0", | |
| 16 | + "moment": "^2.22.2", | |
| 17 | + "antd": "^3.10.9", | |
| 18 | + "ant-design-pro": "^2.1.1", | |
| 19 | + "qs": "^6.6.0", | |
| 20 | + "hash.js": "^1.1.5", | |
| 21 | + "nzh": "^1.0.3", | |
| 22 | + "mockjs": "*" | |
| 23 | + }, | |
| 24 | + "devDependencies": { | |
| 25 | + "umi": "^2.3.0-beta.1", | |
| 26 | + "umi-plugin-react": "^1.3.0-beta.1", | |
| 27 | + "umi-plugin-block-dev": "^1.0.0" | |
| 28 | + }, | |
| 29 | + "license": "ISC" | |
| 30 | +} | ... | ... |
ant-design-pro/TableList/src/TableList.less
0 → 100644
| 1 | +@import '~antd/lib/style/themes/default.less'; | |
| 2 | +@import '~@/utils/utils.less'; | |
| 3 | + | |
| 4 | +.tableList { | |
| 5 | + .tableListOperator { | |
| 6 | + margin-bottom: 16px; | |
| 7 | + button { | |
| 8 | + margin-right: 8px; | |
| 9 | + } | |
| 10 | + } | |
| 11 | +} | |
| 12 | + | |
| 13 | +.tableListForm { | |
| 14 | + :global { | |
| 15 | + .ant-form-item { | |
| 16 | + margin-bottom: 24px; | |
| 17 | + margin-right: 0; | |
| 18 | + display: flex; | |
| 19 | + > .ant-form-item-label { | |
| 20 | + width: auto; | |
| 21 | + line-height: 32px; | |
| 22 | + padding-right: 8px; | |
| 23 | + } | |
| 24 | + .ant-form-item-control { | |
| 25 | + line-height: 32px; | |
| 26 | + } | |
| 27 | + } | |
| 28 | + .ant-form-item-control-wrapper { | |
| 29 | + flex: 1; | |
| 30 | + } | |
| 31 | + } | |
| 32 | + .submitButtons { | |
| 33 | + display: block; | |
| 34 | + white-space: nowrap; | |
| 35 | + margin-bottom: 24px; | |
| 36 | + } | |
| 37 | +} | |
| 38 | + | |
| 39 | +@media screen and (max-width: @screen-lg) { | |
| 40 | + .tableListForm :global(.ant-form-item) { | |
| 41 | + margin-right: 24px; | |
| 42 | + } | |
| 43 | +} | |
| 44 | + | |
| 45 | +@media screen and (max-width: @screen-md) { | |
| 46 | + .tableListForm :global(.ant-form-item) { | |
| 47 | + margin-right: 8px; | |
| 48 | + } | |
| 49 | +} | ... | ... |
ant-design-pro/TableList/src/_mock.js
0 → 100644
| 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 | +}; | ... | ... |
ant-design-pro/TableList/src/index.js
0 → 100644
| 1 | +import React, { PureComponent, Fragment } from 'react'; | |
| 2 | +import { connect } from 'dva'; | |
| 3 | +import moment from 'moment'; | |
| 4 | +import { | |
| 5 | + Row, | |
| 6 | + Col, | |
| 7 | + Card, | |
| 8 | + Form, | |
| 9 | + Input, | |
| 10 | + Select, | |
| 11 | + Icon, | |
| 12 | + Button, | |
| 13 | + Dropdown, | |
| 14 | + Menu, | |
| 15 | + InputNumber, | |
| 16 | + DatePicker, | |
| 17 | + Modal, | |
| 18 | + message, | |
| 19 | + Badge, | |
| 20 | + Divider, | |
| 21 | + Steps, | |
| 22 | + Radio, | |
| 23 | +} from 'antd'; | |
| 24 | +import StandardTable from '@/components/StandardTable'; | |
| 25 | +import PageHeaderWrapper from '@/components/PageHeaderWrapper'; | |
| 26 | + | |
| 27 | +import styles from './TableList.less'; | |
| 28 | + | |
| 29 | +const FormItem = Form.Item; | |
| 30 | +const { Step } = Steps; | |
| 31 | +const { TextArea } = Input; | |
| 32 | +const { Option } = Select; | |
| 33 | +const RadioGroup = Radio.Group; | |
| 34 | +const getValue = obj => | |
| 35 | + Object.keys(obj) | |
| 36 | + .map(key => obj[key]) | |
| 37 | + .join(','); | |
| 38 | +const statusMap = ['default', 'processing', 'success', 'error']; | |
| 39 | +const status = ['关闭', '运行中', '已上线', '异常']; | |
| 40 | + | |
| 41 | +const CreateForm = Form.create()(props => { | |
| 42 | + const { modalVisible, form, handleAdd, handleModalVisible } = props; | |
| 43 | + const okHandle = () => { | |
| 44 | + form.validateFields((err, fieldsValue) => { | |
| 45 | + if (err) return; | |
| 46 | + form.resetFields(); | |
| 47 | + handleAdd(fieldsValue); | |
| 48 | + }); | |
| 49 | + }; | |
| 50 | + return ( | |
| 51 | + <Modal | |
| 52 | + destroyOnClose | |
| 53 | + title="新建规则" | |
| 54 | + visible={modalVisible} | |
| 55 | + onOk={okHandle} | |
| 56 | + onCancel={() => handleModalVisible()} | |
| 57 | + > | |
| 58 | + <FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="描述"> | |
| 59 | + {form.getFieldDecorator('desc', { | |
| 60 | + rules: [{ required: true, message: '请输入至少五个字符的规则描述!', min: 5 }], | |
| 61 | + })(<Input placeholder="请输入" />)} | |
| 62 | + </FormItem> | |
| 63 | + </Modal> | |
| 64 | + ); | |
| 65 | +}); | |
| 66 | + | |
| 67 | +@Form.create() | |
| 68 | +class UpdateForm extends PureComponent { | |
| 69 | + static defaultProps = { | |
| 70 | + handleUpdate: () => {}, | |
| 71 | + handleUpdateModalVisible: () => {}, | |
| 72 | + values: {}, | |
| 73 | + }; | |
| 74 | + | |
| 75 | + constructor(props) { | |
| 76 | + super(props); | |
| 77 | + | |
| 78 | + this.state = { | |
| 79 | + formVals: { | |
| 80 | + name: props.values.name, | |
| 81 | + desc: props.values.desc, | |
| 82 | + key: props.values.key, | |
| 83 | + target: '0', | |
| 84 | + template: '0', | |
| 85 | + type: '1', | |
| 86 | + time: '', | |
| 87 | + frequency: 'month', | |
| 88 | + }, | |
| 89 | + currentStep: 0, | |
| 90 | + }; | |
| 91 | + | |
| 92 | + this.formLayout = { | |
| 93 | + labelCol: { span: 7 }, | |
| 94 | + wrapperCol: { span: 13 }, | |
| 95 | + }; | |
| 96 | + } | |
| 97 | + | |
| 98 | + handleNext = currentStep => { | |
| 99 | + const { form, handleUpdate } = this.props; | |
| 100 | + const { formVals: oldValue } = this.state; | |
| 101 | + form.validateFields((err, fieldsValue) => { | |
| 102 | + if (err) return; | |
| 103 | + const formVals = { ...oldValue, ...fieldsValue }; | |
| 104 | + this.setState( | |
| 105 | + { | |
| 106 | + formVals, | |
| 107 | + }, | |
| 108 | + () => { | |
| 109 | + if (currentStep < 2) { | |
| 110 | + this.forward(); | |
| 111 | + } else { | |
| 112 | + handleUpdate(formVals); | |
| 113 | + } | |
| 114 | + } | |
| 115 | + ); | |
| 116 | + }); | |
| 117 | + }; | |
| 118 | + | |
| 119 | + backward = () => { | |
| 120 | + const { currentStep } = this.state; | |
| 121 | + this.setState({ | |
| 122 | + currentStep: currentStep - 1, | |
| 123 | + }); | |
| 124 | + }; | |
| 125 | + | |
| 126 | + forward = () => { | |
| 127 | + const { currentStep } = this.state; | |
| 128 | + this.setState({ | |
| 129 | + currentStep: currentStep + 1, | |
| 130 | + }); | |
| 131 | + }; | |
| 132 | + | |
| 133 | + renderContent = (currentStep, formVals) => { | |
| 134 | + const { form } = this.props; | |
| 135 | + if (currentStep === 1) { | |
| 136 | + return [ | |
| 137 | + <FormItem key="target" {...this.formLayout} label="监控对象"> | |
| 138 | + {form.getFieldDecorator('target', { | |
| 139 | + initialValue: formVals.target, | |
| 140 | + })( | |
| 141 | + <Select style={{ width: '100%' }}> | |
| 142 | + <Option value="0">表一</Option> | |
| 143 | + <Option value="1">表二</Option> | |
| 144 | + </Select> | |
| 145 | + )} | |
| 146 | + </FormItem>, | |
| 147 | + <FormItem key="template" {...this.formLayout} label="规则模板"> | |
| 148 | + {form.getFieldDecorator('template', { | |
| 149 | + initialValue: formVals.template, | |
| 150 | + })( | |
| 151 | + <Select style={{ width: '100%' }}> | |
| 152 | + <Option value="0">规则模板一</Option> | |
| 153 | + <Option value="1">规则模板二</Option> | |
| 154 | + </Select> | |
| 155 | + )} | |
| 156 | + </FormItem>, | |
| 157 | + <FormItem key="type" {...this.formLayout} label="规则类型"> | |
| 158 | + {form.getFieldDecorator('type', { | |
| 159 | + initialValue: formVals.type, | |
| 160 | + })( | |
| 161 | + <RadioGroup> | |
| 162 | + <Radio value="0">强</Radio> | |
| 163 | + <Radio value="1">弱</Radio> | |
| 164 | + </RadioGroup> | |
| 165 | + )} | |
| 166 | + </FormItem>, | |
| 167 | + ]; | |
| 168 | + } | |
| 169 | + if (currentStep === 2) { | |
| 170 | + return [ | |
| 171 | + <FormItem key="time" {...this.formLayout} label="开始时间"> | |
| 172 | + {form.getFieldDecorator('time', { | |
| 173 | + rules: [{ required: true, message: '请选择开始时间!' }], | |
| 174 | + })( | |
| 175 | + <DatePicker | |
| 176 | + style={{ width: '100%' }} | |
| 177 | + showTime | |
| 178 | + format="YYYY-MM-DD HH:mm:ss" | |
| 179 | + placeholder="选择开始时间" | |
| 180 | + /> | |
| 181 | + )} | |
| 182 | + </FormItem>, | |
| 183 | + <FormItem key="frequency" {...this.formLayout} label="调度周期"> | |
| 184 | + {form.getFieldDecorator('frequency', { | |
| 185 | + initialValue: formVals.frequency, | |
| 186 | + })( | |
| 187 | + <Select style={{ width: '100%' }}> | |
| 188 | + <Option value="month">月</Option> | |
| 189 | + <Option value="week">周</Option> | |
| 190 | + </Select> | |
| 191 | + )} | |
| 192 | + </FormItem>, | |
| 193 | + ]; | |
| 194 | + } | |
| 195 | + return [ | |
| 196 | + <FormItem key="name" {...this.formLayout} label="规则名称"> | |
| 197 | + {form.getFieldDecorator('name', { | |
| 198 | + rules: [{ required: true, message: '请输入规则名称!' }], | |
| 199 | + initialValue: formVals.name, | |
| 200 | + })(<Input placeholder="请输入" />)} | |
| 201 | + </FormItem>, | |
| 202 | + <FormItem key="desc" {...this.formLayout} label="规则描述"> | |
| 203 | + {form.getFieldDecorator('desc', { | |
| 204 | + rules: [{ required: true, message: '请输入至少五个字符的规则描述!', min: 5 }], | |
| 205 | + initialValue: formVals.desc, | |
| 206 | + })(<TextArea rows={4} placeholder="请输入至少五个字符" />)} | |
| 207 | + </FormItem>, | |
| 208 | + ]; | |
| 209 | + }; | |
| 210 | + | |
| 211 | + renderFooter = currentStep => { | |
| 212 | + const { handleUpdateModalVisible, values } = this.props; | |
| 213 | + if (currentStep === 1) { | |
| 214 | + return [ | |
| 215 | + <Button key="back" style={{ float: 'left' }} onClick={this.backward}> | |
| 216 | + 上一步 | |
| 217 | + </Button>, | |
| 218 | + <Button key="cancel" onClick={() => handleUpdateModalVisible(false, values)}> | |
| 219 | + 取消 | |
| 220 | + </Button>, | |
| 221 | + <Button key="forward" type="primary" onClick={() => this.handleNext(currentStep)}> | |
| 222 | + 下一步 | |
| 223 | + </Button>, | |
| 224 | + ]; | |
| 225 | + } | |
| 226 | + if (currentStep === 2) { | |
| 227 | + return [ | |
| 228 | + <Button key="back" style={{ float: 'left' }} onClick={this.backward}> | |
| 229 | + 上一步 | |
| 230 | + </Button>, | |
| 231 | + <Button key="cancel" onClick={() => handleUpdateModalVisible(false, values)}> | |
| 232 | + 取消 | |
| 233 | + </Button>, | |
| 234 | + <Button key="submit" type="primary" onClick={() => this.handleNext(currentStep)}> | |
| 235 | + 完成 | |
| 236 | + </Button>, | |
| 237 | + ]; | |
| 238 | + } | |
| 239 | + return [ | |
| 240 | + <Button key="cancel" onClick={() => handleUpdateModalVisible(false, values)}> | |
| 241 | + 取消 | |
| 242 | + </Button>, | |
| 243 | + <Button key="forward" type="primary" onClick={() => this.handleNext(currentStep)}> | |
| 244 | + 下一步 | |
| 245 | + </Button>, | |
| 246 | + ]; | |
| 247 | + }; | |
| 248 | + | |
| 249 | + render() { | |
| 250 | + const { updateModalVisible, handleUpdateModalVisible, values } = this.props; | |
| 251 | + const { currentStep, formVals } = this.state; | |
| 252 | + | |
| 253 | + return ( | |
| 254 | + <Modal | |
| 255 | + width={640} | |
| 256 | + bodyStyle={{ padding: '32px 40px 48px' }} | |
| 257 | + destroyOnClose | |
| 258 | + title="规则配置" | |
| 259 | + visible={updateModalVisible} | |
| 260 | + footer={this.renderFooter(currentStep)} | |
| 261 | + onCancel={() => handleUpdateModalVisible(false, values)} | |
| 262 | + afterClose={() => handleUpdateModalVisible()} | |
| 263 | + > | |
| 264 | + <Steps style={{ marginBottom: 28 }} size="small" current={currentStep}> | |
| 265 | + <Step title="基本信息" /> | |
| 266 | + <Step title="配置规则属性" /> | |
| 267 | + <Step title="设定调度周期" /> | |
| 268 | + </Steps> | |
| 269 | + {this.renderContent(currentStep, formVals)} | |
| 270 | + </Modal> | |
| 271 | + ); | |
| 272 | + } | |
| 273 | +} | |
| 274 | + | |
| 275 | +/* eslint react/no-multi-comp:0 */ | |
| 276 | +@connect(({ rule, loading }) => ({ | |
| 277 | + rule, | |
| 278 | + loading: loading.models.rule, | |
| 279 | +})) | |
| 280 | +@Form.create() | |
| 281 | +class TableList extends PureComponent { | |
| 282 | + state = { | |
| 283 | + modalVisible: false, | |
| 284 | + updateModalVisible: false, | |
| 285 | + expandForm: false, | |
| 286 | + selectedRows: [], | |
| 287 | + formValues: {}, | |
| 288 | + stepFormValues: {}, | |
| 289 | + }; | |
| 290 | + | |
| 291 | + columns = [ | |
| 292 | + { | |
| 293 | + title: '规则名称', | |
| 294 | + dataIndex: 'name', | |
| 295 | + }, | |
| 296 | + { | |
| 297 | + title: '描述', | |
| 298 | + dataIndex: 'desc', | |
| 299 | + }, | |
| 300 | + { | |
| 301 | + title: '服务调用次数', | |
| 302 | + dataIndex: 'callNo', | |
| 303 | + sorter: true, | |
| 304 | + align: 'right', | |
| 305 | + render: val => `${val} 万`, | |
| 306 | + // mark to display a total number | |
| 307 | + needTotal: true, | |
| 308 | + }, | |
| 309 | + { | |
| 310 | + title: '状态', | |
| 311 | + dataIndex: 'status', | |
| 312 | + filters: [ | |
| 313 | + { | |
| 314 | + text: status[0], | |
| 315 | + value: 0, | |
| 316 | + }, | |
| 317 | + { | |
| 318 | + text: status[1], | |
| 319 | + value: 1, | |
| 320 | + }, | |
| 321 | + { | |
| 322 | + text: status[2], | |
| 323 | + value: 2, | |
| 324 | + }, | |
| 325 | + { | |
| 326 | + text: status[3], | |
| 327 | + value: 3, | |
| 328 | + }, | |
| 329 | + ], | |
| 330 | + render(val) { | |
| 331 | + return <Badge status={statusMap[val]} text={status[val]} />; | |
| 332 | + }, | |
| 333 | + }, | |
| 334 | + { | |
| 335 | + title: '上次调度时间', | |
| 336 | + dataIndex: 'updatedAt', | |
| 337 | + sorter: true, | |
| 338 | + render: val => <span>{moment(val).format('YYYY-MM-DD HH:mm:ss')}</span>, | |
| 339 | + }, | |
| 340 | + { | |
| 341 | + title: '操作', | |
| 342 | + render: (text, record) => ( | |
| 343 | + <Fragment> | |
| 344 | + <a onClick={() => this.handleUpdateModalVisible(true, record)}>配置</a> | |
| 345 | + <Divider type="vertical" /> | |
| 346 | + <a href="">订阅警报</a> | |
| 347 | + </Fragment> | |
| 348 | + ), | |
| 349 | + }, | |
| 350 | + ]; | |
| 351 | + | |
| 352 | + componentDidMount() { | |
| 353 | + const { dispatch } = this.props; | |
| 354 | + dispatch({ | |
| 355 | + type: 'rule/fetch', | |
| 356 | + }); | |
| 357 | + } | |
| 358 | + | |
| 359 | + handleStandardTableChange = (pagination, filtersArg, sorter) => { | |
| 360 | + const { dispatch } = this.props; | |
| 361 | + const { formValues } = this.state; | |
| 362 | + | |
| 363 | + const filters = Object.keys(filtersArg).reduce((obj, key) => { | |
| 364 | + const newObj = { ...obj }; | |
| 365 | + newObj[key] = getValue(filtersArg[key]); | |
| 366 | + return newObj; | |
| 367 | + }, {}); | |
| 368 | + | |
| 369 | + const params = { | |
| 370 | + currentPage: pagination.current, | |
| 371 | + pageSize: pagination.pageSize, | |
| 372 | + ...formValues, | |
| 373 | + ...filters, | |
| 374 | + }; | |
| 375 | + if (sorter.field) { | |
| 376 | + params.sorter = `${sorter.field}_${sorter.order}`; | |
| 377 | + } | |
| 378 | + | |
| 379 | + dispatch({ | |
| 380 | + type: 'rule/fetch', | |
| 381 | + payload: params, | |
| 382 | + }); | |
| 383 | + }; | |
| 384 | + | |
| 385 | + handleFormReset = () => { | |
| 386 | + const { form, dispatch } = this.props; | |
| 387 | + form.resetFields(); | |
| 388 | + this.setState({ | |
| 389 | + formValues: {}, | |
| 390 | + }); | |
| 391 | + dispatch({ | |
| 392 | + type: 'rule/fetch', | |
| 393 | + payload: {}, | |
| 394 | + }); | |
| 395 | + }; | |
| 396 | + | |
| 397 | + toggleForm = () => { | |
| 398 | + const { expandForm } = this.state; | |
| 399 | + this.setState({ | |
| 400 | + expandForm: !expandForm, | |
| 401 | + }); | |
| 402 | + }; | |
| 403 | + | |
| 404 | + handleMenuClick = e => { | |
| 405 | + const { dispatch } = this.props; | |
| 406 | + const { selectedRows } = this.state; | |
| 407 | + | |
| 408 | + if (!selectedRows) return; | |
| 409 | + switch (e.key) { | |
| 410 | + case 'remove': | |
| 411 | + dispatch({ | |
| 412 | + type: 'rule/remove', | |
| 413 | + payload: { | |
| 414 | + key: selectedRows.map(row => row.key), | |
| 415 | + }, | |
| 416 | + callback: () => { | |
| 417 | + this.setState({ | |
| 418 | + selectedRows: [], | |
| 419 | + }); | |
| 420 | + }, | |
| 421 | + }); | |
| 422 | + break; | |
| 423 | + default: | |
| 424 | + break; | |
| 425 | + } | |
| 426 | + }; | |
| 427 | + | |
| 428 | + handleSelectRows = rows => { | |
| 429 | + this.setState({ | |
| 430 | + selectedRows: rows, | |
| 431 | + }); | |
| 432 | + }; | |
| 433 | + | |
| 434 | + handleSearch = e => { | |
| 435 | + e.preventDefault(); | |
| 436 | + | |
| 437 | + const { dispatch, form } = this.props; | |
| 438 | + | |
| 439 | + form.validateFields((err, fieldsValue) => { | |
| 440 | + if (err) return; | |
| 441 | + | |
| 442 | + const values = { | |
| 443 | + ...fieldsValue, | |
| 444 | + updatedAt: fieldsValue.updatedAt && fieldsValue.updatedAt.valueOf(), | |
| 445 | + }; | |
| 446 | + | |
| 447 | + this.setState({ | |
| 448 | + formValues: values, | |
| 449 | + }); | |
| 450 | + | |
| 451 | + dispatch({ | |
| 452 | + type: 'rule/fetch', | |
| 453 | + payload: values, | |
| 454 | + }); | |
| 455 | + }); | |
| 456 | + }; | |
| 457 | + | |
| 458 | + handleModalVisible = flag => { | |
| 459 | + this.setState({ | |
| 460 | + modalVisible: !!flag, | |
| 461 | + }); | |
| 462 | + }; | |
| 463 | + | |
| 464 | + handleUpdateModalVisible = (flag, record) => { | |
| 465 | + this.setState({ | |
| 466 | + updateModalVisible: !!flag, | |
| 467 | + stepFormValues: record || {}, | |
| 468 | + }); | |
| 469 | + }; | |
| 470 | + | |
| 471 | + handleAdd = fields => { | |
| 472 | + const { dispatch } = this.props; | |
| 473 | + dispatch({ | |
| 474 | + type: 'rule/add', | |
| 475 | + payload: { | |
| 476 | + desc: fields.desc, | |
| 477 | + }, | |
| 478 | + }); | |
| 479 | + | |
| 480 | + message.success('添加成功'); | |
| 481 | + this.handleModalVisible(); | |
| 482 | + }; | |
| 483 | + | |
| 484 | + handleUpdate = fields => { | |
| 485 | + const { dispatch } = this.props; | |
| 486 | + dispatch({ | |
| 487 | + type: 'rule/update', | |
| 488 | + payload: { | |
| 489 | + name: fields.name, | |
| 490 | + desc: fields.desc, | |
| 491 | + key: fields.key, | |
| 492 | + }, | |
| 493 | + }); | |
| 494 | + | |
| 495 | + message.success('配置成功'); | |
| 496 | + this.handleUpdateModalVisible(); | |
| 497 | + }; | |
| 498 | + | |
| 499 | + renderSimpleForm() { | |
| 500 | + const { | |
| 501 | + form: { getFieldDecorator }, | |
| 502 | + } = this.props; | |
| 503 | + return ( | |
| 504 | + <Form onSubmit={this.handleSearch} layout="inline"> | |
| 505 | + <Row gutter={{ md: 8, lg: 24, xl: 48 }}> | |
| 506 | + <Col md={8} sm={24}> | |
| 507 | + <FormItem label="规则名称"> | |
| 508 | + {getFieldDecorator('name')(<Input placeholder="请输入" />)} | |
| 509 | + </FormItem> | |
| 510 | + </Col> | |
| 511 | + <Col md={8} sm={24}> | |
| 512 | + <FormItem label="使用状态"> | |
| 513 | + {getFieldDecorator('status')( | |
| 514 | + <Select placeholder="请选择" style={{ width: '100%' }}> | |
| 515 | + <Option value="0">关闭</Option> | |
| 516 | + <Option value="1">运行中</Option> | |
| 517 | + </Select> | |
| 518 | + )} | |
| 519 | + </FormItem> | |
| 520 | + </Col> | |
| 521 | + <Col md={8} sm={24}> | |
| 522 | + <span className={styles.submitButtons}> | |
| 523 | + <Button type="primary" htmlType="submit"> | |
| 524 | + 查询 | |
| 525 | + </Button> | |
| 526 | + <Button style={{ marginLeft: 8 }} onClick={this.handleFormReset}> | |
| 527 | + 重置 | |
| 528 | + </Button> | |
| 529 | + <a style={{ marginLeft: 8 }} onClick={this.toggleForm}> | |
| 530 | + 展开 <Icon type="down" /> | |
| 531 | + </a> | |
| 532 | + </span> | |
| 533 | + </Col> | |
| 534 | + </Row> | |
| 535 | + </Form> | |
| 536 | + ); | |
| 537 | + } | |
| 538 | + | |
| 539 | + renderAdvancedForm() { | |
| 540 | + const { | |
| 541 | + form: { getFieldDecorator }, | |
| 542 | + } = this.props; | |
| 543 | + return ( | |
| 544 | + <Form onSubmit={this.handleSearch} layout="inline"> | |
| 545 | + <Row gutter={{ md: 8, lg: 24, xl: 48 }}> | |
| 546 | + <Col md={8} sm={24}> | |
| 547 | + <FormItem label="规则名称"> | |
| 548 | + {getFieldDecorator('name')(<Input placeholder="请输入" />)} | |
| 549 | + </FormItem> | |
| 550 | + </Col> | |
| 551 | + <Col md={8} sm={24}> | |
| 552 | + <FormItem label="使用状态"> | |
| 553 | + {getFieldDecorator('status')( | |
| 554 | + <Select placeholder="请选择" style={{ width: '100%' }}> | |
| 555 | + <Option value="0">关闭</Option> | |
| 556 | + <Option value="1">运行中</Option> | |
| 557 | + </Select> | |
| 558 | + )} | |
| 559 | + </FormItem> | |
| 560 | + </Col> | |
| 561 | + <Col md={8} sm={24}> | |
| 562 | + <FormItem label="调用次数"> | |
| 563 | + {getFieldDecorator('number')(<InputNumber style={{ width: '100%' }} />)} | |
| 564 | + </FormItem> | |
| 565 | + </Col> | |
| 566 | + </Row> | |
| 567 | + <Row gutter={{ md: 8, lg: 24, xl: 48 }}> | |
| 568 | + <Col md={8} sm={24}> | |
| 569 | + <FormItem label="更新日期"> | |
| 570 | + {getFieldDecorator('date')( | |
| 571 | + <DatePicker style={{ width: '100%' }} placeholder="请输入更新日期" /> | |
| 572 | + )} | |
| 573 | + </FormItem> | |
| 574 | + </Col> | |
| 575 | + <Col md={8} sm={24}> | |
| 576 | + <FormItem label="使用状态"> | |
| 577 | + {getFieldDecorator('status3')( | |
| 578 | + <Select placeholder="请选择" style={{ width: '100%' }}> | |
| 579 | + <Option value="0">关闭</Option> | |
| 580 | + <Option value="1">运行中</Option> | |
| 581 | + </Select> | |
| 582 | + )} | |
| 583 | + </FormItem> | |
| 584 | + </Col> | |
| 585 | + <Col md={8} sm={24}> | |
| 586 | + <FormItem label="使用状态"> | |
| 587 | + {getFieldDecorator('status4')( | |
| 588 | + <Select placeholder="请选择" style={{ width: '100%' }}> | |
| 589 | + <Option value="0">关闭</Option> | |
| 590 | + <Option value="1">运行中</Option> | |
| 591 | + </Select> | |
| 592 | + )} | |
| 593 | + </FormItem> | |
| 594 | + </Col> | |
| 595 | + </Row> | |
| 596 | + <div style={{ overflow: 'hidden' }}> | |
| 597 | + <div style={{ float: 'right', marginBottom: 24 }}> | |
| 598 | + <Button type="primary" htmlType="submit"> | |
| 599 | + 查询 | |
| 600 | + </Button> | |
| 601 | + <Button style={{ marginLeft: 8 }} onClick={this.handleFormReset}> | |
| 602 | + 重置 | |
| 603 | + </Button> | |
| 604 | + <a style={{ marginLeft: 8 }} onClick={this.toggleForm}> | |
| 605 | + 收起 <Icon type="up" /> | |
| 606 | + </a> | |
| 607 | + </div> | |
| 608 | + </div> | |
| 609 | + </Form> | |
| 610 | + ); | |
| 611 | + } | |
| 612 | + | |
| 613 | + renderForm() { | |
| 614 | + const { expandForm } = this.state; | |
| 615 | + return expandForm ? this.renderAdvancedForm() : this.renderSimpleForm(); | |
| 616 | + } | |
| 617 | + | |
| 618 | + render() { | |
| 619 | + const { | |
| 620 | + rule: { data }, | |
| 621 | + loading, | |
| 622 | + } = this.props; | |
| 623 | + const { selectedRows, modalVisible, updateModalVisible, stepFormValues } = this.state; | |
| 624 | + const menu = ( | |
| 625 | + <Menu onClick={this.handleMenuClick} selectedKeys={[]}> | |
| 626 | + <Menu.Item key="remove">删除</Menu.Item> | |
| 627 | + <Menu.Item key="approval">批量审批</Menu.Item> | |
| 628 | + </Menu> | |
| 629 | + ); | |
| 630 | + | |
| 631 | + const parentMethods = { | |
| 632 | + handleAdd: this.handleAdd, | |
| 633 | + handleModalVisible: this.handleModalVisible, | |
| 634 | + }; | |
| 635 | + const updateMethods = { | |
| 636 | + handleUpdateModalVisible: this.handleUpdateModalVisible, | |
| 637 | + handleUpdate: this.handleUpdate, | |
| 638 | + }; | |
| 639 | + return ( | |
| 640 | + <PageHeaderWrapper title="查询表格"> | |
| 641 | + <Card bordered={false}> | |
| 642 | + <div className={styles.tableList}> | |
| 643 | + <div className={styles.tableListForm}>{this.renderForm()}</div> | |
| 644 | + <div className={styles.tableListOperator}> | |
| 645 | + <Button icon="plus" type="primary" onClick={() => this.handleModalVisible(true)}> | |
| 646 | + 新建 | |
| 647 | + </Button> | |
| 648 | + {selectedRows.length > 0 && ( | |
| 649 | + <span> | |
| 650 | + <Button>批量操作</Button> | |
| 651 | + <Dropdown overlay={menu}> | |
| 652 | + <Button> | |
| 653 | + 更多操作 <Icon type="down" /> | |
| 654 | + </Button> | |
| 655 | + </Dropdown> | |
| 656 | + </span> | |
| 657 | + )} | |
| 658 | + </div> | |
| 659 | + <StandardTable | |
| 660 | + selectedRows={selectedRows} | |
| 661 | + loading={loading} | |
| 662 | + data={data} | |
| 663 | + columns={this.columns} | |
| 664 | + onSelectRow={this.handleSelectRows} | |
| 665 | + onChange={this.handleStandardTableChange} | |
| 666 | + /> | |
| 667 | + </div> | |
| 668 | + </Card> | |
| 669 | + <CreateForm {...parentMethods} modalVisible={modalVisible} /> | |
| 670 | + {stepFormValues && Object.keys(stepFormValues).length ? ( | |
| 671 | + <UpdateForm | |
| 672 | + {...updateMethods} | |
| 673 | + updateModalVisible={updateModalVisible} | |
| 674 | + values={stepFormValues} | |
| 675 | + /> | |
| 676 | + ) : null} | |
| 677 | + </PageHeaderWrapper> | |
| 678 | + ); | |
| 679 | + } | |
| 680 | +} | |
| 681 | + | |
| 682 | +export default TableList; | ... | ... |
ant-design-pro/TableList/src/models/list.js
0 → 100644
| 1 | +import { queryFakeList, removeFakeList, addFakeList, updateFakeList } from '@/services/api'; | |
| 2 | + | |
| 3 | +export default { | |
| 4 | + namespace: 'list', | |
| 5 | + | |
| 6 | + state: { | |
| 7 | + list: [], | |
| 8 | + }, | |
| 9 | + | |
| 10 | + effects: { | |
| 11 | + *fetch({ payload }, { call, put }) { | |
| 12 | + const response = yield call(queryFakeList, payload); | |
| 13 | + yield put({ | |
| 14 | + type: 'queryList', | |
| 15 | + payload: Array.isArray(response) ? response : [], | |
| 16 | + }); | |
| 17 | + }, | |
| 18 | + *appendFetch({ payload }, { call, put }) { | |
| 19 | + const response = yield call(queryFakeList, payload); | |
| 20 | + yield put({ | |
| 21 | + type: 'appendList', | |
| 22 | + payload: Array.isArray(response) ? response : [], | |
| 23 | + }); | |
| 24 | + }, | |
| 25 | + *submit({ payload }, { call, put }) { | |
| 26 | + let callback; | |
| 27 | + if (payload.id) { | |
| 28 | + callback = Object.keys(payload).length === 1 ? removeFakeList : updateFakeList; | |
| 29 | + } else { | |
| 30 | + callback = addFakeList; | |
| 31 | + } | |
| 32 | + const response = yield call(callback, payload); // post | |
| 33 | + yield put({ | |
| 34 | + type: 'queryList', | |
| 35 | + payload: response, | |
| 36 | + }); | |
| 37 | + }, | |
| 38 | + }, | |
| 39 | + | |
| 40 | + reducers: { | |
| 41 | + queryList(state, action) { | |
| 42 | + return { | |
| 43 | + ...state, | |
| 44 | + list: action.payload, | |
| 45 | + }; | |
| 46 | + }, | |
| 47 | + appendList(state, action) { | |
| 48 | + return { | |
| 49 | + ...state, | |
| 50 | + list: state.list.concat(action.payload), | |
| 51 | + }; | |
| 52 | + }, | |
| 53 | + }, | |
| 54 | +}; | ... | ... |
ant-design-pro/TableList/src/models/rule.js
0 → 100644
| 1 | +import { queryRule, removeRule, addRule, updateRule } from '@/services/api'; | |
| 2 | + | |
| 3 | +export default { | |
| 4 | + namespace: 'rule', | |
| 5 | + | |
| 6 | + state: { | |
| 7 | + data: { | |
| 8 | + list: [], | |
| 9 | + pagination: {}, | |
| 10 | + }, | |
| 11 | + }, | |
| 12 | + | |
| 13 | + effects: { | |
| 14 | + *fetch({ payload }, { call, put }) { | |
| 15 | + const response = yield call(queryRule, payload); | |
| 16 | + yield put({ | |
| 17 | + type: 'save', | |
| 18 | + payload: response, | |
| 19 | + }); | |
| 20 | + }, | |
| 21 | + *add({ payload, callback }, { call, put }) { | |
| 22 | + const response = yield call(addRule, payload); | |
| 23 | + yield put({ | |
| 24 | + type: 'save', | |
| 25 | + payload: response, | |
| 26 | + }); | |
| 27 | + if (callback) callback(); | |
| 28 | + }, | |
| 29 | + *remove({ payload, callback }, { call, put }) { | |
| 30 | + const response = yield call(removeRule, payload); | |
| 31 | + yield put({ | |
| 32 | + type: 'save', | |
| 33 | + payload: response, | |
| 34 | + }); | |
| 35 | + if (callback) callback(); | |
| 36 | + }, | |
| 37 | + *update({ payload, callback }, { call, put }) { | |
| 38 | + const response = yield call(updateRule, payload); | |
| 39 | + yield put({ | |
| 40 | + type: 'save', | |
| 41 | + payload: response, | |
| 42 | + }); | |
| 43 | + if (callback) callback(); | |
| 44 | + }, | |
| 45 | + }, | |
| 46 | + | |
| 47 | + reducers: { | |
| 48 | + save(state, action) { | |
| 49 | + return { | |
| 50 | + ...state, | |
| 51 | + data: action.payload, | |
| 52 | + }; | |
| 53 | + }, | |
| 54 | + }, | |
| 55 | +}; | ... | ... |
| 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 | +}; | ... | ... |
请
注册
或
登录
后发表评论