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; position: relative;
>div { >div {
color: inherit;
&:hover { &:hover {
text-decoration: none; text-decoration: none;
@ -230,11 +228,13 @@
&-item &-item>&-itemLabel { &-item &-item>&-itemLabel,
&-item>&-placeholder {
padding-left: $Tree-indent; padding-left: $Tree-indent;
} }
&-item &-item &-item>&-itemLabel { &-item &-item &-item>&-itemLabel,
&-item &-item>&-placeholder {
padding-left: $Tree-indent * 2; padding-left: $Tree-indent * 2;
} }

View File

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

View File

@ -524,7 +524,13 @@ export function registerOptionsControl(config: OptionsConfig) {
// 单独发请求 // 单独发请求
if (skipForm && addApi) { if (skipForm && addApi) {
try { try {
const payload = await env.fetcher(addApi!, result); const payload = await env.fetcher(
addApi!,
createObject(data, result),
{
method: 'post'
}
);
if (!payload.ok) { if (!payload.ok) {
env.notify('error', payload.msg || '新增失败,请仔细检查'); env.notify('error', payload.msg || '新增失败,请仔细检查');
@ -580,6 +586,7 @@ export function registerOptionsControl(config: OptionsConfig) {
labelField, labelField,
onOpenDialog, onOpenDialog,
editApi, editApi,
env,
source, source,
data, data,
formItem: model, formItem: model,
@ -616,6 +623,29 @@ export function registerOptionsControl(config: OptionsConfig) {
createObject(data, value) 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) { if (!result) {
return; return;
@ -670,7 +700,9 @@ export function registerOptionsControl(config: OptionsConfig) {
throw new Error('请配置 deleteApi'); throw new Error('请配置 deleteApi');
} }
const result = await env.fetcher(deleteApi!, ctx); const result = await env.fetcher(deleteApi!, ctx, {
method: 'delete'
});
if (!result.ok) { if (!result.ok) {
env.notify('error', result.msg || '删除失败,请重试'); env.notify('error', result.msg || '删除失败,请重试');

View File

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