Browse Source

🅰 地图设计器严格规范ts类型

master
wangxiang 3 years ago
parent
commit
c90ccdcc13
  1. 2
      src/api/platform/common/controller/mapTaskPreset.ts
  2. 24
      src/api/platform/common/entity/mapLogisticPoint.ts
  3. 38
      src/api/platform/common/entity/mapTask.ts
  4. 40
      src/api/platform/common/entity/mapTaskPreset.ts
  5. 40
      src/components/AMap/src/AMapDesigner/index.vue
  6. 9
      src/components/AMap/src/components/MapTaskModal.vue
  7. 14
      src/components/AMap/src/components/MapTaskPresetModal.vue
  8. 36
      src/views/common/mapLogistic/MapLogisticModal.vue

2
src/api/platform/common/controller/mapTaskPreset.ts

@ -14,7 +14,7 @@ enum Api {
del = '/common_proxy/common/mapTaskPreset/remove' del = '/common_proxy/common/mapTaskPreset/remove'
} }
export const listMapTaskPreset = (params?: Partial<MapTaskPresetParams>) => defHttp.get({ url: Api.list, params }, { isReturnResultResponse: true }); export const listMapTaskPreset = (params?: Partial<MapTaskPresetParams>) => defHttp.get<MapTaskPresetResult>({ url: Api.list, params }, { isReturnResultResponse: true });
export const addMapTaskPreset = (params: Partial<MapTaskPreset>) => defHttp.post({ url: Api.add, data: params }); export const addMapTaskPreset = (params: Partial<MapTaskPreset>) => defHttp.post({ url: Api.add, data: params });

24
src/api/platform/common/entity/mapLogisticPoint.ts

@ -11,20 +11,20 @@ import type { CommonEntity, Page } from '/@/api/common/data/entity';
export type MapLogisticPointParams = Page & MapLogisticPoint; export type MapLogisticPointParams = Page & MapLogisticPoint;
export interface MapLogisticPoint extends CommonEntity { export interface MapLogisticPoint extends Partial<CommonEntity> {
id: string; id?: string;
hospitalId: string; lng?: number;
hospitalName: string; lat?: number;
lng: number; sort?: number;
lat: number;
sort: number;
type: string; type: string;
taskType: string; taskType: string;
batchCode: string; hospitalId?: string;
mapLogisticId: string; hospitalName?: string;
mapTaskId: string; batchCode?: string;
key: string; mapLogisticId?: string;
version: number; mapTaskId?: string;
key?: string;
version?: number;
} }
export type MapLogisticPointResult = R<MapLogisticPoint[]>; export type MapLogisticPointResult = R<MapLogisticPoint[]>;

38
src/api/platform/common/entity/mapTask.ts

@ -12,28 +12,28 @@ import type { MapTaskPreset } from './mapTaskPreset';
export type MapTaskParams = Page & MapTask; export type MapTaskParams = Page & MapTask;
export interface MapTask extends CommonEntity { export interface MapTask extends Partial<CommonEntity> {
id: string; id?: string;
name: string; name: string;
sort: number; sort?: number;
taskType: string; taskType: string;
hospitalId: string; hospitalId: string;
hospitalName: string; hospitalName?: string;
hospitalLng: number; hospitalLng?: number;
hospitalLat: number; hospitalLat?: number;
orgId: string; orgId?: string;
orgName: string; orgName?: string;
orgLng: number; orgLng?: number;
orgLat: number; orgLat?: number;
courierUserId: string; courierUserId?: string;
fileId: string; fileId: string | string[];
estimateTime: string; estimateTime?: string;
requireTime: string; requireTime?: string;
batchCode: string; batchCode?: string;
mapLogisticId: string; mapLogisticId?: string;
key: string; key?: string;
version: number; version?: number;
mapTaskPreset: MapTaskPreset[] mapTaskPreset?: MapTaskPreset[]
} }
export type MapTaskResult = R<MapTask[]>; export type MapTaskResult = R<MapTask[]>;

40
src/api/platform/common/entity/mapTaskPreset.ts

