| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- <template>
- <div class="page" @click="handleWholeClick">
- <div class="page-head flex items-center">
- <el-icon size="20"><ArrowLeft /></el-icon>
- <div class="head-opt flex-1 flex justify-between items-center">
- <div>
- <span>场景:</span>
- <el-tree-select
- v-model="selectedShopCode"
- :data="scenesTree"
- accordion
- :render-after-expand="false"
- :default-expand-all="true"
- :teleported="false"
- placeholder="请选择相关场景"
- @change="changeShop"
- />
- </div>
- <div class="flex">
- <!-- <el-button @click="mapEditor.toJson">tojson</el-button> -->
- <el-upload
- class="avatar-uploader flex justify-center items-center"
- action="/skyeye-admin-api/layout/uploadPicture"
- :show-file-list="false"
- :on-success="handleAvatarSuccess"
- :with-credentials="true"
- name="file"
- :data="{ workshopId: selectedShopDetail?.id }"
- >
- <el-button style="font-size: 12px" :icon="Refresh" :disabled="!hasBg">
- 替换照片
- </el-button>
- </el-upload>
- <el-button
- @click="handleSave"
- style="margin-left: 40px"
- type="primary"
- :disabled="!selectedShopCode"
- >保存为布局
- </el-button>
- </div>
- </div>
- </div>
- <div class="paint-tool flex">
- <div class="camera-list">
- <div>
- <span class="label-text flex">相机列表:</span>
- <ElInput
- class="search-put"
- style="margin: 10px 0; width: 230px"
- placeholder="请输入搜索内容"
- v-model="searchKey"
- :suffix-icon="Search"
- />
- </div>
- <span v-if="filterShopCameraList.length == 0" class="ml-1" style="color: #3f3f3f">
- 提示:请先选择相应场景和图片
- </span>
- <el-scrollbar v-else style="position: relative; height: calc(100% - 90px)">
- <div
- v-for="item in filterShopCameraList"
- :key="item.code"
- class="camera-item flex justify-start items-center"
- :class="{
- isAdded: isAddedCamera(item.code),
- isActive: item.code === activeCameraId,
- }"
- @click="handleAddCamera(item.code)"
- >
- <span class="camera-id">{{ item.name }}</span>
- <el-popover
- placement="bottom-start"
- trigger="hover"
- :content="item.name"
- :teleported="false"
- >
- <template #reference>
- <span class="space-name">{{ item.workSpaceName }}</span>
- </template>
- </el-popover>
- </div>
- </el-scrollbar>
- </div>
- <div ref="drawContainer" id="drawContainer" class="draw-container">
- <div id="editContainer" v-moveable:1></div>
- <el-upload
- v-if="!hasBg"
- class="upload-icon flex justify-center items-center"
- action="/skyeye-admin-api/layout/uploadPicture"
- :show-file-list="false"
- :before-upload="handleBeforeUpload"
- :on-success="handleAvatarSuccess"
- :with-credentials="true"
- name="file"
- :data="{ workshopId: selectedShopDetail?.id }"
- >
- <img src="~@/assets/images/img-upload.png" />
- </el-upload>
- </div>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import useMiniMap from './use-mini-map';
- import { storeToRefs } from 'pinia';
- import { ElMessage, ElInput } from 'element-plus';
- import { onMounted, ref } from 'vue';
- import { updateMinMapViewLayoutApi } from '@/api/scene/scene';
- import { computed } from 'vue';
- import { Search, Refresh } from '@element-plus/icons-vue';
- import useMapEditor from './hooks/useMapEditor';
- const mapEditor = useMapEditor();
- const { activeCameraId, addedCameras, bgImgUrl } = mapEditor;
- const miniMap = useMiniMap();
- const { scenesTree, shopCameraList, selectedShopCode, selectedShopDetail } = storeToRefs(miniMap);
- const { getScenesTree, getShowCameras, getMapLayout } = miniMap;
- const drawContainer = ref<HTMLDivElement>();
- const searchKey = ref('');
- // 是否已有背景图
- const hasBg = ref(false);
- const handleBeforeUpload = () => {
- if (!selectedShopCode.value) {
- ElMessage.error({
- message: '请先选择车间',
- });
- return false;
- }
- };
- /** 判断相机是否已经添加 */
- const isAddedCamera = (cameraId: string) => {
- const index = addedCameras.value.findIndex((item) => item === cameraId);
- return index >= 0;
- };
- const handleAvatarSuccess = (e) => {
- bgImgUrl.value = e.data;
- mapEditor.addBg();
- hasBg.value = true;
- };
- const changeShop = (code: string) => {
- mapEditor.resetMap();
- getShopContent(code);
- hasBg.value = false;
- };
- const getShopContent = (code: string) => {
- getShowCameras(code);
- getMapLayout(code).then((res) => {
- if (!res) {
- return;
- }
- hasBg.value = true;
- mapEditor.createMap(res);
- });
- };
- const handleWholeClick = (e) => {
- if (e.button === 0) {
- mapEditor.destoryOptBlock();
- }
- };
- onMounted(() => {
- getScenesTree({ level: 2, valueKey: 'code', labelKey: 'name', disabled: true });
- mapEditor.initContainer({
- container: 'editContainer',
- width: drawContainer.value!.clientWidth,
- height: drawContainer.value!.clientHeight,
- });
- if (selectedShopCode.value) {
- getShopContent(selectedShopCode.value);
- }
- });
- const filterShopCameraList = computed(() => {
- const k = searchKey.value.trim();
- if (!k) return shopCameraList.value;
- return shopCameraList.value.filter((x) => x.code?.includes(k) || x.workSpaceName?.includes(k));
- });
- const handleAddCamera = (cameraId: string) => {
- if (!hasBg.value) {
- ElMessage.warning({
- message: '请先添加背景图片',
- });
- return;
- }
- mapEditor.addCamera(cameraId);
- };
- const handleSave = () => {
- const layout = mapEditor.toJson();
- updateMinMapViewLayoutApi({ layout, targetId: String(selectedShopDetail.value?.id) }).then(
- (res) => {
- console.log('updateMinMapViewLayoutApi', res);
- ElMessage.success('保存成功');
- },
- );
- };
- </script>
- <style scoped lang="scss">
- .page {
- }
- .page-head {
- height: 54px;
- padding-left: 15px;
- background-color: #ffffff;
- }
- .head-opt {
- margin-left: 20px;
- padding-right: 15px;
- font-size: 14px;
- color: #3f3f3f;
- }
- .avatar-uploader {
- /* width: 120px; */
- /* height: 30px; */
- /* border: 1px solid #eee; */
- border-radius: 4px;
- margin-left: 30px;
- }
- .upload-icon {
- position: absolute;
- top: 0;
- right: 0;
- left: 0;
- bottom: 0;
- margin: auto;
- }
- .paint-tool {
- position: relative;
- height: calc(100vh - 138px);
- margin-top: 2px;
- }
- .camera-list {
- width: 250px;
- padding: 0 10px;
- background-color: #ffffff;
- }
- .label-text {
- font-size: 14px;
- font-weight: 600;
- margin: 10px 0 5px 10px;
- }
- .camera-item {
- height: 32px;
- font-size: 14px;
- padding-left: 8px;
- font-weight: 400;
- color: #404040;
- line-height: 14px;
- cursor: pointer;
- &:hover {
- background-color: #e6f7ff;
- color: #1890ff;
- }
- }
- .isAdded {
- color: #1890ff;
- cursor: not-allowed;
- }
- .isActive {
- background-color: #e6f7ff;
- color: #1890ff;
- }
- .camera-item-disabled {
- color: #c6c6c6;
- }
- .camera-id {
- width: 110px;
- }
- .space-name {
- width: 120px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- .draw-container {
- position: relative;
- width: calc(100% - 300px);
- margin: 20px;
- overflow: hidden;
- }
- :deep(.search-put .el-input__wrapper) {
- background-color: #f0f2f5;
- }
- :deep(.el-popper__arrow) {
- display: none;
- }
- :deep(.el-tree-node__content:hover) {
- background: #e6f4ff;
- }
- :deep(.el-button--primary) {
- --el-button-disabled-bg-color: #bfbfbf;
- }
- :deep(.el-popover) {
- width: unset !important;
- min-width: 110px;
- text-align: center;
- font-weight: 400;
- }
- </style>
- ./MapBase/useCameraMap ./MapBase/CameraMapBak
|