!1472 重构:选择板材页面

pull/1472/MERGE
ChenX 4 years ago
parent 08adfb6c5e
commit 626d18e93a

@ -50,7 +50,6 @@
"clean-webpack-plugin": "^3.0.0", "clean-webpack-plugin": "^3.0.0",
"css-loader": "^5.0.1", "css-loader": "^5.0.1",
"file-loader": "^6.1.0", "file-loader": "^6.1.0",
"fork-ts-checker-webpack-plugin": "^6.0.8",
"fs-extra-plus": "^0.5.20", "fs-extra-plus": "^0.5.20",
"git-revision-webpack-plugin": "^3.0.6", "git-revision-webpack-plugin": "^3.0.6",
"gitlog": "^4.0.0", "gitlog": "^4.0.0",
@ -58,8 +57,8 @@
"html-webpack-plugin": "^4.4.1", "html-webpack-plugin": "^4.4.1",
"jest": "^26.4.2", "jest": "^26.4.2",
"jest-snapshot": "^26.4.2", "jest-snapshot": "^26.4.2",
"less": "^3.12.2", "less": "^4.1.1",
"less-loader": "^7.1.0", "less-loader": "7.3.0",
"react-hot-loader": "^4.12.21", "react-hot-loader": "^4.12.21",
"request": "^2.88.2", "request": "^2.88.2",
"request-promise-native": "^1.0.9", "request-promise-native": "^1.0.9",
@ -92,12 +91,12 @@
}, },
"dependencies": { "dependencies": {
"@blueprintjs/core": "^3.36.0", "@blueprintjs/core": "^3.36.0",
"@blueprintjs/table": "^3.8.27",
"@types/react-virtualized-auto-sizer": "^1.0.0", "@types/react-virtualized-auto-sizer": "^1.0.0",
"@types/react-window": "^1.8.2", "@types/react-window": "^1.8.2",
"detect-browser": "^5.1.1", "detect-browser": "^5.1.1",
"dxf-parser-2": "^1.0.0-alpha.4", "dxf-parser-2": "^1.0.0-alpha.4",
"flatbush": "^3.3.0", "flatbush": "^3.3.0",
"golden-layout": "^1.5.9",
"js-angusj-clipper": "^1.1.0", "js-angusj-clipper": "^1.1.0",
"mobx": "^5.15.6", "mobx": "^5.15.6",
"mobx-react": "^6.3.0", "mobx-react": "^6.3.0",

@ -216,6 +216,7 @@ export class BoardProcessModal extends React.Component<BoardProcessProps, {}>{
/> />
<button <button
className="bp3-button bp3-intent-success" className="bp3-button bp3-intent-success"
style={{ width: "2rem" }}
onClick={() => this.showShops.set(true)} onClick={() => this.showShops.set(true)}
></button> ></button>
{ {

@ -4,7 +4,7 @@
} }
.long-select>.bp3-select>select { .long-select>.bp3-select>select {
width: @infoSelectWidth width: @infoSelectWidth;
} }
.board-info>.bp3-label input { .board-info>.bp3-label input {
@ -151,11 +151,6 @@
position : relative; position : relative;
margin-bottom: 0.5rem; margin-bottom: 0.5rem;
// justify-content: space-between;
button {
width: 2rem;
}
input { input {
width: 6.5rem; width: 6.5rem;
} }

@ -1,7 +1,7 @@
import { Button, ButtonGroup, Classes, Icon, Label, NumericInput } from '@blueprintjs/core';
import { IconNames } from '@blueprintjs/icons';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import * as React from 'react'; import * as React from 'react';
import { Label, Classes, Icon } from '@blueprintjs/core';
import { IconNames } from '@blueprintjs/icons';
import { safeEval } from '../../../Common/eval'; import { safeEval } from '../../../Common/eval';
interface IPaginationProps interface IPaginationProps
@ -131,3 +131,134 @@ export class Pagination extends React.Component<IPaginationProps, { startPage: n
); );
} }
} }
const CELL_COUNT = 8;
function pagingCells(n, pos, maxCells = CELL_COUNT)
{
// Consider an array of pages with length `n`. Let `p` be cursor position.
// [1, 2, 3, ..., n-1, n]
//
// Requirements:
// - In all cases we want to keep `1` and `n` visible.
// - We cant render more than CELL_COUNT items.
// - If the cells exceed CELL_COUNT, insert `...` wherever appropriate.
const offset = n - pos;
const pivot = ~~(maxCells / 2);
let cells = [];
if (n > CELL_COUNT)
{
// Fill in first and last positions
cells[0] = { nr: 1 };
cells[1] = { nr: 2 };
cells[CELL_COUNT - 2] = { nr: n - 1 };
cells[CELL_COUNT - 1] = { nr: n };
if (pos <= pivot)
{
// last ellipse is enabled and the rest of the array is filled
cells[CELL_COUNT - 2].ellipsis = true;
for (let i = 2; i < CELL_COUNT - 2; i++)
{
cells[i] = { nr: i + 1 };
}
} else if (offset < pivot)
{
// a ellipsis is enabled and the later part of array is filled
cells[1].ellipsis = true;
for (let i = 2; i < CELL_COUNT - 2; i++)
{
cells[i] = { nr: n - CELL_COUNT + i + 1 };
}
} else
{
// both a and b ellipsis are enabled
cells[1].ellipsis = true;
cells[CELL_COUNT - 2].ellipsis = true;
// Current selected is put in centre
cells[pivot] = { nr: pos };
// Fill next and prev to mid point
// CELL_COUNT - 5 := n{MID, FIRST, SECOND, LAST, SECONDLAST}
for (let i = 1; i < CELL_COUNT - 5; i++)
{
cells[pivot + i] = { nr: pos + i };
cells[pivot - i] = { nr: pos - i };
}
}
} else
{
for (let i = 0; i < n; i++)
{
cells[i] = { nr: i + 1, ellipsis: false };
}
}
return cells;
}
function name({ a, b })
{
}
interface PaginationProps
{
count: number;
cursor: number,
onPaginate: (number) => void;
maxCells?: number;
}
export const Pagination2 = ({ count, cursor, onPaginate, maxCells = CELL_COUNT }: PaginationProps) =>
{
// Renders a Pagination Button Group, inserting ellipsis based on cursor.
// ┌───┬───┬───┬───┬───┐
// │ < │ 1 │ 2 │ 3 │ > │
// └───┴───┴───┴───┴───┘
// ┌───┬───┬───┬───┬───┬───┬───┬───┬───┐
// │ < │ 1 │ 2 │ 3 │ 4 │...│ 9 │10 │ > │
// └───┴───┴───┴───┴───┴───┴───┴───┴───┘
// ┌───┬───┬───┬───┬───┬───┬───┬───┬───┐
// │ < │ 1 │...│ 4 │ 5 │ 6 │...│10 │ > │
// └───┴───┴───┴───┴───┴───┴───┴───┴───┘
const PrevPage = <Button
icon='arrow-left'
disabled={cursor <= 1}
onClick={() => onPaginate(cursor - 1)}
text='' />;
const NextPage = <Button
rightIcon='arrow-right'
disabled={cursor >= count}
onClick={() => onPaginate(cursor + 1)}
text='' />;
return (
<ButtonGroup className='pagination'>
{PrevPage}
{pagingCells(count, cursor, maxCells).map(({ nr, ellipsis }) =>
<Button
text={!ellipsis && nr}
icon={ellipsis ? 'more' : undefined}
disabled={ellipsis}
key={nr}
active={nr === cursor}
onClick={() => onPaginate(nr)} />
)}
{NextPage}
<NumericInput
width={"20px"}
min={1}
max={count}
value={cursor}
defaultValue={cursor} onValueChange={v =>
{
onPaginate(v);
}}></NumericInput >
</ButtonGroup>
);
};