@ -11,27 +11,27 @@ import type { CommonEntity, Page } from '/@/api/common/data/entity';
export type MapTaskPresetParams = Page & MapTaskPreset; export type MapTaskPresetParams = Page & MapTaskPreset;
export interface MapTaskPreset extends CommonEntity { export interface MapTaskPreset extends Partial<CommonEntity> {
id: string; id?: string;
name: string; name: string;
sort: number; sort?: number;
orginPresetId: string; orginPresetId?: string;
orginPresetName: string; orginPresetName?: string;
orginPresetLng: number; orginPresetLng?: number;
orginPresetLat: number; orginPresetLat?: number;
destinationPresetId: string; destinationPresetId?: string;
destinationPresetName: string; destinationPresetName?: string;
destinationPresetLng: number; destinationPresetLng?: number;
destinationPresetLat: number; destinationPresetLat?: number;
courierUserId: string; courierUserId?: string;
key: string; key?: string;
fileId: string; fileId: string | string[];
estimateTime: string; estimateTime?: string;
requireTime: string; requireTime?: string;
batchCode: string; batchCode?: string;
mapLogisticId: string; mapLogisticId?: string;
taskId: string; taskId?: string;
version: number; version?: number;
} }
export type MapTaskPresetResult = R<MapTaskPreset[]>; export type MapTaskPresetResult = R<MapTaskPreset[]>;

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

