var tmpl=`
    <el-button v-if="!isLogin" :type="type" ><a :href="opath" style=" text-decoration:none; "><slot>OAUTH授权登录</slot></a></el-button>
`
module.exports=
`{
   template:'${tmpl}',
   props:['type'],
   data:function(){
     return {
       isLogin:false,
       opath:"",
     };
   },
   mounted:function(){
      this.$nextTick(()=>{
        this.checkLogin();
      });
   },
   created:function(){

   },
   methods:{
     checkLogin(){
         var self=this;
         this.$root.getReq("/web/userCtl/checkLogin",{}).then(function(d){
           /*检查之前先缓存请求字符串*/
           var q=self.$router.history.current.query;
           if(q && q.from){
             localStorage.setItem("query",JSON.stringify(q));
           }
           console.log("qqqqqqqqqqqqqqqqqqqqqqqqqqqqq");
           console.log(q);
           console.log(localStorage);
           if(d && d.status==0){
             self.$store.state.currentUser=d.data;
             self.isLogin=true;

             var qtmp=localStorage.getItem("query");
             if(qtmp!=""){
                qtmp=JSON.parse(qtmp);
             }else{
                qtmp=null;
             }
             self.$emit("logined",qtmp);
           }else{
             self.$store.state.currentUser=null;
             self.isLogin=false;
           }
         }).then(()=>{
            if(!self.isLogin){
              self.fetchOAuthPath();
            }
         });
     },
     fetchOAuthPath(){
         var self =this;
         this.$root.postReq("/web/wxCtl/fetchOAuthPath",{}).then(function(d){
           if(d && d.status==0){
             self.opath=d.data;
             console.log("11111111111111111111111111111111111111111111");
             console.log(self.opath);
           }
         });
     },
   },
   vname:"gsb-wxoauth"
}`
