qsh 3 weeks ago
parent cd3a39fa47
commit b4a5c36fb0
  1. 27
      src/utils/index.ts
  2. 7
      src/views/OKR/Analysis/index.vue
  3. 6
      src/views/OKR/Management/Components/DialogOkrInfo.vue

@ -220,3 +220,30 @@ export const removeNullField = (obj: Object) => {
} }
return obj return obj
} }
import * as XLSX from 'xlsx'
import * as FileSaver from 'file-saver'
export const exportTableWithVue = (domId: any, fileName: String) => {
// const XLSX = require('xlsx')
// 使用 this.$nextTick 是在dom元素都渲染完成之后再执行
// this.$nextTick(function () {
// 设置导出的内容是否只做解析,不进行格式转换 false:要解析, true:不解析
const xlsxParam = { raw: true }
const wb = XLSX.utils.table_to_book(document.querySelector(domId), xlsxParam)
const wbout = XLSX.write(wb, {
bookType: 'xlsx',
bookSST: true,
type: 'array'
})
try {
// 下载保存文件
FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), `${fileName}.xlsx`)
} catch (e) {
if (typeof console !== 'undefined') {
console.log(e, wbout)
}
}
return wbout
// });
}

@ -12,6 +12,7 @@
@change="nodeChange" @change="nodeChange"
/> />
<div class="flex justify-end flex-1"> <div class="flex justify-end flex-1">
<el-button type="info" @click="handleExport">导出</el-button>
<el-popover <el-popover
ref="countRef" ref="countRef"
placement="left" placement="left"
@ -42,6 +43,7 @@
</el-row> </el-row>
<el-table <el-table
id="okrAnalysisTable"
:data="originList" :data="originList"
border border
:span-method="objectSpanMethod" :span-method="objectSpanMethod"
@ -274,6 +276,7 @@ import {
getCommentPage, getCommentPage,
likeComment likeComment
} from '@/api/okr/comment' } from '@/api/okr/comment'
import { exportTableWithVue } from '@/utils'
const message = useMessage() const message = useMessage()
const defaultProps = { const defaultProps = {
@ -541,6 +544,10 @@ function handleSaveComment() {
message.error('创建失败') message.error('创建失败')
} }
} }
function handleExport() {
exportTableWithVue('#okrAnalysisTable', `OKR分析报表-${currentNode.value.nodeName}`)
}
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>

@ -449,7 +449,7 @@ function resetForm() {
startTime: undefined, startTime: undefined,
endTime: undefined, endTime: undefined,
executor: [], executor: [],
dataScope: 1 dataScope: 2
} }
} }
@ -464,7 +464,7 @@ function addObjective() {
objectiveName: '', objectiveName: '',
executor: [], executor: [],
keyResults: [], keyResults: [],
dataScope: 1 dataScope: 2
}) })
} }
@ -495,7 +495,7 @@ function removeKR(oIdx, krIdx) {
} }
function addChildNode() { function addChildNode() {
childNodeList.value.push({ dataScope: 1 }) childNodeList.value.push({ dataScope: 2 })
} }
function removeChildNode(idx) { function removeChildNode(idx) {

Loading…
Cancel
Save