@ -1,22 +0,0 @@
import * as GoldenLayout from 'golden-layout';
import { layoutOnsizeEvent } from './LayoutOnSizeEventManage';
export const ContainerComponenName = "container";
/**
* .
*
* @export
* @param {GoldenLayout} layout
*/
export function LayoutRegisterContainerComponent(layout: GoldenLayout)
{
layout.registerComponent(ContainerComponenName, function (container: GoldenLayout.Container, state)
{
container.on("resize", () =>
{
layoutOnsizeEvent.dispatchonSize(state.id);
});
container.getElement().html(`<div id=${state.id} style="width: 100%;height: 100%;"></div>`);
});
}

@ -1,13 +1,11 @@
import { Card, HTMLTable, Icon, InputGroup, Tooltip } from '@blueprintjs/core';
import { IObservableValue, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react'; import * as React from 'react';
import { observable, IObservableValue } from 'mobx';
import { InputGroup, Icon, Classes, Card } from '@blueprintjs/core';
import { RequestStatus, PostJson } from '../../Common/Request';
import { ShopUrls } from '../../Common/HostUrl'; import { ShopUrls } from '../../Common/HostUrl';
import { appCache } from '../../Common/AppCache';
import { StoreageKeys } from '../../Common/StoreageKeys';
import { Pagination } from '../Components/SourceManage/Pagination';
import { observer } from 'mobx-react';
import { KeyBoard } from '../../Common/KeyEnum'; import { KeyBoard } from '../../Common/KeyEnum';
import { PostJson, RequestStatus } from '../../Common/Request';
import { Pagination2 } from '../Components/SourceManage/Pagination';
export interface IGoodInfo export interface IGoodInfo
{ {
@ -28,9 +26,9 @@ export class GoodsList extends React.Component<IGoodsListProps> {
@observable searchStr = ""; @observable searchStr = "";
@observable goods = []; @observable goods = [];
@observable info = { @observable info = {
count: 0, count: 0,//一共有n个
currentPage: 1, currentPage: 1,
pageCount: 20 pageCount: 22//每页20
}; };
private isDesc: boolean; private isDesc: boolean;
UNSAFE_componentWillMount() UNSAFE_componentWillMount()
@ -42,7 +40,6 @@ export class GoodsList extends React.Component<IGoodsListProps> {
return ( return (
this.props.open.get() && this.props.open.get() &&
<> <>
<Card className="search-shop" <Card className="search-shop"
tabIndex={-1} tabIndex={-1}
onKeyUp={this.handleKeyDown} onKeyUp={this.handleKeyDown}
@ -53,58 +50,58 @@ export class GoodsList extends React.Component<IGoodsListProps> {
onChange={this.handleChange} onChange={this.handleChange}
autoFocus autoFocus
rightElement={<Icon icon="double-caret-vertical" />} /> rightElement={<Icon icon="double-caret-vertical" />} />
<div className="title"> <HTMLTable bordered={true} interactive={true} condensed={true} striped={false}
<span></span> style={{ lineHeight: 0.7 }}
<span></span> >
<span className="flex-between"> <thead>
<Icon <tr>
icon="double-caret-vertical" <th></th>
style={{ padding: 0, cursor: "pointer" }} <th></th>
onClick={this.handleOrderGoods} <th onClick={this.handleOrderGoods}
/> style={{ cursor: "pointer", minWidth: 80 }
</span> }><Icon icon={this.isDesc === undefined ? "double-caret-vertical" : (this.isDesc ? "chevron-up" : "chevron-down")} />
<span></span> </th>
<span></span> <th></th>
<span></span> <th></th>
</div> <th></th>
<ul className={Classes.LIST_UNSTYLED}> </tr>
{ </thead>
this.goods.map(v => <tbody>
{ {
let mat = v.goods_param.find(p => p.name === "材料"); this.goods.map(v =>
let color = v.goods_param.find(p => p.name === "颜色"); {
let thick = v.goods_param.find(p => p.name === "厚"); let mat = v.goods_param.find(p => p.name === "材料");
let color = v.goods_param.find(p => p.name === "颜色");
let thick = v.goods_param.find(p => p.name === "厚");
let matName = mat ? mat.value : ""; let matName = mat ? mat.value : "";
let colorName = color ? color.value : ""; let colorName = color ? color.value : "";
let info = { let info = {
goods_id: v.goods_id, goods_id: v.goods_id,
name: v.goods_name, name: v.goods_name,
color: colorName, color: colorName,
material: matName, material: matName,
}; };
appCache.set(StoreageKeys.Goods + v.goods_id, info);
return <li return <tr
value={v.goods_id} key={v.goods_id}
onClick={() => this.props.select(info)} onClick={() => this.props.select(info)}
> style={{ lineHeight: "normal" }}
<span>{v.goods_sn}</span> >
<span>{v.goods_name}</span> <td>{v.goods_sn}</td>
<span>{thick ? thick.value : ""}</span> <td><OneLineText text={v.goods_name} /></td>
<span>{matName}</span> <td>{thick ? thick.value : ""}</td>
<span>{colorName}</span> <td><OneLineText text={matName} /></td>
<span>{v.goods_stock}</span> <td><OneLineText text={colorName} /></td>
</li>; <td>{v.goods_stock}</td>
}) </tr>;
} })
</ul> }
</tbody>
</HTMLTable>
{ {
this.info.count > 20 && this.info.count > this.info.pageCount &&
<Pagination <Pagination2 count={Math.ceil(this.info.count / this.info.pageCount)} cursor={this.info.currentPage} onPaginate={this.handleSearch} />
pageData={this.info}
getImgListFun={this.handleSearch}
/>
} }
</Card> </Card>
<div className="masking" onClick={this.handleHideSelect}></div> <div className="masking" onClick={this.handleHideSelect}></div>
@ -122,18 +119,19 @@ export class GoodsList extends React.Component<IGoodsListProps> {
await this.handleSearch(); await this.handleSearch();
}, 500); }, 500);
}; };
handleSearch = async (opt: { curr_page: number; } = { curr_page: 1 }) => handleSearch = async (page = 1) =>
{ {
this.info.currentPage = opt.curr_page; this.info.currentPage = page;
let order: string; let order: string;
if (this.isDesc !== undefined) if (this.isDesc !== undefined)
order = this.isDesc ? "2" : "2 DESC"; order = this.isDesc ? "2" : "2 DESC";
const query: any = { const query: any = {
...opt, curr_page: page,
goods_name: this.searchStr, goods_name: this.searchStr,
bind_type: 1, bind_type: 1,
goods_type: 1, goods_type: 1,
page_count: this.info.pageCount,
}; };
if (order) if (order)
query.order = order; query.order = order;
@ -164,7 +162,20 @@ export class GoodsList extends React.Component<IGoodsListProps> {
clearTimeout(this.timeId); clearTimeout(this.timeId);
this.timeId = setTimeout(async () => this.timeId = setTimeout(async () =>
{ {
await this.handleSearch({ curr_page: 1 }); await this.handleSearch(1);
}, 200); }, 200);
}; };
} }
const InLineStyle: React.CSSProperties = {
display: "-webkit-box",
WebkitBoxOrient: "vertical",
WebkitLineClamp: 1,
overflow: "hidden",
alignSelf: "center",
};
function OneLineText({ text }: { text: string; })
{
return <span style={InLineStyle}>{text}</span>;
}

@ -145,29 +145,17 @@
z-index : 35; z-index : 35;
padding : 10px; padding : 10px;
font-size: 16px; font-size: 16px;
width : 740px; width : 1000px;
outline : 1px solid #ccc; outline : 1px solid #ccc;
.title { .bp3-html-table.bp3-html-table-condensed td {
display: flex; padding-top : 1.5px;
padding-bottom: 1.5px;
span { padding-right : 1.5px;
width : 25%;
outline: 1px solid #ccc;
padding: 5px 5px;
}
} }
ul>li { table {
display: flex; width: 100%;
span {
width : 25%;
overflow : hidden;
text-overflow: ellipsis;
outline : 1px solid #ccc;
white-space : nowrap;
}
} }
input { input {
@ -178,10 +166,6 @@
top: 5px !important; top: 5px !important;
} }
li:hover {
background: rgb(26, 128, 191)
}
.pagination li { .pagination li {
padding-left: 11px; padding-left: 11px;
} }

@ -58,6 +58,7 @@ export class MaterialLinkShopId extends React.Component<{ store?: MaterialStore;
/> />
<Button <Button
text="选择" text="选择"
style={{ width: "2rem" }}
intent={Intent.SUCCESS} intent={Intent.SUCCESS}
onClick={this.handleOpenShopList} onClick={this.handleOpenShopList}
/> />

Loading…
Cancel
Save