当前位置: 首页 > news >正文

能在线做实验的网站福田网站建设制作

能在线做实验的网站,福田网站建设制作,html静态网页制作案例,个人网站首页布局图组件介绍 这是一个用于获取验证码的倒计时按钮组件&#xff0c;支持自定义倒计时时间、按钮样式和文字格式。 基本用法 <countdown-verify seconds"60"button-text"获取验证码"bind:send"onSendVerifyCode" />属性说明 属性名类型默认…

组件介绍

这是一个用于获取验证码的倒计时按钮组件,支持自定义倒计时时间、按钮样式和文字格式。

基本用法

<countdown-verify seconds="60"button-text="获取验证码"bind:send="onSendVerifyCode"
/>

属性说明

属性名类型默认值说明
secondsNumber60倒计时总时长(秒),必须大于0
buttonTextString“获取验证码”按钮默认显示的文字
countdownFormatString“剩余%s秒”倒计时过程中显示的文字格式,%s会被替换为剩余秒数
buttonStyleString“”按钮的样式,支持内联样式
disabledStyleString“background-color: #cccccc; color: #ffffff;”倒计时过程中按钮的样式
instanceIdString“”组件实例ID,用于多实例区分,不传会自动生成

事件说明

事件名说明参数
send点击获取验证码按钮时触发{ instanceId: string }
start倒计时开始时触发{ instanceId: string }
end倒计时结束时触发{ instanceId: string }

方法说明

方法名说明参数返回值
start()开始倒计时
stop()停止倒计时
reset()重置倒计时
getStatus()获取当前状态{ isCounting: boolean, remaining: number, instanceId: string }

使用示例

Page({data: {// ...},onSendVerifyCode(e) {// 发送验证码请求wx.request({url: 'your-api-url',success: () => {// 请求成功后开始倒计时this.selectComponent('#verifyCode').start();}});}
});

注意事项

组件会自动处理倒计时过程中的状态切换
倒计时过程中按钮会被禁用
组件销毁时会自动清理定时器
支持多个实例同时使用,每个实例都有唯一的instanceId
倒计时时间必须大于0,否则会自动设置为60秒

样式定制

可以通过 buttonStyle 和 disabledStyle 属性来自定义按钮样式,支持所有CSS属性。

<countdown-verify button-style="background-color: #007AFF; color: white; border-radius: 4px;"disabled-style="background-color: #999999; color: white;"
/>

完整代码

js

// components/countdown-verify/countdown-verify.js
Component({properties: {// 倒计时总时长(秒)seconds: {type: Number,value: 60,observer: function (newVal) {if (newVal <= 0) {console.warn("倒计时时间必须大于0");this.setData({ seconds: 60 });}},},// 按钮默认文字buttonText: {type: String,value: "获取验证码",},// 禁用状态下的文字格式countdownFormat: {type: String,value: "剩余%s秒",},// 按钮样式buttonStyle: {type: String,value: "",},// 禁用状态按钮样式disabledStyle: {type: String,value: "background-color: #cccccc; color: #ffffff;",},// 实例ID,用于多实例区分instanceId: {type: String,value: "",},},data: {remaining: 0,isCounting: false,timer: null,displayText: "",},lifetimes: {attached() {// 生成唯一实例IDif (!this.properties.instanceId) {this.setData({instanceId:"countdown_" +Date.now() +"_" +Math.random().toString(36).substr(2),});}this.updateDisplayText();},detached() {this.clearTimer();},},// 监听倒计时和是否正在倒计时,更新显示文本observers: {"remaining, isCounting": function (remaining, isCounting) {this.updateDisplayText();},},methods: {// 更新显示文本updateDisplayText() {const text = this.data.isCounting? this.properties.countdownFormat.replace("%s", this.data.remaining): this.properties.buttonText;this.setData({ displayText: text });},// 开始倒计时start() {if (this.data.isCounting) {console.warn("倒计时正在进行中");return;}this.clearTimer();this.setData({isCounting: true,remaining: this.properties.seconds,});this.data.timer = setInterval(() => {const remaining = this.data.remaining - 1;if (remaining <= 0) {this.stop();return;}this.setData({ remaining });}, 1000);this.triggerEvent("start", { instanceId: this.data.instanceId });},// 停止倒计时stop() {this.clearTimer();this.setData({isCounting: false,remaining: 0,});this.triggerEvent("end", { instanceId: this.data.instanceId });},// 清除定时器clearTimer() {if (this.data.timer) {clearInterval(this.data.timer);this.data.timer = null;}},// 按钮点击事件handleTap() {if (!this.data.isCounting) {this.triggerEvent("send", { instanceId: this.data.instanceId });}},// 重置倒计时reset() {this.stop();},// 获取当前状态getStatus() {return {isCounting: this.data.isCounting,remaining: this.data.remaining,instanceId: this.data.instanceId,};},},
});

wxml

<!-- components/countdown-verify/countdown-verify.wxml -->
<button style="{{isCounting ? disabledStyle : buttonStyle}}" disabled="{{isCounting}}" bind:tap="handleTap" aria-label="{{isCounting ? '倒计时中' : buttonText}}" data-instance-id="{{instanceId}}">{{displayText}}
</button>

wxss

/* components/countdown-verify/countdown-verify.wxss */
button {margin: 0;padding: 0;border: none;background: none;font-size: 28rpx;line-height: 1.5;text-align: center;border-radius: 8rpx;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;min-width: 180rpx;height: 80rpx;display: flex;align-items: center;justify-content: center;
}button[disabled] {opacity: 0.6;
}
button::after {border: none;
}

json

{"component": true,"usingComponents": {}
}
http://www.dtcms.com/a/562618.html

相关文章:

  • 国际婚恋网站排名wordpress 菜单添加图标
  • 一般网站的后台怎么做的网站调研表
  • 一级域名做网站的好处rails网站开发
  • 自己怎样注册企业网站集团公司网站源码
  • 使用 CloudWatch Logs Insights 分析 Amazon Bedrock 调用延迟
  • 快捷的网站建设软件六盘水做网站
  • 网站开发资金尚层别墅装饰公司官网
  • 网站源码生成知名的中小企业有哪些
  • PCB设计<囫囵吞枣学习法>: 22_PCB设计之设计规则检查
  • 重庆工程建设招标网官方网站广州货运网站建设
  • 银川建企业模板网站网页制作企业网站作业
  • 网站建设有哪些困难房卡app游戏开发
  • 网站建设策划完整方案电商设计培训学校
  • 黄石建设信息网站电商网站建设计入什么科目
  • 多个织梦dedecms网站怎么做站群青海响应式网站建设
  • js做示爱网站例子排名第一的玉米品种
  • 电子商务网站建设需要注意什么外贸企业网站系统源码
  • 复盘与导出工具最新版V34.0版本更新----修复精选个股,今日龙一,风向标,实时盯盘 涨停股竞价 昨日涨停 板块轮动 题材库 失效问题
  • 广州网站建设哪家好个人如何注册公司流程
  • 大作设计网站官网入口做擦边球网站
  • 酵母表面展示技术:蛋白工程的“高通量筛选利器”
  • 让老MP3焕发新生!Rockbox开源固件
  • 门户网站构建国家备案网
  • sourceforge下载提速的方法
  • 网站开发需求分析word微信官网下载安装微信
  • 电影资源分享网站怎么做的网站设计注意因素
  • 郑州建站推广公司优质的广州做网站
  • wordpress 建立网站学生个人网站建设方案书框架栏目
  • 打工人日报#20251102
  • 32HAL——舵机DRV8833驱动电机