Bläddra i källkod

流程表单密码组件

ouyj 5 månader sedan
förälder
incheckning
33e0cf2178

+ 3 - 0
src/main/bpm/com/yw/bpm/instance/service/FormInstanceServiceImpl.java

@@ -3870,6 +3870,9 @@ public class FormInstanceServiceImpl implements FormInstanceService {
                     canEdit = canEdit + "gsjs";
                 }
             }
+            if (("info".equals(type) || "print".equals(type) || "preview".equals(type)) && "25".equals(elementType)) {
+                    canEdit = canEdit + "passNoCopy";
+            }
             resultList.add(PluginUtil.initPlugin("form", node, element, canEdit, defaultValue, type, source, oasession));
             /*
              * //必填提示 if("1".equals(noNull)){ TextNode text = new

+ 127 - 0
src/main/bpm/com/yw/bpm/plugin/entity/PluginFormPassword.java

@@ -0,0 +1,127 @@
+package com.yw.bpm.plugin.entity;
+
+import com.yw.bpm.form.model.FormElement;
+import com.yw.bpm.plugin.service.PluginTemplate;
+import com.yw.core.session.IAppSession;
+import org.htmlparser.Node;
+import org.htmlparser.lexer.Lexer;
+import org.htmlparser.nodes.TextNode;
+import org.htmlparser.scanners.CompositeTagScanner;
+import org.htmlparser.tags.InputTag;
+import org.htmlparser.tags.LabelTag;
+import org.htmlparser.tags.Span;
+import org.htmlparser.util.NodeList;
+
+public class PluginFormPassword extends PluginTemplate {
+
+	@Override
+	public NodeList getNodeList(Node node, FormElement formElement,
+			String operateType, String defaultValue, String pluginId,IAppSession oasession) throws Exception {
+		CompositeTagScanner scanner = new CompositeTagScanner();
+		Lexer lexer = new Lexer();
+		NodeList result = new NodeList();
+		Boolean passNoCopy = false;
+		if(operateType.endsWith("passNoCopy")){
+			operateType = "2";
+			passNoCopy = true;
+		} 
+		if (node instanceof Span) {
+			Span span = (Span) node;
+
+			if ("0".equals(operateType)) {
+				//密码不可见,展示密码形式的数据,类似星号,但是旁边有复制按钮,点击按钮可以复制真正的值
+				InputTag inputTag = new InputTag();
+				inputTag.setAttribute("id", formElement.getTableField());
+				inputTag.setAttribute("value",
+						("" + defaultValue + "").replaceAll(" ", " "));
+				inputTag.setAttribute("name", formElement.getTableField());
+				inputTag.setAttribute("type", "hidden");
+				inputTag.setAttribute("readonly", "true");
+				
+				LabelTag label = new LabelTag();
+				label.setAttribute("id", formElement.getTableField());
+				label.setAttribute("style", 
+						"width:90%;float: left;text-align: left;overflow:auto;padding:10px 10px;");
+				if ("\"\"".equals(defaultValue)) {
+					defaultValue = defaultValue.replace("\"", "");
+				}
+				// 将密码内容替换为星号显示
+				String displayValue = defaultValue.replaceAll(".", "*");
+				TextNode text = new TextNode(displayValue);
+				NodeList list = new NodeList();
+				list.add(text);
+				label.setChildren(list);
+				scanner.scan(label, lexer, list);
+				result.add(label);
+				
+				// 添加复制按钮
+				InputTag btnInputTag = new InputTag();
+				btnInputTag.setAttribute("id", formElement.getTableField() + "_copy_btn");
+				btnInputTag.setAttribute("name", formElement.getTableField() + "_copy_btn");
+				btnInputTag.setAttribute("type", "button");
+				btnInputTag.setAttribute("style", "width:50px;float: left;");
+				btnInputTag.setAttribute("value", "复制");
+				btnInputTag.setAttribute("onclick", "copyPasswordValue_" + formElement.getTableField() + "();");
+				result.add(btnInputTag);
+				
+				result.add(inputTag);
+				
+				// 添加复制功能的JavaScript
+				org.htmlparser.tags.ScriptTag javascript = new org.htmlparser.tags.ScriptTag();
+				javascript.setScriptCode("function copyPasswordValue_" + formElement.getTableField() + "() {\n" +
+				        "    var passwordValue = '" + defaultValue + "';\n" +
+				        "    if (navigator.clipboard && window.isSecureContext) {\n" +
+				        "        navigator.clipboard.writeText(passwordValue).then(function() {\n" +
+				        "            alert('复制成功');\n" +
+				        "        }).catch(function(err) {\n" +
+				        "            console.error('复制失败: ', err);\n" +
+				        "        });\n" +
+				        "    } else {\n" +
+				        "        var textArea = document.createElement('textarea');\n" +
+				        "        textArea.value = passwordValue;\n" +
+				        "        textArea.style.position = 'absolute';\n" +
+				        "        textArea.style.left = '-999999px';\n" +
+				        "        document.body.appendChild(textArea);\n" +
+				        "        textArea.select();\n" +
+				        "        document.execCommand('copy');\n" +
+				        "        document.body.removeChild(textArea);\n" +
+				        "        alert('复制成功');\n" +
+				        "    }\n" +
+				        "}");
+				scanner.scan(javascript, lexer, new NodeList());
+				result.add(javascript);
+			} else if ("2".equals(operateType)) { //不可复制
+				// 密码不可见,只展示密码形式的数据,类似星号
+				LabelTag label = new LabelTag();
+				label.setAttribute("id", formElement.getTableField());
+				label.setAttribute("style", 
+						"width:100%;float: left;text-align: left;overflow:auto;padding:10px 10px;");
+				if ("\"\"".equals(defaultValue)) {
+					defaultValue = defaultValue.replace("\"", "");
+				}
+				// 将密码内容替换为星号显示
+				String displayValue = defaultValue.replaceAll(".", "*");
+				TextNode text = new TextNode(displayValue);
+				NodeList list = new NodeList();
+				list.add(text);
+				label.setChildren(list);
+				scanner.scan(label, lexer, list);
+				result.add(label); 
+			} else {
+				// 密码输入框文本框
+				InputTag inputTag = new InputTag();
+				inputTag.setAttribute("id", formElement.getTableField());
+				// 在编辑模式下,仍保留实际密码值
+				inputTag.setAttribute("value", "" + defaultValue + "");
+				inputTag.setAttribute("name", formElement.getTableField());
+				inputTag.setAttribute("type", "password");
+
+				inputTag.setAttribute("style", span.getAttribute("style").replaceAll("100%", "91%")
+						+ ";float: left;background-color:#F0FFF0;");
+				result.add(inputTag);
+			}
+		}
+
+		return result;
+	}
+}

+ 14 - 0
src/main/bpm/com/yw/bpm/plugin/entity/plugin_formpassword.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<config>
+	<plugin>
+		<id>101018</id>
+		<name>form password</name>
+		<classname>com.yw.bpm.plugin.entity.PluginFormPassword</classname>
+		<javascript></javascript>
+		<type>form</type>
+		<level>0</level>
+		<sql></sql>
+		<elementtype>25</elementtype>
+		<valuetrans>1</valuetrans>
+	</plugin>
+</config>

+ 1 - 0
src/main/bpm/com/yw/bpm/plugin/plugin.xml

@@ -43,6 +43,7 @@
 		<other>/com/yw/bpm/plugin/entity/plugin_formrecord.xml</other>
 		<other>/com/yw/bpm/plugin/entity/plugin_contractSelect.xml</other>
 		<other>/com/yw/bpm/plugin/entity/plugin_formprojectSelect.xml</other>
+		<other>/com/yw/bpm/plugin/entity/plugin_formpassword.xml</other>
 <!-- 		<other>/com/yw/bpm/plugin/entity/plugin_formcustomselect1.xml</other> -->
 <!-- 		<other>/com/yw/bpm/plugin/entity/plugin_formcustomselect2.xml</other> -->
 	</system>

+ 2 - 0
src/main/bpm/com/yw/bpm/plugin/util/PluginUtil.java

@@ -140,6 +140,8 @@ public class PluginUtil {
 			} else if ("1".equals(elementType)) {
 				operateType = operateType.replaceFirst("0", "3");
 				nodeList.add(PluginUtil.getPlugin(pluginType, "101002", node, formElement, operateType, defaultValue, oasession));
+			} else if ("25".equals(elementType)) {
+				nodeList.add(PluginUtil.getPlugin(pluginType, "101018", node, formElement, operateType, defaultValue, oasession));
 			} else {
 				TextNode text = new TextNode(defaultValue);
 				nodeList.add(text);