feat:action/tree组件

This commit is contained in:
wangzenghua 2025-03-11 09:39:25 +01:00
parent cffd50a4fe
commit e1dbf60b53
3 changed files with 85 additions and 3 deletions

View File

@ -5,8 +5,8 @@
<el-dropdown-menu v-if="!isEmpty(actions)"> <el-dropdown-menu v-if="!isEmpty(actions)">
<template v-for="item in actions" :key="item.name"> <template v-for="item in actions" :key="item.name">
<el-dropdown-item v-if="onPermission(item)" @click="item.event(data)"> <el-dropdown-item v-if="onPermission(item)" @click="item.event(data)">
<el-button :type="item.type ?? 'primary'" :icon="item.icon" :size="item.size" :disabled="item.disabled" text> <el-button :type="item.type ?? 'primary'" :icon="formatterIcon(item)" :size="item.size" :disabled="item.disabled" text>
{{ item.name }} {{ item.name || item.formatter(data) }}
</el-button> </el-button>
</el-dropdown-item> </el-dropdown-item>
</template> </template>
@ -26,6 +26,10 @@ const onPermission = (row) => {
if (row.auth === undefined) return true; if (row.auth === undefined) return true;
return typeof row.auth === 'function' ? row.auth(props.data) : row.auth; return typeof row.auth === 'function' ? row.auth(props.data) : row.auth;
}; };
const formatterIcon = (row) => {
return typeof row.icon === 'function' ? row.icon(props.data) : row.icon;
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.custom-table-operate { .custom-table-operate {

View File

@ -0,0 +1,67 @@
<template>
<div :class="`custom-table-tree ${shadow ? 'custom-table-tree__shadow' : ''}`">
<div v-if="title" class="title">{{ title }}</div>
<el-tree
node-key="id"
:data="data"
:show-checkbox="option.showCheckbox"
:default-expanded-keys="option.defaultExpandedKeys"
:default-checked-keys="option.defaultCheckedKeys"
:props="option.defaultProps"
@node-click="handleNodeClick"
/>
</div>
</template>
<script setup name="custom-table-tree">
const props = defineProps({
title: { type: String, default: '' },
shadow: { type: Boolean, default: true },
data: { type: Array, default: () => [] },
option: {
type: Object,
default: () => {
return {
showCheckbox: false,
defaultProps: {
children: 'children',
label: 'label',
},
defaultExpandedKeys: [],
defaultCheckedKeys: [],
};
},
},
});
const emit = defineEmits(['node-click']);
const handleNodeClick = (data) => {
emit('node-click', data);
};
</script>
<style lang="scss" scoped>
.custom-table-tree {
width: 100%;
height: 100%;
min-width: 200px;
@include flex-column();
&__shadow {
box-shadow: 2px 0px 5px rgba(0, 0, 0, 0.1);
}
.title {
height: 36px;
padding: 0 20px;
line-height: 36px;
border-radius: 4px;
font-size: 16px;
color: #fff;
background: var(--el-color-primary);
}
.el-tree {
padding: 16px 10px 10px;
box-sizing: border-box;
}
}
</style>

View File

@ -1,5 +1,6 @@
import SvgIcon from './svg-icon'; import SvgIcon from './svg-icon';
import CustomTableOperate from './custom-table-operate'; import CustomTableOperate from './custom-table-operate';
import CustomTableTree from './custom-table-tree';
import CustomImportExcel from './custom-import-excel'; import CustomImportExcel from './custom-import-excel';
import CustomRichEditor from './custom-rich-editor'; import CustomRichEditor from './custom-rich-editor';
import CustomEchartBar from './custom-echart-bar'; import CustomEchartBar from './custom-echart-bar';
@ -7,4 +8,14 @@ import CustomEchartPie from './custom-echart-pie';
import CustomEchartLine from './custom-echart-line'; import CustomEchartLine from './custom-echart-line';
import CustomEchartMixin from './custom-echart-mixin'; import CustomEchartMixin from './custom-echart-mixin';
export { SvgIcon, CustomTableOperate, CustomImportExcel, CustomRichEditor, CustomEchartBar, CustomEchartPie, CustomEchartLine, CustomEchartMixin }; export {
SvgIcon,
CustomTableOperate,
CustomTableTree,
CustomImportExcel,
CustomRichEditor,
CustomEchartBar,
CustomEchartPie,
CustomEchartLine,
CustomEchartMixin,
};