router.beforeEach((to, from, next) => {
    NProgress.start()
    if (getToken()) {
        if (to.path === '/login') {
            next({ path: '/' })
            NProgress.done() // if current page is dashboard will not trigger	afterEach hook, so manually handle it
        } else {
            if (store.getters.roles.length === 0) {
                store.dispatch('GetInfo').then(res => { // 拉取用户信息
                    next()
                }).catch((err) => {
                    store.dispatch('FedLogOut').then(() => {
                        Message.error(err || 'Verification failed, please login again')
                        next({ path: '/' })
                    })
                })
            } else {
                next()
            }
        }
    } else {
        if (whiteList.indexOf(to.path) !== -1) {
            next()
        } else {
            next('/login')
            NProgress.done()
        }
    }
})
Example #2
0
function MyLoadingComponent(props) {
    NProgress.start()
    if (props.isLoading) {
        // While our other component is loading...
        if (props.timedOut) {
            // In case we've timed out loading our other component.
            return (
                <div>
                    {I18n.t("LoadTimeout")}
                </div>
            )
        } else if (props.pastDelay) {
            // Display a loading screen after a set delay.
            NProgress.inc()
            // return <div>Loading...</div>
            return null
        } else {
            NProgress.done()
            // Don't flash "Loading..." when we don't need to.
            return null
        }
    } else if (props.error) {
        NProgress.done()
        // If we aren't loading, maybe
        return (
            <div>
                {I18n.t("loadFailded")}
            </div>
        )
    } else {
        NProgress.done()
        // This case shouldn't happen... but we'll return null anyways.
        return null
    }
}
router.beforeEach((to, from, next) => {
  NProgress.start()
  if (getToken()) {
    if (to.path === '/login') {
      next({ path: '/' })
      NProgress.done() // if current page is dashboard will not trigger	afterEach hook, so manually handle it
    } else {
      checkToken().then(res => { // 判断token有效性
        next()
      }).catch((err) => {
        logout().then(() => {
          Message.error(err || '已成功退出')
          removeToken()
          next({ path: '/' })
        })
      })
    }
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next('/login')
      NProgress.done()
    }
  }
})
Example #4
0
 async componentDidMount() {
   NProgress.start();
   try {
     const book = await getBookDetail({ slug: this.props.slug });
     this.setState({ book, loading: false }); // eslint-disable-line
     NProgress.done();
   } catch (err) {
     this.setState({ loading: false, error: err.message || err.toString() }); // eslint-disable-line
     NProgress.done();
   }
 }
Example #5
0
 'success': function (responseData) {
     if(!responseData.success){
         util.remind(2,"上传失败,请重新上传");
         NProgress.done();
         return;
     }
     self.set("returnValues",[]);
     self.reload();
     NProgress.done();
     util.remind(2,"上传成功");
     self.trigger("uploaded");
 }
Example #6
0
const handleSyncAllChapters = async (event) => {
  NProgress.start();
  try {
    const { bookid: bookId } = event.currentTarget.dataset;
    await syncAllChapters({ bookId });
    notify('Synced');
    NProgress.done();
  } catch (err) {
    notify(err);
    NProgress.done();
  }
};
  it("should pass on using known methods", () => {
    nprogress.start();

    nprogress.done();
    nprogress.done(true);

    nprogress.inc();
    nprogress.inc(2);

    nprogress.remove();

    nprogress.set(2);
  });
Example #8
0
  onToken = async (token) => {
    NProgress.start();
    const { book } = this.props;
    this.setState({ showModal: false });

    try {
      await buyBook({ stripeToken: token, id: book._id });
      notify('Success!');
      window.location.reload(true);
      NProgress.done();
    } catch (err) {
      NProgress.done();
      notify(err);
    }
  };
Example #9
0
 function refreshCompletion() {
     NProgress.done();
     this.refreshTimeout = setTimeout(this.refresh.bind(this), config.REFRESH_INTERVAL);
     // refresh on mobile unlock/maximize
     // don't bind until the first refresh is done unless you want a world of race conditions with the animations ;_;
     window.addEventListener('pageshow', this.refresh.bind(this));
 }
