优化上级节点选择组件

This commit is contained in:
icssoa 2022-07-22 12:51:41 +08:00
parent deba2c184b
commit a54c42d2c7
7 changed files with 40 additions and 19 deletions

View File

@ -12,19 +12,19 @@ export default {
},
{
type: "string",
includes: ["varchar", "text"]
test: ["varchar", "text"]
},
{
type: "Date",
includes: ["datetime", "date"]
test: ["datetime", "date"]
},
{
type: "number",
includes: ["tinyint", "int", "decimal"]
test: ["tinyint", "int", "decimal"]
},
{
type: "BigInt",
includes: ["bigint"]
test: ["bigint"]
}
]
}

View File

@ -15,7 +15,9 @@ function getType({ entityName, propertyName, type }) {
const resType = map.custom({ entityName, propertyName, type });
if (resType) return resType;
}
if (map.includes?.includes(type)) return map.type;
if (map.test) {
if (map.test.includes(type)) return map.type;
}
}
return type;
}

View File

@ -106,9 +106,9 @@ const handler = {
// 创建组件
function createComponent(item: any) {
const { propertyName: prop, comment: label } = item;
let d: any = null;
const prop = item.propertyName;
let label = item.comment;
let d: any;
rules.forEach((r: any) => {
const s = r.test.find((e: any) => {
@ -145,6 +145,8 @@ function createComponent(item: any) {
});
function parse(v: any) {
label = label.split(" ")[0];
if (v?.name) {
return {
prop,

View File

@ -1,6 +1,6 @@
{
"name": "front-next",
"version": "5.7.0",
"version": "5.7.1",
"scripts": {
"dev": "vite --host",
"build": "vite build",

View File

@ -113,7 +113,10 @@ async function create() {
prop: "parentId",
label: "上级节点",
component: {
vm: MenuSelect
vm: MenuSelect,
props: {
type: 1
}
}
},
{

View File

@ -2,7 +2,7 @@
<div class="menu-select">
<el-tree-select
v-model="value"
:data="list"
:data="tree"
:props="{
label: 'name',
value: 'id',
@ -20,12 +20,17 @@
<script lang="ts" name="menu-select" setup>
import { useForm } from "@cool-vue/crud";
import { onMounted, ref, watch } from "vue";
import { cloneDeep } from "lodash";
import { computed, onMounted, ref, watch } from "vue";
import { useCool } from "/@/cool";
import { deepTree } from "/@/cool/utils";
const props = defineProps({
modelValue: [Number, String]
modelValue: [Number, String],
type: {
type: Number,
default: 1
}
});
const emit = defineEmits(["update:modelValue"]);
@ -38,15 +43,20 @@ const Form = useForm();
//
const value = ref();
//
//
const list = ref<any[]>([]);
//
const tree = computed(() => {
return deepTree(
cloneDeep(list.value).filter((e) => (props.type === 0 ? e.type == 0 : props.type > e.type))
);
});
//
function refresh() {
service.base.sys.menu.list().then((res) => {
list.value = deepTree(
res.filter((e) => e.type != 2 && e.isShow && e.id != Form.value?.form.id)
);
list.value = res.filter((e) => e.isShow && e.id != Form.value?.form.id);
});
}

View File

@ -76,7 +76,11 @@
</el-row>
<!-- 新增编辑 -->
<cl-upsert ref="Upsert" />
<cl-upsert ref="Upsert">
<template #slot-parentId="{ scope }">
<menu-select :type="scope.type" />
</template>
</cl-upsert>
</cl-crud>
</template>
@ -254,7 +258,7 @@ const Upsert = useUpsert({
prop: "parentId",
label: "上级节点",
component: {
vm: MenuSelect
name: "slot-parentId"
}
},
{