Commit ccab7fe3 authored by zhangwenshuai's avatar zhangwenshuai

修改ts配置

parent f35972ec
{
"presets": [
"env",
"react",
"stage-0"
],
"plugins": [
[
"import",
{
"libraryName": "antd",
"style": true
}
]
]
}
...@@ -20,16 +20,15 @@ ...@@ -20,16 +20,15 @@
"react": "16.x" "react": "16.x"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.7.7",
"@babel/preset-env": "^7.7.7",
"@types/core-js": "^2.5.2",
"@types/react": "^16.9.13", "@types/react": "^16.9.13",
"@types/react-dom": "^16.9.4", "@types/react-dom": "^16.9.4",
"af-webpack": "^1.14.4", "awesome-typescript-loader": "^5.2.1",
"babel-core": "^6.26.3", "babel-core": "^6.26.3",
"babel-loader": "^8.0.6", "babel-loader": "^7.1.5",
"babel-plugin-import": "^1.13.0", "babel-plugin-import": "^1.13.0",
"babel-preset-env": "^1.7.0", "babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"clean-webpack-plugin": "^3.0.0", "clean-webpack-plugin": "^3.0.0",
"cross-env": "^6.0.3", "cross-env": "^6.0.3",
"css-loader": "^3.3.0", "css-loader": "^3.3.0",
...@@ -38,6 +37,7 @@ ...@@ -38,6 +37,7 @@
"js-cookie": "^2.2.1", "js-cookie": "^2.2.1",
"less": "^3.10.3", "less": "^3.10.3",
"less-loader": "^5.0.0", "less-loader": "^5.0.0",
"source-map-loader": "^0.2.4",
"style-loader": "^1.0.1", "style-loader": "^1.0.1",
"ts-loader": "^6.2.1", "ts-loader": "^6.2.1",
"typescript": "^3.7.4", "typescript": "^3.7.4",
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
"dom-helpers": "^5.1.3", "dom-helpers": "^5.1.3",
"father": "^2.29.1", "father": "^2.29.1",
"file-saver": "^2.0.2", "file-saver": "^2.0.2",
"react": "^16.13.0",
"react-dom": "^16.12.0", "react-dom": "^16.12.0",
"react-virtualized": "^9.21.2" "react-virtualized": "^9.21.2"
}, },
......
...@@ -114,6 +114,7 @@ export default class Cell extends React.Component<CellProps, CellState> { ...@@ -114,6 +114,7 @@ export default class Cell extends React.Component<CellProps, CellState> {
title: '确认要删除该条数据吗?', title: '确认要删除该条数据吗?',
autoFocusButton: null, autoFocusButton: null,
onOk: async () => { onOk: async () => {
if (typeof delData === 'function') {
const response = await delData({ tableId, data: { id: record.id } }); const response = await delData({ tableId, data: { id: record.id } });
if (response && response.success) { if (response && response.success) {
message.success('删除成功'); message.success('删除成功');
...@@ -121,6 +122,7 @@ export default class Cell extends React.Component<CellProps, CellState> { ...@@ -121,6 +122,7 @@ export default class Cell extends React.Component<CellProps, CellState> {
getData({ isClean: true }); getData({ isClean: true });
} }
} }
}
}, },
}); });
}; };
...@@ -193,7 +195,7 @@ export default class Cell extends React.Component<CellProps, CellState> { ...@@ -193,7 +195,7 @@ export default class Cell extends React.Component<CellProps, CellState> {
</div> </div>
)} )}
{extraMenu && extraMenu.length > 0 && ( {extraMenu && extraMenu.length > 0 && (
<> <React.Fragment>
<div className={style.splitLine} /> <div className={style.splitLine} />
{extraMenu.map((item: any, i: number) => { {extraMenu.map((item: any, i: number) => {
if (typeof item.hidden === 'function' && item.hidden({ record: cellData, menu: item })) { if (typeof item.hidden === 'function' && item.hidden({ record: cellData, menu: item })) {
...@@ -216,7 +218,7 @@ export default class Cell extends React.Component<CellProps, CellState> { ...@@ -216,7 +218,7 @@ export default class Cell extends React.Component<CellProps, CellState> {
</div> </div>
); );
})} })}
</> </React.Fragment>
)} )}
</div> </div>
); );
......
import React, { PureComponent } from 'react'; import React from 'react';
import { config } from './config'; import { RowRendererParams } from './interface';
import s from './Row.less'; import styles from './Table.less';
import { ColumnProps } from './interface'; import _ from 'lodash';
import IconFont from './base/extra/iconFont'; import Cell from './Cell';
export default class TableRow extends PureComponent<ColumnProps> { const renderBodyCell = ({ column, columnIndex, rowData, rowIndex, key }) => {
render() { const columnData: any = rowData.rowData[columnIndex]; // 列数据
let { type, title, width = 200, columnAttrObj = {} } = this.props; const cellData: any = columnData.cellValueList; // 列数据
if (!config[String(type)]) { let text = '';
type = '1'; if (Array.isArray(cellData) && cellData.length > 0) {
text = cellData[0].text;
} }
let icon = config[String(type)] && config[String(type)].icon; const { width = 200, fixed } = column;
if (String(type) === '13' && !columnAttrObj.isMultiple) { const style: any = {
icon = 'iconziduan-lianxiangdanxuan'; display: 'inline-block',
width: '200px',
};
if (fixed) {
style.position = 'sticky';
style.left = 0;
} }
return ( return (
<div className={s.colContainer} style={{ width }}> <div key={key} style={style}>
<div className={s.colBrief}> {text}
{icon && (typeof icon === 'string' ? <IconFont className={s.colIcon} type={icon} /> : icon)}
<span className={s.colTitle}>{title}</span>
</div>
</div> </div>
); );
};
export default function defaultRowRenderer({
rowClassName,
columns,
rowIndex,
key,
onRowClick,
onRowDoubleClick,
onRowMouseOut,
onRowMouseOver,
onRowRightClick,
rowData,
rowStyle,
}: RowRendererParams) {
const a11yProps: any = { 'aria-rowindex': rowIndex + 1 };
if (onRowClick || onRowDoubleClick || onRowMouseOut || onRowMouseOver || onRowRightClick) {
a11yProps['aria-label'] = 'row';
a11yProps.tabIndex = 0;
if (onRowClick) {
a11yProps.onClick = (event) => onRowClick({ event, rowIndex, rowData });
}
if (onRowDoubleClick) {
a11yProps.onDoubleClick = (event) => onRowDoubleClick({ event, rowIndex, rowData });
}
if (onRowMouseOut) {
a11yProps.onMouseOut = (event) => onRowMouseOut({ event, rowIndex, rowData });
}
if (onRowMouseOver) {
a11yProps.onMouseOver = (event) => onRowMouseOver({ event, rowIndex, rowData });
} }
if (onRowRightClick) {
a11yProps.onContextMenu = (event) => onRowRightClick({ event, rowIndex, rowData });
}
}
return (
<div {...a11yProps} className={rowClassName} key={key} role="row" style={rowStyle}>
{columns.map((column, columnIndex) =>
renderBodyCell({
column,
columnIndex,
rowData,
rowIndex,
key,
}),
)}
</div>
);
} }
...@@ -45,9 +45,7 @@ ...@@ -45,9 +45,7 @@
display: flex; display: flex;
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
border-right: 1px solid #e8e8e8; height: 100%;
border-bottom: 1px solid #e8e8e8;
box-sizing: border-box;
&.disabled { &.disabled {
background: @disabledColor; background: @disabledColor;
...@@ -112,6 +110,7 @@ ...@@ -112,6 +110,7 @@
width: 20px; width: 20px;
text-align: center; text-align: center;
cursor: pointer; cursor: pointer;
height: 16px;
.addIcon { .addIcon {
display: none; display: none;
color: @primaryColor; color: @primaryColor;
...@@ -206,4 +205,11 @@ ...@@ -206,4 +205,11 @@
width: 100%; width: 100%;
outline: none; outline: none;
} }
.bodyRow {
width: 100%;
box-sizing: border-box;
}
.bodyCell {
width: 100%;
height: 100%;
}
This diff is collapsed.
...@@ -29,13 +29,13 @@ export const config: any = { ...@@ -29,13 +29,13 @@ export const config: any = {
}, },
detail: require('./detail/textarea').default, detail: require('./detail/textarea').default,
}, },
// '4': { '4': {
// name: '附件上传', name: '附件上传',
// component: require('./edit/upload').default, component: require('./edit/input').default,
// getFormatter: GetFormatter['UPLOAD'], setFormatter: SetFormatter['INPUT'],
// setFormatter: SetFormatter['UPLOAD'], getFormatter: GetFormatter['INPUT'],
// detail: require('./detail/upload').default, detail: require('./detail/input').default,
// }, },
'5': { '5': {
name: '复选', name: '复选',
component: require('./edit/checkbox').default, // 暂未添加 component: require('./edit/checkbox').default, // 暂未添加
......
...@@ -14,11 +14,10 @@ export default function Detail(props: SearchProps) { ...@@ -14,11 +14,10 @@ export default function Detail(props: SearchProps) {
const tagsVal = value.filter((ls) => ls.value); const tagsVal = value.filter((ls) => ls.value);
const textVal = value.filter((ls) => !ls.value); const textVal = value.filter((ls) => !ls.value);
return ( return (
<> <React.Fragment>
{' '}
{tagsVal.length > 0 ? <Tag value={tagsVal} {...selfAttr} /> : null} {tagsVal.length > 0 ? <Tag value={tagsVal} {...selfAttr} /> : null}
{textVal.length > 0 ? <div className={styles.text}>{textVal[0].text}</div> : null} {textVal.length > 0 ? <div className={styles.text}>{textVal[0].text}</div> : null}
</> </React.Fragment>
); );
} }
} }
import React from 'react'; import React from 'react';
import Upload from '../../extra/upload'; // import Upload from '../../extra/upload';
import styles from './styles.less'; import styles from './styles.less';
import { UploadProps } from '../detailInterface'; import { UploadProps } from '../detailInterface';
...@@ -10,13 +10,12 @@ export default function Detail(props: UploadProps) { ...@@ -10,13 +10,12 @@ export default function Detail(props: UploadProps) {
const { value, formatter, width } = props; const { value, formatter, width } = props;
const formatValue = formatter ? formatter(value) : value; const formatValue = formatter ? formatter(value) : value;
if (!formatValue) return null; if (!formatValue) return null;
let themeValue: any[] = []; let themeValue: any[] = [];
if (Array.isArray(formatValue)) { if (Array.isArray(formatValue)) {
themeValue = formatValue.map((item) => { themeValue = formatValue.map((item) => {
return { return {
...item, ...item,
...Upload.checkoutFileType(item.value), // ...Upload.checkoutFileType(item.value),
}; };
}); });
} }
......
import UpLoad from '../../extra/upload'; // import UpLoad from '../../extra/upload';
export default UpLoad; // export default UpLoad;
...@@ -197,7 +197,7 @@ class AssociationSearch extends React.Component<Props> { ...@@ -197,7 +197,7 @@ class AssociationSearch extends React.Component<Props> {
const { data, fetching, value } = this.state; const { data, fetching, value } = this.state;
const { selfCom, autoFocus, onChange, ...rest } = this.props; const { selfCom, autoFocus, onChange, ...rest } = this.props;
return ( return (
<> <React.Fragment>
<Select <Select
filterOption={false} filterOption={false}
suffixIcon={<img alt="" className={s.suffixIcon} src="https://static.mttop.cn/admin/search.png" />} suffixIcon={<img alt="" className={s.suffixIcon} src="https://static.mttop.cn/admin/search.png" />}
...@@ -226,7 +226,7 @@ class AssociationSearch extends React.Component<Props> { ...@@ -226,7 +226,7 @@ class AssociationSearch extends React.Component<Props> {
})} })}
</Select> </Select>
{selfCom || null} {selfCom || null}
</> </React.Fragment>
); );
} }
} }
......
...@@ -20,23 +20,22 @@ interface Props { ...@@ -20,23 +20,22 @@ interface Props {
value: any; value: any;
label: string; label: string;
}; };
placeholder?:string; placeholder?: string;
width?:number; width?: number;
disabled?:boolean; disabled?: boolean;
} }
interface State { interface State {
searchStr: string, searchStr: string;
list: any[], list: any[];
loading: boolean, loading: boolean;
selected: any[], selected: any[] | undefined;
tempSelected: any[], tempSelected: any[] | undefined;
tempVisible: boolean, tempVisible: boolean;
} }
class TextSelect extends React.Component<Props,State> { class TextSelect extends React.Component<Props, State> {
container: any; container: any;
input: any; input: any;
width: number; width: number = 320;
inputWidth = 320;
constructor(props) { constructor(props) {
super(props); super(props);
......
...@@ -30,7 +30,7 @@ export const getComponent = (type: string) => { ...@@ -30,7 +30,7 @@ export const getComponent = (type: string) => {
return value; return value;
}; };
const getFormat = (columnConfig: any, values: any[]) => { const getFormat = (columnConfig: any, values: any) => {
const { columnAttrObj, columnType } = columnConfig || {}; const { columnAttrObj, columnType } = columnConfig || {};
if (!values || !Array.isArray(values) || values.length <= 0) return undefined; if (!values || !Array.isArray(values) || values.length <= 0) return undefined;
const newValue = values.filter((item) => { const newValue = values.filter((item) => {
......
...@@ -11,5 +11,8 @@ ...@@ -11,5 +11,8 @@
.tableC { .tableC {
padding: 0 16px; padding: 0 16px;
} }
.rowClassName{
border: 1px solid black;
}
} }
} }
...@@ -38,6 +38,7 @@ class AirTable extends React.Component<CommonProps, CommonState> { ...@@ -38,6 +38,7 @@ class AirTable extends React.Component<CommonProps, CommonState> {
render() { render() {
const { columns, dataSource, tableId } = this.state; const { columns, dataSource, tableId } = this.state;
const { rowStyle } = this.props;
const operateConfig = {}; const operateConfig = {};
return ( return (
<div className={styles.container}> <div className={styles.container}>
...@@ -48,6 +49,8 @@ class AirTable extends React.Component<CommonProps, CommonState> { ...@@ -48,6 +49,8 @@ class AirTable extends React.Component<CommonProps, CommonState> {
tableId={tableId} tableId={tableId}
onScroll={this.onScroll} onScroll={this.onScroll}
operateConfig={operateConfig} operateConfig={operateConfig}
rowStyle={rowStyle}
rowClassName={styles.rowClassName}
/> />
</div> </div>
</div> </div>
......
...@@ -6,6 +6,9 @@ export interface CommonProps { ...@@ -6,6 +6,9 @@ export interface CommonProps {
tableId: number; tableId: number;
checked?: any[]; checked?: any[];
columnWidth?: number; columnWidth?: number;
rowClassName?: string | Function;
rowStyle?: Object | Function;
rowRenderer?: Function;
} }
export interface CommonState { export interface CommonState {
...@@ -32,6 +35,10 @@ export interface TableProps extends CommonProps { ...@@ -32,6 +35,10 @@ export interface TableProps extends CommonProps {
noAdd?: boolean; noAdd?: boolean;
noEdit?: boolean; noEdit?: boolean;
noDel?: boolean; noDel?: boolean;
rowClassName?: string | Function;
rowStyle?: Object | Function;
rowRenderer?: Function;
rowBorder?:string;
} }
export interface TableState extends CommonState { export interface TableState extends CommonState {
...@@ -39,6 +46,21 @@ export interface TableState extends CommonState { ...@@ -39,6 +46,21 @@ export interface TableState extends CommonState {
tableHeight: number; tableHeight: number;
tableWidth: number; tableWidth: number;
} }
export interface RowRendererParams {
rowClassName?: string|Function;
columns: Array<any>;
rowIndex: number;
isScrolling: boolean;
onRowClick?: Function;
onRowDoubleClick?: Function;
onRowMouseOver?: Function;
onRowMouseOut?: Function;
onRowRightClick?: Function;
rowData: any;
rowStyle?: any;
key: string;
}
export interface ColumnProps { export interface ColumnProps {
type: string; type: string;
title: string; title: string;
......
...@@ -31,7 +31,7 @@ const handleRestfulUrl = (url: string = '', options: any = {}) => { ...@@ -31,7 +31,7 @@ const handleRestfulUrl = (url: string = '', options: any = {}) => {
const { API_IDS = '' } = newParams || {}; const { API_IDS = '' } = newParams || {};
const type = checkoutType(API_IDS); const type = checkoutType(API_IDS);
if (type === 'array' && API_IDS.length > 0) { if (type === 'array' && API_IDS.length > 0) {
const ids = []; const ids:any[] = [];
return url.replace(/{id}/g, (word) => { return url.replace(/{id}/g, (word) => {
ids.push(word); ids.push(word);
return API_IDS[ids.length - 1]; return API_IDS[ids.length - 1];
......
...@@ -4,5 +4,14 @@ import ApolloTable from '../apollo-table'; ...@@ -4,5 +4,14 @@ import ApolloTable from '../apollo-table';
import Data from './data'; import Data from './data';
const { cols, list } = Data; const { cols, list } = Data;
const rowStyle = ({ index, record }) => {
render(<ApolloTable columns={cols} dataSource={list} tableId={1} />, document.getElementById('root')); const style: any = {};
if (index % 3 === 0) {
style.background = 'red';
}
return style;
};
render(
<ApolloTable rowStyle={rowStyle} columns={cols} dataSource={list} tableId={1} />,
document.getElementById('root'),
);
...@@ -3,22 +3,19 @@ ...@@ -3,22 +3,19 @@
"outDir": "./dist/", "outDir": "./dist/",
"sourceMap": false, "sourceMap": false,
"noImplicitAny": false, "noImplicitAny": false,
"module": "commonjs", "module": "esnext",
"target": "es5", "target": "es5",
"jsx": "react", "jsx": "preserve",
"esModuleInterop": true "esModuleInterop": true,
}, "allowSyntheticDefaultImports": true,
"include": ["./typings.d.ts"], "moduleResolution": "node",
"files": [ "importHelpers": true,
"./src/test/index.tsx", "strict": true,
"./src/test/data.ts", "baseUrl": ".",
"./src/apollo-table/index.tsx", "paths": {
"./src/apollo-table/component/index.tsx", "@/*": [
"./src/apollo-table/component/interface.tsx", "src/*"
"./src/apollo-table/component/config.ts",
"./src/apollo-table/component/Table.tsx",
"./src/apollo-table/component/Column.tsx",
"./src/apollo-table/component/base/index.tsx",
"./src/apollo-table/component/base/config.tsx",
] ]
}
}
} }
...@@ -2,28 +2,12 @@ const path = require('path'); ...@@ -2,28 +2,12 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const webpack = require('webpack'); const webpack = require('webpack');
// 根据API_ENV环境不同分为debugger开发代理(api),development为使用dev的api,production为使用线上api
function getIp() {
const interfaces = require('os').networkInterfaces(); // 在开发环境中获取局域网中的本机iP地址
let IPAdress = '';
for (var devName in interfaces) {
var iface = interfaces[devName];
for (var i = 0; i < iface.length; i++) {
var alias = iface[i];
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
IPAdress = alias.address;
}
}
}
return IPAdress;
}
const proxyHost = { const proxyHost = {
localhost: 'http://192.168.16.252:8093', //链接本地调试 localhost: 'http://192.168.16.252:8093', //链接本地调试
development: 'https://arthas.mttop.cn', development: 'https://arthas.mttop.cn',
production: 'https://mt.mttop.cn', production: 'https://mt.mttop.cn',
feature: 'http://192.168.8.108:8096', feature: 'http://192.168.8.108:8096',
mock: `http://${getIp()}:8000`,
}; };
const proxy_env = proxyHost[process.env.PROXY_ENV]; const proxy_env = proxyHost[process.env.PROXY_ENV];
...@@ -44,24 +28,40 @@ module.exports = { ...@@ -44,24 +28,40 @@ module.exports = {
rules: [ rules: [
{ {
test: /\.tsx?$/, test: /\.tsx?$/,
include: [path.resolve(__dirname, 'src')], exclude: /node_modules/,
use: ['ts-loader'], use: [
{
loader: 'babel-loader',
},
{
loader: 'ts-loader',
},
],
}, },
{ {
test: /\.jsx?$/, test: /\.jsx?$/,
include: [path.resolve(__dirname, 'src')], exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.less$/,
include: /node_modules\/antd/, // antd中的样式
use: [ use: [
'style-loader',
'css-loader',
{ {
loader: 'babel-loader', loader: 'less-loader',
options: { options: {
presets: ['@babel/preset-env'], javascriptEnabled: true,
}, },
}, },
], ],
}, },
{ {
test: /\.less$/, test: /\.less$/,
include: [path.resolve(__dirname, 'src')], exclude: /node_modules/, // 项目中的样式
use: [ use: [
'style-loader', 'style-loader',
{ {
...@@ -70,11 +70,16 @@ module.exports = { ...@@ -70,11 +70,16 @@ module.exports = {
modules: true, modules: true,
}, },
}, },
'less-loader', {
loader: 'less-loader',
options: {
modules: true,
},
},
], ],
}, },
{ {
test: /\.css$/, test: /\.css$/, // 外部引入的react-virtualized/styles.css
use: [ use: [
'style-loader', 'style-loader',
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment