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

栏目:云苍穹知识作者:金蝶来源:金蝶云社区发布:2024-09-23浏览:1

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

一、业务场景

本文介绍如何使用自定义卡片实现将待办任务以列表形式展现在首页。


二、实现步骤

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 notifydate = (Date) notifyMap.get("time");

                vs.addRow(notifyMap.get("id"), notifyMap.get("title"), DateUtils.formatDate(notifydate, "yyyy-MM-dd"));

                count++;

            }

            model.batchCreateNewEntryRow("entry_entity", vs);

            model.endInit();

        }

        this.getView().updateView("entry_entity");

    }

 

    @Override

    public void entryRowClick(RowClickEvent evt) {

        CardEntry cardEntry = (CardEntry) evt.getSource();

        if ("entry_entity".equals(cardEntry.getEntryKey())) {

            DynamicObject taskObj = this.getModel().getEntryRowEntity("entry_entity", evt.getRow());

            long taskId = 0;

            if (taskObj != null) {

                taskId = taskObj.getLong("taskid");

            }

            showTaskForm(taskId,1);

        }

    }

 

 

 

 

 

    public void showTaskForm(long id, int personCenterOpenType) {

        this.closeTaskAndMsg();

        if (this.getView().getMainView() == null) {

            // 无上级页面时,直接打开浏览器新窗口

            this.getView().openUrl("#/dform?formId=" + WF_TASKCENTERHOME);

            return;

        }

        // 个人信息界面收起

        IClientViewProxy proxy = this.getView().getService(IClientViewProxy.class);

        Map<String, Object> paramMap = new HashMap<>();

        paramMap.put("close", Boolean.TRUE);

        proxy.addAction(ClientActions.showSlideBill, paramMap);

 

        Map<String, Object> map = new HashMap<>();

        map.put("view", this.getView());

        map.put("appmainnumber", WF_TASKCENTERHOME);

        map.put("appname", AppMetadataCache.getAppInfo("wftask").getName());

        // 任务ID

        Map<String, Object> customparameters = new HashMap<>(2);

        customparameters.put("tabType", personCenterOpenType);

        customparameters.put("messageId", id);

        map.put("customparameters", customparameters);

        // OpenPageUtils.openAppTab(appObj.getString("id"), null, map,

        // this.getView());

        OpenPageUtils.openApp("wftask", null, map, this.getView());

        AppInfo appInfo = AppMetadataCache.getAppInfo("wftask");

        if(appInfo != null){

            String appId = appInfo.getId();

            MyCurrentAppUtil.putMyCurrentAppCache(appId);

        }

    }

 

    /**

     * 关闭个人中心面板

     */

    private void closeTaskAndMsg(){

        IClientViewProxy proxy = this.getView().getService(IClientViewProxy.class);

 

        Map<String, Object> o1 = new HashMap<>(1);

        o1.put("formId", "bos_portal_taskandmsg");

        o1.put("show", Boolean.FALSE);

        proxy.addAction(ClientActions.showSlideBill, o1);

    }

 

}


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

一、业务场景本文介绍如何使用自定义卡片实现将待办任务以列表形式展现在首页。二、实现步骤1. 新建表单 custom_card_list (自定义命...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息