这个功能是基于泛微8.0平台,以js文件引用,调用后端jsp动态获取表单字段id。可供建模台账前端js代码动态获取字段id,有利于前端代码直接上线,减少测试系统和正式系统字段id不一致导致的工作量。
<script type='text/javascript' src='/interface/jslabel/jsModeinfo.js'></script>
<script type="text/javascript">
var isNotFunRuning = false; //不让触发事件
var userAgent = navigator.userAgent; //当前浏览器类型
var mainMap = getLabelMap();
var dtMap1 = getDetailLabelMap("1");
var order_typefield = mainMap.get("day_id"); // 日期ID
var order_idfield= mainMap.get("order_id"); // 订单号
jQuery(document).ready(function() {
alert("打印动态获取的字段id值:"+order_typefield);
});
</script>
/**
*
*/
Array.prototype.remove = function(s) {
for (var i = 0; i < this.length; i++) {
if (s == this[i])
this.splice(i, 1);
}
}
function Map() {
/** 存放键的数组(遍历用到) */
this.keys = new Array();
/** 存放数据 */
this.data = new Object();
/**
* 放入一个键值对
*
* @param {String}
* key
* @param {Object}
* value
*/
this.put = function(key, value) {
if (this.data[key] == null) {
this.keys.push(key);
}
this.data[key] = value;
};
/**
* 获取某键对应的值
*
* @param {String}
* key
* @return {Object} value
*/
this.get = function(key) {
return this.data[key];
};
/**
* 删除一个键值对
*
* @param {String}
* key
*/
this.remove = function(key) {
this.keys.remove(key);
this.data[key] = null;
};
this.clear = function() {
var len = this.keys.length;
for (var i = 0; i < len; i++) {
var k = this.keys[i];
this.keys.remove(k);
this.data[k] = null;
}
}
/**
* 遍历Map,执行处理函数
*
* @param {Function}
* 回调函数 function(key,value,index){..}
*/
this.each = function(fn) {
if (typeof fn != 'function') {
return;
}
var len = this.keys.length;
for (var i = 0; i < len; i++) {
var k = this.keys[i];
fn(k, this.data[k], i);
}
};
/**
* 获取键值数组(类似Java的entrySet())
*
* @return 键值对象{key,value}的数组
*/
this.entrys = function() {
var len = this.keys.length;
var entrys = new Array(len);
for (var i = 0; i < len; i++) {
entrys[i] = {
key : this.keys[i],
value : this.data[i]
};
}
return entrys;
};
/**
* 判断Map是否为空
*/
this.isEmpty = function() {
return this.keys.length == 0;
};
/**
* 获取键值对数量
*/
this.size = function() {
return this.keys.length;
};
/**
* 重写toString
*/
this.toString = function() {
var s = "{";
for (var i = 0; i < this.keys.length; i++, s += ',') {
var k = this.keys[i];
s += k + "=" + this.data[k];
}
s += "}";
return s;
};
}
/**
* 获取url参数值
*
* @param name
* @returns
*/
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null)
return unescape(r[2]);
return null;
}
function GetRequest() {
var url = location.search; // 获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
/**
* 获取建模表单字段id
* 20210624
* @returns {Map}
*/
function getLabelMap() {
return getDetailLabelMap(0);
}
function getMainLabelMap() {
return getDetailLabelMap(0);
}
function getDetailLabelMap(num) {
var mapTemp = new Map();
var workflowid = getQueryString('workflowid');
var modeId = getQueryString('modeId');
var formId = getQueryString('formId');
jQuery.ajaxSetup({
async : false
});
jQuery.get("/interface/jslabel/getjsModeinfo.jsp?modeId=" + modeId
+ "&formId=" + formId + "&num=" + num, function(data,
textStatus, req) {
var objTemp = jQuery.parseJSON(data);
for ( var kTemp in objTemp) {
mapTemp.put(kTemp, 'field' + objTemp[kTemp]);
}
});
return mapTemp;
}
<%@page import="weaver.hrm.User"%>
<%@page import="weaver.hrm.HrmUserVarify"%>
<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@page import="weaver.general.Util"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="weaver.conn.RecordSet"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%!
RecordSet rs = new RecordSet();
RecordSet rs1 = new RecordSet();
public Map<String,String> getLabelMap(int formid,String num){
Map<String,String> array = new HashMap<String,String>();
formid = Math.abs(formid);
String sql = "select tablename from workflow_bill where id = '-"+formid+"' ";
rs1.execute(sql);
rs1.next();
String tablename = Util.null2String(rs1.getString("tablename"));
sql = "select b.id,fieldname,detailtable from workflow_billfield b ,modeinfo a where b.billid=-"
+ formid + " and a.formid=b.billid";
if ("0".equals(num) || "".equals(num)) {
sql = "select b.id,fieldname,detailtable from workflow_billfield b ,modeinfo a where b.billid=-"
+ formid + " and a.formid=b.billid and (detailtable='' or detailtable is null)";
} else {
sql = "select b.id,fieldname,detailtable from workflow_billfield b ,modeinfo a where b.billid=-"
+ formid
+ " and a.formid=b.billid and detailtable='"+tablename
+ "_dt" + num + "'";
}
rs.execute(sql);
while (rs.next()) {
array.put(
Util.null2String(rs.getString("fieldname")).toLowerCase(),
Util.null2String(rs.getString("id")));
}
return array;
}
public int getFormid(String workflowid,String requestid){
int formid = 0;
Map<String,String> array = new HashMap<String,String>();
if(!"".equals(workflowid) && !"null".equals(workflowid)){
rs.executeSql("SELECT FORMID FROM WORKFLOW_BASE WHERE ID='"+workflowid+"'");
if(rs.next()){
formid = -Util.getIntValue(rs.getString("FORMID"));
}
}else{
if(!"".equals(requestid) && !"null".equals(requestid)){
rs.executeSql("SELECT FORMID FROM WORKFLOW_BASE WHERE ID=(SELECT WORKFLOWID FROM WORKFLOW_REQUESTBASE WHERE REQUESTID='"+requestid+"')");
if(rs.next()){
formid = -Util.getIntValue(rs.getString("FORMID"));
}
}
}
return formid;
}
public String getNodeId(String workflowid,String requestid,int userid){
String nodeid = "";
String sql = "select nodeid from workflow_flownode a,workflow_nodebase b where a.nodeid=b.id and b.isstart=1 and a.workflowid='"+workflowid+"'";
if(!"".equals(requestid)){
sql = "select nodeid from workflow_currentoperator where requestid='"+requestid+"' and userid='"+userid+"'";
}
rs.executeSql(sql);
if(rs.next()){
nodeid = Util.null2String(rs.getString("nodeid"));
}
return nodeid;
}
public Map<String,String> getFieldType(int formid){
Map<String,String> array = new HashMap<String,String>();
formid = Math.abs(formid);
String sql = "select fieldhtmltype,fieldname,type from workflow_billfield where billid=-"
+ formid;
rs.execute(sql);
while (rs.next()) {
//单据字段页面类型 : 1:单行文本框 、2:多行文本框、3:浏览按钮、4:Check框、5:选择框、6:附件上传
String fieldhtmltype = Util.null2String(rs.getString("fieldhtmltype"));
String fieldname = Util.null2String(rs.getString("fieldname")).toLowerCase();
String type = Util.null2String(rs.getString("type"));
}
return array;
}
public Map<String,String> getViewType(String nodeid){
String sql = "select a.*,b.fieldname as fieldname from workflow_nodeform a,workflow_billfield b where a.fieldid=b.id and a.nodeid='"+nodeid+"'";
Map<String,String> array = new HashMap<String,String>();
rs.executeSql(sql);
while(rs.next()){
String isview = Util.null2String(rs.getString("isview"));// 可见(当前节点是否显示出来)
String isedit = Util.null2String(rs.getString("isedit"));// 编辑
String ismandatory = Util.null2String(rs.getString("ismandatory")); // 必填
String fieldname = Util.null2String(rs.getString("fieldname")).toLowerCase();
String type = "";
if("1".equals(ismandatory)){
type = "bt"; //必填
}else{
if("1".equals(isedit)){
type = "bj"; //编辑
}else{
if("1".equals(isview)){
type = "zd"; //只读
}
}
}
if(!"".equals(type)) array.put(fieldname, type);
}
return array;
}
%>
<%
/*
* 获取建模表单字段id
* 20210624
*/
String num = Util.null2String(request.getParameter("num"));
String workflowid = Util.null2String(request.getParameter("workflowid"));
String requestid = Util.null2String(request.getParameter("requestid"));
int formid = Util.getIntValue(request.getParameter("formId"),0); // 表单id
int modeid = Util.getIntValue(request.getParameter("modeId"),0); // 模块id
String nodeid = Util.null2String(request.getParameter("nodeid"));
String getOpe = Util.null2String(request.getParameter("get_ope")); //选择获取的数据
Map<String,String> array = new HashMap<String,String>();
array = getLabelMap(formid,num);
out.clear();
out.print(JSONObject.toJSONString(array));
%>
----------根据workflowid查询表单字段及显示名-------------------
select t.fieldname n ,t.id ,h.labelname h, t.fielddbtype d,
(case when t.detailtable is null then 'main' else substr(t.detailtable,length(t.detailtable)-2,3) end ) tab
from workflow_billfield t,workflow_base w,HtmlLabelInfo h
where w.formid = t.billid and t.fieldlabel = h.indexid and h.languageid = 7
and w.id = 5868
order by tab,t.id
--------查询下拉框的值对应的显示名--------------------------------
select a.selectname from WORKFLOW_SELECTITEM a LEFT JOIN WORKFLOW_BILLFIELD b on b.id=a.fieldid ,WORKFLOW_BASE c
where b.billid=c.formid and b.fieldhtmltype=5 and b.fieldname='"+code+"' and a.selectvalue='"+value+"' and c.id='"+workflowId+"'";
----------根据workflowid查询表单字段及显示名-------------------
select a.id wokflowid , 'field'||b.id fieldid , b.fieldname , c.labelname , d.indexdesc , a.workflowname
from workflow_base a,workflow_billfield b,htmllabelinfo c,htmllabelindex d
where a.formid=b.billid and b.fieldlabel=c.indexid and b.fieldlabel=d.id and c.languageid=7
and c.labelname <> d.indexdesc
--and a.id=2702
order by a.id,b.id
----------根据requestId查询表单名称-------------------
select tablename from workflow_bill t1,workflow_base t2, workflow_requestbase t3 where t1.id=t2.formid and t2.id=t3.workflowid and t3.requestid=187048