Example #10
0
export function refreshMember (data) {
  NProgress.done();
  return {
    type    : REFRESH_MEMBER,
    content : data
  };
}
Example #11
0
  response: function (response) {
    if (response.ok) {
      NProgress.done()
    }

    return response
  }
Example #12
0
 this.analyze(file).then((fields) => {
   const endTime = new Date().getTime()
   NProgress.done()
   console.log('finished', endTime - this.startTime)
   this.setState(fields)
   // this.setState.bind(this))
 })
Example #13
0
 Page.prototype.stopWait = function (event) {
     if (this.ladda) {
         this.ladda.stop();
         delete this.ladda;
     }
     NProgress.done();
 };
Example #14
0
  riot.route(route, function(...args) {
    var gateway = routes[route](args)
    if (!app) {

      // extend the gateway using the initial data
      Object.assign(gateway, initialData.gateway)
      // store the initial data
      gateway._data = initialData

      initialData.gateway = gateway
      initialData.user = new User()
      app = riot.mount('app', initialData)[0]
      NProgress.done()
    } else {
      if (!gateway.wasFetched) NProgress.start()

      gateway.fetch()
        .then(function(data) {
          data.gateway = gateway
          app.mountSubview(data)
          NProgress.done()
        })

    }
  })
Example #15
0
export function switchTo(path) {
  let p = normalize(path)
  if (!util.isTabbar(p)) throw new Error(`Can't switchTab ${path} not in tabbar config`)
  let find = false
  Object.keys(views).forEach(key => {
    let view = views[key]
    if (p == view.path) {
      find = view
    } else if (!util.isTabbar(view.path)) {
      view.destroy()
      delete views[key]
    }
  })
  if (!find) {
    let v = curr = new View(p)
    curr.pid = null
    views[v.id] = v
    tabViews[p] = curr
  } else {
    curr = find
    curr.show()
  }
  Nprogress.done()
  onRoute()
}
Example #16
0
 "onComplete":function(){
     if (self.get("suportH5")){
         NProgress.done();
         self._postData();
         self.get("attachUploader").removeAllFile();
     }
 }
 loadingChanged(newValue){
   if (newValue) {
     nprogress.start();
   } else {
     nprogress.done();
   }
 }
Example #18
0
    FormController.prototype.validate = function(form, $event) {
        $event.preventDefault();
        NProgress.start();

        var value,
            self = this,
            object = {
                id: this.data.entityId
            };

        angular.forEach(this.data.fields, function(field){
            value = field.value;
            if (field.type() === 'date') {
                value = self.$filter('date')(value, field.validation().format);
            }

            object[field.getName()] = value;
        });

        try {
            this.Validator.validate(this.data.entityName, object);
        } catch(e) {
            NProgress.done();
            humane.log(e, {addnCls: 'humane-flatty-error'});
            return false;
        }

        return object;
    };
Example #19
0
window.addEventListener('message', function (e) {
  let data = e.data || {}
  let cmd = data.command
  let msg = data.msg
  // location picker of map
  if (data.module == 'locationPicker') {
    currentView().setLocation(data)
    return
  }
  // no need for contentscript
  if (data.to == null || data.to == 'contentscript' || /^devtools/.test(data.to)) return
  if (data.command == 'EXEC_JSSDK') {
    sdk(data)
  } else if (cmd == 'TO_APP_SERVICE') {
    delete data.command
    if (msg && msg.eventName == 'publish_DOMContentLoaded') {
      Bus.emit('ready', data.webviewID)
      Nprogress.done()
    }
    toAppService(data)
  } else if (cmd == 'COMMAND_FROM_ASJS') {
    let sdkName = data.sdkName
    if (command.hasOwnProperty(sdkName)) {
      command[sdkName](data)
    } else {
      console.warn(`Method ${sdkName} not implemented for command!`)
    }
  } else if (cmd == 'PULLDOWN_REFRESH') {
    command['PULLDOWN_REFRESH'](data)
  } else if (cmd == 'WEBVIEW_READY') {
    // TODO figure out WTF is this
  } else {
    console.warn(`Command ${cmd} not recognized!`)
  }
})
 callback(err, (props) => {
   NProgress.done();
   return React.createElement(
     !hasParams(dataPath) || pageData ?
       Template.default || Template : NotFound,
     Object.assign({}, props, nextProps)
   );
 });
