feat: 新增阿里云OSS适配器及分类图标优化
- 新增阿里云OSS SDK核心类库文件 - 新增OSS插件配置文件及钩子监听 - 新增分类图标SVG资源并优化为轻量化格式 - 替换定位接口为天地图逆地理编码接口 - 新增OSS图片缩略处理工具方法
这个提交包含在:
文件差异因一行或多行过长而隐藏
@@ -45,4 +45,252 @@ define([], function () {
|
||||
});
|
||||
});
|
||||
|
||||
if (typeof Config.upload.storage !== 'undefined' && Config.upload.storage === 'alioss') {
|
||||
require(['upload'], function (Upload) {
|
||||
//获取文件MD5值
|
||||
var getFileMd5 = function (file, cb) {
|
||||
//如果savekey中未检测到md5,则无需获取文件md5,直接返回upload的uuid
|
||||
if (!Config.upload.savekey.match(/\{(file)?md5\}/)) {
|
||||
cb && cb(file.upload.uuid);
|
||||
return;
|
||||
}
|
||||
require(['../addons/alioss/js/spark'], function (SparkMD5) {
|
||||
var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,
|
||||
chunkSize = 10 * 1024 * 1024,
|
||||
chunks = Math.ceil(file.size / chunkSize),
|
||||
currentChunk = 0,
|
||||
spark = new SparkMD5.ArrayBuffer(),
|
||||
fileReader = new FileReader();
|
||||
|
||||
fileReader.onload = function (e) {
|
||||
spark.append(e.target.result);
|
||||
currentChunk++;
|
||||
if (currentChunk < chunks) {
|
||||
loadNext();
|
||||
} else {
|
||||
cb && cb(spark.end());
|
||||
}
|
||||
};
|
||||
|
||||
fileReader.onerror = function () {
|
||||
console.warn('文件读取错误');
|
||||
};
|
||||
|
||||
function loadNext() {
|
||||
var start = currentChunk * chunkSize,
|
||||
end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
|
||||
|
||||
fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
|
||||
}
|
||||
|
||||
loadNext();
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
var _onInit = Upload.events.onInit;
|
||||
//初始化中完成判断
|
||||
Upload.events.onInit = function () {
|
||||
_onInit.apply(this, Array.prototype.slice.apply(arguments));
|
||||
//如果上传接口不是阿里OSS,则不处理
|
||||
if (this.options.url !== Config.upload.uploadurl) {
|
||||
return;
|
||||
}
|
||||
$.extend(this.options, {
|
||||
//关闭自动处理队列功能
|
||||
autoQueue: false,
|
||||
params: function (files, xhr, chunk) {
|
||||
var params = Config.upload.multipart;
|
||||
if (chunk) {
|
||||
return $.extend({}, params, {
|
||||
filesize: chunk.file.size,
|
||||
filename: chunk.file.name,
|
||||
chunkid: chunk.file.upload.uuid,
|
||||
chunkindex: chunk.index,
|
||||
chunkcount: chunk.file.upload.totalChunkCount,
|
||||
chunksize: this.options.chunkSize,
|
||||
chunkfilesize: chunk.dataBlock.data.size,
|
||||
width: chunk.file.width || 0,
|
||||
height: chunk.file.height || 0,
|
||||
type: chunk.file.type,
|
||||
uploadId: chunk.file.uploadId,
|
||||
key: chunk.file.key,
|
||||
});
|
||||
} else {
|
||||
params = $.extend({}, params, files[0].params);
|
||||
params.category = files[0].category || '';
|
||||
}
|
||||
return params;
|
||||
},
|
||||
chunkSuccess: function (chunk, file, response) {
|
||||
var etag = chunk.xhr.getResponseHeader("ETag").replace(/(^")|("$)/g, '');
|
||||
file.etags = file.etags ? file.etags : [];
|
||||
file.etags[chunk.index] = etag;
|
||||
},
|
||||
chunksUploaded: function (file, done) {
|
||||
var that = this;
|
||||
Fast.api.ajax({
|
||||
url: "/addons/alioss/index/upload",
|
||||
data: {
|
||||
action: 'merge',
|
||||
filesize: file.size,
|
||||
filename: file.name,
|
||||
chunkid: file.upload.uuid,
|
||||
chunkcount: file.upload.totalChunkCount,
|
||||
md5: file.md5,
|
||||
key: file.key,
|
||||
uploadId: file.uploadId,
|
||||
etags: file.etags,
|
||||
category: file.category || '',
|
||||
aliosstoken: Config.upload.multipart.aliosstoken,
|
||||
},
|
||||
}, function (data, ret) {
|
||||
done(JSON.stringify(ret));
|
||||
return false;
|
||||
}, function (data, ret) {
|
||||
file.accepted = false;
|
||||
that._errorProcessing([file], ret.msg);
|
||||
return false;
|
||||
});
|
||||
|
||||
},
|
||||
});
|
||||
|
||||
var _success = this.options.success;
|
||||
//先移除已有的事件
|
||||
this.off("success", _success).on("success", function (file, response) {
|
||||
var that = this;
|
||||
var ret = {code: 0, msg: response};
|
||||
try {
|
||||
if (response) {
|
||||
ret = typeof response === 'string' ? JSON.parse(response) : response;
|
||||
}
|
||||
if (file.xhr.status === 200) {
|
||||
if (Config.upload.uploadmode === 'client') {
|
||||
var url = '/' + file.key;
|
||||
ret = {code: 1, msg: '', data: {url: url, fullurl: Fast.api.cdnurl(url, true), filename: file.name, filesize: file.size, mimetype: file.type, category: file.category || ''}};
|
||||
Fast.api.ajax({
|
||||
url: "/addons/alioss/index/notify",
|
||||
data: {name: file.name, url: url, md5: file.md5, size: file.size, width: file.width || 0, height: file.height || 0, type: file.type, category: file.category || '', aliosstoken: Config.upload.multipart.aliosstoken}
|
||||
}, function (data, notifyRet) {
|
||||
// 如果notify有返回则使用notify返回
|
||||
_success.call(that, file, data ? notifyRet : ret);
|
||||
return false;
|
||||
}, function (data, ret) {
|
||||
Toastr.error("发生错误:" + (ret.msg || "未知错误"));
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
_success.call(that, file, ret);
|
||||
}
|
||||
} else {
|
||||
console.error(file.xhr);
|
||||
Toastr.error("发生未知错误");
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
Toastr.error("发生未知错误");
|
||||
}
|
||||
});
|
||||
|
||||
this.on("addedfile", function (file) {
|
||||
var that = this;
|
||||
setTimeout(function () {
|
||||
if (file.status === 'error') {
|
||||
return;
|
||||
}
|
||||
getFileMd5(file, function (md5) {
|
||||
var chunk = that.options.chunking && file.size > that.options.chunkSize ? 1 : 0;
|
||||
var params = $(that.element).data("params") || {};
|
||||
var category = typeof params.category !== 'undefined' ? params.category : ($(that.element).data("category") || '');
|
||||
category = typeof category === 'function' ? category.call(that, file) : category;
|
||||
Fast.api.ajax({
|
||||
url: "/addons/alioss/index/params",
|
||||
data: {method: 'POST', category: category, md5: md5, name: file.name, type: file.type, size: file.size, chunk: chunk, chunksize: that.options.chunkSize, aliosstoken: Config.upload.multipart.aliosstoken},
|
||||
}, function (data) {
|
||||
file.md5 = md5;
|
||||
file.id = data.id;
|
||||
file.key = data.key;
|
||||
file.date = data.date;
|
||||
file.uploadId = data.uploadId;
|
||||
file.policy = data.policy;
|
||||
file.signature = data.signature;
|
||||
file.partsAuthorization = data.partsAuthorization;
|
||||
file.params = data;
|
||||
file.category = category;
|
||||
|
||||
if (file.status != 'error') {
|
||||
//开始上传
|
||||
that.enqueueFile(file);
|
||||
} else {
|
||||
that.removeFile(file);
|
||||
}
|
||||
return false;
|
||||
}, function () {
|
||||
that.removeFile(file);
|
||||
});
|
||||
});
|
||||
}, 0);
|
||||
});
|
||||
|
||||
if (Config.upload.uploadmode === 'client') {
|
||||
var _method = this.options.method;
|
||||
var _url = this.options.url;
|
||||
this.options.method = function (files) {
|
||||
if (files[0].upload.chunked) {
|
||||
var chunk = null;
|
||||
files[0].upload.chunks.forEach(function (item) {
|
||||
if (item.status === 'uploading') {
|
||||
chunk = item;
|
||||
}
|
||||
});
|
||||
if (!chunk) {
|
||||
return "POST";
|
||||
} else {
|
||||
return "PUT";
|
||||
}
|
||||
}
|
||||
return _method;
|
||||
};
|
||||
this.options.url = function (files) {
|
||||
if (files[0].upload.chunked) {
|
||||
var chunk = null;
|
||||
files[0].upload.chunks.forEach(function (item) {
|
||||
if (item.status === 'uploading') {
|
||||
chunk = item;
|
||||
}
|
||||
});
|
||||
var index = chunk.dataBlock.chunkIndex;
|
||||
// debugger;
|
||||
this.options.headers = {"Authorization": "OSS " + files[0]['id'] + ":" + files[0]['partsAuthorization'][index], "x-oss-date": files[0]['date']};
|
||||
if (!chunk) {
|
||||
return Config.upload.uploadurl + "/" + files[0].key + "?uploadId=" + files[0].uploadId;
|
||||
} else {
|
||||
return Config.upload.uploadurl + "/" + files[0].key + "?partNumber=" + (index + 1) + "&uploadId=" + files[0].uploadId;
|
||||
}
|
||||
}
|
||||
return _url;
|
||||
};
|
||||
this.on("sending", function (file, xhr, formData) {
|
||||
var that = this;
|
||||
if (file.upload.chunked) {
|
||||
var _send = xhr.send;
|
||||
xhr.send = function () {
|
||||
var chunk = null;
|
||||
file.upload.chunks.forEach(function (item) {
|
||||
if (item.status == 'uploading') {
|
||||
chunk = item;
|
||||
}
|
||||
});
|
||||
if (chunk) {
|
||||
_send.call(xhr, chunk.dataBlock.data);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
@@ -24,32 +24,77 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], fu
|
||||
table.bootstrapTable({
|
||||
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
||||
pk: 'id',
|
||||
sortName: 'sort',
|
||||
sortName: 'id',
|
||||
sortOrder: 'asc',
|
||||
pageSize: 50,
|
||||
pageList: [20, 50, 100, 200],
|
||||
columns: [
|
||||
[
|
||||
{checkbox: true},
|
||||
{field: 'id', title: __('SerialNo'), operate: false, sortable: false, align: 'center', width: '70px', class: 'fc-serial', table: table, formatter: Format.serial},
|
||||
{field: 'province', title: __('Province'), operate: 'LIKE'},
|
||||
{field: 'city', title: __('City'), operate: 'LIKE'},
|
||||
{field: 'district', title: __('District'), operate: 'LIKE'},
|
||||
{field: 'full_name', title: __('FullName'), operate: false, sortable: false},
|
||||
{
|
||||
field: 'enabled', title: __('Enabled'),
|
||||
searchList: {0: '否', 1: '是'},
|
||||
formatter: Format.statusFormatter({0: '否', 1: '是'}, {0: 'default', 1: 'success'})
|
||||
field: 'province', title: '省份', operate: 'LIKE', sortable: false, width: '130px',
|
||||
formatter: function (v) { return '<span class="fc-province">' + (v || '') + '</span>'; }
|
||||
},
|
||||
{field: 'sort', title: __('Sort'), width: '80px'},
|
||||
{field: 'lat', title: __('Lat'), operate: false, visible: false},
|
||||
{field: 'lng', title: __('Lng'), operate: false, visible: false},
|
||||
{field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime},
|
||||
{field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime, visible: false},
|
||||
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
|
||||
{
|
||||
field: 'city', title: '城市', operate: 'LIKE', sortable: false, width: '120px',
|
||||
formatter: function (v) { return '<span class="fc-city">' + (v || '') + '</span>'; }
|
||||
},
|
||||
{
|
||||
field: 'district', title: '区县', operate: 'LIKE', sortable: false, width: '140px',
|
||||
formatter: function (v) { return '<strong>' + (v || '') + '</strong>'; }
|
||||
},
|
||||
{
|
||||
field: 'enabled', title: '启用', searchList: {0: '停用', 1: '启用'}, operate: 'SELECT',
|
||||
formatter: Table.api.formatter.toggle,
|
||||
custom: { 0: 'default', 1: 'success' }
|
||||
},
|
||||
{field: 'sort', title: '排序', width: '70px', align: 'center'},
|
||||
{
|
||||
field: 'lat', title: '纬度', operate: false, width: '95px', align: 'center',
|
||||
formatter: function (v) { return v != null && v !== '' ? Number(v).toFixed(3) : '<span class="text-muted">—</span>'; }
|
||||
},
|
||||
{
|
||||
field: 'lng', title: '经度', operate: false, width: '95px', align: 'center',
|
||||
formatter: function (v) { return v != null && v !== '' ? Number(v).toFixed(3) : '<span class="text-muted">—</span>'; }
|
||||
},
|
||||
{field: 'operate', title: '操作', table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, width: '120px'}
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
// 为表格绑定事件
|
||||
Table.api.bindevent(table);
|
||||
|
||||
// 恢复全国默认(清空覆盖层 + 导入 national_areas.json 3600 条)
|
||||
$('.btn-import').on('click', function () {
|
||||
Layer.confirm(
|
||||
'确定要恢复全国默认吗?此操作会<strong>清空所有现有覆盖层数据</strong>,然后从 national_areas.json 导入全国 3600 个区县(全部启用)。不可撤销。',
|
||||
'恢复全国默认',
|
||||
{icon: 3},
|
||||
function (index) {
|
||||
$.ajax({
|
||||
url: 'fc/area/import',
|
||||
type: 'POST',
|
||||
data: {__token__: Config.token || ''},
|
||||
dataType: 'json',
|
||||
success: function (ret) {
|
||||
if (ret.code === 1) {
|
||||
Toastr.success(ret.msg || '恢复成功');
|
||||
table.bootstrapTable('refresh');
|
||||
} else {
|
||||
Toastr.error(ret.msg || '恢复失败');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
Toastr.error('请求失败,请稍后重试');
|
||||
},
|
||||
complete: function () {
|
||||
Layer.close(index);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], function ($, undefined, Backend, Table, Form, Format) {
|
||||
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format', 'fast'], function ($, undefined, Backend, Table, Form, Format, Fast) {
|
||||
|
||||
/**
|
||||
* categories 目录下的专属图标键名列表
|
||||
* 预设分类图标键名(新风格 SVG,共 20 个扁平无分组)
|
||||
*/
|
||||
var CATEGORY_DIR_KEYS = [
|
||||
'cat-fruit', 'cat-poultry', 'cat-veg', 'cat-job',
|
||||
'fruit-apple', 'fruit-grape', 'fruit-kiwi', 'fruit-orange', 'fruit-passion', 'fruit-peach', 'fruit-strawberry', 'fruit-watermelon',
|
||||
'veg-cabbage', 'veg-chili', 'veg-green-cabbage', 'veg-greens', 'veg-purple-cabbage', 'veg-radish', 'veg-tomato'
|
||||
'cat-job', 'cat-service', 'cat-house', 'cat-goods', 'cat-car',
|
||||
'cat-food', 'cat-education', 'cat-health',
|
||||
'cat-poultry', 'cat-fruit', 'cat-veg', 'cat-seafood',
|
||||
'cat-grain', 'cat-dairy', 'cat-snack', 'cat-season',
|
||||
'cat-clean', 'cat-move', 'cat-digital', 'cat-pet'
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -17,25 +19,40 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], fu
|
||||
* @returns {string} 完整的静态图片URL
|
||||
*/
|
||||
function resolveIconUrl(iconKey, id, image) {
|
||||
if (image && /^(https?:\/\/|\/uploads\/|\/static\/)/i.test(image)) {
|
||||
// 1. 本地静态资源 (/static/...) 必须直接使用本地绝对路径,绝不能走 Fast.api.cdnurl (OSS 上无静态目录)
|
||||
if (image && /^\/static\//i.test(image)) {
|
||||
return image;
|
||||
}
|
||||
// 2. 上传文件 (/uploads/...) 或网络图片才走 CDN 动态缩放
|
||||
if (image && /^(https?:\/\/|\/uploads\/)/i.test(image)) {
|
||||
var fullUrl = Fast.api.cdnurl(image);
|
||||
if ((fullUrl.indexOf('aliyuncs.com') !== -1 || fullUrl.indexOf('oss-') !== -1) && fullUrl.indexOf('x-oss-process') === -1) {
|
||||
fullUrl += (fullUrl.indexOf('?') !== -1 ? '&' : '?') + 'x-oss-process=image/resize,m_fill,w_160,h_160/quality,q_85';
|
||||
}
|
||||
return fullUrl;
|
||||
}
|
||||
if (!iconKey) {
|
||||
iconKey = 'cat-job';
|
||||
}
|
||||
if (/^(https?:\/\/|\/uploads\/|\/static\/)/i.test(iconKey)) {
|
||||
if (/^\/static\//i.test(iconKey)) {
|
||||
return iconKey;
|
||||
}
|
||||
var baseKey = iconKey.replace(/\.(png|jpg|jpeg|gif|svg)$/i, '');
|
||||
var file = (iconKey.indexOf('.') !== -1) ? iconKey : iconKey + '.png';
|
||||
if (iconKey.indexOf('sub-') === 0 || CATEGORY_DIR_KEYS.indexOf(baseKey) !== -1 || /^(veg-|fruit-|cat-veg|cat-fruit|cat-job|cat-poultry)/i.test(baseKey)) {
|
||||
return '/static/categories/' + file + '?v=2';
|
||||
if (/^(https?:\/\/|\/uploads\/)/i.test(iconKey)) {
|
||||
return Fast.api.cdnurl(iconKey);
|
||||
}
|
||||
return '/static/icons/' + file + '?v=2';
|
||||
// 已有扩展名:直接用,放 categories 目录
|
||||
if (iconKey.indexOf('.') !== -1) {
|
||||
return '/static/categories/' + iconKey + '?v=3';
|
||||
}
|
||||
// cat-* 前缀或预设标识(优先返回微质感 SVG)
|
||||
return '/static/categories/' + iconKey + '.svg?v=3';
|
||||
}
|
||||
|
||||
var Controller = {
|
||||
index: function () {
|
||||
// 分类弹窗统一加宽,保证表单与右侧预览布局舒展
|
||||
Fast.config.openArea = ['880px', '92vh'];
|
||||
|
||||
// 初始化表格参数配置
|
||||
Table.api.init({
|
||||
extend: {
|
||||
@@ -85,9 +102,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], fu
|
||||
var color = row.color || '#00E070';
|
||||
return '<div class="fc-img-wrap">' +
|
||||
'<div style="display:inline-block;width:56px;height:56px;border-radius:14px;overflow:hidden;background:' + color + '15;border:1px solid ' + color + '40;box-shadow:0 2px 8px rgba(4,48,30,0.08);cursor:zoom-in;">' +
|
||||
'<img src="' + url + '" style="width:100%;height:100%;object-fit:cover;display:block;" onerror="this.src=\'/static/categories/cat-job.png\'" />' +
|
||||
'<img src="' + url + '" style="width:100%;height:100%;object-fit:cover;display:block;" onerror="this.onerror=null;this.src=\'/static/categories/cat-job.svg\'" />' +
|
||||
'</div>' +
|
||||
'<div class="fc-img-zoom"><img src="' + url + '" onerror="this.src=\'/static/categories/cat-job.png\'" /></div>' +
|
||||
'<div class="fc-img-zoom"><img src="' + url + '" onerror="this.onerror=null;this.src=\'/static/categories/cat-job.svg\'" /></div>' +
|
||||
'</div>';
|
||||
}
|
||||
},
|
||||
@@ -298,6 +315,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], fu
|
||||
*/
|
||||
bindFormInteractions: function () {
|
||||
var $iconInput = $('#c-icon_key');
|
||||
var $imageInput = $('#c-image');
|
||||
var $nameInput = $('#c-name');
|
||||
var $colorInput = $('#c-color');
|
||||
var $colorNative = $('#c-color-native');
|
||||
@@ -308,20 +326,31 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], fu
|
||||
var $previewKind = $('#preview-kind');
|
||||
var $currentIconImg = $('#current-icon-img');
|
||||
var $currentIconLabel = $('#current-icon-label');
|
||||
var $currentIconTip = $('#current-icon-tip');
|
||||
var $iconModal = $('#fc-icon-modal');
|
||||
var $iconSearch = $('#fc-icon-search');
|
||||
var $iconTabs = $('.fc-icon-tab-btn');
|
||||
|
||||
// 刷新界面预览元素
|
||||
function updateLivePreview() {
|
||||
var name = $nameInput.val() || '未命名分类';
|
||||
var key = $iconInput.val() || 'cat-job';
|
||||
var name = ($nameInput.val() || '').trim() || '未命名分类';
|
||||
var key = ($iconInput.val() || '').trim();
|
||||
var img = ($imageInput.length ? ($imageInput.val() || '').trim() : '');
|
||||
var color = $colorInput.val() || '#00E070';
|
||||
var iconUrl = resolveIconUrl(key);
|
||||
var kind = $('input[name="row[kind]"]:checked').val() || 'general';
|
||||
|
||||
var $matchedChip = $('.fc-icon-chip[data-key="' + key + '"]');
|
||||
if ($matchedChip.length) {
|
||||
// 优先采用实际设置的实拍图路径;无实拍图时再按预设图标键名 key 解析
|
||||
var iconUrl = '';
|
||||
if (img) {
|
||||
iconUrl = resolveIconUrl(key, 0, img);
|
||||
} else if (key) {
|
||||
iconUrl = resolveIconUrl(key);
|
||||
} else {
|
||||
iconUrl = '/static/categories/cat-job.svg';
|
||||
}
|
||||
|
||||
var $matchedChip = key ? $('.fc-icon-chip[data-key="' + key + '"]') : $();
|
||||
if (!img && $matchedChip.length) {
|
||||
var chipImg = $matchedChip.find('img').attr('src');
|
||||
if (chipImg) {
|
||||
iconUrl = chipImg;
|
||||
@@ -332,12 +361,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], fu
|
||||
if ($previewIcon.length) $previewIcon.attr('src', iconUrl);
|
||||
if ($currentIconImg.length) $currentIconImg.attr('src', iconUrl);
|
||||
if ($currentIconLabel.length) {
|
||||
if ($matchedChip.length) {
|
||||
if ($matchedChip.length && !img) {
|
||||
$currentIconLabel.text($matchedChip.data('name') || key);
|
||||
} else if (/^(\/uploads\/|https?:\/\/)/i.test(key)) {
|
||||
$currentIconLabel.text('自定义上传图片');
|
||||
} else if (img && /^(\/uploads\/|https?:\/\/)/i.test(img)) {
|
||||
$currentIconLabel.text(name + ' · 高清实拍图');
|
||||
} else {
|
||||
$currentIconLabel.text(key);
|
||||
$currentIconLabel.text(name || key || '分类图片');
|
||||
}
|
||||
}
|
||||
if ($currentIconTip.length) {
|
||||
if (key) {
|
||||
$currentIconTip.text('当前预设标识:' + key);
|
||||
} else if (img) {
|
||||
$currentIconTip.text('当前:已配置实拍图');
|
||||
} else {
|
||||
$currentIconTip.text('暂未设置图片');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,6 +438,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], fu
|
||||
var iconColor = $(this).data('color') || '';
|
||||
|
||||
$iconInput.val(key).trigger('change');
|
||||
if ($imageInput.length) {
|
||||
$imageInput.val('/static/categories/' + key + '.svg').trigger('change');
|
||||
}
|
||||
$('.fc-icon-chip').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
|
||||
@@ -471,6 +512,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], fu
|
||||
$iconInput.on('input change', function () {
|
||||
updateLivePreview();
|
||||
});
|
||||
if ($imageInput.length) {
|
||||
$imageInput.on('input change', function () {
|
||||
updateLivePreview();
|
||||
});
|
||||
}
|
||||
|
||||
// 4. 监听分类名称输入
|
||||
$nameInput.on('input', function () {
|
||||
@@ -499,8 +545,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], fu
|
||||
});
|
||||
|
||||
// 初始化回显
|
||||
var initKey = $iconInput.val() || 'cat-service';
|
||||
$('.fc-icon-chip[data-key="' + initKey + '"]').addClass('active');
|
||||
var initKey = ($iconInput.val() || '').trim();
|
||||
if (initKey) {
|
||||
$('.fc-icon-chip[data-key="' + initKey + '"]').addClass('active');
|
||||
}
|
||||
updateLivePreview();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table', 'backend/format'], fu
|
||||
{field: 'category', title: __('Category'), operate: 'in', formatter: Table.api.formatter.label, searchList: Config.categoryList},
|
||||
{field: 'admin_id', title: __('Admin_id'), visible: false, addClass: "selectpage", extend: "data-source='auth/admin/index' data-field='nickname'"},
|
||||
{field: 'user_id', title: __('User_id'), visible: false, addClass: "selectpage", extend: "data-source='user/user/index' data-field='nickname'"},
|
||||
{field: 'preview', title: __('Preview'), formatter: Controller.api.formatter.thumb, operate: false},
|
||||
{field: 'preview', title: __('Preview'), formatter: Controller.api.formatter.thumb, operate: false, events: Controller.api.events.thumb},
|
||||
{field: 'url', title: __('Url'), formatter: Controller.api.formatter.url, visible: false},
|
||||
{field: 'filename', title: __('Filename'), sortable: true, formatter: Controller.api.formatter.filename, operate: 'like'},
|
||||
{
|
||||
@@ -81,6 +81,14 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table', 'backend/format'], fu
|
||||
// 为表格绑定事件
|
||||
Table.api.bindevent(table);
|
||||
|
||||
// 为表格绑定图片放大预览事件
|
||||
$(table).on('click', '.img-preview', function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
Controller.api.previewImage(this);
|
||||
return false;
|
||||
});
|
||||
|
||||
// 附件归类
|
||||
$(document).on('click', '.btn-classify', function () {
|
||||
var ids = Table.api.selectedids(table);
|
||||
@@ -152,7 +160,7 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table', 'backend/format'], fu
|
||||
{field: 'category', title: __('Category'), operate: 'in', formatter: Table.api.formatter.label, searchList: Config.categoryList},
|
||||
{field: 'admin_id', title: __('Admin_id'), formatter: Table.api.formatter.search, visible: false},
|
||||
{field: 'user_id', title: __('User_id'), formatter: Table.api.formatter.search, visible: false},
|
||||
{field: 'url', title: __('Preview'), formatter: Controller.api.formatter.thumb, operate: false},
|
||||
{field: 'url', title: __('Preview'), formatter: Controller.api.formatter.thumb, operate: false, events: Controller.api.events.thumb},
|
||||
{field: 'filename', title: __('Filename'), sortable: true, formatter: Controller.api.formatter.filename, operate: 'like'},
|
||||
{field: 'imagewidth', title: __('Imagewidth'), operate: false, sortable: true},
|
||||
{field: 'imageheight', title: __('Imageheight'), operate: false, sortable: true},
|
||||
@@ -200,6 +208,14 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table', 'backend/format'], fu
|
||||
|
||||
// 为表格绑定事件
|
||||
Table.api.bindevent(table);
|
||||
|
||||
// 为表格绑定图片放大预览事件
|
||||
$(table).on('click', '.img-preview', function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
Controller.api.previewImage(this);
|
||||
return false;
|
||||
});
|
||||
require(['upload'], function (Upload) {
|
||||
$("#toolbar .faupload").data("category", function (file) {
|
||||
var category = $("ul.nav-tabs[data-field='category'] li.active a").data("value");
|
||||
@@ -231,9 +247,89 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table', 'backend/format'], fu
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
api: {
|
||||
/**
|
||||
* 绑定表单通用事件
|
||||
*/
|
||||
bindevent: function () {
|
||||
Form.api.bindevent($("form[role=form]"));
|
||||
},
|
||||
/**
|
||||
* 表格事件定义
|
||||
*/
|
||||
events: {
|
||||
thumb: {
|
||||
/**
|
||||
* 点击缩略图触发放大预览
|
||||
* @param {Event} e 事件对象
|
||||
* @param {any} value 字段值
|
||||
* @param {object} row 当前行数据
|
||||
* @param {number} index 行索引
|
||||
*/
|
||||
'click .img-preview': function (e, value, row, index) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
Controller.api.previewImage(this, row);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 放大预览单张或多张图片附件(调用Layer.photos灯箱)
|
||||
* @param {HTMLElement} element 当前点击的DOM元素
|
||||
* @param {object} [row] 当前行数据(可选)
|
||||
*/
|
||||
previewImage: function (element, row) {
|
||||
var $elem = $(element);
|
||||
var currentSrc = $elem.attr('href') || (row && row.fullurl) || '';
|
||||
if (!currentSrc) {
|
||||
return;
|
||||
}
|
||||
var photos = [];
|
||||
var startIndex = 0;
|
||||
var $container = $elem.closest('.bootstrap-table');
|
||||
var $items = $container && $container.length ? $container.find('.img-preview') : $('.img-preview');
|
||||
$items.each(function () {
|
||||
var src = $(this).attr('href');
|
||||
var alt = $(this).data('caption') || $(this).find('img').attr('alt') || '';
|
||||
if (src) {
|
||||
photos.push({
|
||||
alt: alt,
|
||||
src: src,
|
||||
thumb: $(this).find('img').attr('src') || src
|
||||
});
|
||||
if (this === element || (src === currentSrc && startIndex === 0)) {
|
||||
startIndex = photos.length - 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (photos.length === 0) {
|
||||
photos.push({
|
||||
alt: (row && row.filename) || $elem.data('caption') || '',
|
||||
src: currentSrc,
|
||||
thumb: $elem.find('img').attr('src') || currentSrc
|
||||
});
|
||||
}
|
||||
|
||||
var layerObj = typeof Layer !== 'undefined' ? Layer : (window.Layer || (window.parent && window.parent.Layer));
|
||||
if (layerObj && typeof layerObj.photos === 'function') {
|
||||
layerObj.photos({
|
||||
photos: {
|
||||
title: (row && row.filename) || $elem.data('caption') || __('Preview'),
|
||||
start: startIndex,
|
||||
data: photos
|
||||
},
|
||||
anim: 5
|
||||
});
|
||||
} else {
|
||||
window.open(currentSrc, '_blank');
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 安全校验并过滤URL
|
||||
* @param {string} value 待校验URL
|
||||
* @returns {string} 过滤转义后的URL
|
||||
*/
|
||||
safeurl: function (value) {
|
||||
value = value == null ? '' : String(value);
|
||||
if (/[\x00-\x1f\x7f]/.test(value)) {
|
||||
@@ -246,9 +342,19 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table', 'backend/format'], fu
|
||||
return Fast.api.escape(value);
|
||||
},
|
||||
formatter: {
|
||||
/**
|
||||
* 文本转义格式化
|
||||
* @param {string} value 文本内容
|
||||
* @returns {string} 转义后文本
|
||||
*/
|
||||
text: function (value) {
|
||||
return Fast.api.escape(value == null ? '' : String(value));
|
||||
},
|
||||
/**
|
||||
* 兼容历史HTML实体的文本格式化
|
||||
* @param {string} value 原始文本
|
||||
* @returns {string} 处理后文本
|
||||
*/
|
||||
legacytext: function (value) {
|
||||
value = value == null ? '' : String(value);
|
||||
value = value.replace(/&(amp|lt|gt|quot|#0*39|#x0*27);/gi, function (match, entity) {
|
||||
@@ -261,21 +367,36 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table', 'backend/format'], fu
|
||||
});
|
||||
return Controller.api.formatter.text(value);
|
||||
},
|
||||
/**
|
||||
* 通用搜索列格式化
|
||||
* @param {string} value 单元格值
|
||||
* @param {object} row 当前行数据
|
||||
* @param {number} index 行索引
|
||||
* @returns {string} 渲染HTML
|
||||
*/
|
||||
search: function (value, row, index) {
|
||||
if (row && this.field && typeof row[this.field] !== 'undefined') {
|
||||
value = row[this.field];
|
||||
}
|
||||
return Table.api.formatter.search.call(this, Controller.api.formatter.text(value), row, index);
|
||||
},
|
||||
/**
|
||||
* 附件缩略图与图标格式化器
|
||||
* @param {string} value 字段值
|
||||
* @param {object} row 当前行数据
|
||||
* @param {number} index 行索引
|
||||
* @returns {string} 渲染后的预览HTML
|
||||
*/
|
||||
thumb: function (value, row, index) {
|
||||
var html = '';
|
||||
var fullurl = Controller.api.safeurl(row.fullurl);
|
||||
if (row.mimetype.indexOf("image") > -1) {
|
||||
var filename = Controller.api.formatter.text(row.filename || '');
|
||||
if (row.mimetype && row.mimetype.indexOf("image") > -1) {
|
||||
var thumburl = Controller.api.safeurl((row.fullurl || '') + (row.thumb_style || ''));
|
||||
html = '<a href="' + fullurl + '" target="_blank"><img src="' + thumburl + '" alt="" style="max-height:60px;max-width:120px"></a>';
|
||||
html = '<a href="' + fullurl + '" target="_blank" class="img-preview" data-caption="' + filename + '"><img src="' + thumburl + '" alt="' + filename + '" style="max-height:60px;max-width:120px"></a>';
|
||||
} else {
|
||||
var iconurl = Controller.api.safeurl(Fast.api.fixurl("ajax/icon") + "?suffix=" + encodeURIComponent(row.imagetype || ''));
|
||||
html = '<a href="' + fullurl + '" target="_blank"><img src="' + iconurl + '" alt="" style="max-height:90px;max-width:120px"></a>';
|
||||
html = '<a href="' + fullurl + '" target="_blank"><img src="' + iconurl + '" alt="' + filename + '" style="max-height:90px;max-width:120px"></a>';
|
||||
}
|
||||
return '<div style="width:120px;margin:0 auto;text-align:center;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;">' + html + '</div>';
|
||||
},
|
||||
|
||||
在新工单中引用
屏蔽一个用户