You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/drawer-htmlroot/components/WellGroupEditDialog.vue

188 lines
4.7 KiB
Vue

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<!-- <teleport to="body"> -->
<el-dialog v-model="visible" class="frame" title="井组编辑" @close="close" :close-on-click-modal="false" :width="1000"
:modal="true" :style="{ height: '650px' }" :destroy-on-close="true">
<div class="canvas-render">
<WellRecommend ref="wrRef" :tokenKey="currentTokenKey" :showRight="false" />
</div>
<template #footer>
<div class="oper">
<el-button type="primary" :icon="Select" @click="handleConfirm"></el-button>
</div>
</template>
</el-dialog>
<!-- </teleport> -->
</template>
<script setup>
import { Select } from "@element-plus/icons-vue";
import { STORAGE_KEYS } from '~/utils/storageKeys';
import { emitter } from "~/utils/eventBus";
import { EMIT_COMMAND } from "~/utils/commandTypes";
import { LRUCache } from 'lru-cache';
import { useWebSocket } from '@/composables/useWebSocket'
const { messages, onMessage, send } = useWebSocket();
// 当前页图件token的 key
const currentTokenKey = STORAGE_KEYS.WELL_GROUP_EDIT_TOKEN;
const parentTokenKey = STORAGE_KEYS.WELL_RECOMMAND_TOKEN;
// const cmdid = 'wellgroupedit_cmd';
const EXPIRE_TIME = 5 * 60 * 1000;// 5 分钟
const cache = new LRUCache({
max: 1000, // 最多 1000 个条目
ttl: EXPIRE_TIME // 5 分钟过期
});
const wrRef = ref(null);
const props = defineProps({
modelValue: {
type: Boolean,
default: false
},
parentToken: {
type: String,
default: ''
},
wellGroupData: {
type: Object
}
})
const groupData = computed(() => props.wellGroupData)
const emit = defineEmits(['update:modelValue']);
const unsubscribe = onMessage((data) => {
try {
if (!data) return; // 如果没有新消息,直接返回
const json = JSON.parse(data);
// console.log("Edit 判断:", json.cmdID, currentTokenKey);
if (json.cmdID && json.cmdID !== currentTokenKey) {
return;
}
const evtType = json.type;
const msgId = `${evtType}-${json.dateTime}`;
if (cache.has(msgId)) {
return;
}
cache.set(msgId, true);
switch (evtType) {
case COMMAND.NEW_TOKEN:
localStorage.setItem(currentTokenKey, json.drawerToken);
console.log("收到编辑井组回应 NEW_TOKEN", json);
break;
case COMMAND.REDRAW:
console.log("收到编辑井组回应 REDRAW:", json);
// emitter.emit(EMIT_COMMAND.EDIT_REDRAW, json);
break;
}
} finally {
}
});
// 状态
const visible = ref(props.modelValue)
// 监听 v-model
watch(() => props.modelValue, (val) => {
visible.value = val;
if (visible.value) {
nextTick(() => {
sendCommand();
});
}
})
// onMounted(() => {
// sendCommand();
// });
const sendCommand = () => {
console.log("父token", props.parentToken, "\r\n井组数据", groupData.value)
const rect = wrRef.value.getCanvasSize();
console.log("rect:", rect.width, rect.height);
const token = generateGUID();
const obj = { parentToken: props.parentToken, data: groupData.value.ElementData, token: token, width: rect.width, height: rect.height };
console.log("发送编辑井组命令:", COMMAND.EDIT_WELL_GROUP, obj);
send(COMMAND.EDIT_WELL_GROUP, obj, token, currentTokenKey)
}
// 控制显隐
function close() {
visible.value = false
unsubscribe();
emit('update:modelValue', false)
}
const handleConfirm = () => {
const token = localStorage.getItem(currentTokenKey);
send(COMMAND.SAVE_FILE, {}, token, parentTokenKey);
close();
}
onMounted(() => {
nextTick();
});
onUnmounted(() => {
unsubscribe();
});
</script>
<style scoped>
/* 设置 dialog 整体尺寸 */
:deep(.frame .el-dialog) {
width: 1000px !important;
height: 700px;
/* margin-top: 100px; */
display: flex;
flex-direction: column;
}
/* Header 保持默认高度 */
:deep(.frame .el-dialog__header) {
flex: 0 0 auto;
/* padding: 10px 20px; */
border-bottom: 1px solid #eee;
}
.canvas-render {
flex: 1;
width: 100%;
height: 100%;
overflow: hidden;
padding: 0;
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 4px;
}
/* Footer 固定高度 */
:deep(.frame .el-dialog__footer) {
flex: 0 0 30px;
display: flex;
align-items: center;
justify-content: flex-end;
padding: 0 10px;
background-color: #f5f5f5;
border-top: 1px solid #ddd;
}
.oper {
display: flex;
justify-content: flex-end;
/* margin-top: 10px; */
margin-right: 10px;
/* margin-bottom: 0; */
}
</style>