未完全适配,待更新。
/***********************************************
该文件提供xform相关的公用函数(移动端)
***********************************************/
function AttachChangeEventById(flagid, func) {
// 明细表控件
if (flagid.substring(0,3) === "DL_") {
flagid = flagid.substring(3);
AttachXFormValueChangeEventById(flagid, func);
return;
}
// $("[flagid='" + flagid + "']").bind("change", func);// 无效
const flagtype = getXFormFlagType(flagid);
let selector = "[id='_xform_extendDataFormInfo.value("+ flagid +")']";
// 特殊 -
const special = "xform_address;xform_new_address;xform_select;xform_fSelect;" +
"xform_datetime;formula_calculation;xform_relation_select;xform_relation_choose";
if (special.includes(flagtype)) {
AttachXFormValueChangeEventById(flagid, func);
return;
}
$(document).on("change", selector, {flagid: flagid}, func);
}
function AttachChangeEventById_attachment(flagid, func) {
console.log("AttachChangeEventById_attachment 未适配移动端")
}
function ChangeEventValue(a, b) {
// console.log({a})
// console.log({b})
// 取flagid
const flagid = ChangeEventFlagid(a, b);
// 取值
let rtnValue = getValueById(flagid);
// 解决触发函数中获取到实际值有延后的问题(操作的flagid必须与AttachChangeEventById.special一致)
const flagtype = getXFormFlagType(flagid);
if ("formula_calculation".includes(flagtype)) {
if (typeof b === "undefined") {console.error("非AttachXFormValueChangeEventById,a并非值")}
rtnValue = a;
}
return rtnValue;
}
function ChangeEventTargetValue(a, b) {
const flagtype = getXFormFlagType(ChangeEventFlagid(a, b));
if (flagtype === "xform_checkbox") {
return typeof b === "undefined" ? a.target.value : a;
}
return flagtype + " : xform_public_mb.ChangeEventTargetValue未适配"
}
function ChangeEventFlagid(a, b) {
let flagid;
if (typeof b === "undefined" && typeof a.data !== "undefined") {
flagid = a.data.flagid;
}
else {
const id = $(b.domNode).closest("xformflag").attr("id");
flagid = id.substring(id.indexOf("(") + 1, id.indexOf(")"));// id转flagid
}
return flagid
}
function ChangeEventSameRowFlagid(a, b, sameRowId) {
const flagid = ChangeEventFlagid(a, b);
if (flagid.includes(".")) {// 是明细表控件
const rowIndex = ChangeEventDetailListRowIndex(a, b);
return flagid.substring(0, flagid.indexOf(".")) + "." + rowIndex + "." + sameRowId;
}
else {
return sameRowId;
}
}
function ChangeEventDetailListRowIndex(a, b) {
const flagid = ChangeEventFlagid(a, b);
let rowIndex = -1;
// 明细表目标控件在明细表中
if (flagid.includes(".")) {
const dot1 = flagid.indexOf(".");
const dot2 = flagid.indexOf(".", dot1 + 1);
rowIndex = Number(flagid.substring(dot1 + 1, dot2));
}
return rowIndex;
}
function AttachClickEventById(flagid, func) {
// const flagtype = getXFormFlagType(flagid);
const selector = "[id='_xform_extendDataFormInfo.value("+ flagid +")']";
$(selector).css("cursor", "pointer");
$(document).on("click", selector, {flagid: flagid}, func);
}
function AttachWindowLoadEvent(func) {
require(["dojo/ready"], function(ready){
ready(function(){ func() });
});
// $("body")[0].onload = () => {
// alert("load");
// }
// // $(document).on("load", "body", function () {
// // alert("load");
// // })
}
function getXFormFlagType(flagid) {
const selector = "[id='_xform_extendDataFormInfo.value("+ flagid +")']";
let _xform_type = $(selector).attr("_xform_type");
// 处理明细表相关的flagtype获取
const dotIndex = flagid.indexOf(".");
if (!_xform_type && dotIndex > -1) {// 无法获取到控件类型(可能是明细表控件flagid未渲染完成) && 需要获取明细表控件类型
const tempId = flagid.replace(/\.\d{1,10}\./, ".!{index}.");// 未渲染完成前的id格式:id.!{index}.id
_xform_type = $("[flagid='" + tempId + "']").attr("_xform_type");
}
if (!_xform_type) {// 若仍然获取不到,则此时要么就是id错误,要么就是在上一步获取时id突然又渲染完成了
_xform_type = $(selector).attr("_xform_type");
}
// 转换(保证移动端和pc端拿到的flagtype一致)
// 注意:pc和移动端的_xform_type属性值都有略微差别(移动端没有flagtype属性)
const to_pc_type = {
inputText: "xform_text",// 单行输入
textarea: "xform_textarea",// 多行输入
inputRadio: "xform_radio",// 单选按钮
inputCheckbox: "xform_checkbox",// 多选按钮
select: "xform_select",// 下拉菜单
fSelect: "xform_fSelect",// 复选下拉
datetime: "xform_datetime",// 日期选择
rtf: "xform_rtf",// 富文本
address: "xform_address",// 地址本
new_address: "xform_new_address",// 高级地址本
calculation: "xform_calculate",// 前端值计算
formula_calculation: "formula_calculation",// 公式加载
attachment: "xform_relation_attachment",// 附件上传
docimg: "xform_docimg",// 图片上传
divcontrol: "divcontrol",// div控件
relationSelect: "xform_relation_select",// 动态下拉框
relationRadio: "xform_relation_radio",// 动态单选
relationCheckbox: "xform_relation_checkbox",// 动态多选
relationChoose: "xform_relation_choose",// 选择框
}
return to_pc_type[_xform_type];
}
function getXFormLabel(flagid) {}
function getValueById(flagid) {
// 适配只读状态
const flagtype = getXFormFlagType(flagid);
let rtnValue = null;
if (isEmpty(flagtype)) {
return undefined;
}
const xform = $("[id='_xform_extendDataFormInfo.value("+ flagid +")']")[0];
if ("xform_text".includes(flagtype)) {// 1、【单行输入框】
// 只读、编辑
// 解决取值延迟问题:触发函数中通过GetXFormFieldValueById取到的值为上一个值,并非当前触发值
let value = $(xform).find("input[name='extendDataFormInfo.value("+ flagid +")']").val();
value = value.replace(/\n/g, "");
return value;
}
else if ("xform_textarea".includes(flagtype)) {// 2、【多行输入框】
// 解决取值延迟问题:触发函数中通过GetXFormFieldValueById取到的值为上一个值,并非当前触发值
const textarea = $(xform).find("textarea");
if (textarea.length === 0) {// 只读
let value = $(xform).find($(xform).find("div.muiFormTextareaContent"))[0].innerText.replace(/ /g, " ");
if (value && value.length > 1 && value[value.length - 1] === "\n") {
value = delLastChar(value, 1);
}
return value;
}
return $(xform).find("textarea").val();// 编辑
}
else if ("xform_radio;xform_checkbox;xform_select;xform_fSelect;xform_datetime".includes(flagtype)) {
// 3、【单选按钮】 4、【多选按钮】 5、【下拉菜单】 6、【复选下拉】 7、【日期选择】
// 只读、编辑
return GetXFormFieldValueById(flagid, true)[0];
}
else if ("xform_address;xform_new_address;".includes(flagtype)) {// 9、【地址本、高级地址本】
const obj = GetXFormFieldById(flagid, true)[0];
if (typeof obj !== "undefined") {
return [obj.curIds, obj.curNames];
}
return ["", ""];
}
else if ("xform_calculate".includes(flagtype)) {// 10、【前端值计算】
// 只读、编辑
// 解决取值延迟问题:触发函数中通过GetXFormFieldValueById取到的值为上一个值,并非当前触发值
return $(xform).find("[name='extendDataFormInfo.value("+ flagid +")']").val();
}
else if ("formula_calculation".includes(flagtype)) {// 11、【公式加载】
// 只读、编辑
return GetXFormFieldById("fd_fc_1")[0].value;
}
else if ("xform_relation_select;xform_relation_radio;xform_relation_checkbox".includes(flagtype)) {
// 11、【动态下拉框】 12、【动态单选】 13、【动态多选】
// 只读、编辑
const obj = GetXFormFieldById(flagid, true)[0];
if (typeof obj !== "undefined") {
return [obj.value, obj.text];
}
return ["", ""];
}
else if ("xform_relation_choose".includes(flagtype)) {// 14、【选择框】
const obj = GetXFormFieldById(flagid, true)[0];
if (typeof obj !== "undefined") {
const rtnValue = [obj.value, obj.text];
if (isEmpty(rtnValue[0])) rtnValue[1] = "";// 解决:清空时触发,实际值为空,但显示值不为空
return rtnValue;
}
return ["", ""];
}
else {
return flagtype + "类型控件:在publicMethod.getValueById()中还未适配"
}
}
// 未适配完全:xform_relation_choose选择框、xform_select下拉菜单、xform_address地址本、xform_new_address高级地址本
function setValueById(flagid, value) {
const flagtype = getXFormFlagType(flagid);
if ("divcontrol".includes(flagtype)) {
return;
}
if (isEmpty(value) || "{};[];[\"\"];[\"\",\"\"];[null];[null,null]".includes(JSON.stringify(value))) {
clearField(flagid);
return;
}
/* 拿值 */
if (isEmpty(flagtype)) {// 非flagType控件
return undefined;
}
else if ("xform_text;xform_textarea;xform_radio;xform_checkbox;xform_datetime;xform_calculate".includes(flagtype)) {
// 单行输入框、多行输入框、单选按钮、多选按钮、下拉菜单、日期选择、选择框、前端值计算
SetXFormFieldValueById(flagid, value, true);
}
else if (flagtype === "xform_calculate") {
$("[name='extendDataFormInfo.value("+ flagid +")']").val(value);
}
else if ("xform_address;xform_new_address;".includes(flagtype)) {
console.error(flagtype + ": xform_public_mb.setValueById()中未适配");
}
else if ("xform_select" === flagtype) {
console.error(flagtype + ": xform_public_mb.setValueById()中未适配");
}
else {
console.error(flagtype + ": xform_public_mb.setValueById()中未适配");
}
/* 执行校验 */
exeValidation(flagid);
}
function exeValidation(flagid) {
}
function setValueById_await(flagid, value, await=500, until=5000) {
setTimeout(function () {
setValueById(flagid, value);
const interval = setInterval(() =>{
console.log("setValueById_await");
const afterValue = getValueById(flagid);
if (JSON.stringify(afterValue) === JSON.stringify(value)) clearInterval(interval);
else setValueById(flagid, value);
}, 100);
setTimeout(() =>{
clearInterval(interval);
}, until)
}, await)
}
function formatValue(value, flagtype) {
/* 本应该传入数组形式,但传入了字符串或数字 */
if (typeof value === "string" || typeof value === "number") {
value = value + "";
// 字符串不应以[换行符]结尾
if (value.charAt(value.length - 1) === "\n") {
value = delLastChar(value, 1);
}
if ("xform_relation_radio;xform_relation_select;xform_relation_checkbox;xform_relation_choose".includes(flagtype)) {
value = [value, value];
}
else if ("xform_relation_radio;xform_relation_select;xform_relation_checkbox;xform_relation_choose".includes(flagtype)
&& value.includes("$$$")) {
const arr = value.split("$$$");
value = [arr[0], arr[1]];
}
else if ("xform_address;xform_new_address".includes(flagtype) && value.includes("$$$")) {
const arr = value.split("$$$");
value = [arr[0], arr[1]];
}
else if ("xform_address;xform_new_address".includes(flagtype) && value.includes(":")) {
const arr = value.split("|");
let idStr = "";
let nameStr = "";
for (const str of arr) {
let id = str.split(":")[0];
let name = str.split(":")[1];
if (isNotEmpty(id) && isNotEmpty(name)) {
idStr += id + ";";
nameStr += name + ";";
}
value = [delLastChar(idStr, 1), delLastChar(nameStr, 1)];
}
}
}
/* 地址本,但传入了id和name的对象 */
if (typeof value === "object" && value !== null && value.id && value.name
&& "xform_address;xform_new_address".includes(flagtype)) {
value = [value.id, value.name];
}
return value;
}
function clearField(flagids) {
var idArr = flagids.split(";");
var actionType1 = "xform_text;xform_textarea;xform_checkbox;xform_select";
for (var i = 0; i < idArr.length; i++) {
var flagtype = getXFormFlagType(idArr[i]);
if (flagtype === "") continue;
if (actionType1.indexOf(flagtype) > -1) {
SetXFormFieldValueById(idArr[i], "", true);
} else if ("xform_radio;xform_fSelect;xform_datetime;xform_address;xform_new_address;xform_relation_choose".includes(flagtype)) {
console.error(flagtype + ": xform_public_mb.clearField()中未适配");
} else {
console.error(flagtype + ": xform_public_mb.clearField()中未适配");
}
/* 执行校验 */
exeValidation(idArr[i]);
}
}
function hideField(flagid, hide, isClearField) {
}
function isFieldDisplay(flagid) {
}
function getBaseField(flagid) {
}
function setEditById(flagid, edit) {
}
function isFieldEdit(flagid) {
}
// 未适配:目前可用属性变更来控制移动端的必填或非必填:移动端,只读单行输入框可触发属性变更
function setValidateById(flagid, validate) {
// 红点肯定都在xformflag标签内
// 必填提示肯定都在td内
const xformflagObj = $("xformflag[id='_xform_extendDataFormInfo.value("+ flagid +")']");
const tdObj= xformflagObj.closest("td");
let inputObj = GetXFormFieldById(flagid, true);
}
function isFieldValidate(flagid) {
}
function setDisplayById(flagid, display) {
hideField(flagid, display,false);
}
function setXformflagNowrap(flagid) {}// 无需适配移动端
function setXformTdNowrap(flagTypes) {}// 无需适配移动端
// 未适配
function setAddressScope(flagids, scope) {
for (const flagid of flagids.split(";")) {
const xform_address = $("[flagid='"+ flagid +"']");
// 1、修改弹窗的选择范围
const orgelement = xform_address.find("div.orgelement")[0];
const onclick = $(orgelement).attr("onclick");
// console.log({onclick}); // "Dialog_Address(false,$(this).attr('__id'),$(this).attr('__name'),';',ORG_TYPE_PERSON,function(){__CallXFormAddressOnValueChange(this.fieldList[0],this.fieldList[1],function(value, domElement){__xformDispatch.call(this,value,domElement);$(document).trigger($.Event('relation_event_setvalue'),Address_GetIdByInputField(this));});},null,null,null,null,null,null,null);"
if (isEmpty(onclick)) return;// 只读地址本无法设置选择范围
const onclickArr = onclick.split(",");
onclickArr[onclickArr.length - 1] = "'"+ scope +"');";// 设置Dialog_Address的deptLimit参数
const newOnclick = onclickArr.join(",");
orgelement.setAttribute("onclick", newOnclick);
// 2、修改输入提示范围
const scriptArr = xform_address.find("script");
for (const script of scriptArr) {
let str = $(script).html();
str = str.replace(/,\[{"id":".{0,100}"}],/, ",null,");// 去除默认值(避免重复赋值给地址本)
if (str.includes("Address_QuickSelection")) {
const strArr = str.split(",");
strArr[strArr.length - 2] = "'"+ scope +"'";
const afterCode = strArr.join(",");
eval(afterCode);
// console.log(afterCode)
break;
}
}
}
}
function getCheckedCount(flagid) {
const flagtype = getXFormFlagType(flagid);
if (flagtype === "xform_checkbox") {
const checkValue = getValueById(flagid);
return isEmpty(checkValue) ? 0 : checkValue.split(";").length;
}
return flagtype + " : xform_public_mb.getCheckedCount未适配";
}
function getAttInfoList(attachmentId) {
// 待开发
}
function getAttIds(attachmentId) {
// 待开发
}
function getAttNames(attachmentId) {
// 待开发
}
function clearBtwFields(oneFlagid, oneValue, multiFlagids) {
AttachChangeEventById(oneFlagid, (a,b) => {
let changeValue = ChangeEventValue(a,b);
if (JSON.stringify(changeValue) === JSON.stringify(oneValue)) {
clearField(multiFlagids);
}
})
}
function hideSimpleMainBottomFrame() {}