上传图片 添加加载中动画

This commit is contained in:
浅念
2025-09-01 14:22:08 +08:00
parent 431c41be79
commit ec19e24f68
10 changed files with 96 additions and 6 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
// 多语言配置
// var baseUrl = 'https://server.orzar.shop/'
var baseUrllang = "https://usedcar.server.hnxinyouhe.com/";
var baseUrllang = 'https://server.orzar.shop/';
// var baseUrllang = "https://usedcar.server.hnxinyouhe.com/";
var langConfig = {
'zh': {
'baseUrl':baseUrllang,
+2 -2
View File
@@ -3,8 +3,8 @@ var ajax = null,queue = [];
var isAjaxLock=false;
var Utils={}
var userinfowifi='';
// var baseUrl = "https://server.orzar.shop/";
var baseUrl = "https://usedcar.server.hnxinyouhe.com/";
var baseUrl = "https://server.orzar.shop/";
// var baseUrl = "https://usedcar.server.hnxinyouhe.com/";
// var baseUrl = "http://192.168.50.6:8787/";
if(sessionStorage.wifiuserinfo){
userinfowifi=JSON.parse(sessionStorage.wifiuserinfo)
+36
View File
@@ -51,6 +51,33 @@ layui.$(function () {
toggleSearchFormShow();
});
// 公共:上传loading 显示/隐藏(兼容 iframe,优先使用顶层 layer)
var uploadLoadingIndex = null;
var uploadLoadingLayerRef = null;
function showUploadLoading(){
try{
if(uploadLoadingIndex === null){
var layerRef = (typeof top !== 'undefined' && top.layui && top.layui.layer) ? top.layui.layer
: (typeof parent !== 'undefined' && parent.layui && parent.layui.layer) ? parent.layui.layer
: (typeof layui !== 'undefined' && layui.layer) ? layui.layer
: null;
if(layerRef){
uploadLoadingLayerRef = layerRef;
uploadLoadingIndex = layerRef.load(2, {shade: [0.2, '#000']});
}
}
}catch(e){}
}
function hideUploadLoading(){
try{
if(uploadLoadingIndex !== null && uploadLoadingLayerRef){
uploadLoadingLayerRef.close(uploadLoadingIndex);
uploadLoadingIndex = null;
uploadLoadingLayerRef = null;
}
}catch(e){}
}
function brandpresetfn(form,istrue){
self.brandpreset({
type:'get',
@@ -487,6 +514,8 @@ function uploadimage(upload,baseUrl){
acceptMime: 'image/*',
field: 'image',
before: function(obj) {
// 显示上传loading
showUploadLoading();
// 预读本地文件,如果是多文件,则会遍历。(不支持ie8/9)
obj.preview(function(index, file, result) {
// 生成唯一的图片ID
@@ -513,12 +542,19 @@ function uploadimage(upload,baseUrl){
// 通过data-index属性找到对应的元素
$('.upload-itemm[data-index="' + index + '"]').find('input[name="pic[]"]').val(
res.data.image_name);
hideUploadLoading();
} else {
layer.msg('上传失败');
hideUploadLoading();
}
},
allDone: function(obj){
// 多文件上传结束后兜底隐藏
if (typeof hideUploadLoading === 'function') hideUploadLoading();
},
error: function() {
layer.msg('上传失败');
hideUploadLoading();
}
});
+2 -2
View File
@@ -157,8 +157,8 @@
$(this).addClass('icon-check');
}
});
// var baseUrl = "https://server.orzar.shop/";
var baseUrl = "https://usedcar.server.hnxinyouhe.com/";
var baseUrl = "https://server.orzar.shop/";
// var baseUrl = "https://usedcar.server.hnxinyouhe.com/";
// 进行登录操作
form.on('submit(login)', function (data) {
data = data.field;
+9
View File
@@ -365,11 +365,20 @@
url:baseUrl+ 'console/upload/image',
accept: 'images',
field: 'image',
before: function(obj) {
// 显示上传loading
showUploadLoading();
},
done: function(res){
hideUploadLoading();
if(res.code == 0){
$item.find('img').attr('src',res.data.image_url);
$item.find('input').val(res.data.image_name);
}
},
error: function() {
layer.msg('上传失败');
hideUploadLoading();
}
});
});
+9
View File
@@ -436,13 +436,22 @@
url:baseUrl+ 'console/upload/image',
accept: 'images',
field: 'image',
before: function(obj) {
// 显示上传loading
showUploadLoading();
},
done: function(res){
hideUploadLoading();
if(res.code == 0){
// var $preview = $item.find('.preview-box');
// $preview.html('<img src="'+res.data.src+'" style="max-width:100px;">');
$item.find('img').attr('src',res.data.image_url);
$item.find('input').val(res.data.image_name);
}
},
error: function() {
layer.msg('上传失败');
hideUploadLoading();
}
});
});
+9
View File
@@ -255,11 +255,20 @@
url:baseUrl+ 'console/upload/image',
accept: 'images',
field: 'image',
before: function(obj) {
// 显示上传loading
showUploadLoading();
},
done: function(res){
hideUploadLoading();
if(res.code == 0){
$item.find('img').attr('src',res.data.image_url);
$item.find('input').val(res.data.image_name);
}
},
error: function() {
layer.msg('上传失败');
hideUploadLoading();
}
});
});
+9
View File
@@ -360,11 +360,20 @@
url:baseUrl+ 'console/upload/image',
accept: 'images',
field: 'image',
before: function(obj) {
// 显示上传loading
showUploadLoading();
},
done: function(res){
hideUploadLoading();
if(res.code == 0){
$item.find('img').attr('src',res.data.image_url);
$item.find('input').val(res.data.image_name);
}
},
error: function() {
layer.msg('上传失败');
hideUploadLoading();
}
});
});
+9
View File
@@ -76,11 +76,20 @@
url:baseUrl+ 'console/upload/image',
accept: 'images',
field: 'image',
before: function(obj) {
// 显示上传loading
showUploadLoading();
},
done: function(res){
hideUploadLoading();
if(res.code == 0){
$(".img-3").attr('src',res.data.image_url);
$("#avatarinput").val(res.data.image_name);
}
},
error: function() {
layer.msg('上传失败');
hideUploadLoading();
}
});
//监听提交
+9
View File
@@ -120,11 +120,20 @@
url:baseUrl+ 'console/upload/image',
accept: 'images',
field: 'image',
before: function(obj) {
// 显示上传loading
showUploadLoading();
},
done: function(res){
hideUploadLoading();
if(res.code == 0){
$(".img-3").attr('src',res.data.image_url);
$("#avatarinput").val(res.data.image_name);
}
},
error: function() {
layer.msg('上传失败');
hideUploadLoading();
}
});
});