优化上级节点选择组件

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", type: "string",
includes: ["varchar", "text"] test: ["varchar", "text"]
}, },
{ {
type: "Date", type: "Date",
includes: ["datetime", "date"] test: ["datetime", "date"]
}, },
{ {
type: "number", type: "number",
includes: ["tinyint", "int", "decimal"] test: ["tinyint", "int", "decimal"]
}, },
{ {
type: "BigInt", type: "BigInt",
includes: ["bigint"] test: ["bigint"]
} }
] ]
} }

View File

@ -15,7 +15,9 @@ function getType({ entityName, propertyName, type }) {
const resType = map.custom({ entityName, propertyName, type }); const resType = map.custom({ entityName, propertyName, type });
if (resType) return resType; 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; return type;
} }

View File

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

View File

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

View File

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

View File

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

View File

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