@ -106,7 +106,7 @@
import { getCourierUserList } from '/@/api/platform/system/controller/user'; import { getCourierUserList } from '/@/api/platform/system/controller/user';
import { listOrg } from '/@/api/platform/common/controller/org'; import { listOrg } from '/@/api/platform/common/controller/org';
import { useUserStore } from '/@/store/modules/user'; import { useUserStore } from '/@/store/modules/user';
import {split, divide, subtract, merge, isEmpty, cloneDeep, add, omit} from 'lodash-es'; import { split, divide, subtract, merge, isEmpty, cloneDeep, add } from 'lodash-es';
import componentSetting from '/@/settings/componentSetting'; import componentSetting from '/@/settings/componentSetting';
import { BasicUpload } from '/@/components/Upload'; import { BasicUpload } from '/@/components/Upload';
import { commonUpload } from '/@/api/platform/core/controller/upload'; import { commonUpload } from '/@/api/platform/core/controller/upload';
@ -118,6 +118,7 @@
import { MapLogistic } from '/@/api/platform/common/entity/mapLogistic'; import { MapLogistic } from '/@/api/platform/common/entity/mapLogistic';
import { buildUUID } from '/@/utils/uuid'; import { buildUUID } from '/@/utils/uuid';
import { RuleObject } from 'ant-design-vue/es/form/interface'; import { RuleObject } from 'ant-design-vue/es/form/interface';
import { MapLogisticPoint } from '/@/api/platform/common/entity/mapLogisticPoint';
/** 类型规范统一声明定义区域 */ /** 类型规范统一声明定义区域 */
interface MapState { interface MapState {
@ -351,7 +352,7 @@
const { lnglat } = ctx; const { lnglat } = ctx;
map.setZoomAndCenter(18, lnglat); map.setZoomAndCenter(18, lnglat);
}); });
const orgPoints = mapState.orgList.map((org: any) => ({ const orgPoints = mapState.orgList.map(org => ({
lnglat: [org.mapLng, org.mapLat], ...org lnglat: [org.mapLng, org.mapLat], ...org
})); }));
orgMarkerCluster?.setData(orgPoints); orgMarkerCluster?.setData(orgPoints);
@ -401,7 +402,7 @@
const { lnglat } = ctx; const { lnglat } = ctx;
map.setZoomAndCenter(18, lnglat); map.setZoomAndCenter(18, lnglat);
}); });
const hospitalPoints = mapState.hospitalList.map((hospital: any) => ({ const hospitalPoints = mapState.hospitalList.map(hospital => ({
lnglat: [hospital.mapLng, hospital.mapLat], ...hospital lnglat: [hospital.mapLng, hospital.mapLat], ...hospital
})); }));
hospitalMarkerCluster?.setData(hospitalPoints); hospitalMarkerCluster?.setData(hospitalPoints);
@ -445,7 +446,7 @@
const { lnglat } = ctx; const { lnglat } = ctx;
map.setZoomAndCenter(18, lnglat); map.setZoomAndCenter(18, lnglat);
}); });
const courierUserPoints = mapState.courierUserList.map((courierUser: any) => ({ const courierUserPoints = mapState.courierUserList.map(courierUser => ({
lnglat: [courierUser.mapLng, courierUser.mapLat], ...courierUser lnglat: [courierUser.mapLng, courierUser.mapLat], ...courierUser
})); }));
courierUserMarkerCluster?.setData(courierUserPoints); courierUserMarkerCluster?.setData(courierUserPoints);
@ -502,7 +503,7 @@
if (!mapProps.sidebarControl) mapState.toggleOperatePanelClass.siderWidth = 0; if (!mapProps.sidebarControl) mapState.toggleOperatePanelClass.siderWidth = 0;
if (!mapProps.toolbarControl) mapState.toggleOperatePanelClass.toolbarHeight = 0; if (!mapProps.toolbarControl) mapState.toggleOperatePanelClass.toolbarHeight = 0;
}); });
watch(toRefs(mapProps).options, (newValue) => { watch(toRefs(mapProps).options, (newValue: MapLogistic) => {
setMapDataJson(newValue); setMapDataJson(newValue);
}, { }, {
immediate: true, immediate: true,
@ -564,9 +565,9 @@
} }
/** 处理收样员搜索 */ /** 处理收样员搜索 */
function handleCourierUserSearch(value) { function handleCourierUserSearch(hospitalId: string) {
// //
const hospitalMap = mapState.hospitalList.find(item => item.value == value); const hospitalMap = mapState.hospitalList.find(item => item.value == hospitalId);
if (hospitalMap) { if (hospitalMap) {
map.remove(scanCourierUserCircleRange || {}); map.remove(scanCourierUserCircleRange || {});
scanCourierUserCircleRange.setCenter([hospitalMap.mapLng, hospitalMap.mapLat]); scanCourierUserCircleRange.setCenter([hospitalMap.mapLng, hospitalMap.mapLat]);
@ -650,8 +651,8 @@
} }
/** 设置地图数据json */ /** 设置地图数据json */
function setMapDataJson(data) { function setMapDataJson(mapData: MapLogistic) {
let options = data; let options: Nullable<MapLogistic> = mapData;
if (typeof options === 'string') { if (typeof options === 'string') {
try { try {
options = eval('(' + options + ')'); options = eval('(' + options + ')');
@ -660,7 +661,7 @@
message: '非法配置', message: '非法配置',
duration: 2 duration: 2
}); });
options = {}; options = null;
} }
} }
handleMapReset(); handleMapReset();
@ -678,13 +679,13 @@
return cloneDeep(mapState.mapData); return cloneDeep(mapState.mapData);
} }
/** 获取部件表单数据 */ /** 清除表单校验数据 */
function formClearValidate(fields: string[] | string) { function formClearValidate(fields: string[] | string) {
return formElRef.value.clearValidate(fields); return formElRef.value.clearValidate(fields);
} }
/** 绘制地图导航路线 */ /** 绘制地图导航路线 */
function drawMapNavigate(points: Recordable[] = []) { function drawMapNavigate(points: MapLogisticPoint[] = []) {
points = points.filter(item => item.lng && item.lat); points = points.filter(item => item.lng && item.lat);
if (points.length > 0 && mapState.mapData.courierLng && mapState.mapData.courierLat) { if (points.length > 0 && mapState.mapData.courierLng && mapState.mapData.courierLat) {
const lngLats = points.map(item => new AMap.LngLat(item.lng, item.lat)); const lngLats = points.map(item => new AMap.LngLat(item.lng, item.lat));
@ -703,7 +704,7 @@
/** 处理地图标记点生成 */ /** 处理地图标记点生成 */
async function handleMapPointGenerate() { async function handleMapPointGenerate() {
setTableData(mapState.mapData.mapTask); setTableData(mapState.mapData.mapTask);
const pointData:Recordable[] = []; const pointData:MapLogisticPoint[] = [];
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),
org = mapState.orgList.find(e => e.value == item.orgId); org = mapState.orgList.find(e => e.value == item.orgId);
@ -761,7 +762,7 @@
} }
/** 处理地图标记点数据 */ /** 处理地图标记点数据 */
function handleMapPoint(mapLogisticPoint: Recordable[] = []) { function handleMapPoint(mapLogisticPoint: MapLogisticPoint[] = []) {
if (!isEmpty(mapLogisticPoint)) { if (!isEmpty(mapLogisticPoint)) {
mapState.mapData.mapLogisticPoint = mapLogisticPoint; mapState.mapData.mapLogisticPoint = mapLogisticPoint;
drawMapNavigate(mapLogisticPoint); drawMapNavigate(mapLogisticPoint);
@ -790,15 +791,15 @@
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 = childItem.hospitalId && mapState.hospitalList.find(e => e.value == childItem.hospitalId), const childHospital = childItem.orginPresetId && mapState.hospitalList.find(e => e.value == childItem.orginPresetId),
childOrg = childItem.orgId && mapState.orgList.find(e => e.value == childItem.orgId); childOrg = childItem.destinationPresetId && mapState.orgList.find(e => e.value == childItem.destinationPresetId);
childItem.courierUserId = mapData.courierUserId; childItem.courierUserId = mapData.courierUserId;
childHospital && Object.assign(item,{ childHospital && Object.assign(childItem,{
orginPresetName: childHospital.label, orginPresetName: childHospital.label,
orginPresetLat: childHospital.mapLat, orginPresetLat: childHospital.mapLat,
orginPresetLng: childHospital.mapLng orginPresetLng: childHospital.mapLng
}); });
childOrg && Object.assign(item,{ childOrg && Object.assign(childItem,{
destinationPresetName: childOrg.label, destinationPresetName: childOrg.label,
destinationPresetLng: childOrg.mapLng, destinationPresetLng: childOrg.mapLng,
destinationPresetLat: childOrg.mapLat destinationPresetLat: childOrg.mapLat
@ -839,7 +840,8 @@
defineExpose({ defineExpose({
drawMapNavigate, drawMapNavigate,
getMapDataJson, getMapDataJson,
setMapDataJson setMapDataJson,
formClearValidate
}); });
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

9
src/components/AMap/src/components/MapTaskModal.vue

@ -68,6 +68,7 @@
import { defaultMapData } from '/@/enums/amapEnum'; import { defaultMapData } from '/@/enums/amapEnum';
import { MapLogistic } from '/@/api/platform/common/entity/mapLogistic'; import { MapLogistic } from '/@/api/platform/common/entity/mapLogistic';
import { buildUUID } from '/@/utils/uuid'; import { buildUUID } from '/@/utils/uuid';
import { MapTask } from '/@/api/platform/common/entity/mapTask';
/** 类型规范统一声明定义区域 */ /** 类型规范统一声明定义区域 */
type OptionsType = { type OptionsType = {
@ -97,7 +98,7 @@
const [registerModal, { setModalProps, closeModal }] = useModalInner(async data => { const [registerModal, { setModalProps, closeModal }] = useModalInner(async data => {
// //
const { mapData, options } = data; const { mapData, options } = data;
state.mapData = mapData; state.mapData = mapData as MapLogistic;
state.options = options as OptionsType; state.options = options as OptionsType;
const props: Partial<ModalProps> = { confirmLoading: false }; const props: Partial<ModalProps> = { confirmLoading: false };
props.title = '任务配置'; props.title = '任务配置';
@ -230,7 +231,7 @@
orgId: '', orgId: '',
fileId: [], fileId: [],
key: buildUUID() key: buildUUID()
}); } as MapTask);
} }
/** 处理普通任务删除 */ /** 处理普通任务删除 */
@ -253,7 +254,7 @@
orgName: '等待收样员设置!', orgName: '等待收样员设置!',
fileId: [], fileId: [],
key: buildUUID() key: buildUUID()
}); } as MapTask);
} }
/** 处理交接任务删除 */ /** 处理交接任务删除 */
@ -404,7 +405,7 @@
}); });
taskOrdinaryData.forEach((item, index)=> item.sort = add(index, 1)); taskOrdinaryData.forEach((item, index)=> item.sort = add(index, 1));
taskPresetData.forEach((item, index)=> item.sort = add(index, 1)); taskPresetData.forEach((item, index)=> item.sort = add(index, 1));
state.mapData.mapTask = [...taskOrdinaryData, ...taskPresetData]; state.mapData.mapTask = [...taskOrdinaryData, ...taskPresetData] as MapTask[];
// //
closeModal(); closeModal();
emit('success'); emit('success');

14
src/components/AMap/src/components/MapTaskPresetModal.vue

@ -51,6 +51,8 @@
import { useMessage } from '/@/hooks/web/useMessage'; import { useMessage } from '/@/hooks/web/useMessage';
import { add, cloneDeep, omit } from 'lodash-es'; import { add, cloneDeep, omit } from 'lodash-es';
import { buildUUID } from '/@/utils/uuid'; import { buildUUID } from '/@/utils/uuid';
import { MapTask } from '/@/api/platform/common/entity/mapTask';
import { MapTaskPreset } from '/@/api/platform/common/entity/mapTaskPreset';
/** 类型规范统一声明定义区域 */ /** 类型规范统一声明定义区域 */
type OptionsType = { type OptionsType = {
@ -60,7 +62,7 @@
}; };
interface WindowState { interface WindowState {
currentEditRowRef: Nullable<Recordable>; currentEditRowRef: Nullable<Recordable>;
taskPresetRow: Recordable; taskPresetRow: Nullable<MapTask>;
modelRef: Recordable; modelRef: Recordable;
options: OptionsType; options: OptionsType;
} }
@ -68,7 +70,7 @@
/** 通用变量统一声明区域 */ /** 通用变量统一声明区域 */
const state = reactive<WindowState>({ const state = reactive<WindowState>({
currentEditRowRef: null, currentEditRowRef: null,
taskPresetRow: {}, taskPresetRow: null,
modelRef: { modelRef: {
destinationPresetId: '' destinationPresetId: ''
}, },
@ -90,7 +92,7 @@
formElRef.value.clearValidate(); formElRef.value.clearValidate();
// //
const { row, options } = data; const { row, options } = data;
state.taskPresetRow = row; state.taskPresetRow = row as MapTask;
state.options = options as OptionsType; state.options = options as OptionsType;
const props: Partial<ModalProps> = { confirmLoading: false }; const props: Partial<ModalProps> = { confirmLoading: false };
props.title = '转办任务配置'; props.title = '转办任务配置';
@ -159,7 +161,7 @@
destinationPresetName: '等待收样员设置!', destinationPresetName: '等待收样员设置!',
fileId: [], fileId: [],
key: buildUUID() key: buildUUID()
}); } as MapTaskPreset);
} }
/** 处理转办任务删除 */ /** 处理转办任务删除 */
@ -259,7 +261,7 @@
duration: 2 duration: 2
}); });
// //
const lastElement = mapTaskPresetData[mapTaskPresetData.length - 1]; const lastElement = mapTaskPresetData[mapTaskPresetData.length - 1] as MapTaskPreset;
const option = state.options.orgList?.find(item => item.value == formData.destinationPresetId); const option = state.options.orgList?.find(item => item.value == formData.destinationPresetId);
if (option && lastElement) { if (option && lastElement) {
lastElement.destinationPresetId = option.value; lastElement.destinationPresetId = option.value;
@ -268,7 +270,7 @@
lastElement.destinationPresetLat = option.mapLat; lastElement.destinationPresetLat = option.mapLat;
} }
mapTaskPresetData.forEach((item, index)=> item.sort = add(index, 1)); mapTaskPresetData.forEach((item, index)=> item.sort = add(index, 1));
state.taskPresetRow.mapTaskPreset = mapTaskPresetData; (state.taskPresetRow ?? Object()).mapTaskPreset = mapTaskPresetData as MapTaskPreset[];
// //
closeModal(); closeModal();
emit('success'); emit('success');

