This commit is contained in:
神仙都没用 2023-09-28 17:02:45 +08:00
parent 528491151a
commit 9120cc61dc

View File

@ -1,12 +1,34 @@
<template>
<div class="cl-menu-file">
<el-cascader v-model="value" :options="data" clearable @change="onChange" />
<template v-if="isEdit">
<el-input placeholder="请输入" v-model="text" @change="onTextChange"></el-input>
<el-icon @click="toggle(false)">
<FolderChecked />
</el-icon>
</template>
<template v-else>
<el-cascader
v-model="path"
:options="data"
clearable
filterable
allow-create
@change="onPathChange"
/>
<el-icon @click="toggle(true)">
<Edit />
</el-icon>
</template>
</div>
</template>
<script lang="ts" name="cl-menu-file" setup>
import { ref, watch } from "vue";
import { deepPaths } from "/@/cool/utils";
import { FolderChecked, Edit } from "@element-plus/icons-vue";
const props = defineProps({
modelValue: {
@ -32,22 +54,46 @@ function findFiles() {
}
//
const value = ref();
const path = ref();
//
const text = ref();
//
const isEdit = ref(false);
//
const data = ref(findFiles());
//
function onChange(arr: string[]) {
const v = "modules/" + arr.join("/");
//
function onPathChange(arr: string[]) {
const v = "modules/" + (arr || []).join("/");
emit("update:modelValue", v);
emit("change", v);
}
//
function onTextChange(v: string) {
emit("update:modelValue", v);
emit("change", v);
}
//
function toggle(f: boolean) {
isEdit.value = f;
}
watch(
() => props.modelValue,
(val) => {
value.value = (val || "").replace(/(modules\/|cool\/)/g, "").split("/");
if (val) {
if (val.includes("http")) {
text.value = val;
isEdit.value = true;
} else {
path.value = val.replace(/(modules\/|cool\/)/g, "").split("/");
}
}
},
{
immediate: true
@ -57,10 +103,22 @@ watch(
<style lang="scss" scoped>
.cl-menu-file {
display: flex;
align-items: center;
width: 100%;
:deep(.el-cascader) {
width: 100%;
}
.el-icon {
margin: 0 0 0 10px;
font-size: 18px;
cursor: pointer;
&:hover {
color: var(--el-color-primary);
}
}
}
</style>