| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910 |
- <template>
- <div
- class="widget-report widget-view fm-report-table"
- :class="{
- active: selectWidget.key && selectWidget.key == element.key,
- 'is_hidden': element.options.hidden
- }"
- @click.stop="handleSelectWidget(index)"
- @mouseover.stop="handleMouseover"
- @mouseout="handleMouseout"
- ref="widgetReport"
- >
- <div>
- <table class="fm-report-table__table" :style="{
- 'border': 0,
- 'width': element.options.width || 'auto'
- }"
- :class="{
- [element.options && element.options.customClass]: element.options.customClass ? true : false
- }"
- >
- <tr>
- <template v-for="(th, i) in element.headerRow">
- <th :key="i" :style="{
- 'border-style': 'solid',
- 'border-width': element.options.borderWidth + 'px',
- 'border-color': element.options.borderColor,
- 'width': th.options.width,
- }"
- class="widget-report-item widget-report-header"
- valign="top"
- @click.stop="handleSelectHeaderWidget(i)"
- :class="{
- active: select.key && select.key == th.key
- }"
- @mouseover.stop="handleMouseoverTH(i)"
- @mouseout="handleMouseoutTH(i)"
- :ref="`widgetTH_${i}`"
- ><div style="text-align: center; height: 10px;line-height: 10px;font-size: 12px;">{{th.options.width}}</div></th>
- </template>
- </tr>
- <tr :key="rowIndex" v-for="(row, rowIndex) in element.rows">
- <td :style="{
- 'border-style': 'solid',
- 'border-width': element.options.borderWidth + 'px',
- 'border-color': element.options.borderColor,
- 'width': column.options.width,
- 'height': column.options.height,
- 'text-align': column.options.textAlign,
- 'vertical-align': column.options.verticalAlign,
- }"
- v-for="(column, i) in row.columns" :key="rowIndex + '-' + i"
- v-if="!column.options.invisible"
- :colspan="column.options.colspan"
- :rowspan="column.options.rowspan"
- class="widget-report-item fm-report-table__td"
- :class="{
- active: selectWidget.key && selectWidget.key == column.key,
- [column.options.customClass]: column.options.customClass?true: false,
- selected: selectIndex == i && column.options.colspan == 1
- }"
- @click.stop="handleSelectItemWidget(rowIndex, i)"
- valign="top"
- @mouseover.stop="handleMouseoverTD(rowIndex, i)"
- @mouseout="handleMouseoutTD(rowIndex, i)"
- :ref="`widgetTD_${rowIndex}_${i}`"
- >
- <draggable
- v-model="column.list"
- v-bind="{group:{name: 'people', put: handlePut}, ghostClass: 'ghost',animation: 200, handle: '.drag-widget'}"
- :no-transition-on-drag="true"
- @add="handleWidgetItemAdd($event, element, rowIndex, i)"
- @update="handleWidgetItemUpdate"
- @start="setDragging(true)"
- @end="setDragging(false)"
- class="widget-col-list"
- :style="{
- 'text-align': column.options.textAlign,
- 'vertical-align': column.options.verticalAlign,
- }"
- >
- <template v-for="(c, cindex) in column.list" v-if="c && c.key">
- <widget-tab-item
- v-if="c.type === 'tabs'"
- :key="c.key"
- :element="c"
- :select.sync="selectWidget"
- :index="cindex" :data="column"
- @select-change="handleSelectChange($event, column)"
- :platform="platform"
- :form-key="formKey"
- :subform="subform"
- >
- </widget-tab-item>
- <widget-collapse
- v-else-if="c.type === 'collapse'"
- :key="c.key"
- :element="c"
- :select.sync="selectWidget"
- :index="cindex"
- :data="column"
- @select-change="handleSelectChange($event, column)"
- :platform="platform"
- :form-key="formKey"
- :subform="subform"
- >
- </widget-collapse>
- <widget-table
- v-else-if="c.type === 'table'"
- :key="c.key"
- :element="c"
- :select.sync="selectWidget"
- :index="cindex" :data="column"
- @select-change="handleSelectChange($event, column)"
- :platform="platform"
- :form-key="formKey"
- >
- </widget-table>
- <widget-sub-form
- v-else-if="c.type === 'subform'"
- :key="c.key"
- :element="c"
- :select.sync="selectWidget"
- :index="cindex"
- :data="column"
- @select-change="handleSelectChange($event, column)"
- :platform="platform"
- :form-key="formKey"
- >
- </widget-sub-form>
- <widget-card
- v-else-if="c.type === 'card'"
- :key="c.key"
- :element="c"
- :select.sync="selectWidget"
- :index="cindex"
- :data="column"
- @select-change="handleSelectChange($event, column)"
- :platform="platform"
- :form-key="formKey"
- >
- </widget-card>
- <widget-group
- v-else-if="c.type === 'group'"
- :key="c.key"
- :element="c"
- :select.sync="selectWidget"
- :index="cindex"
- :data="column"
- @select-change="handleSelectChange($event, column)"
- :platform="platform"
- :form-key="formKey"
- >
- </widget-group>
- <widget-inline
- v-else-if="c.type === 'inline'"
- :key="c.key"
- :element="c"
- :select.sync="selectWidget"
- :index="cindex" :data="column"
- @select-change="handleSelectChange($event, column)"
- :platform="platform"
- :form-key="formKey"
- ></widget-inline>
- <widget-report
- v-else-if="c.type === 'report'"
- :key="c.key"
- :element="c"
- :select.sync="selectWidget"
- :index="cindex" :data="column"
- @select-change="handleSelectChange($event, column)"
- :platform="platform"
- :form-key="formKey"
- :subform="subform"
- >
- </widget-report>
- <widget-form-item
- v-else-if="c.type !== 'grid'"
- :key="c.key"
- :element="c"
- :select.sync="selectWidget"
- :index="cindex" :data="column"
- @select-change="handleSelectChange($event, column)"
- :form-key="formKey"
- >
- </widget-form-item>
- <widget-col-item
- v-else
- :key="c.key"
- :element="c"
- :select.sync="selectWidget"
- :index="cindex" :data="column"
- @select-change="handleSelectChange($event, column)"
- :platform="platform"
- :form-key="formKey"
- :subform="subform"
- >
- </widget-col-item>
- </template>
-
- </draggable>
- <div class="widget-view-action widget-col-action" v-if="selectWidget.key == column.key">
- <el-dropdown size="small" trigger="click">
- <span class="el-dropdown-link">
- <i class="fm-iconfont icon-biaogeshezhi" :title="$t('fm.tooltip.cellsetting')"></i>
- </span>
- <el-dropdown-menu slot="dropdown">
- <el-dropdown-item command="insertleft" @click.native.stop="handleInsertLeft">{{$t('fm.tooltip.insertcolumnleft')}}</el-dropdown-item>
- <el-dropdown-item command="insertright" @click.native.stop="handleInsertRight">{{$t('fm.tooltip.insertcolumnright')}}</el-dropdown-item>
- <el-dropdown-item command="insertbefore" @click.native.stop="handleInserBefore">{{$t('fm.tooltip.insertrowbefore')}}</el-dropdown-item>
- <el-dropdown-item command="insertafter" @click.native.stop="handleInserAfter">{{$t('fm.tooltip.insertrowafter')}}</el-dropdown-item>
- <el-dropdown-item command="right" @click.native.stop="handleRight(column)" :disabled="!showRight" divided>{{$t('fm.tooltip.mergeright')}}</el-dropdown-item>
- <el-dropdown-item command="bottom" @click.native.stop="handleBottom(column)" :disabled="!showBottom">{{$t('fm.tooltip.mergedown')}}</el-dropdown-item>
- <el-dropdown-item command="splitcolumns" @click.native.stop="handleSplitColumn" divided :disabled="!showSplitColumn">{{$t('fm.tooltip.splitcolumns')}}</el-dropdown-item>
- <el-dropdown-item command="splitrows" @click.native.stop="handleSplitRow" :disabled="!showSplitRow">{{$t('fm.tooltip.splitrows')}}</el-dropdown-item>
- <el-dropdown-item command="removecolumn" @click.native.stop="handleRemoveColumn" :disabled="!showRemoveColumn" divided>{{$t('fm.tooltip.deletecolumn')}}</el-dropdown-item>
- <el-dropdown-item command="removerow" @click.native.stop="handleRemoveRow" :disabled="!showRemoveRow" >{{$t('fm.tooltip.deleterow')}}</el-dropdown-item>
- <el-dropdown-item command="setcolwidth" @click.native.stop="handleSetColumnWidth" :disabled="column.options.colspan !== 1" divided>{{$t('fm.tooltip.setcolwidth')}}</el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
- </div>
- <div class="widget-view-type ">
- <span>{{column.type ? $t('fm.components.fields.' + column.type) : ''}}</span>
- </div>
- </td>
- </tr>
- </table>
- </div>
- <div class="widget-view-action widget-col-action" v-if="selectWidget.key == element.key">
- <i class="fm-iconfont icon--charuhang" @click.stop="handleAddRow(index)" :title="$t('fm.tooltip.addrow')"></i>
- <i class="fm-iconfont icon--charulie" @click.stop="handleAddColumns(index)" :title="$t('fm.tooltip.addcolumn')"></i>
- <i class="fm-iconfont icon-icon_clone" @click.stop="handleReportClone(index)" :title="$t('fm.tooltip.clone')"></i>
- <i class="fm-iconfont icon-trash" @click.stop="handleWidgetDelete(index)" :title="$t('fm.tooltip.trash')"></i>
- </div>
- <div class="widget-view-drag widget-col-drag" v-if="selectWidget.key == element.key">
- <i class="fm-iconfont icon-drag drag-widget"></i>
- </div>
- <div class="widget-view-model " :style="{'color': element.options.dataBind ? '' : '#666'}">
- <span>{{element.model}}</span>
- </div>
- <div class="widget-view-type ">
- <span>{{element.type ? $t('fm.components.fields.' + element.type) : ''}}</span>
- </div>
- </div>
- </template>
- <script>
- import WidgetFormItem from './WidgetFormItem'
- import WidgetTable from './WidgetTable'
- import WidgetInline from './WidgetInline'
- import Draggable from 'vuedraggable'
- import _ from 'lodash'
- import { CloneLayout } from '../util/layout-clone.js'
- import { EventBus } from '../util/event-bus.js'
- import { generateKeyToTD, generateKeyToTH, generateKeyToCol, fixDraggbleList, addClass, removeClass } from '../util'
- export default {
- name: 'widget-report',
- components: {
- Draggable,
- WidgetFormItem,
- WidgetTable,
- WidgetInline,
- WidgetColItem: () => import('./WidgetColItem.vue'),
- WidgetTabItem: () => import('./WidgetTabItem.vue'),
- WidgetSubForm: () => import('./WidgetSubForm.vue'),
- WidgetCollapse: () => import('./WidgetCollapse.vue'),
- WidgetCard: () => import('./WidgetCard.vue'),
- WidgetGroup: () => import('./WidgetGroup.vue')
- },
- props: ['element', 'select', 'index', 'data', 'platform', 'formKey', 'subform'],
- inject: ['getDragging', 'setDragging'],
- data () {
- return {
- selectWidget: this.select || {},
- selectR: -1,
- selectC: -1,
- selectIndex: -1
- }
- },
- created () {
- // 处理v1.5.8以前的表格
- console.log('created', this.element)
- if (!this.element.headerRow) {
- this.element.headerRow = this.element.rows[0].columns.map(item => ({
- type: 'th',
- options: {
- width: item.options.width
- },
- key: Math.random().toString(36).slice(-8)
- }))
- }
- },
- computed: {
- showRight () {
-
- if (this.selectR >= 0 && this.selectC >= 0) {
- const currentRowspan = this.element.rows[this.selectR].columns[this.selectC].options.rowspan
- const currentColspan = this.element.rows[this.selectR].columns[this.selectC].options.colspan
- if (this.selectC + currentColspan < this.element.rows[this.selectR].columns.length) {
- const nextColumn = this.element.rows[this.selectR].columns[currentColspan + this.selectC]
- if (!nextColumn.options.invisible && currentRowspan == nextColumn.options.rowspan) {
- return true
- }
- }
- }
- return false
- },
- showBottom () {
- if (this.selectR >= 0 && this.selectC >= 0) {
- const currentRowspan = this.element.rows[this.selectR].columns[this.selectC].options.rowspan
- const currentColspan = this.element.rows[this.selectR].columns[this.selectC].options.colspan
- if (currentRowspan + this.selectR < this.element.rows.length) {
- const nextColumn = this.element.rows[currentRowspan + this.selectR].columns[this.selectC]
- if (!nextColumn.options.invisible && currentColspan == nextColumn.options.colspan) {
- return true
- }
- }
- }
- return false
- },
- showRemoveRow () {
- if (this.element.rows.length > 1 && this.selectR >= 0 && this.selectC >= 0) {
- const currentRowspan = this.element.rows[this.selectR].columns[this.selectC].options.rowspan
- if (currentRowspan == 1) {
- return true
- } else {
- let i = 0
- for (; i < this.element.rows[this.selectR].columns.length; i++) {
- if (currentRowspan != this.element.rows[this.selectR].columns[i].options.rowspan || this.element.rows[this.selectR].columns[i].options.invisible) {
- return false
- }
- }
- if (this.element.rows[this.selectR].columns.length == i) {
- return true
- }
- }
- }
- return false
- },
- showRemoveColumn () {
- if (this.selectR >= 0 && this.selectC >= 0 && this.element.rows[this.selectR].columns.length > 1) {
- const currentColspan = this.element.rows[this.selectR].columns[this.selectC].options.colspan
- if (currentColspan == 1) {
- return true
- } else {
- let i = 0;
- for (; i < this.element.rows.length; i++) {
- if (currentColspan != this.element.rows[i].columns[this.selectC].options.colspan || this.element.rows[i].columns[this.selectC].options.invisible) {
- return false
- }
- }
- if (this.element.rows.length == i) {
- return true
- }
- }
- }
- return false
- },
- showSplitColumn () {
- if (this.selectR >= 0 && this.selectC >= 0) {
- return this.element.rows[this.selectR].columns[this.selectC].options.colspan > 1
- }
- return false
- },
- showSplitRow () {
- if (this.selectR >= 0 && this.selectC >= 0) {
- return this.element.rows[this.selectR].columns[this.selectC].options.rowspan > 1
- }
- return false
- }
- },
- methods: {
- handleMouseover (e) {
- !this.getDragging() && addClass(this.$refs['widgetReport'], 'is-hover')
- },
- handleMouseout (e) {
- removeClass(this.$refs['widgetReport'], 'is-hover')
- },
- handleMouseoverTD (r, i) {
- !this.getDragging() && addClass(this.$refs[`widgetTD_${r}_${i}`][0], 'is-hover')
- },
- handleMouseoutTD (r, i) {
- removeClass(this.$refs[`widgetTD_${r}_${i}`][0], 'is-hover')
- },
- handleMouseoverTH (i) {
- !this.getDragging() && addClass(this.$refs[`widgetTH_${i}`][0], 'is-hover')
- },
- handleMouseoutTH (i) {
- removeClass(this.$refs[`widgetTH_${i}`][0], 'is-hover')
- },
- handlePut (a, b, c) {
- if (c.className.split(' ').indexOf('widget-dialog') >=0 || c.className.split(' ').indexOf('dialog-put') >= 0 || c.children[0].className.split(' ').indexOf('dialog-put') >= 0) {
- return false
- }
- return true
- },
- handleSelectWidget (index) {
- this.selectWidget = this.data.list[index]
- },
- handleSelectItemWidget (rowIndex, colIndex) {
- this.selectWidget = this.data.list[this.index].rows[rowIndex].columns[colIndex]
- this.selectR = rowIndex
- this.selectC = colIndex
- },
- handleSelectHeaderWidget (index) {
- this.selectWidget = this.data.list[this.index].headerRow[index]
- },
- handleWidgetDelete (index) {
- if (this.data.list.length == 1) {
- this.$emit('select-change', -1)
- } else {
- if (this.data.list.length - 1 == index) {
- this.$emit('select-change', index - 1)
- } else {
- this.$emit('select-change', index)
- }
- }
-
- this.data.list.splice(index, 1)
- setTimeout(() => {
- EventBus.$emit('on-history-add-' + this.formKey)
- }, 20)
- },
- handleWidgetItemAdd ($event, element, rowIndex, colIndex) {
- const newIndex = $event.newIndex
- fixDraggbleList(element.rows[rowIndex].columns[colIndex].list, newIndex)
- const key = Math.random().toString(36).slice(-8)
- this.$set(element.rows[rowIndex].columns[colIndex].list, newIndex, _.cloneDeep(element.rows[rowIndex].columns[colIndex].list[newIndex]))
- this.$set(element.rows[rowIndex].columns[colIndex].list, newIndex, {
- ...element.rows[rowIndex].columns[colIndex].list[newIndex],
- options: {
- ...element.rows[rowIndex].columns[colIndex].list[newIndex].options,
- remoteFunc: element.rows[rowIndex].columns[colIndex].list[newIndex].options.remoteFunc || 'func_'+key,
- remoteOption: element.rows[rowIndex].columns[colIndex].list[newIndex].options.remoteOption || 'option_'+key,
- tableColumn: false,
- hideLabel: true,
- subform: this.subform ? true : false
- },
- key: element.rows[rowIndex].columns[colIndex].list[newIndex].key ? element.rows[rowIndex].columns[colIndex].list[newIndex].key : key,
- model: element.rows[rowIndex].columns[colIndex].list[newIndex].model ? element.rows[rowIndex].columns[colIndex].list[newIndex].model : element.rows[rowIndex].columns[colIndex].list[newIndex].type + '_' + key,
- rules: element.rows[rowIndex].columns[colIndex].list[newIndex].rules ? [...element.rows[rowIndex].columns[colIndex].list[newIndex].rules] : []
- })
- if (element.rows[rowIndex].columns[colIndex].list[newIndex].type == 'report') {
- element.rows[rowIndex].columns[colIndex].list[newIndex].rows = generateKeyToTD(element.rows[rowIndex].columns[colIndex].list[newIndex].rows)
- element.rows[rowIndex].columns[colIndex].list[newIndex].headerRow = generateKeyToTH(element.rows[rowIndex].columns[colIndex].list[newIndex].headerRow)
- }
- if (element.rows[rowIndex].columns[colIndex].list[newIndex].type == 'grid') {
- element.rows[rowIndex].columns[colIndex].list[newIndex].columns = generateKeyToCol(element.rows[rowIndex].columns[colIndex].list[newIndex].columns)
- }
- this.selectWidget = element.rows[rowIndex].columns[colIndex].list[newIndex]
- EventBus.$emit('on-history-add-' + this.formKey)
- },
- handleWidgetItemUpdate () {
- EventBus.$emit('on-history-add-' + this.formKey)
- },
- handleReportClone (index) {
- let cloneData = _.cloneDeep(this.data.list[index])
- this.data.list.splice(index + 1, 0, CloneLayout(cloneData))
- this.$nextTick(() => {
- this.selectWidget = this.data.list[index + 1]
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- })
- },
- handleAddRow (index) {
- const columns = this.data.list[index].rows[this.data.list[index].rows.length - 1].columns.length
- this.data.list[index].rows.push({
- columns: Array.from({length: columns}, _ => {
- return {
- type: 'td',
- list: [],
- options: {
- customClass: '',
- colspan: 1,
- rowspan: 1,
- align: 'left',
- valign: 'top',
- width: '',
- height: '',
- },
- key: Math.random().toString(36).slice(-8)
- }
- })
- })
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- },
- handleAddColumns (index) {
- this.data.list[index].headerRow.push({
- type: 'th',
- options: {
- width: ''
- },
- key: Math.random().toString(36).slice(-8)
- })
- this.data.list[index].rows.forEach(item => {
- item.columns.push({
- type: 'td',
- list: [],
- options: {
- customClass: '',
- colspan: 1,
- rowspan: 1,
- align: 'left',
- valign: 'top',
- width: '',
- height: '',
- },
- key: Math.random().toString(36).slice(-8)
- })
- })
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- },
- insertColumns (insertIndex) {
- this.element.headerRow.splice(insertIndex, 0,{
- type: 'th',
- options: {
- width: ''
- },
- key: Math.random().toString(36).slice(-8)
- })
- for (let i = 0; i < this.element.rows.length; i++) {
- const prevIndex = this.findPrevColIndex(i, insertIndex)
- if (prevIndex != insertIndex && this.element.rows[i].columns[insertIndex].options.invisible) {
- this.element.rows[i].columns.splice(insertIndex, 0, {
- type: 'td',
- list: [],
- options: {
- customClass: '',
- colspan: 1,
- rowspan: 1,
- align: 'left',
- valign: 'top',
- width: '',
- height: '',
- invisible: true
- },
- key: Math.random().toString(36).slice(-8)
- })
- // 插入隐藏列后,进行标记计算
- const beforeColspan = this.element.rows[i].columns[prevIndex].options.colspan
- this.element.rows[i].columns[prevIndex].options.colspan = beforeColspan + 1
- for (let j = 0; j < beforeColspan + 1; j++) {
- this.element.rows[i].columns[prevIndex + j].options.markCol = j
- }
- } else {
- this.element.rows[i].columns.splice(insertIndex, 0, {
- type: 'td',
- list: [],
- options: {
- customClass: '',
- colspan: 1,
- rowspan: 1,
- align: 'left',
- valign: 'top',
- width: '',
- height: '',
- },
- key: Math.random().toString(36).slice(-8)
- })
- }
- }
- },
- insertRow (insertIndex) {
- const rowArray = []
- for (let i = 0; i < this.element.rows[0].columns.length; i++) {
- const prevIndex = this.findPrevRowIndex(insertIndex, i)
- if (prevIndex != insertIndex && this.element.rows[insertIndex].columns[i].options.invisible) {
- rowArray.push({
- type: 'td',
- list: [],
- options: {
- customClass: '',
- colspan: 1,
- rowspan: 1,
- align: 'left',
- valign: 'top',
- width: '',
- height: '',
- invisible: true
- },
- key: Math.random().toString(36).slice(-8)
- })
- this.element.rows[prevIndex].columns[i].options.rowspan = this.element.rows[prevIndex].columns[i].options.rowspan + 1
- } else {
- rowArray.push({
- type: 'td',
- list: [],
- options: {
- customClass: '',
- colspan: 1,
- rowspan: 1,
- align: 'left',
- valign: 'top',
- width: '',
- height: '',
- },
- key: Math.random().toString(36).slice(-8)
- })
- }
- }
- this.element.rows.splice(insertIndex, 0, {
- columns: rowArray
- })
- // 行插入成功后,处理标记
- this.$nextTick(() => {
- for (let i = 0; i < this.element.rows[insertIndex].columns.length; i++) {
- if (this.element.rows[insertIndex].columns[i].options.invisible) {
- const prevIndex = this.findPrevRowIndex(insertIndex - 1, i)
- if (!this.element.rows[prevIndex].columns[i].options.invisible) {
- this.markTableItem(prevIndex, i)
- }
- }
- }
- })
- },
- handleInsertLeft () {
- const insertIndex = this.selectC
- this.insertColumns(insertIndex)
- this.selectC = this.selectC++
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- },
- handleInsertRight () {
- const insertColIndex = this.element.rows[this.selectR].columns[this.selectC].options.colspan > 1
- ? this.findNextColIndex(this.selectR, this.selectC + 1) : this.selectC + 1
- this.insertColumns(insertColIndex)
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- },
- handleInserBefore () {
- const insertIndex = this.selectR
- this.insertRow(insertIndex)
- this.selectR = this.selectR++
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- },
- handleInserAfter () {
- const insertRowIndex = this.element.rows[this.selectR].columns[this.selectC].options.rowspan > 1
- ? this.findNextRowIndex(this.selectR + 1, this.selectC) : this.selectR + 1
- this.insertRow(insertRowIndex)
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- },
- // 合并的表格做上标记
- markTableItem (R, C) {
- const colspan = this.element.rows[R].columns[C].options.colspan
- const rowspan = this.element.rows[R].columns[C].options.rowspan
- for (let i = 0; i < rowspan; i++) {
- for (let j = 0; j < colspan; j++) {
- this.element.rows[R + i].columns[C + j].options.markCol = j
- this.element.rows[R + i].columns[C + j].options.markRow = i
- }
- }
- },
- handleRight (column) {
- const currentColspan = column.options.colspan
- const nextC = this.selectC + currentColspan
- const nextColspan = this.element.rows[this.selectR].columns[nextC].options.colspan
- this.$set(column.options, 'colspan', currentColspan + nextColspan) // 设置当前colspan
- this.element.rows[this.selectR].columns[nextC].options.invisible = true // 将被合并项隐藏
- // 处理表格中元素
- const tempList = [...this.element.rows[this.selectR].columns[nextC].list]
- this.element.rows[this.selectR].columns[nextC].list = []
- column.list = column.list.concat(tempList)
- // 将合并的表格做上标记
- this.markTableItem(this.selectR, this.selectC)
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- },
- handleBottom (column) {
- const currentRowspan = column.options.rowspan
- const nextR = this.selectR + currentRowspan
- const nextRowspan = this.element.rows[nextR].columns[this.selectC].options.rowspan
- this.$set(column.options, 'rowspan', currentRowspan + nextRowspan)
- this.element.rows[nextR].columns[this.selectC].options.invisible = true
- const tempList = [...this.element.rows[nextR].columns[this.selectC].list]
- this.element.rows[nextR].columns[this.selectC].list = []
- column.list = column.list.concat(tempList)
- // 将合并的表格做上标记
- this.markTableItem(this.selectR, this.selectC)
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- },
- handleSplitColumn () {
- const currentColspan = this.element.rows[this.selectR].columns[this.selectC].options.colspan
- const currentRowspan = this.element.rows[this.selectR].columns[this.selectC].options.rowspan
- for (let i = 0; i < currentColspan; i++) {
- this.element.rows[this.selectR].columns[this.selectC + i].options.invisible = false
- this.element.rows[this.selectR].columns[this.selectC + i].options.colspan = 1
- this.element.rows[this.selectR].columns[this.selectC + i].options.rowspan = currentRowspan
- this.markTableItem(this.selectR, this.selectC + i)
- }
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- },
- handleSplitRow () {
- const currentColspan = this.element.rows[this.selectR].columns[this.selectC].options.colspan
- const currentRowspan = this.element.rows[this.selectR].columns[this.selectC].options.rowspan
- for (let i = 0; i < currentRowspan; i++) {
- this.element.rows[this.selectR + i].columns[this.selectC].options.invisible = false
- this.element.rows[this.selectR + i].columns[this.selectC].options.rowspan = 1
- this.element.rows[this.selectR + i].columns[this.selectC].options.colspan = currentColspan
-
- this.markTableItem(this.selectR + i, this.selectC)
- }
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- },
- findPrevRowIndex (rowIndex, colIndex) {
- if (rowIndex >= this.element.rows.length || !this.element.rows[rowIndex].columns[colIndex].options.markRow) {
- return rowIndex
- } else {
- return this.findPrevRowIndex(rowIndex - 1, colIndex)
- }
- },
- findPrevColIndex (rowIndex, colIndex) {
- if (colIndex >= this.element.rows[rowIndex].columns.length || !this.element.rows[rowIndex].columns[colIndex].options.markCol) {
- return colIndex
- } else {
- return this.findPrevColIndex(rowIndex, colIndex - 1)
- }
- },
- findNextColIndex (rowIndex, colIndex) {
- if (colIndex >= this.element.rows[rowIndex].columns.length || !this.element.rows[rowIndex].columns[colIndex].options.markCol) {
- return colIndex
- } else {
- return this.findNextColIndex(rowIndex, colIndex + 1)
- }
- },
- findNextRowIndex (rowIndex, colIndex) {
- if (rowIndex >= this.element.rows.length || !this.element.rows[rowIndex].columns[colIndex].options.markRow) {
- return rowIndex
- } else {
- return this.findNextRowIndex(rowIndex + 1, colIndex)
- }
- },
- handleRemoveRow () {
- for (let j = 0; j < this.element.rows[this.selectR].columns.length; j++) {
- const currentRowspan = this.element.rows[this.selectR].columns[j].options.rowspan
- const currentcolspan = this.element.rows[this.selectR].columns[j].options.colspan
- const invisible = this.element.rows[this.selectR].columns[j].options.invisible
- if (invisible) {
- const prevIndex = this.findPrevRowIndex(this.selectR, j)
- if (prevIndex != this.selectR && this.element.rows[prevIndex].columns[j].options.rowspan > 1) {
- this.element.rows[prevIndex].columns[j].options.rowspan = this.element.rows[prevIndex].columns[j].options.rowspan - 1
- }
- } else if (currentRowspan > 1) {
- this.element.rows[this.selectR + 1].columns[j].list = [...this.element.rows[this.selectR].columns[j].list]
- this.element.rows[this.selectR + 1].columns[j].options.invisible = false
- this.element.rows[this.selectR + 1].columns[j].options.rowspan = currentRowspan - 1
- this.element.rows[this.selectR + 1].columns[j].options.colspan = currentcolspan
- // 重新计算标记
- this.markTableItem(this.selectR + 1, j)
- } else {
-
- }
- }
- this.element.rows.splice(this.selectR, 1)
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- },
- handleRemoveColumn () {
- for (let i = 0; i < this.element.rows.length; i++) {
-
- const currentColspan = this.element.rows[i].columns[this.selectC].options.colspan
- const currentRowspan = this.element.rows[i].columns[this.selectC].options.rowspan
- const invisible = this.element.rows[i].columns[this.selectC].options.invisible
- if (invisible) {
- const prevIndex = this.findPrevColIndex(i, this.selectC)
- if (prevIndex != this.selectC && this.element.rows[i].columns[prevIndex].options.colspan > 1) {
- this.element.rows[i].columns[prevIndex].options.colspan = this.element.rows[i].columns[prevIndex].options.colspan - 1
- }
- } else if (currentColspan > 1) {
- this.element.rows[i].columns[this.selectC + 1].list = [...this.element.rows[i].columns[this.selectC].list]
- this.element.rows[i].columns[this.selectC + 1].options.invisible = false
- this.element.rows[i].columns[this.selectC + 1].options.colspan = currentColspan - 1
- this.element.rows[i].columns[this.selectC + 1].options.rowspan = currentRowspan
- // 重新计算标记
- this.markTableItem(i, this.selectC + 1)
- } else {
- }
- this.element.rows[i].columns.splice(this.selectC, 1)
- }
- this.element.headerRow.splice(this.selectC, 1)
- this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
- },
- handleSetColumnWidth () {
- this.selectWidget = this.data.list[this.index].headerRow[this.selectC]
- },
- handleSelectChange (index, item) {
- setTimeout(() => {
- index >=0 ? (this.selectWidget = item.list[index]) : (this.selectWidget = this.data.list[this.index])
- })
- }
- },
- watch: {
- select (val) {
- this.selectWidget = val
- this.element.headerRow && (this.selectIndex = this.element.headerRow.findIndex(item => item.key === val.key))
- },
- selectWidget: {
- deep: false,
- handler (val) {
- this.$emit('update:select', val)
- this.element.headerRow && (this.selectIndex = this.element.headerRow.findIndex(item => item.key === val.key))
- }
- },
- }
- }
- </script>
|