style:表格合并
Showing
6 changed files
with
140 additions
and
114 deletions
... | @@ -13,6 +13,7 @@ | ... | @@ -13,6 +13,7 @@ |
13 | "clipboard": "^2.0.11", | 13 | "clipboard": "^2.0.11", |
14 | "core-js": "^3.6.5", | 14 | "core-js": "^3.6.5", |
15 | "echarts": "^4.6.0", | 15 | "echarts": "^4.6.0", |
16 | "file-saver": "^2.0.5", | ||
16 | "js-cookie": "2.2.0", | 17 | "js-cookie": "2.2.0", |
17 | "jsoneditor": "^9.9.2", | 18 | "jsoneditor": "^9.9.2", |
18 | "lodash": "^4.17.21", | 19 | "lodash": "^4.17.21", |
... | @@ -22,10 +23,11 @@ | ... | @@ -22,10 +23,11 @@ |
22 | "vue": "2.6.10", | 23 | "vue": "2.6.10", |
23 | "vue-awesome": "^4.5.0", | 24 | "vue-awesome": "^4.5.0", |
24 | "vue-json-editor": "^1.4.3", | 25 | "vue-json-editor": "^1.4.3", |
25 | "vue-json-excel": "^0.3.0", | ||
26 | "vue-router": "3.0.2", | 26 | "vue-router": "3.0.2", |
27 | "vuex": "3.1.0", | 27 | "vuex": "3.1.0", |
28 | "xe-utils": "^3.5.7" | 28 | "xe-utils": "^3.5.7", |
29 | "xlsx": "^0.17.0", | ||
30 | "xlsx-style": "^0.8.13" | ||
29 | }, | 31 | }, |
30 | "devDependencies": { | 32 | "devDependencies": { |
31 | "@vue/cli-plugin-babel": "4.4.4", | 33 | "@vue/cli-plugin-babel": "4.4.4", | ... | ... |
... | @@ -6,7 +6,7 @@ import '@/styles/element-variables.scss' | ... | @@ -6,7 +6,7 @@ import '@/styles/element-variables.scss' |
6 | import '@/styles/index.scss' | 6 | import '@/styles/index.scss' |
7 | import Base from './base' // 全局组件引入 | 7 | import Base from './base' // 全局组件引入 |
8 | import mixin from '@/utils/mixin/theme.js' | 8 | import mixin from '@/utils/mixin/theme.js' |
9 | import JsonExcel from 'vue-json-excel' | 9 | |
10 | import dataV from '@jiaminghi/data-view'; | 10 | import dataV from '@jiaminghi/data-view'; |
11 | import echarts from "echarts" | 11 | import echarts from "echarts" |
12 | import { startLoadingAddCount, endLoadingSubCount } from './utils/requestLoading' | 12 | import { startLoadingAddCount, endLoadingSubCount } from './utils/requestLoading' |
... | @@ -44,7 +44,6 @@ import _ from 'lodash' | ... | @@ -44,7 +44,6 @@ import _ from 'lodash' |
44 | import './permission' // permission control | 44 | import './permission' // permission control |
45 | Vue.use(Element, { size: 'small', zIndex: 1000 }) | 45 | Vue.use(Element, { size: 'small', zIndex: 1000 }) |
46 | Vue.use(Base) | 46 | Vue.use(Base) |
47 | Vue.component('downloadExcel', JsonExcel) | ||
48 | Vue.component('icon', Icon); | 47 | Vue.component('icon', Icon); |
49 | Vue.prototype.$echarts = echarts | 48 | Vue.prototype.$echarts = echarts |
50 | Vue.use(dataV) | 49 | Vue.use(dataV) | ... | ... |
1 | 1 | ||
2 | import XLSX2 from "xlsx"; | ||
3 | import XLSX from "xlsx-style"; | ||
2 | /** | 4 | /** |
3 | * 获取数据类型 | 5 | * 获取数据类型 |
4 | * @param {All} [o] 需要检测的数据 | 6 | * @param {All} [o] 需要检测的数据 |
... | @@ -131,3 +133,103 @@ export function getCurrentDate (date = 'firstDay') { | ... | @@ -131,3 +133,103 @@ export function getCurrentDate (date = 'firstDay') { |
131 | return new Date(nowYear, nowMonth + 1, 0); // 本月结束时间 | 133 | return new Date(nowYear, nowMonth + 1, 0); // 本月结束时间 |
132 | } | 134 | } |
133 | } | 135 | } |
136 | |||
137 | export function setExport2Excel (exportName) { | ||
138 | /* generate workbook object from table */ | ||
139 | var wb = XLSX2.utils.table_to_sheet(document.querySelector("#mytable"));//mytable为表格的id名 | ||
140 | if (!wb['!merges']) { | ||
141 | this.$message.warning('无法导出:报表无数据'); | ||
142 | return | ||
143 | } | ||
144 | for (var i = 0; i < 11; i++) { | ||
145 | wb["!cols"][i] = { wpx: 150 } | ||
146 | } | ||
147 | // 样式的文档地址 | ||
148 | // https://www.npmjs.com/package/xlsx-style | ||
149 | for (const key in wb) { | ||
150 | if (key.indexOf('!') === -1 && wb[key].v) { | ||
151 | wb[key].s = { | ||
152 | font: {//字体设置 | ||
153 | sz: 13, | ||
154 | bold: false, | ||
155 | color: { | ||
156 | rgb: '000000'//十六进制,不带# | ||
157 | } | ||
158 | }, | ||
159 | alignment: {//文字居中 | ||
160 | horizontal: 'center', | ||
161 | vertical: 'center', | ||
162 | wrapText: 1, | ||
163 | indent: 0, | ||
164 | wrap_text: true | ||
165 | }, | ||
166 | border: { // 设置边框 | ||
167 | top: { style: 'thin' }, | ||
168 | bottom: { style: 'thin' }, | ||
169 | left: { style: 'thin' }, | ||
170 | right: { style: 'thin' } | ||
171 | } | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | var data = addRangeBorder(wb['!merges'], wb) //合并项添加边框 | ||
176 | var filedata = sheet2blob(data) | ||
177 | openDownloadDialog(filedata, exportName + ".xlsx") | ||
178 | } | ||
179 | //为合并项添加边框 | ||
180 | function addRangeBorder (range, ws) { | ||
181 | let arr = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; | ||
182 | |||
183 | range.forEach(item => { | ||
184 | let startColNumber = Number(item.s.r), endColNumber = Number(item.e.r); | ||
185 | let startRowNumber = Number(item.s.c), endRowNumber = Number(item.e.c); | ||
186 | const test = ws[arr[startRowNumber] + (startColNumber + 1)]; | ||
187 | for (let col = startColNumber; col <= endColNumber; col++) { | ||
188 | for (let row = startRowNumber; row <= endRowNumber; row++) { | ||
189 | ws[arr[row] + (col + 1)] = test; | ||
190 | } | ||
191 | } | ||
192 | }) | ||
193 | return ws; | ||
194 | } | ||
195 | //将一个sheet转成最终的excel文件的blob对象,然后利用URL.createObjectURL下载 | ||
196 | function sheet2blob (sheet, sheetName) { | ||
197 | sheetName = sheetName || 'sheet1'; | ||
198 | var workbook = { | ||
199 | SheetNames: [sheetName], | ||
200 | Sheets: {} | ||
201 | }; | ||
202 | workbook.Sheets[sheetName] = sheet; // 生成excel的配置项 | ||
203 | |||
204 | var wopts = { | ||
205 | bookType: 'xlsx', // 要生成的文件类型 | ||
206 | bookSST: false, // 是否生成Shared String Table,官方解释是,如果开启生成速度会下降,但在低版本IOS设备上有更好的兼容性 | ||
207 | type: 'binary' | ||
208 | }; | ||
209 | var wbout = XLSX.write(workbook, wopts); | ||
210 | var blob = new Blob([s2ab(wbout)], { | ||
211 | type: "application/octet-stream" | ||
212 | }); // 字符串转ArrayBuffer | ||
213 | function s2ab (s) { | ||
214 | var buf = new ArrayBuffer(s.length); | ||
215 | var view = new Uint8Array(buf); | ||
216 | for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; | ||
217 | return buf; | ||
218 | } | ||
219 | return blob; | ||
220 | } | ||
221 | function openDownloadDialog (url, saveName) { | ||
222 | if (typeof url == 'object' && url instanceof Blob) { | ||
223 | url = URL.createObjectURL(url); // 创建blob地址 | ||
224 | } | ||
225 | var aLink = document.createElement('a'); | ||
226 | aLink.href = url; | ||
227 | aLink.download = saveName || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效 | ||
228 | var event; | ||
229 | if (window.MouseEvent) event = new MouseEvent('click'); | ||
230 | else { | ||
231 | event = document.createEvent('MouseEvents'); | ||
232 | event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | ||
233 | } | ||
234 | aLink.dispatchEvent(event); | ||
235 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -25,10 +25,7 @@ | ... | @@ -25,10 +25,7 @@ |
25 | <el-form-item> | 25 | <el-form-item> |
26 | <btn nativeType="cz" @click="handleResetForm">重置</btn> | 26 | <btn nativeType="cz" @click="handleResetForm">重置</btn> |
27 | <btn nativeType="cx" @click="handleSearch">查询</btn> | 27 | <btn nativeType="cx" @click="handleSearch">查询</btn> |
28 | <download-excel class="export-excel-wrapper" :data="DetailsForm" :fields="json_fields" :header="title" | 28 | <btn nativeType="cx" @click="handlesetExport2Excel(2121)">导出</btn> |
29 | name="需要导出的表格名字.xls"> | ||
30 | <btn nativeType="cx">导出</btn> | ||
31 | </download-excel> | ||
32 | </el-form-item> | 29 | </el-form-item> |
33 | </el-col> | 30 | </el-col> |
34 | </el-row> | 31 | </el-row> |
... | @@ -36,9 +33,9 @@ | ... | @@ -36,9 +33,9 @@ |
36 | </div> | 33 | </div> |
37 | <!-- 列表区域 --> | 34 | <!-- 列表区域 --> |
38 | <div class="from-clues-content"> | 35 | <div class="from-clues-content"> |
39 | <lb-table ref="table" :page-size="pageData.size" :current-page.sync="pageData.current" :total="tableData.total" | 36 | <lb-table ref="table" :id="'mytable'" :page-size="pageData.size" :header-cell-style="headerStyle" |
40 | @size-change="handleSizeChange" @p-current-change="handleCurrentChange" :column="tableData.columns" | 37 | :current-page.sync="pageData.current" :total="tableData.total" @size-change="handleSizeChange" |
41 | :data="tableData.data"> | 38 | @p-current-change="handleCurrentChange" :column="tableData.columns" :data="tableData.data"> |
42 | </lb-table> | 39 | </lb-table> |
43 | </div> | 40 | </div> |
44 | </div> | 41 | </div> |
... | @@ -53,7 +50,7 @@ import tableMixin from "@/mixins/tableMixin.js"; | ... | @@ -53,7 +50,7 @@ import tableMixin from "@/mixins/tableMixin.js"; |
53 | //引入日期处理方法 | 50 | //引入日期处理方法 |
54 | import { timeFormat } from "@/utils/operation"; | 51 | import { timeFormat } from "@/utils/operation"; |
55 | // 获取时间 | 52 | // 获取时间 |
56 | import { getCurrentDate } from "@/utils/tools"; | 53 | import { getCurrentDate, setExport2Excel } from "@/utils/tools"; |
57 | export default { | 54 | export default { |
58 | name: "jsbwcx", | 55 | name: "jsbwcx", |
59 | mixins: [tableMixin], | 56 | mixins: [tableMixin], |
... | @@ -115,41 +112,23 @@ export default { | ... | @@ -115,41 +112,23 @@ export default { |
115 | total: 0, | 112 | total: 0, |
116 | pageSize: 10, | 113 | pageSize: 10, |
117 | current: 1 | 114 | current: 1 |
118 | }, | ||
119 | // 表格导出 | ||
120 | title: "xx公司表格", | ||
121 | json_fields: { | ||
122 | "排查日期": 'date', | ||
123 | "整改隐患内容": 'details', | ||
124 | "整改措施": 'measure', | ||
125 | "整改时限": 'timeLimit', | ||
126 | "应急措施和预案": 'plan', | ||
127 | "整改责任人": 'personInCharge', | ||
128 | "填表人": 'preparer', | ||
129 | "整改资金": 'fund', | ||
130 | "整改完成情况": 'complete', | ||
131 | "备注": 'remark', | ||
132 | }, | ||
133 | DetailsForm: [ | ||
134 | { | ||
135 | date: "2022-3-10", | ||
136 | details: "卸油区过路灯损坏", | ||
137 | measure: "更换灯泡", | ||
138 | timeLimit: "2022-3-21", | ||
139 | plan: "先使用充电灯代替,贴好安全提醒告示", | ||
140 | personInCharge: "王xx", | ||
141 | preparer: "王xx", | ||
142 | fund: "20元", | ||
143 | complete: "已完成整改", | ||
144 | remark: "重新更换了灯泡", | ||
145 | } | 115 | } |
146 | ] | ||
147 | } | 116 | } |
148 | }, | 117 | }, |
149 | created () { | 118 | created () { |
150 | this.handleResetForm() | 119 | this.handleResetForm() |
151 | }, | 120 | }, |
152 | methods: { | 121 | methods: { |
122 | headerStyle ({ row, rowIndex }) { | ||
123 | if (rowIndex == 3) { | ||
124 | row[2].rowSpan = 2; | ||
125 | row[3].rowSpan = 2; | ||
126 | row[4].rowSpan = 2; | ||
127 | } | ||
128 | }, | ||
129 | handlesetExport2Excel (val) { | ||
130 | setExport2Excel(val) | ||
131 | }, | ||
153 | //截止日期变化 | 132 | //截止日期变化 |
154 | endTimeChange (val) { | 133 | endTimeChange (val) { |
155 | this.form.endTime = timeFormat(new Date(val), true) | 134 | this.form.endTime = timeFormat(new Date(val), true) | ... | ... |
... | @@ -22,14 +22,11 @@ | ... | @@ -22,14 +22,11 @@ |
22 | </el-col> | 22 | </el-col> |
23 | <!-- 按钮操作 --> | 23 | <!-- 按钮操作 --> |
24 | <el-col :span="12" class="btnColRight"> | 24 | <el-col :span="12" class="btnColRight"> |
25 | <el-form-item class="d-flex"> | 25 | <el-form-item> |
26 | <btn nativeType="cz" @click="handleResetForm">重置</btn> | 26 | <btn nativeType="cz" @click="handleResetForm">重置</btn> |
27 | <!-- 导出excel --> | 27 | <!-- 导出excel --> |
28 | <btn nativeType="cx" @click="handleSearch">查询</btn> | 28 | <btn nativeType="cx" @click="handleSearch">查询</btn> |
29 | <download-excel class="export-excel-wrapper" :data="DetailsForm" :fields="json_fields" :header="title" | 29 | <btn nativeType="cx" @click="handlesetExport2Excel(2121)">导出</btn> |
30 | name="需要导出的表格名字.xls"> | ||
31 | <btn nativeType="cx">导出</btn> | ||
32 | </download-excel> | ||
33 | </el-form-item> | 30 | </el-form-item> |
34 | </el-col> | 31 | </el-col> |
35 | </el-row> | 32 | </el-row> |
... | @@ -37,9 +34,9 @@ | ... | @@ -37,9 +34,9 @@ |
37 | </div> | 34 | </div> |
38 | <!-- 列表区域 --> | 35 | <!-- 列表区域 --> |
39 | <div class="from-clues-content"> | 36 | <div class="from-clues-content"> |
40 | <lb-table ref="table" :page-size="pageData.size" :current-page.sync="pageData.current" :total="tableData.total" | 37 | <lb-table ref="table" :page-size="pageData.size" :id="'mytable'" :current-page.sync="pageData.current" |
41 | @size-change="handleSizeChange" @p-current-change="handleCurrentChange" :column="tableData.columns" | 38 | :total="tableData.total" @size-change="handleSizeChange" @p-current-change="handleCurrentChange" |
42 | :data="tableData.data"> | 39 | :column="tableData.columns" :data="tableData.data"> |
43 | </lb-table> | 40 | </lb-table> |
44 | </div> | 41 | </div> |
45 | </div> | 42 | </div> |
... | @@ -54,7 +51,7 @@ import tableMixin from "@/mixins/tableMixin.js"; | ... | @@ -54,7 +51,7 @@ import tableMixin from "@/mixins/tableMixin.js"; |
54 | //引入日期处理方法 | 51 | //引入日期处理方法 |
55 | import { timeFormat } from "@/utils/operation"; | 52 | import { timeFormat } from "@/utils/operation"; |
56 | // 获取时间 | 53 | // 获取时间 |
57 | import { getCurrentDate } from "@/utils/tools"; | 54 | import { getCurrentDate, setExport2Excel } from "@/utils/tools"; |
58 | export default { | 55 | export default { |
59 | name: "jsbwcx", | 56 | name: "jsbwcx", |
60 | mixins: [tableMixin], | 57 | mixins: [tableMixin], |
... | @@ -116,41 +113,16 @@ export default { | ... | @@ -116,41 +113,16 @@ export default { |
116 | total: 0, | 113 | total: 0, |
117 | pageSize: 10, | 114 | pageSize: 10, |
118 | current: 1 | 115 | current: 1 |
119 | }, | ||
120 | // 表格导出 | ||
121 | title: "xx公司表格", | ||
122 | json_fields: { | ||
123 | "排查日期": 'date', | ||
124 | "整改隐患内容": 'details', | ||
125 | "整改措施": 'measure', | ||
126 | "整改时限": 'timeLimit', | ||
127 | "应急措施和预案": 'plan', | ||
128 | "整改责任人": 'personInCharge', | ||
129 | "填表人": 'preparer', | ||
130 | "整改资金": 'fund', | ||
131 | "整改完成情况": 'complete', | ||
132 | "备注": 'remark', | ||
133 | }, | ||
134 | DetailsForm: [ | ||
135 | { | ||
136 | date: "2022-3-10", | ||
137 | details: "卸油区过路灯损坏", | ||
138 | measure: "更换灯泡", | ||
139 | timeLimit: "2022-3-21", | ||
140 | plan: "先使用充电灯代替,贴好安全提醒告示", | ||
141 | personInCharge: "王xx", | ||
142 | preparer: "王xx", | ||
143 | fund: "20元", | ||
144 | complete: "已完成整改", | ||
145 | remark: "重新更换了灯泡", | ||
146 | } | ||
147 | ] | ||
148 | } | 116 | } |
117 | }; | ||
149 | }, | 118 | }, |
150 | created () { | 119 | created () { |
151 | this.handleResetForm() | 120 | this.handleResetForm() |
152 | }, | 121 | }, |
153 | methods: { | 122 | methods: { |
123 | handlesetExport2Excel (val) { | ||
124 | setExport2Excel(val) | ||
125 | }, | ||
154 | //截止日期变化 | 126 | //截止日期变化 |
155 | endTimeChange (val) { | 127 | endTimeChange (val) { |
156 | this.form.endTime = timeFormat(new Date(val), true) | 128 | this.form.endTime = timeFormat(new Date(val), true) | ... | ... |
... | @@ -25,10 +25,7 @@ | ... | @@ -25,10 +25,7 @@ |
25 | <el-form-item> | 25 | <el-form-item> |
26 | <btn nativeType="cz" @click="handleResetForm">重置</btn> | 26 | <btn nativeType="cz" @click="handleResetForm">重置</btn> |
27 | <btn nativeType="cx" @click="handleSearch">查询</btn> | 27 | <btn nativeType="cx" @click="handleSearch">查询</btn> |
28 | <download-excel class="export-excel-wrapper" :data="DetailsForm" :fields="json_fields" :header="title" | 28 | <btn nativeType="cx" @click="handlesetExport2Excel(2121)">导出</btn> |
29 | name="需要导出的表格名字.xls"> | ||
30 | <btn nativeType="cx">导出</btn> | ||
31 | </download-excel> | ||
32 | </el-form-item> | 29 | </el-form-item> |
33 | </el-col> | 30 | </el-col> |
34 | </el-row> | 31 | </el-row> |
... | @@ -36,9 +33,9 @@ | ... | @@ -36,9 +33,9 @@ |
36 | </div> | 33 | </div> |
37 | <!-- 列表区域 --> | 34 | <!-- 列表区域 --> |
38 | <div class="from-clues-content"> | 35 | <div class="from-clues-content"> |
39 | <lb-table ref="table" :page-size="pageData.size" :current-page.sync="pageData.current" :total="tableData.total" | 36 | <lb-table ref="table" :id="'mytable'" :page-size="pageData.size" :current-page.sync="pageData.current" |
40 | @size-change="handleSizeChange" @p-current-change="handleCurrentChange" :column="tableData.columns" | 37 | :total="tableData.total" @size-change="handleSizeChange" @p-current-change="handleCurrentChange" |
41 | :data="tableData.data"> | 38 | :column="tableData.columns" :data="tableData.data"> |
42 | </lb-table> | 39 | </lb-table> |
43 | </div> | 40 | </div> |
44 | </div> | 41 | </div> |
... | @@ -53,7 +50,7 @@ import tableMixin from "@/mixins/tableMixin.js"; | ... | @@ -53,7 +50,7 @@ import tableMixin from "@/mixins/tableMixin.js"; |
53 | //引入日期处理方法 | 50 | //引入日期处理方法 |
54 | import { timeFormat } from "@/utils/operation"; | 51 | import { timeFormat } from "@/utils/operation"; |
55 | // 获取时间 | 52 | // 获取时间 |
56 | import { getCurrentDate } from "@/utils/tools"; | 53 | import { getCurrentDate, setExport2Excel } from "@/utils/tools"; |
57 | export default { | 54 | export default { |
58 | name: "jsbwcx", | 55 | name: "jsbwcx", |
59 | mixins: [tableMixin], | 56 | mixins: [tableMixin], |
... | @@ -116,40 +113,15 @@ export default { | ... | @@ -116,40 +113,15 @@ export default { |
116 | pageSize: 10, | 113 | pageSize: 10, |
117 | current: 1 | 114 | current: 1 |
118 | }, | 115 | }, |
119 | // 表格导出 | ||
120 | title: "xx公司表格", | ||
121 | json_fields: { | ||
122 | "排查日期": 'date', | ||
123 | "整改隐患内容": 'details', | ||
124 | "整改措施": 'measure', | ||
125 | "整改时限": 'timeLimit', | ||
126 | "应急措施和预案": 'plan', | ||
127 | "整改责任人": 'personInCharge', | ||
128 | "填表人": 'preparer', | ||
129 | "整改资金": 'fund', | ||
130 | "整改完成情况": 'complete', | ||
131 | "备注": 'remark', | ||
132 | }, | ||
133 | DetailsForm: [ | ||
134 | { | ||
135 | date: "2022-3-10", | ||
136 | details: "卸油区过路灯损坏", | ||
137 | measure: "更换灯泡", | ||
138 | timeLimit: "2022-3-21", | ||
139 | plan: "先使用充电灯代替,贴好安全提醒告示", | ||
140 | personInCharge: "王xx", | ||
141 | preparer: "王xx", | ||
142 | fund: "20元", | ||
143 | complete: "已完成整改", | ||
144 | remark: "重新更换了灯泡", | ||
145 | } | ||
146 | ] | ||
147 | } | 116 | } |
148 | }, | 117 | }, |
149 | created () { | 118 | created () { |
150 | this.handleResetForm() | 119 | this.handleResetForm() |
151 | }, | 120 | }, |
152 | methods: { | 121 | methods: { |
122 | handlesetExport2Excel (val) { | ||
123 | setExport2Excel(val) | ||
124 | }, | ||
153 | //截止日期变化 | 125 | //截止日期变化 |
154 | endTimeChange (val) { | 126 | endTimeChange (val) { |
155 | this.form.endTime = timeFormat(new Date(val), true) | 127 | this.form.endTime = timeFormat(new Date(val), true) | ... | ... |
-
Please register or sign in to post a comment