hy-app 0.2.13 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/hy-action-sheet/hy-action-sheet.vue +81 -13
- package/components/hy-action-sheet/typing.d.ts +1 -3
- package/components/hy-address-picker/hy-address-picker.vue +109 -8
- package/components/hy-address-picker/index.scss +2 -2
- package/components/hy-address-picker/typing.d.ts +39 -30
- package/components/hy-avatar/hy-avatar.vue +78 -4
- package/components/hy-avatar/typing.d.ts +21 -16
- package/components/hy-back-top/hy-back-top.vue +86 -28
- package/components/hy-back-top/typing.d.ts +17 -12
- package/components/hy-badge/hy-badge.vue +114 -43
- package/components/hy-badge/typing.d.ts +20 -15
- package/components/hy-button/HyButton.docgen.js +6 -0
- package/components/hy-button/hy-button.vue +70 -77
- package/components/hy-button/props.ts +40 -41
- package/components/hy-calendar/hy-calendar.vue +290 -143
- package/components/hy-calendar/typing.d.ts +38 -31
- package/components/hy-card/hy-card.vue +139 -36
- package/components/hy-card/typing.d.ts +39 -28
- package/components/hy-cell/hy-cell.vue +131 -67
- package/components/hy-cell/typing.d.ts +6 -1
- package/components/hy-check-button/hy-check-button.vue +101 -32
- package/components/hy-check-button/typing.d.ts +26 -19
- package/components/hy-checkbox/hy-checkbox.vue +167 -78
- package/components/hy-checkbox/typing.d.ts +26 -19
- package/components/hy-code-input/hy-code-input.vue +101 -5
- package/components/hy-code-input/typing.d.ts +9 -0
- package/components/hy-config-provider/hy-config-provider.vue +44 -24
- package/components/hy-config-provider/typing.d.ts +0 -4
- package/components/hy-count-down/hy-count-down.vue +99 -62
- package/components/hy-count-down/typing.d.ts +18 -5
- package/components/hy-count-to/hy-count-to.vue +165 -113
- package/components/hy-count-to/typing.d.ts +15 -11
- package/components/hy-datetime-picker/hy-datetime-picker.vue +338 -232
- package/components/hy-datetime-picker/typing.d.ts +49 -39
- package/components/hy-divider/hy-divider.vue +128 -64
- package/components/hy-divider/typing.d.ts +16 -16
- package/components/hy-dropdown/hy-dropdown.vue +57 -19
- package/components/hy-dropdown/typing.d.ts +14 -14
- package/components/hy-dropdown-item/hy-dropdown-item.vue +34 -5
- package/components/hy-dropdown-item/typing.d.ts +13 -6
- package/components/hy-empty/hy-empty.vue +64 -6
- package/components/hy-empty/typing.d.ts +5 -0
- package/components/hy-float-button/hy-float-button.vue +117 -5
- package/components/hy-float-button/typing.d.ts +7 -0
- package/components/hy-folding-panel/hy-folding-panel.vue +87 -25
- package/components/hy-folding-panel/typing.d.ts +24 -15
- package/components/hy-grid/hy-grid.vue +95 -35
- package/components/hy-grid/typing.d.ts +24 -19
- package/components/hy-icon/hy-icon.vue +84 -6
- package/components/hy-icon/typing.d.ts +5 -0
- package/components/hy-image/hy-image.vue +105 -6
- package/components/hy-image/typing.d.ts +9 -0
- package/components/hy-input/hy-input.vue +277 -130
- package/components/hy-input/props.ts +13 -14
- package/components/hy-input/typing.d.ts +59 -38
- package/components/hy-line/hy-line.vue +65 -25
- package/components/hy-line-progress/hy-line-progress.vue +68 -35
- package/components/hy-list/hy-list.vue +127 -61
- package/components/hy-list/typing.d.ts +19 -12
- package/components/hy-loading/hy-loading.vue +79 -25
- package/components/hy-menu/hy-menu.vue +69 -45
- package/components/hy-menu/typing.d.ts +22 -15
- package/components/hy-modal/hy-modal.vue +91 -4
- package/components/hy-modal/typing.d.ts +11 -0
- package/components/hy-navbar/hy-navbar.vue +105 -25
- package/components/hy-navbar/typing.d.ts +25 -20
- package/components/hy-notice-bar/hy-notice-bar.vue +97 -19
- package/components/hy-notice-bar/typing.d.ts +22 -17
- package/components/hy-notify/hy-notify.vue +106 -54
- package/components/hy-number-step/hy-number-step.vue +211 -120
- package/components/hy-number-step/typing.d.ts +45 -28
- package/components/hy-overlay/hy-overlay.vue +60 -16
- package/components/hy-overlay/typing.d.ts +11 -6
- package/components/hy-pagination/hy-pagination.vue +94 -37
- package/components/hy-pagination/typing.d.ts +20 -11
- package/components/hy-picker/hy-picker.vue +225 -160
- package/components/hy-picker/typing.d.ts +51 -28
- package/components/hy-popover/hy-popover.vue +55 -7
- package/components/hy-popover/typing.d.ts +21 -1
- package/components/hy-popup/hy-popup.vue +164 -99
- package/components/hy-popup/typing.d.ts +11 -0
- package/components/hy-price/hy-price.vue +77 -30
- package/components/hy-price/typing.d.ts +10 -10
- package/components/hy-qrcode/hy-qrcode.vue +75 -5
- package/components/hy-qrcode/typing.d.ts +25 -16
- package/components/hy-radio/hy-radio.vue +169 -88
- package/components/hy-radio/typing.d.ts +29 -22
- package/components/hy-rate/hy-rate.vue +155 -104
- package/components/hy-rate/typing.d.ts +23 -16
- package/components/hy-read-more/hy-read-more.vue +83 -56
- package/components/hy-read-more/typing.d.ts +18 -11
- package/components/hy-scroll-list/hy-scroll-list.vue +69 -58
- package/components/hy-scroll-list/typing.d.ts +14 -7
- package/components/hy-search/hy-search.vue +168 -62
- package/components/hy-search/typing.d.ts +47 -26
- package/components/hy-signature/hy-signature.vue +354 -272
- package/components/hy-signature/typing.d.ts +65 -52
- package/components/hy-slider/hy-slider.vue +208 -160
- package/components/hy-slider/typing.d.ts +28 -17
- package/components/hy-steps/hy-steps.vue +125 -99
- package/components/hy-steps/typing.d.ts +21 -14
- package/components/hy-submit-bar/hy-submit-bar.vue +129 -48
- package/components/hy-submit-bar/typing.d.ts +30 -23
- package/components/hy-subsection/hy-subsection.vue +139 -96
- package/components/hy-subsection/typing.d.ts +23 -16
- package/components/hy-swipe-action/hy-swipe-action.vue +161 -135
- package/components/hy-swipe-action/typing.d.ts +26 -17
- package/components/hy-swiper/hy-swiper.vue +178 -73
- package/components/hy-swiper/typing.d.ts +37 -28
- package/components/hy-switch/hy-switch.vue +107 -60
- package/components/hy-switch/typing.d.ts +25 -18
- package/components/hy-tabs/hy-tabs.vue +170 -160
- package/components/hy-tabs/typing.d.ts +36 -22
- package/components/hy-tag/hy-tag.vue +133 -58
- package/components/hy-tag/typing.d.ts +26 -18
- package/components/hy-text/hy-text.vue +106 -6
- package/components/hy-text/typing.d.ts +31 -26
- package/components/hy-textarea/hy-textarea.vue +183 -89
- package/components/hy-textarea/typing.d.ts +41 -24
- package/components/hy-tooltip/hy-tooltip.vue +145 -101
- package/components/hy-tooltip/typing.d.ts +18 -13
- package/components/hy-transition/hy-transition.vue +48 -13
- package/components/hy-transition/typing.d.ts +17 -0
- package/components/hy-upload/hy-upload.vue +113 -148
- package/components/hy-upload/typing.d.ts +71 -71
- package/components/hy-warn/hy-warn.vue +79 -36
- package/components/hy-warn/typing.d.ts +18 -11
- package/components/hy-waterfall/hy-waterfall.vue +90 -77
- package/components/hy-watermark/hy-watermark.vue +82 -5
- package/components/hy-watermark/typing.d.ts +20 -20
- package/global.d.ts +39 -59
- package/package.json +5 -13
- package/utils/inspect.ts +3 -1
- package/web-types.json +1 -1
- package/component-helper.ts +0 -177
- package/components.json +0 -3287
- package/dist/attributes.json +0 -1
- package/dist/docs/components/hy-action-sheet/hy-action-sheet.md +0 -41
- package/dist/docs/components/hy-address-picker/hy-address-picker.md +0 -25
- package/dist/docs/components/hy-avatar/hy-avatar.md +0 -19
- package/dist/docs/components/hy-back-top/hy-back-top.md +0 -19
- package/dist/docs/components/hy-badge/hy-badge.md +0 -13
- package/dist/docs/components/hy-button/hy-button.md +0 -61
- package/dist/docs/components/hy-calendar/header.md +0 -17
- package/dist/docs/components/hy-calendar/hy-calendar.md +0 -27
- package/dist/docs/components/hy-calendar/month.md +0 -38
- package/dist/docs/components/hy-card/hy-card.md +0 -24
- package/dist/docs/components/hy-cell/hy-cell.md +0 -26
- package/dist/docs/components/hy-check-button/hy-check-button.md +0 -14
- package/dist/docs/components/hy-checkbox/hy-checkbox.md +0 -21
- package/dist/docs/components/hy-code-input/hy-code-input.md +0 -15
- package/dist/docs/components/hy-config-provider/hy-config-provider.md +0 -13
- package/dist/docs/components/hy-count-down/hy-count-down.md +0 -34
- package/dist/docs/components/hy-count-to/hy-count-to.md +0 -31
- package/dist/docs/components/hy-datetime-picker/hy-datetime-picker.md +0 -25
- package/dist/docs/components/hy-divider/hy-divider.md +0 -13
- package/dist/docs/components/hy-dropdown/hy-dropdown.md +0 -13
- package/dist/docs/components/hy-dropdown-item/hy-dropdown-item.md +0 -20
- package/dist/docs/components/hy-empty/hy-empty.md +0 -20
- package/dist/docs/components/hy-float-button/hy-float-button.md +0 -20
- package/dist/docs/components/hy-folding-panel/hy-folding-panel.md +0 -24
- package/dist/docs/components/hy-form/hy-form.md +0 -29
- package/dist/docs/components/hy-grid/hy-grid.md +0 -19
- package/dist/docs/components/hy-icon/hy-icon.md +0 -13
- package/dist/docs/components/hy-image/hy-image.md +0 -22
- package/dist/docs/components/hy-input/hy-input.md +0 -29
- package/dist/docs/components/hy-line/hy-line.md +0 -7
- package/dist/docs/components/hy-line-progress/hy-line-progress.md +0 -13
- package/dist/docs/components/hy-list/hy-list.md +0 -25
- package/dist/docs/components/hy-loading/hy-loading.md +0 -14
- package/dist/docs/components/hy-login/ThePhoneLogin.md +0 -20
- package/dist/docs/components/hy-login/TheUserLogin.md +0 -44
- package/dist/docs/components/hy-login/hy-login.md +0 -14
- package/dist/docs/components/hy-menu/hy-menu.md +0 -21
- package/dist/docs/components/hy-modal/hy-modal.md +0 -23
- package/dist/docs/components/hy-navbar/hy-navbar.md +0 -22
- package/dist/docs/components/hy-notice-bar/hy-column-notice.md +0 -20
- package/dist/docs/components/hy-notice-bar/hy-notice-bar.md +0 -14
- package/dist/docs/components/hy-notice-bar/hy-row-notice.md +0 -20
- package/dist/docs/components/hy-notify/hy-notify.md +0 -23
- package/dist/docs/components/hy-number-step/hy-number-step.md +0 -27
- package/dist/docs/components/hy-overlay/hy-overlay.md +0 -19
- package/dist/docs/components/hy-pagination/hy-pagination.md +0 -14
- package/dist/docs/components/hy-parse/hy-parse.md +0 -46
- package/dist/docs/components/hy-parse/node/node.md +0 -7
- package/dist/docs/components/hy-picker/hy-picker.md +0 -32
- package/dist/docs/components/hy-popover/hy-popover.md +0 -34
- package/dist/docs/components/hy-popup/hy-popup.md +0 -22
- package/dist/docs/components/hy-price/hy-price.md +0 -13
- package/dist/docs/components/hy-qrcode/hy-qrcode.md +0 -15
- package/dist/docs/components/hy-radio/hy-radio.md +0 -21
- package/dist/docs/components/hy-rate/hy-rate.md +0 -14
- package/dist/docs/components/hy-read-more/hy-read-more.md +0 -21
- package/dist/docs/components/hy-scroll-list/hy-scroll-list.md +0 -21
- package/dist/docs/components/hy-search/hy-search.md +0 -27
- package/dist/docs/components/hy-signature/hy-signature.md +0 -45
- package/dist/docs/components/hy-slider/hy-slider.md +0 -24
- package/dist/docs/components/hy-status-bar/hy-status-bar.md +0 -13
- package/dist/docs/components/hy-steps/hy-steps.md +0 -23
- package/dist/docs/components/hy-submit-bar/hy-submit-bar.md +0 -21
- package/dist/docs/components/hy-subsection/hy-subsection.md +0 -14
- package/dist/docs/components/hy-swipe-action/hy-swipe-action.md +0 -29
- package/dist/docs/components/hy-swiper/hy-swiper-indicator.md +0 -23
- package/dist/docs/components/hy-swiper/hy-swiper.md +0 -22
- package/dist/docs/components/hy-switch/hy-switch.md +0 -20
- package/dist/docs/components/hy-tabBar/hy-tabBar.md +0 -13
- package/dist/docs/components/hy-tabs/hy-tabs.md +0 -27
- package/dist/docs/components/hy-tag/hy-tag.md +0 -21
- package/dist/docs/components/hy-text/hy-text.md +0 -13
- package/dist/docs/components/hy-textarea/hy-textarea.md +0 -19
- package/dist/docs/components/hy-toast/hy-toast.md +0 -17
- package/dist/docs/components/hy-tooltip/hy-tooltip.md +0 -13
- package/dist/docs/components/hy-transition/hy-transition.md +0 -25
- package/dist/docs/components/hy-upload/hy-upload.md +0 -25
- package/dist/docs/components/hy-warn/hy-warn.md +0 -14
- package/dist/docs/components/hy-waterfall/hy-waterfall.md +0 -30
- package/dist/docs/components/hy-watermark/hy-watermark.md +0 -7
- package/dist/docs/components/message/TheMessage.md +0 -17
- package/dist/docs/components/yk-dialog/yk-dialog.md +0 -7
- package/dist/tags.json +0 -1
- package/dist/web-types.json +0 -1
- package/docgen.config.js +0 -14
- package/web-types.config.js +0 -7
|
@@ -8,17 +8,13 @@
|
|
|
8
8
|
:style="[switchStyle, customStyle]"
|
|
9
9
|
@tap="clickHandler"
|
|
10
10
|
>
|
|
11
|
-
<view class="hy-switch--bg" :style="[bgStyle]"
|
|
11
|
+
<view class="hy-switch--bg" :style="[bgStyle]"></view>
|
|
12
12
|
<view
|
|
13
13
|
:class="['hy-switch--node', modelValue && 'hy-switch__node--on']"
|
|
14
14
|
:style="[nodeStyle]"
|
|
15
15
|
ref="hy-switch__node"
|
|
16
16
|
>
|
|
17
|
-
<hy-loading
|
|
18
|
-
:show="loading"
|
|
19
|
-
:size="switchSize * 0.6"
|
|
20
|
-
mode="circle"
|
|
21
|
-
></hy-loading>
|
|
17
|
+
<hy-loading :show="loading" :size="switchSize * 0.6" mode="circle"></hy-loading>
|
|
22
18
|
<view class="" v-if="!loading">
|
|
23
19
|
<slot>
|
|
24
20
|
<HyIcon
|
|
@@ -42,27 +38,84 @@
|
|
|
42
38
|
</template>
|
|
43
39
|
|
|
44
40
|
<script lang="ts">
|
|
41
|
+
/**
|
|
42
|
+
* 选择开关用于在打开和关闭状态之间进行切换。
|
|
43
|
+
* @displayName hy-switch
|
|
44
|
+
*/
|
|
45
|
+
defineOptions({})
|
|
45
46
|
export default {
|
|
46
|
-
name:
|
|
47
|
+
name: 'hy-switch',
|
|
47
48
|
options: {
|
|
48
49
|
addGlobalClass: true,
|
|
49
50
|
virtualHost: true,
|
|
50
|
-
styleIsolation:
|
|
51
|
+
styleIsolation: 'shared',
|
|
51
52
|
},
|
|
52
|
-
}
|
|
53
|
+
}
|
|
53
54
|
</script>
|
|
54
55
|
|
|
55
56
|
<script setup lang="ts">
|
|
56
|
-
import { toRefs, watch, nextTick, computed, type CSSProperties } from
|
|
57
|
-
import { addUnit, error } from
|
|
58
|
-
import
|
|
59
|
-
import type IProps from "./typing";
|
|
57
|
+
import { toRefs, watch, nextTick, computed, type CSSProperties, PropType } from 'vue'
|
|
58
|
+
import { addUnit, error } from '../../utils'
|
|
59
|
+
import type { ISwitchEmits } from './typing'
|
|
60
60
|
|
|
61
61
|
// 组件
|
|
62
|
-
import HyLoading from
|
|
63
|
-
import HyIcon from
|
|
62
|
+
import HyLoading from '../hy-loading/hy-loading.vue'
|
|
63
|
+
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
64
|
+
import HyIconProps from '../hy-icon/typing'
|
|
64
65
|
|
|
65
|
-
const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
66
|
+
// const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
67
|
+
const props = defineProps({
|
|
68
|
+
/** 通过v-model双向绑定的值 */
|
|
69
|
+
modelValue: {
|
|
70
|
+
type: Boolean,
|
|
71
|
+
default: false,
|
|
72
|
+
},
|
|
73
|
+
/** 是否处于加载中 */
|
|
74
|
+
loading: {
|
|
75
|
+
type: Boolean,
|
|
76
|
+
default: false,
|
|
77
|
+
},
|
|
78
|
+
/** 是否禁用 */
|
|
79
|
+
disabled: {
|
|
80
|
+
type: Boolean,
|
|
81
|
+
default: false,
|
|
82
|
+
},
|
|
83
|
+
/** 开关尺寸,单位px */
|
|
84
|
+
size: {
|
|
85
|
+
type: String,
|
|
86
|
+
default: 'medium',
|
|
87
|
+
},
|
|
88
|
+
/** 打开时的背景色 */
|
|
89
|
+
activeColor: String,
|
|
90
|
+
/** 关闭时的背景色 */
|
|
91
|
+
inactiveColor: String,
|
|
92
|
+
/** 打开选择器时通过change事件发出的值 */
|
|
93
|
+
activeValue: {
|
|
94
|
+
type: Boolean,
|
|
95
|
+
default: true,
|
|
96
|
+
},
|
|
97
|
+
/** 关闭选择器时通过change事件发出的值 */
|
|
98
|
+
inactiveValue: {
|
|
99
|
+
type: Boolean,
|
|
100
|
+
default: false,
|
|
101
|
+
},
|
|
102
|
+
/** 打开选择器时图标 */
|
|
103
|
+
activeIcon: String,
|
|
104
|
+
/** 关闭选择器时图标 */
|
|
105
|
+
inactiveIcon: String,
|
|
106
|
+
/** 图标 */
|
|
107
|
+
icon: Object as unknown as PropType<HyIconProps>,
|
|
108
|
+
/** 是否开启异步变更,开启后需要手动控制输入值 */
|
|
109
|
+
asyncChange: {
|
|
110
|
+
type: Boolean,
|
|
111
|
+
default: false,
|
|
112
|
+
},
|
|
113
|
+
/** 圆点与外边框的距离 */
|
|
114
|
+
space: {
|
|
115
|
+
type: Number,
|
|
116
|
+
default: 0,
|
|
117
|
+
},
|
|
118
|
+
})
|
|
66
119
|
const {
|
|
67
120
|
modelValue,
|
|
68
121
|
size,
|
|
@@ -74,25 +127,25 @@ const {
|
|
|
74
127
|
loading,
|
|
75
128
|
asyncChange,
|
|
76
129
|
inactiveColor,
|
|
77
|
-
} = toRefs(props)
|
|
78
|
-
const emit = defineEmits(
|
|
130
|
+
} = toRefs(props)
|
|
131
|
+
const emit = defineEmits<ISwitchEmits>()
|
|
79
132
|
|
|
80
133
|
watch(
|
|
81
134
|
() => modelValue.value,
|
|
82
135
|
(newValue) => {
|
|
83
136
|
if (newValue !== inactiveValue.value && newValue !== activeValue.value) {
|
|
84
|
-
error(
|
|
137
|
+
error('v-model绑定的值必须为inactiveValue、activeValue二者之一')
|
|
85
138
|
}
|
|
86
139
|
},
|
|
87
140
|
{ immediate: true },
|
|
88
|
-
)
|
|
141
|
+
)
|
|
89
142
|
|
|
90
143
|
/**
|
|
91
144
|
* @description 是否打开
|
|
92
145
|
* */
|
|
93
146
|
const isActive = computed(() => {
|
|
94
|
-
return modelValue.value === activeValue.value
|
|
95
|
-
})
|
|
147
|
+
return modelValue.value === activeValue.value
|
|
148
|
+
})
|
|
96
149
|
|
|
97
150
|
/**
|
|
98
151
|
* @description 设置开关大小
|
|
@@ -102,87 +155,81 @@ const switchSize = computed((): number => {
|
|
|
102
155
|
small: 20,
|
|
103
156
|
medium: 25,
|
|
104
157
|
large: 30,
|
|
105
|
-
}
|
|
158
|
+
}
|
|
106
159
|
|
|
107
|
-
return typeof size.value ===
|
|
108
|
-
|
|
109
|
-
: sz[size.value] || Number(size.value);
|
|
110
|
-
});
|
|
160
|
+
return typeof size.value === 'number' ? size.value : sz[size.value] || Number(size.value)
|
|
161
|
+
})
|
|
111
162
|
|
|
112
163
|
/**
|
|
113
164
|
* @description 开关样式
|
|
114
165
|
* */
|
|
115
166
|
const switchStyle = computed<CSSProperties>(() => {
|
|
116
|
-
let style: CSSProperties = {}
|
|
167
|
+
let style: CSSProperties = {}
|
|
117
168
|
// 这里需要加2,是为了腾出边框的距离,否则圆点node会和外边框紧贴在一起
|
|
118
|
-
style.width = addUnit(switchSize.value * 2 + 2)
|
|
119
|
-
style.height = addUnit(switchSize.value + 2)
|
|
169
|
+
style.width = addUnit(switchSize.value * 2 + 2)
|
|
170
|
+
style.height = addUnit(switchSize.value + 2)
|
|
120
171
|
// style.borderColor = this.value ? 'rgba(0, 0, 0, 0)' : 'rgba(0, 0, 0, 0.12)'
|
|
121
172
|
// 如果自定义了“非激活”演示,name边框颜色设置为透明(跟非激活颜色一致)
|
|
122
173
|
// 这里不能简单的设置为非激活的颜色,否则打开状态时,会有边框,所以需要透明
|
|
123
174
|
if (customInactiveColor.value) {
|
|
124
|
-
style.borderColor =
|
|
175
|
+
style.borderColor = 'rgba(0, 0, 0, 0)'
|
|
125
176
|
}
|
|
126
|
-
style.backgroundColor = isActive.value
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return style;
|
|
130
|
-
});
|
|
177
|
+
style.backgroundColor = isActive.value ? activeColor.value : inactiveColor.value
|
|
178
|
+
return style
|
|
179
|
+
})
|
|
131
180
|
|
|
132
181
|
/**
|
|
133
182
|
* @description 圆圈样式
|
|
134
183
|
* */
|
|
135
184
|
const nodeStyle = computed<CSSProperties>(() => {
|
|
136
|
-
let style: CSSProperties = {}
|
|
185
|
+
let style: CSSProperties = {}
|
|
137
186
|
// 如果自定义非激活颜色,将node圆点的尺寸减少两个像素,让其与外边框距离更大一点
|
|
138
|
-
style.width = addUnit(switchSize.value - space.value)
|
|
139
|
-
style.height = addUnit(switchSize.value - space.value)
|
|
140
|
-
const translateX = isActive.value
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return style;
|
|
145
|
-
});
|
|
187
|
+
style.width = addUnit(switchSize.value - space.value)
|
|
188
|
+
style.height = addUnit(switchSize.value - space.value)
|
|
189
|
+
const translateX = isActive.value ? addUnit(space.value) : addUnit(switchSize.value)
|
|
190
|
+
style.transform = `translateX(-${translateX})`
|
|
191
|
+
return style
|
|
192
|
+
})
|
|
146
193
|
|
|
147
194
|
/**
|
|
148
195
|
* @description 背景样式
|
|
149
196
|
* */
|
|
150
197
|
const bgStyle = computed<CSSProperties>(() => {
|
|
151
|
-
let style: CSSProperties = {}
|
|
198
|
+
let style: CSSProperties = {}
|
|
152
199
|
// 这里配置一个多余的元素在HTML中,是为了让switch切换时,有更良好的背景色扩充体验(见实际效果)
|
|
153
|
-
style.width = addUnit(switchSize.value * 2 - switchSize.value / 2)
|
|
154
|
-
style.height = addUnit(switchSize.value)
|
|
155
|
-
style.backgroundColor = inactiveColor.value
|
|
200
|
+
style.width = addUnit(switchSize.value * 2 - switchSize.value / 2)
|
|
201
|
+
style.height = addUnit(switchSize.value)
|
|
202
|
+
style.backgroundColor = inactiveColor.value
|
|
156
203
|
// 打开时,让此元素收缩,否则反之
|
|
157
|
-
style.transform = `scale(${isActive.value ? 0 : 1})
|
|
158
|
-
return style
|
|
159
|
-
})
|
|
204
|
+
style.transform = `scale(${isActive.value ? 0 : 1})`
|
|
205
|
+
return style
|
|
206
|
+
})
|
|
160
207
|
|
|
161
208
|
/**
|
|
162
209
|
* @description 自定义颜色
|
|
163
210
|
* */
|
|
164
211
|
const customInactiveColor = computed(() => {
|
|
165
212
|
// 之所以需要判断是否自定义了“非激活”颜色,是为了让node圆点离外边框更宽一点的距离
|
|
166
|
-
return inactiveColor.value !==
|
|
167
|
-
})
|
|
213
|
+
return inactiveColor.value !== '#fff' && inactiveColor.value !== '#ffffff'
|
|
214
|
+
})
|
|
168
215
|
|
|
169
216
|
/**
|
|
170
217
|
* @description 点击事件
|
|
171
218
|
* */
|
|
172
219
|
const clickHandler = () => {
|
|
173
220
|
if (!disabled.value && !loading.value) {
|
|
174
|
-
const oldValue = isActive.value ? inactiveValue.value : activeValue.value
|
|
221
|
+
const oldValue = isActive.value ? inactiveValue.value : activeValue.value
|
|
175
222
|
if (!asyncChange.value) {
|
|
176
|
-
emit(
|
|
223
|
+
emit('update:modelValue', oldValue)
|
|
177
224
|
}
|
|
178
225
|
// 放到下一个生命周期,因为双向绑定的value修改父组件状态需要时间,且是异步的
|
|
179
226
|
nextTick(() => {
|
|
180
|
-
emit(
|
|
181
|
-
})
|
|
227
|
+
emit('change', oldValue)
|
|
228
|
+
})
|
|
182
229
|
}
|
|
183
|
-
}
|
|
230
|
+
}
|
|
184
231
|
</script>
|
|
185
232
|
|
|
186
233
|
<style lang="scss" scoped>
|
|
187
|
-
@import
|
|
234
|
+
@import './index.scss';
|
|
188
235
|
</style>
|
|
@@ -1,62 +1,69 @@
|
|
|
1
|
-
import type { CSSProperties } from
|
|
2
|
-
import { HyApp } from
|
|
3
|
-
import type IconProps from
|
|
1
|
+
import type { CSSProperties } from 'vue'
|
|
2
|
+
import { HyApp } from '@/package/typing/modules/common'
|
|
3
|
+
import type IconProps from '../hy-icon/typing'
|
|
4
4
|
|
|
5
5
|
export default interface HySwitchProps {
|
|
6
6
|
/**
|
|
7
7
|
* @description 通过v-model双向绑定的值 (默认 false )
|
|
8
8
|
* */
|
|
9
|
-
modelValue: boolean | string | number
|
|
9
|
+
modelValue: boolean | string | number
|
|
10
10
|
/**
|
|
11
11
|
* @description 是否处于加载中(默认 false )
|
|
12
12
|
* */
|
|
13
|
-
loading?: boolean
|
|
13
|
+
loading?: boolean
|
|
14
14
|
/**
|
|
15
15
|
* @description 是否禁用(默认 false )
|
|
16
16
|
* */
|
|
17
|
-
disabled?: boolean
|
|
17
|
+
disabled?: boolean
|
|
18
18
|
/**
|
|
19
19
|
* @description 开关尺寸,单位px (默认 25 )
|
|
20
20
|
* */
|
|
21
|
-
size?: HyApp.SizeType | string | number
|
|
21
|
+
size?: HyApp.SizeType | string | number
|
|
22
22
|
/**
|
|
23
23
|
* @description 打开时的背景色 (默认 '#2979ff' )
|
|
24
24
|
* */
|
|
25
|
-
activeColor?: string
|
|
25
|
+
activeColor?: string
|
|
26
26
|
/**
|
|
27
27
|
* @description 关闭时的背景色 (默认 '#ffffff' )
|
|
28
28
|
* */
|
|
29
|
-
inactiveColor?: string
|
|
29
|
+
inactiveColor?: string
|
|
30
30
|
/**
|
|
31
31
|
* @description 打开选择器时通过change事件发出的值 (默认 true )
|
|
32
32
|
* */
|
|
33
|
-
activeValue?: boolean | string | number
|
|
33
|
+
activeValue?: boolean | string | number
|
|
34
34
|
/**
|
|
35
35
|
* @description 关闭选择器时通过change事件发出的值 (默认 false )
|
|
36
36
|
* */
|
|
37
|
-
inactiveValue?: boolean | string | number
|
|
37
|
+
inactiveValue?: boolean | string | number
|
|
38
38
|
/**
|
|
39
39
|
* @description 打开选择器时图标
|
|
40
40
|
* */
|
|
41
|
-
activeIcon?: string
|
|
41
|
+
activeIcon?: string
|
|
42
42
|
/**
|
|
43
43
|
* @description 关闭选择器时图标
|
|
44
44
|
* */
|
|
45
|
-
inactiveIcon?: string
|
|
45
|
+
inactiveIcon?: string
|
|
46
46
|
/**
|
|
47
|
-
* @description
|
|
47
|
+
* @description 图标
|
|
48
48
|
* */
|
|
49
|
-
icon?: IconProps
|
|
49
|
+
icon?: IconProps
|
|
50
50
|
/**
|
|
51
51
|
* @description 是否开启异步变更,开启后需要手动控制输入值 (默认 false )
|
|
52
52
|
* */
|
|
53
|
-
asyncChange?: boolean
|
|
53
|
+
asyncChange?: boolean
|
|
54
54
|
/**
|
|
55
55
|
* @description 圆点与外边框的距离 (默认 0 )
|
|
56
56
|
* */
|
|
57
|
-
space?: number
|
|
57
|
+
space?: number
|
|
58
58
|
/**
|
|
59
59
|
* @description 定义需要用到的外部样式
|
|
60
60
|
* */
|
|
61
|
-
customStyle?: CSSProperties
|
|
61
|
+
customStyle?: CSSProperties
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ISwitchEmits {
|
|
65
|
+
/** 改变值触发 */
|
|
66
|
+
(e: 'change', value: boolean): void
|
|
67
|
+
/** 改变值触发 */
|
|
68
|
+
(e: 'update:modelValue', value: boolean): void
|
|
62
69
|
}
|