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
60
61
62
63
64
65
66
67
<template>
  <el-select v-model="value"
             v-bind="props"
             multiple
             @change="onChange">
    <el-option v-for="(item, index) in list"
               :key="index"
               :value="item.logic_id"
               :label="item.logic_id" />
  </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-device-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 () => {
            console.log(list, "list");
            list.value = await service.business.basedeviceinfo.list();
            console.log(list.value, "value_value");
        });
 
        return {
            list,
            value,
            onChange
        };
    }
});
</script>