crud-page-react 0.0.7 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -4
- package/dist/index.d.ts +6 -6
- package/dist/index.esm.js +8 -26
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +8 -26
- package/dist/index.js.map +1 -1
- package/dist/types/schema.d.ts +6 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -829,24 +829,6 @@ function processTemplateData(data, record) {
|
|
|
829
829
|
}
|
|
830
830
|
return result;
|
|
831
831
|
}
|
|
832
|
-
/** 解析 API 配置,支持字符串和对象两种格式 */
|
|
833
|
-
function parseApiConfig(apiDef) {
|
|
834
|
-
if (!apiDef)
|
|
835
|
-
return undefined;
|
|
836
|
-
if (typeof apiDef === 'string') {
|
|
837
|
-
// 简单字符串 URL 配置
|
|
838
|
-
return {
|
|
839
|
-
url: apiDef,
|
|
840
|
-
method: 'GET',
|
|
841
|
-
responseType: 'json'
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
else if (typeof apiDef === 'object') {
|
|
845
|
-
// 完整的 API 配置对象
|
|
846
|
-
return apiDef;
|
|
847
|
-
}
|
|
848
|
-
return undefined;
|
|
849
|
-
}
|
|
850
832
|
/** 通用请求封装 */
|
|
851
833
|
async function apiRequest(url, options) {
|
|
852
834
|
const res = await fetch(url, Object.assign({ headers: { 'Content-Type': 'application/json' } }, options));
|
|
@@ -895,12 +877,12 @@ const CrudPage = ({ schema, initialData = [], apiRequest: customApiRequest }) =>
|
|
|
895
877
|
}, []);
|
|
896
878
|
// ---------- 获取列表 ----------
|
|
897
879
|
const fetchList = react.useCallback(async (params = filterParams, p = page, ps = pageSize) => {
|
|
898
|
-
|
|
899
|
-
if (!listApiConfig) {
|
|
880
|
+
if (!schema.api.list) {
|
|
900
881
|
// 没有配置 API,使用初始数据
|
|
901
882
|
initializeData();
|
|
902
883
|
return;
|
|
903
884
|
}
|
|
885
|
+
const listApiConfig = schema.api.list;
|
|
904
886
|
setLoading(true);
|
|
905
887
|
try {
|
|
906
888
|
// 构建查询参数
|
|
@@ -965,11 +947,11 @@ const CrudPage = ({ schema, initialData = [], apiRequest: customApiRequest }) =>
|
|
|
965
947
|
}, []);
|
|
966
948
|
// ---------- 删除 ----------
|
|
967
949
|
const handleDelete = react.useCallback(async (record) => {
|
|
968
|
-
|
|
969
|
-
if (!deleteApiConfig) {
|
|
950
|
+
if (!schema.api.delete) {
|
|
970
951
|
messageApi.error('删除功能未配置');
|
|
971
952
|
return;
|
|
972
953
|
}
|
|
954
|
+
const deleteApiConfig = schema.api.delete;
|
|
973
955
|
try {
|
|
974
956
|
// 构建 URL,动态替换占位符
|
|
975
957
|
let url = deleteApiConfig.url;
|
|
@@ -1089,11 +1071,11 @@ const CrudPage = ({ schema, initialData = [], apiRequest: customApiRequest }) =>
|
|
|
1089
1071
|
const handleFormOk = react.useCallback(async (values) => {
|
|
1090
1072
|
const isCreate = modalState.mode === 'create';
|
|
1091
1073
|
if (isCreate) {
|
|
1092
|
-
|
|
1093
|
-
if (!createApiConfig) {
|
|
1074
|
+
if (!schema.api.create) {
|
|
1094
1075
|
messageApi.error('新增功能未配置');
|
|
1095
1076
|
return;
|
|
1096
1077
|
}
|
|
1078
|
+
const createApiConfig = schema.api.create;
|
|
1097
1079
|
try {
|
|
1098
1080
|
// 构建请求选项
|
|
1099
1081
|
const options = {
|
|
@@ -1118,11 +1100,11 @@ const CrudPage = ({ schema, initialData = [], apiRequest: customApiRequest }) =>
|
|
|
1118
1100
|
}
|
|
1119
1101
|
}
|
|
1120
1102
|
else {
|
|
1121
|
-
|
|
1122
|
-
if (!updateApiConfig) {
|
|
1103
|
+
if (!schema.api.update) {
|
|
1123
1104
|
messageApi.error('编辑功能未配置');
|
|
1124
1105
|
return;
|
|
1125
1106
|
}
|
|
1107
|
+
const updateApiConfig = schema.api.update;
|
|
1126
1108
|
try {
|
|
1127
1109
|
// 构建 URL,动态替换占位符
|
|
1128
1110
|
let url = updateApiConfig.url;
|