# 历史记录保存

利用localStorage来保存用户的选项

```javascript
function initPopOverData(key) {
    var result = localStorage.getItem(key);
    try {
        result = JSON.parse(result);
    } catch(e) {}
    return result;
}

if (!RCRE.filter.hasFilter('initPopOverData')) {
    RCRE.filter.setFilter('initPopOverData', initPopOverData);   
}
```

```json
{
    "body": [{
        "type": "container",
        "model": "history",
        "children": [
            {
                "type":"popover",
                "title":"定制报表",
                "triggerType":"click",
                "name":"showFilter",
                "content": {
                    "type": "container",
                    "model": "popContainer",
                    "data": {
                        "diyProductLine": "#ES{initPopOverData('diyProductLine')}",
                        "tmpDiyProductLine": "#ES{initPopOverData('diyProductLine')}"
                    },
                    "dataCustomer": {
                        "customers": [
                            {
                                "mode": "localStorage", 
                                "name": "setLocalStorage", 
                                "config": {
                                    "groups": "#ES{$trigger.setLocalStorage.groups}"
                                }
                            },
                            {
                                "mode": "pass",
                                "name": "hidePopover",
                                "config": {
                                    "model": "history",
                                    "assign": "#ES{$trigger.hidePopover}"
                                }
                            }
                        ]
                    },
                    "children": [
                        {
                            "type": "row", 
                            "flexDirection": "column", 
                            "className": "diyReportFilter", 
                            "style": {
                                "width": "650px"
                            }, 
                            "children": [
                                {
                                    "type": "row", 
                                    "children": [
                                        {
                                            "type": "text", 
                                            "text": "产品线:", 
                                            "gridWidth": "100px", 
                                            "style": {
                                                "fontSize": "12px", 
                                                "marginTop": "-12px"
                                            }
                                        }, 
                                        {
                                            "type": "checkbox", 
                                            "name": "diyProductLine", 
                                            "groups": [
                                                {
                                                    "key": "baidu", 
                                                    "text": "百度APP"
                                                }, 
                                                {
                                                    "key": "baiduWise", 
                                                    "text": "百度WISE"
                                                }, 
                                                {
                                                    "key": "tieba", 
                                                    "text": "百度贴吧"
                                                }, 
                                                {
                                                    "key": "baiduHaokan", 
                                                    "text": "百度好看"
                                                }, 
                                                {
                                                    "key": "baiduExpoler", 
                                                    "text": "百度浏览器"
                                                }, 
                                                {
                                                    "key": "baiduNew", 
                                                    "text": "百度新闻"
                                                }, 
                                                {
                                                    "key": "huiChuanRead", 
                                                    "text": "汇川阅读"
                                                }, 
                                                {
                                                    "key": "huiChuanMiddle", 
                                                    "text": "汇川中间页"
                                                }
                                            ], 
                                            "groupSelectAll": true, 
                                            "style": {
                                                "marginBottom": "20px", 
                                                "fontSize": "12px", 
                                                "marginTop": "10px"
                                            }
                                        }
                                    ], 
                                    "style": {
                                        "marginTop": "15px"
                                    }
                                },
                                {
                                    "type": "row",
                                    "children": [
                                        {
                                            "type": "button", 
                                            "text": "确认", 
                                            "buttonType": "primary", 
                                            "gridWidth": "80px", 
                                            "trigger": [
                                                {
                                                    "event": "onClick", 
                                                    "targetCustomer": "hidePopover", 
                                                    "params": {
                                                        "showFilter": false
                                                    }
                                                }, 
                                                {
                                                    "event": "onClick", 
                                                    "targetCustomer": "setLocalStorage", 
                                                    "params": {
                                                        "groups": [
                                                            {
                                                                "key": "diyProductLine", 
                                                                "value": "#ES{$data.diyProductLine}"
                                                            }
                                                        ]
                                                    }
                                                },
                                                {
                                                    "event": "onClick",
                                                    "targetCustomer": "$this",
                                                    "params": {
                                                        "tmpDiyProductLine": "#ES{_.cloneDeep($data.diyProductLine)}"
                                                    }
                                                }
                                            ]
                                        }, 
                                        {
                                            "type": "button", 
                                            "text": "取消", 
                                            "gridWidth": "80px", 
                                            "trigger": [
                                                {
                                                    "event": "onClick", 
                                                    "targetCustomer": "hidePopover", 
                                                    "params": {
                                                        "showFilter": false
                                                    }
                                                },
                                                {
                                                    "event": "onClick",
                                                    "targetCustomer": "$this",
                                                    "params": {
                                                        "diyProductLine": "#ES{_.cloneDeep($data.tmpDiyProductLine)}"
                                                    }
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                },
                "children":[
                    {
                        "type":"button",
                        "text":"定制报表"
                    }
                ]
            }
        ]
    }]
}
```
