index.vue
3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
<div class="vue-grid">
<div class="dataTables_wrapper no-footer">
<table grid-select="{{checkedFields}}" class="table table-striped table-bordered responsive dataTable no-footer">
<thead>
<tr>
<th v-if="checkAble" class="operation-th"></th>
<th v-for="item in columns">
{{item.display}}
</th>
</tr>
</thead>
<tbody>
<template v-if="pageAble">
<template v-if="data.length > 0">
<tr v-for="item in data">
<td v-if="checkAble"><input type="checkbox" id="{{item[checkedField]}}" value="{{item[checkedField]}}" v-model="checkedFields"></td>
<td v-for="option in columnsConfigs" >{{{bodyCell(item,option)}}} </td>
</tr>
</template>
<template v-else>
<tr><td :colspan="100">没有数据</td></tr>
</template>
</template>
<template v-else>
<tr v-for="item in data">
<td v-for="option in columnsConfigs" >{{{ item[option.name] }}} </td>
</tr>
</template>
</tbody>
</table>
</div>
<template v-if="pageAble">
<pagination :page-size="pageSize" :pages="rowsTotal" :current-page.sync="page"></pagination>
</template>
</div>
</template>
<script>
import Pagination from './Pagination'
module.exports = {
components: {
pagination: Pagination
},
props: {
pageAble: {
type: Boolean,
default: true
},
checkedField: {
type: String,
default: 'id'
},
checkedFields: {
type: Array,
default: []
},
checkAble: {
type: Boolean,
default: false
},
pageSize: {
type: Number,
default: 10
},
columns: {
type: Array,
required: true
},
url:{
type:String
},
data: {
type: Array,
default: [],
required: true
}
},
data(){
return {
params:{}
}
},
methods: {
getParam:function(param){
var me=this;
me.params=param||me.params;
me.params.page=me.page||1;
me.params.size=me.pageSize;
return me.params;
},
resquest:function(param){
var me=this;
var data=me.getParam(param);
this.$http.post(me.url, data).then(function (response) {
var res = response.data;
me.data = res.data.list;
me.rowsTotal = res.data.totalPage;
me.page = res.data.page;
me.$dispatch('complete', res.data);
},function (response) {
me.rowsTotal=0;
me.page=0;
});
},
bodyCell:function(row,col){
if (!row || !col) return "";
var value = col.name ? row[col.name] : null;
var content = "";
if (col.render) {
content = col.render.call(null, row);
} else {
content = value;
}
return content;
}
},
ready:function(){
//this.resquest();
},
computed: {
pageStart: function () {
return (this.page - 1) * this.pageSize
},
columnsConfigs: function () {
let columns = this.columns
let cl = columns.length
let arr = []
for (let i = 0; i < cl; i++) {
arr.push(columns[i])
}
return arr
}
},
events:{
//子组件(grid)进行接收
'grid-reload':function(param){
this.page=1;
this.resquest(param);
},
'page':function(page){
this.page=page;
console.log(page);
this.resquest();
}
},
data: function () {
return {
page: 0,
rowsTotal:0
}
}
}
</script>