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,46 @@
<import-sjs
from="./index.sjs"
name="utils"
></import-sjs>
<button
formType="{{formType}}"
hoverClass="{{utils.getHoverClass(loading, type, activeClassName)}}"
scope="{{scope}}"
onTap="{{onTap ? 'onTap' : ''}}"
onGetAuthorize="onGetAuthorize"
onFollowLifestyle="onFollowLifestyle"
onError="onError"
onGetUserInfo="onGetUserInfo"
onGetPhoneNumber="onGetPhoneNumber"
catchTap="{{catchTap ? 'catchTap' : ''}}"
publicId="{{publicId}}"
openType="{{openType}}"
class="ant-button {{inline ? 'ant-button-inline ' + utils.getClass(size) : ''}} {{'ant-button-' + type + (danger ? '-danger' : '')}} {{disabled || loading ? 'ant-button-disabled' : ''}} {{className ? className : ''}}"
style="{{style}}"
>
<view class="ant-button-wrap">
<ant-icon
a:if="{{!!icon}}"
type="{{icon}}"
></ant-icon>
<view class="ant-button-content-text {{icon ? 'ant-button-content-text-margin' : ''}}">
<slot></slot>
<view
a:if="{{!inline && subText}}"
class="ant-button-content-subtext"
>
{{subText}}
</view>
</view>
<view
a:if="{{loading}}"
class="ant-button-content-loading-container"
>
<loading
type="mini"
color="currentColor"
className="ant-button-content-loading"
></loading>
</view>
</view>
</button>

View File

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

View File

@ -0,0 +1,55 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { ButtonDefaultProps } from './props';
import fmtEvent from '../_util/fmtEvent';
Component({
props: ButtonDefaultProps,
methods: {
onTap: function (e) {
var _a = this.props, onTap = _a.onTap, disabled = _a.disabled, loading = _a.loading, onDisabledTap = _a.onDisabledTap;
if (disabled && onDisabledTap) {
var event_1 = fmtEvent(this.props, e);
onDisabledTap(event_1);
}
if (onTap && !disabled && !loading) {
var event_2 = fmtEvent(this.props, e);
return onTap(event_2);
}
},
catchTap: function (e) {
var _a = this.props, catchTap = _a.catchTap, disabled = _a.disabled, loading = _a.loading, onDisabledTap = _a.onDisabledTap;
if (disabled && onDisabledTap) {
var event_3 = fmtEvent(this.props, e);
onDisabledTap(event_3);
}
if (catchTap && !disabled && !loading) {
var event_4 = fmtEvent(this.props, e);
return catchTap(event_4);
}
},
onGetAuthorize: function (e) {
if (this.props.onGetAuthorize) {
this.props.onGetAuthorize(fmtEvent(this.props, e));
}
},
onFollowLifestyle: function (e) {
if (this.props.onFollowLifestyle) {
this.props.onFollowLifestyle(fmtEvent(this.props, e));
}
},
onError: function (e) {
if (this.props.onError) {
this.props.onError(fmtEvent(this.props, e));
}
},
onGetUserInfo: function (e) {
if (this.props.onGetUserInfo) {
this.props.onGetUserInfo(fmtEvent(this.props, e));
}
},
onGetPhoneNumber: function (e) {
if (this.props.onGetPhoneNumber) {
this.props.onGetPhoneNumber(fmtEvent(this.props, e));
}
},
},
});

View File

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

View File

