Files
pqs-9100_client/frontend/src/hooks/useHandleData.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-08-22 11:27:06 +08:00
import { ElMessageBox, ElMessage } from "element-plus";
import { HandleData } from "./interface";
/**
* @description ()
* @param {Function} api api方法 ()
* @param {Object} params {id,params} ()
* @param {String} message ()
* @param {String} confirmType icon类型 (, warning)
* @returns {Promise}
*/
export const useHandleData = (
api: (params: any) => Promise<any>,
params: any = {},
message: string,
confirmType: HandleData.MessageType = "warning"
) => {
return new Promise((resolve, reject) => {
ElMessageBox.confirm(`是否${message}?`, "温馨提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: confirmType,
draggable: true
}).then(async () => {
const res = await api(params);
if (!res) return reject(false);
ElMessage({
type: "success",
message: `${message}成功!`
});
resolve(true);
});
});
};