# 优化分页、搜索
This commit is contained in:
parent
5a8b4fa683
commit
ddec16ea60
|
@ -0,0 +1,42 @@
|
||||||
|
|
||||||
|
import { addResizeListener, removeResizeListener } from 'element-ui/src/utils/resize-event'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How to use
|
||||||
|
* <el-table height="100px" v-el-height-adaptive-table="{bottomOffset: 30}">...</el-table>
|
||||||
|
* el-table height is must be set
|
||||||
|
* bottomOffset: 30(default) // The height of the table from the bottom of the page.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const doResize = (el, binding, vnode) => {
|
||||||
|
const { componentInstance: $table } = vnode
|
||||||
|
|
||||||
|
const { value } = binding
|
||||||
|
|
||||||
|
if (!$table.height) {
|
||||||
|
throw new Error(`el-$table must set the height. Such as height='100px'`)
|
||||||
|
}
|
||||||
|
const bottomOffset = (value && value.bottomOffset) || 30
|
||||||
|
|
||||||
|
if (!$table) return
|
||||||
|
|
||||||
|
const height = window.innerHeight - el.getBoundingClientRect().top - bottomOffset
|
||||||
|
$table.layout.setHeight(height)
|
||||||
|
$table.doLayout()
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
bind(el, binding, vnode) {
|
||||||
|
el.resizeListener = () => {
|
||||||
|
doResize(el, binding, vnode)
|
||||||
|
}
|
||||||
|
|
||||||
|
addResizeListener(el, el.resizeListener)
|
||||||
|
},
|
||||||
|
inserted(el, binding, vnode) {
|
||||||
|
doResize(el, binding, vnode)
|
||||||
|
},
|
||||||
|
unbind(el) {
|
||||||
|
removeResizeListener(el, el.resizeListener)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
import adaptive from './adaptive'
|
||||||
|
|
||||||
|
const install = function(Vue) {
|
||||||
|
Vue.directive('el-height-adaptive-table', adaptive)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.Vue) {
|
||||||
|
window['el-height-adaptive-table'] = adaptive
|
||||||
|
Vue.use(install); // eslint-disable-line
|
||||||
|
}
|
||||||
|
|
||||||
|
adaptive.install = install
|
||||||
|
export default adaptive
|
|
@ -180,6 +180,7 @@ export default {
|
||||||
deviceName: 'Device Name',
|
deviceName: 'Device Name',
|
||||||
humitureChart: 'Humiture chart',
|
humitureChart: 'Humiture chart',
|
||||||
temperature: 'Temperature',
|
temperature: 'Temperature',
|
||||||
humidity: 'Humidity'
|
humidity: 'Humidity',
|
||||||
|
logSeachContent: 'Device ID/Name'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,6 +180,7 @@ export default {
|
||||||
deviceName: '设备名称',
|
deviceName: '设备名称',
|
||||||
humitureChart: '温湿度',
|
humitureChart: '温湿度',
|
||||||
temperature: '温度',
|
temperature: '温度',
|
||||||
humidity: '湿度'
|
humidity: '湿度',
|
||||||
|
logSeachContent: '设备名称/ID'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<p class="warn-content">
|
<div class="filter-container">
|
||||||
{{$t('counter.logDesc')}}
|
<el-input @keyup.enter.native="handleFilter" size="small" style="width: 220px;" class="filter-item" :placeholder="$t('counter.logSeachContent')" v-model="logsListQuery.search">
|
||||||
</p>
|
</el-input>
|
||||||
|
<el-button class="filter-item" size="small" type="primary" v-waves icon="el-icon-search" @click="handleFilter">{{$t('table.search')}}</el-button>
|
||||||
|
</div>
|
||||||
<el-table
|
<el-table
|
||||||
v-loading="listLoading"
|
v-loading="listLoading"
|
||||||
:data="deviceCount"
|
:data="deviceCount"
|
||||||
|
@ -19,6 +21,12 @@
|
||||||
sortable
|
sortable
|
||||||
min-width="150">
|
min-width="150">
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column
|
||||||
|
prop="device_name"
|
||||||
|
:label="$t('counter.deviceName')"
|
||||||
|
sortable
|
||||||
|
min-width="150">
|
||||||
|
</el-table-column>
|
||||||
<el-table-column
|
<el-table-column
|
||||||
prop="signal"
|
prop="signal"
|
||||||
:label="$t('counter.signal')"
|
:label="$t('counter.signal')"
|
||||||
|
@ -34,18 +42,6 @@
|
||||||
prop="energy"
|
prop="energy"
|
||||||
:label="$t('counter.energy')"
|
:label="$t('counter.energy')"
|
||||||
min-width="100">
|
min-width="100">
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
sortable
|
|
||||||
prop="temperature"
|
|
||||||
:label="$t('counter.temperature')"
|
|
||||||
min-width="100">
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
sortable
|
|
||||||
prop="humidity"
|
|
||||||
:label="$t('counter.humidity')"
|
|
||||||
min-width="100">
|
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column
|
<el-table-column
|
||||||
prop="coordinate"
|
prop="coordinate"
|
||||||
|
@ -59,26 +55,35 @@
|
||||||
min-width="150">
|
min-width="150">
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
<el-pagination
|
<div class="pagination-container">
|
||||||
class="pagination"
|
<el-pagination background
|
||||||
background
|
:current-page="1"
|
||||||
layout="total, prev, pager, next, jumper"
|
:page-sizes="[10,20,30,50]"
|
||||||
@current-change="handleCurrentChange"
|
:page-size="logsListQuery.limit"
|
||||||
@size-change="handleSizeChange"
|
layout="total, sizes, prev, pager, next, jumper"
|
||||||
:total="total">
|
:total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
|
||||||
</el-pagination>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { fetchDeviceLogs } from '@/api/counter'
|
import { fetchDeviceLogs } from '@/api/counter'
|
||||||
|
import waves from '@/directive/waves' // 水波纹指令
|
||||||
export default {
|
export default {
|
||||||
name: 'count',
|
name: 'count',
|
||||||
|
directives: {
|
||||||
|
waves
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
deviceCount: [],
|
deviceCount: [],
|
||||||
listLoading: true,
|
listLoading: true,
|
||||||
total: 0
|
total: 0,
|
||||||
|
logsListQuery: {
|
||||||
|
search: undefined,
|
||||||
|
limit: 10,
|
||||||
|
page: 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -98,15 +103,20 @@ export default {
|
||||||
handleCurrentChange(page) {
|
handleCurrentChange(page) {
|
||||||
// console.log(page)
|
// console.log(page)
|
||||||
this.listLoading = true
|
this.listLoading = true
|
||||||
this.getDeviceLogs({ page })
|
this.logsListQuery.page = page
|
||||||
|
this.getDeviceLogs(this.logsListQuery)
|
||||||
},
|
},
|
||||||
handleSizeChange(page) {
|
handleSizeChange(val) {
|
||||||
this.listLoading = true
|
this.logsListQuery.limit = val
|
||||||
this.getDeviceLogs({ page })
|
this.getDeviceLogs(this.logsListQuery)
|
||||||
|
},
|
||||||
|
handleFilter() {
|
||||||
|
this.logsListQuery.page = 1
|
||||||
|
this.getDeviceLogs(this.logsListQuery)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.getDeviceLogs()
|
this.getDeviceLogs(this.logsListQuery)
|
||||||
},
|
},
|
||||||
deactivated() {
|
deactivated() {
|
||||||
this.$destroy(true)
|
this.$destroy(true)
|
||||||
|
|
Loading…
Reference in New Issue