Merge remote-tracking branch 'baidu/master'

This commit is contained in:
2betop 2021-08-30 11:50:35 +08:00
commit 8a68509de6
9 changed files with 55 additions and 38 deletions

View File

@ -10,7 +10,7 @@ import hoistNonReactStatic from 'hoist-non-react-statics';
import qs from 'qs'; import qs from 'qs';
import {dataMapping} from './utils/tpl-builtin'; import {dataMapping} from './utils/tpl-builtin';
import {RendererEnv, RendererProps} from './factory'; import {RendererEnv, RendererProps} from './factory';
import {noop, autobind, qsstringify} from './utils/helper'; import {noop, autobind, qsstringify, qsparse} from './utils/helper';
import {RendererData, Action} from './types'; import {RendererData, Action} from './types';
export interface ScopedComponentType extends React.Component<RendererProps> { export interface ScopedComponentType extends React.Component<RendererProps> {
@ -112,7 +112,7 @@ function createScopedTools(
let query = null; let query = null;
if (~idx2) { if (~idx2) {
const queryObj = qs.parse( const queryObj = qsparse(
name name
.substring(idx2 + 1) .substring(idx2 + 1)
.replace( .replace(
@ -158,7 +158,7 @@ function createScopedTools(
const askIdx = name.indexOf('?'); const askIdx = name.indexOf('?');
if (~askIdx) { if (~askIdx) {
const query = name.substring(askIdx + 1); const query = name.substring(askIdx + 1);
const queryObj = qs.parse( const queryObj = qsparse(
query.replace( query.replace(
/\$\{(.*?)\}/, /\$\{(.*?)\}/,
(_, match) => '${' + encodeURIComponent(match) + '}' (_, match) => '${' + encodeURIComponent(match) + '}'
@ -183,7 +183,7 @@ function createScopedTools(
component.receive(values, subPath); component.receive(values, subPath);
} else if (name === 'window' && env && env.updateLocation) { } else if (name === 'window' && env && env.updateLocation) {
const query = { const query = {
...(location.search ? qs.parse(location.search.substring(1)) : {}), ...(location.search ? qsparse(location.search.substring(1)) : {}),
...values ...values
}; };
const link = location.pathname + '?' + qsstringify(query); const link = location.pathname + '?' + qsstringify(query);

View File

@ -151,11 +151,16 @@ export class CustomDaysView extends DaysView {
const hours = this.computedTimeOptions(24); const hours = this.computedTimeOptions(24);
const times = this.computedTimeOptions(60); const times = this.computedTimeOptions(60);
const options = type === 'hours' ? hours : times; const options = type === 'hours' ? hours : times;
const formatMap = {
hours: 'HH',
minutes: 'mm',
seconds: 'ss'
};
inputs.push( inputs.push(
<Downshift <Downshift
key={i + 'input'} key={i + 'input'}
inputValue={date.format(format)} inputValue={date.format(formatMap[type])}
> >
{({isOpen, getInputProps, openMenu, closeMenu}) => { {({isOpen, getInputProps, openMenu, closeMenu}) => {
const inputProps = getInputProps({ const inputProps = getInputProps({
@ -175,7 +180,7 @@ export class CustomDaysView extends DaysView {
<div className={cx('CalendarInputWrapper')}> <div className={cx('CalendarInputWrapper')}>
<input <input
type="text" type="text"
value={date.format(format)} value={date.format(formatMap[type])}
className={cx('CalendarInput')} className={cx('CalendarInput')}
min={min} min={min}
max={max} max={max}
@ -189,7 +194,7 @@ export class CustomDaysView extends DaysView {
<div <div
key={option.value} key={option.value}
className={cx('CalendarInput-sugsItem', { className={cx('CalendarInput-sugsItem', {
'is-highlight': option.value === date.format(format) 'is-highlight': option.value === date.format(formatMap[type])
})} })}
onClick={() => { onClick={() => {
this.setTime( this.setTime(

View File

@ -4,7 +4,7 @@ import {RendererStore, IRendererStore, IIRendererStore} from './store/index';
import {getEnv, destroy} from 'mobx-state-tree'; import {getEnv, destroy} from 'mobx-state-tree';
import {wrapFetcher} from './utils/api'; import {wrapFetcher} from './utils/api';
import {normalizeLink} from './utils/normalizeLink'; import {normalizeLink} from './utils/normalizeLink';
import {findIndex, promisify, string2regExp} from './utils/helper'; import {findIndex, promisify, qsparse, string2regExp} from './utils/helper';
import {Api, fetcherResult, Payload, SchemaNode, Schema, Action} from './types'; import {Api, fetcherResult, Payload, SchemaNode, Schema, Action} from './types';
import {observer} from 'mobx-react'; import {observer} from 'mobx-react';
import Scoped from './Scoped'; import Scoped from './Scoped';
@ -302,8 +302,8 @@ const defaultOptions: RenderOptions = {
if (pathname !== location.pathname || !location.search) { if (pathname !== location.pathname || !location.search) {
return false; return false;
} }
const query = qs.parse(search.substring(1)); const query = qsparse(search.substring(1));
const currentQuery = qs.parse(location.search.substring(1)); const currentQuery = qsparse(location.search.substring(1));
return Object.keys(query).every(key => query[key] === currentQuery[key]); return Object.keys(query).every(key => query[key] === currentQuery[key]);
} else if (pathname === location.pathname) { } else if (pathname === location.pathname) {
return true; return true;

View File

@ -19,7 +19,8 @@ import {
noop, noop,
isVisible, isVisible,
getVariable, getVariable,
qsstringify qsstringify,
qsparse
} from '../utils/helper'; } from '../utils/helper';
import {observer} from 'mobx-react'; import {observer} from 'mobx-react';
import partition from 'lodash/partition'; import partition from 'lodash/partition';
@ -435,14 +436,14 @@ export default class CRUD extends React.Component<CRUDProps, any> {
if (syncLocation && location && (location.query || location.search)) { if (syncLocation && location && (location.query || location.search)) {
store.updateQuery( store.updateQuery(
qs.parse(location.search.substring(1)), qsparse(location.search.substring(1)),
undefined, undefined,
pageField, pageField,
perPageField perPageField
); );
} else if (syncLocation && !location && window.location.search) { } else if (syncLocation && !location && window.location.search) {
store.updateQuery( store.updateQuery(
qs.parse(window.location.search.substring(1)) as object, qsparse(window.location.search.substring(1)) as object,
undefined, undefined,
pageField, pageField,
perPageField perPageField
@ -517,7 +518,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
) { ) {
// 同步地址栏,那么直接检测 query 是否变了,变了就重新拉数据 // 同步地址栏,那么直接检测 query 是否变了,变了就重新拉数据
store.updateQuery( store.updateQuery(
qs.parse(props.location.search.substring(1)), qsparse(props.location.search.substring(1)),
undefined, undefined,
props.pageField, props.pageField,
props.perPageField props.perPageField
@ -804,18 +805,11 @@ export default class CRUD extends React.Component<CRUDProps, any> {
perPageField, perPageField,
loadDataOnceFetchOnFilter loadDataOnceFetchOnFilter
} = this.props; } = this.props;
values = syncLocation values = syncLocation
? qs.parse( ? qsparse(qsstringify(values, undefined, true))
qsstringify(
values,
{
arrayFormat: 'indices',
encodeValuesOnly: true
},
true
)
)
: values; : values;
store.updateQuery( store.updateQuery(
{ {
...values, ...values,

View File

@ -9,7 +9,13 @@ import find from 'lodash/find';
import qs from 'qs'; import qs from 'qs';
import {Payload} from '../../types'; import {Payload} from '../../types';
import {buildApi} from '../../utils/api'; import {buildApi} from '../../utils/api';
import {createObject, qsstringify, guid, isEmpty} from '../../utils/helper'; import {
createObject,
qsstringify,
guid,
isEmpty,
qsparse
} from '../../utils/helper';
import {Icon} from '../../components/icons'; import {Icon} from '../../components/icons';
import Button from '../../components/Button'; import Button from '../../components/Button';
import accepts from 'attr-accept'; import accepts from 'attr-accept';
@ -1037,7 +1043,7 @@ export default class ImageControl extends React.Component<
if (~idx && params) { if (~idx && params) {
params = { params = {
...qs.parse(api.url.substring(idx + 1)), ...qsparse(api.url.substring(idx + 1)),
...params ...params
}; };
api.url = api.url.substring(0, idx) + '?' + qsstringify(params); api.url = api.url.substring(0, idx) + '?' + qsstringify(params);
@ -1213,8 +1219,7 @@ export default class ImageControl extends React.Component<
<Cropper {...crop} ref={this.cropper} src={cropFile.preview} /> <Cropper {...crop} ref={this.cropper} src={cropFile.preview} />
</Suspense> </Suspense>
<div className={cx('ImageControl-croperToolbar')}> <div className={cx('ImageControl-croperToolbar')}>
{ {crop.rotatable && (
crop.rotatable &&
<a <a
className={cx('ImageControl-cropRotatable')} className={cx('ImageControl-cropRotatable')}
onClick={this.rotatableCrop} onClick={this.rotatableCrop}
@ -1223,7 +1228,7 @@ export default class ImageControl extends React.Component<
> >
<Icon icon="retry" className="icon" /> <Icon icon="retry" className="icon" />
</a> </a>
} )}
<a <a
className={cx('ImageControl-cropCancel')} className={cx('ImageControl-cropCancel')}
onClick={this.cancelCrop} onClick={this.cancelCrop}

View File

@ -18,7 +18,8 @@ import {
SkipOperation, SkipOperation,
isEmpty, isEmpty,
getVariable, getVariable,
isObjectShallowModified isObjectShallowModified,
qsparse
} from '../../utils/helper'; } from '../../utils/helper';
import debouce from 'lodash/debounce'; import debouce from 'lodash/debounce';
import flatten from 'lodash/flatten'; import flatten from 'lodash/flatten';
@ -1701,7 +1702,7 @@ export class FormRenderer extends Form {
const idx2 = target ? target.indexOf('?') : -1; const idx2 = target ? target.indexOf('?') : -1;
if (~idx2) { if (~idx2) {
subQuery = dataMapping( subQuery = dataMapping(
qs.parse((target as string).substring(idx2 + 1)), qsparse((target as string).substring(idx2 + 1)),
ctx ctx
); );
target = (target as string).substring(0, idx2); target = (target as string).substring(0, idx2);

View File

@ -1,6 +1,6 @@
import {Instance, types} from 'mobx-state-tree'; import {Instance, types} from 'mobx-state-tree';
import qs from 'qs'; import qs from 'qs';
import {createObject} from '../utils/helper'; import {createObject, qsparse} from '../utils/helper';
import {ServiceStore} from './service'; import {ServiceStore} from './service';
export const RootStore = ServiceStore.named('RootStore') export const RootStore = ServiceStore.named('RootStore')
@ -33,9 +33,9 @@ export const RootStore = ServiceStore.named('RootStore')
(location && location.query) || (location && location.query) ||
(location && (location &&
location.search && location.search &&
qs.parse(location.search.substring(1))) || qsparse(location.search.substring(1))) ||
(window.location.search && (window.location.search &&
qs.parse(window.location.search.substring(1))); qsparse(window.location.search.substring(1)));
self.query = query; self.query = query;
} }

View File

@ -10,7 +10,8 @@ import {
object2formData, object2formData,
qsstringify, qsstringify,
cloneObject, cloneObject,
createObject createObject,
qsparse
} from './helper'; } from './helper';
const rSchema = /(?:^|raw\:)(get|post|put|delete|patch|options|head):/i; const rSchema = /(?:^|raw\:)(get|post|put|delete|patch|options|head):/i;
@ -75,7 +76,7 @@ export function buildApi(
if (~idx) { if (~idx) {
const hashIdx = api.url.indexOf('#'); const hashIdx = api.url.indexOf('#');
const params = qs.parse( const params = qsparse(
api.url.substring(idx + 1, ~hashIdx ? hashIdx : undefined) api.url.substring(idx + 1, ~hashIdx ? hashIdx : undefined)
); );
api.url = api.url =
@ -109,7 +110,7 @@ export function buildApi(
const idx = api.url.indexOf('?'); const idx = api.url.indexOf('?');
if (~idx) { if (~idx) {
let params = (api.query = { let params = (api.query = {
...qs.parse(api.url.substring(idx + 1)), ...qsparse(api.url.substring(idx + 1)),
...data ...data
}); });
api.url = api.url.substring(0, idx) + '?' + qsstringify(params); api.url = api.url.substring(0, idx) + '?' + qsstringify(params);
@ -123,7 +124,7 @@ export function buildApi(
const idx = api.url.indexOf('?'); const idx = api.url.indexOf('?');
if (~idx) { if (~idx) {
let params = (api.query = { let params = (api.query = {
...qs.parse(api.url.substring(idx + 1)), ...qsparse(api.url.substring(idx + 1)),
...api.data ...api.data
}); });
api.url = api.url.substring(0, idx) + '?' + qsstringify(params); api.url = api.url.substring(0, idx) + '?' + qsstringify(params);

View File

@ -1319,6 +1319,17 @@ export function qsstringify(
return qs.stringify(data, options); return qs.stringify(data, options);
} }
export function qsparse(
data: string,
options: any = {
arrayFormat: 'indices',
encodeValuesOnly: true,
depth: 1000 // 默认是 5 所以condition-builder只要来个条件组就会导致报错
}
) {
return qs.parse(data, options);
}
export function object2formData( export function object2formData(
data: any, data: any,
options: any = { options: any = {