123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- // components/tail_tip/index.js
- import {
- getDate,
- getWaterDrop,
- formatTime
- } from '../../utils/index/index'
- const app = getApp()
- Component({
- /**
- * 组件的属性列表
- */
- properties: {},
- props: {
- onFinish: {
- type: Function,
- value: () => {}
- },
- showTitText: true, //是否显示“操作时间"
- countdown: 0, // 倒计时时间
- urlPath: '../../', //图片路径
- titleText: '', // 右侧展示页面小标题
- isHomePage: false, // 是否是首页
- },
- /**
- * 组件的初始数据
- */
- data: {
- newDate: '', //现在时间
- remainingTime: '', //倒计时剩余时间
- timer: null,
- timer2: null,
- count: 0,
- hasNetworkType: false,
- cusModalObj: {
- visible: false,
- showCloseBtn: true,
- daysDifference: 0
- },
- },
- didMount() {
- let showTitText = this.props.showTitText
- let remainingTime = showTitText ? '操作时间 ' + this.props.countdown + ' 秒' : this.props.countdown + ' 秒'
- this.setData({
- newDate: getDate(),
- remainingTime,
- })
- this.data.timer2 && clearInterval(this.data.timer2)
- let _this = this
- this.data.timer2 = setInterval(() => {
- // 获取当前时间
- const currentHour = (new Date()).getHours();
- if (currentHour == 24) {
- app.globalData.expirationDateTodayOpen = false;
- }
- _this.checkExpiryDate()
- this.setData({
- newDate: getDate()
- })
- this.getNetworkType()
- }, 1000);
- this.getNetworkType()
- this.startCountdown()
- },
- /**
- * 组件的方法列表
- */
- methods: {
- checkExpiryDate() {
- // let expiryDate = app.globalData.snDisposition.expirationDate;
- let expiryDate = '2025-01-01';
- // let expiryDate = '2024-12-26';
- if (expiryDate && expiryDate !== '') {
- let { cusModalObj } = this.data
- const now = new Date();
- // 计算当前日期
- const currentDate = new Date(formatTime(now,'YYYY-MM-DD 00:00:00'));
- // 计算到期日期
- const expiry = new Date(formatTime(expiryDate,'YYYY-MM-DD 00:00:00'));
- const timeDifference = expiry - currentDate;
- // 将毫秒转换为天数
- const daysDifference = Math.ceil(timeDifference / (1000 * 3600 * 24));
- console.log(`弹窗次数:${app.globalData.expirationDateTodayOpen}`, daysDifference);
- // 检查是否在30天内
- if (!app.globalData.expirationDateTodayOpen && !cusModalObj.visible && daysDifference <= 30 && daysDifference > 0) {
- console.log(`您的FKJ账户将在 ${daysDifference} 天后到期:${expiry.toLocaleDateString()}`);
- app.globalData.expirationDateTodayOpen = true;
- this.setData({
- 'cusModalObj.visible': true,
- 'cusModalObj.showCloseBtn': true,
- 'cusModalObj.daysDifference': daysDifference,
- })
- return;
- }
- // 如果当前日期超过到期日期
- if (!cusModalObj.visible && currentDate.getTime() >= expiry.getTime()) {
- console.log(`您的FKJ账户已到期。${expiry.toLocaleDateString()}`);
- this.setData({
- 'cusModalObj.visible': true,
- 'cusModalObj.showCloseBtn': false,
- })
- }
- }
- },
- onOk() {
- this.setData({
- 'cusModalObj.visible': false
- })
- },
- // 倒计时
- startCountdown() {
- let that = this
- let {
- count
- } = that.data
- count = that.props.countdown
- let showTitText = that.props.showTitText
- if (count && count > 0) {
- that.data.timer && clearInterval(that.data.timer)
- that.data.timer = setInterval(() => {
- count--
- let remainingTime = showTitText ? '操作时间 ' + count + ' 秒' : count + ' 秒'
- that.setData({
- remainingTime
- })
- if (count <= 0) {
- that.data.timer && clearInterval(that.data.timer)
- that.props.onFinish('finish')
- // 倒计时结束,清除定时器
- }
- }, 1000) // 每秒更新一次倒计时数字
- }
- },
- // 网络状态
- getNetworkType() {
- my.getNetworkType({
- success: (res) => {
- if (res.networkType == 'NOTREACHABLE') {
- this.setData({
- hasNetworkType: false,
- })
- my.showToast({
- content: '网络状态异常',
- duration: 2000
- });
- } else {
- this.setData({
- hasNetworkType: true,
- })
- }
- },
- fail: (error) => {
- console.log(error)
- this.setData({
- hasNetworkType: false,
- })
- },
- })
- },
- // 长按logo进入设置
- goto() {
- this.data.timer && clearInterval(this.data.timer)
- getWaterDrop()
- if (this.props.isHomePage) {
- this.clearIntervalAll()
- my.reLaunch({
- url: '/pages/settings/login/index'
- });
- }
- },
- clearIntervalAll() {
- this.data.timer && clearInterval(this.data.timer)
- this.data.timer2 && clearInterval(this.data.timer2)
- },
- onClose() {
- console.log('onclose')
- this.clearIntervalAll();
- my.reLaunch({
- url: '/pages/home/index'
- });
- }
- },
- didUnmount() {
- this.clearIntervalAll();
- },
- onUnload() {
- this.clearIntervalAll();
- },
- observers: {}
- })
|