gaoshp
2024-11-05 e2fdfe540eaf160dc7d063c60667041edcc64e86
src/views/mdc/MYTree.vue
@@ -1,17 +1,30 @@
<!--
 * @Date: 2024-04-18 19:53:35
 * @LastEditors: Sneed
 * @LastEditTime: 2024-06-16 16:21:59
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/mdc/MYTree.vue
 * @LastEditors: gaoshp
 * @LastEditTime: 2024-11-04 20:05:01
 * @FilePath: /cps-web/src/views/mdc/MYTree.vue
-->
<template>
    <el-tree :expand-on-click-node="false" ref="treeRef" v-bind="$attrs" :show-checkbox="showCheckbox"
        :current-node-key="currentNodeKey" node-key="id" :props="defalutProps" :data="data" @check-change="checkChange"
        @node-click="handleNodeClick" highlight-current default-expand-all :render-content="renderContent"></el-tree>
    <el-input v-model="word" style="max-width: 600px" placeholder="" @change="search" class="input-with-select">
        <template #append>
            <el-button :icon="ElementPlusIconsVue.Search" />
        </template>
    </el-input>
    <el-switch v-model="showType" active-text="列表" inactive-text="树状" @change="switchFn" />
    <el-tree v-show="!showType" :expand-on-click-node="false" ref="treeRef" v-bind="$attrs"
        :show-checkbox="showCheckbox" :current-node-key="currentNodeKey" node-key="id" :props="defalutProps"
        :data="data" @check-change="checkChange" @node-click="handleNodeClick" highlight-current default-expand-all
        :render-content="renderContent"></el-tree>
    <el-table v-show="showType" :data="tableData" @selection-change="handleSelectionChange" highlight-current-row
        :current-row-key="currentNodeKey" row-key="id" @row-click="rowClick">
        <el-table-column v-if="showCheckbox" type="selection" :selectable="selectable" width="55" />
        <el-table-column prop="title" label="工位名称" />
    </el-table>
</template>
<script>
import pmsPng from '@/assets/pms.png'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
export default {
    props: {
        showCheckbox: {
@@ -31,6 +44,10 @@
    },
    data() {
        return {
            ElementPlusIconsVue,
            word: '',
            showType: false, // 显示类型
            tableData: [],
            pmsPng,
            firstWorkKey: '',
            currentNodeKey: [],
@@ -57,10 +74,28 @@
            this.$emit('update:modelValue', value)
        }
    },
    created() {
    mounted() {
        this.getList()
        let key = this.$route.path
        if (localStorage.getItem(key) === '1') {
            this.showType = true
        }
        console.log(this.$route, '>>>>>>')
    },
    methods: {
        search() {
            this.getList()
        },
        switchFn(val) {
            console.log(this.$route, val, '>>>>>>')
            localStorage.setItem(this.$route.path, val ? '1' : '0')
        },
        handleSelectionChange(selection) {
            this.value = selection.map(v => v.id)
        },
        rowClick(row) {
            this.currentNodeKey = row.id
        },
        renderContent(h, { data, node }) {
            let img = data.groupTag == 'fms_beltline'
            return h('a', {
@@ -80,20 +115,18 @@
                groupType: "group_workstation"
            }).then(({ code, data }) => {
                if (code === 200) {
                    this.data = this.formatData(data)
                    this.tableData = data.filter(v => v.isWorkstation && v.title.indexOf(this.word) > -1)
                    this.data = this.formatData(data.filter(v => !v.isWorkstation || (v.isWorkstation && v.title.indexOf(this.word) > -1)))
                    this.$nextTick(() => {
                        this.currentNodeKey = this.firstWorkKey
                        this.$emit('loaded', this.firstWorkKey)
                        this.setCurrentKey(data)
                        this.$emit('loaded', this.currentNodeKey)
                        this.$emit('request', data)
                    })
                }
            })
        },
        setCurrentKey(v) {
            if (this.firstWorkKey) return
            if (v.isWorkstation) {
                this.firstWorkKey = v.id
            }
        setCurrentKey(data) {
            this.currentNodeKey = data.find(v => v.isWorkstation && v.title.indexOf(this.word) > -1).id
        },
        formatData(data, current) {
            let newData = []
@@ -103,7 +136,7 @@
                    v.children = this.formatData(data, v).sort((a, b) => {
                        return b.sort - a.sort
                    })
                    this.setCurrentKey(v)
                    // this.setCurrentKey(v)
                    return v
                })
            } else {
@@ -113,7 +146,7 @@
                    item.children = this.formatData(data, item).sort((a, b) => {
                        return b.sort - a.sort
                    })
                    this.setCurrentKey(item)
                    // this.setCurrentKey(item)
                    return item
                })
                return res
@@ -129,6 +162,7 @@
        },
        checkChange(data, data1, data2) {
            console.log('>>>>>>>')
            if (this.getAll) {
                return this.value = this.$refs.treeRef.getCheckedNodes().filter(v => v.isWorkstation)
            }