36
src/views/common/mapLogistic/MapLogisticModal.vue

@ -17,21 +17,39 @@
*/ */
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal'; import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
import { AMapDesigner } from '/@/components/AMap'; import { AMapDesigner } from '/@/components/AMap';
import { getMapDataByCourierUserId } from '/@/api/platform/common/controller/mapLogistic';
import { reactive } from 'vue';
import { MapLogistic } from '/@/api/platform/common/entity/mapLogistic';
/** 类型规范统一声明定义区域 */
interface WindowState {
tag: string;
mapData: Nullable<MapLogistic>;
}
/** 通用变量统一声明区域 */ /** 通用变量统一声明区域 */
const state = reactive<WindowState>({
tag: '',
mapData: null
});
/** https://v3.cn.vuejs.org/api/options-data.html#emits */ /** https://v3.cn.vuejs.org/api/options-data.html#emits */
const emit = defineEmits(['success', 'register']); const emit = defineEmits(['success', 'register']);
const [registerModal, { setModalProps, closeModal }] = useModalInner(async data => { const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data: WindowInnerData = { _tag: '' }) => {
const mapId = data?.id; //
state.tag = data._tag;
const courierUserId = data.record?.courierUserId;
const props: Partial<ModalProps> = { confirmLoading: false, title: '地图设计器' }; const props: Partial<ModalProps> = { confirmLoading: false, title: '地图设计器' };
// tag
switch (state.tag) {
case 'add':
props.title = '新增科室';
break;
case 'edit':
props.title = '编辑科室';
state.mapData = await getMapDataByCourierUserId(courierUserId);
break;
}
// : // :
setModalProps(props); setModalProps(props);
}); });

Loading…
Cancel
Save