Browse Source

🚀 优雅的弹出错误

master
wangxiang 3 years ago
parent
commit
3a7d2ac354
  1. 26
      src/components/AMap/src/AMapDesigner/index.vue
  2. 27
      src/components/AMap/src/components/MapTaskModal.vue
  3. 22
      src/components/AMap/src/components/MapTaskPresetModal.vue

26
src/components/AMap/src/AMapDesigner/index.vue

@ -155,7 +155,7 @@
const emit = defineEmits(['success']); const emit = defineEmits(['success']);
const userStore = useUserStore(); const userStore = useUserStore();
const instance = getCurrentInstance(); const instance = getCurrentInstance();
const { createMessage } = useMessage(); const { notification } = useMessage();
const { mapDesigner } = componentSetting; const { mapDesigner } = componentSetting;
const mapState = reactive<MapState>({ const mapState = reactive<MapState>({
/** 遮罩层状态 */ /** 遮罩层状态 */
@ -619,10 +619,12 @@
mapState.mapData.mapTask.forEach(item => { mapState.mapData.mapTask.forEach(item => {
const hospital = mapState.hospitalList.find(e => e.value == item.hospitalId); const hospital = mapState.hospitalList.find(e => e.value == item.hospitalId);
const org = mapState.orgList.find(e => e.value == item.orgId); const org = mapState.orgList.find(e => e.value == item.orgId);
// , // ,,
if (!hospital) { if (!hospital) {
createMessage.error('当前机构数据或者医院数据已经更新,请重新刷新页面!'); throw notification.error({
throw Error('当前机构数据或者医院数据已经更新,请重新刷新页面!'); message: '当前机构数据或者医院数据已经更新,请重新刷新页面!',
duration: 2
});
} }
pointData.push({ pointData.push({
lng: hospital.mapLng, lng: hospital.mapLng,
@ -630,6 +632,7 @@
sort: undefined, sort: undefined,
type: '0', type: '0',
key: item.key, key: item.key,
taskType: item.taskType,
hospitalId: hospital.value, hospitalId: hospital.value,
hospitalName: hospital.label hospitalName: hospital.label
}); });
@ -639,6 +642,7 @@
sort: undefined, sort: undefined,
type: '1', type: '1',
key: item.key, key: item.key,
taskType: item.taskType,
hospitalId: org.value, hospitalId: org.value,
hospitalName: org.label hospitalName: org.label
}); });
@ -683,10 +687,10 @@
async function handleMapSave() { async function handleMapSave() {
await formElRef.value.validate(); await formElRef.value.validate();
const mapData = toRaw(mapState.mapData); const mapData = toRaw(mapState.mapData);
mapData.fileId = (mapData.fileId as [] || []).join(','); mapData.fileId = (mapData.fileId as[])?.join(',');
mapData.mapTask.forEach(item => { mapData.mapTask.forEach(item => {
const hospital = mapState.hospitalList.find(e => e.value == item.hospitalId), const hospital = item.hospitalId && mapState.hospitalList.find(e => e.value == item.hospitalId),
org = mapState.orgList.find(e => e.value == item.orgId); org = item.orgId && mapState.orgList.find(e => e.value == item.orgId);
item.courierUserId = mapData.courierUserId; item.courierUserId = mapData.courierUserId;
hospital && Object.assign(item,{ hospital && Object.assign(item,{
hospitalName: hospital.label, hospitalName: hospital.label,
@ -698,11 +702,11 @@
orgLng: org.mapLng, orgLng: org.mapLng,
orgLat: org.mapLat orgLat: org.mapLat
}); });
item.fileId = (item.fileId as [] || []).join(','); item.fileId = (item.fileId as [])?.join(',');
if (~~item.taskType == 1) { if (~~item.taskType == 1) {
item?.mapTaskPreset?.forEach(childItem => { item?.mapTaskPreset?.forEach(childItem => {
const childHospital = mapState.hospitalList.find(e => e.value == childItem.hospitalId), const childHospital = childItem.hospitalId && mapState.hospitalList.find(e => e.value == childItem.hospitalId),
childOrg = mapState.orgList.find(e => e.value == childItem.orgId); childOrg = childItem.orgId && mapState.orgList.find(e => e.value == childItem.orgId);
childItem.courierUserId = mapData.courierUserId; childItem.courierUserId = mapData.courierUserId;
childHospital && Object.assign(item,{ childHospital && Object.assign(item,{
orginPresetName: childHospital.label, orginPresetName: childHospital.label,
@ -714,7 +718,7 @@
destinationPresetLng: childOrg.mapLng, destinationPresetLng: childOrg.mapLng,
destinationPresetLat: childOrg.mapLat destinationPresetLat: childOrg.mapLat
}); });
childItem.fileId = (childItem.fileId as [] || [])?.join(','); childItem.fileId = (childItem.fileId as [])?.join(',');
}); });
} }
}); });

27
src/components/AMap/src/components/MapTaskModal.vue

@ -94,7 +94,7 @@
// : // :
setModalProps(props); setModalProps(props);
}); });
const { createMessage } = useMessage(); const { notification } = useMessage();
const [taskPresetRegisterModal, { openModal }] = useModal(); const [taskPresetRegisterModal, { openModal }] = useModal();
const [taskOrdinaryRegisterTable, { const [taskOrdinaryRegisterTable, {
getDataSource: getTaskOrdinaryDataSource, getDataSource: getTaskOrdinaryDataSource,
@ -162,7 +162,10 @@
const index = getTaskOrdinaryDataSource().findIndex(item => item.key == record.key); const index = getTaskOrdinaryDataSource().findIndex(item => item.key == record.key);
if (index != -1) { if (index != -1) {
getTaskOrdinaryDataSource().splice(record.index, 1); getTaskOrdinaryDataSource().splice(record.index, 1);
} else createMessage.error(`找不到key:${record.key}的数据,请刷新页面重试!`); } else notification.error({
message: `找不到key:${record.key}的数据,请刷新页面重试!`,
duration: 2
});
} }
/** 处理交接任务新增 */ /** 处理交接任务新增 */
@ -182,7 +185,10 @@
const index = getTaskPresetDataSource().findIndex(item => item.key == record.key); const index = getTaskPresetDataSource().findIndex(item => item.key == record.key);
if (index != -1) { if (index != -1) {
getTaskPresetDataSource().splice(record.index, 1); getTaskPresetDataSource().splice(record.index, 1);
} else createMessage.error(`找不到key:${record.key}的数据,请刷新页面重试!`); } else notification.error({
message: `找不到key:${record.key}的数据,请刷新页面重试!`,
duration: 2
});
} }
/** 创建普通任务操作列 */ /** 创建普通任务操作列 */
@ -299,8 +305,14 @@
setModalProps({ confirmLoading: true }); setModalProps({ confirmLoading: true });
const taskOrdinaryData = toRaw(getTaskOrdinaryDataSource()); const taskOrdinaryData = toRaw(getTaskOrdinaryDataSource());
const taskPresetData = toRaw(getTaskPresetDataSource()); const taskPresetData = toRaw(getTaskPresetDataSource());
if (state.taskOrdinaryCurrentEditRowRef || state.taskPresetCurrentEditRowRef) return createMessage.error('表格行未保存,请检查!'); if (state.taskOrdinaryCurrentEditRowRef || state.taskPresetCurrentEditRowRef) throw notification.error({
if (taskOrdinaryData.length === 0 && taskPresetData.length === 0) return createMessage.error('表格数据不能为空!'); message: '表格行未保存,请检查!',
duration: 2
});
if (taskOrdinaryData.length === 0 && taskPresetData.length === 0) throw notification.error({
message: '表格数据不能为空!',
duration: 2
});
// //
const validateData:Promise<boolean>[] = []; const validateData:Promise<boolean>[] = [];
taskOrdinaryData.forEach(item => { taskOrdinaryData.forEach(item => {
@ -310,7 +322,10 @@
validateData.push(item.onValid?.() || Promise.resolve(true)); validateData.push(item.onValid?.() || Promise.resolve(true));
}); });
const validateResult = await Promise.all(validateData); const validateResult = await Promise.all(validateData);
if (!validateResult.every(item => item)) return createMessage.error('表格行校验未通过,请检查!'); if (!validateResult.every(item => item)) throw notification.error({
message: '表格行校验未通过,请检查!',
duration: 2
});
state.mapData.mapTask = [...taskOrdinaryData, ...taskPresetData]; state.mapData.mapTask = [...taskOrdinaryData, ...taskPresetData];
// //
closeModal(); closeModal();

22
src/components/AMap/src/components/MapTaskPresetModal.vue

@ -78,7 +78,7 @@
const ASelect = Select; const ASelect = Select;
const formElRef = ref(); const formElRef = ref();
const emit = defineEmits(['success', 'register']); const emit = defineEmits(['success', 'register']);
const { createMessage } = useMessage(); const { notification } = useMessage();
const [registerModal, { setModalProps, closeModal }] = useModalInner(async data => { const [registerModal, { setModalProps, closeModal }] = useModalInner(async data => {
// //
formElRef.value.resetFields(); formElRef.value.resetFields();
@ -170,7 +170,10 @@
const index = getDataSource().findIndex(item => item.key == record.key); const index = getDataSource().findIndex(item => item.key == record.key);
if (index != -1) { if (index != -1) {
getDataSource().splice(record.index, 1); getDataSource().splice(record.index, 1);
} else createMessage.error(`找不到key:${record.key}的数据,请刷新页面重试!`); } else notification.error({
message: `找不到key:${record.key}的数据,请刷新页面重试!`,
duration: 2
});
} }
/** 创建转办任务操作列 */ /** 创建转办任务操作列 */
@ -233,8 +236,14 @@
// //
setModalProps({ confirmLoading: true }); setModalProps({ confirmLoading: true });
const mapTaskPresetData = toRaw(getDataSource()); const mapTaskPresetData = toRaw(getDataSource());
if (state.currentEditRowRef) return createMessage.error('表格行未保存,请检查!'); if (state.currentEditRowRef) throw notification.error({
if (mapTaskPresetData.length === 0) return createMessage.error('表格数据不能为空!'); message: '表格行未保存,请检查!',
duration: 2
});
if (mapTaskPresetData.length === 0) throw notification.error({
message: '表格数据不能为空!',
duration: 2
});
const formData = await formElRef.value.validate(); const formData = await formElRef.value.validate();
const validateData:Promise<boolean>[] = []; const validateData:Promise<boolean>[] = [];
// //
@ -248,7 +257,10 @@
} }
}); });
const validateResult = await Promise.all(validateData); const validateResult = await Promise.all(validateData);
if (!validateResult.every(item => item)) return createMessage.error('表格行校验未通过,请检查!'); if (!validateResult.every(item => item)) throw notification.error({
message: '表格行校验未通过,请检查!',
duration: 2
});
// //
const lastElement = mapTaskPresetData[mapTaskPresetData.length - 1]; const lastElement = mapTaskPresetData[mapTaskPresetData.length - 1];
const option = state.orgList.find(item => item.value == formData.destinationPresetId); const option = state.orgList.find(item => item.value == formData.destinationPresetId);

Loading…
Cancel
Save