mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2024-11-01 06:02:38 +08:00
优化上级节点选择组件
This commit is contained in:
parent
deba2c184b
commit
a54c42d2c7
@ -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"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "front-next",
|
||||
"version": "5.7.0",
|
||||
"version": "5.7.1",
|
||||
"scripts": {
|
||||
"dev": "vite --host",
|
||||
"build": "vite build",
|
||||
|
@ -113,7 +113,10 @@ async function create() {
|
||||
prop: "parentId",
|
||||
label: "上级节点",
|
||||
component: {
|
||||
vm: MenuSelect
|
||||
vm: MenuSelect,
|
||||
props: {
|
||||
type: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user