basecomp.forEach(function (comp) {
  try{
    var obj = eval("(" + comp + ")");
    Vue.component(obj.vname, obj);
  }catch(e){
    console.log(e);
  }
});
  console.log("load base component finished...");
  function buildPromise(compath){
     return Promise.resolve(new Promise(function(resolve,reject){
       //异步加载组件
       axios.get(compath).then(function(res){
          console.log(compath);
         // var obj=eval("("+res.data+")");
          var obj = eval("(" + unescape(res.data) + ")");
          resolve(obj);
       }).catch(function(reason){
         console.log(reason)
       })
     }));
  }
  function componentFactory(comname){
    var compath="/vue/comp/"+comname;
    var tmpFunc=function(){
      return buildPromise(compath);
    }
    return tmpFunc;
  }
  window.componentFactory=componentFactory;
  const store = new Vuex.Store({
    state: {
      currentCodePath:"",
      currentUser:null,
      curSelRow:{},
      company:null,
    },
  });
  Vue.mixin({
    props:["groupName","modelName"],
    computed:Vuex.mapState({
      currentUser:state=>{
        return  state.currentUser;
      },
      codePath:state=>{
         return state.currentCodePath;
      },
      ctlName:function(){
         return this.groupName +"/"+this.modelName+"Ctl";
      },
      currentCompany:state=>{
        return state.company;
      },
    }),
    methods:{
      getUrl(md){
        return "web/"+this.ctlName+"/"+md;
      },
    }
  });
  var routes=[];
  var codepaths={};
  axios.get("/web/common/metaCtl/getRouteConfig").then(d=>{
    Object.keys(d.data.data.bizs).map((k)=>{
      //path是路由，静态的路由
      var pathTmp=d.data.data.bizs[k].path;
      var codepath=d.data.data.bizs[k].codepath;
      var tmp={"path":pathTmp,"components":{
        "default":componentFactory(d.data.data.bizs[k].comname)
      },};
       routes.push(tmp);
       codepaths[pathTmp]=codepath;//暂存每个叶子节点对应的codepath
    });
    console.log(routes);
    var router=new VueRouter({
      routes:routes,
    });

    router.beforeEach((to, from,next) => {
      store.state.currentCodePath = codepaths[to.path];
      store.state.company=companyinfo;
       next();
    });
    var app = new Vue({
      el:"#app",
      router:router,
      store:store,
      data:function(){
        return {
          loading:true,
          logins:[
          
          ],
          ismenuopen:true,
          outheight:0,
          tocomany:tocompanyinfo,
        };
      },
      created(){
          $(window).resize(()=>{
            this.initWindowShow();
          });
          this.initWindowShow();
          this.loading=false;
          this.$store.state.company=companyinfo;
      },
      updated(){
  
      },
      mounted(){
        var self=this;
        if(!this.currentUser){
          this.logins.push({"icon":"el-icon-location-outline","title":"登录","type":"text",key:"login","isOnGrid":true});
          this.logins.push({"icon":"el-icon-edit-outline","title":"注册","type":"text",key:"register","isOnGrid":true});
        }else{
          this.logins.push({"icon":"el-icon-arrow-right","title":"退出","type":"text",key:"exit","isOnGrid":true});
        }
        this.checkLogin(()=>{
          if(location.hash=="#/"){
            this.$router.push("/myappinfo");
          }

        });
      },
      methods:{
          showmenu(){
            if(this.ismenuopen){
              $("#leftmenuid").fadeOut(1500);
              $("#clkhandle").css("left","25px");
              this.ismenuopen=false;
            }else{
              $("#leftmenuid").fadeIn(1500);
              $("#clkhandle").css("left","240px");
              this.ismenuopen=true;
            }
          },
          cmpsclick(){
            // this.$router.push("/companyinfo");
          },
          appclick(){
            location.href=appinfo.homePage;
          },
          initWindowShow(){
            var h=$(window).height();
            var m=h-90;
            this.outheight=m;
            $("#app").css("min-height",h+"px");
            $("#app-stage").css("min-height",m+"px");
            $("#app").css("visibility",'visible');
          },
          localdata(key,item){
            if(item){
              localStorage.setItem(key,JSON.stringify(item));
            }else{
              var strobj=localStorage.getItem(key);
              if(strobj){
                return  JSON.parse(strobj);
              }else{
                return null;
              }

            }
        },
        showMask(){
          this.loading=true;
        },
        hideMask(){
          this.loading=false;
        },
        onMenuSelect: function (index,keyIndex) {
          console.log(index);
          this.$router.push(index);
        },
        formatItem: function (t, label) {
          if (t) {
            if (!label && t.src) {//表示当前是image元素
              if (this.currentUser) {
                return this.currentUser.imgUrl;
              }
              return t.src;
            } else {
              return label;
            }
          }
        },
        clkapp(){
          location.href=appinfo.homePage;
        },
        async exitclick(){
          var d=  await this.$root.postReq("/web/auth/userCtl/exit",{});
          location.href=appinfo.homePage;
        },
        async checkLogin(cbk){
          var d=  await this.$root.postReq("/web/auth/userCtl/checkLogin",{});
          if(d && d.status==0 && d.data){
              this.$store.state.currentUser=d.data;
             if(cbk){
              cbk();
             }

          }else{
            //alert("no login");
            if(cbk){
              cbk();
             }
            location.href=appinfo.homePage;
          
          }
        },
        getReq(path,data){
          var self=this;
          return axios.get(path,{params:data,"headers":{"codepath":this.codePath}}).then(function(r){
            if(r && r.data && r.data.status==-99){
              self.$store.state.currentUser=null;
              self.hideMask();
              self.$router.push("/");
              self.$message({
                message: '扫码成为合伙人',
                type: 'warning'
              });
              self.showLogin();
              return null;
            }else{
              if(r.data && r.data.bizmsg && r.data.bizmsg!="empty"){
                self.$message({
                  message: r.data.bizmsg,
                  type: 'warning'
                });
              }
              return r.data?r.data:null;;
            }
          });
        },
        postReq(path,data){
          return axios.post(path,data,{"headers":{'codepath': this.codePath}}).then(function(r){
            if(r && r.data && r.data.status==-99){
              self.$store.state.currentUser=null;
              self.hideMask();
              self.$router.push("/");
              self.$message({
                message: '扫码成为合伙人',
                type: 'warning'
              });
              self.showLogin();
              return null;
            }else{
              return r.data?r.data:null;
            }
          });
        },
      },
    });
  });
//});
