feiyu02
2025-03-28 aa75a9d46ee325f0a92e42f733aabb1f92103aeb
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<template>
  <!-- <el-button type="primary" class="el-button-custom" size="small">
    
    {{ checkValue ? activeText : inactiveText }}
  </el-button> -->
  <el-checkbox
    ref="checkboxRef"
    :disabled="loading"
    :model-value="modelValue"
    @update:model-value="(e) => emits('update:modelValue', e)"
    @change="handleChange"
    border
    size="small"
  >
    <template #default>
      <el-space>
        <el-icon v-if="loading" class="is-loading" color="#00fff2"><Loading /></el-icon>
        {{ activeText }}
      </el-space>
    </template>
  </el-checkbox>
</template>
<script setup>
import { ref, onMounted, onUnmounted, watch } from 'vue';
// import $ from 'jquery';
 
const props = defineProps({
  modelValue: {
    type: Boolean
  },
  loading: {
    type: Boolean
  },
  defaultValue: {
    type: Boolean
  },
  activeText: {
    type: String,
    default: '开'
  },
  inactiveText: {
    type: String,
    default: '关'
  }
});
 
const emits = defineEmits(['change', 'update:modelValue']);
 
const checkboxRef = ref();
const checkValue = ref(false);
 
watch(
  () => props.defaultValue,
  (nV, oV) => {
    if (nV != oV) {
      checkValue.value = nV;
    }
  },
  { immediate: true }
);
 
watch(
  () => props.loading,
  (nV, oV) => {
    if (nV != oV) {
      // setTimeout(() => {
      //   const e1 = checkboxRef.value.$el.querySelector('.el-checkbox__input');
      //   console.log(e1);
 
      //   // e1.classList.toggle('is-disabled');
      //   e1.classList.toggle('checkbox__input_none');
      //   const e2 = checkboxRef.value.$el.querySelector('.el-checkbox__label');
      //   console.log(e2);
      //   e2.classList.toggle('checkbox__label_nopadding');
      // }, 500);
 
      // if (props.id) {
      //   console.log(
      //     checkboxRef.value.$el.querySelector('.el-checkbox__input').classList
      //   );
      //   console.log(
      //     checkboxRef.value.$el.querySelector('.el-checkbox__label').classList
      //   );
      // }
    }
  }
);
 
onMounted(() => {
  if (props.id) {
    console.log(
      checkboxRef.value.$el.querySelector('.el-checkbox__input').classList
    );
    console.log(
      checkboxRef.value.$el.querySelector('.el-checkbox__label').classList
    );
  }
});
 
function handleChange(value) {
  emits('change', value);
}
</script>
<style scoped>
.el-checkbox {
  --el-checkbox-text-color: white;
  /*--main-color: #00fff2;*/
  --main-color: #23dad1;
  --el-checkbox-checked-text-color: var(--main-color);
  --el-checkbox-checked-input-border-color: var(--main-color);
  --el-checkbox-checked-bg-color: var(--main-color);
  --el-checkbox-input-border-color-hover: var(--main-color);
 
  --el-checkbox-disabled-checked-input-fill: var(--main-color);
  --el-checkbox-disabled-checked-input-border-color: var(--main-color);
  --el-checkbox-disabled-checked-icon-color: white;
  margin-right: 6px;
  /* height: initial; */
}
 
.el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: var(--el-color-primary);
}
 
:deep(.checkbox__input_none) {
  display: none !important;
}
 
:deep(.checkbox__label_nopadding) {
  padding-left: 0px;
}
</style>