Newer
Older
smartwell_app_front / src / page / mine / index.vue
StephanieGitHub on 27 Aug 2021 5 KB MOD: 增加推送开关
<template>
  <transition name="slide">
    <div class="index-container">
      <!--标题-->
      <mt-header class="header" title="个人中心">
      </mt-header>
      <div class="listbody">
        <mt-cell :title="name" is-link to="/information"></mt-cell>
        <mt-cell title="帮助中心" is-link to="/helpMe"></mt-cell>
        <mt-cell title="联系客服" is-link to="/contactUs"></mt-cell>
        <!--<mt-cell title="版本更新" is-link @click.native="checkVersions"></mt-cell>-->
        <mt-cell title="关于我们" is-link to="/aboutUs"></mt-cell>
        <mt-cell title="报警推送开关">
          <!--<span style="color: green" @click="openActionSheet">开</span>-->
          <mt-button type="default" size="small" @click="openActionSheet">{{pushOpen=='0'?'关':'开'}}</mt-button>
        </mt-cell>
        <mt-actionsheet
          v-model="actionsheetConf.flag"
          :actions="actionsheetConf.actions"
          :cancelText="actionsheetConf.cancelText"
          :closeOnClickModal="actionsheetConf.closeOnClickModal">
        </mt-actionsheet>
      </div>
      <tabbottom activeTabItem="MINE"/>
    </div>
  </transition>
</template>

<script>
  import {checkVersion, downloadApk} from '@/api/app'
  import { MessageBox,Toast } from 'mint-ui';
  import { appSpApi } from '@/api/special'
  export default {
    name: "Mine",
    data() {
      return {
        name:this.$store.getters.name,
        actionsheetConf: {
          flag: false,  // 显隐控制
          actions: [  // 内容数组
            {
              name: '开',
              method: this.openPush
            },
            {
              name: '关',
              method: this.closePush
            }
          ],
          cancelText: '取消', // 取消按钮
          closeOnClickModal: false, // 是否可以点击遮罩取消
        },
        pushOpen: this.$store.getters.attr1,
        oldPushOpen: this.$store.getters.attr1
      }
    },
    methods: {
      //检查更新
      checkVersions(){
        console.log('checkVersion')
        checkVersion().then(response => {
          console.log('response:')
          const version = response.data.version
          //如果有新版本的话
          if(version!=this.$store.getters.version){
            const base_url = process.env.BASE_API + '/static/'
            MessageBox({
              title: '提示',
              message: '新版本来了,马上更新!',
              showCancelButton: true,
              confirmButtonText:'立即下载',
              cancelButtonText:'稍后再说'
            }).then(action=>{
              if(action!='cancel') {
                const url = response.data.downloadUrl
                var url2 = base_url + url
                window.open(url2);
                //
                // console.log('action:')
                // console.log(action)
                // //下载apk
                // downloadApk(url).then(res => {
                //   loading.close() // 关闭加载动画
                //   console.log('download===', res)
                //   const blob = new Blob([res.data])
                //   const downloadElement = document.createElement('a')
                //   const href = window.URL.createObjectURL(blob) // 创建下载的链接
                //   downloadElement.href = href
                //   downloadElement.download = `smartWell.apk` // 下载后文件名
                //   document.body.appendChild(downloadElement)
                //   downloadElement.click() // 点击下载
                //   document.body.removeChild(downloadElement) // 下载完成移除元素
                //   window.URL.revokeObjectURL(href) // 释放blob对象
                // }).catch((res) => {
                //   Toast(res.message);
                // })
              }
            })
          }else{
            MessageBox('提示', '当前已是最新版,无需更新');
          }
        })
      },
      openActionSheet(){
        this.actionsheetConf.flag = true
      },
      // 打开推送
      openPush(){
        this.oldPushOpen = this.pushOpen
        console.log(this.oldPushOpen, this.pushOpen)
        this.updatePushOpen('1')
      },
      // 关闭推送
      closePush(pushOpen){
        this.oldPushOpen = this.pushOpen
        console.log(this.oldPushOpen, this.pushOpen)
        this.updatePushOpen('0')
      },
      updatePushOpen(pushOpen){
        const query = {
          id: this.$store.getters.id,
          pushOpen: pushOpen
        }
        MessageBox.confirm('确定要修改报警推送配置吗?').then(action => {
          if(action=='confirm'){
            appSpApi('alarm/pushOpen',query, 'POST').then(response =>{
              if(response.code==200){
                Toast({
                  message: '修改成功',
                  position: 'bottom',
                })
                this.pushOpen = pushOpen
              }else{
                Toast({
                  message: '修改失败',
                  position: 'bottom',
                })
              }
            })
          }
        })
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
  .mint-cell-title {
    margin-left: 5px !important
  }
</style>