|
@@ -26,6 +26,31 @@ export default function () {
|
|
|
constructor(config) {
|
|
|
const me = this
|
|
|
const {dataSource} = config
|
|
|
+
|
|
|
+ this.columnConfigCacheKey = this.makeColumnConfigCacheKey(config)
|
|
|
+ if (Array.isArray(config.columns) && config.columns.length > 0) {
|
|
|
+ const cacheData = this.getColumnConfigCache()
|
|
|
+ if (Array.isArray(cacheData) && cacheData.length > 0) {
|
|
|
+ const newColumns = []
|
|
|
+
|
|
|
+ for (let j = 0; j < cacheData.length; j++) {
|
|
|
+ const itData = cacheData[j]
|
|
|
+ for (let i = 0; i < config.columns.length; i++) {
|
|
|
+ const column = config.columns[i]
|
|
|
+ if (itData.dataIndex === column.dataIndex) {
|
|
|
+ if (itData.width) {
|
|
|
+ column.width = itData.width
|
|
|
+ }
|
|
|
+ column.hidden = itData.hidden
|
|
|
+ newColumns.push(column)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ config.columns = newColumns
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
const newConfig = _.defaultsDeep({
|
|
|
// 强制性属性
|
|
|
|
|
@@ -222,7 +247,7 @@ export default function () {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- exportExcel1(excelExportParams){
|
|
|
+ exportExcelClick(excelExportParams) {
|
|
|
const me = this
|
|
|
const {config} = me
|
|
|
excelExportParams.isExcelExport = true
|
|
@@ -231,7 +256,7 @@ export default function () {
|
|
|
|
|
|
let excelFileName = config.excelFileName || scope.vjson.title || _.uniqueId("excel-")
|
|
|
|
|
|
- gridInvokeBuild(scope, me, config, dataSource, excelExportParams, true, (responseData)=>{
|
|
|
+ gridInvokeBuild(scope, me, config, dataSource, excelExportParams, true, (responseData) => {
|
|
|
let page = parseInt(responseData.pagination.current)
|
|
|
const size = parseInt(responseData.pagination.size)
|
|
|
const total = parseInt(responseData.pagination.total)
|
|
@@ -243,13 +268,13 @@ export default function () {
|
|
|
if (excelFileName.endsWith(".xlsx")) {
|
|
|
excelFileName = excelFileName.split(".xlsx")[0]
|
|
|
}
|
|
|
- excelFileName += "(第" + me.exportExcelCurrentPage + "页,共" + Math.ceil(total/size) + "页、" + total + "条)"
|
|
|
+ excelFileName += "(第" + me.exportExcelCurrentPage + "页,共" + Math.ceil(total / size) + "页、" + total + "条)"
|
|
|
excelFileName += ".xlsx"
|
|
|
const excelData = me.makeExcelData(responseData.data)
|
|
|
LAY_EXCEL.exportExcel(excelData, excelFileName, 'xlsx')
|
|
|
|
|
|
- if (page < total/size) {
|
|
|
- page ++
|
|
|
+ if (page < total / size) {
|
|
|
+ page++
|
|
|
}
|
|
|
})
|
|
|
},
|
|
@@ -293,7 +318,7 @@ export default function () {
|
|
|
if (typeof headers[j].renderer === 'function') {
|
|
|
value = headers[j].renderer(value)
|
|
|
}
|
|
|
- row.push(value||"")
|
|
|
+ row.push(value || "")
|
|
|
}
|
|
|
data.push(row)
|
|
|
}
|
|
@@ -359,6 +384,18 @@ export default function () {
|
|
|
return false;
|
|
|
}
|
|
|
},
|
|
|
+ columnmove(sender, column, fromIndex, toIndex, eOpts) {
|
|
|
+ this.setColumnConfigCache()
|
|
|
+ },
|
|
|
+ columnhide(sender, column, eOpts) {
|
|
|
+ this.setColumnConfigCache()
|
|
|
+ },
|
|
|
+ columnshow(sender, column, eOpts) {
|
|
|
+ this.setColumnConfigCache()
|
|
|
+ },
|
|
|
+ columnresize(sender, column, width, eOpts) {
|
|
|
+ this.setColumnConfigCache()
|
|
|
+ },
|
|
|
destory() {
|
|
|
},
|
|
|
})
|
|
@@ -372,6 +409,54 @@ export default function () {
|
|
|
this.superclass.initComponent.call(this)
|
|
|
},
|
|
|
|
|
|
+ // 生成列自定义的缓存key
|
|
|
+ makeColumnConfigCacheKey(config) {
|
|
|
+ const me = this
|
|
|
+ let key = "gridColumnCache-" + window.location.href
|
|
|
+ if (config.reference) {
|
|
|
+ key += config.reference
|
|
|
+ } else {
|
|
|
+ let subKey = ""
|
|
|
+ for (let i = 0; i < config.columns.length; i++) {
|
|
|
+ const column = config.columns[i]
|
|
|
+ if (column.dataIndex) {
|
|
|
+ subKey += column.dataIndex
|
|
|
+ }
|
|
|
+ }
|
|
|
+ key += subKey
|
|
|
+ }
|
|
|
+ return key
|
|
|
+ },
|
|
|
+
|
|
|
+ getColumnConfigCache() {
|
|
|
+ const key = this.columnConfigCacheKey
|
|
|
+ const dataStr = localStorage.getItem(key)
|
|
|
+ if (dataStr) {
|
|
|
+ return JSON.parse(dataStr)
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+ },
|
|
|
+
|
|
|
+ setColumnConfigCache() {
|
|
|
+ const key = this.columnConfigCacheKey
|
|
|
+ const cacheData = []
|
|
|
+ const columns = this.headerCt.getGridColumns()
|
|
|
+ let index = 0
|
|
|
+ for (let i = 0; i < columns.length; i++) {
|
|
|
+ const column = columns[i]
|
|
|
+ if (column.dataIndex) {
|
|
|
+ cacheData.push({
|
|
|
+ dataIndex: column.dataIndex,
|
|
|
+ width: column.width,
|
|
|
+ hidden: column.hidden,
|
|
|
+ index
|
|
|
+ })
|
|
|
+ index++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ localStorage.setItem(key, JSON.stringify(cacheData))
|
|
|
+ },
|
|
|
+
|
|
|
autoSizeColumns(sender) {
|
|
|
const grid = sender.up('grid')
|
|
|
// const columns = grid.columns;
|
|
@@ -414,10 +499,10 @@ export default function () {
|
|
|
maskRe: /[0-9]/,
|
|
|
value: grid.exportExcelCurrentPage,
|
|
|
listeners: {
|
|
|
- render: (sender)=>{
|
|
|
+ render: (sender) => {
|
|
|
grid.exportExcelCurrentPageCmp = sender
|
|
|
},
|
|
|
- change: (sender, value)=> {
|
|
|
+ change: (sender, value) => {
|
|
|
let v = parseInt(value)
|
|
|
if (isNaN(v) || v === 0) {
|
|
|
window['system'].msg("页码不能为0")
|
|
@@ -426,8 +511,8 @@ export default function () {
|
|
|
}
|
|
|
const size = parseInt(grid.exportExcelPageSize)
|
|
|
const total = parseInt(grid.exportExcelTotal)
|
|
|
- if (v > total/size) {
|
|
|
- v = parseInt(total/size + "")
|
|
|
+ if (v > total / size) {
|
|
|
+ v = parseInt(total / size + "")
|
|
|
}
|
|
|
grid.exportExcelCurrentPage = v + ""
|
|
|
}
|
|
@@ -438,10 +523,10 @@ export default function () {
|
|
|
maskRe: /[0-9]/,
|
|
|
value: grid.exportExcelPageSize,
|
|
|
listeners: {
|
|
|
- render: (sender)=>{
|
|
|
+ render: (sender) => {
|
|
|
grid.exportExcelPageSizeCmp = sender
|
|
|
},
|
|
|
- change: (sender, value)=> {
|
|
|
+ change: (sender, value) => {
|
|
|
let v = parseInt(value)
|
|
|
if (isNaN(v) || v === 0) {
|
|
|
window['system'].msg("导出页大小不能为0")
|
|
@@ -450,8 +535,8 @@ export default function () {
|
|
|
}
|
|
|
let page = parseInt(grid.exportExcelCurrentPage)
|
|
|
const total = parseInt(grid.exportExcelTotal)
|
|
|
- if (page > total/v) {
|
|
|
- page = parseInt(total/v + "") + 1
|
|
|
+ if (page > total / v) {
|
|
|
+ page = parseInt(total / v + "") + 1
|
|
|
grid.exportExcelCurrentPageCmp.setValue(page)
|
|
|
}
|
|
|
grid.exportExcelPageSize = v + ""
|
|
@@ -467,8 +552,11 @@ export default function () {
|
|
|
text: '导出',
|
|
|
iconCls: 'x-fa fa-download',
|
|
|
listeners: {
|
|
|
- click: (sender, value)=> {
|
|
|
- grid.exportExcel1({exportExcelPageSize: grid.exportExcelPageSize, exportExcelCurrentPage: grid.exportExcelCurrentPage})
|
|
|
+ click: (sender, value) => {
|
|
|
+ grid.exportExcelClick({
|
|
|
+ exportExcelPageSize: grid.exportExcelPageSize,
|
|
|
+ exportExcelCurrentPage: grid.exportExcelCurrentPage
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}]
|