|
|
@@ -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;
|
|
|
+ }
|
|
|
+}
|