如何实现自定义的确认提示框原创
金蝶云社区-已离职
已离职
51人赞赏了该文章 15783次浏览 未经作者许可,禁止转载编辑于2022年08月05日 15:49:51

关键词:消息确认提示


一、需求

1. 自定义消息确认提示框:表单内显示信息(悬浮框), 可设置消息头, 消息体, 消息类型, 以及确认监听。

2. 自定义消息确认提示框:表单内显示信息(悬浮框), 支持内容设置超链接, 可设置消息头, 消息类型, 以及确认监听。


二、思路与方案

在 kd.bos.form.AbstractFormView 提供多个 showConfirm 方法。


三、实现过程

1. 自定义消息确认提示框:表单内显示信息(悬浮框), 可设置消息头, 消息体, 消息类型, 以及确认监听。

注意:

按钮名称参数Map的key值必须和 options 参数相对应, 否则按钮名称修改不生效!

	/**
	 * 自定义消息确认提示框:表单内显示信息(悬浮框), 可设置消息头, 消息体, 消息类型, 以及确认监听
	 */
	private void showCustomConfirm1() {
		// 基本信息
		// 备注: \r\n 可换行
		String msg = "消息头\r\n message header...";
		// 详细消息
		String detail = "消息体\r\nmessage body...";
		// 消息框按钮类型
		// None:不启用  Toast:简短提示,几秒后消失
		MessageBoxOptions options = MessageBoxOptions.AbortRetryIgnore;
		// 确认提示类型
		// Default:默认提示  Save:保存提交类提示  Delete:删除类提示  Wait:等待类提示  Fail:失败类提示
		ConfirmTypes confirmTypes = ConfirmTypes.Default;
		// 确认框回调
		ConfirmCallBackListener callBack = new ConfirmCallBackListener(CALLBACKID_DEMO1, this);
		// 按钮名称
		// 注意: 按钮名称参数Map的key值必须和 options 参数相对应, 否则按钮名称修改不生效!
		// 例: options 使用 MessageBoxOptions.OKCancel, 则 按钮名称参数Map的key必须为2 or 6
		//    options 使用 MessageBoxOptions.AbortRetryIgnore, 则 按钮名称参数Map的key必须为3 or 4 or 5
		// none-0; ok-1; cancel-2; abort-3; retry-4; ignore-5; yes-6; no-7; custom-8
		// -----------------------------------------------------------------
		//             options                   |    btnNameMaps的key的取值 
		//   MessageBoxOptions.None              |           2
		//   MessageBoxOptions.OK                |           2
		//   MessageBoxOptions.OKCancel          |         2 & 6
		//   MessageBoxOptions.AbortRetryIgnore  |       3 & 4 & 5
		//   MessageBoxOptions.YesNoCancel       |       6 & 7 & 2
		//   MessageBoxOptions.YesNo             |         6 & 7
		//   MessageBoxOptions.RetryCancel       |         4 & 2
		//   MessageBoxOptions.Toast             |           2
		// -----------------------------------------------------------------
		Map<Integer, String> btnNameMaps = new HashMap<Integer, String>();
		btnNameMaps.put(3, "按钮名称3");
		btnNameMaps.put(4, "按钮名称4");
		btnNameMaps.put(5, "按钮名称5");
		// 用户自定义参数,前端会在afterConfirm中返回
		String customValue = "paramStr";
		this.getView().showConfirm(msg, detail, options, confirmTypes, callBack, btnNameMaps, customValue);
	}


2. 自定义消息确认提示框:表单内显示信息(悬浮框), 支持内容设置超链接, 可设置消息头, 消息类型, 以及确认监听。

	/**
	 * 自定义消息确认提示框:表单内显示信息(悬浮框), 支持内容设置超链接, 可设置消息头, 消息类型, 以及确认监听
	 */
	private void showCustomConfirm2() {
		// 消息模板#{x}为超链接占位符,格式如“保存成功,#{0},单据详情,#{1}”
		String tempMsg = "保存成功: #{0} & 单据详情: #{1}";
		// 模板占位符替换对象
		List<MessageBoxLink> msglinks = new ArrayList<MessageBoxLink>();
		MessageBoxLink messageBoxLink1 = new MessageBoxLink();
		// 索引,对应占位符编号
//		messageBoxLink1.setIndex(0);
		// 超链接显示文本
		messageBoxLink1.setText("首页");
		// 改超链接回调标识(内部跳转需要设置)
//		messageBoxLink1.setValue("mainpage");
		// 超链接url
		// 备注: 如果是跳转外部链接需要设置改URL, 需以http/https为开头全地址
		messageBoxLink1.setUrl("?formId=pc_main_console");
		msglinks.add(messageBoxLink1);
		
		MessageBoxLink messageBoxLink2 = new MessageBoxLink();
//		messageBoxLink2.setIndex(1);
		messageBoxLink2.setText("百度");
//		messageBoxLink2.setValue("baidu");
		messageBoxLink2.setUrl("https://www.baidu.com");
		msglinks.add(messageBoxLink2);
		// 消息框按钮类型
		MessageBoxOptions options = MessageBoxOptions.OKCancel;
		// 确认提示类型
		ConfirmTypes confirmTypes = ConfirmTypes.Default;
		// 确认框回调
		ConfirmCallBackListener callBack = new ConfirmCallBackListener(CALLBACKID_DEMO2, this);
		// 按钮名称
		Map<Integer, String> btnNameMaps = new HashMap<Integer, String>();
		btnNameMaps.put(2, "按钮名称2");
		btnNameMaps.put(6, "按钮名称6");
		this.getView().showConfirm(tempMsg, msglinks, options, confirmTypes, callBack, btnNameMaps);
	}


3. 消息回调处理。

	/**
	 * 消息确认回调
	 */
	@Override
	public void confirmCallBack(MessageBoxClosedEvent evt) {
		// 回调ID
		String callBackId = evt.getCallBackId();
		// 消息选择结果
		MessageBoxResult messageboxResult = evt.getResult();
		int resultInt = messageboxResult.getValue();
		String resultVal = evt.getResultValue();
		// 提示消息内容
		StringBuffer tipsBuffer = new StringBuffer("结果: ");
		tipsBuffer.append(resultVal).append("(").append(resultInt).append(")").append(", 消息确认回调ID: ").append(callBackId);
		if (StringUtils.equalsIgnoreCase(CALLBACKID_DEMO1, callBackId)) {
			String customValue = evt.getCustomVaule();
			tipsBuffer.append(" , 消息确认提示框传入的参数: ").append(customValue);
		}
		String tips = tipsBuffer.toString();
		logger.info(tips);
		getView().showTipNotification(tips);
		super.confirmCallBack(evt);
	}


四、效果图

自定义消息确认提示框:表单内显示信息(悬浮框), 可设置消息头, 消息体, 消息类型, 以及确认监听

方式一.jpg

点击消息提示框按钮后的回调效果

自定义确认消息提示-效果图-1.2.png


2. 自定义消息确认提示框:表单内显示信息(悬浮框), 支持内容设置超链接, 可设置消息头, 消息类型, 以及确认监听

image.png

点击消息提示框按钮后的回调效果

自定义确认消息提示-效果图-2.2.png


五、开发环境版本

不限


六、参考资料

开发平台

学习成长中心

弹出提示的多种实现方式

提示消息提示框



赞 51