优化url功能;优化filePreview表现;

This commit is contained in:
2022-05-28 16:00:14 +08:00
parent d3046f9744
commit ca75ce8602
2 changed files with 65 additions and 27 deletions

View File

@@ -20,8 +20,12 @@ define(["jquery", "easy-admin"], function ($, ea) {
{ type: "checkbox" }, { type: "checkbox" },
{ field: 'id', width: 80, title: 'ID' }, { field: 'id', width: 80, title: 'ID' },
{ field: 'upload_type', minWidth: 80, title: '存储位置', search: 'select', selectList: { 'local': '本地', 'alioss': '阿里云', 'qnoss': '七牛云', ',txcos': '腾讯云' } }, { field: 'upload_type', minWidth: 80, title: '存储位置', search: 'select', selectList: { 'local': '本地', 'alioss': '阿里云', 'qnoss': '七牛云', ',txcos': '腾讯云' } },
{field: 'url', minWidth: 80, search: false, title: '图片信息', templet: ea.table.filePreview}, { field: 'url', minWidth: 80, search: false, title: '文件预览', templet: ea.table.filePreview },
{field: 'url', minWidth: 120, title: '保存地址', templet: ea.table.url}, {
field: 'url', minWidth: 120, title: '保存地址', templet: ea.table.url, urlNameField: function (data) {
return data.url;
}
},
{ field: 'original_name', minWidth: 80, title: '文件原名' }, { field: 'original_name', minWidth: 80, title: '文件原名' },
{ field: 'mime_type', minWidth: 80, title: 'mime类型' }, { field: 'mime_type', minWidth: 80, title: 'mime类型' },
{ field: 'file_ext', minWidth: 80, title: '文件后缀' }, { field: 'file_ext', minWidth: 80, title: '文件后缀' },

View File

@@ -43,6 +43,7 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
'video': ['mp4', 'avi', 'wmv', '3gp', 'flv'], 'video': ['mp4', 'avi', 'wmv', '3gp', 'flv'],
// visio扩展名数组 // visio扩展名数组
'visio': ['vsd', 'vsdx'], 'visio': ['vsd', 'vsdx'],
'file': []
} }
for (const extGroupName in extGroup) { for (const extGroupName in extGroup) {
@@ -852,18 +853,25 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
} }
}, },
filePreview: function (data) { filePreview: function (data) {
var option = data.LAY_COL;
if (!data.mime_type) {
return admin.table.url(data);
}
var mimeName = data.mime_type.split('/')[0]; var mimeName = data.mime_type.split('/')[0];
var field = option.field;
if (mimeName == 'image') { if (mimeName == 'image') {
return admin.table.image(data); return admin.table.image(data);
} else {
try {
var value = eval("data." + field);
} catch (e) {
var value = undefined;
}
var groupName = admin.getExtGroupName(data.file_ext);
return '<a href="' + value + '"><img style="height:40px;width:40px" src="/static/admin/images/upload-icons/' + groupName + '.png" /></a>'
} }
return admin.table.url(data);
}, },
image: function (data) { image: function (data) {
var option = data.LAY_COL; var option = data.LAY_COL;
@@ -893,12 +901,32 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
url: function (data) { url: function (data) {
var option = data.LAY_COL; var option = data.LAY_COL;
var field = option.field; var field = option.field;
var urlNameField = option.urlNameField || '';
try { try {
var value = eval("data." + field); var value = eval("data." + field);
} catch (e) { } catch (e) {
var value = undefined; var value = undefined;
} }
return '<a class="layuimini-table-url" href="' + value + '" target="_blank" class="label bg-green">' + value + '</a>';
var urlName = value;
if (urlNameField != '') {
try {
var urlNameFieldType = typeof urlNameField;
if (urlNameFieldType == 'string') {
urlName = data[urlNameField]
} else if (urlNameFieldType == 'function') {
urlName = urlNameField(data)
}
} catch (e) {
}
}
return '<a class="layuimini-table-url" href="' + value + '" target="_blank" class="label bg-green">' + urlName + '</a>';
}, },
switch: function (data) { switch: function (data) {
var option = data.LAY_COL; var option = data.LAY_COL;
@@ -1705,15 +1733,7 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
// 不是图片 // 不是图片
// 遍历extGroup数组找到扩展名所在的索引 // 遍历extGroup数组找到扩展名所在的索引
for (const extGroupName in extGroup) { uploadIcon = admin.getExtGroupName(ext);
if (Object.hasOwnProperty.call(extGroup, extGroupName)) {
const extGroupList = extGroup[extGroupName];
if (extGroupList.indexOf(ext) != -1) {
uploadIcon = extGroupName;
break;
}
}
}
liHtml += '<li><a title="点击打开文件" target="_blank" href="' + v + '" ><img src="/static/admin/images/upload-icons/' + uploadIcon + '.png"></a><small class="uploads-delete-tip bg-red badge" data-upload-delete="' + uploadName + '" data-upload-url="' + v + '" data-upload-sign="' + uploadSign + '">×</small></li>\n'; liHtml += '<li><a title="点击打开文件" target="_blank" href="' + v + '" ><img src="/static/admin/images/upload-icons/' + uploadIcon + '.png"></a><small class="uploads-delete-tip bg-red badge" data-upload-delete="' + uploadName + '" data-upload-url="' + v + '" data-upload-sign="' + uploadSign + '">×</small></li>\n';
@@ -1923,6 +1943,20 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
return this.dataBrage[name]; return this.dataBrage[name];
},
getExtGroupName(ext) {
var groupName = 'file';
for (const extGroupName in extGroup) {
if (Object.hasOwnProperty.call(extGroup, extGroupName)) {
const extGroupList = extGroup[extGroupName];
if (extGroupList.indexOf(ext) != -1) {
groupName = extGroupName;
break;
}
}
}
return groupName;
} }
}; };