You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.0 KiB
102 lines
2.0 KiB
2 years ago
|
import { isConstructorDeclaration } from "typescript"
|
||
|
|
||
|
// components/tableView/table.js
|
||
|
Component({
|
||
|
/**
|
||
|
* 组件的属性列表
|
||
|
*/
|
||
|
properties: {
|
||
|
title: {
|
||
|
type: String,
|
||
|
value: ''
|
||
|
},
|
||
|
header: {
|
||
|
type: Array,
|
||
|
value: []
|
||
|
},
|
||
|
list: {
|
||
|
type: Array,
|
||
|
value: []
|
||
|
},
|
||
|
isClick: {
|
||
|
type: Boolean,
|
||
|
value: true
|
||
|
},
|
||
|
agencyId: {
|
||
|
type: String,
|
||
|
value: ''
|
||
|
},
|
||
|
gridId: {
|
||
|
type: String,
|
||
|
value: "",
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 组件的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
width: '100%',
|
||
|
positionHeader: [],
|
||
|
positionData: [],
|
||
|
columnsHeader: [],
|
||
|
tableClass: '',
|
||
|
tableList: []
|
||
|
},
|
||
|
ready() {
|
||
|
this.computedWidth()
|
||
|
|
||
|
},
|
||
|
|
||
|
observers: {
|
||
|
'list': function() {
|
||
|
this.concatCell()
|
||
|
}
|
||
|
},
|
||
|
/**
|
||
|
* 组件的方法列表
|
||
|
*/
|
||
|
methods: {
|
||
|
computedWidth() {
|
||
|
let { header, tableClass } = this.data
|
||
|
let _width = '100%'
|
||
|
if (header.length > 5) {
|
||
|
_width = 100 + (header.length - 5) * 15 + '%'
|
||
|
}
|
||
|
if (header.length === 3) {
|
||
|
tableClass = 'table-short'
|
||
|
}
|
||
|
if (header.length === 4) {
|
||
|
tableClass = 'table-middle'
|
||
|
}
|
||
|
this.setData({
|
||
|
width: _width,
|
||
|
positionHeader: header.slice(0, 2),
|
||
|
columnsHeader: header.slice(1),
|
||
|
tableClass
|
||
|
})
|
||
|
},
|
||
|
concatCell() {
|
||
|
let { list } = this.data
|
||
|
console.log('list', list)
|
||
|
list = list.map(item => {
|
||
|
return {
|
||
|
...item,
|
||
|
gridName: item.agencyName + '-' + item.gridName
|
||
|
}
|
||
|
})
|
||
|
|
||
|
this.setData({
|
||
|
tableList: list
|
||
|
})
|
||
|
console.log('tablelist', this.data.tableList)
|
||
|
},
|
||
|
handleChange(e) {
|
||
|
if (!this.data.isClick) return false
|
||
|
const index = e.currentTarget.dataset.index
|
||
|
|
||
|
this.triggerEvent('change', this.data.list[index])
|
||
|
}
|
||
|
}
|
||
|
})
|