mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 19:17:54 +08:00
统一 qs.stringify 因为可能会统一更新参数
This commit is contained in:
parent
d6cd751021
commit
f79ef10e49
@ -10,7 +10,7 @@ import hoistNonReactStatic = require('hoist-non-react-statics');
|
||||
import qs from 'qs';
|
||||
import {dataMapping} from './utils/tpl-builtin';
|
||||
import {RendererEnv, RendererProps} from './factory';
|
||||
import {noop, autobind} from './utils/helper';
|
||||
import {noop, autobind, qsstringify} from './utils/helper';
|
||||
import {RendererData, Action} from './types';
|
||||
|
||||
interface ScopedComponentType extends React.Component<RendererProps> {
|
||||
@ -139,7 +139,7 @@ function createScopedTools(path?: string, parent?: AlisIScopedContext, env?: Ren
|
||||
...(location.search ? qs.parse(location.search.substring(1)) : {}),
|
||||
...values
|
||||
};
|
||||
const link = location.pathname + '?' + qs.stringify(query);
|
||||
const link = location.pathname + '?' + qsstringify(query);
|
||||
env.updateLocation(link);
|
||||
}
|
||||
});
|
||||
|
@ -10,7 +10,8 @@ import {
|
||||
isObjectShallowModified,
|
||||
noop,
|
||||
isVisible,
|
||||
getVariable
|
||||
getVariable,
|
||||
qsstringify
|
||||
} from '../utils/helper';
|
||||
import {observer} from 'mobx-react';
|
||||
import partition = require('lodash/partition');
|
||||
@ -167,12 +168,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
this.mounted = true;
|
||||
|
||||
if (syncLocation && location && (location.query || location.search)) {
|
||||
store.updateQuery(
|
||||
qs.parse(location.search.substring(1)),
|
||||
undefined,
|
||||
pageField,
|
||||
perPageField
|
||||
);
|
||||
store.updateQuery(qs.parse(location.search.substring(1)), undefined, pageField, perPageField);
|
||||
} else if (syncLocation && !location && window.location.search) {
|
||||
store.updateQuery(
|
||||
qs.parse(window.location.search.substring(1)) as object,
|
||||
@ -413,7 +409,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
search: boolean = true
|
||||
) {
|
||||
const {store, syncLocation, env, pageField, perPageField} = this.props;
|
||||
values = syncLocation ? qs.parse(qs.stringify(values)) : values;
|
||||
values = syncLocation ? qs.parse(qsstringify(values)) : values;
|
||||
|
||||
store.updateQuery(
|
||||
{
|
||||
@ -579,33 +575,33 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
const data = createObject(store.data, store.query);
|
||||
isEffectiveApi(api, data)
|
||||
? store
|
||||
.fetchInitData(api, data, {
|
||||
successMessage: messages && messages.fetchSuccess,
|
||||
errorMessage: messages && messages.fetchFailed,
|
||||
autoAppend: true,
|
||||
forceReload,
|
||||
loadDataOnce,
|
||||
source,
|
||||
silent,
|
||||
pageField,
|
||||
perPageField,
|
||||
loadDataMode,
|
||||
syncResponse2Query
|
||||
})
|
||||
.then(value => {
|
||||
interval &&
|
||||
this.mounted &&
|
||||
(!stopAutoRefreshWhen ||
|
||||
!(
|
||||
(stopAutoRefreshWhenModalIsOpen && store.hasModalOpened) ||
|
||||
evalExpression(stopAutoRefreshWhen, data)
|
||||
)) &&
|
||||
(this.timer = setTimeout(
|
||||
silentPolling ? this.silentSearch : this.search,
|
||||
Math.max(interval, 3000)
|
||||
));
|
||||
return value;
|
||||
})
|
||||
.fetchInitData(api, data, {
|
||||
successMessage: messages && messages.fetchSuccess,
|
||||
errorMessage: messages && messages.fetchFailed,
|
||||
autoAppend: true,
|
||||
forceReload,
|
||||
loadDataOnce,
|
||||
source,
|
||||
silent,
|
||||
pageField,
|
||||
perPageField,
|
||||
loadDataMode,
|
||||
syncResponse2Query
|
||||
})
|
||||
.then(value => {
|
||||
interval &&
|
||||
this.mounted &&
|
||||
(!stopAutoRefreshWhen ||
|
||||
!(
|
||||
(stopAutoRefreshWhenModalIsOpen && store.hasModalOpened) ||
|
||||
evalExpression(stopAutoRefreshWhen, data)
|
||||
)) &&
|
||||
(this.timer = setTimeout(
|
||||
silentPolling ? this.silentSearch : this.search,
|
||||
Math.max(interval, 3000)
|
||||
));
|
||||
return value;
|
||||
})
|
||||
: source && store.initFromScope(data, source);
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import ImageControl from './Image';
|
||||
import {Payload} from '../../types';
|
||||
import {filter} from '../../utils/tpl';
|
||||
import Alert from '../../components/Alert2';
|
||||
import {qsstringify} from '../../utils/helper';
|
||||
|
||||
export interface FileProps extends FormControlProps {
|
||||
btnClassName: string;
|
||||
@ -493,9 +494,9 @@ export default class FileControl extends React.Component<FileProps, FileState> {
|
||||
...qs.parse(reciever.substring(idx + 1)),
|
||||
...params
|
||||
};
|
||||
reciever = reciever.substring(0, idx) + '?' + qs.stringify(params);
|
||||
reciever = reciever.substring(0, idx) + '?' + qsstringify(params);
|
||||
} else if (params) {
|
||||
reciever += '?' + qs.stringify(params);
|
||||
reciever += '?' + qsstringify(params);
|
||||
}
|
||||
|
||||
return this._send(reciever, fd, {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {types, getParent, flow, getEnv, getRoot} from 'mobx-state-tree';
|
||||
import {IRendererStore} from './index';
|
||||
import {ServiceStore} from './service';
|
||||
import {extendObject, createObject, isObjectShallowModified, sortArray, isEmpty} from '../utils/helper';
|
||||
import {extendObject, createObject, isObjectShallowModified, sortArray, isEmpty, qsstringify} from '../utils/helper';
|
||||
import {Api, Payload, fetchOptions, Action} from '../types';
|
||||
import qs from 'qs';
|
||||
import pick = require('lodash/pick');
|
||||
@ -91,7 +91,7 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
|
||||
|
||||
updater &&
|
||||
isObjectShallowModified(originQuery, self.query, false) &&
|
||||
setTimeout(() => updater(`?${qs.stringify(self.query, {encodeValuesOnly: true})}`), 4);
|
||||
setTimeout(() => updater(`?${qsstringify(self.query)}`), 4);
|
||||
}
|
||||
|
||||
const fetchInitData: (
|
||||
|
@ -3,7 +3,7 @@ import {fetcherConfig} from '../factory';
|
||||
import {tokenize, dataMapping} from './tpl-builtin';
|
||||
import qs from 'qs';
|
||||
import {evalExpression} from './tpl';
|
||||
import {isObject, isObjectShallowModified, hasFile, object2formData} from './helper';
|
||||
import {isObject, isObjectShallowModified, hasFile, object2formData, qsstringify} from './helper';
|
||||
|
||||
const rSchema = /(?:^|raw\:)(get|post|put|delete|patch|options|head):/i;
|
||||
|
||||
@ -81,9 +81,9 @@ export function buildApi(
|
||||
...qs.parse(api.url.substring(idx + 1)),
|
||||
...api.data
|
||||
};
|
||||
api.url = api.url.substring(0, idx) + '?' + qs.stringify(params);
|
||||
api.url = api.url.substring(0, idx) + '?' + qsstringify(params);
|
||||
} else {
|
||||
api.url += '?' + qs.stringify(api.data);
|
||||
api.url += '?' + qsstringify(api.data);
|
||||
}
|
||||
delete api.data;
|
||||
}
|
||||
|
@ -777,14 +777,25 @@ export function hasFile(object: any): boolean {
|
||||
});
|
||||
}
|
||||
|
||||
export function qsstringify(
|
||||
data: any,
|
||||
options: any = {
|
||||
arrayFormat: 'brackets',
|
||||
encodeValuesOnly: true
|
||||
}
|
||||
) {
|
||||
return qs.stringify(data, options);
|
||||
}
|
||||
|
||||
export function object2formData(
|
||||
data: any,
|
||||
options: any = {
|
||||
arrayForamt: 'brackets'
|
||||
}
|
||||
arrayFormat: 'brackets',
|
||||
encodeValuesOnly: true
|
||||
},
|
||||
fd: FormData = new FormData()
|
||||
): any {
|
||||
let others: any = {};
|
||||
const fd = new FormData();
|
||||
Object.keys(data).forEach(key => {
|
||||
const value = data[key];
|
||||
|
||||
@ -798,7 +809,7 @@ export function object2formData(
|
||||
});
|
||||
|
||||
// 因为 key 的格式太多了,偷个懒,用 qs 来处理吧。
|
||||
qs.stringify(others, options)
|
||||
qsstringify(others, options)
|
||||
.split('&')
|
||||
.forEach(item => {
|
||||
let parts = item.split('=');
|
||||
|
Loading…
Reference in New Issue
Block a user