This commit is contained in:
weipengfei 2023-08-17 11:23:12 +08:00
parent df68af20ef
commit 1d888836aa
3 changed files with 136 additions and 9 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div id="container"></div> <div id="container" ref="map"></div>
</template> </template>
<script lang="ts" setup name="mapContainer"> <script lang="ts" setup name="mapContainer">
@ -10,22 +10,27 @@ const map = shallowRef(null);
const initMap = () => { const initMap = () => {
AMapLoader.load({ AMapLoader.load({
key: "", // WebKey load key: "4f8f55618010007147aab96fc72bb408", // WebKey load
version: "2.0", // JSAPI 1.4.15 version: "2.0", // JSAPI 1.4.15
plugins: [""], // 使'AMap.Scale' plugins: [""], // 使'AMap.Scale'
}) })
.then((AMap) => { .then((AMap) => {
map = new AMap.Map("container", { map.value = new AMap.Map("container", {
//id //id
viewMode: "2D", //3D viewMode: "2D", //3D
zoom: 5, // zoom: 10, //
center: [105.602725, 37.076636], // center: [105.602725, 37.076636], //
}); });
}) })
.catch((e) => { .catch((e) => {
console.log(e); console.log("地图错误", e);
ElMessage.error("未知错误");
}); });
}; };
onMounted(() => {
initMap();
});
</script> </script>
@ -33,7 +38,7 @@ const initMap = () => {
#container { #container {
padding: 0px; padding: 0px;
margin: 0px; margin: 0px;
width: 100%; width: 400px;
height: 800px; height: 400px;
} }
</style> </style>

View File

@ -119,6 +119,12 @@
/> />
</el-form-item> </el-form-item>
</el-form> </el-form>
<taskMap
v-if="mapShow"
ref="mapRef"
@success="setMap"
@close="mapShow = false"
></taskMap>
</popup> </popup>
</div> </div>
</template> </template>
@ -134,6 +140,7 @@ import {
import { timeFormat } from "@/utils/util"; import { timeFormat } from "@/utils/util";
import type { PropType } from "vue"; import type { PropType } from "vue";
import { dictDataLists } from "@/api/setting/dict"; import { dictDataLists } from "@/api/setting/dict";
import taskMap from "./map.vue";
defineProps({ defineProps({
dictData: { dictData: {
type: Object as PropType<Record<string, any[]>>, type: Object as PropType<Record<string, any[]>>,
@ -222,9 +229,22 @@ const getDetail = async (row: Record<string, any>) => {
setFormData(data); setFormData(data);
}; };
//
const mapShow = ref(false);
const mapRef = shallowRef<InstanceType<typeof taskMap>>();
// //
const changeTaskType = (e: any) => { const changeTaskType = async (e: any) => {
console.log(e); if (e == 32) {
mapShow.value = true; //
await nextTick();
console.log(mapRef.value);
mapRef.value?.open();
}
};
const setMap = (e: any) => {
console.log("选择了地图", e);
}; };
// //

View File

@ -0,0 +1,102 @@
<template>
<div class="edit-popup">
<popup
ref="popupRef"
title="选择地点"
:async="true"
width="550px"
@confirm="handleSubmit"
@close="handleClose"
>
<el-form>
<el-form-item label="">
<el-input style="width: 300px; margin-right: 16px" />
<el-button type="primary">搜索</el-button>
</el-form-item>
<el-form-item label="地图">
<MapContainer></MapContainer>
</el-form-item>
</el-form>
</popup>
</div>
</template>
<script lang="ts" setup name="taskTemplateEdit">
import type { FormInstance } from "element-plus";
import Popup from "@/components/popup/index.vue";
import {
apiTaskTemplateAdd,
apiTaskTemplateEdit,
apiTaskTemplateDetail,
} from "@/api/task_template";
import { timeFormat } from "@/utils/util";
import type { PropType } from "vue";
import { dictDataLists } from "@/api/setting/dict";
import MapContainer from "@/components/map/MapContainer.vue";
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
default: () => ({}),
},
});
const emit = defineEmits(["success", "close"]);
const formRef = shallowRef<FormInstance>();
const popupRef = shallowRef<InstanceType<typeof Popup>>();
const mode = ref("add");
const datalist = ref([]);
//
const setFormData = async (data: Record<any, any>) => {
for (const key in formData) {
if (data[key] != null && data[key] != undefined) {
//@ts-ignore
formData[key] = data[key];
}
}
};
const getDetail = async (row: Record<string, any>) => {
const data = await apiTaskTemplateDetail({
id: row.id,
});
setFormData(data);
};
//
const mapShow = ref(false);
const mapPopupRef = ref(null);
//
const changeTaskType = (e: any) => {
if (e == 32) {
mapShow.value = true; //
mapPopupRef.value.open();
}
};
//
const handleSubmit = async () => {
return console.log("ss");
popupRef.value?.close();
emit("success");
};
//
const open = (type = "add") => {
mode.value = type;
popupRef.value?.open();
};
//
const handleClose = () => {
emit("close");
};
defineExpose({
open,
setFormData,
getDetail,
});
</script>