Files
certd/packages/ui/certd-client/src/views/crud/feature/editable/crud.tsx
T
GitHub Actions Bot 6ec697b010 🔱: [client] sync upgrade with 12 commits [trident-sync]
refactor: 1.11.0
refactor: 1.11.0
refactor: 1.11.0
refactor: 1.11.0
refactor: ts化
refactor: ts化
feat: 全面TS化
perf: 全面ts化
refactor: 继续优化ts
perf: ts定义优化
fix: 修复wangeditor无法上传视频的bug
2023-03-16 19:24:01 +00:00

116 lines
3.0 KiB
TypeScript

import * as api from "./api";
import { dict, compute, CreateCrudOptionsProps, CreateCrudOptionsRet, UserPageQuery, UserPageRes, EditReq, DelReq, AddReq } from "@fast-crud/fast-crud";
export default function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const { crudBinding } = crudExpose;
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
return await api.GetList(query);
};
const editRequest = async ({ form, row }: EditReq) => {
form.id = row.id;
return await api.UpdateObj(form);
};
const delRequest = async ({ row }: DelReq) => {
return await api.DelObj(row.id);
};
const addRequest = async ({ form }: AddReq) => {
return await api.AddObj(form);
};
return {
crudOptions: {
request: {
pageRequest,
addRequest,
editRequest,
delRequest
},
actionbar: {
buttons: {
add: {
show: compute(() => {
if (crudBinding.value) {
return !crudBinding.value?.table.editable.enabled;
}
return false;
})
},
addRow: {
show: compute(() => {
if (crudBinding.value) {
return crudBinding.value?.table.editable.enabled;
}
return false;
})
}
}
},
table: {
editable: {
mode: "free"
}
},
columns: {
id: {
title: "ID",
type: "number",
form: {
show: false
},
column: { width: 80, align: "center" }
},
disable: {
title: "禁止编辑",
type: "text",
column: {
editable: {
disabled: true //也可以配置为方法,根据条件禁用或启用编辑
// disabled: ({ column, index, row }) => {
// return index % 2 === 0;
// }
}
}
},
radio: {
title: "状态",
search: { show: true },
type: "dict-radio",
dict: dict({
url: "/mock/dicts/OpenStatusEnum?single"
})
},
name: {
title: "姓名",
type: "text"
},
address: {
title: "地址",
children: {
province: {
title: "省份",
search: { show: true },
type: "text"
},
city: {
title: "城市",
search: { show: true },
type: "dict-select",
dict: dict({
value: "id",
label: "text",
data: [
{ id: "sz", text: "深圳", color: "success" },
{ id: "gz", text: "广州", color: "primary" },
{ id: "bj", text: "北京" },
{ id: "wh", text: "武汉" },
{ id: "sh", text: "上海" }
]
})
}
}
}
}
}
};
}