Skip to content

Commit 40f5bb5

Browse files
committed
增加H5 table加载后的方法
1 parent 5f40417 commit 40f5bb5

File tree

1 file changed

+122
-94
lines changed

1 file changed

+122
-94
lines changed

Vue.H5/src/components/VolTable.vue

Lines changed: 122 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,196 +1,224 @@
11
<template>
2-
3-
<div class="vol-table"
4-
:class="[cellOverflowHidden?'vol-cell-overflow-hidden':'']">
2+
<div
3+
class="vol-table"
4+
:class="[cellOverflowHidden ? 'vol-cell-overflow-hidden' : '']"
5+
>
56
<div class="col-header">
6-
<div class="col-cell"
7-
:style="getStyle(column)"
8-
v-for="(column,index) in filterColumns()"
9-
:key="index">
10-
{{column.title}}
7+
<div
8+
class="col-cell"
9+
:style="getStyle(column)"
10+
v-for="(column, index) in filterColumns()"
11+
:key="index"
12+
>
13+
{{ column.title }}
1114
</div>
1215
</div>
13-
<PullRefreshList :immediate-check="false"
14-
:default-load="true"
15-
:getUrl="getUrl"
16-
:height="bodyHeight"
17-
httpType="post"
18-
ref="PRL"
19-
:index="'1'">
16+
<PullRefreshList
17+
:immediate-check="false"
18+
:default-load="true"
19+
:getUrl="getUrl"
20+
:height="bodyHeight"
21+
httpType="post"
22+
:loadDataAfter="loadDataAfter"
23+
ref="PRL"
24+
:index="'1'"
25+
>
2026
<template slot-scope="scope">
2127
<div class="col-body">
22-
<div class="col-rows"
23-
v-for="(row,index) in scope.list"
24-
:key="index"
25-
@click="rowClick(row,index)">
26-
<div class="col-cell"
27-
:style="getStyle(column)"
28-
v-for="(column) in fields"
29-
:key="column.field">
30-
<div v-if="column.type=='img'">
31-
<img class="tb-cell-img"
32-
v-for="(imgItem,imgIndex) in getImgs(row[column.field])"
33-
:src="imgItem"
34-
:key="imgIndex" />
28+
<div
29+
class="col-rows"
30+
v-for="(row, index) in scope.list"
31+
:key="index"
32+
@click="rowClick(row, index)"
33+
>
34+
<div
35+
class="col-cell"
36+
:style="getStyle(column)"
37+
v-for="column in fields"
38+
:key="column.field"
39+
>
40+
<div v-if="column.type == 'img'">
41+
<img
42+
class="tb-cell-img"
43+
v-for="(imgItem, imgIndex) in getImgs(row[column.field])"
44+
:src="imgItem"
45+
:key="imgIndex"
46+
/>
3547
</div>
36-
<div v-else-if="column.formatter"
37-
v-html="column.formatter(row[column.field],row,column)"></div>
38-
<template v-else-if="column.bind"> {{converDicValue( row[column.field],column)}}</template>
39-
<template v-else> {{ row[column.field]}}</template>
48+
<div
49+
v-else-if="column.formatter"
50+
v-html="column.formatter(row[column.field], row, column)"
51+
></div>
52+
<template v-else-if="column.bind">
53+
{{ converDicValue(row[column.field], column) }}</template
54+
>
55+
<template v-else> {{ row[column.field] }}</template>
4056
</div>
4157
</div>
4258
</div>
4359
</template>
4460
</PullRefreshList>
4561
</div>
46-
4762
</template>
4863
<script>
4964
import PullRefreshList from "@/components/PullRefreshList.vue";
5065
export default {
5166
components: {
52-
PullRefreshList
67+
PullRefreshList,
5368
},
5469
props: {
55-
cellOverflowHidden: {//单元格超出是否隐藏
70+
cellOverflowHidden: {
71+
//单元格超出是否隐藏
5672
type: Boolean,
57-
defalut: false
73+
defalut: false,
5874
},
5975
height: {
6076
type: Number,
61-
default: 0
77+
default: 0,
6278
},
63-
queryParams: { //查询的参数
79+
queryParams: {
80+
//查询的参数
6481
type: Function,
6582
default: () => {
66-
return []
67-
}
83+
return [];
84+
},
6885
},
6986
url: {
70-
type: String, default: ""
87+
type: String,
88+
default: "",
7189
},
7290
rowClick: {
7391
type: Function,
7492
default: () => {
75-
return ""
76-
}
93+
return "";
94+
},
7795
},
7896
columns: {
7997
type: Array,
8098
default: () => {
8199
return [];
82-
}
83-
}
100+
},
101+
},
84102
},
85-
data () {
103+
data() {
86104
return {
87105
bodyHeigth: 0,
88106
fields: [],
89107
keySource: {},
90-
imgFields: [],//图片字段
91-
list: []
92-
}
108+
imgFields: [], //图片字段
109+
list: [],
110+
};
93111
},
94112
methods: {
95-
getCellStyle (column) {
113+
getCellStyle(column) {
96114
if (column.type == "img") {
97-
return { "line-height": "40px" }
115+
return { "line-height": "40px" };
98116
}
99117
return "";
100118
},
101-
getImgs (imgs) {
119+
getImgs(imgs) {
102120
if (!imgs) return [];
103-
var _imgs = imgs.split(',');
104-
return _imgs.filter(x => { return x }).map(m => {
105-
if (m.substr(0, 4) == "http") {
106-
return m;
107-
}
108-
return this.http.ipAddress + m;
109-
})
121+
var _imgs = imgs.split(",");
122+
return _imgs
123+
.filter((x) => {
124+
return x;
125+
})
126+
.map((m) => {
127+
if (m.substr(0, 4) == "http") {
128+
return m;
129+
}
130+
return this.http.ipAddress + m;
131+
});
110132
},
111-
reload () {
133+
reload() {
112134
this.$refs.PRL.refresh();
113135
},
114-
filterColumns () {
115-
return this.columns.filter(x => {
116-
return !x.hidden
117-
})
136+
filterColumns() {
137+
return this.columns.filter((x) => {
138+
return !x.hidden;
139+
});
118140
},
119-
getStyle (column) {
141+
getStyle(column) {
120142
if (column.width) {
121-
return 'width:' + column.width + 'px'
143+
return "width:" + column.width + "px";
122144
}
123-
return 'flex: 1'
145+
return "flex: 1";
124146
},
125-
isEmpty (val) {
126-
127-
return val === "" || val === null || val === undefined
128-
129-
}, converDicValue (val, column) {
147+
isEmpty(val) {
148+
return val === "" || val === null || val === undefined;
149+
},
150+
converDicValue(val, column) {
130151
if (this.isEmpty(val)) return "";
131152
if (column.bind.type == "selectList") {
132153
var _values = [];
133154
var _array = (val + "").split(",");
134155
for (let index = 0; index < _array.length; index++) {
135156
if (!this.isEmpty(_array[index])) {
136-
_values.push(this.getDicValue(_array[index], column))
157+
_values.push(this.getDicValue(_array[index], column));
137158
}
138159
}
139-
return _values.join(',')
160+
return _values.join(",");
140161
}
141162
return this.getDicValue(val, column);
142163
},
143-
getDicValue (val, column) {
144-
var kv = column.bind.data.find(x => { return x.key + "" === val + "" });
164+
getDicValue(val, column) {
165+
var kv = column.bind.data.find((x) => {
166+
return x.key + "" === val + "";
167+
});
145168
return kv ? kv.value : val;
146169
},
147-
getUrl () {
170+
getUrl() {
148171
var params = {};
149172
params.wheres = this.queryParams();
150-
return { url: this.url, params: { wheres: JSON.stringify(params.wheres) } }
151-
}
173+
return {
174+
url: this.url,
175+
params: { wheres: JSON.stringify(params.wheres) },
176+
};
177+
},
178+
loadDataAfter(rows) {
179+
this.$emit("loadTableAfter", rows);
180+
},
152181
},
153-
created () {
182+
created() {
154183
if (!this.height) {
155184
this.bodyHeight = document.body.clientHeight - 92;
156185
} else {
157186
this.bodyHeight = this.height;
158187
}
159-
var keys = []
160-
this.columns.forEach(x => {
188+
var keys = [];
189+
this.columns.forEach((x) => {
161190
if (!x.hidden) {
162191
this.fields.push(x);
163192
if (x.bind && x.bind.key) {
164193
if (!x.bind.data) {
165-
x.bind.data = []
194+
x.bind.data = [];
166195
}
167196
if (!x.bind.data.length) {
168-
keys.push(x.bind.key)
197+
keys.push(x.bind.key);
169198
}
170199
this.keySource[x.bind.key] = x.bind.data;
171200
}
172201
}
173-
})
202+
});
174203
if (keys.length) {
175204
this.http
176205
.post("/api/Sys_Dictionary/GetVueDictionary", keys)
177206
.then((dic) => {
178207
dic.forEach((x) => {
179-
x.data.forEach(x => {
208+
x.data.forEach((x) => {
180209
x.key = x.key + "";
181-
})
182-
this.keySource[x.dicNo].push(...x.data)
210+
});
211+
this.keySource[x.dicNo].push(...x.data);
183212
});
184213
});
185214
}
186215
187-
this.http.post("/api/Sys_Log/getPageData", {}, true).then(x => {
188-
//this.$emit("loadTableAfter", x.rows);
189-
216+
this.http.post("/api/Sys_Log/getPageData", {}, true).then((x) => {
217+
this.loadDataAfter(x.rows);
190218
this.list = x.rows;
191-
})
192-
}
193-
}
219+
});
220+
},
221+
};
194222
</script>
195223
<style lang="less" scoped>
196224
.col-header {

0 commit comments

Comments
 (0)