繁体   English   中英

在meteor中将表数据导出到excel

[英]export table data into excel in meteor

在我的应用程序起始 URL localhost:3000带我登录页面,在我登录后,它需要/afterlogin现在一切正常,一旦我删除/afterlogin并输入它将再次登录页面如何在登录后阻止该 url并留在流星主页?

与其使用 / 作为用户登录的 URL,更多“Meteor.js”要做的事情是在您网站的登录页面的主模板中使用条件逻辑。 Accounts的 Meteor 文档解释说应用程序应该:

使用{{#if currentUser}}检查用户是否登录。

查看登录示例应用程序,了解如何在实践中应用{{#if currentUser}} 为方便起见,我复制了以下模板:

<template name="main">
  {{#if loggingIn}}
    <div class="loading">Loading...</div>
  {{else}}
    {{#if currentUser}}
      <div class="msgDiv">
        Signed in as: {{currentUser.services.google.email}}
      </div>
      <a href="#" id="logout">Sign out</a>
    {{else}}
      <a href="#" id="login">Sign In With Google</a>
    {{/if}}
  {{/if}}
  <div class="msgDiv">
    Client can see {{numGizmos}} gizmos.
  </div>
</template>

在“主”模板中,您可以看到应用程序使用空格键检查以下条件:

  • 如果loggingIn为 true(用户正在登录),则显示加载屏幕
  • 如果loggingInfalse currentUsertrue (用户已经登录),则显示带有登录用户信息的屏幕
  • 如果loggingInfalse currentUserfalse (用户尚未登录),则显示登录提示

注意:在此示例应用程序中,他们演示了使用accounts-google身份验证包进行登录,但您可以对基于accounts-password的基本登录使用相同的模式。 其他身份验证包包括accounts-facebookaccounts-githubaccounts-twitter和社区包。

如果您在应用程序中使用iron:router ,那么您还可以使用如下逻辑保护应用程序 URL(取自文档):

Router.onBeforeAction(function() {
  if (! Meteor.userId()) {
    this.render('login');
  } else {
    this.next();
  }
});

第1步从npm下载“alasql,XLSX,moment”包//meteor npm install alasql

步骤 2将 alasql 、 XLSX 和 moment 导入文件形式,我们必须在其中创建 excel

            import alasql from 'alasql';
            import XLSX from 'xlsx';
            import moment from "moment";

            alasql.utils.isBrowserify = false;
            alasql.utils.global.XLSX = XLSX;

在同一个文件中的第 3 步通过调用该方法从服务器获取数据

          Meteor.call('getAllUserData', function ( err,userData ) { //get data form server call
        
            if ( !_.isEmpty( userData ) )
            {
                var opts = [
                    {sheetid:'User List',header:true}
                ];
                alasql('SELECT INTO XLSX("User-List-'+moment(new Date()).format('DD-MM-YYYY')+'.xlsx",?) FROM ?',
                    [opts,[
                        userData
                    ]]);
            }
        })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM