Skip to content

Commit

Permalink
table out
Browse files Browse the repository at this point in the history
  • Loading branch information
szuprefix committed Jul 10, 2019
1 parent 4c3759a commit 5fee752
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/components/rest/ModelBatchCreator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<script>
import BatchCreator from '../../utils/batch_creator'
import CsvInput from '../widgets/CsvInput.vue'
import DataTable from '../layout/table/DataTable.vue'
import DataTable from '../table/DataTable.vue'
import queue_limit from '../../utils/async_queue'
export default{
props: {
Expand Down
18 changes: 9 additions & 9 deletions src/components/sheets/Block.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

</template>
<script>
import DataTable from '../layout/table/DataTable.vue'
import DataTable from '../table/DataTable.vue'
import ActionLabel from './ActionLabel.vue'
import EditableLabel from '../widgets/EditableLabel.vue'
import select_actions from './mixins/select_action'
import {set, unset, uniqueId, pick, range} from 'lodash'
import sheets from '../../utils/sheets'
import {ColumnUtil} from '../../utils/sheets'
export default{
mixins: [select_actions],
props: {
Expand All @@ -26,7 +26,7 @@
ActionLabel,
EditableLabel,
actions: [
{name: 'delete', label: '删除整列', postAction: this.deleteColumn, do: this.toDoSelectionAction},
{name: 'drop', label: '删除整列', postAction: this.dropColumn, do: this.toDoSelectionAction},
{name: 'merge', label: '合并字段', postAction: this.mergeColumn, do: this.toDoSelectionAction},
{
name: 'splitline2column',
Expand All @@ -53,7 +53,7 @@
return fields
},
headerChange ({context, newValue, oldValue}){
sheets.renameColumn(this.value, [oldValue, newValue])
ColumnUtil.rename(this.value, [oldValue, newValue])
},
mergeColumn(){
let fl = this.selection.list
Expand All @@ -63,20 +63,20 @@
}
this.selection.show = false
this.loading = '合并中...'
sheets.mergeColumn(this.value, fl)
ColumnUtil.merge(this.value, fl)
this.loading = false
},
deleteColumn(){
dropColumn(){
this.selection.show = false
this.value.fields = this.value.fields.filter(a => !this.selection.list.includes(a.name))
ColumnUtil.drop(this.value, this.selection.list)
},
splitLine2Column(){
this.selection.show = false
sheets.splitLine2Column(this.value, this.selection.list)
ColumnUtil.splitLine2Column(this.value, this.selection.list)
},
splitLine2Row(){
this.selection.show = false
sheets.splitLine2Row(this.value, this.selection.list)
ColumnUtil.splitLine2Row(this.value, this.selection.list)
}
},
computed: {}
Expand Down
19 changes: 9 additions & 10 deletions src/components/sheets/Book.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import ActionLabel from './ActionLabel.vue'
import select_actions from './mixins/select_action'
import Sheet from './Sheet.vue'
import {SheetUtil} from '../../utils/sheets'
export default{
mixins: [select_actions],
props: {
Expand All @@ -25,30 +26,28 @@
return {
curSheet: this.value.sheets[0].name,
actions: [
{name: 'delete', label: '删除数据表', postAction: this.deleteSheet, do: this.toDoSelectionAction},
{name: 'merge', label: '合并数据表', postAction: this.splitLine2Column, do: this.toDoSelectionAction}
{name: 'drop', label: '删除数据表', postAction: this.dropSheet, do: this.toDoSelectionAction},
{name: 'merge', label: '合并数据表', postAction: this.mergeSheet, do: this.toDoSelectionAction}
],
}
},
components: { ActionLabel, Sheet},
methods: {
deleteSheet(context){
dropSheet(){
if (this.selection.list.length === this.value.sheets.length) {
this.$message({message: '请至少留下一张数据表吧?'})
return
}
this.selection.show = false
this.value.sheets = this.value.sheets.filter(a => !this.selection.list.includes(a.name))
SheetUtil.drop(this.value, this.selection.list)
this.curSheet = this.value.sheets[0].name
},
mergeSheet() {
this.selection.show = false
SheetUtil.merge(this.value, this.selection.list)
}
},
computed: {}
}
</script>
<style>
.data-sheet-block {
margin-bottom: 8rem;
}
</style>
16 changes: 9 additions & 7 deletions src/components/sheets/Sheet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import ActionLabel from './ActionLabel.vue'
import Block from './Block.vue'
import select_actions from './mixins/select_action'
import sheets from '../../utils/sheets'
import {BlockUtil} from '../../utils/sheets'
export default{
mixins: [select_actions],
props: {
Expand All @@ -26,7 +26,7 @@
return {
activeNames: this.value.blocks.map(b => b.name),
actions: [
{name: 'delete', label: '删除', postAction: this.deleteBlock, do: this.toDoSelectionAction},
{name: 'drop', label: '删除', postAction: this.dropBlock, do: this.toDoSelectionAction},
{name: 'merge', label: '合并', postAction: this.mergeBlock, do: this.toDoSelectionAction},
]
Expand All @@ -40,15 +40,17 @@
})
return fields
},
deleteBlock(){
dropBlock(){
if (this.selection.list.length === this.value.blocks.length) {
this.$message({message: '请至少留下一个数据块吧?'})
return
}
this.selection.show = false
this.value.blocks = this.value.blocks.filter(a => !this.selection.list.includes(a.name))
BlockUtil.drop(this.value, this.selection.list)
},
mergeBlock() {
this.selection.show = false
let mbls = this.value.blocks.filter(a => this.selection.list.includes(a.name))
let nbs = sheets.mergeBlock(mbls)
this.value.blocks = this.value.blocks.filter(a => !this.selection.list.includes(a.name)).concat(nbs)
BlockUtil.merge(this.value, this.selection.list)
}
},
computed: {
Expand Down
3 changes: 2 additions & 1 deletion src/components/sheets/mixins/select_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export default {

methods: {
toDoSelectionAction(context){
this.selection.first = context.name
this.selection.list = [context.name]
this.selection.actionName = context.action.label
this.selection.action = context.action.postAction
this.selection.action = this[context.action.name] //context.action.postAction
this.selection.show = true
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/stats/ChartGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<script>
import Qs from 'qs'
import server_response from 'vue-django/src/mixins/server_response'
import DataTable from 'vue-django/src/components/layout/table/DataTable.vue'
import DataTable from 'vue-django/src/components/table/DataTable.vue'
import {zipObject} from 'lodash'
let OPTIONS_TOOLBOX = {
show: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
</el-table>
</template>
<script>
import {percent, toThousandslsFilter} from '../../../utils/filters'
import {percent, toThousandslsFilter} from '../../utils/filters'
import {sortBy} from 'lodash'
import DataTableColumn from './DataTableColumn.vue'
import Actions from '../Actions.vue'
import Actions from '../layout/Actions.vue'
function flatten(ns, children_field_name) {
let r = []
ns.forEach(a => {
Expand Down
File renamed without changes.
File renamed without changes.
163 changes: 101 additions & 62 deletions src/utils/sheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/

import {set, unset, uniqueId, pick, range} from 'lodash'
export default {
mergeColumn(block,mfns){
export const ColumnUtil = {
merge (block,mfns){
let fs = block.fields
let bf = fs.find(a => a.name === mfns[0])
let mfs = fs.filter(a => mfns.slice(1).includes(a.name))
Expand All @@ -28,66 +28,7 @@ export default {
block.data = ds.concat(ds2)
block.fields = cfs.concat([bf, nf])
},
mergeBlock(blocks, extras){
if (blocks.length === 0) {
return blocks
}
let ds = []
let bb = blocks[0]
let fs = bb.fields
blocks.forEach((b, i) => {
if(i>0){
let pairs = b.fields.map((f,j) => [f.name, fs[j].name])
this.renameColumn(b, pairs)
console.log(pairs)
}
b.data.forEach((d, j) => {
ds.push(Object.assign({block: b.name }, extras, d))
})
})
if (!fs.find(a => a.name === 'block')) {
fs.push({name: 'block', type: 'string'})
}
if (extras) {
Object.keys(extras).forEach(k => {
if (!fs.find(a => a.name === k)) {
fs.push({name: k, type: typeof extras[k]})
}
})
}
return [{count: ds.length, data: ds, fields: fs, name: bb.name}]
},
mergeSheet(sheets){
let data = []
let sheet = sheets.find(s => s.blocks && s.blocks.length > 0)

let fields = sheet.blocks[0].fields
sheets.forEach((s, i) => {
let block = this.mergeBlock(s.blocks, {sheet: s.name || `sheet${1 + i}`})[0]
if (block) {
data = data.concat(block.data)
}
})
return [{blocks: [{count: data.length, data, fields}], name: sheet.name}]
},
normalize(sheets){
sheets.forEach((s, i) => {
if (!s.name) {
s.name = `Sheet${1 + i}`
}
s.blocks.forEach((b, j) => {
if (!b.name) {
b.name = `Block${1 + j}`
}
b.fields.forEach((f, k) => {
if (!f.label) {
f.label = f.name
}
})
})
})
},
renameColumn(block, pairs){
rename(block, pairs){
pairs = pairs.filter(p => p[0] !== p[1])
if(pairs.length === 0){
return
Expand All @@ -102,6 +43,10 @@ export default {
let f = block.fields.find(f => f.name === p[0])
f.label = f.name = p[1]
})

},
drop (block, cns){
block.fields = block.fields.filter(a => !cns.includes(a.name))
},
splitLine2Column(block, spfns){
let re = /\s+/g
Expand Down Expand Up @@ -155,4 +100,98 @@ export default {
})
block.data = nds
}
}

export const BlockUtil={
merge(sheet, mbns, extras){
let bs = sheet.blocks
let mbs = bs.filter(b => mbns.includes(b.name))
let obs = bs.filter(b => !mbns.includes(b.name))
if (mbs.length === 0) {
return
}
let ds = []
let bb = mbs[0]
let fs = bb.fields
mbs.forEach((b, i) => {
if(i>0){
let pairs = b.fields.map((f,j) => [f.name, fs[j].name])
ColumnUtil.rename(b, pairs)
}
b.data.forEach((d, j) => {
ds.push(Object.assign({block: b.name }, d))
})
})
if (!fs.find(a => a.name === 'block')) {
fs.push({name: 'block', type: 'string'})
}
if (extras) {
ds.forEach((d, i) => {
Object.assign(d, extras)
})
Object.keys(extras).forEach(k => {
if (!fs.find(a => a.name === k)) {
fs.push({name: k, type: typeof extras[k]})
}
})
}
sheet.blocks = [{count: ds.length, data: ds, fields: fs, name: bb.name}].concat(obs)
},
drop(sheet, bns){
sheet.blocks = sheet.blocks.filter(a => !bns.includes(a.name))
}
}
export const SheetUtil = {
merge(book , msns){
let ss = book.sheets
let mss = ss.filter(s => msns.includes(s.name))
let oss = ss.filter(s => !msns.includes(s.name))
let blocks = []
ss.forEach((s, i) => {
blocks = blocks.concat( s.blocks)
})
book.sheets = [{blocks, name: mss[0].name}].concat(oss)
},
drop(book, sns){
book.sheets = book.sheets.filter(a => !sns.includes(a.name))
}
}

export default {


normalize(sheets){
sheets.forEach((s, i) => {
if (!s.name) {
s.name = `Sheet${1 + i}`
}
s.blocks.forEach((b, j) => {
if (!b.name) {
b.name = `Block${1 + j}`
}
b.fields.forEach((f, k) => {
if (!f.label) {
f.label = f.name
}
})
})
})
},
renameColumn(block, pairs){
pairs = pairs.filter(p => p[0] !== p[1])
if(pairs.length === 0){
return
}
block.data.forEach(d => {
pairs.forEach(p => {
d[p[1]] = d[p[0]]
delete d[p[0]]
})
})
pairs.forEach(p => {
let f = block.fields.find(f => f.name === p[0])
f.label = f.name = p[1]
})
},

}

0 comments on commit 5fee752

Please sign in to comment.