import { message, Modal } from 'antd';
|
|
const confirm = Modal.confirm;
|
|
export function showConfirm(title, content, okHandler) {
|
confirm({
|
title: title,
|
content: content,
|
onOk() {
|
okHandler();
|
},
|
onCancel() { },
|
});
|
}
|
|
export function showDelConfirm(okHandler, content, confirmText, cancelText, titleText) {
|
confirm({
|
className: 'del-confirm',
|
title: titleText || '确定要删除这条数据?',
|
content: content || '删除后不可恢复,请谨慎操作!',
|
okText: confirmText || '删除',
|
cancelText: cancelText || '取消',
|
okType: 'default',
|
icon: <div className='del-icon'>?</div>,
|
footer: (params) => {
|
return [params.props.children[0], params.props.children[1]];
|
},
|
onOk() {
|
okHandler();
|
},
|
onCancel() {
|
|
},
|
});
|
}
|
// 转换成ProFormSelect可用的数据
|
export async function buildProFormSelectDataSourceTwo(fun, params) {
|
const response = await fun(params);
|
const options = (response.data.records || response.data).map(item => {
|
return {
|
label: item.phone,
|
value: item.uid || item.id || item.roleId,
|
...item
|
}
|
})
|
return options;
|
}
|
|
// 医废类型ProFormSelect
|
export async function buildProFormSelectDataSource(fun, params) {
|
const response = await fun(params);
|
const options = response.data.map(item => {
|
return {
|
label: item.dictLabel,
|
value: item.dictCode,
|
...item
|
}
|
})
|
return options;
|
}
|
|
// 转换成ProFormSelect可用的数据
|
export async function buildProFormSelectDataSourceCopy(fun, params) {
|
const response = await fun(params);
|
const options = response.data.map(item => {
|
return {
|
label: item.equipmentName,
|
value: item.id,
|
...item
|
}
|
})
|
return options;
|
}
|
|
/**
|
* 服务端的分页数据转换成AntD的数据类型
|
*/
|
export function pageData2Obj(pageData) {
|
return {
|
list: pageData.records || [],
|
pagination: {
|
total: pageData.total || 0,
|
pageSize: pageData.size || 10,
|
current: pageData.current || 0,
|
},
|
};
|
}
|
export async function buildProFormDataSource(fun, params) {
|
const response = await fun(params);
|
const data = Promise.resolve({
|
...response.data
|
});
|
return data;
|
}
|
|
export async function buildProFormDataSourceSpecial(fun, params) {
|
const response = await fun(params);
|
response.data.parkingDuration = response.data.parkingDuration || 0 + ' 分钟';
|
const data = Promise.resolve({
|
...response.data
|
});
|
return data;
|
}
|
|
export async function buildProTableDataSource(fun, params) {
|
params.pageNum = params.current;
|
delete params.current
|
const response = await fun(params);
|
const data = Promise.resolve({
|
data: response.data.records || [],
|
total: response.data.total || 0,
|
success: true,
|
pageSize: response.data.size || 10,
|
pageCurr: response.data.pages || 0,
|
});
|
return data;
|
}
|
|
export async function buildTreeDataSource(func, params) {
|
const response = await func(params);
|
const data = Promise.resolve({
|
data: response || [],
|
success: true,
|
});
|
return data;
|
}
|
|
export async function builDataSource(func, params) {
|
const response = await func(params);
|
const data = Promise.resolve({
|
data: response || [],
|
success: true,
|
});
|
return data;
|
}
|
|
/**
|
* 统一处理返回结果信息
|
*/
|
export function responseDataParse(response, callback) {
|
if (callback && typeof callback === 'function' && response) {
|
callback(response); // 返回结果
|
}
|
}
|
|
/**
|
* 发送请求
|
* @param func
|
* @param params
|
* @returns {Promise<boolean>}
|
*/
|
export async function sendRequest(func, params) {
|
const hide = message.loading('正在请求中');
|
try {
|
const data = params instanceof Object ? { ...params } : params;
|
const res = await func(data);
|
hide();
|
if (res.code == '200') {
|
message.success('操作成功');
|
return true;
|
} else if (res.code == '602') {
|
|
return res;
|
} else {
|
return false;
|
}
|
} catch (error) {
|
hide();
|
return false;
|
}
|
}
|
/**
|
* GET下载
|
* @param {*} url
|
*/
|
export function dowloadByGet(url) {
|
const eleLink = document.createElement('a');
|
eleLink.style.display = 'none';
|
// eleLink.target = "_blank"
|
eleLink.href = url;
|
// eleLink.href = record;
|
document.body.appendChild(eleLink);
|
eleLink.click();
|
document.body.removeChild(eleLink);
|
}
|
/**
|
* POST方法下载
|
* @param {*} params
|
*/
|
export async function downloadByPost(params) {
|
let form = document.createElement('form');
|
form.style.display = 'none';
|
form.action = `${api}tCmPaymentOrd/export`;
|
form.method = 'POST';
|
document.body.appendChild(form);
|
// 动态创建input并给value赋值
|
for (var key in params) {
|
var input = document.createElement('input');
|
input.type = 'hidden';
|
input.name = key;
|
input.value = params[key];
|
form.appendChild(input);
|
}
|
form.submit();
|
form.remove();
|
}
|
|
export const pageOption = { size: 10, current: 1 };
|