From 20278d28e9b32874a739483b979ddd093f9a1b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E7=AC=99=E6=AD=8C?= <2277317060@qq.com> Date: Fri, 5 Jul 2024 16:33:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B93d=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hw-ui/src/views/board/demo/index.vue | 122 +++++++++++++++------------ 1 file changed, 69 insertions(+), 53 deletions(-) diff --git a/hw-ui/src/views/board/demo/index.vue b/hw-ui/src/views/board/demo/index.vue index e105dfe..be3d164 100644 --- a/hw-ui/src/views/board/demo/index.vue +++ b/hw-ui/src/views/board/demo/index.vue @@ -21,22 +21,34 @@ label="工序" width="180" > + + + + @@ -48,35 +60,42 @@ let id = 0 let deepSearch = (arr, target) => { let results = [] arr.forEach(element => { - id = Math.max(id,element.id) - if (Array.isArray(element.children)) { - results = results.concat(deepSearch(element.children, target)) - } else if (element.id === target) { + console.log(element) + id = Math.max(id, element.id) + if (element.id === target) { results.push(element) + } else if (Array.isArray(element.children)) { + results = results.concat(deepSearch(element.children, target)) } + // if (Array.isArray(element.children)) { + // results = results.concat(deepSearch(element.children, target)) + // } else if (element.id === target) { + // results.push(element) + // } }) - return results + return results } export default { name: 'Demo', data() { return { show: true, + id:0, tableData: [ - { - id: 1, - process: 1, - procedure: '2016-05-02', - staff: '王小虎', - time: '上海市普陀区金沙江路 1518 弄' - }, - { - id: 2, - process: 1, - procedure: '2016-05-02', - staff: '王小虎', - time: '上海市普陀区金沙江路 1518 弄' - }, + // { + // id: 1, + // process: 1, + // procedure: '2016-05-02', + // staff: '王小虎', + // time: '上海市普陀区金沙江路 1518 弄' + // }, + // { + // id: 2, + // process: 1, + // procedure: '2016-05-02', + // staff: '王小虎', + // time: '上海市普陀区金沙江路 1518 弄' + // }, { id: 3, process: 1, @@ -92,56 +111,53 @@ export default { time: '上海市普陀区金沙江路 1518 弄' } ] - }, - { - id: 5, - process: 1, - procedure: '2016-05-02', - staff: '王小虎', - time: '上海市普陀区金沙江路 1518 弄' } + // { + // id: 5, + // process: 1, + // procedure: '2016-05-02', + // staff: '王小虎', + // time: '上海市普陀区金沙江路 1518 弄' + // } ] } }, + mounted() { + this.getId(this.tableData) + }, methods: { + getId(arr) { + arr.forEach(element => { + this.id = Math.max(this.id, element.id) + if (Array.isArray(element.children)) { + this.getId(element.children) + } + }) + }, add(e) { let data = deepSearch(this.tableData, e.row.id)?.[0] if (Array.isArray(data.children)) { this.$set(data.children, data.children.length, { - id: id+1, - process: 1, - procedure: '2016-05-02', - staff: '王小虎', - time: '上海市普陀区金沙江路 1518 弄' + id: this.id + 1, + process: null, + procedure: null, + staff: null, + time: null }) - // data.children.push( - // ) } else { this.$set(data, 'children', [ { - id: id+1, - process: 1, - procedure: '2016-05-02', - staff: '王小虎', - time: '上海市普陀区金沙江路 1518 弄' + id: this.id + 1, + process: null, + procedure: null, + staff: null, + time: null } ]) } - // console.log(e) - // e.row = {} - // this.$set(e,'row',[ - // { - // id: 6, - // process: 1, - // procedure: '2016-05-02', - // staff: '王小虎', - // time: '上海市普陀区金沙江路 1512138 弄' - // }, - // ]) - console.log(data) - console.log(this.tableData) - this.show = false - this.show = true + this.id += 1 + // this.show = false + // this.show = true } }, metaInfo() {