Skip to content

Commit 14f5477

Browse files
committed
增加table单元格为img时,可以自定义formatter及对base64图片的默认支持
1 parent a9ca975 commit 14f5477

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

Vol.Vue/src/components/basic/VolTable.vue

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
v-if="column.link"
179179
v-text="scope.row[column.field]"></a>
180180
<img v-else-if="column.type == 'img'"
181-
v-for="(file, vIndex) in getFilePath(scope.row[column.field])"
181+
v-for="(file, vIndex) in getFilePath(scope.row[column.field],column)"
182182
:key="vIndex"
183183
:onerror="defaultImg"
184184
@click="viewImg(scope.row, column, file.path)"
@@ -187,7 +187,7 @@
187187
<a style="margin-right: 15px"
188188
v-else-if="column.type == 'file' || column.type == 'excel'"
189189
class="t-file"
190-
v-for="(file, vIndex) in getFilePath(scope.row[column.field])"
190+
v-for="(file, vIndex) in getFilePath(scope.row[column.field],column)"
191191
:key="vIndex"
192192
@click="dowloadFile(file)">{{ file.name }}</a>
193193
<Tag v-else-if="column.type == 'date'">{{
@@ -553,14 +553,26 @@ export default {
553553
this.http.ipAddress
554554
);
555555
},
556-
getFilePath (pathSring) {
556+
getFilePath (pathSring, column) {
557557
//获取表的图片与文件显示
558-
if (!pathSring) return "";
558+
if (!pathSring) return [];
559+
//增加图片自定义操作
560+
//返回格式必须是[{name:"文件名",path:"图片全路径或base64格式"}]
561+
if (column.formatter) {
562+
return column.formatter(pathSring);
563+
}
559564
let filePath = pathSring.replace(/\\/g, "/").split(",");
560565
let fileInfo = [];
561566
for (let index = 0; index < filePath.length; index++) {
562567
let file = filePath[index];
563-
if (file.indexOf(".") != -1) {
568+
//2020.12.19增加base64图片显示
569+
if (column.base64) {
570+
fileInfo.push({
571+
name: "",
572+
path: (file.indexOf('base64,') == -1 ? 'data:image/png;base64,' : '') + file,
573+
});
574+
}
575+
else if (file.indexOf(".") != -1) {
564576
let splitFile = file.split("/");
565577
if (splitFile.length > 0) {
566578
fileInfo.push({
@@ -862,7 +874,7 @@ export default {
862874
this.rowData.push(row);
863875
},
864876
viewImg (row, column, url) {
865-
this.base.previewImg(url, this.http.ipAddress);
877+
this.base.previewImg(url);
866878
// window.open(row[column.field]);
867879
},
868880
link (row, column, $e) {

开发版dev/Vue.NetCore/Vol.Vue/src/components/basic/VolTable.vue

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
v-if="column.link"
179179
v-text="scope.row[column.field]"></a>
180180
<img v-else-if="column.type == 'img'"
181-
v-for="(file, vIndex) in getFilePath(scope.row[column.field])"
181+
v-for="(file, vIndex) in getFilePath(scope.row[column.field],column)"
182182
:key="vIndex"
183183
:onerror="defaultImg"
184184
@click="viewImg(scope.row, column, file.path)"
@@ -187,7 +187,7 @@
187187
<a style="margin-right: 15px"
188188
v-else-if="column.type == 'file' || column.type == 'excel'"
189189
class="t-file"
190-
v-for="(file, vIndex) in getFilePath(scope.row[column.field])"
190+
v-for="(file, vIndex) in getFilePath(scope.row[column.field],column)"
191191
:key="vIndex"
192192
@click="dowloadFile(file)">{{ file.name }}</a>
193193
<Tag v-else-if="column.type == 'date'">{{
@@ -553,14 +553,26 @@ export default {
553553
this.http.ipAddress
554554
);
555555
},
556-
getFilePath (pathSring) {
556+
getFilePath (pathSring, column) {
557557
//获取表的图片与文件显示
558-
if (!pathSring) return "";
558+
if (!pathSring) return [];
559+
//增加图片自定义操作
560+
//返回格式必须是[{name:"文件名",path:"图片全路径或base64格式"}]
561+
if (column.formatter) {
562+
return column.formatter(pathSring);
563+
}
559564
let filePath = pathSring.replace(/\\/g, "/").split(",");
560565
let fileInfo = [];
561566
for (let index = 0; index < filePath.length; index++) {
562567
let file = filePath[index];
563-
if (file.indexOf(".") != -1) {
568+
//2020.12.19增加base64图片显示
569+
if (column.base64) {
570+
fileInfo.push({
571+
name: "",
572+
path: (file.indexOf('base64,') == -1 ? 'data:image/png;base64,' : '') + file,
573+
});
574+
}
575+
else if (file.indexOf(".") != -1) {
564576
let splitFile = file.split("/");
565577
if (splitFile.length > 0) {
566578
fileInfo.push({
@@ -862,7 +874,7 @@ export default {
862874
this.rowData.push(row);
863875
},
864876
viewImg (row, column, url) {
865-
this.base.previewImg(url, this.http.ipAddress);
877+
this.base.previewImg(url);
866878
// window.open(row[column.field]);
867879
},
868880
link (row, column, $e) {

0 commit comments

Comments
 (0)