feat(zhst/biz): 优化树选择
This commit is contained in:
parent
aea6e2ec4c
commit
207e734e73
@ -1,5 +1,52 @@
|
||||
# @zhst/biz
|
||||
|
||||
## 0.18.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- zhst/biz 优化 boxselecttree
|
||||
|
||||
## 0.18.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- biz-transfer: 修改删除时透出
|
||||
|
||||
## 0.18.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- zhst/biz - 修改穿梭框事件透出
|
||||
|
||||
## 0.18.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @zhst/func@0.11.2
|
||||
- @zhst/hooks@0.10.2
|
||||
- @zhst/meta@0.16.2
|
||||
|
||||
## 0.18.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @zhst/func@0.11.1
|
||||
- @zhst/hooks@0.10.1
|
||||
- @zhst/meta@0.16.1
|
||||
|
||||
## 0.18.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- zhst/biz:新增摘要列表-无限滚动组件
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @zhst/hooks@0.10.0
|
||||
- @zhst/func@0.11.0
|
||||
- @zhst/meta@0.16.0
|
||||
|
||||
## 0.17.0
|
||||
|
||||
### Minor Changes
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/biz",
|
||||
"version": "0.17.0",
|
||||
"version": "0.18.5",
|
||||
"description": "业务库",
|
||||
"keywords": [
|
||||
"business",
|
||||
|
@ -34,63 +34,43 @@ const BoxSelectTree: FC<BoxSelectTreeProps> = (props) => {
|
||||
{
|
||||
key: '1',
|
||||
label: <div style={{ textAlign:'center', width: '160px' }} >盒子</div>,
|
||||
children: (
|
||||
<BoxPanel
|
||||
searchInputProps={searchInputProps}
|
||||
boxDataSource={boxDataSource}
|
||||
treeProps={treeProps}
|
||||
data={data}
|
||||
onCreate={onCreate}
|
||||
onCreateSubmit={onCreateSubmit}
|
||||
onBoxBatchDelete={onBoxBatchDelete}
|
||||
onBoxDelete={onBoxDelete}
|
||||
onSearch={onSearch}
|
||||
onItemCheck={onItemCheck}
|
||||
onItemSelect={onItemSelect}
|
||||
showOptions={showOptions}
|
||||
customImport={customImport}
|
||||
extraBtns={extraBtns}
|
||||
onClockClick={onClockClick}
|
||||
onImport={onImport}
|
||||
/>
|
||||
)
|
||||
},
|
||||
{
|
||||
key: '2',
|
||||
label: <div style={{ textAlign:'center', width: '160px' }} >盒子组</div>,
|
||||
children: (
|
||||
<BoxPanel
|
||||
searchInputProps={searchInputProps}
|
||||
boxDataSource={boxDataSource}
|
||||
treeProps={treeProps}
|
||||
data={data}
|
||||
onCreate={onCreate}
|
||||
onCreateSubmit={onCreateSubmit}
|
||||
onBoxBatchDelete={onBoxBatchDelete}
|
||||
onBoxDelete={onBoxDelete}
|
||||
onSearch={onSearch}
|
||||
onItemCheck={onItemCheck}
|
||||
onItemSelect={onItemSelect}
|
||||
showOptions={showOptions}
|
||||
customImport={customImport}
|
||||
extraBtns={extraBtns}
|
||||
onClockClick={onClockClick}
|
||||
onImport={onImport}
|
||||
/>
|
||||
)
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
defaultActiveKey="1"
|
||||
centered
|
||||
items={items}
|
||||
onChange={onTabChange}
|
||||
tabBarGutter={0}
|
||||
indicator={{ size: (origin) => origin, align: 'center' }}
|
||||
{...tabsProps}
|
||||
/>
|
||||
<div className='box-select-tree'>
|
||||
<Tabs
|
||||
defaultActiveKey="1"
|
||||
centered
|
||||
items={items}
|
||||
onChange={onTabChange}
|
||||
tabBarGutter={0}
|
||||
indicator={{ size: (origin) => origin, align: 'center' }}
|
||||
{...tabsProps}
|
||||
/>
|
||||
<BoxPanel
|
||||
searchInputProps={searchInputProps}
|
||||
boxDataSource={boxDataSource}
|
||||
treeProps={treeProps}
|
||||
data={data}
|
||||
onCreate={onCreate}
|
||||
onCreateSubmit={onCreateSubmit}
|
||||
onBoxBatchDelete={onBoxBatchDelete}
|
||||
onBoxDelete={onBoxDelete}
|
||||
onSearch={onSearch}
|
||||
onItemCheck={onItemCheck}
|
||||
onItemSelect={onItemSelect}
|
||||
showOptions={showOptions}
|
||||
customImport={customImport}
|
||||
extraBtns={extraBtns}
|
||||
onClockClick={onClockClick}
|
||||
onImport={onImport}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -18,4 +18,4 @@ export type { VideoPlayerCardProps } from './VideoPlayerCard'
|
||||
export { default as VideoPlayerCard } from './VideoPlayerCard'
|
||||
export { default as RealTimeMonitor } from './RealTimeMonitor'
|
||||
export { default as InfiniteList } from './infiniteList'
|
||||
// export type { InfiniteListProps, InfiniteListRefProps } from './infiniteList'
|
||||
export type { InfiniteListProps, InfiniteListRefProps } from './infiniteList'
|
||||
|
@ -9,6 +9,7 @@ import classNames from 'classnames';
|
||||
import InfiniteScroll from 'react-infinite-scroll-component';
|
||||
import { SearchCard, SearchCardProps } from './components';
|
||||
import './index.less'
|
||||
import { Idata } from './components/SearchCard';
|
||||
|
||||
const { ConfigContext } = ConfigProvider
|
||||
|
||||
@ -18,7 +19,7 @@ export interface InfiniteListProps {
|
||||
height?: number;
|
||||
itemRender?: (data?: any) => React.ReactNode
|
||||
loading?: boolean; //
|
||||
data: any[];
|
||||
data: Idata[];
|
||||
targetId?: string; // 滚动列表 ID
|
||||
loadMore?: (data?: any) => any;
|
||||
params?: {
|
||||
@ -92,17 +93,19 @@ const InfiniteList = forwardRef<InfiniteListRefProps, InfiniteListProps>((props,
|
||||
scrollableTarget={targetId}
|
||||
>
|
||||
<Flex wrap='wrap' gap="small" className={classNames(componentName + 'items')}>
|
||||
{data?.map((item) => (
|
||||
{data?.map((item, idx) => (
|
||||
itemRender?.(item) || (
|
||||
<div
|
||||
key={item.key || item.id}
|
||||
key={idx}
|
||||
className={classNames(componentName + 'items-item')}
|
||||
onClick={(e) => {
|
||||
onClick={() => {
|
||||
onItemClick?.(item)
|
||||
}}
|
||||
>
|
||||
<SearchCard
|
||||
id={idx + 1}
|
||||
data={item}
|
||||
width="184px"
|
||||
{...searchCardProps}
|
||||
/>
|
||||
</div>
|
||||
|
@ -9,18 +9,19 @@ import './index.less'
|
||||
|
||||
const { ConfigContext } = ConfigProvider
|
||||
|
||||
export interface SearchCardProps {
|
||||
prefixCls?: string;
|
||||
id?: string;
|
||||
key?: string;
|
||||
export interface Idata {
|
||||
id?: string | number;
|
||||
url?: string;
|
||||
data?: {
|
||||
key?: string;
|
||||
url?: string;
|
||||
sort?: number;
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
}
|
||||
sort?: number;
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
}
|
||||
|
||||
export interface SearchCardProps extends Idata {
|
||||
prefixCls?: string;
|
||||
data?: Idata
|
||||
width?: string;
|
||||
height?: string;
|
||||
onCreateTxt?: string;
|
||||
onCreate?: (data: any) => void;
|
||||
onAddTxt?: string;
|
||||
@ -38,7 +39,9 @@ const SearchCard = forwardRef<SearchCardRefProps, SearchCardProps>((props, ref)
|
||||
prefixCls: customizePrefixCls,
|
||||
url,
|
||||
id,
|
||||
key,
|
||||
title,
|
||||
subtitle,
|
||||
sort,
|
||||
data,
|
||||
onCreate,
|
||||
onCreateTxt = '创建检索',
|
||||
@ -46,14 +49,16 @@ const SearchCard = forwardRef<SearchCardRefProps, SearchCardProps>((props, ref)
|
||||
onRemoveTxt = '移除轨迹',
|
||||
onAdd,
|
||||
onRemove,
|
||||
customOptionRender
|
||||
customOptionRender,
|
||||
width = '184px',
|
||||
height = '100%'
|
||||
} = props
|
||||
const { getPrefixCls } = useContext(ConfigContext)
|
||||
const componentName = getPrefixCls('biz-search-card', customizePrefixCls);
|
||||
|
||||
const stopBumble = (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>, fn: ((data: any) => void) | undefined, data: { url?: string | undefined; key?: string | undefined; title?: string | undefined; subtitle?: string | undefined; } | undefined) => {
|
||||
const stopBumble = (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>, fn?: ((data: Idata) => void), data?: Idata) => {
|
||||
e.stopPropagation()
|
||||
fn?.(data)
|
||||
fn?.(data!)
|
||||
}
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
@ -61,11 +66,17 @@ const SearchCard = forwardRef<SearchCardRefProps, SearchCardProps>((props, ref)
|
||||
}))
|
||||
|
||||
return (
|
||||
<div className={componentName} key={id || key}>
|
||||
<div
|
||||
className={componentName}
|
||||
style={{
|
||||
width,
|
||||
height
|
||||
}}
|
||||
>
|
||||
<div className={`${componentName}-main`}>
|
||||
<i className={`${componentName}-main-num`}>-</i>
|
||||
<i className={`${componentName}-main-num`}>{id || sort}</i>
|
||||
<Image
|
||||
src={url}
|
||||
src={url || data?.url}
|
||||
preview={false}
|
||||
width={'100%'}
|
||||
height={'240px'}
|
||||
@ -84,8 +95,8 @@ const SearchCard = forwardRef<SearchCardRefProps, SearchCardProps>((props, ref)
|
||||
</Flex>
|
||||
</div>
|
||||
<div className={`${componentName}-footer`}>
|
||||
<p className={`${componentName}-footer-tit`}>04/28 08:21:58</p>
|
||||
<p className={`${componentName}-footer-subtitle`}>西2-1</p>
|
||||
<p className={`${componentName}-footer-tit`}>{title || data?.title}</p>
|
||||
<p className={`${componentName}-footer-subtitle`}>{subtitle || data?.subtitle}</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
@ -13,8 +13,6 @@
|
||||
|
||||
&-main {
|
||||
position: relative;
|
||||
width: 184px;
|
||||
height: 240px;
|
||||
|
||||
&-num {
|
||||
position: absolute;
|
||||
@ -22,7 +20,10 @@
|
||||
top: 2px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
font-style: normal;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
color: rgb(153, 153, 153);
|
||||
background-color: rgba(255, 255, 255, 75%);
|
||||
z-index: 1;
|
||||
@ -53,7 +54,7 @@
|
||||
}
|
||||
|
||||
&-footer {
|
||||
padding: 12px;
|
||||
padding: 6px;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
|
||||
|
@ -13,7 +13,14 @@ export default () => {
|
||||
fetch('https://randomuser.me/api/?results=10&inc=id,key,name,gender,email,nat,picture&noinfo')
|
||||
.then((res) => res.json())
|
||||
.then((body) => {
|
||||
setData([...data, ...body.results]);
|
||||
let res = body.results.map(o => {
|
||||
return {
|
||||
title: o.name.first,
|
||||
subtitle: o.name.last,
|
||||
url: o.picture.large
|
||||
}
|
||||
})
|
||||
setData([...data, ...res]);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch(() => {
|
||||
|
@ -15,7 +15,14 @@ export default () => {
|
||||
fetch('https://randomuser.me/api/?results=10&inc=id,key,name,gender,email,nat,picture&noinfo')
|
||||
.then((res) => res.json())
|
||||
.then((body) => {
|
||||
setData([...data, ...body.results]);
|
||||
let res = body.results.map(o => {
|
||||
return {
|
||||
title: o.name.first,
|
||||
subtitle: o.name.last,
|
||||
url: o.picture.large
|
||||
}
|
||||
})
|
||||
setData([...data, ...res]);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch(() => {
|
||||
|
@ -54,7 +54,13 @@ export default () => {
|
||||
loadingMessage={<Button onClick={() => loadMoreData(params)}>加载更多</Button>}
|
||||
itemRender={() => {
|
||||
return (
|
||||
<div style={{ width: '200px', height: '200px', border: '1px solid #000' }}>
|
||||
<div
|
||||
style={{
|
||||
width: '200px',
|
||||
height: '100px',
|
||||
border: '1px solid #000',
|
||||
boxSizing: 'border-box'
|
||||
}}>
|
||||
自定义的子元素
|
||||
</div>
|
||||
)
|
||||
|
@ -18,4 +18,21 @@ group:
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| data | 数据源 | Idata[] | [] | - |
|
||||
| loading | 数据源 | Array[] | [] | - |
|
||||
| data | 数据源 | Array[] | [] | - |
|
||||
| data | 数据源 | Array[] | [] | - |
|
||||
| data | 数据源 | Array[] | [] | - |
|
||||
| data | 数据源 | Array[] | [] | - |
|
||||
| data | 数据源 | Array[] | [] | - |
|
||||
|
||||
## Idata
|
||||
|
||||
```js
|
||||
interface Idata {
|
||||
id?: string | number;
|
||||
url?: string; // 链接
|
||||
title?: string; // 标题
|
||||
subtitle?: string; // 副标题
|
||||
}
|
||||
```
|
||||
|
@ -1,5 +1,5 @@
|
||||
import InfinityList from './InfiniteList'
|
||||
|
||||
// export { InfiniteListProps, InfiniteListRefProps } from './InfiniteList'
|
||||
export type { InfiniteListProps, InfiniteListRefProps } from './InfiniteList'
|
||||
|
||||
export default InfinityList
|
||||
|
@ -3,7 +3,6 @@ import { Button, Card, ConfigProvider, Flex, Input, InputProps, TransferProps, T
|
||||
import theme from 'antd/es/theme'
|
||||
import './index.less'
|
||||
import { DeleteOutlined, DoubleRightOutlined, SearchOutlined } from '@ant-design/icons';
|
||||
import { getAllRootKeyById } from './treeTransferHelper';
|
||||
|
||||
const componentName = 'zhst-biz-treeTransfer'
|
||||
|
||||
@ -15,7 +14,7 @@ export interface TreeTransferProps {
|
||||
checkedKeys: string[];
|
||||
onTreeSelect?: TreeProps['onSelect']
|
||||
onTreeCheck?: TreeProps['onCheck']
|
||||
onItemDelete?: (key: string, info?: { root: TreeDataNode[], keys: string[] }) => void
|
||||
onItemDelete?: (key: string, info?: TreeDataNode) => void
|
||||
onChange?: TransferProps['onChange'];
|
||||
onOk?: (data: any) => void;
|
||||
onReset?: () => void;
|
||||
@ -109,8 +108,8 @@ const TreeTransfer: React.FC<TreeTransferProps> = ({
|
||||
{item.title as any}
|
||||
<div style={{ float: 'right' }}>
|
||||
<DeleteOutlined onClick={() => {
|
||||
const { root, keys } = getAllRootKeyById(item.key as string, dataSource)
|
||||
onItemDelete?.(item.key as string, { root, keys })
|
||||
// const { root, keys } = getAllRootKeyById(item.key as string, dataSource)
|
||||
onItemDelete?.(item.key as string, item)
|
||||
}} />
|
||||
</div>
|
||||
</div>
|
||||
|
@ -24,30 +24,49 @@ export const boxDataSource: TreeDataNode[] = [
|
||||
{ key: '0-1-3-2', title: '分组0-1-3-2', isLeaf: true },
|
||||
{ key: '0-1-3-3', title: '分组0-1-3-3', isLeaf: true },
|
||||
],
|
||||
},{
|
||||
key: '0-1-3',
|
||||
title: '分组0-1-3',
|
||||
},
|
||||
{
|
||||
key: '0-1-4',
|
||||
title: '分组0-1-4',
|
||||
isLeaf: false,
|
||||
children: [
|
||||
{ key: '0-1-3-1', title: '分组0-1-3-1', isLeaf: true },
|
||||
{ key: '0-1-3-2', title: '分组0-1-3-2', isLeaf: true },
|
||||
{ key: '0-1-3-3', title: '分组0-1-3-3', isLeaf: true },
|
||||
{ key: '0-1-4-2', title: '分组0-1-3-2', isLeaf: true },
|
||||
{ key: '0-1-4-3', title: '分组0-1-3-3', isLeaf: true },
|
||||
],
|
||||
},{
|
||||
key: '0-1-3',
|
||||
title: '分组0-1-3',
|
||||
},
|
||||
{
|
||||
key: '0-1-5',
|
||||
title: '分组0-1-5',
|
||||
isLeaf: false,
|
||||
children: [
|
||||
{ key: '0-1-3-1', title: '分组0-1-3-1', isLeaf: true },
|
||||
{ key: '0-1-3-2', title: '分组0-1-3-2', isLeaf: true },
|
||||
{ key: '0-1-3-3', title: '分组0-1-3-3', isLeaf: true },
|
||||
{ key: '0-1-5-1', title: '分组0-1-3-1', isLeaf: true },
|
||||
{ key: '0-1-5-2', title: '分组0-1-3-2', isLeaf: true },
|
||||
{ key: '0-1-5-3', title: '分组0-1-3-3', isLeaf: true },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{ key: '0-2', title: '分组0-2', isLeaf: false, checkable: false, },
|
||||
{ key: '0-3', title: '分组0-3', isLeaf: false, checkable: false, },
|
||||
{ key: '0-4', title: '分组0-4', isLeaf: false, checkable: false, },
|
||||
{
|
||||
key: '0-4',
|
||||
title: '分组0-4',
|
||||
isLeaf: false,
|
||||
checkable: false,
|
||||
children: [
|
||||
{
|
||||
key: '0-4-5',
|
||||
title: '分组0-4-5',
|
||||
isLeaf: false,
|
||||
children: [
|
||||
{ key: '0-4-5-1', title: '分组0-1-3-1', isLeaf: true },
|
||||
{ key: '0-4-5-2', title: '分组0-1-3-2', isLeaf: true },
|
||||
{ key: '0-4-5-3', title: '分组0-1-3-3', isLeaf: true },
|
||||
],
|
||||
},
|
||||
]
|
||||
},
|
||||
{ key: '0-5', title: '分组0-4', isLeaf: false, checkable: false, },
|
||||
{ key: '0-6', title: '分组0-4', isLeaf: false, checkable: false, },
|
||||
];
|
||||
|
@ -1,6 +1,7 @@
|
||||
import React, { FC, useState } from 'react';
|
||||
import { Modal, ModalProps, Radio, RadioGroupProps, Select, SelectProps, TransferProps, TreeDataNode, TreeProps } from 'antd';
|
||||
import TreeTransfer from '../treeTransfer';
|
||||
import { TreeTransferProps } from '../treeTransfer'
|
||||
|
||||
export interface TreeTransferModalProps {
|
||||
dataSource: TreeDataNode[]
|
||||
@ -9,7 +10,7 @@ export interface TreeTransferModalProps {
|
||||
checkedKeys: string[];
|
||||
onTreeSelect?: TreeProps['onSelect']
|
||||
onTreeCheck?: TreeProps['onCheck']
|
||||
onItemDelete?: (key: string, info?: { root: TreeDataNode[], keys: string[] }) => void
|
||||
onItemDelete?: TreeTransferProps['onItemDelete']
|
||||
onChange?: TransferProps['onChange'];
|
||||
onOk?: (data: any) => void;
|
||||
onReset?: () => void;
|
||||
|
@ -2,11 +2,12 @@ import React, { useState } from 'react';
|
||||
import { TreeTransferModal } from '@zhst/biz';
|
||||
import { Button, TreeDataNode } from 'antd';
|
||||
import { TreeProps } from 'antd/lib';
|
||||
import { boxDataSource } from './mock'
|
||||
import { boxDataSource, boxGroupDataSource } from './mock'
|
||||
|
||||
const App: React.FC = () => {
|
||||
const [targetItems, setTargetItems] = useState<TreeDataNode[]>([]);
|
||||
const [checkedKeys, setCheckedKeys] = useState<string[]>([]);
|
||||
const [type, setType] = useState<string>('1');
|
||||
const [open, setOpen] = useState(true)
|
||||
|
||||
const onTreeCheck: TreeProps['onCheck'] = (keys: any, info) => {
|
||||
@ -47,14 +48,17 @@ const App: React.FC = () => {
|
||||
<TreeTransferModal
|
||||
open={open}
|
||||
onCancel={() => setOpen(false)}
|
||||
onRadioChange={(e) => console.log('radioChange', e)} // 顶部 radio 事件
|
||||
dataSource={boxDataSource} // 数据源
|
||||
onRadioChange={(e) => setType(e.target.value)} // 顶部 radio 事件
|
||||
dataSource={type === '1' ? boxDataSource : boxGroupDataSource} // 数据源
|
||||
targetItems={targetItems} // 右侧选中项
|
||||
checkedKeys={checkedKeys} // 左侧选中
|
||||
onReset={onReset} // 重置按钮事件
|
||||
onOk={onOk} // 确定按钮事件
|
||||
onTreeCheck={onTreeCheck} // 树check选中事件
|
||||
onItemDelete={onItemDelete} // 右侧点击删除事件
|
||||
radioProps={{
|
||||
value: type
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
@ -3,33 +3,74 @@ import { TreeDataNode } from "antd";
|
||||
export const boxDataSource: TreeDataNode[] = [
|
||||
{
|
||||
key: '0-0',
|
||||
title: '分组0-0',
|
||||
title: '全部盒子',
|
||||
value: 0,
|
||||
isLeaf: false,
|
||||
checkable: false,
|
||||
children: [
|
||||
{
|
||||
key: '0-1',
|
||||
title: '盒子组-1',
|
||||
value: 1,
|
||||
isLeaf: false,
|
||||
children: [
|
||||
{ key: '0-1-0', value: '10', title: '盒子1-0', isLeaf: true, },
|
||||
{ key: '0-1-1', value: '11', title: '盒子1-1', isLeaf: true, },
|
||||
{ key: '0-1-2', value: '12', title: '盒子1-2', isLeaf: true, },
|
||||
],
|
||||
},
|
||||
{ key: '0-2', value: '2', title: '盒子组-2', isLeaf: false, checkable: false, },
|
||||
{ key: '0-3', value: '3', title: '盒子组-3', isLeaf: false, checkable: false, },
|
||||
{
|
||||
key: '0-4',
|
||||
title: '盒子组-4',
|
||||
value: '4',
|
||||
isLeaf: false,
|
||||
children: [
|
||||
{ key: '0-4-10', value: '10', title: '盒子1-0', isLeaf: true, },
|
||||
{ key: '0-4-11', value: '11', title: '盒子1-1', isLeaf: true, },
|
||||
{ key: '0-4-12', value: '12', title: '盒子1-2', isLeaf: true, },
|
||||
],
|
||||
},
|
||||
{ key: '0-5', value: '5', title: '盒子组-4', isLeaf: false, checkable: false, },
|
||||
{ key: '0-6', value: '6', title: '盒子组-4', isLeaf: false, checkable: false, },
|
||||
]
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
|
||||
export const boxGroupDataSource: TreeDataNode[] = [
|
||||
{
|
||||
key: '0',
|
||||
title: '盒子组-0',
|
||||
value: '0',
|
||||
isLeaf: false,
|
||||
checkable: false,
|
||||
},
|
||||
{
|
||||
key: '0-1',
|
||||
title: '分组0-1',
|
||||
key: '1',
|
||||
value: '1',
|
||||
title: '盒子组-1',
|
||||
isLeaf: false,
|
||||
children: [
|
||||
{ key: '0-1-0', title: '分组0-1-0', isLeaf: true, checkable: false },
|
||||
{ key: '0-1-1', title: '分组0-1-1', isLeaf: true, checkable: false },
|
||||
{ key: '0-1-2', title: '分组0-1-2', isLeaf: true, checkable: false },
|
||||
{
|
||||
key: '0-1-3',
|
||||
title: '分组0-1-3',
|
||||
isLeaf: false,
|
||||
children: [
|
||||
{ key: '0-1-3-1', title: '分组0-1-3-1', isLeaf: true },
|
||||
{ key: '0-1-3-2', title: '分组0-1-3-2', isLeaf: true },
|
||||
{ key: '0-1-3-3', title: '分组0-1-3-3', isLeaf: true },
|
||||
],
|
||||
},
|
||||
{ key: '0-1-10', value: '10', title: '盒子1-0', isLeaf: true, },
|
||||
{ key: '0-1-11', value: '11', title: '盒子1-1', isLeaf: true, },
|
||||
{ key: '0-1-12', value: '12', title: '盒子1-2', isLeaf: true, },
|
||||
],
|
||||
},
|
||||
{ key: '0-2', title: '分组0-2', isLeaf: false, checkable: false, },
|
||||
{ key: '0-3', title: '分组0-3', isLeaf: false, checkable: false, },
|
||||
{ key: '0-4', title: '分组0-4', isLeaf: false, checkable: false, },
|
||||
{ key: '0-5', title: '分组0-4', isLeaf: false, checkable: false, },
|
||||
{ key: '0-6', title: '分组0-4', isLeaf: false, checkable: false, },
|
||||
{ key: '2', value: '2', title: '盒子组-2', isLeaf: false, checkable: false, },
|
||||
{
|
||||
key: '3',
|
||||
title: '盒子组-3',
|
||||
value: '3',
|
||||
isLeaf: false,
|
||||
children: [
|
||||
{ key: '3-10', value: '10', title: '盒子1-0', isLeaf: true, },
|
||||
{ key: '3-11', value: '11', title: '盒子1-1', isLeaf: true, },
|
||||
{ key: '3-12', value: '12', title: '盒子1-2', isLeaf: true, },
|
||||
],
|
||||
},
|
||||
{ key: '4', value: '4', title: '盒子组-4', isLeaf: false, checkable: false, },
|
||||
{ key: '5', value: '4', title: '盒子组-5', isLeaf: false, checkable: false, },
|
||||
];
|
||||
|
@ -1,5 +1,30 @@
|
||||
# @zhst/utils
|
||||
|
||||
## 0.11.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @zhst/request@0.12.2
|
||||
|
||||
## 0.11.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @zhst/request@0.12.1
|
||||
|
||||
## 0.11.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- zhst/biz:新增摘要列表-无限滚动组件
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @zhst/request@0.12.0
|
||||
|
||||
## 0.10.2
|
||||
|
||||
### Patch Changes
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/func",
|
||||
"version": "0.10.2",
|
||||
"version": "0.11.2",
|
||||
"description": "函数合集",
|
||||
"keywords": [
|
||||
"hooks"
|
||||
|
@ -1,5 +1,28 @@
|
||||
# @zhst/hooks
|
||||
|
||||
## 0.10.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @zhst/func@0.11.2
|
||||
|
||||
## 0.10.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @zhst/func@0.11.1
|
||||
|
||||
## 0.10.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- zhst/biz:新增摘要列表-无限滚动组件
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @zhst/func@0.11.0
|
||||
|
||||
## 0.9.2
|
||||
|
||||
### Patch Changes
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/hooks",
|
||||
"version": "0.9.2",
|
||||
"version": "0.10.2",
|
||||
"description": "hooks合集",
|
||||
"keywords": [
|
||||
"hooks"
|
||||
|
@ -1,5 +1,59 @@
|
||||
# @zhst/material
|
||||
|
||||
## 0.12.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @zhst/biz@0.18.5
|
||||
|
||||
## 0.12.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @zhst/biz@0.18.4
|
||||
|
||||
## 0.12.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @zhst/biz@0.18.3
|
||||
|
||||
## 0.12.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- zhst/request 修改报错提示逻辑、zhst/material - 删除算法配置路数
|
||||
- @zhst/func@0.11.2
|
||||
- @zhst/biz@0.18.2
|
||||
- @zhst/hooks@0.10.2
|
||||
- @zhst/meta@0.16.2
|
||||
|
||||
## 0.12.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @zhst/func@0.11.1
|
||||
- @zhst/biz@0.18.1
|
||||
- @zhst/hooks@0.10.1
|
||||
- @zhst/meta@0.16.1
|
||||
|
||||
## 0.12.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- zhst/biz:新增摘要列表-无限滚动组件
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @zhst/hooks@0.10.0
|
||||
- @zhst/func@0.11.0
|
||||
- @zhst/meta@0.16.0
|
||||
- @zhst/biz@0.18.0
|
||||
|
||||
## 0.11.0
|
||||
|
||||
### Minor Changes
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/material",
|
||||
"version": "0.11.0",
|
||||
"version": "0.12.5",
|
||||
"description": "物料库",
|
||||
"keywords": [
|
||||
"business",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { forwardRef } from 'react';
|
||||
import React, { forwardRef, useImperativeHandle } from 'react';
|
||||
import { Flex, Image } from "antd";
|
||||
import theme from 'antd/es/theme'
|
||||
import { CropperImage } from '@zhst/meta'
|
||||
@ -54,7 +54,7 @@ export interface AlgorithmConfigProps {
|
||||
export interface AlgorithmConfigRef {
|
||||
}
|
||||
|
||||
const AlgorithmConfig = forwardRef<AlgorithmConfigRef, AlgorithmConfigProps>((props) => {
|
||||
const AlgorithmConfig = forwardRef<AlgorithmConfigRef, AlgorithmConfigProps>((props, ref) => {
|
||||
const {
|
||||
algorithmTableDataSource = [],
|
||||
timeTemplateDataSource = [],
|
||||
@ -72,8 +72,8 @@ const AlgorithmConfig = forwardRef<AlgorithmConfigRef, AlgorithmConfigProps>((pr
|
||||
// @ts-ignore
|
||||
const { type: cropType } = cropperImageProps
|
||||
|
||||
// useImperativeHandle(ref, () => ({
|
||||
// }))
|
||||
useImperativeHandle(ref, () => ({
|
||||
}))
|
||||
|
||||
return (
|
||||
<Flex style={{ border: `1px solid ${token.colorBorder}`, backgroundColor: token.colorBgBase }}>
|
||||
|
@ -91,7 +91,7 @@ const AlgorithmTable= <DataSource extends AnyObject = AnyObject>(
|
||||
<ProTable<DataSource>
|
||||
columns={columns}
|
||||
bordered
|
||||
scroll={{ y: 240 }}
|
||||
scroll={{ y: 240, x: 600 }}
|
||||
dataSource={[]}
|
||||
headerTitle={(
|
||||
<Space size={16}>
|
||||
@ -101,7 +101,7 @@ const AlgorithmTable= <DataSource extends AnyObject = AnyObject>(
|
||||
onChange={onSortSelect}
|
||||
options={sortList}
|
||||
/>
|
||||
<PlusCircleFilled onClick={() => onAddAlgorithm?.()} style={{ fontSize: '24px', color: token.colorPrimary, cursor: 'pointer' }} />
|
||||
<PlusCircleFilled onClick={() => onAddAlgorithm?.(selectedKey)} style={{ fontSize: '24px', color: token.colorPrimary, cursor: 'pointer' }} />
|
||||
</Space>
|
||||
)}
|
||||
toolbar={undefined}
|
||||
|
@ -3,7 +3,7 @@ import type { ParamsType, ProColumns, ProTableProps } from '@ant-design/pro-comp
|
||||
import {
|
||||
ProTable,
|
||||
} from '@ant-design/pro-components';
|
||||
import { InputNumber } from 'antd';
|
||||
// import { InputNumber } from 'antd';
|
||||
import { AnyObject } from 'antd/es/_util/type';
|
||||
|
||||
export interface TimeTemplateTableProps<DataSource, Params extends ParamsType = ParamsType, ValueType = "text"> extends ProTableProps<DataSource, Params, ValueType> {
|
||||
@ -14,7 +14,7 @@ const TimeTemplateTable = <DataSource extends AnyObject = AnyObject>(
|
||||
props: TimeTemplateTableProps<DataSource, ParamsType, 'text'>
|
||||
) => {
|
||||
const {
|
||||
onItemBlur,
|
||||
// onItemBlur,
|
||||
} = props
|
||||
|
||||
|
||||
@ -35,12 +35,13 @@ const TimeTemplateTable = <DataSource extends AnyObject = AnyObject>(
|
||||
title: '算力占用',
|
||||
dataIndex: 'powerOccupy',
|
||||
},
|
||||
{
|
||||
title: '配置路数',
|
||||
key: 'option',
|
||||
valueType: 'option',
|
||||
render: (_, record) => <InputNumber value={record.lineNum} onBlur={e => onItemBlur?.(e.target.value, record.id, record)} min={0} />,
|
||||
},
|
||||
// !! 暂时不需要
|
||||
// {
|
||||
// title: '配置路数',
|
||||
// key: 'option',
|
||||
// valueType: 'option',
|
||||
// render: (_, record) => <InputNumber value={record.lineNum} onBlur={e => onItemBlur?.(e.target.value, record.id, record)} min={0} />,
|
||||
// },
|
||||
];
|
||||
|
||||
return (
|
||||
|
@ -1,5 +1,6 @@
|
||||
import React, { useState } from 'react';
|
||||
import { AlgorithmConfigModal } from '@zhst/material';
|
||||
import { Button } from 'antd';
|
||||
|
||||
const algorithmTableDataSource: any = []
|
||||
const timeTemplateDataSource: any = []
|
||||
@ -26,7 +27,7 @@ for (let i = 0; i < 5; i += 1) {
|
||||
}
|
||||
|
||||
const demo = () => {
|
||||
const [open, setOpen] = useState(true)
|
||||
const [open, setOpen] = useState(false)
|
||||
const [algorithmTableList, setAlgorithmTableList] = useState(algorithmTableDataSource)
|
||||
const [timeTemplateData, setTimeTemplateData] = useState(timeTemplateDataSource)
|
||||
const [boxList, setBoxList] = useState(boxListData)
|
||||
@ -34,7 +35,8 @@ const demo = () => {
|
||||
const [algorithmSelectedKey, setAlgorithmSelectedKey] = useState('1')
|
||||
|
||||
return (
|
||||
<div style={{ border: '1px solid #ccc', width: '340px', minHeight: '900px' }}>
|
||||
<div>
|
||||
<Button onClick={() => setOpen(true)}>打开</Button>
|
||||
<AlgorithmConfigModal
|
||||
title="批量算法设置"
|
||||
width={1500}
|
||||
|
@ -47,12 +47,12 @@ const Password: FC<PasswordProps> = (props) => {
|
||||
<Form.Item
|
||||
name="rePassword"
|
||||
label="确认密码"
|
||||
dependencies={['password']}
|
||||
dependencies={['newPassword']}
|
||||
rules={[
|
||||
{ required: true, message: '请再次输入密码!' },
|
||||
({ getFieldValue }) => ({
|
||||
validator(_, value) {
|
||||
if (!value || getFieldValue('password') === value) {
|
||||
if (!value || getFieldValue('newPassword') === value) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return Promise.reject(new Error('两次输入的密码不一致!'));
|
||||
|
@ -1,5 +1,34 @@
|
||||
# @zhst/utils
|
||||
|
||||
## 0.16.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @zhst/func@0.11.2
|
||||
- @zhst/hooks@0.10.2
|
||||
- @zhst/meta@0.16.2
|
||||
|
||||
## 0.16.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @zhst/func@0.11.1
|
||||
- @zhst/hooks@0.10.1
|
||||
- @zhst/meta@0.16.1
|
||||
|
||||
## 0.16.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- zhst/biz:新增摘要列表-无限滚动组件
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @zhst/hooks@0.10.0
|
||||
- @zhst/func@0.11.0
|
||||
- @zhst/meta@0.16.0
|
||||
|
||||
## 0.15.0
|
||||
|
||||
### Minor Changes
|
||||
|
@ -48,4 +48,5 @@ export { default as Tour } from "./tour";
|
||||
export { default as Segmented } from "./segmented";
|
||||
export { default as App } from "./app";
|
||||
export { default as notification } from "./notification";
|
||||
export { default as ButtonList } from "./ButtonList";
|
||||
export { default as ButtonList } from "./ButtonList";
|
||||
export * from "./utils";
|
@ -0,0 +1 @@
|
||||
export * from "./constants";
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/meta",
|
||||
"version": "0.15.0",
|
||||
"version": "0.16.2",
|
||||
"description": "原子组件",
|
||||
"keywords": [
|
||||
"meta",
|
||||
|
@ -1,5 +1,30 @@
|
||||
# @zhst/request
|
||||
|
||||
## 0.12.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- zhst/request 修改报错提示逻辑、zhst/material - 删除算法配置路数
|
||||
- @zhst/func@0.11.2
|
||||
|
||||
## 0.12.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- request 修改报错提示
|
||||
- @zhst/func@0.11.1
|
||||
|
||||
## 0.12.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- zhst/biz:新增摘要列表-无限滚动组件
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @zhst/func@0.11.0
|
||||
|
||||
## 0.11.0
|
||||
|
||||
### Minor Changes
|
||||
|
@ -8,15 +8,18 @@ import { message } from 'antd';
|
||||
export var reqConfig = function reqConfig(config) {
|
||||
var _ref = config || {},
|
||||
authorization = _ref.authorization,
|
||||
showMsg = _ref.showMsg,
|
||||
_ref$showMsg = _ref.showMsg,
|
||||
showMsg = _ref$showMsg === void 0 ? true : _ref$showMsg,
|
||||
onError = _ref.onError;
|
||||
return _objectSpread({
|
||||
timeout: 1000,
|
||||
baseURL: location.origin,
|
||||
errorConfig: {
|
||||
// @ts-ignore
|
||||
errorHandler: function errorHandler(error, opts) {
|
||||
if ([403, 401].includes(error.request.status)) {
|
||||
errorHandler: function errorHandler(error) {
|
||||
var _ref2 = (error === null || error === void 0 ? void 0 : error.request) || {},
|
||||
status = _ref2.status;
|
||||
if ([403, 401].includes(status)) {
|
||||
message.error('登录过期,请重新登录');
|
||||
onError === null || onError === void 0 || onError(error);
|
||||
return;
|
||||
@ -80,17 +83,23 @@ export var reqConfig = function reqConfig(config) {
|
||||
responseInterceptors: [
|
||||
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
||||
[function (response) {
|
||||
if (response.status !== 200) {
|
||||
throw Error(JSON.stringify(response.data));
|
||||
}
|
||||
var _ref2 = response.data || {},
|
||||
code = _ref2.code;
|
||||
// if (response.status !== 200) {
|
||||
// throw Error(JSON.stringify(response.data));
|
||||
// }
|
||||
var _ref3 = (response === null || response === void 0 ? void 0 : response.data) || {},
|
||||
code = _ref3.code;
|
||||
if (showMsg && code !== 200) {
|
||||
message.error(response.data.message || '请求失败!');
|
||||
return null;
|
||||
}
|
||||
return response.data;
|
||||
}, function (error) {
|
||||
var _error$response;
|
||||
var _ref4 = ((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data) || {},
|
||||
code = _ref4.code;
|
||||
if (showMsg && code !== 200) {
|
||||
message.error(error.response.data.message || '请求失败!');
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}]]
|
||||
}, config);
|
||||
|
@ -26,7 +26,7 @@ var import_antd = require("antd");
|
||||
var reqConfig = (config) => {
|
||||
const {
|
||||
authorization,
|
||||
showMsg,
|
||||
showMsg = true,
|
||||
onError
|
||||
} = config || {};
|
||||
return {
|
||||
@ -34,8 +34,9 @@ var reqConfig = (config) => {
|
||||
baseURL: location.origin,
|
||||
errorConfig: {
|
||||
// @ts-ignore
|
||||
errorHandler(error, opts) {
|
||||
if ([403, 401].includes(error.request.status)) {
|
||||
errorHandler(error) {
|
||||
const { status } = (error == null ? void 0 : error.request) || {};
|
||||
if ([403, 401].includes(status)) {
|
||||
import_antd.message.error("登录过期,请重新登录");
|
||||
onError == null ? void 0 : onError(error);
|
||||
return;
|
||||
@ -72,10 +73,7 @@ var reqConfig = (config) => {
|
||||
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
||||
[
|
||||
(response) => {
|
||||
if (response.status !== 200) {
|
||||
throw Error(JSON.stringify(response.data));
|
||||
}
|
||||
const { code } = response.data || {};
|
||||
const { code } = (response == null ? void 0 : response.data) || {};
|
||||
if (showMsg && code !== 200) {
|
||||
import_antd.message.error(response.data.message || "请求失败!");
|
||||
return null;
|
||||
@ -83,6 +81,11 @@ var reqConfig = (config) => {
|
||||
return response.data;
|
||||
},
|
||||
(error) => {
|
||||
var _a;
|
||||
const { code } = ((_a = error.response) == null ? void 0 : _a.data) || {};
|
||||
if (showMsg && code !== 200) {
|
||||
import_antd.message.error(error.response.data.message || "请求失败!");
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
]
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/request",
|
||||
"version": "0.11.0",
|
||||
"version": "0.12.2",
|
||||
"description": "请求库",
|
||||
"keywords": [
|
||||
"request",
|
||||
|
@ -15,7 +15,7 @@ export interface ReqConfigProps {
|
||||
export const reqConfig = (config: ReqConfigProps) => {
|
||||
const {
|
||||
authorization,
|
||||
showMsg,
|
||||
showMsg = true,
|
||||
onError,
|
||||
} = config || {}
|
||||
|
||||
@ -24,8 +24,9 @@ export const reqConfig = (config: ReqConfigProps) => {
|
||||
baseURL: location.origin,
|
||||
errorConfig: {
|
||||
// @ts-ignore
|
||||
errorHandler(error: any, opts: any) {
|
||||
if ([403,401].includes(error.request.status)) {
|
||||
errorHandler(error: any) {
|
||||
const { status } = error?.request || {}
|
||||
if ([403,401].includes(status)) {
|
||||
message.error('登录过期,请重新登录')
|
||||
onError?.(error)
|
||||
return
|
||||
@ -96,10 +97,10 @@ export const reqConfig = (config: ReqConfigProps) => {
|
||||
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
||||
[
|
||||
(response: { status: number; data: any; }) => {
|
||||
if (response.status !== 200) {
|
||||
throw Error(JSON.stringify(response.data));
|
||||
}
|
||||
const { code } = response.data || {}
|
||||
// if (response.status !== 200) {
|
||||
// throw Error(JSON.stringify(response.data));
|
||||
// }
|
||||
const { code } = response?.data || {}
|
||||
|
||||
if (showMsg && code !== 200) {
|
||||
message.error(response.data.message || '请求失败!')
|
||||
@ -108,6 +109,11 @@ export const reqConfig = (config: ReqConfigProps) => {
|
||||
return response.data;
|
||||
},
|
||||
(error: any) => {
|
||||
const { code } = error.response?.data || {}
|
||||
|
||||
if (showMsg && code !== 200) {
|
||||
message.error(error.response.data.message || '请求失败!')
|
||||
}
|
||||
return Promise.reject(error);
|
||||
},
|
||||
],
|
||||
|
@ -1,5 +1,28 @@
|
||||
# @zhst/slave
|
||||
|
||||
## 0.7.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @zhst/func@0.11.2
|
||||
|
||||
## 0.7.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @zhst/func@0.11.1
|
||||
|
||||
## 0.7.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- zhst/biz:新增摘要列表-无限滚动组件
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @zhst/func@0.11.0
|
||||
|
||||
## 0.6.2
|
||||
|
||||
### Patch Changes
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/slave",
|
||||
"version": "0.6.2",
|
||||
"version": "0.7.2",
|
||||
"description": "微前端子应用方法库",
|
||||
"keywords": [
|
||||
"slave",
|
||||
|
@ -23,6 +23,7 @@ title: 快速上手
|
||||
| msgText | 提示框自定义文案 | string | 请先登录 | - |
|
||||
| from | 来自哪个链接(可选) | string | localhost | - |
|
||||
| to | 准备去的链接(可选) | string | localhost | - |
|
||||
| force | 强制跳转 | boolean | false | - |
|
||||
|
||||
## slave 实例方法
|
||||
|
||||
|
@ -46,20 +46,16 @@ class Slave {
|
||||
let _token = currentUrl.searchParams.get(tokenKey || 'token') || this.getToken()
|
||||
this.setToken(_token)
|
||||
|
||||
let _fromUrl = from || (location.origin + location.pathname)
|
||||
this.checkUrl(_fromUrl, 'from')
|
||||
|
||||
// 判段from字段是否为链接
|
||||
if (!currentJumpUrl.searchParams.get('from')) {
|
||||
currentJumpUrl.searchParams.set('from', _fromUrl)
|
||||
}
|
||||
|
||||
let _toUrl = to || (location.origin + location.pathname)
|
||||
this.checkUrl(_toUrl, 'to')
|
||||
|
||||
if (!currentJumpUrl.searchParams.get('to')) {
|
||||
currentJumpUrl.searchParams.set('to', _toUrl)
|
||||
}
|
||||
this._setUrlKey({
|
||||
targetKey: 'from',
|
||||
targetUrl: from,
|
||||
jumpUrl: currentJumpUrl
|
||||
})
|
||||
this._setUrlKey({
|
||||
targetKey: 'to',
|
||||
targetUrl: to,
|
||||
jumpUrl: currentJumpUrl
|
||||
})
|
||||
|
||||
// 判断当前登录环境
|
||||
this.checkEnv({ showMsg, msgText })
|
||||
@ -76,6 +72,24 @@ class Slave {
|
||||
}
|
||||
}
|
||||
|
||||
// 设置 URL 中的值
|
||||
/**
|
||||
* @param opt targetUrl 目标链接,目标链接的 key 值,sourceUrl: 需要添加参数的链接
|
||||
*/
|
||||
_setUrlKey(opt: {targetUrl?: string, targetKey: string, jumpUrl: URL}) {
|
||||
const {
|
||||
targetUrl,
|
||||
targetKey,
|
||||
jumpUrl
|
||||
} = opt
|
||||
let _targetUrl = targetUrl || (location.origin + location.pathname)
|
||||
this.checkUrl(_targetUrl, targetKey)
|
||||
|
||||
if (!jumpUrl.searchParams.get(targetKey)) {
|
||||
jumpUrl.searchParams.set(targetKey, _targetUrl)
|
||||
}
|
||||
}
|
||||
|
||||
// 判端是否登录
|
||||
checkEnv(_opt: { showMsg: boolean, msgText?: string }): boolean {
|
||||
const _token = this.getToken() || String(this.getToken())
|
||||
@ -99,17 +113,17 @@ class Slave {
|
||||
location.replace(location.origin + location.pathname)
|
||||
}
|
||||
|
||||
public setToken(val: string | null) {
|
||||
val && localStorage.setItem(this.authTokenDefine, val)
|
||||
public setToken(val: string | null, tokenKey: string = this.authTokenDefine) {
|
||||
val && localStorage.setItem(tokenKey, val)
|
||||
}
|
||||
|
||||
public removeToken(cb?: () => void) {
|
||||
localStorage.removeItem(this.authTokenDefine)
|
||||
public removeToken(cb?: () => void, tokenKey: string = this.authTokenDefine) {
|
||||
localStorage.removeItem(tokenKey)
|
||||
cb?.()
|
||||
}
|
||||
|
||||
public getToken() {
|
||||
return localStorage.getItem(this.authTokenDefine)
|
||||
public getToken(tokenKey: string = this.authTokenDefine) {
|
||||
return localStorage.getItem(tokenKey)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user