xxx.data.ts文件,
{
field: 'productValue',
label: '关联设备',
component: 'Input',
render: ({ model, field }) => {
if (model[field]) {
return h(renderList, {
value: model[field],
onChange: (e: any) => {
model[field] = e;
},
});
}
return '';
},
// required: true,
},
renderList.vue 文件
<template>
<div>
<BasicTree
title="设备列表"
v-model:value="getPropsValue"
toolbar
checkable
search
:treeData="treeData"
/>
</div>
</template>
<script lang="ts">
import { defineComponent, nextTick, ref, watch } from 'vue';
import { getDeviceListTree } from '/@/api/device/deviceList';
import { BasicTree, TreeItem } from '/@/components/Tree/index';
import { cloneDeep } from 'lodash-es';
export default defineComponent({
name: 'RenderList',
components: {
BasicTree,
},
props: {
value: {
type: Array as () => string[],
default: () => [],
},
},
emits: ['change'],
setup(props, context) {
const getPropsValue = ref<string[]>([]);
let treeData = ref<TreeItem[]>([]);
let modelOptions;
getDevice();
async function getDevice() {
const res = await getDeviceListTree();
modelOptions = res.map((item) => {
const children = item.list.map((items) => {
items.productValue = items.productValue + '';
const { productValue: key, name: title } = items;
return {
key,
title,
};
});
const { modelName: title, modelName: key } = item;
const modelOptionsItem = { title, key, children };
return modelOptionsItem;
});
nextTick(() => {
treeData.value = cloneDeep(modelOptions);
getPropsValue.value = props.value;
});
}
watch(getPropsValue, () => {
context.emit('change', getPropsValue.value);
});
return {
treeData: treeData,
getPropsValue,
};
},
});
</script>
<style lang="less">
@prefix-cls: ~'@{namespace}-image-preview';
.@{prefix-cls} {
.ant-image {
margin-right: 10px;
}
.ant-image-preview-operations {
background-color: rgb(0 0 0 / 40%);
}
}
</style>