loulijun2021
2022-10-07 49b1409c6886034321042f9e7e19d119f1fe3901
src/views/kb/cgdd.vue
@@ -263,6 +263,8 @@
  },
  data() {
    return {
      onLine: navigator.onLine, // 监听网络是否在线
      headTime: '',
      purchaseLeftTopData: [],
@@ -272,8 +274,11 @@
      number1: '',
      MarqueeTipsContent: '', // 公告
      speed: 100// 公告播放的速度
      speed: 100, // 公告播放的速度
      PurchaseLeftTop: null,
      PurchaseLeftBottom: null,
      PurchaseRight: null
    }
  },
@@ -281,13 +286,49 @@
    setInterval(this.getNowTime, 1000)
  },
  mounted() {
    this.getPurchaseLeftTop()
    this.getPurchaseLeftBottom()
    this.getPurchaseRight()
    this.getMarqueeTipsContent()
    window.addEventListener('online', this.updateOnlineStatus)
    window.addEventListener('offline', this.updateOnlineStatus)
    this.updateOnlineStatus({ type: this.onLine ? 'online' : 'offline', isFirst: true })
  },
  beforeDestroy() {
    window.removeEventListener('online', this.updateOnlineStatus)
    window.removeEventListener('offline', this.updateOnlineStatus)
  },
  methods: {
    // 更新网络状态
    updateOnlineStatus(e) {
      if (e.isFirst) {
        this.getPurchaseLeftTop()
        this.getPurchaseLeftBottom()
        this.getPurchaseRight()
        // this.getMarqueeTipsContent()
      } else {
        const loading = this.$loading({
          lock: true,
          text: '断网了,正在拼命联网中,请检查网络是否正常...',
          spinner: 'el-icon-loading',
          customClass: 'osloading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
        const { type } = e
        this.onLine = type === 'online'
        if (this.onLine) {
          this.getPurchaseLeftTop()
          this.getPurchaseLeftBottom()
          this.getPurchaseRight()
          // this.getMarqueeTipsContent()
          loading.close()
          this.$message.success('网络连接成功!')
        } else {
          clearInterval(this.PurchaseLeftTop)
          clearInterval(this.PurchaseLeftBottom)
          clearInterval(this.PurchaseRight)
          this.$message.error('网络掉线,请关注网络状态!')
        }
      }
    },
    // 获取公告
    getMarqueeTipsContent() {
      // this.MarqueeTipsContent = '各位员工们:根据上级的通知,结合我企实际情况,现将20xx年的元旦放假通知如下:一、1月1日至1月3日放假调休,共3天。1月4日正式上班。二、节假日期间,各班组要严格落实上级的重要指示精神,按照上级的具体要求,认真抓好落实节日期间值班备勤工作,确保节日期间企业各项工作正常运转。xx企业20xx年12月28日'
@@ -300,13 +341,12 @@
        this.purchaseLeftTopData = res.data[0]
        // console.log(this.purchaseLeftTopData)
      })
      setInterval(() => {
      this.PurchaseLeftTop = setInterval(() => {
        PurchaseLeftTop().then(res => {
          this.purchaseLeftTopData = res.data[0]
        })
      }, 1000 * 6)
    },
    getPurchaseLeftBottom() {
      PurchaseLeftBottom().then(res => {
        this.tableData = res.data
@@ -314,7 +354,7 @@
        const divData = this.$refs.tableData.bodyWrapper
        // 拿到元素后,对元素进行定时增加距离顶部距离,实现滚动效果(此配置为每100毫秒移动1像素)
        const task = setInterval(() => {
        this.PurchaseLeftBottom = setInterval(() => {
          // 元素自增距离顶部1像素
          divData.scrollTop += 1
          // 判断元素是否滚动到底部(可视高度+距离顶部=整个高度)
@@ -325,7 +365,7 @@
              this.tableData = res.data
              this.number1 = this.tableData.length
              if (this.tableData.length > 14) {
                clearInterval(task)
                clearInterval(this.PurchaseLeftBottom)
                this.getPurchaseLeftBottom()
              }
            })
@@ -333,13 +373,12 @@
        }, this.tableData.length <= 14 ? 1000 * 3 : 100)
      })
    },
    getPurchaseRight() {
      PurchaseRight().then(res => {
        this.tableDataRank = res.data
        const divData = this.$refs.tableDataRank.bodyWrapper
        // 拿到元素后,对元素进行定时增加距离顶部距离,实现滚动效果(此配置为每100毫秒移动1像素)
        const task = setInterval(() => {
        this.PurchaseRight = setInterval(() => {
          // 元素自增距离顶部1像素
          divData.scrollTop += 1
          // 判断元素是否滚动到底部(可视高度+距离顶部=整个高度)
@@ -349,7 +388,7 @@
            PurchaseRight().then(res => {
              this.tableDataRank = res.data
              if (this.tableDataRank.length > 21) {
                clearInterval(task)
                clearInterval(this.PurchaseRight)
                this.getPurchaseRight()
              }
            })