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 @@ @@ -155,7 +155,7 @@
const emit = defineEmits(['success']);
const userStore = useUserStore();
const instance = getCurrentInstance();
const { createMessage } = useMessage();
const { notification } = useMessage();
const { mapDesigner } = componentSetting;
const mapState = reactive<MapState>({
/** 遮罩层状态 */
@ -619,10 +619,12 @@ @@ -619,10 +619,12 @@
mapState.mapData.mapTask.forEach(item => {
const hospital = mapState.hospitalList.find(e => e.value == item.hospitalId);
const org = mapState.orgList.find(e => e.value == item.orgId);
// ,
// ,,
if (!hospital) {
createMessage.error('当前机构数据或者医院数据已经更新,请重新刷新页面!');
throw Error('当前机构数据或者医院数据已经更新,请重新刷新页面!');
throw notification.error({
message: '当前机构数据或者医院数据已经更新,请重新刷新页面!',
duration: 2
});
}
pointData.push({
lng: hospital.mapLng,
@ -630,6 +632,7 @@ @@ -630,6 +632,7 @@
sort: undefined,
type: '0',
key: item.key,
taskType: item.taskType,
hospitalId: hospital.value,
hospitalName: hospital.label
});
@ -639,6 +642,7 @@ @@ -639,6 +642,7 @@
sort: undefined,
type: '1',
key: item.key,
taskType: item.taskType,
hospitalId: org.value,
hospitalName: org.label
});
@ -683,10 +687,10 @@ @@ -683,10 +687,10 @@
async function handleMapSave() {
await formElRef.value.validate();
const mapData = toRaw(mapState.mapData);
mapData.fileId = (mapData.fileId as [] || []).join(',');
mapData.fileId = (mapData.fileId as[])?.join(',');
mapData.mapTask.forEach(item => {
const hospital = mapState.hospitalList.find(e => e.value == item.hospitalId),
org = mapState.orgList.find(e => e.value == item.orgId);
const hospital = item.hospitalId && mapState.hospitalList.find(e => e.value == item.hospitalId),
org = item.orgId && mapState.orgList.find(e => e.value == item.orgId);
item.courierUserId = mapData.courierUserId;
hospital && Object.assign(item,{
hospitalName: hospital.label,
@ -698,11 +702,11 @@ @@ -698,11 +702,11 @@
orgLng: org.mapLng,
orgLat: org.mapLat
});
item.fileId = (item.fileId as [] || []).join(',');
item.fileId = (item.fileId as [])?.join(',');
if (~~item.taskType == 1) {
item?.mapTaskPreset?.forEach(childItem => {
const childHospital = mapState.hospitalList.find(e => e.value == childItem.hospitalId),
childOrg = mapState.orgList.find(e => e.value == childItem.orgId);
const childHospital = childItem.hospitalId && mapState.hospitalList.find(e => e.value == childItem.hospitalId),
childOrg = childItem.orgId && mapState.orgList.find(e => e.value == childItem.orgId);
childItem.courierUserId = mapData.courierUserId;
childHospital && Object.assign(item,{
orginPresetName: childHospital.label,
@ -714,7 +718,7 @@ @@ -714,7 +718,7 @@
destinationPresetLng: childOrg.mapLng,
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 @@ @@ -94,7 +94,7 @@
// :
setModalProps(props);
});
const { createMessage } = useMessage();
const { notification } = useMessage();
const [taskPresetRegisterModal, { openModal }] = useModal();
const [taskOrdinaryRegisterTable, {
getDataSource: getTaskOrdinaryDataSource,
@ -162,7 +162,10 @@ @@ -162,7 +162,10 @@
const index = getTaskOrdinaryDataSource().findIndex(item => item.key == record.key);
if (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 @@ @@ -182,7 +185,10 @@
const index = getTaskPresetDataSource().findIndex(item => item.key == record.key);
if (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 @@ @@ -299,8 +305,14 @@
setModalProps({ confirmLoading: true });
const taskOrdinaryData = toRaw(getTaskOrdinaryDataSource());
const taskPresetData = toRaw(getTaskPresetDataSource());
if (state.taskOrdinaryCurrentEditRowRef || state.taskPresetCurrentEditRowRef) return createMessage.error('表格行未保存,请检查!');
if (taskOrdinaryData.length === 0 && taskPresetData.length === 0) return createMessage.error('表格数据不能为空!');
if (state.taskOrdinaryCurrentEditRowRef || state.taskPresetCurrentEditRowRef) throw notification.error({
message: '表格行未保存,请检查!',
duration: 2
});
if (taskOrdinaryData.length === 0 && taskPresetData.length === 0) throw notification.error({
message: '表格数据不能为空!',
duration: 2
});
//
const validateData:Promise<boolean>[] = [];
taskOrdinaryData.forEach(item => {
@ -310,7 +322,10 @@ @@ -310,7 +322,10 @@
validateData.push(item.onValid?.() || Promise.resolve(true));
});
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];
//
closeModal();

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

@ -78,7 +78,7 @@ @@ -78,7 +78,7 @@
const ASelect = Select;
const formElRef = ref();
const emit = defineEmits(['success', 'register']);
const { createMessage } = useMessage();
const { notification } = useMessage();
const [registerModal, { setModalProps, closeModal }] = useModalInner(async data => {
//
formElRef.value.resetFields();
@ -170,7 +170,10 @@ @@ -170,7 +170,10 @@
const index = getDataSource().findIndex(item => item.key == record.key);
if (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 @@ @@ -233,8 +236,14 @@
//
setModalProps({ confirmLoading: true });
const mapTaskPresetData = toRaw(getDataSource());
if (state.currentEditRowRef) return createMessage.error('表格行未保存,请检查!');
if (mapTaskPresetData.length === 0) return createMessage.error('表格数据不能为空!');
if (state.currentEditRowRef) throw notification.error({
message: '表格行未保存,请检查!',
duration: 2
});
if (mapTaskPresetData.length === 0) throw notification.error({
message: '表格数据不能为空!',
duration: 2
});
const formData = await formElRef.value.validate();
const validateData:Promise<boolean>[] = [];
//
@ -248,7 +257,10 @@ @@ -248,7 +257,10 @@
}
});
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 option = state.orgList.find(item => item.value == formData.destinationPresetId);

Loading…
Cancel
Save