master
2022-02-14 1684d66eaf39f77980b987359f413d2ff5714940
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<template>
    <div class="cl-menu-file">
        <el-select v-model="path" allow-create filterable clearable placeholder="请选择">
            <el-option
                v-for="(item, index) in list"
                :key="index"
                :label="item.value"
                :value="item.value"
            />
        </el-select>
    </div>
</template>
 
<script lang="ts">
import { defineComponent, ref, watch } from "vue";
 
// 扫描文件
function findFiles() {
    const files = import.meta.globEager("/**/views/**/*.vue");
    let list = [];
 
    for (const i in files) {
        if (!i.includes("components")) {
            list.push({
                value: i.substr(5)
            });
        }
    }
 
    return list;
}
 
export default defineComponent({
    name: "cl-menu-file",
 
    props: {
        modelValue: {
            type: String,
            default: ""
        }
    },
 
    emits: ["update:modelValue"],
 
    setup(props, { emit }) {
        // 路径
        const path = ref<string>(props.modelValue);
 
        // 数据列表
        const list = ref<any[]>(findFiles());
 
        watch(
            () => props.modelValue,
            (val) => {
                path.value = val || "";
            }
        );
 
        watch(path, (val) => {
            emit("update:modelValue", val);
        });
 
        return {
            path,
            list
        };
    }
});
</script>
 
<style lang="scss" scoped>
.cl-menu-file {
    width: 100%;
 
    .el-select {
        width: 100%;
    }
 
    &__module {
        display: inline-flex;
 
        .label {
            width: 40px;
            text-align: right;
            margin-right: 10px;
        }
    }
}
</style>