fuchengshen
2022-07-15 dfdcca599b595c7340b31ee7cd5878f29a3268eb
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
<template>
    <el-select v-model="value" v-bind="props" multiple @change="onChange">
        <el-option v-for="(item, index) in list" :key="index" :value="item.id" :label="item.name" />
    </el-select>
</template>
 
<script lang="ts">
import { defineComponent, onMounted, ref, watch } from "vue";
import { useCool } from "/@/cool";
import { isArray } from "/@/cool/utils";
 
export default defineComponent({
    name: "cl-role-select",
 
    props: {
        modelValue: [String, Number, Array],
        props: Object
    },
 
    emits: ["update:modelValue"],
 
    setup(props, { emit }) {
        // 请求服务
        const { service } = useCool();
 
        // 数据列表
        const list = ref<any[]>([]);
 
        // 绑定值
        const value = ref<any>();
 
        // 绑定值回调
        function onChange(val: any) {
            emit("update:modelValue", val);
        }
 
        // 解析值
        watch(
            () => props.modelValue,
            (val: any) => {
                value.value = (isArray(val) ? val : [val]).filter(Boolean);
            },
            {
                immediate: true
            }
        );
 
        onMounted(async () => {
            list.value = await service.base.sys.role.list();
        });
 
        return {
            list,
            value,
            onChange
        };
    }
});
</script>