修复table
parent
6a5ccc2ff3
commit
e2999a6be7
|
@ -0,0 +1,27 @@
|
||||||
|
## 1.2.3(2023-03-28)
|
||||||
|
- 修复 在vue3模式下可能会出现错误的问题
|
||||||
|
## 1.2.2(2022-11-29)
|
||||||
|
- 优化 主题样式
|
||||||
|
## 1.2.1(2022-06-06)
|
||||||
|
- 修复 微信小程序存在无使用组件的问题
|
||||||
|
## 1.2.0(2021-11-19)
|
||||||
|
- 优化 组件UI,并提供设计资源,详见:[https://uniapp.dcloud.io/component/uniui/resource](https://uniapp.dcloud.io/component/uniui/resource)
|
||||||
|
- 文档迁移,详见:[https://uniapp.dcloud.io/component/uniui/uni-table](https://uniapp.dcloud.io/component/uniui/uni-table)
|
||||||
|
## 1.1.0(2021-07-30)
|
||||||
|
- 组件兼容 vue3,如何创建vue3项目,详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834)
|
||||||
|
## 1.0.7(2021-07-08)
|
||||||
|
- 新增 uni-th 支持 date 日期筛选范围
|
||||||
|
## 1.0.6(2021-07-05)
|
||||||
|
- 新增 uni-th 支持 range 筛选范围
|
||||||
|
## 1.0.5(2021-06-28)
|
||||||
|
- 新增 uni-th 筛选功能
|
||||||
|
## 1.0.4(2021-05-12)
|
||||||
|
- 新增 示例地址
|
||||||
|
- 修复 示例项目缺少组件的Bug
|
||||||
|
## 1.0.3(2021-04-16)
|
||||||
|
- 新增 sortable 属性,是否开启单列排序
|
||||||
|
- 优化 表格多选逻辑
|
||||||
|
## 1.0.2(2021-03-22)
|
||||||
|
- uni-tr 添加 disabled 属性,用于 type=selection 时,设置某行是否可由全选按钮控制
|
||||||
|
## 1.0.1(2021-02-05)
|
||||||
|
- 调整为uni_modules目录规范
|
|
@ -1,89 +1,89 @@
|
||||||
<template>
|
<template>
|
||||||
<view class="uni-table-scroll" :class="{ 'table--border': border, 'border-none': !noData }">
|
<view class="uni-table-scroll" :class="{ 'table--border': border, 'border-none': !noData }">
|
||||||
<!-- #ifdef H5 -->
|
<!-- #ifdef H5 -->
|
||||||
<table class="uni-table" border="0" cellpadding="0" cellspacing="0" :class="{ 'table--stripe': stripe }" :style="{ 'min-width': minWidth + 'px' }">
|
<table class="uni-table" border="0" cellpadding="0" cellspacing="0" :class="{ 'table--stripe': stripe }" :style="{ 'min-width': minWidth + 'px' }">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<tr v-if="noData" class="uni-table-loading">
|
<tr v-if="noData" class="uni-table-loading">
|
||||||
<td class="uni-table-text" :class="{ 'empty-border': border }">{{ emptyText }}</td>
|
<td class="uni-table-text" :class="{ 'empty-border': border }">{{ emptyText }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<view v-if="loading" class="uni-table-mask" :class="{ 'empty-border': border }"><div class="uni-table--loader"></div></view>
|
<view v-if="loading" class="uni-table-mask" :class="{ 'empty-border': border }"><div class="uni-table--loader"></div></view>
|
||||||
</table>
|
</table>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
<!-- #ifndef H5 -->
|
<!-- #ifndef H5 -->
|
||||||
<view class="uni-table" :style="{ 'min-width': minWidth + 'px' }" :class="{ 'table--stripe': stripe }">
|
<view class="uni-table" :style="{ 'min-width': minWidth + 'px' }" :class="{ 'table--stripe': stripe }">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<view v-if="noData" class="uni-table-loading">
|
<view v-if="noData" class="uni-table-loading">
|
||||||
<view class="uni-table-text" :class="{ 'empty-border': border }">{{ emptyText }}</view>
|
<view class="uni-table-text" :class="{ 'empty-border': border }">{{ emptyText }}</view>
|
||||||
</view>
|
</view>
|
||||||
<view v-if="loading" class="uni-table-mask" :class="{ 'empty-border': border }"><div class="uni-table--loader"></div></view>
|
<view v-if="loading" class="uni-table-mask" :class="{ 'empty-border': border }"><div class="uni-table--loader"></div></view>
|
||||||
</view>
|
</view>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
/**
|
/**
|
||||||
* Table 表格
|
* Table 表格
|
||||||
* @description 用于展示多条结构类似的数据
|
* @description 用于展示多条结构类似的数据
|
||||||
* @tutorial https://ext.dcloud.net.cn/plugin?id=3270
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=3270
|
||||||
* @property {Boolean} border 是否带有纵向边框
|
* @property {Boolean} border 是否带有纵向边框
|
||||||
* @property {Boolean} stripe 是否显示斑马线
|
* @property {Boolean} stripe 是否显示斑马线
|
||||||
* @property {Boolean} type 是否开启多选
|
* @property {Boolean} type 是否开启多选
|
||||||
* @property {String} emptyText 空数据时显示的文本内容
|
* @property {String} emptyText 空数据时显示的文本内容
|
||||||
* @property {Boolean} loading 显示加载中
|
* @property {Boolean} loading 显示加载中
|
||||||
* @event {Function} selection-change 开启多选时,当选择项发生变化时会触发该事件
|
* @event {Function} selection-change 开启多选时,当选择项发生变化时会触发该事件
|
||||||
*/
|
*/
|
||||||
export default {
|
export default {
|
||||||
name: 'uniTable',
|
name: 'uniTable',
|
||||||
options: {
|
options: {
|
||||||
virtualHost: true
|
virtualHost: true
|
||||||
},
|
},
|
||||||
emits:['selection-change'],
|
emits:['selection-change'],
|
||||||
props: {
|
props: {
|
||||||
data: {
|
data: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default() {
|
default() {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 是否有竖线
|
// 是否有竖线
|
||||||
border: {
|
border: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
// 是否显示斑马线
|
// 是否显示斑马线
|
||||||
stripe: {
|
stripe: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
// 多选
|
// 多选
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
// 没有更多数据
|
// 没有更多数据
|
||||||
emptyText: {
|
emptyText: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '没有更多数据'
|
default: '没有更多数据'
|
||||||
},
|
},
|
||||||
loading: {
|
loading: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
rowKey: {
|
rowKey: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
noData: true,
|
noData: true,
|
||||||
minWidth: 0,
|
minWidth: 0,
|
||||||
multiTableHeads: []
|
multiTableHeads: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
loading(val) {},
|
loading(val) {},
|
||||||
data(newVal) {
|
data(newVal) {
|
||||||
let theadChildren = this.theadChildren
|
let theadChildren = this.theadChildren
|
||||||
let rowspan = 1
|
let rowspan = 1
|
||||||
|
@ -92,21 +92,21 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.trChildren.length - rowspan
|
// this.trChildren.length - rowspan
|
||||||
this.noData = false
|
this.noData = false
|
||||||
// this.noData = newVal.length === 0
|
// this.noData = newVal.length === 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
// 定义tr的实例数组
|
// 定义tr的实例数组
|
||||||
this.trChildren = []
|
this.trChildren = []
|
||||||
this.thChildren = []
|
this.thChildren = []
|
||||||
this.theadChildren = null
|
this.theadChildren = null
|
||||||
this.backData = []
|
this.backData = []
|
||||||
this.backIndexData = []
|
this.backIndexData = []
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
isNodata() {
|
isNodata() {
|
||||||
let theadChildren = this.theadChildren
|
let theadChildren = this.theadChildren
|
||||||
let rowspan = 1
|
let rowspan = 1
|
||||||
if (this.theadChildren) {
|
if (this.theadChildren) {
|
||||||
|
@ -117,108 +117,108 @@ export default {
|
||||||
/**
|
/**
|
||||||
* 选中所有
|
* 选中所有
|
||||||
*/
|
*/
|
||||||
selectionAll() {
|
selectionAll() {
|
||||||
let startIndex = 1
|
let startIndex = 1
|
||||||
let theadChildren = this.theadChildren
|
let theadChildren = this.theadChildren
|
||||||
if (!this.theadChildren) {
|
if (!this.theadChildren) {
|
||||||
theadChildren = this.trChildren[0]
|
theadChildren = this.trChildren[0]
|
||||||
} else {
|
} else {
|
||||||
startIndex = theadChildren.rowspan - 1
|
startIndex = theadChildren.rowspan - 1
|
||||||
}
|
}
|
||||||
let isHaveData = this.data && this.data.length > 0
|
let isHaveData = this.data && this.data.length > 0
|
||||||
theadChildren.checked = true
|
theadChildren.checked = true
|
||||||
theadChildren.indeterminate = false
|
theadChildren.indeterminate = false
|
||||||
this.trChildren.forEach((item, index) => {
|
this.trChildren.forEach((item, index) => {
|
||||||
if (!item.disabled) {
|
if (!item.disabled) {
|
||||||
item.checked = true
|
item.checked = true
|
||||||
if (isHaveData && item.keyValue) {
|
if (isHaveData && item.keyValue) {
|
||||||
const row = this.data.find(v => v[this.rowKey] === item.keyValue)
|
const row = this.data.find(v => v[this.rowKey] === item.keyValue)
|
||||||
if (!this.backData.find(v => v[this.rowKey] === row[this.rowKey])) {
|
if (!this.backData.find(v => v[this.rowKey] === row[this.rowKey])) {
|
||||||
this.backData.push(row)
|
this.backData.push(row)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (index > (startIndex - 1) && this.backIndexData.indexOf(index - startIndex) === -1) {
|
|
||||||
this.backIndexData.push(index - startIndex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// this.backData = JSON.parse(JSON.stringify(this.data))
|
|
||||||
this.$emit('selection-change', {
|
|
||||||
detail: {
|
|
||||||
value: this.backData,
|
|
||||||
index: this.backIndexData
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* 用于多选表格,切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中)
|
|
||||||
*/
|
|
||||||
toggleRowSelection(row, selected) {
|
|
||||||
// if (!this.theadChildren) return
|
|
||||||
row = [].concat(row)
|
|
||||||
|
|
||||||
this.trChildren.forEach((item, index) => {
|
|
||||||
// if (item.keyValue) {
|
|
||||||
|
|
||||||
const select = row.findIndex(v => {
|
|
||||||
//
|
|
||||||
if (typeof v === 'number') {
|
|
||||||
return v === index - 1
|
|
||||||
} else {
|
|
||||||
return v[this.rowKey] === item.keyValue
|
|
||||||
}
|
|
||||||
})
|
|
||||||
let ischeck = item.checked
|
|
||||||
if (select !== -1) {
|
|
||||||
if (typeof selected === 'boolean') {
|
|
||||||
item.checked = selected
|
|
||||||
} else {
|
|
||||||
item.checked = !item.checked
|
|
||||||
}
|
}
|
||||||
|
if (index > (startIndex - 1) && this.backIndexData.indexOf(index - startIndex) === -1) {
|
||||||
|
this.backIndexData.push(index - startIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// this.backData = JSON.parse(JSON.stringify(this.data))
|
||||||
|
this.$emit('selection-change', {
|
||||||
|
detail: {
|
||||||
|
value: this.backData,
|
||||||
|
index: this.backIndexData
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 用于多选表格,切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中)
|
||||||
|
*/
|
||||||
|
toggleRowSelection(row, selected) {
|
||||||
|
// if (!this.theadChildren) return
|
||||||
|
row = [].concat(row)
|
||||||
|
|
||||||
|
this.trChildren.forEach((item, index) => {
|
||||||
|
// if (item.keyValue) {
|
||||||
|
|
||||||
|
const select = row.findIndex(v => {
|
||||||
|
//
|
||||||
|
if (typeof v === 'number') {
|
||||||
|
return v === index - 1
|
||||||
|
} else {
|
||||||
|
return v[this.rowKey] === item.keyValue
|
||||||
|
}
|
||||||
|
})
|
||||||
|
let ischeck = item.checked
|
||||||
|
if (select !== -1) {
|
||||||
|
if (typeof selected === 'boolean') {
|
||||||
|
item.checked = selected
|
||||||
|
} else {
|
||||||
|
item.checked = !item.checked
|
||||||
|
}
|
||||||
if (ischeck !== item.checked) {
|
if (ischeck !== item.checked) {
|
||||||
this.check(item.rowData||item, item.checked, item.rowData?item.keyValue:null, true)
|
this.check(item.rowData||item, item.checked, item.rowData?item.keyValue:null, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
})
|
})
|
||||||
this.$emit('selection-change', {
|
this.$emit('selection-change', {
|
||||||
detail: {
|
detail: {
|
||||||
value: this.backData,
|
value: this.backData,
|
||||||
index:this.backIndexData
|
index:this.backIndexData
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用于多选表格,清空用户的选择
|
* 用于多选表格,清空用户的选择
|
||||||
*/
|
*/
|
||||||
clearSelection() {
|
clearSelection() {
|
||||||
let theadChildren = this.theadChildren
|
let theadChildren = this.theadChildren
|
||||||
if (!this.theadChildren) {
|
if (!this.theadChildren) {
|
||||||
theadChildren = this.trChildren[0]
|
theadChildren = this.trChildren[0]
|
||||||
}
|
}
|
||||||
// if (!this.theadChildren) return
|
// if (!this.theadChildren) return
|
||||||
theadChildren.checked = false
|
theadChildren.checked = false
|
||||||
theadChildren.indeterminate = false
|
theadChildren.indeterminate = false
|
||||||
this.trChildren.forEach(item => {
|
this.trChildren.forEach(item => {
|
||||||
// if (item.keyValue) {
|
// if (item.keyValue) {
|
||||||
item.checked = false
|
item.checked = false
|
||||||
// }
|
// }
|
||||||
})
|
})
|
||||||
this.backData = []
|
this.backData = []
|
||||||
this.backIndexData = []
|
this.backIndexData = []
|
||||||
this.$emit('selection-change', {
|
this.$emit('selection-change', {
|
||||||
detail: {
|
detail: {
|
||||||
value: [],
|
value: [],
|
||||||
index: []
|
index: []
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 用于多选表格,切换所有行的选中状态
|
* 用于多选表格,切换所有行的选中状态
|
||||||
*/
|
*/
|
||||||
toggleAllSelection() {
|
toggleAllSelection() {
|
||||||
let list = []
|
let list = []
|
||||||
let startIndex = 1
|
let startIndex = 1
|
||||||
let theadChildren = this.theadChildren
|
let theadChildren = this.theadChildren
|
||||||
if (!this.theadChildren) {
|
if (!this.theadChildren) {
|
||||||
|
@ -233,97 +233,97 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.toggleRowSelection(list)
|
this.toggleRowSelection(list)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 选中\取消选中
|
* 选中\取消选中
|
||||||
* @param {Object} child
|
* @param {Object} child
|
||||||
* @param {Object} check
|
* @param {Object} check
|
||||||
* @param {Object} rowValue
|
* @param {Object} rowValue
|
||||||
*/
|
*/
|
||||||
check(child, check, keyValue, emit) {
|
check(child, check, keyValue, emit) {
|
||||||
let theadChildren = this.theadChildren
|
let theadChildren = this.theadChildren
|
||||||
if (!this.theadChildren) {
|
if (!this.theadChildren) {
|
||||||
theadChildren = this.trChildren[0]
|
theadChildren = this.trChildren[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let childDomIndex = this.trChildren.findIndex((item, index) => child === item)
|
let childDomIndex = this.trChildren.findIndex((item, index) => child === item)
|
||||||
if(childDomIndex < 0){
|
if(childDomIndex < 0){
|
||||||
childDomIndex = this.data.findIndex(v=>v[this.rowKey] === keyValue) + 1
|
childDomIndex = this.data.findIndex(v=>v[this.rowKey] === keyValue) + 1
|
||||||
}
|
}
|
||||||
const dataLen = this.trChildren.filter(v => !v.disabled && v.keyValue).length
|
const dataLen = this.trChildren.filter(v => !v.disabled && v.keyValue).length
|
||||||
if (childDomIndex === 0) {
|
if (childDomIndex === 0) {
|
||||||
check ? this.selectionAll() : this.clearSelection()
|
check ? this.selectionAll() : this.clearSelection()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check) {
|
if (check) {
|
||||||
if (keyValue) {
|
if (keyValue) {
|
||||||
this.backData.push(child)
|
this.backData.push(child)
|
||||||
}
|
}
|
||||||
this.backIndexData.push(childDomIndex - 1)
|
this.backIndexData.push(childDomIndex - 1)
|
||||||
} else {
|
} else {
|
||||||
const index = this.backData.findIndex(v => v[this.rowKey] === keyValue)
|
const index = this.backData.findIndex(v => v[this.rowKey] === keyValue)
|
||||||
const idx = this.backIndexData.findIndex(item => item === childDomIndex - 1)
|
const idx = this.backIndexData.findIndex(item => item === childDomIndex - 1)
|
||||||
if (keyValue) {
|
if (keyValue) {
|
||||||
this.backData.splice(index, 1)
|
this.backData.splice(index, 1)
|
||||||
}
|
}
|
||||||
this.backIndexData.splice(idx, 1)
|
this.backIndexData.splice(idx, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
const domCheckAll = this.trChildren.find((item, index) => index > 0 && !item.checked && !item.disabled)
|
const domCheckAll = this.trChildren.find((item, index) => index > 0 && !item.checked && !item.disabled)
|
||||||
if (!domCheckAll) {
|
if (!domCheckAll) {
|
||||||
theadChildren.indeterminate = false
|
theadChildren.indeterminate = false
|
||||||
theadChildren.checked = true
|
theadChildren.checked = true
|
||||||
} else {
|
} else {
|
||||||
theadChildren.indeterminate = true
|
theadChildren.indeterminate = true
|
||||||
theadChildren.checked = false
|
theadChildren.checked = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.backIndexData.length === 0) {
|
if (this.backIndexData.length === 0) {
|
||||||
theadChildren.indeterminate = false
|
theadChildren.indeterminate = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!emit) {
|
if (!emit) {
|
||||||
this.$emit('selection-change', {
|
this.$emit('selection-change', {
|
||||||
detail: {
|
detail: {
|
||||||
value: this.backData,
|
value: this.backData,
|
||||||
index: this.backIndexData
|
index: this.backIndexData
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
$border-color: #ebeef5;
|
$border-color: #ebeef5;
|
||||||
|
|
||||||
.uni-table-scroll {
|
.uni-table-scroll {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
}
|
}
|
||||||
|
|
||||||
.uni-table {
|
.uni-table {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
// box-shadow: 0px 0px 3px 1px rgba(0, 0, 0, 0.1);
|
// box-shadow: 0px 0px 3px 1px rgba(0, 0, 0, 0.1);
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
display: table;
|
display: table;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
::v-deep .uni-table-tr:nth-child(n + 2) {
|
::v-deep .uni-table-tr:nth-child(n + 2) {
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: #f5f7fa;
|
background-color: #f5f7fa;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
::v-deep .uni-table-thead {
|
::v-deep .uni-table-thead {
|
||||||
.uni-table-tr {
|
.uni-table-tr {
|
||||||
|
@ -332,124 +332,124 @@ $border-color: #ebeef5;
|
||||||
background-color:#fafafa;
|
background-color:#fafafa;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* #endif */
|
/* #endif */
|
||||||
}
|
}
|
||||||
|
|
||||||
.table--border {
|
.table--border {
|
||||||
border: 1px $border-color solid;
|
border: 1px $border-color solid;
|
||||||
border-right: none;
|
border-right: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.border-none {
|
.border-none {
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
}
|
}
|
||||||
|
|
||||||
.table--stripe {
|
.table--stripe {
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
::v-deep .uni-table-tr:nth-child(2n + 3) {
|
::v-deep .uni-table-tr:nth-child(2n + 3) {
|
||||||
background-color: #fafafa;
|
background-color: #fafafa;
|
||||||
}
|
}
|
||||||
/* #endif */
|
/* #endif */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 表格加载、无数据样式 */
|
/* 表格加载、无数据样式 */
|
||||||
.uni-table-loading {
|
.uni-table-loading {
|
||||||
position: relative;
|
position: relative;
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
display: table-row;
|
display: table-row;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
height: 50px;
|
height: 50px;
|
||||||
line-height: 50px;
|
line-height: 50px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
.empty-border {
|
.empty-border {
|
||||||
border-right: 1px $border-color solid;
|
border-right: 1px $border-color solid;
|
||||||
}
|
}
|
||||||
.uni-table-text {
|
.uni-table-text {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
.uni-table-mask {
|
.uni-table-mask {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
background-color: rgba(255, 255, 255, 0.8);
|
background-color: rgba(255, 255, 255, 0.8);
|
||||||
z-index: 99;
|
z-index: 99;
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
display: flex;
|
display: flex;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
transition: all 0.5s;
|
transition: all 0.5s;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.uni-table--loader {
|
.uni-table--loader {
|
||||||
width: 30px;
|
width: 30px;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
border: 2px solid #aaa;
|
border: 2px solid #aaa;
|
||||||
// border-bottom-color: transparent;
|
// border-bottom-color: transparent;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
animation: 2s uni-table--loader linear infinite;
|
animation: 2s uni-table--loader linear infinite;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes uni-table--loader {
|
@keyframes uni-table--loader {
|
||||||
0% {
|
0% {
|
||||||
transform: rotate(360deg);
|
transform: rotate(360deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
10% {
|
10% {
|
||||||
border-left-color: transparent;
|
border-left-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
20% {
|
20% {
|
||||||
border-bottom-color: transparent;
|
border-bottom-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
30% {
|
30% {
|
||||||
border-right-color: transparent;
|
border-right-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
40% {
|
40% {
|
||||||
border-top-color: transparent;
|
border-top-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
50% {
|
50% {
|
||||||
transform: rotate(0deg);
|
transform: rotate(0deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
60% {
|
60% {
|
||||||
border-top-color: transparent;
|
border-top-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
70% {
|
70% {
|
||||||
border-left-color: transparent;
|
border-left-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
80% {
|
80% {
|
||||||
border-bottom-color: transparent;
|
border-bottom-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
90% {
|
90% {
|
||||||
border-right-color: transparent;
|
border-right-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
100% {
|
100% {
|
||||||
transform: rotate(-360deg);
|
transform: rotate(-360deg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
<template>
|
<template>
|
||||||
<!-- #ifdef H5 -->
|
<!-- #ifdef H5 -->
|
||||||
<tbody>
|
<tbody>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</tbody>
|
</tbody>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
<!-- #ifndef H5 -->
|
<!-- #ifndef H5 -->
|
||||||
<view><slot></slot></view>
|
<view><slot></slot></view>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'uniBody',
|
name: 'uniBody',
|
||||||
options: {
|
options: {
|
||||||
virtualHost: true
|
virtualHost: true
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {},
|
created() {},
|
||||||
methods: {}
|
methods: {}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -9,30 +9,30 @@
|
||||||
<view class="uni-table-td" :class="{'table--border':border}" :style="{width:width + 'px','text-align':align}">
|
<view class="uni-table-td" :class="{'table--border':border}" :style="{width:width + 'px','text-align':align}">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</view>
|
</view>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
/**
|
/**
|
||||||
* Td 单元格
|
* Td 单元格
|
||||||
* @description 表格中的标准单元格组件
|
* @description 表格中的标准单元格组件
|
||||||
* @tutorial https://ext.dcloud.net.cn/plugin?id=3270
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=3270
|
||||||
* @property {Number} align = [left|center|right] 单元格对齐方式
|
* @property {Number} align = [left|center|right] 单元格对齐方式
|
||||||
*/
|
*/
|
||||||
export default {
|
export default {
|
||||||
name: 'uniTd',
|
name: 'uniTd',
|
||||||
options: {
|
options: {
|
||||||
virtualHost: true
|
virtualHost: true
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
width: {
|
width: {
|
||||||
type: [String, Number],
|
type: [String, Number],
|
||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
align: {
|
align: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'left'
|
default: 'left'
|
||||||
},
|
},
|
||||||
rowspan: {
|
rowspan: {
|
||||||
type: [Number,String],
|
type: [Number,String],
|
||||||
|
@ -41,50 +41,50 @@
|
||||||
colspan: {
|
colspan: {
|
||||||
type: [Number,String],
|
type: [Number,String],
|
||||||
default: 1
|
default: 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
border: false
|
border: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.root = this.getTable()
|
this.root = this.getTable()
|
||||||
this.border = this.root.border
|
this.border = this.root.border
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
/**
|
/**
|
||||||
* 获取父元素实例
|
* 获取父元素实例
|
||||||
*/
|
*/
|
||||||
getTable() {
|
getTable() {
|
||||||
let parent = this.$parent;
|
let parent = this.$parent;
|
||||||
let parentName = parent.$options.name;
|
let parentName = parent.$options.name;
|
||||||
while (parentName !== 'uniTable') {
|
while (parentName !== 'uniTable') {
|
||||||
parent = parent.$parent;
|
parent = parent.$parent;
|
||||||
if (!parent) return false;
|
if (!parent) return false;
|
||||||
parentName = parent.$options.name;
|
parentName = parent.$options.name;
|
||||||
}
|
}
|
||||||
return parent;
|
return parent;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
$border-color:#EBEEF5;
|
$border-color:#EBEEF5;
|
||||||
|
|
||||||
.uni-table-td {
|
.uni-table-td {
|
||||||
display: table-cell;
|
display: table-cell;
|
||||||
padding: 8px 10px;
|
padding: 8px 10px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
border-bottom: 1px $border-color solid;
|
border-bottom: 1px $border-color solid;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
color: #606266;
|
color: #606266;
|
||||||
line-height: 23px;
|
line-height: 23px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table--border {
|
.table--border {
|
||||||
border-right: 1px $border-color solid;
|
border-right: 1px $border-color solid;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,285 +1,285 @@
|
||||||
<template>
|
<template>
|
||||||
<!-- #ifdef H5 -->
|
<!-- #ifdef H5 -->
|
||||||
<th :rowspan="rowspan" :colspan="colspan" class="uni-table-th" :class="{ 'table--border': border }" :style="{ width: customWidth + 'px', 'text-align': align }">
|
<th :rowspan="rowspan" :colspan="colspan" class="uni-table-th" :class="{ 'table--border': border }" :style="{ width: customWidth + 'px', 'text-align': align }">
|
||||||
<view class="uni-table-th-row">
|
<view class="uni-table-th-row">
|
||||||
<view class="uni-table-th-content" :style="{ 'justify-content': contentAlign }" @click="sort">
|
<view class="uni-table-th-content" :style="{ 'justify-content': contentAlign }" @click="sort">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<view v-if="sortable" class="arrow-box">
|
<view v-if="sortable" class="arrow-box">
|
||||||
<text class="arrow up" :class="{ active: ascending }" @click.stop="ascendingFn"></text>
|
<text class="arrow up" :class="{ active: ascending }" @click.stop="ascendingFn"></text>
|
||||||
<text class="arrow down" :class="{ active: descending }" @click.stop="descendingFn"></text>
|
<text class="arrow down" :class="{ active: descending }" @click.stop="descendingFn"></text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<dropdown v-if="filterType || filterData.length" :filterDefaultValue="filterDefaultValue" :filterData="filterData" :filterType="filterType" @change="ondropdown"></dropdown>
|
<dropdown v-if="filterType || filterData.length" :filterDefaultValue="filterDefaultValue" :filterData="filterData" :filterType="filterType" @change="ondropdown"></dropdown>
|
||||||
</view>
|
</view>
|
||||||
</th>
|
</th>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
<!-- #ifndef H5 -->
|
<!-- #ifndef H5 -->
|
||||||
<view class="uni-table-th" :class="{ 'table--border': border }" :style="{ width: customWidth + 'px', 'text-align': align }"><slot></slot></view>
|
<view class="uni-table-th" :class="{ 'table--border': border }" :style="{ width: customWidth + 'px', 'text-align': align }"><slot></slot></view>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
import dropdown from './filter-dropdown.vue'
|
import dropdown from './filter-dropdown.vue'
|
||||||
// #endif
|
// #endif
|
||||||
/**
|
/**
|
||||||
* Th 表头
|
* Th 表头
|
||||||
* @description 表格内的表头单元格组件
|
* @description 表格内的表头单元格组件
|
||||||
* @tutorial https://ext.dcloud.net.cn/plugin?id=3270
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=3270
|
||||||
* @property {Number | String} width 单元格宽度(支持纯数字、携带单位px或rpx)
|
* @property {Number | String} width 单元格宽度(支持纯数字、携带单位px或rpx)
|
||||||
* @property {Boolean} sortable 是否启用排序
|
* @property {Boolean} sortable 是否启用排序
|
||||||
* @property {Number} align = [left|center|right] 单元格对齐方式
|
* @property {Number} align = [left|center|right] 单元格对齐方式
|
||||||
* @value left 单元格文字左侧对齐
|
* @value left 单元格文字左侧对齐
|
||||||
* @value center 单元格文字居中
|
* @value center 单元格文字居中
|
||||||
* @value right 单元格文字右侧对齐
|
* @value right 单元格文字右侧对齐
|
||||||
* @property {Array} filterData 筛选数据
|
* @property {Array} filterData 筛选数据
|
||||||
* @property {String} filterType [search|select] 筛选类型
|
* @property {String} filterType [search|select] 筛选类型
|
||||||
* @value search 关键字搜素
|
* @value search 关键字搜素
|
||||||
* @value select 条件选择
|
* @value select 条件选择
|
||||||
* @event {Function} sort-change 排序触发事件
|
* @event {Function} sort-change 排序触发事件
|
||||||
*/
|
*/
|
||||||
export default {
|
export default {
|
||||||
name: 'uniTh',
|
name: 'uniTh',
|
||||||
options: {
|
options: {
|
||||||
virtualHost: true
|
virtualHost: true
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
dropdown
|
dropdown
|
||||||
// #endif
|
// #endif
|
||||||
},
|
},
|
||||||
emits:['sort-change','filter-change'],
|
emits:['sort-change','filter-change'],
|
||||||
props: {
|
props: {
|
||||||
width: {
|
width: {
|
||||||
type: [String, Number],
|
type: [String, Number],
|
||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
align: {
|
align: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'left'
|
default: 'left'
|
||||||
},
|
},
|
||||||
rowspan: {
|
rowspan: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: 1
|
default: 1
|
||||||
},
|
},
|
||||||
colspan: {
|
colspan: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: 1
|
default: 1
|
||||||
},
|
},
|
||||||
sortable: {
|
sortable: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
filterType: {
|
filterType: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ""
|
default: ""
|
||||||
},
|
},
|
||||||
filterData: {
|
filterData: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default () {
|
default () {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
filterDefaultValue: {
|
filterDefaultValue: {
|
||||||
type: [Array,String],
|
type: [Array,String],
|
||||||
default () {
|
default () {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
border: false,
|
border: false,
|
||||||
ascending: false,
|
ascending: false,
|
||||||
descending: false
|
descending: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
// 根据props中的width属性 自动匹配当前th的宽度(px)
|
// 根据props中的width属性 自动匹配当前th的宽度(px)
|
||||||
customWidth(){
|
customWidth(){
|
||||||
if(typeof this.width === 'number'){
|
if(typeof this.width === 'number'){
|
||||||
return this.width
|
return this.width
|
||||||
} else if(typeof this.width === 'string') {
|
} else if(typeof this.width === 'string') {
|
||||||
let regexHaveUnitPx = new RegExp(/^[1-9][0-9]*px$/g)
|
let regexHaveUnitPx = new RegExp(/^[1-9][0-9]*px$/g)
|
||||||
let regexHaveUnitRpx = new RegExp(/^[1-9][0-9]*rpx$/g)
|
let regexHaveUnitRpx = new RegExp(/^[1-9][0-9]*rpx$/g)
|
||||||
let regexHaveNotUnit = new RegExp(/^[1-9][0-9]*$/g)
|
let regexHaveNotUnit = new RegExp(/^[1-9][0-9]*$/g)
|
||||||
if (this.width.match(regexHaveUnitPx) !== null) { // 携带了 px
|
if (this.width.match(regexHaveUnitPx) !== null) { // 携带了 px
|
||||||
return this.width.replace('px', '')
|
return this.width.replace('px', '')
|
||||||
} else if (this.width.match(regexHaveUnitRpx) !== null) { // 携带了 rpx
|
} else if (this.width.match(regexHaveUnitRpx) !== null) { // 携带了 rpx
|
||||||
let numberRpx = Number(this.width.replace('rpx', ''))
|
let numberRpx = Number(this.width.replace('rpx', ''))
|
||||||
let widthCoe = uni.getSystemInfoSync().screenWidth / 750
|
let widthCoe = uni.getSystemInfoSync().screenWidth / 750
|
||||||
return Math.round(numberRpx * widthCoe)
|
return Math.round(numberRpx * widthCoe)
|
||||||
} else if (this.width.match(regexHaveNotUnit) !== null) { // 未携带 rpx或px 的纯数字 String
|
} else if (this.width.match(regexHaveNotUnit) !== null) { // 未携带 rpx或px 的纯数字 String
|
||||||
return this.width
|
return this.width
|
||||||
} else { // 不符合格式
|
} else { // 不符合格式
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
contentAlign() {
|
contentAlign() {
|
||||||
let align = 'left'
|
let align = 'left'
|
||||||
switch (this.align) {
|
switch (this.align) {
|
||||||
case 'left':
|
case 'left':
|
||||||
align = 'flex-start'
|
align = 'flex-start'
|
||||||
break
|
break
|
||||||
case 'center':
|
case 'center':
|
||||||
align = 'center'
|
align = 'center'
|
||||||
break
|
break
|
||||||
case 'right':
|
case 'right':
|
||||||
align = 'flex-end'
|
align = 'flex-end'
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return align
|
return align
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.root = this.getTable('uniTable')
|
this.root = this.getTable('uniTable')
|
||||||
this.rootTr = this.getTable('uniTr')
|
this.rootTr = this.getTable('uniTr')
|
||||||
this.rootTr.minWidthUpdate(this.customWidth ? this.customWidth : 140)
|
this.rootTr.minWidthUpdate(this.customWidth ? this.customWidth : 140)
|
||||||
this.border = this.root.border
|
this.border = this.root.border
|
||||||
this.root.thChildren.push(this)
|
this.root.thChildren.push(this)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
sort() {
|
sort() {
|
||||||
if (!this.sortable) return
|
if (!this.sortable) return
|
||||||
this.clearOther()
|
this.clearOther()
|
||||||
if (!this.ascending && !this.descending) {
|
if (!this.ascending && !this.descending) {
|
||||||
this.ascending = true
|
this.ascending = true
|
||||||
this.$emit('sort-change', { order: 'ascending' })
|
this.$emit('sort-change', { order: 'ascending' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.ascending && !this.descending) {
|
if (this.ascending && !this.descending) {
|
||||||
this.ascending = false
|
this.ascending = false
|
||||||
this.descending = true
|
this.descending = true
|
||||||
this.$emit('sort-change', { order: 'descending' })
|
this.$emit('sort-change', { order: 'descending' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.ascending && this.descending) {
|
if (!this.ascending && this.descending) {
|
||||||
this.ascending = false
|
this.ascending = false
|
||||||
this.descending = false
|
this.descending = false
|
||||||
this.$emit('sort-change', { order: null })
|
this.$emit('sort-change', { order: null })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ascendingFn() {
|
ascendingFn() {
|
||||||
this.clearOther()
|
this.clearOther()
|
||||||
this.ascending = !this.ascending
|
this.ascending = !this.ascending
|
||||||
this.descending = false
|
this.descending = false
|
||||||
this.$emit('sort-change', { order: this.ascending ? 'ascending' : null })
|
this.$emit('sort-change', { order: this.ascending ? 'ascending' : null })
|
||||||
},
|
},
|
||||||
descendingFn() {
|
descendingFn() {
|
||||||
this.clearOther()
|
this.clearOther()
|
||||||
this.descending = !this.descending
|
this.descending = !this.descending
|
||||||
this.ascending = false
|
this.ascending = false
|
||||||
this.$emit('sort-change', { order: this.descending ? 'descending' : null })
|
this.$emit('sort-change', { order: this.descending ? 'descending' : null })
|
||||||
},
|
},
|
||||||
clearOther() {
|
clearOther() {
|
||||||
this.root.thChildren.map(item => {
|
this.root.thChildren.map(item => {
|
||||||
if (item !== this) {
|
if (item !== this) {
|
||||||
item.ascending = false
|
item.ascending = false
|
||||||
item.descending = false
|
item.descending = false
|
||||||
}
|
}
|
||||||
return item
|
return item
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
ondropdown(e) {
|
ondropdown(e) {
|
||||||
this.$emit("filter-change", e)
|
this.$emit("filter-change", e)
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 获取父元素实例
|
* 获取父元素实例
|
||||||
*/
|
*/
|
||||||
getTable(name) {
|
getTable(name) {
|
||||||
let parent = this.$parent
|
let parent = this.$parent
|
||||||
let parentName = parent.$options.name
|
let parentName = parent.$options.name
|
||||||
while (parentName !== name) {
|
while (parentName !== name) {
|
||||||
parent = parent.$parent
|
parent = parent.$parent
|
||||||
if (!parent) return false
|
if (!parent) return false
|
||||||
parentName = parent.$options.name
|
parentName = parent.$options.name
|
||||||
}
|
}
|
||||||
return parent
|
return parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
$border-color: #ebeef5;
|
$border-color: #ebeef5;
|
||||||
$uni-primary: #007aff !default;
|
$uni-primary: #007aff !default;
|
||||||
|
|
||||||
.uni-table-th {
|
.uni-table-th {
|
||||||
padding: 12px 10px;
|
padding: 12px 10px;
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
display: table-cell;
|
display: table-cell;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: #909399;
|
color: #909399;
|
||||||
border-bottom: 1px $border-color solid;
|
border-bottom: 1px $border-color solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
.uni-table-th-row {
|
.uni-table-th-row {
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
display: flex;
|
display: flex;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table--border {
|
.table--border {
|
||||||
border-right: 1px $border-color solid;
|
border-right: 1px $border-color solid;
|
||||||
}
|
}
|
||||||
.uni-table-th-content {
|
.uni-table-th-content {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
.arrow-box {
|
.arrow-box {
|
||||||
}
|
}
|
||||||
.arrow {
|
.arrow {
|
||||||
display: block;
|
display: block;
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 10px;
|
width: 10px;
|
||||||
height: 8px;
|
height: 8px;
|
||||||
// border: 1px red solid;
|
// border: 1px red solid;
|
||||||
left: 5px;
|
left: 5px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.down {
|
.down {
|
||||||
top: 3px;
|
top: 3px;
|
||||||
::after {
|
::after {
|
||||||
content: '';
|
content: '';
|
||||||
width: 8px;
|
width: 8px;
|
||||||
height: 8px;
|
height: 8px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 2px;
|
left: 2px;
|
||||||
top: -5px;
|
top: -5px;
|
||||||
transform: rotate(45deg);
|
transform: rotate(45deg);
|
||||||
background-color: #ccc;
|
background-color: #ccc;
|
||||||
}
|
}
|
||||||
&.active {
|
&.active {
|
||||||
::after {
|
::after {
|
||||||
background-color: $uni-primary;
|
background-color: $uni-primary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.up {
|
.up {
|
||||||
::after {
|
::after {
|
||||||
content: '';
|
content: '';
|
||||||
width: 8px;
|
width: 8px;
|
||||||
height: 8px;
|
height: 8px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 2px;
|
left: 2px;
|
||||||
top: 5px;
|
top: 5px;
|
||||||
transform: rotate(45deg);
|
transform: rotate(45deg);
|
||||||
background-color: #ccc;
|
background-color: #ccc;
|
||||||
}
|
}
|
||||||
&.active {
|
&.active {
|
||||||
::after {
|
::after {
|
||||||
background-color: $uni-primary;
|
background-color: $uni-primary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,129 +1,129 @@
|
||||||
<template>
|
<template>
|
||||||
<!-- #ifdef H5 -->
|
<!-- #ifdef H5 -->
|
||||||
<thead class="uni-table-thead">
|
<thead class="uni-table-thead">
|
||||||
<tr class="uni-table-tr">
|
<tr class="uni-table-tr">
|
||||||
<th :rowspan="rowspan" colspan="1" class="checkbox" :class="{ 'tr-table--border': border }">
|
<th :rowspan="rowspan" colspan="1" class="checkbox" :class="{ 'tr-table--border': border }">
|
||||||
<table-checkbox :indeterminate="indeterminate" :checked="checked" @checkboxSelected="checkboxSelected"></table-checkbox>
|
<table-checkbox :indeterminate="indeterminate" :checked="checked" @checkboxSelected="checkboxSelected"></table-checkbox>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</thead>
|
</thead>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
<!-- #ifndef H5 -->
|
<!-- #ifndef H5 -->
|
||||||
<view class="uni-table-thead"><slot></slot></view>
|
<view class="uni-table-thead"><slot></slot></view>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import tableCheckbox from '../uni-tr/table-checkbox.vue'
|
import tableCheckbox from '../uni-tr/table-checkbox.vue'
|
||||||
export default {
|
export default {
|
||||||
name: 'uniThead',
|
name: 'uniThead',
|
||||||
components: {
|
components: {
|
||||||
tableCheckbox
|
tableCheckbox
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
virtualHost: true
|
virtualHost: true
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
border: false,
|
border: false,
|
||||||
selection: false,
|
selection: false,
|
||||||
rowspan: 1,
|
rowspan: 1,
|
||||||
indeterminate: false,
|
indeterminate: false,
|
||||||
checked: false
|
checked: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.root = this.getTable()
|
this.root = this.getTable()
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
this.root.theadChildren = this
|
this.root.theadChildren = this
|
||||||
// #endif
|
// #endif
|
||||||
this.border = this.root.border
|
this.border = this.root.border
|
||||||
this.selection = this.root.type
|
this.selection = this.root.type
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
init(self) {
|
init(self) {
|
||||||
this.rowspan++
|
this.rowspan++
|
||||||
},
|
},
|
||||||
checkboxSelected(e) {
|
checkboxSelected(e) {
|
||||||
this.indeterminate = false
|
this.indeterminate = false
|
||||||
const backIndexData = this.root.backIndexData
|
const backIndexData = this.root.backIndexData
|
||||||
const data = this.root.trChildren.filter(v => !v.disabled && v.keyValue)
|
const data = this.root.trChildren.filter(v => !v.disabled && v.keyValue)
|
||||||
if (backIndexData.length === data.length) {
|
if (backIndexData.length === data.length) {
|
||||||
this.checked = false
|
this.checked = false
|
||||||
this.root.clearSelection()
|
this.root.clearSelection()
|
||||||
} else {
|
} else {
|
||||||
this.checked = true
|
this.checked = true
|
||||||
this.root.selectionAll()
|
this.root.selectionAll()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 获取父元素实例
|
* 获取父元素实例
|
||||||
*/
|
*/
|
||||||
getTable(name = 'uniTable') {
|
getTable(name = 'uniTable') {
|
||||||
let parent = this.$parent
|
let parent = this.$parent
|
||||||
let parentName = parent.$options.name
|
let parentName = parent.$options.name
|
||||||
while (parentName !== name) {
|
while (parentName !== name) {
|
||||||
parent = parent.$parent
|
parent = parent.$parent
|
||||||
if (!parent) return false
|
if (!parent) return false
|
||||||
parentName = parent.$options.name
|
parentName = parent.$options.name
|
||||||
}
|
}
|
||||||
return parent
|
return parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
$border-color: #ebeef5;
|
$border-color: #ebeef5;
|
||||||
|
|
||||||
.uni-table-thead {
|
.uni-table-thead {
|
||||||
display: table-header-group;
|
display: table-header-group;
|
||||||
}
|
}
|
||||||
|
|
||||||
.uni-table-tr {
|
.uni-table-tr {
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
display: table-row;
|
display: table-row;
|
||||||
transition: all 0.3s;
|
transition: all 0.3s;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
border: 1px red solid;
|
border: 1px red solid;
|
||||||
background-color: #fafafa;
|
background-color: #fafafa;
|
||||||
}
|
}
|
||||||
|
|
||||||
.checkbox {
|
.checkbox {
|
||||||
padding: 0 8px;
|
padding: 0 8px;
|
||||||
width: 26px;
|
width: 26px;
|
||||||
padding-left: 12px;
|
padding-left: 12px;
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
display: table-cell;
|
display: table-cell;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
color: #333;
|
color: #333;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
border-bottom: 1px $border-color solid;
|
border-bottom: 1px $border-color solid;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
// text-align: center;
|
// text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tr-table--border {
|
.tr-table--border {
|
||||||
border-right: 1px $border-color solid;
|
border-right: 1px $border-color solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
.uni-table-tr {
|
.uni-table-tr {
|
||||||
::v-deep .uni-table-th {
|
::v-deep .uni-table-th {
|
||||||
&.table--border:last-child {
|
&.table--border:last-child {
|
||||||
// border-right: none;
|
// border-right: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
::v-deep .uni-table-td {
|
::v-deep .uni-table-td {
|
||||||
&.table--border:last-child {
|
&.table--border:last-child {
|
||||||
// border-right: none;
|
// border-right: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* #endif */
|
/* #endif */
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,41 +1,41 @@
|
||||||
<template>
|
<template>
|
||||||
<view class="uni-table-checkbox" @click="selected">
|
<view class="uni-table-checkbox" @click="selected">
|
||||||
<view v-if="!indeterminate" class="checkbox__inner" :class="{'is-checked':isChecked,'is-disable':isDisabled}">
|
<view v-if="!indeterminate" class="checkbox__inner" :class="{'is-checked':isChecked,'is-disable':isDisabled}">
|
||||||
<view class="checkbox__inner-icon"></view>
|
<view class="checkbox__inner-icon"></view>
|
||||||
</view>
|
</view>
|
||||||
<view v-else class="checkbox__inner checkbox--indeterminate">
|
<view v-else class="checkbox__inner checkbox--indeterminate">
|
||||||
<view class="checkbox__inner-icon"></view>
|
<view class="checkbox__inner-icon"></view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'TableCheckbox',
|
name: 'TableCheckbox',
|
||||||
emits:['checkboxSelected'],
|
emits:['checkboxSelected'],
|
||||||
props: {
|
props: {
|
||||||
indeterminate: {
|
indeterminate: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
checked: {
|
checked: {
|
||||||
type: [Boolean,String],
|
type: [Boolean,String],
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
disabled: {
|
disabled: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
index: {
|
index: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: -1
|
default: -1
|
||||||
},
|
},
|
||||||
cellData: {
|
cellData: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default () {
|
default () {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch:{
|
watch:{
|
||||||
checked(newVal){
|
checked(newVal){
|
||||||
|
@ -48,132 +48,132 @@
|
||||||
indeterminate(newVal){
|
indeterminate(newVal){
|
||||||
this.isIndeterminate = newVal
|
this.isIndeterminate = newVal
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isChecked: false,
|
isChecked: false,
|
||||||
isDisabled: false,
|
isDisabled: false,
|
||||||
isIndeterminate:false
|
isIndeterminate:false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
if(typeof this.checked === 'boolean'){
|
if(typeof this.checked === 'boolean'){
|
||||||
this.isChecked = this.checked
|
this.isChecked = this.checked
|
||||||
}
|
}
|
||||||
this.isDisabled = this.disabled
|
this.isDisabled = this.disabled
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
selected() {
|
selected() {
|
||||||
if (this.isDisabled) return
|
if (this.isDisabled) return
|
||||||
this.isIndeterminate = false
|
this.isIndeterminate = false
|
||||||
this.isChecked = !this.isChecked
|
this.isChecked = !this.isChecked
|
||||||
this.$emit('checkboxSelected', {
|
this.$emit('checkboxSelected', {
|
||||||
checked: this.isChecked,
|
checked: this.isChecked,
|
||||||
data: this.cellData
|
data: this.cellData
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
$uni-primary: #007aff !default;
|
$uni-primary: #007aff !default;
|
||||||
$border-color: #DCDFE6;
|
$border-color: #DCDFE6;
|
||||||
$disable:0.4;
|
$disable:0.4;
|
||||||
|
|
||||||
.uni-table-checkbox {
|
.uni-table-checkbox {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
margin: 5px 0;
|
margin: 5px 0;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
// 多选样式
|
// 多选样式
|
||||||
.checkbox__inner {
|
.checkbox__inner {
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 16px;
|
width: 16px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
border: 1px solid $border-color;
|
border: 1px solid $border-color;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
|
|
||||||
.checkbox__inner-icon {
|
.checkbox__inner-icon {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
/* #ifdef APP-NVUE */
|
/* #ifdef APP-NVUE */
|
||||||
top: 2px;
|
top: 2px;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
top: 2px;
|
top: 2px;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
left: 5px;
|
left: 5px;
|
||||||
height: 7px;
|
height: 7px;
|
||||||
width: 3px;
|
width: 3px;
|
||||||
border: 1px solid #fff;
|
border: 1px solid #fff;
|
||||||
border-left: 0;
|
border-left: 0;
|
||||||
border-top: 0;
|
border-top: 0;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform-origin: center;
|
transform-origin: center;
|
||||||
transform: rotate(45deg);
|
transform: rotate(45deg);
|
||||||
box-sizing: content-box;
|
box-sizing: content-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.checkbox--indeterminate {
|
&.checkbox--indeterminate {
|
||||||
border-color: $uni-primary;
|
border-color: $uni-primary;
|
||||||
background-color: $uni-primary;
|
background-color: $uni-primary;
|
||||||
|
|
||||||
.checkbox__inner-icon {
|
.checkbox__inner-icon {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transform: rotate(0deg);
|
transform: rotate(0deg);
|
||||||
height: 2px;
|
height: 2px;
|
||||||
top: 0;
|
top: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
left: 0px;
|
left: 0px;
|
||||||
right: 0px;
|
right: 0px;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
width: auto;
|
width: auto;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
transform: scale(0.5);
|
transform: scale(0.5);
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&:hover{
|
&:hover{
|
||||||
border-color: $uni-primary;
|
border-color: $uni-primary;
|
||||||
}
|
}
|
||||||
// 禁用
|
// 禁用
|
||||||
&.is-disable {
|
&.is-disable {
|
||||||
/* #ifdef H5 */
|
/* #ifdef H5 */
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
background-color: #F2F6FC;
|
background-color: #F2F6FC;
|
||||||
border-color: $border-color;
|
border-color: $border-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 选中
|
// 选中
|
||||||
&.is-checked {
|
&.is-checked {
|
||||||
border-color: $uni-primary;
|
border-color: $uni-primary;
|
||||||
background-color: $uni-primary;
|
background-color: $uni-primary;
|
||||||
|
|
||||||
.checkbox__inner-icon {
|
.checkbox__inner-icon {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transform: rotate(45deg);
|
transform: rotate(45deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 选中禁用
|
// 选中禁用
|
||||||
&.is-disable {
|
&.is-disable {
|
||||||
opacity: $disable;
|
opacity: $disable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,84 +1,84 @@
|
||||||
<template>
|
<template>
|
||||||
<!-- #ifdef H5 -->
|
<!-- #ifdef H5 -->
|
||||||
<tr class="uni-table-tr">
|
<tr class="uni-table-tr">
|
||||||
<th v-if="selection === 'selection' && ishead" class="checkbox" :class="{ 'tr-table--border': border }">
|
<th v-if="selection === 'selection' && ishead" class="checkbox" :class="{ 'tr-table--border': border }">
|
||||||
<table-checkbox :checked="checked" :indeterminate="indeterminate" :disabled="disabled" @checkboxSelected="checkboxSelected"></table-checkbox>
|
<table-checkbox :checked="checked" :indeterminate="indeterminate" :disabled="disabled" @checkboxSelected="checkboxSelected"></table-checkbox>
|
||||||
</th>
|
</th>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<!-- <uni-th class="th-fixed">123</uni-th> -->
|
<!-- <uni-th class="th-fixed">123</uni-th> -->
|
||||||
</tr>
|
</tr>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
<!-- #ifndef H5 -->
|
<!-- #ifndef H5 -->
|
||||||
<view class="uni-table-tr">
|
<view class="uni-table-tr">
|
||||||
<view v-if="selection === 'selection' " class="checkbox" :class="{ 'tr-table--border': border }">
|
<view v-if="selection === 'selection' " class="checkbox" :class="{ 'tr-table--border': border }">
|
||||||
<table-checkbox :checked="checked" :indeterminate="indeterminate" :disabled="disabled" @checkboxSelected="checkboxSelected"></table-checkbox>
|
<table-checkbox :checked="checked" :indeterminate="indeterminate" :disabled="disabled" @checkboxSelected="checkboxSelected"></table-checkbox>
|
||||||
</view>
|
</view>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</view>
|
</view>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import tableCheckbox from './table-checkbox.vue'
|
import tableCheckbox from './table-checkbox.vue'
|
||||||
/**
|
/**
|
||||||
* Tr 表格行组件
|
* Tr 表格行组件
|
||||||
* @description 表格行组件 仅包含 th,td 组件
|
* @description 表格行组件 仅包含 th,td 组件
|
||||||
* @tutorial https://ext.dcloud.net.cn/plugin?id=
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=
|
||||||
*/
|
*/
|
||||||
export default {
|
export default {
|
||||||
name: 'uniTr',
|
name: 'uniTr',
|
||||||
components: { tableCheckbox },
|
components: { tableCheckbox },
|
||||||
props: {
|
props: {
|
||||||
disabled: {
|
disabled: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
keyValue: {
|
keyValue: {
|
||||||
type: [String, Number],
|
type: [String, Number],
|
||||||
default: ''
|
default: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
virtualHost: true
|
virtualHost: true
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
value: false,
|
value: false,
|
||||||
border: false,
|
border: false,
|
||||||
selection: false,
|
selection: false,
|
||||||
widthThArr: [],
|
widthThArr: [],
|
||||||
ishead: true,
|
ishead: true,
|
||||||
checked: false,
|
checked: false,
|
||||||
indeterminate:false
|
indeterminate:false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.root = this.getTable()
|
this.root = this.getTable()
|
||||||
this.head = this.getTable('uniThead')
|
this.head = this.getTable('uniThead')
|
||||||
if (this.head) {
|
if (this.head) {
|
||||||
this.ishead = false
|
this.ishead = false
|
||||||
this.head.init(this)
|
this.head.init(this)
|
||||||
}
|
}
|
||||||
this.border = this.root.border
|
this.border = this.root.border
|
||||||
this.selection = this.root.type
|
this.selection = this.root.type
|
||||||
this.root.trChildren.push(this)
|
this.root.trChildren.push(this)
|
||||||
const rowData = this.root.data.find(v => v[this.root.rowKey] === this.keyValue)
|
const rowData = this.root.data.find(v => v[this.root.rowKey] === this.keyValue)
|
||||||
if(rowData){
|
if(rowData){
|
||||||
this.rowData = rowData
|
this.rowData = rowData
|
||||||
}
|
}
|
||||||
this.root.isNodata()
|
this.root.isNodata()
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.widthThArr.length > 0) {
|
if (this.widthThArr.length > 0) {
|
||||||
const selectionWidth = this.selection === 'selection' ? 50 : 0
|
const selectionWidth = this.selection === 'selection' ? 50 : 0
|
||||||
this.root.minWidth = this.widthThArr.reduce((a, b) => Number(a) + Number(b)) + selectionWidth
|
this.root.minWidth = this.widthThArr.reduce((a, b) => Number(a) + Number(b)) + selectionWidth
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// #ifndef VUE3
|
// #ifndef VUE3
|
||||||
destroyed() {
|
destroyed() {
|
||||||
const index = this.root.trChildren.findIndex(i => i === this)
|
const index = this.root.trChildren.findIndex(i => i === this)
|
||||||
this.root.trChildren.splice(index, 1)
|
this.root.trChildren.splice(index, 1)
|
||||||
this.root.isNodata()
|
this.root.isNodata()
|
||||||
},
|
},
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef VUE3
|
// #ifdef VUE3
|
||||||
|
@ -87,85 +87,85 @@ export default {
|
||||||
this.root.trChildren.splice(index, 1)
|
this.root.trChildren.splice(index, 1)
|
||||||
this.root.isNodata()
|
this.root.isNodata()
|
||||||
},
|
},
|
||||||
// #endif
|
// #endif
|
||||||
methods: {
|
methods: {
|
||||||
minWidthUpdate(width) {
|
minWidthUpdate(width) {
|
||||||
this.widthThArr.push(width)
|
this.widthThArr.push(width)
|
||||||
},
|
},
|
||||||
// 选中
|
// 选中
|
||||||
checkboxSelected(e) {
|
checkboxSelected(e) {
|
||||||
let rootData = this.root.data.find(v => v[this.root.rowKey] === this.keyValue)
|
let rootData = this.root.data.find(v => v[this.root.rowKey] === this.keyValue)
|
||||||
this.checked = e.checked
|
this.checked = e.checked
|
||||||
this.root.check(rootData||this, e.checked,rootData? this.keyValue:null)
|
this.root.check(rootData||this, e.checked,rootData? this.keyValue:null)
|
||||||
},
|
},
|
||||||
change(e) {
|
change(e) {
|
||||||
this.root.trChildren.forEach(item => {
|
this.root.trChildren.forEach(item => {
|
||||||
if (item === this) {
|
if (item === this) {
|
||||||
this.root.check(this, e.detail.value.length > 0 ? true : false)
|
this.root.check(this, e.detail.value.length > 0 ? true : false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 获取父元素实例
|
* 获取父元素实例
|
||||||
*/
|
*/
|
||||||
getTable(name = 'uniTable') {
|
getTable(name = 'uniTable') {
|
||||||
let parent = this.$parent
|
let parent = this.$parent
|
||||||
let parentName = parent.$options.name
|
let parentName = parent.$options.name
|
||||||
while (parentName !== name) {
|
while (parentName !== name) {
|
||||||
parent = parent.$parent
|
parent = parent.$parent
|
||||||
if (!parent) return false
|
if (!parent) return false
|
||||||
parentName = parent.$options.name
|
parentName = parent.$options.name
|
||||||
}
|
}
|
||||||
return parent
|
return parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
$border-color: #ebeef5;
|
$border-color: #ebeef5;
|
||||||
|
|
||||||
.uni-table-tr {
|
.uni-table-tr {
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
display: table-row;
|
display: table-row;
|
||||||
transition: all 0.3s;
|
transition: all 0.3s;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
}
|
}
|
||||||
|
|
||||||
.checkbox {
|
.checkbox {
|
||||||
padding: 0 8px;
|
padding: 0 8px;
|
||||||
width: 26px;
|
width: 26px;
|
||||||
padding-left: 12px;
|
padding-left: 12px;
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
display: table-cell;
|
display: table-cell;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
/* #endif */
|
/* #endif */
|
||||||
color: #333;
|
color: #333;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
border-bottom: 1px $border-color solid;
|
border-bottom: 1px $border-color solid;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
// text-align: center;
|
// text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tr-table--border {
|
.tr-table--border {
|
||||||
border-right: 1px $border-color solid;
|
border-right: 1px $border-color solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* #ifndef APP-NVUE */
|
/* #ifndef APP-NVUE */
|
||||||
.uni-table-tr {
|
.uni-table-tr {
|
||||||
::v-deep .uni-table-th {
|
::v-deep .uni-table-th {
|
||||||
&.table--border:last-child {
|
&.table--border:last-child {
|
||||||
// border-right: none;
|
// border-right: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
::v-deep .uni-table-td {
|
::v-deep .uni-table-td {
|
||||||
&.table--border:last-child {
|
&.table--border:last-child {
|
||||||
// border-right: none;
|
// border-right: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* #endif */
|
/* #endif */
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"filter-dropdown.reset": "Reset",
|
||||||
|
"filter-dropdown.search": "Search",
|
||||||
|
"filter-dropdown.submit": "Submit",
|
||||||
|
"filter-dropdown.filter": "Filter",
|
||||||
|
"filter-dropdown.gt": "Greater or equal to",
|
||||||
|
"filter-dropdown.lt": "Less than or equal to",
|
||||||
|
"filter-dropdown.date": "Date"
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"filter-dropdown.reset": "Reiniciar",
|
||||||
|
"filter-dropdown.search": "Búsqueda",
|
||||||
|
"filter-dropdown.submit": "Entregar",
|
||||||
|
"filter-dropdown.filter": "Filtrar",
|
||||||
|
"filter-dropdown.gt": "Mayor o igual a",
|
||||||
|
"filter-dropdown.lt": "Menos que o igual a",
|
||||||
|
"filter-dropdown.date": "Fecha"
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"filter-dropdown.reset": "Réinitialiser",
|
||||||
|
"filter-dropdown.search": "Chercher",
|
||||||
|
"filter-dropdown.submit": "Soumettre",
|
||||||
|
"filter-dropdown.filter": "Filtre",
|
||||||
|
"filter-dropdown.gt": "Supérieur ou égal à",
|
||||||
|
"filter-dropdown.lt": "Inférieur ou égal à",
|
||||||
|
"filter-dropdown.date": "Date"
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
import en from './en.json'
|
||||||
|
import es from './es.json'
|
||||||
|
import fr from './fr.json'
|
||||||
|
import zhHans from './zh-Hans.json'
|
||||||
|
import zhHant from './zh-Hant.json'
|
||||||
|
export default {
|
||||||
|
en,
|
||||||
|
es,
|
||||||
|
fr,
|
||||||
|
'zh-Hans': zhHans,
|
||||||
|
'zh-Hant': zhHant
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"filter-dropdown.reset": "重置",
|
||||||
|
"filter-dropdown.search": "搜索",
|
||||||
|
"filter-dropdown.submit": "确定",
|
||||||
|
"filter-dropdown.filter": "筛选",
|
||||||
|
"filter-dropdown.gt": "大于等于",
|
||||||
|
"filter-dropdown.lt": "小于等于",
|
||||||
|
"filter-dropdown.date": "日期范围"
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"filter-dropdown.reset": "重置",
|
||||||
|
"filter-dropdown.search": "搜索",
|
||||||
|
"filter-dropdown.submit": "確定",
|
||||||
|
"filter-dropdown.filter": "篩選",
|
||||||
|
"filter-dropdown.gt": "大於等於",
|
||||||
|
"filter-dropdown.lt": "小於等於",
|
||||||
|
"filter-dropdown.date": "日期範圍"
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
{
|
||||||
|
"id": "uni-table",
|
||||||
|
"displayName": "uni-table 表格",
|
||||||
|
"version": "1.2.3",
|
||||||
|
"description": "表格组件,多用于展示多条结构类似的数据,如",
|
||||||
|
"keywords": [
|
||||||
|
"uni-ui",
|
||||||
|
"uniui",
|
||||||
|
"table",
|
||||||
|
"表格"
|
||||||
|
],
|
||||||
|
"repository": "https://github.com/dcloudio/uni-ui",
|
||||||
|
"engines": {
|
||||||
|
"HBuilderX": ""
|
||||||
|
},
|
||||||
|
"directories": {
|
||||||
|
"example": "../../temps/example_temps"
|
||||||
|
},
|
||||||
|
"dcloudext": {
|
||||||
|
"sale": {
|
||||||
|
"regular": {
|
||||||
|
"price": "0.00"
|
||||||
|
},
|
||||||
|
"sourcecode": {
|
||||||
|
"price": "0.00"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"contact": {
|
||||||
|
"qq": ""
|
||||||
|
},
|
||||||
|
"declaration": {
|
||||||
|
"ads": "无",
|
||||||
|
"data": "无",
|
||||||
|
"permissions": "无"
|
||||||
|
},
|
||||||
|
"npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui",
|
||||||
|
"type": "component-vue"
|
||||||
|
},
|
||||||
|
"uni_modules": {
|
||||||
|
"dependencies": ["uni-scss","uni-datetime-picker"],
|
||||||
|
"encrypt": [],
|
||||||
|
"platforms": {
|
||||||
|
"cloud": {
|
||||||
|
"tcb": "y",
|
||||||
|
"aliyun": "y"
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"App": {
|
||||||
|
"app-vue": "y",
|
||||||
|
"app-nvue": "n"
|
||||||
|
},
|
||||||
|
"H5-mobile": {
|
||||||
|
"Safari": "y",
|
||||||
|
"Android Browser": "y",
|
||||||
|
"微信浏览器(Android)": "y",
|
||||||
|
"QQ浏览器(Android)": "y"
|
||||||
|
},
|
||||||
|
"H5-pc": {
|
||||||
|
"Chrome": "y",
|
||||||
|
"IE": "y",
|
||||||
|
"Edge": "y",
|
||||||
|
"Firefox": "y",
|
||||||
|
"Safari": "y"
|
||||||
|
},
|
||||||
|
"小程序": {
|
||||||
|
"微信": "y",
|
||||||
|
"阿里": "y",
|
||||||
|
"百度": "y",
|
||||||
|
"字节跳动": "n",
|
||||||
|
"QQ": "y"
|
||||||
|
},
|
||||||
|
"快应用": {
|
||||||
|
"华为": "n",
|
||||||
|
"联盟": "n"
|
||||||
|
},
|
||||||
|
"Vue": {
|
||||||
|
"vue2": "y",
|
||||||
|
"vue3": "y"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
|
||||||
|
## Table 表单
|
||||||
|
> 组件名:``uni-table``,代码块: `uTable`。
|
||||||
|
|
||||||
|
用于展示多条结构类似的数据
|
||||||
|
|
||||||
|
### [查看文档](https://uniapp.dcloud.io/component/uniui/uni-table)
|
||||||
|
#### 如使用过程中有任何问题,或者您对uni-ui有一些好的建议,欢迎加入 uni-ui 交流群:871950839
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue