add-to-lite.js 1.91 KB
// components/tips/add-to-lite.js
import util from '../../utils/util'
const cache_key='A2L-'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    bgColor:{
      type:String,
      value:'rgba(0,0,0,0.6)',
    },
    key:String,
    type:{
      type:String,
      value:'yellow',
    },
    hitStr:String,
  },

  /**
   * 组件的初始数据
   */
  data: {
    hidden:true,
    statusBarHeightFull:0,
  },
  attached(){
    let cacheKey=cache_key+this.data.key
    let ca=util.cache(cacheKey);
    if(ca){
      this.hide();
    }else{
      let p=getCurrentPages()
      console.log('add-to-lite.attached',p)
      if(p.length==1){
        this.show();
      }
    }

  },
  /**
   * 组件的方法列表
   */
  methods: {
    show(){
      this.triggerEvent("show");
      //导航栏自适应
      if(this.data.type=='black20'){
        let systemInfo = wx.getSystemInfoSync();
        let reg = /ios/i;
        let pt = 20;//导航状态栏上内边距
        let h = 44;//导航状态栏高度
        if(reg.test(systemInfo.system)){
          pt = systemInfo.statusBarHeight;
          h = 44;
        }else{
          pt = systemInfo.statusBarHeight;
          h = 48;
        }
        this.setData({
          hidden:false,
          statusBarHeightFull:(pt+h-5),
        })
      }else{
        this.setData({
          hidden:false,
          statusBarHeightFull:0,
        })
      }
      if(!this.timeInterval){
        this.timeIntervalNum=0;
        this.timeInterval=setInterval(()=>{
          this.hasClose();
        },1000)
      }
    },
    hasClose(){
      if(this.timeIntervalNum>=10){
        this.hide();
        clearInterval(this.timeInterval);
        return;
      }
      this.timeIntervalNum++;
    },
    hide(){
      this.triggerEvent("hide");
      let cacheKey=cache_key+this.data.key
      util.cache(cacheKey,cacheKey);
      this.setData({
        hidden:true,
      })
    },
  }
})