From e13367edf304cb78f978e321f1679299a66b3a23 Mon Sep 17 00:00:00 2001 From: quanyawei <401863037@qq.com> Date: Wed, 10 Jan 2024 16:08:18 +0800 Subject: [PATCH] fix:地图 --- uni_modules/uview-ui/components/u-code/u-code.vue | 129 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 129 insertions(+), 0 deletions(-) diff --git a/uni_modules/uview-ui/components/u-code/u-code.vue b/uni_modules/uview-ui/components/u-code/u-code.vue new file mode 100644 index 0000000..f79a09a --- /dev/null +++ b/uni_modules/uview-ui/components/u-code/u-code.vue @@ -0,0 +1,129 @@ +<template> + <view class="u-code"> + <!-- ������������������js������������������html������ --> + </view> +</template> + +<script> + import props from './props.js'; + /** + * Code ������������������ + * @description ������������������������������������������������������������������������������������������������������������������������������������������ ������������������������������������������������������������������������������������������ + * @tutorial https://www.uviewui.com/components/code.html + * @property {String | Number} seconds ��������������������������������� 60 ��� + * @property {String} startText ������������������������������������������������ '���������������' ��� + * @property {String} changeText ������������������������������������������������"x"��������������������������� 'X���������������' ��� + * @property {String} endText ��������������������������������������������������� '������������' ��� + * @property {Boolean} keepRunning ���������H5��������������������������������������������������� ������false ��� + * @property {String} uniqueKey ������������������������������������������������������������������������������������������������������ + * + * @event {Function} change ������������������������������������ + * @event {Function} start ��������������������� + * @event {Function} end ��������������������� + * @example <u-code ref="uCode" @change="codeChange" seconds="20"></u-code> + */ + export default { + name: "u-code", + mixins: [uni.$u.mpMixin, uni.$u.mixin,props], + data() { + return { + secNum: this.seconds, + timer: null, + canGetCode: true, // ��������������������������������� + } + }, + mounted() { + this.checkKeepRunning() + }, + watch: { + seconds: { + immediate: true, + handler(n) { + this.secNum = n + } + } + }, + methods: { + checkKeepRunning() { + // ���������������������������(H5���������������)������������������������������������������������������������������ + let lastTimestamp = Number(uni.getStorageSync(this.uniqueKey + '_$uCountDownTimestamp')) + if(!lastTimestamp) return this.changeEvent(this.startText) + // ��������������������� + let nowTimestamp = Math.floor((+ new Date()) / 1000) + // ������������������������������������������������������������������������������������������������������ + if(this.keepRunning && lastTimestamp && lastTimestamp > nowTimestamp) { + // ������������������������������������ + this.secNum = lastTimestamp - nowTimestamp + // ��������������������������� + uni.removeStorageSync(this.uniqueKey + '_$uCountDownTimestamp') + // ��������������� + this.start() + } else { + // ������������������������������������������������������������������������ + this.changeEvent(this.startText) + } + }, + // ��������������� + start() { + // ������������������������������������������������������������������������������������������ + if(this.timer) { + clearInterval(this.timer) + this.timer = null + } + this.$emit('start') + this.canGetCode = false + // ���������������������������������������������������������������setInterval���1��������������������� + this.changeEvent(this.changeText.replace(/x|X/, this.secNum)) + this.timer = setInterval(() => { + if (--this.secNum) { + // ������������������������������������������������������"x"������ + this.changeEvent(this.changeText.replace(/x|X/, this.secNum)) + } else { + clearInterval(this.timer) + this.timer = null + this.changeEvent(this.endText) + this.secNum = this.seconds + this.$emit('end') + this.canGetCode = true + } + }, 1000) + this.setTimeToStorage() + }, + // ��������������������������������������������� + reset() { + this.canGetCode = true + clearInterval(this.timer) + this.secNum = this.seconds + this.changeEvent(this.endText) + }, + changeEvent(text) { + this.$emit('change', text) + }, + // ������������������������������������������������������H5������������������������������������������������������ + setTimeToStorage() { + if(!this.keepRunning || !this.timer) return + // ������������������������������������������������������������������������������������������������������ + // ������������������������������������0��������������������������������������������������������������������������������������������������������������������� + if(this.secNum > 0 && this.secNum <= this.seconds) { + // ���������������������(+ new Date()���������������)���������1000��������������������������������� + let nowTimestamp = Math.floor((+ new Date()) / 1000) + // ��������������������������������������������� => ��������������� + ��������������� + uni.setStorage({ + key: this.uniqueKey + '_$uCountDownTimestamp', + data: nowTimestamp + Number(this.secNum) + }) + } + } + }, + // ��������������������������������������������������������������������������������������������������� + beforeDestroy() { + this.setTimeToStorage() + clearTimeout(this.timer) + this.timer = null + } + } +</script> + +<style lang="scss" scoped> + @import "../../libs/css/components.scss"; +</style> -- Gitblit v1.8.0