当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript formatDate.default函数代码示例

本文整理汇总了TypeScript中src/utilities/formatDate.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了default函数的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: formatDate

export const printInvoice = (
  account: Linode.Account,
  invoice: Linode.Invoice,
  items: Linode.InvoiceItem[]
) => {
  try {
    const itemsPerPage = 18;
    const date = formatDate(invoice.date, { format: 'YYYY-MM-DD' });
    const invoiceId = invoice.id;
    const itemsChunks = items ? splitEvery(itemsPerPage, items) : [[]];
    const tableEnd =
      tableBodyStart + cellHeight * itemsChunks[itemsChunks.length - 1].length;

    const doc = new jsPDF({
      unit: 'px'
    });

    const addTable = (itemsChunk: Linode.InvoiceItem[]) => {
      doc.setFontSize(10);

      const header = [
        { name: 'Description', prompt: 'Description', width: 235 },
        { name: 'From', prompt: 'From', width: 72 },
        { name: 'To', prompt: 'To', width: 72 },
        { name: 'Quantity', prompt: 'Quantity', width: 52 },
        { name: 'Unit Price', prompt: 'Unit Price', width: 67 },
        { name: 'Amount', prompt: 'Amount', width: 52 }
      ] as any[]; // assert type 'any' because per source code this is an extended and more advanced way of usage

      const itemRows = itemsChunk.map(item => {
        const { label, from, to, quantity, unit_price, amount } = item;
        return {
          Description: formatDescription(label),
          From: renderDate(from),
          To: renderDate(to),
          Quantity: renderQuantity(quantity),
          'Unit Price': renderUnitPrice(unit_price),
          Amount: '$' + amount
        };
      });

      // Place table header
      doc.table(leftPadding, 140, [], header, {
        fontSize: 10,
        printHeaders: true,
        autoSize: false,
        margins: {
          left: 15,
          top: 10,
          width: 800,
          bottom: 0
        }
      });

      // Place table body
      doc.table(leftPadding, tableBodyStart, itemRows, header, {
        fontSize: 9,
        printHeaders: false,
        autoSize: false,
        margins: {
          left: leftPadding,
          top: 10,
          width: 800,
          bottom: 0
        }
      });
    };

    const addTotalAmount = () => {
      doc.setFontSize(13);
      doc.setFontStyle('bold');
      // Empty line
      doc.cell(leftPadding, tableEnd, 412.5, 10, ' ', 1, 'left');
      // "Total" cell
      doc.cell(leftPadding, tableEnd + 10, 374, 20, 'Total:  ', 2, 'right');
      // Total value cell
      doc.cell(
        leftPadding + 300,
        tableEnd + 10,
        38.5,
        20,
        `$${Number(invoice.total).toFixed(2)}`,
        2,
        'left'
      );
      // reset text format
      doc.setFontStyle('normal');
    };

    // Create a separate page for each set of invoice items
    itemsChunks.forEach((itemsChunk, index) => {
      doc.addImage(LinodeLogo, 'JPEG', 150, 5, 120, 50);
      addLeftHeader(doc, index + 1, itemsChunks.length, date, 'Invoice');
      addRightHeader(doc, account);
      addTitle(doc, `Invoice: #${invoiceId}`);
      addTable(itemsChunk);
      addFooter(doc);
      if (index < itemsChunks.length - 1) {
        doc.addPage();
      }
//.........这里部分代码省略.........
开发者ID:displague,项目名称:manager,代码行数:101,代码来源:PdfGenerator.ts


注:本文中的src/utilities/formatDate.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。