<script>
	export default {
	  data(){
	    return{
        appVersion: ''
      }
    },
		onLaunch: function() {

		  // // #ifdef APP-PLUS
		  // this.getAppVersion();
		  // // #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
    methods:{
      //获取App版本号
      getAppVersion() {
        let that = this;
        console.log(plus.runtime.appid)
        plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
          that.appVersion = wgtinfo.version;
          // that.update(this.appVersion)
        });
      },
      //检查更新
      checkUpdate: function(v) {

      },
      update(widgetInfo){
        uni.request({
          url: 'http://www.example.com/update/',
          data: {
            version: widgetInfo.version,
            name: widgetInfo.name
          },
          success: (result) => {
            let data = result.data;
            if (data.update && data.wgtUrl) {
              uni.downloadFile({
                url: data.wgtUrl,
                success: (downloadResult) => {
                  if (downloadResult.statusCode === 200) {
                    plus.runtime.install(downloadResult.tempFilePath, {
                      force: false
                    }, function() {
                      console.log('install success...');
                      plus.runtime.restart();
                    }, function(e) {
                      console.error('install fail...');
                    });
                  }
                }
              });
            }
          }
        });
      }
    }
	}
</script>

<style lang="scss">
@import "./static/style/index";
	/*每个页面公共css */
</style>
