2023-01-29 15:26:45 +08:00
|
|
|
import * as api from "./api";
|
|
|
|
|
import { requestForMock } from "/src/api/service";
|
2023-03-16 19:24:01 +00:00
|
|
|
import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, EditReq, GetContextFn, ScopeContext, useCompute, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud";
|
2023-01-29 15:26:45 +08:00
|
|
|
import { message } from "ant-design-vue";
|
2023-06-09 19:24:11 +00:00
|
|
|
import { computed } from "vue";
|
2023-03-16 19:24:01 +00:00
|
|
|
|
2025-03-03 19:24:51 +00:00
|
|
|
export default function ({ context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
|
|
|
|
const { asyncCompute, compute } = useCompute();
|
2023-03-12 19:23:59 +00:00
|
|
|
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
|
2023-01-29 15:26:45 +08:00
|
|
|
return await api.GetList(query);
|
|
|
|
|
};
|
2023-03-12 19:23:59 +00:00
|
|
|
const editRequest = async ({ form, row }: EditReq) => {
|
2023-11-23 19:24:19 +00:00
|
|
|
if (form.id == null) {
|
|
|
|
|
form.id = row.id;
|
|
|
|
|
}
|
2023-01-29 15:26:45 +08:00
|
|
|
return await api.UpdateObj(form);
|
|
|
|
|
};
|
2023-03-12 19:23:59 +00:00
|
|
|
const delRequest = async ({ row }: DelReq) => {
|
2023-01-29 15:26:45 +08:00
|
|
|
return await api.DelObj(row.id);
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-12 19:23:59 +00:00
|
|
|
const addRequest = async ({ form }: AddReq) => {
|
2023-01-29 15:26:45 +08:00
|
|
|
return await api.AddObj(form);
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-09 19:24:11 +00:00
|
|
|
const { showRef, showTableComputed, columnComponentShowComputed } = context;
|
2023-01-29 15:26:45 +08:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
crudOptions: {
|
|
|
|
|
request: {
|
|
|
|
|
pageRequest,
|
|
|
|
|
addRequest,
|
|
|
|
|
editRequest,
|
|
|
|
|
delRequest
|
|
|
|
|
},
|
2024-06-15 18:32:36 +00:00
|
|
|
toolbar: {
|
|
|
|
|
compact: false
|
|
|
|
|
},
|
2023-01-29 15:26:45 +08:00
|
|
|
table: {
|
|
|
|
|
scroll: {
|
|
|
|
|
x: 1500
|
|
|
|
|
},
|
|
|
|
|
//通过switch动态显隐table
|
|
|
|
|
show: showTableComputed //不仅支持computed,直接传showTableRef也是可以的
|
|
|
|
|
},
|
|
|
|
|
form: {
|
|
|
|
|
labelCol: { span: 8 },
|
|
|
|
|
wrapperCol: { span: 14 }
|
|
|
|
|
},
|
|
|
|
|
rowHandle: {
|
|
|
|
|
fixed: "right",
|
2023-03-13 19:24:02 +00:00
|
|
|
show: computed(() => {
|
2023-03-16 19:24:01 +00:00
|
|
|
return true;
|
2023-03-13 19:24:02 +00:00
|
|
|
}),
|
2023-01-29 15:26:45 +08:00
|
|
|
buttons: {
|
|
|
|
|
edit: {
|
2023-03-13 19:24:02 +00:00
|
|
|
show: compute<boolean>(({ row }) => {
|
2023-01-29 15:26:45 +08:00
|
|
|
return row.editable;
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
remove: {
|
|
|
|
|
show: compute(({ row }) => {
|
|
|
|
|
return row.editable;
|
|
|
|
|
})
|
2023-03-16 19:24:01 +00:00
|
|
|
}
|
2023-01-29 15:26:45 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
columns: {
|
|
|
|
|
id: {
|
|
|
|
|
title: "ID",
|
|
|
|
|
key: "id",
|
|
|
|
|
type: "number",
|
|
|
|
|
column: {
|
|
|
|
|
width: 50,
|
|
|
|
|
resizable: true
|
|
|
|
|
},
|
|
|
|
|
form: {
|
|
|
|
|
show: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
refSwitch: {
|
|
|
|
|
title: "ref引用切换",
|
|
|
|
|
type: "text",
|
|
|
|
|
form: {
|
|
|
|
|
helper: "点我切换右边的输入框显示"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
ref: {
|
|
|
|
|
title: "根据ref引用显示",
|
|
|
|
|
type: ["text"],
|
|
|
|
|
form: {
|
|
|
|
|
component: {
|
|
|
|
|
show: showRef
|
|
|
|
|
},
|
|
|
|
|
helper: "我会根据showRef进行显隐"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
compute: {
|
|
|
|
|
title: "compute",
|
|
|
|
|
search: { show: false },
|
|
|
|
|
type: "text",
|
|
|
|
|
column: {
|
|
|
|
|
show: columnComponentShowComputed,
|
|
|
|
|
columnSetDisabled: true, //这里采用自定义控制显隐,那么列设置里面就要禁用
|
|
|
|
|
// columnSetShow: false, //直接不在列设置里面显示也行
|
|
|
|
|
component: {
|
|
|
|
|
name: "a-switch",
|
|
|
|
|
vModel: "checked"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
form: {
|
|
|
|
|
component: {
|
|
|
|
|
name: "a-switch",
|
|
|
|
|
vModel: "checked"
|
|
|
|
|
},
|
|
|
|
|
helper: "点我触发动态计算"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
shower: {
|
|
|
|
|
title: "根据compute显示",
|
|
|
|
|
search: { show: false },
|
|
|
|
|
type: "button",
|
|
|
|
|
form: {
|
|
|
|
|
component: {
|
|
|
|
|
show: compute(({ form }) => {
|
|
|
|
|
return form.compute;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
column: {
|
|
|
|
|
width: 250,
|
|
|
|
|
resizable: true,
|
|
|
|
|
component: {
|
|
|
|
|
show: compute(({ row }) => {
|
|
|
|
|
return row.compute;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
remote: {
|
|
|
|
|
title: "asyncCompute",
|
|
|
|
|
search: { show: true },
|
|
|
|
|
type: "text",
|
|
|
|
|
form: {
|
|
|
|
|
component: {
|
|
|
|
|
name: "a-select",
|
|
|
|
|
vModel: "value",
|
|
|
|
|
placeholder: "异步计算远程获取options",
|
|
|
|
|
options: asyncCompute({
|
2023-03-16 19:24:01 +00:00
|
|
|
async asyncFn(watchValue: any, context: GetContextFn) {
|
2024-12-03 19:26:18 +00:00
|
|
|
message.info("asyncCompute 获取options");
|
2023-01-29 15:26:45 +08:00
|
|
|
const url = "/mock/dicts/OpenStatusEnum?remote";
|
|
|
|
|
return await requestForMock({ url });
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
helper: "我的options是异步计算远程获取的,只会获取一次"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
remote2: {
|
|
|
|
|
title: "监听switch触发异步计算",
|
|
|
|
|
search: { show: false },
|
|
|
|
|
type: "text",
|
|
|
|
|
form: {
|
|
|
|
|
component: {
|
|
|
|
|
name: "a-select",
|
|
|
|
|
vModel: "value",
|
|
|
|
|
placeholder: "异步计算远程获取options",
|
|
|
|
|
options: asyncCompute({
|
2023-03-16 19:24:01 +00:00
|
|
|
watch({ form }: ScopeContext) {
|
2023-01-29 15:26:45 +08:00
|
|
|
return form.compute;
|
|
|
|
|
},
|
2023-03-16 19:24:01 +00:00
|
|
|
async asyncFn(watchValue: string) {
|
2023-01-29 15:26:45 +08:00
|
|
|
message.info("监听switch,触发远程获取options");
|
2023-03-09 19:24:01 +00:00
|
|
|
const url = watchValue ? "/mock/dicts/OpenStatusEnum?remote" : "/mock/dicts/moreOpenStatusEnum?remote";
|
2023-01-29 15:26:45 +08:00
|
|
|
return await requestForMock({ url });
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
helper: "监听其他属性修改后,触发重新计算"
|
|
|
|
|
},
|
|
|
|
|
column: {
|
|
|
|
|
width: 200
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
editable: {
|
|
|
|
|
title: "可编辑",
|
|
|
|
|
search: { show: false },
|
|
|
|
|
type: "text",
|
|
|
|
|
column: {
|
2024-06-15 18:32:36 +00:00
|
|
|
order: 1000,
|
2023-01-29 15:26:45 +08:00
|
|
|
fixed: "right",
|
|
|
|
|
component: {
|
|
|
|
|
name: "a-switch",
|
|
|
|
|
vModel: "checked"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
form: {
|
|
|
|
|
show: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|