报名工具小程序初始代码
This commit is contained in:
108
components/SendCodeItem/SendCodeItem.vue
Normal file
108
components/SendCodeItem/SendCodeItem.vue
Normal file
@@ -0,0 +1,108 @@
|
||||
<template>
|
||||
<view :style="{'border-radius': '5rpx','height': '65rpx','width': '160rpx','text-align': 'center','line-height': '65rpx','font-size': '26rpx',
|
||||
'background-color': background,'color': 'white'}"
|
||||
@click="click">
|
||||
{{textDetail}}
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
'background': '#2fa1f0',
|
||||
"isCanClick": true,
|
||||
"textDetail": "获取验证码",
|
||||
"countdown": 60,
|
||||
'cookie': ''
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
getCookie() {
|
||||
return this.cookie;
|
||||
},
|
||||
click() {
|
||||
|
||||
if (!this.isCanClick) {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.phoneNum.length != 11 || !this.phoneNum.startsWith("1")) {
|
||||
this.Toast("请输入合法的手机号")
|
||||
} else {
|
||||
|
||||
// 更改样式并且不可点击
|
||||
this.background = "gray"
|
||||
|
||||
this.isCanClick = false
|
||||
|
||||
let timeOut = setInterval(() => {
|
||||
|
||||
if (this.countdown == 1) {
|
||||
this.textDetail = "获取验证码"
|
||||
this.countdown = 60
|
||||
clearInterval(timeOut)
|
||||
this.background = "#2fa1f0"
|
||||
|
||||
this.isCanClick = true
|
||||
} else {
|
||||
this.countdown = this.countdown - 1;
|
||||
this.textDetail = this.countdown + "s"
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
let _this = this
|
||||
|
||||
// if (this.sendByCookie != null) {
|
||||
|
||||
// // 此方法会判断是否是小程序,小程序才执行cookie
|
||||
// this.HttpCookie({
|
||||
// 'url': this.url,
|
||||
// 'data': {
|
||||
// "mobile": this.phoneNum
|
||||
// },
|
||||
// cookie: this.sendByCookie,
|
||||
// loading: true
|
||||
// }).then((res) => {
|
||||
// _this.cookie = res.data
|
||||
// }, (err) => {
|
||||
// clearInterval(timeOut)
|
||||
// this.countdown = 60
|
||||
// // 失败重置状态
|
||||
// this.background = "#2fa1f0"
|
||||
|
||||
// this.isCanClick = true
|
||||
// this.textDetail = "获取验证码"
|
||||
// })
|
||||
|
||||
// } else {
|
||||
_this.HTTP({
|
||||
url: _this.url+"?mobile="+_this.phoneNum,
|
||||
data: {},
|
||||
method: 'GET',
|
||||
paramsType: "FORM",
|
||||
loading: true
|
||||
}).then((res) => {
|
||||
_this.cookie = res.data
|
||||
console.log('=======', res)
|
||||
}, (err) => {
|
||||
clearInterval(timeOut)
|
||||
this.countdown = 60
|
||||
// 失败重置状态
|
||||
this.background = "#2fa1f0"
|
||||
|
||||
this.isCanClick = true
|
||||
this.textDetail = "获取验证码"
|
||||
})
|
||||
// }
|
||||
}
|
||||
}
|
||||
},
|
||||
props: ['phoneNum', 'url', 'data', 'sendByCookie'],
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user