| | |
| | | * @Author: 小飞侠 |
| | | * @Date: 2024-03-01 09:11:24 |
| | | * @LastEditors: Please set LastEditors |
| | | * @LastEditTime: 2024-03-21 09:47:04 |
| | | * @LastEditTime: 2024-04-26 13:25:48 |
| | | * Copyright: 2024 MinTinge CO.,LTD. All Rights Reserved. |
| | | * @Descripttion: 写入你的描述 |
| | | */ |
| | |
| | | * @LastEditTime: Do not Edit |
| | | */ |
| | | function filterTreeWithjQuery(tree, predicate) { |
| | | var results = []; |
| | | var results = []; |
| | | |
| | | function traverse(node) { |
| | | if (predicate(node)) { |
| | | results.push(node); |
| | | function traverse(node) { |
| | | if (predicate(node)) { |
| | | results.push(node); |
| | | } |
| | | if (node.children && Array.isArray(node.children)) { |
| | | $.each(node.children, traverse); |
| | | } |
| | | } |
| | | if (node.children && Array.isArray(node.children)) { |
| | | $.each(node.children, traverse); |
| | | } |
| | | } |
| | | |
| | | $.each(tree, traverse); |
| | | $.each(tree, traverse); |
| | | |
| | | return results; |
| | | return results; |
| | | } |
| | | /** |
| | | * @description: 判断一个字符串是不是数字字符串 |
| | |
| | | * @LastEditTime: Do not Edit |
| | | */ |
| | | function isNumericString(str) { |
| | | const regex = /^-?\d+(\.\d+)?$/; // 匹配整数或小数,包括负数 |
| | | return regex.test(str); |
| | | const regex = /^-?\d+(\.\d+)?$/; // 匹配整数或小数,包括负数 |
| | | return regex.test(str); |
| | | } |
| | | |
| | | |
| | |
| | | * 当使用了formatAreaInPut 后 可使用此函数获取一个由地址id组成的areaId 字符串,用,号分割 |
| | | * @param {Object} field -表单。 |
| | | */ |
| | | function GetAreaCodeFormFileid(field,idname) { |
| | | let areaCode=""; |
| | | if (isNumericString(field[`${idname}_1`])) { |
| | | areaCode+=`${field[`${idname}_1`]}`; |
| | | if (isNumericString(field[`${idname}_2`])) |
| | | areaCode+=`,${field[`${idname}_2`]}`; |
| | | if (isNumericString(field[`${idname}_3`])) |
| | | areaCode+=`,${field[`${idname}_3`]}`; |
| | | } else { |
| | | |
| | | } |
| | | return areaCode; |
| | | function GetAreaCodeFormFileid(field, idname) { |
| | | let areaCode = ""; |
| | | if (isNumericString(field[`${idname}_1`])) { |
| | | areaCode += `${field[`${idname}_1`]}`; |
| | | if (isNumericString(field[`${idname}_2`])) |
| | | areaCode += `,${field[`${idname}_2`]}`; |
| | | if (isNumericString(field[`${idname}_3`])) |
| | | areaCode += `,${field[`${idname}_3`]}`; |
| | | } else { |
| | | |
| | | } |
| | | return areaCode; |
| | | } |
| | | |
| | | /** |
| | |
| | | * 会生成几个areaId-1,areaId-3,areaId-3 |
| | | * @param {Object} coreHelper - 核心辅助对象,用于执行HTTP请求等操作。 |
| | | */ |
| | | function formatAreaInPut(coreHelper,idname,areaid="") { |
| | | let area=0; |
| | | if(areaid!=="") |
| | | area= areaid.split(",").reverse()[0]; |
| | | |
| | | coreHelper.Post("Api/Tools/GetAreaCheckedList", { id: Number(area) }, function (data) { |
| | | if (debug) { console.log(data); } //开启调试返回数据 |
| | | var str = ""; |
| | | $.each(data, function (i, n) { |
| | | str += `<select lay-ignore name='${idname}_` + (i + 1) + "' dep='" + (i + 1) + "' class='select-address'>"; |
| | | str += "<option value='' >请选择</option>"; |
| | | $.each(n.list, function (h, z) { |
| | | if (n.hasOwnProperty('info') && n.info?.id == z.id) { |
| | | str += "<option value='" + z.id + "' selected='selected'>" + z.name + "</option>"; |
| | | } else { |
| | | str += "<option value='" + z.id + "' >" + z.name + "</option>"; |
| | | function formatAreaInPut(coreHelper, idname, areaid = "") { |
| | | let area = 0; |
| | | |
| | | if ((areaid !== "")&&(areaid!==null) &&(areaid!==0)) |
| | | area = areaid.split(",").reverse()[0]; |
| | | |
| | | coreHelper.Post("Api/Tools/GetAreaCheckedList", { id: Number(area) }, function (data) { |
| | | if (debug) { console.log(data); } //开启调试返回数据 |
| | | var str = ""; |
| | | $.each(data, function (i, n) { |
| | | str += `<select lay-ignore name='${idname}_` + (i + 1) + "' dep='" + (i + 1) + "' class='select-address'>"; |
| | | str += "<option value='' >请选择</option>"; |
| | | |
| | | if(n?.list?.length>0) |
| | | { |
| | | $.each(n.list, function (h, z) { |
| | | if (n.hasOwnProperty('info') && n.info?.id == z.id) { |
| | | str += "<option value='" + z.id + "' selected='selected'>" + z.name + "</option>"; |
| | | } else { |
| | | str += "<option value='" + z.id + "' >" + z.name + "</option>"; |
| | | } |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | $.each(n.thisList, function (h, z) { |
| | | if (n.hasOwnProperty('info') && n.info?.id == z.id) { |
| | | str += "<option value='" + z.id + "' selected='selected'>" + z.name + "</option>"; |
| | | } else { |
| | | str += "<option value='" + z.id + "' >" + z.name + "</option>"; |
| | | } |
| | | }); |
| | | } |
| | | str += "</select>"; |
| | | }); |
| | | $(`input[name='${idname}']`).after(str); |
| | | //以上数据输出完,以下绑定事件 |
| | | $.each(data, function (i, n) { |
| | | if (i < (data.length)) { |
| | | // $(`select[name='${idname}_` + (i + 1) + "']").change(function () { |
| | | // changeareaIdArea(i + 1, data.length, idname); |
| | | // }); |
| | | $(`select[name='${idname}_` + (i + 1) + "']").click(function () { |
| | | changeareaIdArea(i + 1, data.length, idname); |
| | | }); |
| | | } |
| | | }); |
| | | str += "</select>"; |
| | | }); |
| | | $(`input[name='${idname}']`).after(str); |
| | | //以上数据输出完,以下绑定事件 |
| | | $.each(data, function (i, n) { |
| | | if (i < (data.length)) { |
| | | $(`select[name='${idname}_` + (i + 1) + "']").change(function () { |
| | | changeareaIdArea(i + 1, data.length,idname); |
| | | }); |
| | | function changeareaIdArea(i, max_i, idname) { |
| | | //清除后面节点 |
| | | for (var x = i + 1; x <= 6; x++) { //最多6层,足够了 |
| | | $(`select[name='${idname}_` + x + "']").remove(); |
| | | } |
| | | }); |
| | | }); |
| | | function changeareaIdArea(i, max_i,idname) { |
| | | //清除后面节点 |
| | | for (var x = i + 1; x <= 6; x++) { //最多6层,足够了 |
| | | $(`select[name='${idname}_` + x + "']").remove(); |
| | | } |
| | | var val = $(`select[name='${idname}_` + i + "']").val(); |
| | | if (val != "") { |
| | | //取子节点数据,然后显示下一级 |
| | | coreHelper.Post("Api/Tools/GetAreaChildren", { id: val }, function (e) { |
| | | if (debug) { console.log(e); } //开启调试返回数据 |
| | | var val = $(`select[name='${idname}_` + i + "']").val(); |
| | | if (val != "") { |
| | | //取子节点数据,然后显示下一级 |
| | | coreHelper.Post("Api/Tools/GetAreaChildren", { id: val }, function (e) { |
| | | if (debug) { console.log(e); } //开启调试返回数据 |
| | | |
| | | if (e.length > 0) { |
| | | var str = ""; |
| | | str += `<select lay-ignore name='${idname}_` + (i + 1) + "' dep='" + (i + 1) + "' class='select-address'>"; |
| | | str += "<option value='' >请选择</option>"; |
| | | $.each(e, function (h, z) { |
| | | str += "<option value='" + z.id + "' >" + z.name + "</option>"; |
| | | }); |
| | | str += "</select>"; |
| | | $(`select[name='${idname}_` + i + "']").after(str); |
| | | //以上数据输出完,以下绑定事件 |
| | | $(`select[name='${idname}_` + (i+1) + "']").change(function () { |
| | | changeareaIdArea(i + 1, i + 2,idname); |
| | | }); |
| | | if (e.length > 0) { |
| | | var str = ""; |
| | | str += `<select lay-ignore name='${idname}_` + (i + 1) + "' dep='" + (i + 1) + "' class='select-address'>"; |
| | | str += "<option value='' >请选择</option>"; |
| | | $.each(e, function (h, z) { |
| | | str += "<option value='" + z.id + "' >" + z.name + "</option>"; |
| | | }); |
| | | str += "</select>"; |
| | | $(`select[name='${idname}_` + i + "']").after(str); |
| | | //以上数据输出完,以下绑定事件 |
| | | $(`select[name='${idname}_` + (i + 1) + "']").change(function () { |
| | | changeareaIdArea(i + 1, i + 2, idname); |
| | | }); |
| | | |
| | | //如果有返回值,就说明省市区没有选择到最终节点 |
| | | if (1 == 1) { |
| | | $(`input[name='${idname}']`).val(""); |
| | | //如果有返回值,就说明省市区没有选择到最终节点 |
| | | if (1 == 1) { |
| | | $(`input[name='${idname}']`).val(""); |
| | | } else { |
| | | $(`input[name='${idname}']`).val($(`select[name='${idname}_` + i + "']").val()); |
| | | } |
| | | } else { |
| | | $(`input[name='${idname}']`).val($(`select[name='${idname}_` + i + "']").val()); |
| | | } |
| | | } else { |
| | | $(`input[name='${idname}']`).val($(`select[name='${idname}_` + i + "']").val()); |
| | | } |
| | | }); |
| | | } else { |
| | | if (1 == 1) { |
| | | $(`input[name='${idname}']`).val(""); |
| | | }); |
| | | } else { |
| | | //第一级的元素就直接赋值为空就是了 |
| | | if (i == 1) { |
| | | if (1 == 1) { |
| | | $(`input[name='${idname}']`).val(""); |
| | | } else { |
| | | i--; |
| | | $(`input[name='${idname}']`).val($(`select[name='${idname}` + i + "']").val()); |
| | | } |
| | | //第一级的元素就直接赋值为空就是了 |
| | | if (i == 1) { |
| | | $(`input[name='${idname}']`).val(""); |
| | | } else { |
| | | i--; |
| | | $(`input[name='${idname}']`).val($(`select[name='${idname}` + i + "']").val()); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 根据用户选择,格式化并更新 select 输入元素中的选项。 |
| | | * @param {object} coreHelper 核心辅助对象,用于执行 post 请求等操作。 |
| | | * @param {object} form 表单对象,用于重新渲染 select 元素。 |
| | | * @param {string} idname select 元素的 id 名称。 |
| | | */ |
| | | |
| | | function formatUserSelInPut(coreHelper, form, idname,selectedID="") { |
| | | |
| | | // 向服务器发送请求,获取用户列表 |
| | | coreHelper.PostForm("Api/CommonAPI/GetUserList", { sKey: "" }, function (data) { |
| | | if (debug) { console.log(data); } // 如果处于调试模式,打印返回的数据 |
| | | |
| | | if (data.code == 0) { |
| | | // 获取指定 id 的 select 元素 |
| | | var selectElement = document.getElementById(idname); |
| | | |
| | | // 遍历返回的用户数据,为 select 元素创建并添加新的 option 选项 |
| | | for (var i = 0; i < data.data.length; i++) { |
| | | var option = document.createElement('option'); |
| | | option.value = data.data[i].id; |
| | | if(selectedID==data.data[i].id){ |
| | | option.selected=true; |
| | | } |
| | | option.innerHTML = data.data[i].name; |
| | | selectElement.appendChild(option); |
| | | } |
| | | |
| | | // 重新渲染 select 元素,确保新的选项生效 |
| | | form.render('select'); |
| | | } |
| | | }) |
| | | } |
| | | |
| | | Date.prototype.Format = function (fmt) { |
| | | //author: meizz |
| | | var o = { |
| | | "M+": this.getMonth() + 1, //月份 |
| | | "d+": this.getDate(), //日 |
| | | "h+": this.getHours(), //小时 |
| | | "m+": this.getMinutes(), //分 |
| | | "s+": this.getSeconds(), //秒 |
| | | "q+": Math.floor((this.getMonth() + 3) / 3), //季度 |
| | | }; |
| | | if (/(y+)/.test(fmt)) |
| | | fmt = fmt.replace( |
| | | RegExp.$1, |
| | | (this.getFullYear() + "").substr(4 - RegExp.$1.length) |
| | | ); |
| | | for (var k in o) |
| | | if (new RegExp("(" + k + ")").test(fmt)) |
| | | fmt = fmt.replace( |
| | | RegExp.$1, |
| | | RegExp.$1.length == 1 |
| | | ? o[k] |
| | | : ("00" + o[k]).substr(("" + o[k]).length) |
| | | ); |
| | | return fmt; |
| | | }; |
| | | |
| | | /** |
| | | * 检查给定的字符串是否为日期时间格式 |
| | | * @param {string} str - 需要检查的字符串 |
| | | * @return {boolean} 返回一个布尔值,指示字符串是否符合日期时间格式 |
| | | */ |
| | | function isDateTimeString(str) { |
| | | // 定义日期时间的正则表达式模式 |
| | | const dateTimePattern = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/; |
| | | // 使用正则表达式模式测试字符串 |
| | | return dateTimePattern.test(str); |
| | | } |
| | | |
| | | /** |
| | | * 格式化商品分类选择输入框 |
| | | * @param {object} coreHelper 核心辅助对象,用于发送请求等操作 |
| | | * @param {object} form 表单对象,用于重新渲染select元素 |
| | | * @param {string} idname 输入框的id名称 |
| | | * @param {string} selectedID 默认选中的分类ID,为空时默认不选中任何项 |
| | | */ |
| | | function formatGoodsCategorySelInPut(coreHelper, form, idname,selectedID="") { |
| | | |
| | | // 向服务器发送请求,获取用户列表 |
| | | coreHelper.PostForm("Api/CommonAPI/GetGoodsCategory", { }, function (data) { |
| | | if (debug) { console.log(data); } // 如果处于调试模式,打印返回的数据 |
| | | |
| | | if (data.code == 0) { |
| | | // 获取指定 id 的 select 元素 |
| | | var selectElement = document.getElementById(idname); |
| | | |
| | | // 遍历返回的用户数据,为 select 元素创建并添加新的 option 选项 |
| | | for (var i = 0; i < data.data.length; i++) { |
| | | var option = document.createElement('option'); |
| | | option.value = data.data[i].id; |
| | | if(selectedID==data.data[i].id){ |
| | | option.selected=true; |
| | | } |
| | | option.innerHTML = data.data[i].name; |
| | | selectElement.appendChild(option); |
| | | } |
| | | |
| | | // 重新渲染 select 元素,确保新的选项生效 |
| | | form.render('select'); |
| | | } |
| | | }) |
| | | } |