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. 13
      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 { @@ -14,7 +14,7 @@ enum Api {
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 });

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

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

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

@ -12,28 +12,28 @@ import type { MapTaskPreset } from './mapTaskPreset'; @@ -12,28 +12,28 @@ import type { MapTaskPreset } from './mapTaskPreset';
export type MapTaskParams = Page & MapTask;
export interface MapTask extends CommonEntity {
id: string;
export interface MapTask extends Partial<CommonEntity> {
id?: string;
name: string;
sort: number;
sort?: number;
taskType: string;
hospitalId: string;
hospitalName: string;
hospitalLng: number;
hospitalLat: number;
orgId: string;
orgName: string;
orgLng: number;
orgLat: number;
courierUserId: string;
fileId: string;
estimateTime: string;
requireTime: string;
batchCode: string;
mapLogisticId: string;
key: string;
version: number;
mapTaskPreset: MapTaskPreset[]
hospitalName?: string;
hospitalLng?: number;
hospitalLat?: number;
orgId?: string;
orgName?: string;
orgLng?: number;
orgLat?: number;
courierUserId?: string;
fileId: string | string[];
estimateTime?: string;
requireTime?: string;
batchCode?: string;
mapLogisticId?: string;
key?: string;
version?: number;
mapTaskPreset?: MapTaskPreset[]
}
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'; @@ -11,27 +11,27 @@ import type { CommonEntity, Page } from '/@/api/common/data/entity';
export type MapTaskPresetParams = Page & MapTaskPreset;
export interface MapTaskPreset extends CommonEntity {
id: string;
export interface MapTaskPreset extends Partial<CommonEntity> {
id?: string;
name: string;
sort: number;
orginPresetId: string;
orginPresetName: string;
orginPresetLng: number;
orginPresetLat: number;
destinationPresetId: string;
destinationPresetName: string;
destinationPresetLng: number;
destinationPresetLat: number;
courierUserId: string;
key: string;
fileId: string;
estimateTime: string;
requireTime: string;
batchCode: string;
mapLogisticId: string;
taskId: string;
version: number;
sort?: number;
orginPresetId?: string;
orginPresetName?: string;
orginPresetLng?: number;
orginPresetLat?: number;
destinationPresetId?: string;
destinationPresetName?: string;
destinationPresetLng?: number;
destinationPresetLat?: number;
courierUserId?: string;
key?: string;
fileId: string | string[];
estimateTime?: string;
requireTime?: string;
batchCode?: string;
mapLogisticId?: string;
taskId?: string;
version?: number;
}
export type MapTaskPresetResult = R<MapTaskPreset[]>;

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

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

13
src/components/AMap/src/components/MapTaskModal.vue

@ -59,7 +59,7 @@ @@ -59,7 +59,7 @@
</template>
<script lang="ts" setup>
import { reactive, toRaw } from 'vue';
import {BasicModal, ModalProps, useModal, useModalInner} from '/@/components/Modal';
import { BasicModal, ModalProps, useModal, useModalInner } from '/@/components/Modal';
import { BasicTable, useTable, EditRecordRow, BasicColumn, ActionItem, TableAction } from '/@/components/Table';
import { MapPointType, taskOrdinaryColumns, taskPresetColumns } from '../amap.data';
import TaskPresetModal from './MapTaskPresetModal.vue';
@ -68,6 +68,7 @@ @@ -68,6 +68,7 @@
import { defaultMapData } from '/@/enums/amapEnum';
import { MapLogistic } from '/@/api/platform/common/entity/mapLogistic';
import { buildUUID } from '/@/utils/uuid';
import { MapTask } from '/@/api/platform/common/entity/mapTask';
/** 类型规范统一声明定义区域 */
type OptionsType = {
@ -96,8 +97,8 @@ @@ -96,8 +97,8 @@
const emit = defineEmits(['success', 'register']);
const [registerModal, { setModalProps, closeModal }] = useModalInner(async data => {
//
const { mapData, options } = data;
state.mapData = mapData;
const { mapData, options } = data;
state.mapData = mapData as MapLogistic;
state.options = options as OptionsType;
const props: Partial<ModalProps> = { confirmLoading: false };
props.title = '任务配置';
@ -230,7 +231,7 @@ @@ -230,7 +231,7 @@
orgId: '',
fileId: [],
key: buildUUID()
});
} as MapTask);
}
/** 处理普通任务删除 */
@ -253,7 +254,7 @@ @@ -253,7 +254,7 @@
orgName: '等待收样员设置!',
fileId: [],
key: buildUUID()
});
} as MapTask);
}
/** 处理交接任务删除 */
@ -404,7 +405,7 @@ @@ -404,7 +405,7 @@
});
taskOrdinaryData.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();
emit('success');

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

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

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

@ -17,21 +17,39 @@ @@ -17,21 +17,39 @@
*/
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
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 */
const emit = defineEmits(['success', 'register']);
const [registerModal, { setModalProps, closeModal }] = useModalInner(async data => {
const mapId = data?.id;
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data: WindowInnerData = { _tag: '' }) => {
//
state.tag = data._tag;
const courierUserId = data.record?.courierUserId;
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);
});

Loading…
Cancel
Save