<template>
  <div class="fs-12 p-2">
    <div>
      {{ stateData[state1].msg }}
    </div>
    <div class="mt-1 text-view1 pl-2" v-if="state1 == 3">
      <el-progress :percentage="percent" class="w-100" color="#67c23a"></el-progress>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
import { ipcRenderer } from 'electron'
export default {
  name: 'Settingwin',
  data() {
    return {
      webURL: '',
      stateData: [{ code: 0, msg: '正在查询更新...' },
      { code: 1, msg: '更新出错,请重启软件' },
      { code: 2, msg: '无更新可用' },
      { code: 3, msg: '发现有新版本，正在下载' },
      { code: 4, msg: '下载完成，重启更新' },
      { code: 5, msg: '未设置更新地址' }
      ],
      state1: 0,
      percent: 0,
    }
  },
  created() {
    let locationpath = localStorage.getItem('locationpath') ? JSON.parse(localStorage.getItem('locationpath')) : {}
    this.baseURL = locationpath.baseURL || '';
    this.webURL = locationpath.webURL || '';
    this.get1()
    this.get2()
    this.sendurl()
    // console.log(this.$router)
  },
  methods: {
    ...mapActions({
      getlocationpath: 'user/getlocationpath',
    }),
    sendurl(){
      console.log(111,this.webURL)
      ipcRenderer.send('sendurl',{url:this.webURL})
    },
    get1() {
      let t = this
      ipcRenderer.on('state1', (event, data) => {
        t.state1 = data
        // console.log(59, data, t.state1)
      })
    },
    get2() {
      let t = this
      ipcRenderer.on('downloadProgress', (event, data) => {
        t.percent = (data.percent).toFixed(1);
        console.log(t.percent)
        if (data.percent >= 100) {
          t.state1 = 4;
        }
      })
    },
  }
}
</script>

<style lang="less" scoped>
.bg {
  background: #fff;
  padding: 20px;
  border-radius: 50%;
}
</style>
