Commit b9863fef authored by LeeJiancong's avatar LeeJiancong
parents 0332bf08 6226b7ff
import React, { useState, useEffect, useRef } from 'react' import React, { useState, useEffect, useRef } from 'react'
import { Select, Input } from 'antd'; import { Select, Input, Row, Button } from 'antd';
import { useDebounceFn } from '@umijs/hooks'; import { useDebounceFn } from '@umijs/hooks';
import { ISchemaFieldComponentProps, FormPath, useFormEffects, createFormActions, createAsyncFormActions } from '@formily/antd' import { ISchemaFieldComponentProps, FormPath, useFormEffects, createFormActions, createAsyncFormActions } from '@formily/antd'
import pinyin from 'pinyin' import pinyin from 'pinyin'
const SelectContent = (props) => { const SelectContent = (props) => {
const { handleChange } = props const { handleChange, multiple, confirm, resetField } = props
return <div>
return <div onBlur={confirm}>
<div style={{padding: '12px'}}> <div style={{padding: '12px'}}>
<Input.Search <Input.Search
onChange={handleChange} onChange={handleChange}
/> />
</div> </div>
{props.children} {props.children}
{
multiple &&
<Row justify='end' style={{borderTop: '1px solid #eee'}}>
<Button type='link' onClick={resetField}>重置</Button>
<Button type='link' onClick={confirm}>确定</Button>
</Row>
}
</div> </div>
} }
// 自定义搜索型下拉框 // 自定义搜索型下拉框
const SearchSelect = (props: ISchemaFieldComponentProps) => { const SearchSelect = (props: ISchemaFieldComponentProps) => {
const ref = useRef<any>({})
const { schema, form, path, mutators } = props const { schema, form, path, mutators } = props
const dataSourceRef = useRef<any[]>([]) const dataSourceRef = useRef<any[]>([])
const pinyinRef = useRef<any[]>([]) const pinyinRef = useRef<any[]>([])
// 可选参数 fetchSearch, select为search // 可选参数 fetchSearch, select为search
const { fetchSearch, fetchParams = 'name', fetchFormat, ...resetProps } = schema.getExtendsComponentProps() // multiple 是否开启多选
const { fetchSearch, fetchParams = 'name', fetchFormat, multiple = false, ...resetProps } = schema.getExtendsComponentProps()
const [dataSource, setDataSource] = useState<any[]>([]) const [dataSource, setDataSource] = useState<any[]>([])
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const [openSelect, setOpenSelect] = useState(false)
const fuzzyQuery = (keyword) => { const fuzzyQuery = (keyword) => {
const pinyinArr = pinyinRef.current const pinyinArr = pinyinRef.current
...@@ -42,6 +52,15 @@ const SearchSelect = (props: ISchemaFieldComponentProps) => { ...@@ -42,6 +52,15 @@ const SearchSelect = (props: ISchemaFieldComponentProps) => {
return result return result
} }
const resetField = () => {
form.setFieldValue(path, multiple ? [] : '')
}
const confirm = (e) => {
e.preventDefault()
setOpenSelect(false)
}
useEffect(() => { useEffect(() => {
setLoading(true) setLoading(true)
fetchSearch({ fetchSearch({
...@@ -97,15 +116,18 @@ const SearchSelect = (props: ISchemaFieldComponentProps) => { ...@@ -97,15 +116,18 @@ const SearchSelect = (props: ISchemaFieldComponentProps) => {
// } // }
// const { run } = useDebounceFn(dispatchSearch, 500) // const { run } = useDebounceFn(dispatchSearch, 500)
return ( return (
<Select <Select
ref={ref}
mode={multiple ? 'multiple' : null}
onChange={e => mutators.change(e)} onChange={e => mutators.change(e)}
filterOption={false} filterOption={false}
loading={loading} loading={loading}
options={dataSource} options={dataSource}
onFocus={() => setOpenSelect(true)}
value={props.value} value={props.value}
dropdownRender={originNode => <SelectContent handleChange={handleChange}>{originNode}</SelectContent>} open={multiple ? openSelect : null}
dropdownRender={originNode => <SelectContent confirm={confirm} resetField={resetField} parentRef={ref} handleChange={handleChange} multiple={multiple} value={props.value}>{originNode}</SelectContent>}
{...resetProps} {...resetProps}
> >
</Select> </Select>
......
...@@ -23,4 +23,27 @@ ...@@ -23,4 +23,27 @@
box-shadow: none; box-shadow: none;
border-bottom: 1px solid #DFE1E6; border-bottom: 1px solid #DFE1E6;
} }
}
.flex-layout-label-required {
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
height: 32px;
color: rgba(0, 0, 0, 0.85);
font-size: 14px;
&::before {
display: inline-block;
margin-right: 4px;
color: #ff4d4f;
font-size: 14px;
font-family: SimSun, sans-serif;
line-height: 1;
content: '*';
}
} }
\ No newline at end of file
...@@ -24,6 +24,7 @@ import CustomRadio from './components/CustomRadio'; ...@@ -24,6 +24,7 @@ import CustomRadio from './components/CustomRadio';
import SearchSelect from './components/SearchSelect'; import SearchSelect from './components/SearchSelect';
import './index.less' import './index.less'
import { Checkbox } from '@formily/antd-components'; import { Checkbox } from '@formily/antd-components';
import cx from 'classnames'
export interface NiceFormProps extends IAntdSchemaFormProps {} export interface NiceFormProps extends IAntdSchemaFormProps {}
...@@ -36,6 +37,30 @@ const RowLayout = styled(props => <Row justify='end' {...props}/>)` ...@@ -36,6 +37,30 @@ const RowLayout = styled(props => <Row justify='end' {...props}/>)`
} }
` `
const renderCol = (schema, isLast) => {
const { flexcol = {} } = schema['x-component-props']
return <Col style={isLast ? {} : {marginRight: 24}} {...flexcol} key={schema.path}>
<SchemaField schema={schema.toJSON()} path={schema.path}/>
</Col>
}
// 自定义flex布局容器
registerVirtualBox('flex-box', props => {
const childProperties = props.schema.getOrderProperties()
const { title, required } = props.props
const {labelcol, wrappercol} = props.schema.getExtendsComponentProps()
return <Row>
{ title && <Col span={labelcol} className={cx(required ? 'flex-layout-label-required' : '')}>{title}</Col>}
<Col span={wrappercol}>
<Row>
{
childProperties.map((v, i, arr) => renderCol(v.schema, arr.length - 1 === i))
}
</Row>
</Col>
</Row>
})
registerVirtualBox('flex-layout', (_props) => { registerVirtualBox('flex-layout', (_props) => {
const { children, props } = _props const { children, props } = _props
const rowStyle = props['x-component-props'] ? props['x-component-props'].rowStyle : {} const rowStyle = props['x-component-props'] ? props['x-component-props'].rowStyle : {}
......
export interface MemberType {
id: number;
typeName: string;
}
export interface BusinessType {
id: number;
typeName: string;
}
export interface UseType {
memberType: MemberType[];
businessType: BusinessType[];
}
export interface UserRegister {
useType: UseType;
}
export interface Web {
shopInfo: any[];
}
export interface PayConfig {
paymemberConfig?: any;
}
export interface CountryList {
name: string;
key: string;
icon: string;
}
export interface Global {
siteId: number;
siteUrl: string;
logo: string;
countryList: CountryList[];
}
export interface RootObject {
userRegister: UserRegister;
web: Web;
payConfig: PayConfig;
global: Global;
}
\ No newline at end of file
...@@ -77,7 +77,7 @@ export const repositSchema: ISchema = { ...@@ -77,7 +77,7 @@ export const repositSchema: ISchema = {
fetchSearch: PublicApi.getProductSelectGetSelectCategory, fetchSearch: PublicApi.getProductSelectGetSelectCategory,
placeholder: '请选择品类', placeholder: '请选择品类',
style: { style: {
minWidth: 160 width: 160,
} }
}, },
enum: [] enum: []
...@@ -89,7 +89,7 @@ export const repositSchema: ISchema = { ...@@ -89,7 +89,7 @@ export const repositSchema: ISchema = {
fetchSearch: PublicApi.getProductSelectGetSelectBrand, fetchSearch: PublicApi.getProductSelectGetSelectBrand,
placeholder: '请选择品牌', placeholder: '请选择品牌',
style: { style: {
minWidth: 160 width: 160
} }
}, },
enum: [] enum: []
......
...@@ -70,10 +70,12 @@ const baseRequest = extend({ ...@@ -70,10 +70,12 @@ const baseRequest = extend({
// 请求拦截器 // 请求拦截器
baseRequest.interceptors.request.use((url: string, options: RequestOptionsInit): { url: string, options: RequestOptionsInit } => { baseRequest.interceptors.request.use((url: string, options: RequestOptionsInit): { url: string, options: RequestOptionsInit } => {
// 判断是否有权限 // 判断是否有权限
const loginAfterHeaders = getAuth() const { userId, memberId, token } = getAuth() || {}
const headers = { const headers = {
...options.headers, ...options.headers,
...loginAfterHeaders userId,
memberId,
token
} }
return { return {
// 前缀如果已经带上api, 跳过自动补前缀 // 前缀如果已经带上api, 跳过自动补前缀
......
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