Tree 优化

This commit is contained in:
liaoxuezhi 2019-11-10 11:38:33 +08:00
parent fbae712fdc
commit 732ea0c41e
4 changed files with 44 additions and 10 deletions

View File

@ -32,8 +32,6 @@
position: relative;
>div {
color: inherit;
&:hover {
text-decoration: none;
@ -230,11 +228,13 @@
&-item &-item>&-itemLabel {
&-item &-item>&-itemLabel,
&-item>&-placeholder {
padding-left: $Tree-indent;
}
&-item &-item &-item>&-itemLabel {
&-item &-item &-item>&-itemLabel,
&-item &-item>&-placeholder {
padding-left: $Tree-indent * 2;
}

View File

@ -646,6 +646,8 @@ export class TreeSelector extends React.Component<
) : null}
{childrenItems}
</ul>
) : !childrenItems && item.placeholder ? (
<div className={cx('Tree-placeholder')}>{item.placeholder}</div>
) : null}
</li>
);
@ -674,7 +676,7 @@ export class TreeSelector extends React.Component<
let addBtn = null;
if (creatable && hideRoot) {
if (creatable && rootCreatable !== false && hideRoot) {
addBtn = (
<a
className={cx('Tree-addTopBtn', {

View File

@ -524,7 +524,13 @@ export function registerOptionsControl(config: OptionsConfig) {
// 单独发请求
if (skipForm && addApi) {
try {
const payload = await env.fetcher(addApi!, result);
const payload = await env.fetcher(
addApi!,
createObject(data, result),
{
method: 'post'
}
);
if (!payload.ok) {
env.notify('error', payload.msg || '新增失败,请仔细检查');
@ -580,6 +586,7 @@ export function registerOptionsControl(config: OptionsConfig) {
labelField,
onOpenDialog,
editApi,
env,
source,
data,
formItem: model,
@ -616,6 +623,29 @@ export function registerOptionsControl(config: OptionsConfig) {
createObject(data, value)
);
// 单独发请求
if (skipForm && editApi) {
try {
const payload = await env.fetcher(
editApi!,
createObject(data, result),
{
method: 'post'
}
);
if (!payload.ok) {
env.notify('error', payload.msg || '保存失败,请仔细检查');
} else {
result = payload.data || result;
}
} catch (e) {
result = null;
console.error(e);
env.notify('error', e.message);
}
}
// 没有结果,说明取消了。
if (!result) {
return;
@ -670,7 +700,9 @@ export function registerOptionsControl(config: OptionsConfig) {
throw new Error('请配置 deleteApi');
}
const result = await env.fetcher(deleteApi!, ctx);
const result = await env.fetcher(deleteApi!, ctx, {
method: 'delete'
});
if (!result.ok) {
env.notify('error', result.msg || '删除失败,请重试');

View File

@ -20,13 +20,13 @@ interface ApiCacheConfig extends ApiObject {
const apiCaches: Array<ApiCacheConfig> = [];
export function normalizeApi(api: Api): ApiObject {
export function normalizeApi(api: Api, defaultMethod?: string): ApiObject {
if (typeof api === 'string') {
let method = rSchema.test(api) ? RegExp.$1 : '';
method && (api = api.replace(method + ':', ''));
api = {
method: method as any,
method: (method || defaultMethod) as any,
url: api
};
} else {
@ -46,7 +46,7 @@ export function buildApi(
[propName: string]: any;
} = {}
): ApiObject {
api = normalizeApi(api);
api = normalizeApi(api, options.method);
const {autoAppend, ignoreData, ...rest} = options;
api.config = {