@ -0,0 +1,136 @@
@import (reference) './variable.less';
@buttonPrefix: ant-button;
.@{buttonPrefix} {
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: auto;
line-height: normal;
padding: @button-padding;
border-radius: @button-corner-radius;
border: 0 none;
box-sizing: border-box;
font-size: 36 * @rpx;
z-index: 2;
&-large {
font-size: 36 * @rpx;
padding: 24 * @rpx 24 * @rpx 24 * @rpx 24 * @rpx;
}
&-medium {
font-size: 34 * @rpx;
padding: 16 * @rpx 24 * @rpx 16 * @rpx 24 * @rpx;
}
&-small {
font-size: 30 * @rpx;
padding: 8 * @rpx 24 * @rpx 8 * @rpx 24 * @rpx;
}
&-primary {
color: @button-primary-color;
background-color: @button-primary-background-color;
box-shadow: inset 0 0 0 @button-border-size @COLOR_BRAND1;
}
&-default {
color: @COLOR_BRAND1;
background-color: @COLOR_CARD;
box-shadow: inset 0 0 0 @button-border-size @COLOR_BRAND1;
}
&-text {
color: @COLOR_BRAND1;
background-color: transparent;
box-shadow: none;
}
&-primary-danger {
color: @button-danger-color;
background-color: @COLOR_RED;
box-shadow: inset 0 0 0 @button-border-size @COLOR_RED;
}
&-default-danger {
color: @COLOR_RED;
background-color: @COLOR_CARD;
box-shadow: inset 0 0 0 @button-border-size @COLOR_RED;
}
&-text-danger {
color: @COLOR_RED;
background-color: transparent;
box-shadow: none;
}
&-text-active {
background-color: fade(@COLOR_WHITE_CHANGE, 92);
}
&-active {
filter: brightness(0.92);
}
&-disabled {
opacity: @button-disabled-opacity;
}
&-wrap {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
&-content-text-margin {
margin-left: @h-spacing-standard;
}
&-content-text {
&:empty {
margin-left: 0;
width: 0;
opacity: 0;
&::after {
content: '\00a0';
}
}
}
&-content-subtext {
font-size: @button-subtext-size;
opacity: 0.6;
}
&-content-loading-container {
display: flex;
justify-content: center;
align-items: center;
width: 33px;
height: 16px;
margin-left: 8px;
}
&-content-loading {
position: relative;
}
&-inline {
display: inline-block;
border-radius: @button-inline-corner;
.@{buttonPrefix}-content-loading-container {
width: 16px;
height: 16px;
}
.@{buttonPrefix}-content-loading {
transform: scale(0.5);
}
}
}

View File

@ -0,0 +1,24 @@
function getClass(size) {
var list = ['small', 'medium', 'large'];
if (list.indexOf(size) >= 0) {
return "ant-button-".concat(size);
}
return 'ant-button-medium';
}
function getHoverClass(loading, type, activeClassName) {
if (loading) {
return '';
}
var className = 'ant-button-active';
if (type === 'text') {
className += ' ant-button-text-active';
}
if (activeClassName) {
className += ' ' + activeClassName;
}
return className;
}
export default {
getClass: getClass,
getHoverClass: getHoverClass
};

View File

@ -0,0 +1,85 @@
import { IBaseProps } from '../_util/base';
/**
* @description 按钮,用户只需单击一下即可执行操作并做出选择。
* 常用于表单提交、界面跳转、模块引导点击。具体用法和小程序框架中 button 保持一致,在 button 基础上做了样式的封装。
* 封装后的按钮可改变按钮形态、增加 loading以及内置了几种不同样式的按钮。
*/
export interface IButtonProps extends IBaseProps {
/**
* @description 按钮类型
* @default default
*/
type?: 'default' | 'primary' | 'text';
/**
* @description 是否禁用
* @default false
*/
disabled?: boolean;
/**
* @description 按下时的类名
*/
activeClassName?: string;
/**
* @description 辅助文字,显示在第二行
*/
subText?: string;
/**
* @description 内联,不撑满父级宽度
* @default false
*/
inline?: boolean;
/**
* @description 内联尺寸
* @default medium
*/
size?: 'small' | 'medium' | 'large';
/**
* @description 按钮左侧图标
*/
icon?: string;
/**
* @description 是否加载中,加载中时不可点击
* @default false
*/
loading?: boolean;
/**
* @description 是否为危险按钮,危险按钮的颜色会变成红色
* @default false
*/
danger?: boolean;
/**
* @description 按钮原生类型,在表单提交时有效
* @default button
*/
formType?: 'button' | 'submit' | 'reset';
/**
* @description 点击回调
*/
onTap?: (event: any) => void;
/**
* @description 点击回调
*/
catchTap?: (event: any) => void;
/**
* @description 禁用时点击回调
*/
onDisabledTap?: (event: any) => void;
/**
* @description 生活号 id必须是当前小程序同主体且已关联的生活号open-type="lifestyle" 时有效。
*/
publicId?: string;
/**
* @description 开放能力。
*/
openType?: string;
/**
* @description 当 openType 为 getAuthorize 时有效。
*/
scope?: string;
onGetAuthorize?: (event: any) => void;
onFollowLifestyle?: (event: any) => void;
onError?: (event: any) => void;
onGetUserInfo?: (event: any) => void;
onGetPhoneNumber?: (event: any) => void;
}
export declare const ButtonDefaultProps: Partial<IButtonProps>;

View File

@ -0,0 +1,5 @@
export var ButtonDefaultProps = {
type: 'default',
formType: 'button',
size: 'medium',
};

View File

@ -0,0 +1,85 @@
@import (reference) '../style/themes/index.less';
/* size | 按钮内间距 */
@button-padding: @size-3;
/* corner-radius| 按钮圆角 */
@button-corner-radius: @corner-radius-md;
/* font-size | 副标题字号 */
@button-subtext-size: @font-size-subcontent;
/* color | 按钮边框宽度 */
@button-border-size: @border-width-standard;
/* opacity | disable状态不透明度 */
@button-disabled-opacity: @opacity-disabled;
/* color | 默认按钮文字色 */
@button-color: @COLOR_TEXT_PRIMARY;
/* color | 默认按钮背景色 */
@button-background-color: @COLOR_WHITE_CHANGE;
/* color | 默认按钮边框色 */
@button-border-color: @COLOR_BORDER;
/* color |primary按钮背景色 */
@button-primary-background-color: @COLOR_BRAND1;
/* color |primary按钮边框色 */
@button-primary-border-color: @COLOR_BRAND1;
/* color |primary按钮文字色 */
@button-primary-color: @COLOR_WHITE;
/* color |ghost按钮边框色 */
@button-ghost-border-color: @COLOR_BRAND1;
/* color |ghost按钮文字色 */
@button-ghost-color: @COLOR_BRAND1;
/* color |danger按钮背景色 */
@button-danger-background-color: @COLOR_RED;
/* color |danger按钮边框色 */
@button-danger-border-color: @COLOR_RED;
/* color |danger按钮文字色 */
@button-danger-color: @COLOR_WHITE;
/* color |danger-ghost按钮边框色 */
@button-danger-ghost-border-color: @COLOR_RED;
/* color |danger-ghost按钮文字色 */
@button-danger-ghost-color: @COLOR_RED;
/* color |light按钮背景色 */
@button-light-background-color: @COLOR_WATHET;
/* color |light按钮边框色 */
@button-light-border-color: @COLOR_WATHET;
/* color |light按钮文字色 */
@button-light-color: @COLOR_BRAND1;
/* size | 胶囊按钮圆角 */
@button-inline-corner: @corner-radius-md;
/* size | 胶囊按钮水平内间距 */
@button-inline-padding-h: @size-3;
/* size | 胶囊按钮垂直内间距 */
@button-inline-padding-v: @size-1;
/* font-size | 胶囊按钮大字号 */
@button-inline-size-large: @font-size-subtitle;
/* font-size | 胶囊按钮中字号 */
@button-inline-size-medium: @font-size-content;
/* font-size | 胶囊按钮小字号 */
@button-inline-size-small: @font-size-subcontent;
/* 图标尺寸 */
@button-icon-size: 44 * @rpx;