//ajax封装 function ajaxR(url, type, data, otherParam, successCallback, errorCallback) { let {dataType="json", async=true, isHandoverLang=1} = otherParam; $.ajax({ url: url, type: type, data: data, dataType: dataType, // 假设我们处理的数据类型为JSON async:async, beforeSend: function(xhr) { // 在这里可以处理请求前的逻辑,例如显示加载动画 if(isHandoverLang == 1){//切换语言保存 let isAllowed = handoverLang(); if(!isAllowed){ // 不发送请求,中止 foxui.message({ type: 'danger', text: "语言切换失败,防止数据混乱,请刷新页面后再操作!" }) xhr.abort(); // 或者返回 false; } } }, success: function(response) { // 请求成功后的处理逻辑 console.log('请求成功,处理数据...'); if (successCallback && typeof successCallback === 'function') { successCallback(response); } }, error: function(xhr, status, error) { // 请求失败的处理逻辑 console.log('请求失败,处理错误...'); if (errorCallback && typeof errorCallback === 'function') { errorCallback(xhr, status, error); }else{ foxui.message({ type: 'warning', text: "操作失败" }) } }, complete: function() { // 请求完成后的处理逻辑,无论成功或失败都会执行 console.log('请求完成的处理...'); } }); } //当前显示语言 function handoverLang() { let showLang = $(".lang-select button").attr('data-lang'); let isChange = false; if ($(".lang-select button").hasClass('display-none')) { isChange = true; } else { $.ajax({ type: "post", url: HANDOVER_LANG_PATH, dataType: "json", data: {"lang":showLang}, async:false, success: function (res) { if(res.code == 1){ isChange = true; } }, error: function (res) { } }); } return isChange; } //语言切换 function langHandover(obj) { let lang = $(obj).attr('data-lang'); foxui.loading(); $.ajax({ type: "post", url: HANDOVER_LANG_PATH, dataType: "json", data: {"lang":lang}, success: function (res) { foxui.closeLoading(); if(res.code == 1){ let langName = ""; if(res.data){ langName = res.data.name; } foxui.message({ type: 'success', text: "当前语言已切换成“"+langName+"”" }) window.location.href= ADMIN_PATH+"/Index"; }else{ foxui.message({ type: 'danger', text:res.msg }) } }, error: function (res) { foxui.closeLoading(); } }); } //获取栏目或者模型的自定义属性值 function getField(obj, url) { let saveData = {}; //拉取栏目属性 $.ajax({ type: 'get', url: url, dataType: 'json', async: false, success: function (res) { if (res.code == 1 && res.data) { let data = res.data; data.forEach((item, index) => { let cn = '.' + item.name; let itemC = $(obj).find(cn); if (item.dtype == 'radio') { //单选 let rinput = $(itemC).find('.foxui-radio.is-checked').find('input'); saveData[item.name] = $(rinput).val()||""; } else if (item.dtype == 'checkbox') { //多选项 let dxx = ''; let fcs = $(itemC).find('.foxui-checkbox.is-checked'); $.each(fcs, function (key, value) { //遍历多选值 let ri = $(value).find('input'); dxx += $(ri).val() + ','; }); if (dxx.length > 0) { dxx = dxx.substr(0, dxx.length - 1); } saveData[item.name] = dxx; } else if (item.dtype == 'switch') { //开关 saveData[item.name] = $(itemC).prop('checked')?1:0; } else if (item.dtype == 'htmltext') { //HTML文本 saveData[item.name] = getRTtContent(item.name); } else if (item.dtype == 'select') { //下拉框 saveData[item.name] = $(itemC).attr('data-id')||""; } else if (item.dtype == 'datetime') { //日期和时间 saveData[item.name] = $(itemC).val()||""; } else if (item.dtype == 'int') { //整数类型 saveData[item.name] = $(itemC).val()||""; } else if (item.dtype == 'text') { //单行文本 saveData[item.name] = $(itemC).val()||""; } else if (item.dtype == 'multitext') { //多行文本 saveData[item.name] = $(itemC).val()||""; } else if (item.dtype == 'color') { //颜色 saveData[item.name] = $(itemC).val()||""; } else if (item.dtype == 'pic') { //图片文件 let imgIds = ''; let imgs = $(itemC).find('img'); $.each(imgs, function (key, value) { //遍历多选值 // let imgId = $(value).attr("data-id"); let imgId = $(value).attr('src'); imgIds += imgId + ','; }); if (imgIds.length > 0) { imgIds = imgIds.substr(0, imgIds.length - 1); } saveData[item.name] = imgIds||""; } else if (item.dtype == 'pics') { //图片文件 let imgSrcs = ''; let imgs = $(itemC).find('img'); $.each(imgs, function (key, value) { //遍历多选值 let imgSrc = $(value).attr('src'); imgSrcs += imgSrc + ','; }); if (imgSrcs.length > 0) { imgSrcs = imgSrcs.substr(0, imgSrcs.length - 1); } saveData[item.name] = imgSrcs||""; }else if (item.dtype == 'media') {//媒体 //媒体文件 let lis = $(itemC).find('li'); let videos = []; $.each(lis, function (key, li) { let videoId = $(li).find("img").attr('data-id'); let url = $(li).find("img").attr('data-url'); let pic = $(li).find("img").attr('src'); let videoTitle = $(li).find("input").val(); videos.push({"id":videoId, "title": videoTitle, "url":url, pic}); }); saveData[item.name] = JSON.stringify(videos); } else if (item.dtype == 'decimal') { //金额类型 saveData[item.name] = $(itemC).val()||""; } else if (item.dtype == 'float') { //小数类型 saveData[item.name] = $(itemC).val()||""; }else{ //普通的input标签,varchar字段获取 saveData[item.name] = $(itemC).val()||""; } }); } }, error: function (res) { console.log('字段属性。。。。'); }, }); return saveData; } /** * 根据字典类型获取对应字典数据(dict_data查询) * @param dictType 字典类型 * @param dictType $resultField 返回的字段 如 dict_label,dict_value */ function getColumModels() { let dictDatas = []; $.ajax({ type: 'get', // url: ADMIN_PATH + '/Column/getColumModels', url: GETCOLUMMODELS_PATH, dataType: 'json', async: false, success: function (res) { if (res.code == 1 && res.data) { dictDatas = res.data; } }, error: function (res) { console.log('查询字典失败。。。。'); }, }); return dictDatas; } function dialogContent() { return `
成功生成栏目:
失败生成栏目: