mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-26 03:16:36 +08:00
优化文件选择器
This commit is contained in:
parent
1d73c7e142
commit
55c037d7aa
@ -33,6 +33,7 @@
|
|||||||
list: [],
|
list: [],
|
||||||
data: [],
|
data: [],
|
||||||
idxs: {},
|
idxs: {},
|
||||||
|
urls: [],
|
||||||
},
|
},
|
||||||
created: function () {
|
created: function () {
|
||||||
this.$btn = $('#{$get.id|default=""}');
|
this.$btn = $('#{$get.id|default=""}');
|
||||||
@ -46,15 +47,24 @@
|
|||||||
this.page = 1;
|
this.page = 1;
|
||||||
this.loadPage();
|
this.loadPage();
|
||||||
},
|
},
|
||||||
|
// 确认选择数据
|
||||||
|
confirm: function () {
|
||||||
|
this.urls = [];
|
||||||
|
this.data.forEach(function (file) {
|
||||||
|
app.setValue(file.xurl);
|
||||||
|
});
|
||||||
|
this.setInput();
|
||||||
|
},
|
||||||
// 设置单项数据
|
// 设置单项数据
|
||||||
setItem: function (item) {
|
setItem: function (item) {
|
||||||
if (!this.mult) return this.setValue(item.xurl);
|
if (!this.mult) {
|
||||||
if ((item.checked = !this.idxs[item.id])) {
|
this.setValue(item.xurl).setInput();
|
||||||
|
} else if ((item.checked = !this.idxs[item.id])) {
|
||||||
(this.idxs[item.id] = item) && this.data.push(item);
|
(this.idxs[item.id] = item) && this.data.push(item);
|
||||||
} else {
|
} else {
|
||||||
delete this.idxs[item.id];
|
delete this.idxs[item.id];
|
||||||
layui.each(this.data, function (idx, _ite) {
|
this.data.forEach(function (temp, idx) {
|
||||||
_ite.id === item.id && app.data.splice(idx, 1);
|
temp.id === item.id && app.data.splice(idx, 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -64,20 +74,19 @@
|
|||||||
this.list.forEach(function (item) {
|
this.list.forEach(function (item) {
|
||||||
item.checked = !!app.idxs[item.id]
|
item.checked = !!app.idxs[item.id]
|
||||||
item.style = 'background-image:url(' + item.xurl + ')';
|
item.style = 'background-image:url(' + item.xurl + ')';
|
||||||
});
|
}), this.addPage(count);
|
||||||
this.addPage(count);
|
|
||||||
},
|
|
||||||
// 确认选择数据
|
|
||||||
confirm: function () {
|
|
||||||
layui.each(this.data, function (idx, file) {
|
|
||||||
app.setValue(file.xurl);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
// 设置选择数据
|
// 设置选择数据
|
||||||
setValue: function (url) {
|
setValue: function (xurl) {
|
||||||
this.$btn.triggerHandler('push', url);
|
this.urls.push(xurl) && this.$btn.triggerHandler('push', xurl);
|
||||||
if (this.$btn.data('input')) $(this.$btn.data('input')).val(url).trigger('change', url);
|
|
||||||
$('#ImageDialog').parents('.layui-layer-content').next().find('.layui-layer-close').trigger('click');
|
$('#ImageDialog').parents('.layui-layer-content').next().find('.layui-layer-close').trigger('click');
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
// 设置输入表单
|
||||||
|
setInput: function () {
|
||||||
|
if (this.$btn.data('input')) {
|
||||||
|
$(this.$btn.data('input')).val(this.urls.join('|')).trigger('change');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// 创建分页工具条
|
// 创建分页工具条
|
||||||
addPage: function (count) {
|
addPage: function (count) {
|
||||||
@ -99,8 +108,11 @@
|
|||||||
},
|
},
|
||||||
// 上传图片文件
|
// 上传图片文件
|
||||||
uploadImage: function () {
|
uploadImage: function () {
|
||||||
|
this.urls = [];
|
||||||
this.$ups.off('push').on('push', function (e, xurl) {
|
this.$ups.off('push').on('push', function (e, xurl) {
|
||||||
app.setValue(xurl);
|
app.setValue(xurl);
|
||||||
|
}).off('upload.complete').on('upload.complete', function () {
|
||||||
|
app.setInput();
|
||||||
}).click();
|
}).click();
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user