Skip to content

Commit

Permalink
feat(docx): footer insert
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Dec 2, 2021
1 parent 1e45bf7 commit 1493a5a
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/use/docx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { saveAs } from 'file-saver'
import { useProjectStore } from '@/store/project'
import { Entity } from '@/types/context'
import { useEnv } from './env'
import { useNProgress } from '@vueuse/integrations'

export const useDocx = () => {
const PROJECT = useProjectStore()

const env = useEnv()
const { isLoading } = useNProgress()

const create = () => {
const properties = () => {
Expand All @@ -16,6 +18,23 @@ export const useDocx = () => {
}
}

const footer = () => {
return {
default: new docx.Footer({
children: [
new docx.Paragraph({
alignment: docx.AlignmentType.CENTER,
children: [
new docx.TextRun({
children: [docx.PageNumber.CURRENT],
}),
],
}),
],
}),
}
}

const styles = () => {
return {
default: {
Expand Down Expand Up @@ -153,7 +172,7 @@ export const useDocx = () => {
return arr
}

return { properties, styles, entities, content }
return { properties, footer, styles, entities, content }
}

const doc = (): docx.File => {
Expand All @@ -168,15 +187,22 @@ export const useDocx = () => {
{
properties: create().properties(),
children: create().content(),
footers: create().footer(),
},
],
})
}

const download = (doc: docx.File) => {
docx.Packer.toBlob(doc).then((blob) => {
saveAs(blob, PROJECT.nameRaw + '.docx')
})
isLoading.value = true

docx.Packer.toBlob(doc)
.then((blob) => {
saveAs(blob, PROJECT.nameRaw + '.docx')
})
.finally(() => {
isLoading.value = false
})
}

const generate = () => {
Expand Down

0 comments on commit 1493a5a

Please sign in to comment.