上传图片 添加加载中动画

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();
}
});