Эх сурвалжийг харах

新增自定义节点接口调用

duy 1 жил өмнө
parent
commit
878fcee409

+ 16 - 0
src/api/modules/data-fill/wbs.js

@@ -97,6 +97,14 @@ export default {
             params: form,
         }, msg)
     },
+    //新增自定义节点项目全加载树
+    async queryPriateTree(form, msg = true) {
+        return httpApi({
+            url: '/apiblade-user/wbs/private/tree',
+            method: 'get',
+            params: form,
+        }, msg)
+    },
     //新增节点及其子节点
     async saveContractTreeNode(form, msg = true) {
         return httpApi({
@@ -105,6 +113,14 @@ export default {
             data: form,
         }, msg)
     },
+    //新增自定义节点
+    async saveCustomAddContractNode(form, msg = true) {
+        return httpApi({
+            url: '/api/blade-business/informationWriteQuery/customAddContractNode',
+            method: 'post',
+            data: form,
+        }, msg)
+    },
     //复制节点
     async copyContractTreeNode(form, msg = true) {
         return httpApi({

+ 82 - 51
src/views/data-fill/components/HcTreeNode.vue

@@ -1,19 +1,20 @@
 <template>
     <div v-loading="isElTreeLoadNode">
-        <HcDataTree ref="ElTreeRef"
-                    :hProps="ElTreeProps"
-                    :datas="ElTreeData"
-                    :check-strictly="isStrictly"
-                    show-checkbox
-                    @check="ElTreeCheckChange"
+        <HcDataTree
+            ref="ElTreeRef"
+            :h-props="ElTreeProps"
+            :datas="ElTreeData"
+            :check-strictly="isStrictly"
+            show-checkbox
+            @check="ElTreeCheckChange"
         >
-            <template #default="{node, data}">
+            <template #default="{ node, data }">
                 <div class="custom-tree-node">
                     <div class="label" @dblclick="ElTreeDblClick(data)">
-                        <el-input v-if="data.isInputName" v-model="data.nodeName" size="small" @blur="ElTreeBtnClick(data)" @keyup="keyUpEvent($event,data)">
+                        <el-input v-if="data.isInputName" v-model="data.nodeName" size="small" @blur="ElTreeBtnClick(data)" @keyup="keyUpEvent($event, data)">
                             <template #append>
                                 <el-button plain size="small" type="primary" @click="ElTreeBtnClick(data)">
-                                    <HcIcon name="check"/>
+                                    <HcIcon name="check" />
                                 </el-button>
                             </template>
                         </el-input>
@@ -26,66 +27,75 @@
 </template>
 
 <script setup>
-import {nextTick, onMounted, ref, watch} from "vue";
-import {getArrValue} from "js-fast-way"
-import wbsApi from '~api/data-fill/wbs';
+import { nextTick, onActivated, onMounted, ref, watch } from 'vue'
+import { getArrValue } from 'js-fast-way'
+import wbsApi from '~api/data-fill/wbs'
 
 //参数
 const props = defineProps({
     projectId: {
         type: [String, Number],
-        default: ''
+        default: '',
     },
     contractId:{
         type: [String, Number],
-        default: ''
+        default: '',
     },
     nodeKey: {
         type: String,
-        default: 'primaryKeyId'
+        default: 'primaryKeyId',
     },
     nodeId: {
         type: [String, Number],
-        default: ''
+        default: '',
     },
     oldId: {
         type: [String, Number],
-        default: ''
+        default: '',
     },
     strictly: {
         type: Boolean,
-        default: false
+        default: false,
     },
     wbsId:{
         type: [String, Number],
-        default: ''
-    }
+        default: '',
+    },
+    isCustom:{
+        type: [String, Number],
+        default: '',
+    },
 })
 
+//事件
+const emit = defineEmits(['check-change'])
 //变量
 const ElTreeRef = ref(null)
 const projectId = ref(props.projectId)
 const contractId = ref(props.contractId)
 const isStrictly = ref(props.strictly)
-const wbsId=ref(props.wbsId)
+const wbsId = ref(props.wbsId)
+const isCustom = ref(props.isCustom)
 const ElTreeProps = ref({
     label: 'nodeName',
     children: 'children',
-    isLeaf: 'notExsitChild'
+    isLeaf: 'notExsitChild',
 })
-const  isElTreeLoadNode = ref(false)
+const isElTreeLoadNode = ref(false)
 
 //监听
 watch(() => [
     props.projectId,
     props.strictly,
     props.contractId,
-    props.wbsId
-], ([pid, strictly,cid,wid]) => {
+    props.wbsId,
+    props.isCustom,
+], ([pid, strictly, cid, wid, cus]) => {
     projectId.value = pid
     contractId.value = cid
     isStrictly.value = strictly
-    wbsId.value=wid
+    wbsId.value = wid
+    isCustom.value = cus
 
 })
 
@@ -94,33 +104,54 @@ onMounted(() => {
     ElTreeLoadNode()
 })
 
-//事件
-const emit = defineEmits(['check-change'])
-
 //树形结构异步加载数据
 const ElTreeData = ref([])
 const ElTreeLoadNode = async () => {
-    isElTreeLoadNode.value=true
-    let nodeId = props.nodeId || ''
-    const {error, code, data} = await wbsApi.queryWbsTreeContractByContractIdAndId({
-        pKeyId: nodeId,
-        contractId: contractId.value,
-        projectId: projectId.value,
-    })
-    if (!error && code === 200) {
-        isElTreeLoadNode.value=false
-        ElTreeData.value = getArrValue(data)
-        ElTreeData.value.forEach((ele,index)=>{
-            if (index==0) {
-                ele.isPeer=1
-            }
+    if (isCustom.value === 1) {
+        isElTreeLoadNode.value = true
+        let nodeId = props.nodeId || ''
+        const { error, code, data } = await wbsApi.queryPriateTree({
+            pKeyId: nodeId,
+            contractId: contractId.value,
+            projectId: projectId.value,
         })
-    
-        await nextTick(() => {
-            ElTreeCheckedKeys()
+        if (!error && code === 200) {
+            isElTreeLoadNode.value = false
+            ElTreeData.value = getArrValue(data)
+            ElTreeData.value.forEach((ele, index)=>{
+                if (index == 0) {
+                    ele.isPeer = 1
+                }
+            })
+        
+            await nextTick(() => {
+                ElTreeCheckedKeys()
+            })
+        }
+        isElTreeLoadNode.value = false
+    } else {
+        isElTreeLoadNode.value = true
+        let nodeId = props.nodeId || ''
+        const { error, code, data } = await wbsApi.queryWbsTreeContractByContractIdAndId({
+            pKeyId: nodeId,
+            contractId: contractId.value,
+            projectId: projectId.value,
         })
+        if (!error && code === 200) {
+            isElTreeLoadNode.value = false
+            ElTreeData.value = getArrValue(data)
+            ElTreeData.value.forEach((ele, index)=>{
+                if (index == 0) {
+                    ele.isPeer = 1
+                }
+            })
+        
+            await nextTick(() => {
+                ElTreeCheckedKeys()
+            })
+        }
+        isElTreeLoadNode.value = false
     }
-    isElTreeLoadNode.value=false
 }
 
 //被选择的
@@ -134,17 +165,17 @@ const ElTreeCheckedKeys = () => {
     const HalfNodes = ElTreeRef.value?.treeRef?.getHalfCheckedNodes() || []
     emit('check-change', {
         checkedNodes: Nodes,
-        halfCheckedNodes: HalfNodes
+        halfCheckedNodes: HalfNodes,
     })
 }
 
 //更改节点名称
 const ElTreeDblClick = (item) => {
-    item.isInputName = true;
+    item.isInputName = true
 }
 //回车
 const keyUpEvent = (e, item) => {
-    if (e.key === "Enter") {
+    if (e.key === 'Enter') {
         ElTreeBtnClick(item)
     }
 }
@@ -153,7 +184,7 @@ const ElTreeBtnClick = (item) => {
     if (!item?.nodeName) {
         window?.$message?.warning('节点名称不能为空')
     } else {
-        item.isInputName = false;
+        item.isInputName = false
         ElTreeCheckedKeys()
     }
 }

+ 62 - 19
src/views/data-fill/wbs.vue

@@ -396,6 +396,7 @@
                 :contract-id="contractId"
                 :wbs-id="projectInfo.referenceWbsTemplateId"
                 :project-id="projectId"
+                :is-custom="isCustom"
                 @check-change="addTreeNodeCheckChange"
             />
             <HcTreeNode
@@ -405,7 +406,8 @@
                 :contract-id="contractId"
                 :wbs-id="projectInfo.referenceWbsTemplateId"
                 :project-id="projectId"
-                strictly @check-change="addTreeNodeCheckChange"
+                strictly :is-custom="isCustom"
+                @check-change="addTreeNodeCheckChange"
             />
             <template #footer>
                 <div class="lr-dialog-footer">
@@ -424,6 +426,12 @@
             </template>
         </hc-new-dialog>
 
+        <!-- 新增自定义节点 -->
+        <hc-new-dialog v-model="addNodeModalCus" :loading="addNodeLoadingCus" loading-text="新增节点中,请耐心等待..." title="新增自定义节点" widths="720px" @save="addNodeClickCur">
+            <div>节点名称:</div>
+            <el-input v-model="nodeNameinput" placeholder="请输入节点名称" size="large" style="margin-top: 15px;" />
+        </hc-new-dialog>
+
         <!-- 调整排序 -->
         <hc-new-dialog v-model="sortNodeModal" :loading="sortNodeLoading" title="调整排序" widths="700px" @save="sortNodeClick">
             <el-alert :closable="false" title="可拖动排序,也可在后面点击图标,切换排序" type="warning" />
@@ -762,6 +770,8 @@ const TreeMark = ref(false)
 const setElTreeMenu = (contractType) => {
     let newArr = []
     if (contractType === 1) {
+        //新增自定义节点功能
+        newArr.push({ icon: 'add-circle', label: '新增自定义节点', key: 'add1' })
         if (HcIsButton('wbs_tree_add')) {
             newArr.push({ icon: 'add-circle', label: '新增节点', key: 'add' })
         }
@@ -788,6 +798,8 @@ const setElTreeMenu = (contractType) => {
             newArr.push({ icon: 'folder-shared', label: '工程划分', key: 'nodetree' })
         }
     } else if (contractType === 2) {
+          //新增自定义节点功能
+          newArr.push({ icon: 'add-circle', label: '新增自定义节点', key: 'add1' })
         if (HcIsButton('wbs_tree_add')) {
             newArr.push({ icon: 'add-circle', label: '新增节点', key: 'add' })
         }
@@ -976,11 +988,19 @@ const setTreeMenuDataClick = ({ key, node, data }) => {
         copyNodeLoading.value = false
         copyNodeModal.value = true
     } else if (key === 'add') {
-        console.log(data, 'data')
+        isCustomAdd.value = false
+        isCustom.value = data?.isCustom 
         addTreeNodeId.value = data?.primaryKeyId
         addTreeNodeOldId.value = data?.oldId
         addNodeLoading.value = false
         addNodeModal.value = true
+    } else if (key === 'add1') {
+        isCustomAdd.value = true
+        addTreeNodeId.value = data?.primaryKeyId
+        addTreeNodeOldId.value = data?.oldId
+        addNodeLoading.value = false
+        nodeNameinput.value = ''
+        addNodeModalCus.value = true
     } else if (key === 'upload') {
         const info = nodeDataInfo.value
         //上传的配置
@@ -1366,7 +1386,13 @@ const addNodeModal = ref(false)
 const addTreeNodeId = ref('')
 const addTreeNodeOldId = ref('')
 const addTreeNodeType = ref('1')
+const isCustom = ref(null)
+const isCustomAdd = ref(false)
 
+//新增自定义节点
+const addNodeModalCus = ref(false)
+const addNodeLoadingCus = ref(false)
+const nodeNameinput = ref('')
 //选中的节点
 const allSelectedList = ref([])
 const halfSelectedList = ref([])
@@ -1404,25 +1430,42 @@ const addNodeClick = async () => {
     if (keys.length <= 0) {
         window?.$message?.warning('请先选择节点')
     } else {
-        //发起请求
-        addNodeLoading.value = true
-        const primaryKeyId = nodeDataInfo.value?.primaryKeyId || ''
-        const { error, code } = await wbsApi.saveContractTreeNode({
-            projectId: projectId.value,
-            contractId: contractId.value,
-            saveType: addTreeNodeType.value,
-            allSelectedList: allSelectedList.value,
-            halfSelectedList: halfSelectedList.value,
-            currentNodePrimaryKeyId: primaryKeyId,
-        })
-        //判断状态
-        addNodeLoading.value = false
-        if (!error && code === 200) {
-            window?.$message?.success('新增成功')
-            addNodeModal.value = false
-            window?.location?.reload() //刷新页面
+         //发起请求
+         addNodeLoading.value = true
+            const primaryKeyId = nodeDataInfo.value?.primaryKeyId || ''
+            const { error, code } = await wbsApi.saveContractTreeNode({
+                projectId: projectId.value,
+                contractId: contractId.value,
+                saveType: addTreeNodeType.value,
+                allSelectedList: allSelectedList.value,
+                halfSelectedList: halfSelectedList.value,
+                currentNodePrimaryKeyId: primaryKeyId,
+            })
+            //判断状态
+            addNodeLoading.value = false
+            if (!error && code === 200) {
+                window?.$message?.success('新增成功')
+                addNodeModal.value = false
+                // window?.location?.reload() //刷新页面
+            }
         }
     }
+const addNodeClickCur = async ()=>{
+             //发起请求
+             addNodeLoadingCus.value = true
+            const { error, code } = await wbsApi.saveCustomAddContractNode({
+                nodeName: nodeNameinput.value,
+                nodeType: nodeDataInfo.value?.nodeType || '',
+                partitionCode: nodeDataInfo.value?.partitionCode || '',
+                primaryKeyId: nodeDataInfo.value?.primaryKeyId || '',
+            })
+            //判断状态
+            addNodeLoadingCus.value = false
+            if (!error && code === 200) {
+                window?.$message?.success('新增成功')
+                addNodeModalCus.value = false
+                // window?.location?.reload() //刷新页面
+            }
 }
 
 //删除节点