|
@@ -0,0 +1,308 @@
|
|
|
+<template>
|
|
|
+ <div class="page-container">
|
|
|
+ <el-card class="box-card">
|
|
|
+ <template #header>
|
|
|
+ <div class="card-header">
|
|
|
+ <span>系统井</span>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ <el-tree
|
|
|
+ :load="loadMyDefTree"
|
|
|
+ lazy
|
|
|
+ :highlight-current="true"
|
|
|
+ :props="sysTreeProps"
|
|
|
+ ref="myDefTreeRef"
|
|
|
+ class="tree"
|
|
|
+ node-key="id">
|
|
|
+ <template #default="{ node, data }">
|
|
|
+ <span :id="data.id" :draggable="data.nodeType=='well'" @dragstart="sysDragStartHandle">{{ node.label }}</span>
|
|
|
+
|
|
|
+ </template>
|
|
|
+ </el-tree>
|
|
|
+ </el-card>
|
|
|
+ <el-card class="box-card">
|
|
|
+ <template #header>
|
|
|
+ <div class="card-header">
|
|
|
+ <span>
|
|
|
+ <span @click="showNodes" style="margin-right: 10px;">自选井</span>
|
|
|
+ <el-button type="primary" icon="plus" size="small"/>
|
|
|
+ </span>
|
|
|
+
|
|
|
+ <el-button type="primary" plain size="small" :loading="isSaving" @click="saveCustomTree">保存</el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ <el-tree
|
|
|
+ :data="customTreeData"
|
|
|
+ :highlight-current="true"
|
|
|
+ :props="customTreeProps"
|
|
|
+ ref="customTreeRef"
|
|
|
+ class="custom-tree"
|
|
|
+ draggable
|
|
|
+ :default-expand-all="true"
|
|
|
+ node-key="nodeId"
|
|
|
+ >
|
|
|
+ <template #default="{ node, data }">
|
|
|
+ <span class="custom-tree-node" :class="{'dropping-node':dropId==data.nodeId}" :id="data.nodeId" @dragenter="customDragEnter" @drop="customDropHandle" @dragover="customDragOverHandle">
|
|
|
+ <el-input v-model="data.nodeName" v-if="data.editing" @blur="data.editing=false"/>
|
|
|
+ <span v-else>{{ node.label }}</span>
|
|
|
+ <span>
|
|
|
+ <el-icon :size="20" title="上移" @click="sortNode(data.nodeId,true)"><SortUp/></el-icon>
|
|
|
+ <el-icon :size="20" title="下移" @click="sortNode(data.nodeId,false)"><SortDown/></el-icon>
|
|
|
+ <el-icon :size="20" title="重命名" style="margin: 0px 5px;" @click="data.editing=!data.editing" v-if="data.nodeType!='well'"><Edit/></el-icon>
|
|
|
+ <el-icon :size="20" title="删除" @click="delNodeFront(data.nodeId)"><CloseBold/></el-icon>
|
|
|
+ </span>
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+ </el-tree>
|
|
|
+ </el-card>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+ import {reactive,ref,toRaw,onMounted,nextTick} from 'vue'
|
|
|
+ import {ElMessageBox,ElMessage} from 'element-plus'
|
|
|
+
|
|
|
+ import customWellAPI from '@/api/customWell.js'
|
|
|
+ import stationAPI from '@/api/station.js'
|
|
|
+ import utils from '../../utils/utils.js'
|
|
|
+
|
|
|
+ const isSaving=ref(false)
|
|
|
+
|
|
|
+ const myDefTreeRef=ref(null)
|
|
|
+
|
|
|
+ const customTreeRef=ref(null)
|
|
|
+
|
|
|
+ const sysTreeData=ref([])
|
|
|
+
|
|
|
+ const customTreeData=ref([])
|
|
|
+
|
|
|
+ const sysTreeProps = {
|
|
|
+ children: 'children',
|
|
|
+ label: 'name',
|
|
|
+ isLeaf:'isLeaf'
|
|
|
+ }
|
|
|
+
|
|
|
+ const customTreeProps = {
|
|
|
+ children: 'children',
|
|
|
+ label: 'nodeName',
|
|
|
+ isLeaf:'isLeaf'
|
|
|
+ }
|
|
|
+
|
|
|
+ const dropId=ref('')
|
|
|
+
|
|
|
+ const customDragEnter=(ev)=>{
|
|
|
+ let inId=ev.target.id
|
|
|
+ dropId.value=inId
|
|
|
+ }
|
|
|
+
|
|
|
+ const sysDragStartHandle=(ev)=>{
|
|
|
+ ev.dataTransfer.dropEffect="copy"
|
|
|
+ ev.dataTransfer.setData("text/plain",ev.target.id)
|
|
|
+ }
|
|
|
+
|
|
|
+ const customDragOverHandle=(ev)=>{
|
|
|
+ ev.preventDefault()
|
|
|
+ ev.dataTransfer.dropEffect="link"
|
|
|
+ }
|
|
|
+
|
|
|
+ const customDropHandle=(ev)=>{
|
|
|
+ ev.preventDefault()
|
|
|
+ let outId=ev.dataTransfer.getData("text/plain");
|
|
|
+ let inId=ev.target.id
|
|
|
+ let hadNode=customTreeRef.value.getNode(outId)
|
|
|
+ if(hadNode){
|
|
|
+ ElMessage.error('该井已添加过')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let inNode=customTreeRef.value.getNode(inId)
|
|
|
+ if(inNode.data.nodeType=='well'){
|
|
|
+ ElMessage.error('非目录节点')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 获取拖拽节点
|
|
|
+ let outNode=myDefTreeRef.value.getNode(outId)
|
|
|
+ outNode.data['nodeName']=outNode.data['name']
|
|
|
+ outNode.data['nodeId']=outNode.data['id']
|
|
|
+ customTreeRef.value.append(outNode.data,inId)
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ const sortNode=(nodeId,isup)=>{
|
|
|
+ let crtNode=customTreeRef.value.getNode(nodeId)
|
|
|
+ let sibNodes=crtNode.parent.childNodes
|
|
|
+ let idx=null
|
|
|
+ sibNodes.forEach((node,index)=>{
|
|
|
+ if(node.data.nodeId==nodeId){
|
|
|
+ idx=index
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ if(isup&&(idx-1)>=0){
|
|
|
+ customTreeRef.value.remove(crtNode)
|
|
|
+ customTreeRef.value.insertBefore(crtNode.data,sibNodes[idx-1])
|
|
|
+ }
|
|
|
+ else if(!isup&&(idx+1)<sibNodes.length){
|
|
|
+ customTreeRef.value.remove(crtNode)
|
|
|
+ customTreeRef.value.insertAfter(crtNode.data,sibNodes[idx+1])
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ const delNodeFront=(id)=>{
|
|
|
+ customTreeRef.value.remove(customTreeRef.value.getNode(id))
|
|
|
+ }
|
|
|
+
|
|
|
+ let rootNode=null
|
|
|
+
|
|
|
+ const loadMyDefTree=(node,resolve)=>{
|
|
|
+
|
|
|
+ let srcNode=node&&node.data?toRaw(node.data):{}
|
|
|
+ let {id,nodeType,typeEnd}=srcNode
|
|
|
+ stationAPI.loadSubNodes({id,nodeType,typeEnd}).then((resp) => {
|
|
|
+ if(resp.code===0&&resp.data){
|
|
|
+ resolve(resp.data)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const loadCustomTree=()=>{
|
|
|
+ let converDef={id:'nodeId',name:'nodeName',superId:'superId',superName:'superName',children:'children'}
|
|
|
+ customWellAPI.loadCustomTree().then(resp=>{
|
|
|
+ if(resp.code===0){
|
|
|
+ let treeDatas=utils.list2Tree(resp.data||[],converDef)
|
|
|
+ customTreeData.value=treeDatas['topNodes']
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ console.log(resp.msg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const addCustomFold=()=>{
|
|
|
+ ElMessageBox.prompt('请输入自定义节点名称(如:重点井)', '新建自定义节点', {
|
|
|
+ confirmButtonText:'确定',
|
|
|
+ cancelButtonText:'取消',
|
|
|
+ inputPattern:/\S{1,32}/,
|
|
|
+ inputErrorMessage:'自定义节点名称应为1-32字符'
|
|
|
+ }).then(({value})=>{
|
|
|
+
|
|
|
+ customTreeRef.value.append({
|
|
|
+ nodeId:'1111',
|
|
|
+ nodeName:value,
|
|
|
+ children:[]
|
|
|
+ },null)
|
|
|
+
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const saveCustomTree=()=>{
|
|
|
+ isSaving.value=true
|
|
|
+ let saveDatas=[...customTreeData.value]
|
|
|
+ processSaveNodes(saveDatas)
|
|
|
+ //console.log(saveDatas)
|
|
|
+ customWellAPI.saveCustom(saveDatas).then(resp=>{
|
|
|
+ isSaving.value=false
|
|
|
+ if(resp.code!=0){
|
|
|
+ ElMessage.error(resp.msg||'保存失败')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ElMessage.success('保存成功')
|
|
|
+ loadCustomTree()
|
|
|
+ }).catch(err=>{
|
|
|
+ isSaving.value=false
|
|
|
+ ElMessage.error('保存出错')
|
|
|
+ console.log(err)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const processSaveNodes=(datas)=>{
|
|
|
+ let childNodes=[]
|
|
|
+ datas.forEach(data=>{
|
|
|
+ if(data.children&&data.children.length>0){
|
|
|
+ data.children.forEach(child=>{
|
|
|
+ if(child.nodeType=='well'){
|
|
|
+ childNodes.push({wellId:child.id,superId:data.nodeId}) //由左侧拖入的井节点
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ childNodes.push(child) //本身就存在的子节点
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ delete data.children
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ datas.splice(0,0,...childNodes)
|
|
|
+ }
|
|
|
+
|
|
|
+ onMounted(()=>{
|
|
|
+ loadCustomTree()
|
|
|
+ })
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+ .page-container{
|
|
|
+ width:100%;
|
|
|
+ height: 100%;
|
|
|
+ padding:20px 10px;
|
|
|
+ box-sizing: border-box;
|
|
|
+ display: grid;
|
|
|
+ grid-template-columns: 50% 50%;
|
|
|
+ grid-column-gap: 10px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .page-container:deep(.el-card__body){
|
|
|
+ height: calc(100% - 100px);
|
|
|
+ overflow-y: auto;
|
|
|
+ }
|
|
|
+
|
|
|
+ .card-header{
|
|
|
+ height: 25px;
|
|
|
+ display: flex;
|
|
|
+ flex-flow: row nowrap;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+ }
|
|
|
+
|
|
|
+ .custom-tree:deep(.el-tree-node__content){
|
|
|
+ height: 35px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .custom-tree-node{
|
|
|
+ display: flex;
|
|
|
+ flex-flow: row nowrap;
|
|
|
+ justify-content: space-between;
|
|
|
+ flex:1;
|
|
|
+ align-items: center;
|
|
|
+ /* background-color: #f8f8f8; */
|
|
|
+ height: 30px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .dropping-node{
|
|
|
+ background-color: #d0dbfa;
|
|
|
+ }
|
|
|
+
|
|
|
+ .custom-tree-node span{
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ .custom-tree-node span+span{
|
|
|
+ display: none;
|
|
|
+ }
|
|
|
+
|
|
|
+ .custom-tree-node:hover span+span{
|
|
|
+ display: inline;
|
|
|
+ }
|
|
|
+
|
|
|
+ .custom-tree-node .el-input{
|
|
|
+ /* width:200px; */
|
|
|
+ height:28px;
|
|
|
+ }
|
|
|
+</style>
|