#let times = "Times New Roman"
#let song = (times, "Noto Serif CJK SC")
#let hei = (times, "Noto Sans CJK SC")
#let kai = (times, "Noto Serif CJK SC")
#let xbsong = (times, "Noto Serif CJK SC")
#let fsong = (times, "Noto Serif CJK SC")
#let code = (times, "Maple Mono NF CN")

#let requirement_report(
  title: "", 
  author: "", 
  id: "", 
  grade: "",
  major: "",
  department: "",
  advisor: "",
  version: "V1.0",
  date: "",
  header_str: "",
  body) = {
  
  // Set the document's basic properties.
  set document(author: author, title: title)
  set page(
    margin: (left: 30mm, right: 30mm, top: 30mm, bottom: 30mm),
  )

  // Title row.
  v(158pt)
  align(center)[
    #block(text(weight: 700, size: 30pt, font: hei, tracking: 15pt, "网络应用开发"))
  ]
  align(center)[
    #block(text(weight: 700, size: 30pt, font: song, tracking: 15pt, ""))
  ]

  v(103pt)
  pad(
    left: 1em,
    right: 1em,
    grid(
        columns: (80pt, 1fr),
        rows: (17pt, auto),
        text(weight: 700, size: 16pt, font: song, "项目名称："),
        align(center, text(weight: "regular", size: 16pt, font: song, title)),
        text(""),
        line(length: 100%)
    )
  )

  // Author information.
  v(82.5pt)

  grid(
    columns: (0.25fr, 0.25fr, 0.25fr, 0.25fr),
    rows: (15pt, 8pt, 15pt, 8pt, 15pt, 8pt, 15pt, 8pt),
    text(size: 14pt, font: song, tracking: 10pt, "开发小组"),
    align(center, text(size: 14pt, font: song, author)),
    text(size: 14pt, font: song, tracking: 10pt, "小组成员"),
    align(center, text(size: 12pt, font: song, id)),
    text(""),
    line(length: 100%),
    text(""),
    line(length: 100%),
    
    text(size: 14pt, font: song, tracking: 54pt, "专业"),
    align(center, text(size: 14pt, font: song, major)),
    text(size: 14pt, font: song, tracking: 54pt, "年级"),
    align(center, text(size: 14pt, font: times, grade)),
    text(""),
    line(length: 100%),
    text(""),
    line(length: 100%),

    text(size: 14pt, font: song, tracking: 9pt, "所属学院"),
    align(center, text(size: 14pt, font: song, department)),
    text(size: 14pt, font: song, tracking: 9pt, "指导教员"),
    align(center, text(size: 14pt, font: song, advisor)),
    text(""),
    line(length: 100%),
    text(""),
    line(length: 100%),

    text(size: 14pt, font: song, tracking: 20pt, "版本号"),
    align(center, text(size: 14pt, font: song, version)),
    text(size: 14pt, font: song, tracking: 9pt, "编写时间"),
    align(center, text(size: 14pt, font: song, date)),
    text(""),
    line(length: 100%),
    text(""),
    line(length: 100%),
  )

  v(35pt)
  align(center)[#image("figures/logo-long.png", width: 6cm)]

  pagebreak()
  
  set page(
    margin: (left: 30mm, right: 30mm, top: 30mm, bottom: 30mm),
    numbering: "i",
    number-align: center,
  )

  v(14pt)
  align(center)[
    #block(text(font: hei, size: 14pt, "《项目需求分析报告》编写说明"))
  ]

  v(14pt)
  text("")
  par(first-line-indent: 2em, text(font: song, size: 12pt, "项目需求分析报告应符合以下要求："))
  
  par(first-line-indent: 2em, text(font: fsong, size: 12pt, "（1）采用A4（21cm×29.7cm）白色复印纸。页边距均为3cm；正文字号为小4号，中文宋体，英文Times New Roman，每页30行，页码居中。"))

  par(first-line-indent: 2em, text(font: fsong, size: 12pt, "（2）报告主要涵盖：引言（目的、背景）、项目概述（功能、环境）、功能性需求（详细功能描述）、非功能性需求（性能、安全、可靠性）以及外部接口需求。"))

  par(first-line-indent: 2em, text(font: fsong, size: 12pt, "（3）应结合图表（如UML用例图、流程图）对需求进行辅助说明，图表需有编号和名称。"))

  pagebreak()

  set page(
    margin: (left: 30mm, right: 30mm, top: 30mm, bottom: 30mm),
    numbering: "1",
    number-align: center,
  )

  set heading(numbering: "1.1")
  
  show heading: it => box(width: 100%)[
    #v(0.50em)
    #set text(font: hei)
    #if it.numbering != none {
      counter(heading).display()
      h(0.5em)
    }
    #it.body
  ]
  // Main body.
  set par(justify: true, first-line-indent: 2em)

  body
}

#let para(t) = par(text(font: song, size: 10.5pt, t))

#let abstract-keywords(abstract: none, keywords: "") = {
  if abstract != none {
    place(
      top + center,
      scope: "parent",
      float: true,
      block(width: 100%)[
        #set par(justify: true, first-line-indent: 0pt)
        #text(font: hei, size: 10.5pt)[【摘 要】]
        #text(font: song, size: 9pt)[#abstract]
        
        #v(0.8em)
        #text(font: hei, size: 10.5pt)[【关键词】]
        #text(font: hei, size: 10.5pt)[#keywords]
        #v(1.5em)
      ]
    )
  }
}
