自定义卡片展示待办列表开发案例

一、业务场景
本文介绍如何使用自定义卡片实现将待办任务以列表形式展现在首页。
二、实现步骤
1. 新建表单 custom_card_list (自定义命名)
路径:应用 -> 开发服务云 -> 开发平台 -> 【选择一个业务云】-> 创建页面 -> 卡片
2. 用苍穹平台画出自己的卡片页面

3. 根据自己的业务写一个插件,这里给出一个展示任务列表数据的插件示例,示例如下:



4. 在门户首页添加自定义卡片,完成,如下图:
步骤:点击调整首页布局(右上角)- 添加卡片(正下方)- 选择自定义卡片 – 填写卡片名称和选择自己刚刚新建的卡片表单

三、完整示例代码
import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.AppInfo;
import kd.bos.entity.AppMetadataCache;
import kd.bos.entity.datamodel.AbstractFormDataModel;
import kd.bos.entity.datamodel.TableValueSetter;
import kd.bos.form.ClientActions;
import kd.bos.form.IClientViewProxy;
import kd.bos.form.cardentry.CardEntry;
import kd.bos.form.control.Control;
import kd.bos.form.control.EntryGrid;
import kd.bos.form.control.Label;
import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.control.events.RowClickEvent;
import kd.bos.form.control.events.RowClickEventListener;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.util.CollectionUtils;
import kd.bos.portal.util.DateUtils;
import kd.bos.portal.util.MyCurrentAppUtil;
import kd.bos.portal.util.OpenPageUtils;
import kd.bos.servicehelper.workflow.MessageCenterServiceHelper;
import java.util.Date;
import java.util.EventObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CustomCardListPlugin extends AbstractFormPlugin implements RowClickEventListener {
private static Log logger = LogFactory.getLog(CustomCardListPlugin.class);
private static final int DEFAULT_COUNT = 100;
/**
* 任务中心页面元数据标识
*/
private static final String WF_TASKCENTERHOME = "wf_msg_center";
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
EntryGrid entryentity = getControl("entry_entity");
if (entryentity != null) {
entryentity.addRowClickListener(this);
}
// 通知:更多
Label notifymore = this.getControl("notifymore");
if (notifymore != null) {
notifymore.addClickListener(this);
}
}
@Override
public void afterCreateNewData(EventObject e) {
super.afterCreateNewData(e);
showNotification();
}
@Override
public void itemClick(ItemClickEvent evt) {
String opKey = evt.getOperationKey();
switch (opKey) {
case "notifymore":
showTaskForm(0, 1);
break;
default:
break;
}
}
@Override
public void click(EventObject evt) {
super.click(evt);
if (evt.getSource() instanceof Control) {
Control c = (Control) evt.getSource();
String key = c.getKey();
switch (key) {
case "notifymore":
showTaskForm(0, 1);
break;
default:
break;
}
}
}
/**
* @method showNotification
* @description 显示通知内容
*/
private void showNotification() {
// 设置通知内容
long userId = RequestContext.get().getCurrUserId();
List<Map<String, Object>> notifyList = MessageCenterServiceHelper.getToHandleTasksMessage(userId, DEFAULT_COUNT);
this.getModel().deleteEntryData("entry_entity");
if (!CollectionUtils.isEmpty(notifyList)) {
AbstractFormDataModel model = (AbstractFormDataModel) this.getModel();
model.beginInit();
//表值设置器
TableValueSetter vs = new TableValueSetter();
vs.addField("taskid");
vs.addField("card_title");
vs.addField("card_date");
int count = 0;
for (Map<String, Object> notifyMap : notifyList) {
if (count > 5) {
break;
}
Date notify
自定义卡片展示待办列表开发案例
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。



