Ver código fonte

签到有效期一天不在展示

xiabx 5 anos atrás
pai
commit
c4991771eb
3 arquivos alterados com 35 adições e 5 exclusões
  1. 26 0
      src/api/utils.js
  2. 2 2
      src/components/sign/index.ux
  3. 7 3
      src/views/Index/index.ux

+ 26 - 0
src/api/utils.js

@@ -162,3 +162,29 @@ export const validatePhone = phone => {
   const isMobile = VALIDATE_REG.test(phone);
   return isMobile;
 };
+//存储期限storge
+export const setStore = (key, value) => {
+  if (!key) return;
+  let curTime = new Date().getTime();
+  value = JSON.stringify({ data: value, time: curTime });
+  storage.set({ key: key, value: value });
+};
+
+//取期限storge expDay:storge 几天内有效
+export const getStore = async (key, expDay = 3) => {
+  if (!key) return false;
+  let storgeData = JSON.parse((await storage.get({ key: key })).data);
+  if (isExceedDay(storgeData.time, expDay)) {
+    return false;
+  } else {
+    return storgeData.data;
+  }
+};
+
+function isExceedDay(theDate, expDay) {
+  let date = new Date();
+  let targetTime =
+    new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() -
+    (expDay - 1) * 24 * 3600 * 1000;
+  return theDate < targetTime;
+}

+ 2 - 2
src/components/sign/index.ux

@@ -17,7 +17,7 @@
 </template>
 <script>
 import { userSign } from "../../api/index";
-
+import { setStore } from "../../api/utils";
 export default {
 	data: {
 		signList: [
@@ -38,7 +38,6 @@ export default {
 		this.sign();
 	},
 	async sign() {
-		console.log(this.signList,'dddd')
 		let res =	await userSign();
 		this.signData=res;
 		this.signList.forEach(item => {
@@ -46,6 +45,7 @@ export default {
 				item.iconType='checked';
 			}
 		});
+		setStore('SIGN_DATE',{isSign:true});
 	},
 	setSignPop() {
 		this.$dispatch('dispathEvt')

+ 7 - 3
src/views/Index/index.ux

@@ -43,7 +43,8 @@
 <script>
 import clipboard from '@system.clipboard';
 import prompt from '@system.prompt';
-import {downImg} from '../../api/utils.js';
+import {downImg,getStore} from '../../api/utils.js';
+import storage from "@system.storage";
 export default {
   private: {
     tabbar: [
@@ -80,8 +81,11 @@ export default {
     showPopup: false,
     showSignPop:true
   },
-  onInit(){
-      this.$on('dispathEvt',this.changeSignPop)
+  async onInit(){
+    this.$on('dispathEvt',this.changeSignPop);
+    //今日已签到过不在弹框签到
+    let signData = await getStore('SIGN_DATE',1);
+    if(signData && signData.isSign) this.showSignPop=false;
     },
   onBackPress() {
     // 退出逻辑