This commit is contained in:
Ling53666
2025-08-18 09:11:51 +08:00
commit 02554225da
2516 changed files with 133155 additions and 0 deletions

View File

@ -0,0 +1,21 @@
<view
class="ant-switch {{className ? className : ''}} ant-switch-{{size}} {{mixin.value ? 'ant-switch-checked' : ''}} {{disabled ? 'ant-switch-disabled' : ''}} {{loading ? 'ant-switch-loading' : ''}}"
style="{{mixin.value && color ? 'background:' + color + '; border-color:' + color : ''}};{{style || ''}}"
onTap="onChange"
>
<view class="ant-switch-handle">
<ant-icon
a:if="{{loading}}"
type="UndoOutline"
className="ant-switch-loading-icon"
></ant-icon>
</view>
<view class="ant-switch-inner">
<block a:if="{{mixin.value}}">
<slot name="checkedText">{{checkedText}}</slot>
</block>
<block a:else>
<slot name="uncheckedText">{{uncheckedText}}</slot>
</block>
</view>
</view>

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,17 @@
import { Component, triggerEvent } from '../_util/simply';
import { SwitchDefaultProps } from './props';
import mixinValue from '../mixins/value';
Component(SwitchDefaultProps, {
onChange: function (e) {
var value = !this.getValue();
if (!this.isControlled()) {
this.update(value);
}
triggerEvent(this, 'change', value, e);
},
}, null, [
mixinValue({
valueKey: 'checked',
defaultValueKey: 'defaultChecked',
}),
]);

View File

@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"ant-icon": "../Icon/index"
}
}

View File

@ -0,0 +1,120 @@
@import (reference) './variable.less';
@switchPrefix: ant-switch;
@keyframes loading-rotate {
100% {
transform: rotate(1turn);
}
}
.@{switchPrefix} {
display: inline-block;
vertical-align: middle;
box-sizing: border-box;
position: relative;
align-self: center;
min-width: @switch-width;
height: @switch-height;
border: @switch-border solid @COLOR_BORDER;
border-radius: @switch-height * 0.5;
background: @COLOR_WHITE;
overflow: hidden;
line-height: @switch-height;
&-checked {
background: @switch-fill;
border-color: @switch-fill;
.@{switchPrefix}-handle {
left: calc(100% - (@switch-height - 2 * @switch-border));
}
.@{switchPrefix}-inner {
color: @COLOR_WHITE;
justify-content: flex-start;
}
}
&-disabled {
opacity: 0.4;
pointer-events: none;
}
&-loading {
pointer-events: none;
}
&-loading-icon {
font-size: 20 * @rpx;
animation: loading-rotate 1s linear infinite;
color: @COLOR_BRAND1;
}
&-handle {
display: flex;
justify-content: center;
align-items: center;
width: @switch-height - 2 * @switch-border;
height: @switch-height - 2 * @switch-border;
border-radius: 50%;
background: @COLOR_WHITE;
position: absolute;
top: 0;
left: 0;
transition: all 200ms;
box-shadow: 0 0 2px 0 fade(@COLOR_WHITE_CHANGE_DARK, 20%),
0 2px 11.5px 0 fade(@COLOR_WHITE_CHANGE_DARK, 8%),
-1px 2px 2px 0 fade(@COLOR_WHITE_CHANGE_DARK, 10%);
}
&-inner {
position: relative;
display: flex;
justify-content: flex-end;
align-items: center;
height: 100%;
color: @COLOR_TEXT_ASSIST;
transition: margin 200ms;
font-size: 30 * @rpx;
padding: 0 14 * @rpx;
min-width: 108 * @rpx;
box-sizing: border-box;
&:empty {
display: none;
}
}
&-small {
min-width: @switch-width-small;
height: @switch-height-small;
border-radius: @switch-height-small * 0.5;
.@{switchPrefix}-handle {
width: @switch-height-small - 2 * @switch-border;
height: @switch-height-small - 2 * @switch-border;
}
.@{switchPrefix}-inner {
font-size: 16 * @rpx;
padding: 0 10 * @rpx;
min-width: 72 * @rpx;
}
}
&-small&-checked {
.@{switchPrefix}-handle {
left: calc(100% - (@switch-height-small - 2 * @switch-border));
}
}
&-x-small {
min-width: @switch-width-x-small;
height: @switch-height-x-small;
border-radius: @switch-height-x-small * 0.5;
.@{switchPrefix}-handle {
width: @switch-height-x-small - 2 * @switch-border;
height: @switch-height-x-small - 2 * @switch-border;
}
.@{switchPrefix}-inner {
font-size: 10 * @rpx;
padding: 0 6 * @rpx;
min-width: 56 * @rpx;
}
}
&-x-small&-checked {
.@{switchPrefix}-handle {
left: calc(100% - (@switch-height-x-small - 2 * @switch-border));
}
}
}

View File

@ -0,0 +1,44 @@
import { IBaseProps } from '../_util/base';
/**
* @description 开关。
*/
export interface ISwitchProps extends IBaseProps {
/**
* @description 是否勾选
*/
checked?: boolean;
/**
* @description 是否加载状态
*/
loading?: boolean;
/**
* @description 选中时的颜色
*/
color?: string;
/**
* @description 选中时的内容
*/
checkedText?: string;
/**
* @description 非选中时的内容
*/
uncheckedText?: string;
/**
* @default medium
* @description 尺寸
*/
size?: 'medium' | 'small' | 'x-small';
/**
* 是否禁用
*/
disabled?: boolean;
/**
* 初始值
*/
defaultChecked?: boolean;
/**
* @description 修改回调方法
*/
onChange?: (checked: boolean, e: Record<string, any>) => void;
}
export declare const SwitchDefaultProps: Partial<ISwitchProps>;

View File

@ -0,0 +1,10 @@
export var SwitchDefaultProps = {
checked: null,
loading: false,
color: '',
checkedText: '',
uncheckedText: '',
size: 'medium',
disabled: false,
defaultChecked: false,
};

View File

@ -0,0 +1,24 @@
@import (reference) '../style/themes/index.less';
// 激活时颜色
@switch-fill: @COLOR_BRAND1;
// 开关宽度
@switch-width: 102 * @rpx;
// 开关高度
@switch-height: 62 * @rpx;
// 开关边框
@switch-border: 4 * @rpx;
// 开关宽度
@switch-width-small: 72 * @rpx;
// 开关高度
@switch-height-small: 42 * @rpx;
// 开关边框
@switch-border-small: 3 * @rpx;
// 开关宽度
@switch-width-x-small: 52 * @rpx;
// 开关高度
@switch-height-x-small: 32 * @rpx;
// 开关边框
@switch-border-x-small: 2 * @rpx;