Example #21
0
File: view.js Project: ioPanda/erp
 .then((res) => {
   if(res){
     console.log(res.status);
   }else{
     console.log(res.status);
   }
   nprogress.done();
 })
 LoadingIndicator.prototype.loadingChanged = function (newValue) {
     if (newValue) {
         nprogress_1.default.start();
     }
     else {
         nprogress_1.default.done();
     }
 };
Example #23
0
axios.interceptors.response.use(res => {
  NProgress.done()
  // _csrf(res)
  let ct = res.headers['content-type']
  if (ct !== undefined && (ct.indexOf('application/octet-stream') >= 0 || ct.indexOf('application/vnd.ms-excel') >= 0)) {
    downloadUrl(res.request.responseURL)
  } else return res
}, err => {
Example #24
0
      complete: () => {
        const fieldsArray = analyzeRowResults(fieldsHash)

        NProgress.done()
        const endTime = new Date().getTime()
        console.log('total time', endTime - startTime)

        this.setState({ fields: fieldsArray, rowCount })
      }
    request.end((error, response) => {
        nprogress.done();

        if (error) {
            errorCb.forEach((func) => func(response));
        } else {
            successCb.forEach((func) => func(response));
        }
    });
Example #26
0
 componentDidMount() {
   NProgress.done();
   const loadingNode = document.getElementById('ant-site-loading');
   if (!loadingNode) {
     return;
   }
   this.timer = setTimeout(() => {
     loadingNode.parentNode.removeChild(loadingNode);
   }, 450);
 }
Example #27
0
 next((response) => {
   NProgress.done()
   if (response.status >= 400) {
     Vue.toastr({
       message: response.statusText,
       type: 'danger'
     })
   }
   return response
 })
Example #28
0
    axios.interceptors.response.use(response => {
      NProgress.done()

      // …get the token from the header or response data if exists, and save it.
      const token = response.headers['Authorization'] || response.data['token']
      if (token) {
        ls.set('jwt-token', token)
      }

      return response
    }, error => {
 .then(json => new Promise(function (resolve, reject) {
   switch (response.status) {
     case 401:
       reject(new Error(json.message));
       nprogress.done();
       dispatch(push('/login'));
       break;
     default:
       resolve(json);
   }
 }), error => new Promise(function (resolve, reject) {
router.beforeEach((to, from, next) => {
  NProgress.start() // start progress bar
  if (getToken()) { // determine if there has token
    /* has token*/
    if (to.path === '/login') {
      next({ path: '/' })
      NProgress.done() // if current page is dashboard will not trigger	afterEach hook, so manually handle it
    } else {
      if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息
        store.dispatch('GetUserInfo').then(res => { // 拉取user_info
          const roles = res.data.roles // note: roles must be a array! such as: ['editor','develop']
          store.dispatch('GenerateRoutes', { roles }).then(() => { // 根据roles权限生成可访问的路由表
            router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
            next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
          })
        }).catch((err) => {
          store.dispatch('FedLogOut').then(() => {
            Message.error(err || 'Verification failed, please login again')
            next({ path: '/' })
          })
        })
      } else {
        // 没有动态改变权限的需求可直接next() 删除下方权限判断 ↓
        if (hasPermission(store.getters.roles, to.meta.roles)) {
          next()//
        } else {
          next({ path: '/401', replace: true, query: { noGoBack: true }})
        }
        // 可删 ↑
      }
    }
  } else {
    /* has no token*/
    if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入
      next()
    } else {
      next('/login') // 否则全部重定向到登录页
      NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it
    }
  }
})