|
|
@@ -1,21 +1,18 @@
|
|
|
<template>
|
|
|
<view :class="classes" @click="onClick" :style="style">
|
|
|
<view class="switch-button">
|
|
|
- <view v-show="!modelValue" class="close-line"></view>
|
|
|
+ <nut-icon v-if="loading" :name="name" :size="size" :color="color"></nut-icon>
|
|
|
+ <!-- <view v-show="!modelValue" class="close-line"></view> -->
|
|
|
<template v-if="activeText">
|
|
|
- <view class="nut-switch-label open" v-show="modelValue">{{
|
|
|
- activeText
|
|
|
- }}</view>
|
|
|
- <view class="nut-switch-label close" v-show="!modelValue">{{
|
|
|
- inactiveText
|
|
|
- }}</view>
|
|
|
+ <view class="nut-switch-label open" v-show="modelValue">{{ activeText }}</view>
|
|
|
+ <view class="nut-switch-label close" v-show="!modelValue">{{ inactiveText }}</view>
|
|
|
</template>
|
|
|
</view>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
|
-import { computed, ref } from 'vue';
|
|
|
+import { computed } from 'vue';
|
|
|
import { createComponent } from '../../utils/create';
|
|
|
const { componentName, create } = createComponent('switch');
|
|
|
|
|
|
@@ -44,6 +41,22 @@ export default create({
|
|
|
inactiveText: {
|
|
|
type: String,
|
|
|
default: ''
|
|
|
+ },
|
|
|
+ loading: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ },
|
|
|
+ name: {
|
|
|
+ type: String,
|
|
|
+ default: 'loading1'
|
|
|
+ },
|
|
|
+ size: {
|
|
|
+ type: [String, Number],
|
|
|
+ default: '12px'
|
|
|
+ },
|
|
|
+ color: {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
}
|
|
|
},
|
|
|
emits: ['change', 'update:modelValue'],
|
|
|
@@ -60,15 +73,14 @@ export default create({
|
|
|
|
|
|
const style = computed(() => {
|
|
|
return {
|
|
|
- backgroundColor: props.modelValue
|
|
|
- ? props.activeColor
|
|
|
- : props.inactiveColor
|
|
|
+ backgroundColor: props.modelValue ? props.activeColor : props.inactiveColor
|
|
|
};
|
|
|
});
|
|
|
|
|
|
const onClick = (event: Event) => {
|
|
|
- if (props.disable) return;
|
|
|
+ if (props.disable || props.loading) return;
|
|
|
emit('update:modelValue', !props.modelValue);
|
|
|
+ emit('update:loading');
|
|
|
emit('change', !props.modelValue, event);
|
|
|
};
|
|
|
|