首页 > Web开发 > 详细

js分享3

时间:2016-01-18 22:50:28      阅读:341      评论:0      收藏:0      [点我收藏+]
(function (window) {

    var _WFCFrame = function () {
    }

    //    $.extend(_WFCFrame, {
    //        Param: {//公共参数,若为组件私有参数,可定义在compName.Param中
    //            windcode: ‘600000.SH‘,
    //            resizable: getParameter(‘resizable‘) != 0,
    //            sortable: getParameter(‘sortable‘) != 0,
    //            custType: null, //客户类型(风险类型)
    //            FCType: 1, //fc类型
    //            TerminalType: getParameter(‘TerminalType‘) || 101, //终端类型
    //            CustomerId: null
    //            //CustAddType:null//客户新增类型(手动新增/导入)
    //        }
    //        , CurrentWorkspace: null//当前workspace
    //    });


    /* 通用方法 */
    $.fn.extend({
        whSize: function (type, size) {
            if (type.toLowerCase() == ‘w‘) {
                return size ? this.width(size) : this.width();
            } else if (type.toLowerCase() == ‘h‘) {
                return size ? this.height(size) : this.height();
            } else {
                return size ? -1 : this;
            }
        },
        bindFocusEffect: function () {
            return this.focus(function () {
                if ($(this).is(‘input[type="text"],textarea‘)) {
                    setClientSmartInput(0);
                }
                $(this).addClass(‘ui-state-focus‘);
            }).blur(function () {
                if ($(this).is(‘input[type="text"],textarea‘)) {
                    setClientSmartInput(1);
                }
                $(this).removeClass(‘ui-state-focus‘);
            });
        }
    });

    $.extend({
        isObjEqual: IsObjEqual
    });

    function inverseColor(colorCode/* #AABBCC or rgb(12,34,56) */) {
        if (typeof colorCode == ‘string‘) {
            if (colorCode.search(/rgb/i) >= 0) {
                var colors = colorCode.replace(/RGB|\(|\)/ig, ‘‘).split(‘,‘);
                if (colors && colors.length == 3) {
                    return ‘rgb(‘ + (255 - colors[0]) + ‘,‘ + (255 - colors[1]) + ‘,‘ + (255 - colors[2]) + ‘)‘;
                }
            } else if (colorCode.search(/#/i) >= 0) {
                var color = colorCode.replace(/#/ig, ‘‘);
                return ‘#‘ + (parseInt(‘FFFFFF‘, 16) - parseInt(color, 16)).toString(16);
            }
        }
        return ‘‘;
    }

    function fillSettingBySettingProperty(setting, settingProperty) {
        if (settingProperty) {
            $.each(settingProperty, function (index, item) {
                if (!setting.hasOwnProperty(index)) {
                    //为区分复杂类型的setting值与settingProperty,settingProperty obj必须有dVal
                    var val = $.type(item) === ‘object‘ ? item.dVal : item;
                    if (val != null && typeof (val) != ‘undefined‘) {
                        setting[index] = val;
                    }
                }
            });
        }
    }

    //跟$.extend(obj1,obj2)的区别在于obj2的为null的属性会复制过去但null值不会带过去
    function mergeObj(/*target,obj1,obj2,obj3,...*/) {
        var target = arguments[0] || {}, len = arguments.length, options, name;
        if (typeof target !== "object" && !jQuery.isFunction(target)) {
            target = {};
        }

        for (i = 1; i < len; i++) {
            if ((options = arguments[i]) != null) {
                for (name in options) {
                    if (options[name] === undefined || options[name] === null) {
                        if (!target.hasOwnProperty(name)) {
                            target[name] = options[name];
                        }
                    } else {
                        target[name] = options[name];
                    }
                }
            }
        }

        return target;
    }

    //与mergeObj类似,增加了对dVal的判断
    function mergeSettingProperty(/*target,obj1,obj2,obj3,...*/) {
        var target = arguments[0] || {}, len = arguments.length, options, name;
        if (typeof target !== "object" && !jQuery.isFunction(target)) {
            target = {};
        }

        for (i = 1; i < len; i++) {
            if ((options = arguments[i]) != null) {
                for (name in options) {
                    if (!target.hasOwnProperty(name)) {
                        target[name] = options[name];
                    } else {
                        if ($.isPlainObject(options[name])) {
                            if (!$.isPlainObject(target[name])) {
                                target[name] = { dVal: target[name] };
                            }
                            mergeObj(target[name], options[name]);
                        }
                        else if (options[name] != undefined && options[name] != null) {
                            if ($.isPlainObject(target[name])) {
                                target[name].dVal = options[name];
                            } else {
                                target[name] = options[name];
                            }
                        }
                    }
                }
            }
        }

        return target;
    }

    //填入默认对象中property填充到目标对象中(在目标对象无此属性时,且只判断第一层,但属性值深度拷贝)
    function fillDefalutProperty(targetObj, defaultObj) {
        if ($.type(targetObj) !== ‘object‘)
            targetObj = {};
        $.each(defaultObj, function (index, item) {
            if (!targetObj.hasOwnProperty(index)) {
                targetObj[index] = $.type(item) === ‘object‘ ? $.extend(true, {}, item) : item;
            }
        });
        return targetObj;
    }

    function replaceSettingPropertyGroup(SP) {
        if (!SP) {
            return;
        }
        $.each(SP, function (index, item) {
            if (item && item.isGroup) {
                delete SP[index];
                if (SettingPropertyGroups.hasOwnProperty(index)) {
                    /*待修改,改为单独设置优先与group设置*/
                    $.extend(SP, $.extend(true, {}, SettingPropertyGroups[index]));
                }
            }
        });
    }

    /* end of 通用方法 */





    /*内部变量*/
    var param = {//公共参数,若为组件私有参数,可定义在compName.Param中
        windcode: ‘600000.SH‘,
        resizable: getParameter(‘resizable‘) != 0,
        sortable: getParameter(‘sortable‘) != 0,
        custType: null, //客户类型(风险类型)
        FCType: 1, //fc类型
        TerminalType: getParameter(‘TerminalType‘) || 101, //终端类型
        CustomerId: null
        //CustAddType:null//客户新增类型(手动新增/导入)
    }
    var currentWorkspace = null;
    var containerSelHelper = null;
    var minSize = 10; //最小宽度或高度
    var droppable_option = {
        accept: ‘.widgetCase,.widget‘
        , hoverClass: ‘droppable-hover‘
        //        , over: function () {
        //            console.log(‘over‘);
        //        }
        //        , out: function () {
        //            console.log(‘out‘);
        //        }
        , drop: function (event, ui) {
            var $dropHolder = $(‘.droppable-placeHolder‘).hide();
            var pos = $dropHolder.prop(‘pos‘);
            if (pos && pos.type) {
                var isCase = ui.draggable.hasClass(‘widgetCase‘); //是否外部拖入元素
                var $widget = isCase ? createWidget($.extend(true, {}, ui.draggable.prop(‘WFCWidgetOption‘))) : ui.draggable;
                var $parent = ui.draggable.parent(‘.container‘);
                var $this = $(this);
                switch (pos.type) {
                    case ‘topLeft‘:
                        //替换或交换位置
                        if (isCase) {
                            removeWidget($(this).children(‘.widget‘));
                            $this.append($widget);
                        } else {
                            var $p = ui.draggable.parent();
                            if ($p.is($this)) {
                                return;
                            }

                            $p.append($this.find(‘.widget‘));
                            $this.append($widget);

                            //交换位置导致selected变化
                            if ($p.hasClass(‘selected‘)) {
                                $p.removeClass(‘selected‘);
                                $this.addClass(‘selected‘);
                            } else if ($this.hasClass(‘selected‘)) {
                                $this.removeClass(‘selected‘);
                                $p.addClass(‘selected‘);
                            }

                            resizeContainer($p);
                            resizeContainer($this);
                        }
                        break;
                    case ‘topRight‘:
                        //左右切分
                        divideContainer($(this), ‘horizontal‘, 0, $widget);
                        if (!isCase) {
                            removeContainer($parent); //删除原容器
                        }
                        break;
                    case ‘bottom‘:
                        //上下切分
                        divideContainer($(this), ‘vertical‘, 0, $widget);
                        if (!isCase) {
                            removeContainer($parent); //删除原容器
                        }
                        break;
                }

                var $ws = $widget.closest(‘.workspace‘);
                if ($ws.data(‘WFCWorkspace‘)) {
                    $ws.WFCWorkspace("Update");
                }

                if (isCase) {
                    //$widget.WFCWidget($widget.prop(‘WFCWidgetOption‘));
                    initWorkspaceWidget($widget, $ws);
                    //remove selected
                    if ($ws.data(‘WFCWorkspace‘)) {
                        $ws.WFCWorkspace(‘UnSelectContainer‘);
                    }
                    $widget.parent().trigger(‘click‘);
                }
            }

            //                if ($(this).children(‘.widget‘).length > 0) {
            //                    return; //已经有内容了
            //                }
        }
    }

    var resizable_option = {
        handles: ‘e‘
        //, containment: "parent"//此项有时会失效且调整完成后,会莫名增加left样式(发生位移) 
        , minHeight: minSize
        , minWidth: minSize
        , helper: ‘resizable-helper-e‘
        //, grid: 2
        , stop: function (event, ui) {
            var parent = ui.element.parent();
            var $next = ui.element.next();
            var isHor = parent.hasClass(‘horizontal‘);
            var sF = ui.element.whSize(isHor ? ‘w‘ : ‘h‘) + (isHor ? 4 : (typeof isIE8 === ‘undefined‘ ? 3 : 4)); //4横向对其了,但纵向差1 (但在ie8下正好)
            var sT = parent.whSize(isHor ? ‘w‘ : ‘h‘);
            var sN = $next.whSize(isHor ? ‘w‘ : ‘h‘);
            var oSize = isHor ? ui.originalSize.width : ui.originalSize.height;
            var sNTarget = sN + oSize - sF;
            if (sF < minSize) {
                sF = minSize;
                sNTarget = sN + oSize - sF;
            } else if (sNTarget < minSize) {
                sNTarget = minSize;
                sF = sN + oSize - sNTarget;
            }

            resizeContainer(ui.element.attr(‘size‘, (sF / sT).toFixed(5)), sF, isHor);
            resizeContainer(ui.element.next().attr(‘size‘, (sNTarget / sT).toFixed(5)), sNTarget, isHor); //-1 for abcpdf

            //这里包括content与页眉页脚都可能调用
            var $ws = ui.element.closest(‘.workspace‘);
            if ($ws.data(‘WFCWorkspace‘)) {
                if (ui.element.closest(‘.pageHeader,.pageFooter‘).length > 0) {
                    $ws.data(‘WFCWorkspace‘).PageHeaderFooterUpdate();
                } else {
                    $ws.WFCWorkspace("Update");
                }
            }
        }
    };

    var draggable_option = {
        cursorAt: { left: 60, top: 45 },
        appendTo: "body",
        helper: function () {
            var self = $(this);
            if (self.hasClass(‘widgetCase‘)) {
                return self.clone().addClass(‘widget-draggable-helper ui-state-hover‘);
            } else {
                return $(‘<div class="widget-draggable-helper ui-state-hover"><div class="widget-draggable-helper-del">删除</div><div class="widget-draggable-helper-title">‘ + $(this).find(‘.widget-head > .ui-dialog-title‘).text() + ‘</div></div>‘);
            }
        },
        scroll: false,
        iframeFix: true,
        drag: function (event, ui) {
            //console.log(ui.position.top + ‘,‘ + ui.position.left + ‘ ; ‘ + ui.offset.top + ‘,‘ + ui.offset.left);
            var $currentDrop = $(‘.workspace .droppable-hover‘);
            if ($currentDrop.length > 0) {
                ui.helper.removeClass("del").removeClass("ui-state-error");
                //get pos
                var pos = null;
                var cH = $currentDrop.height(), cH2 = Math.round(cH / 2), cW = $currentDrop.width(), cW2 = Math.round(cW / 2), cOffset = $currentDrop.offset();
                var mouseX = event.pageX, mouseY = event.pageY;
                if ($currentDrop.children(‘.container,.widget‘).length == 0 || $(this).parent()[0] === $currentDrop[0] || (cOffset.left <= mouseX && mouseX <= cOffset.left + cW2 && cOffset.top <= mouseY && mouseY <= cOffset.top + cH2)) {
                    pos = { type: ‘topLeft‘, left: cOffset.left, top: cOffset.top, width: cW, height: cH };
                } else if (cOffset.left + cW2 < mouseX && mouseX <= cOffset.left + cW && cOffset.top <= mouseY && mouseY <= cOffset.top + cH2) {
                    pos = { type: ‘topRight‘, left: cOffset.left + cW2, top: cOffset.top, width: cW - cW2, height: cH };
                } else if (cOffset.left <= mouseX && mouseX <= cOffset.left + cW && cOffset.top + cH2 < mouseY && mouseY <= cOffset.top + cH) {
                    pos = { type: ‘bottom‘, left: cOffset.left, top: cOffset.top + cH2, width: cW, height: cH - cH2 };
                }
                showDroppablePlaceHolder(pos);
            } else {
                hideDroppablePlaceHolder();
                //console.log(ui.position.top + ‘,‘ + ui.position.left + "|" + ui.offset.top + ‘,‘ + ui.offset.left);
                //if (!event.srcElement.closest(‘.workspace‘).length) {
                //这里还是应该判断鼠标位置是否在workspace中来做
                if (!ui.helper.hasClass(‘widgetCase‘))
                    ui.helper.addClass("del ui-state-error");
                //}
            }
        },
        stop: function (event, ui) {
            if (!ui.helper.hasClass(‘widgetCase‘) && ui.helper.hasClass(‘del‘)) {
                removeContainer($(this).parent(‘.container‘));
            }
        }
    };

    var ProductsBasicInfo = {};

    var SettingPropertyGroups = {
        group_tableStyle: {
            tableStyle: { groupId: ‘tableBorder‘, groupText: ‘框线‘ },
            tableBorderColor: { groupId: ‘tableBorder‘ },
            tableHeadFontStyle: { groupId: ‘tableHead‘, groupText: ‘表头‘ },
            tableHeadFontColor: { groupId: ‘tableHead‘ },
            tableHead: { groupId: ‘tableHead‘ },
            tableRowHeight: { groupId: ‘tableRow‘, groupText: ‘行设置‘ },
            tableBgColor: { groupId: ‘tableRow‘ },
            tableInterlacedRowBgColor: { groupId: ‘tableRow‘ }
        }
    };



    /*end of 内部变量*/


    /* functions */
    function containerClick(evt) {
        var sel = $(‘.workspace .container.selected‘);
        if (sel.length > 0 && sel[0] === this) {
            //$(this).removeClass(‘selected‘);
        } else {
            sel.closest(‘.workspace‘).WFCWorkspace(‘UnSelectContainer‘);

            var self = $(this);
            self.closest(‘.workspace‘).WFCWorkspace(‘SelectContainer‘, self);
        }
        return true;
    }

    //用:hover实现(不支持ie6)
    //    function containerHoverOver(evt) {
    //        var self = $(this);
    //        self.addClass(‘hover‘).append(containerSelHelper);
    //    }

    //    function containerHoverOut(evt) {
    //        var self = $(this);
    //        self.removeClass(‘hover‘);
    //    }

    function removeSelected() {
        $(‘.workspace .container.selected‘).removeClass(‘selected‘);
        var SA = WFCFrame.Settings.widgetSetArea;
        if (SA && SA.data(‘WFCSetting‘)) {
            SA.WFCSetting(‘destroy‘);
        }
        this._trigger("Destroy", null, null);
    }

    function divideContainer($container, direction, childrenPos/*原内容位置,0放置在first中(默认),1放置在last中*/, otherChildren/*需装入另一个容器的内容*/) {
        var isHor = direction.toLowerCase() == ‘horizontal‘ ? true : false; //水平/垂直切分
        if ($container && $container.length > 0) {
            var sT = isHor ? $container.width() : $container.height();
            var sF = Math.round(sT / 2);
            if (sF < minSize)
                return;

            var $children = $container.children(‘.container,.widget‘); //$container.find(‘.widget‘)
            var hasSel = $container.hasClass(‘selected‘);
            $container.unbind("click").droppable(‘destroy‘).removeClass(‘selected horizontal vertical‘).addClass(isHor ? ‘horizontal‘ : ‘vertical‘);
            var $cF = $(‘<div class="container container-first ‘ + (hasSel ? ‘selected‘ : ‘‘) + ‘"></div>‘).attr(‘size‘, (sF / sT).toFixed(5)).whSize(isHor ? ‘w‘ : ‘h‘, sF).append($children).prepend(containerSelHelper);
            var $cL = $(‘<div class="container container-last"></div>‘).whSize(isHor ? ‘w‘ : ‘h‘, sT - sF); //-1 for abcpdf
            $children.appendTo(childrenPos ? $cL : $cF);
            if (otherChildren) {
                otherChildren.appendTo(childrenPos ? $cF : $cL);
            }
            $container.append($cF).append($cL);

            $cF.resizable($.extend(resizable_option, { handles: (isHor ? ‘e‘ : ‘s‘), helper: (isHor ? ‘resizable-helper-e‘ : ‘resizable-helper-s‘) }));

            bindLeafContainerEvent($container.children(‘.container‘));

            //call widget resize
            //resizeWidget($widget);
            resizeContainer($container); //内容需resize
        }
    }

    function removeContainer($container) {
        //有子container时不可删除,并保留另一个container的children
        if ($container && $container.length > 0 && $container.children(‘.container‘).length <= 0) {
            var $ws = $container.closest(‘.workspace‘);
            //有子widget,先删除widget
            removeWidget($container.children(‘.widget‘));

            //根容器本身不可删除(只删除widget)
            if (!$container.parent().hasClass(‘container‘))
                return;

            var $p = $container.parent();
            var $sibs = $container.siblings(‘.container‘);
            if ($sibs.children(‘.container‘).length > 0) {
                var isHor = $sibs.hasClass(‘horizontal‘);
                $p.append($sibs.children(‘.container‘)).removeClass(‘horizontal vertical‘).addClass(isHor ? ‘horizontal‘ : ‘vertical‘);
            }
            else {
                $p.append($sibs.children(‘.widget‘)).removeClass(‘horizontal vertical‘);
                bindLeafContainerEvent($p);
            }
            $sibs.remove();
            //$container.find(‘.widget‘).WFCWidget(‘destroy‘);
            var isSelected = $container.hasClass(‘selected‘);
            $container.remove();

            if (isSelected) {
                var $setArea = WFCFrame.Settings.widgetSetArea;
                if ($setArea && $setArea.data(‘WFCSetting‘))
                    $setArea.WFCSetting(‘destroy‘);
            }

            resizeContainer($p);
            //call widget reseize or do it in resizeContainer

            //通知workspace更新 (若要求效率,是不是没有给container都要隐藏要给引用指向对应的workspace,或放在dom上或放在绑定事件中)

            if ($ws.data(‘WFCWorkspace‘)) {
                $ws.WFCWorkspace("Update");
            }
        }
    }

    function resizeContainer($container, size, isHor) {
        if ($container && $container.length > 0) {
            //deal with self if size is defined
            if (size) {
                $container.whSize(isHor ? ‘w‘ : ‘h‘, size).whSize(isHor ? ‘h‘ : ‘w‘, ‘100%‘); // whSize(isHor ? ‘h‘ : ‘w‘, isHor ? $container.parent().height() : $container.parent().width()); //在container不显示时,设置100%并不起作用
            }

            var $children = $container.children(‘.container‘);
            var len = $children.length;
            var isHorChild = $container.hasClass(‘horizontal‘);
            if (len > 0) {
                var childTotalSize = $container.whSize(isHorChild ? ‘w‘ : ‘h‘);
                var sizeUsed = 0;
                var sF = 0;
                $children.each(function (index, item) {
                    if (index < len - 1) {
                        sF = Math.round(childTotalSize * ($(item).attr(‘size‘) || 0));
                        sizeUsed += sF;
                    } else {
                        sF = childTotalSize - sizeUsed;
                    }
                    resizeContainer($(item), sF, isHorChild);
                });
            } else {
                //call widget resize
                resizeWidget($container.find(‘.widget‘));
            }
        }
    }

    function createWidget(option, noDaggable) {
        var $w = $(‘<div class="widget"></div>‘).prop(‘WFCWidgetOption‘, option);
        if (!noDaggable) {
            $w.draggable(draggable_option);
        }
        return $w;
    }

    function removeWidget($widget) {
        if ($widget && $widget.length > 0) {
            var isSelected = $widget.parent().hasClass(‘selected‘);
            $widget.remove();
            if (isSelected) {//如被删除控件中含被选中的,则需要销毁设置区域
                var SA = WFCFrame.Settings.widgetSetArea;
                if (SA && SA.data(‘WFCSetting‘)) {
                    SA.WFCSetting(‘destroy‘);
                }
            }
        }
    }

    function createContainer($pContainer, option, isLast, dicWidgets, editable) {
        if (!option)
            return;
        editable = typeof (editable) == ‘undefined‘ || editable;
        if (option.type > 0) {
            //widget
            if (option.WidgetID && dicWidgets.hasOwnProperty(option.WidgetID)) {
                option.setting = dicWidgets[option.WidgetID].setting;
            }
            if (editable) {
                bindLeafContainerEvent($pContainer);
            }
            $pContainer.append(createWidget(option, !editable));
        } else {
            //container
            var isHor = $pContainer.hasClass(‘horizontal‘);
            var $new = $(‘<div class="container ‘ + (isLast ? ‘ container-last‘ : ‘ container-first‘) + (option.hv == 0 ? ‘ horizontal‘ : ‘ vertical‘) + ‘"></div>‘).attr(‘size‘, option.sz);
            if (!isLast && editable) {
                $new.resizable($.extend(resizable_option, { handles: (isHor ? ‘e‘ : ‘s‘), helper: (isHor ? ‘resizable-helper-e‘ : ‘resizable-helper-s‘) }));
            }
            $pContainer.append($new);
            if (option.ct && option.ct.length > 0) {
                createContainer($new, option.ct[0], option.ct.length == 1, dicWidgets, editable);
                if (option.ct.length > 1)//只考虑1或2个container的情况
                    createContainer($new, option.ct[1], true, dicWidgets, editable);
            } else if (editable) {
                bindLeafContainerEvent($new);
            }
        }
    }

    function bindLeafContainerEvent($container) {
        if ($container && $container.length) {
            $container.click(containerClick).droppable(droppable_option); //.hover(containerHoverOver, containerHoverOut)
        }
        return $container;
    }

    function showDroppablePlaceHolder(pos) {
        var $pHolder = $(‘.droppable-placeHolder‘);
        if ($pHolder.length <= 0) {
            $pHolder = $(‘<div class="droppable-placeHolder ui-widget-overlay"></div>‘).css({ position: ‘absolute‘ }).appendTo(‘body‘);
        }

        var oraginalPos = $pHolder.prop(‘pos‘);
        if (pos && pos.type) {
            if (oraginalPos && oraginalPos.type == pos.type && oraginalPos.left == pos.left && oraginalPos.top == pos.top && oraginalPos.width == pos.width && oraginalPos.height == pos.height) {
                //位置不变
            } else {
                $pHolder.css({ left: pos.left + ‘px‘, top: pos.top + ‘px‘, width: pos.width + ‘px‘, height: pos.height + ‘px‘ }).prop(‘pos‘, pos);
            }
            $pHolder.show();
        } else
            $pHolder.hide();
    }

    function hideDroppablePlaceHolder() {
        $(‘.droppable-placeHolder‘).hide();
    }

    function initWorkspaceWidget($widget, $ws) {
        var callbacks = ($ws && $ws.data("WFCWorkspace")) ? {
            //通知workspace更新,function不会被json化
            Update: function () {
                $ws.WFCWorkspace("Update");
            },
            Complete: function () {
                $ws.WFCWorkspace("WidgetComplete");
            }
        } : null;
        $widget.WFCWidget($.extend($widget.prop(‘WFCWidgetOption‘), callbacks));
    }

    function getNoDataBlockOption(message) {
        var html = ‘<p class="noDataTip"><span class="iconfont">&#xe612;</span>‘ + (message || ‘暂无数据‘) + ‘&nbsp;&nbsp;<a class="aWidgetRefresh" onclick="WFCFrame.RefreshWidget(this);">刷新</a><p>‘;
        //html += ‘<p class="noDataTip">1.数据加载失败,点击<a>此处</a>刷新<br/>2.检查输入条件是否存在数据</p>‘;

        var NoDataBlockOption = {
            noIframe: true,
            message: html,
            css: {
                padding: 0,
                margin: 0,
                textAlign: ‘center‘,
                color: ‘#929292‘,
                width: ‘80%‘,
                //border: ‘1px solid #A6C9E2‘,
                fontSize: ‘16px‘,
                cursor: ‘default‘
            },
            overlayCSS: {
                backgroundColor: ‘#FCFDFD‘,
                opacity: 0.4,
                cursor: ‘default‘
            }
        }
        return NoDataBlockOption;
    }

    function initSelHelper() {
        var $helper = $(‘<div class="container-selected-helper"></div>‘).appendTo(‘body‘); //<a class="container-selected-helper-del">删除</a>
        //        $helper.find(‘.container-selected-helper-del‘).click(function () {
        //            var $ct = $(this).closest(‘.container.selected‘);
        //            var $wt = $ct.find(‘.widget‘);
        //            if ($wt.length > 0) {
        //                removeWidget($wt);
        //            } else {
        //                $helper.prependTo(‘body‘);
        //                removeContainer($ct);
        //            }
        //        });
        $helper.click(function (event) {
            event.stopPropagation();
        });
        return $helper;
    }

    function resizeWidget($widget) {
        try {
            if ($widget.data(‘WFCWidget‘))
                $widget.WFCWidget(‘Resize‘);
        }
        catch (e) {
            showDebugMsg(e.message);
        }
    }

    function getContainerContentObj($container) {
        //var _widgets = [];

        function _getContainerContentObj($container) {
            if ($container.hasClass(‘widget‘)) {
                var widgetOpt = $container.prop(‘WFCWidgetOption‘);
                //_widgets.push(widgetOpt);
                //var reval = $.extend({}, widgetOpt);
                //delete reval.setting; //setting不再单独存储
                //return reval;
                return widgetOpt;
            } else if ($container.hasClass(‘container‘)) {
                var ct = {
                    type: 0,
                    hv: $container.hasClass(‘horizontal‘) ? 0 : 1,
                    sz: $container.attr(‘size‘) || ‘‘
                };

                var $children = $container.children(‘.container,.widget‘);
                if ($children.length > 0) {
                    ct.ct = [];
                    $children.each(function () {
                        ct.ct.push(_getContainerContentObj($(this)));
                    });
                }
                return ct;
            }
            return {};
        }

        var _content = _getContainerContentObj($container);
        //widget(setting)与workspace content分开保存
        return { /*widgets: _widgets,*/content: _content };
    }




    function getProductsBasicInfo(windcodes/*array*/, callback) {
        var reVal = {};
        if (windcodes && $.isArray(windcodes)) {
            var codesNoInfo = ‘‘;
            $.each(windcodes, function (index, item) {
                if (item && !ProductsBasicInfo.hasOwnProperty(item))
                    codesNoInfo += (item + ‘,‘);
            });
            if (codesNoInfo.length > 0) {
                codesNoInfo = codesNoInfo.substring(0, codesNoInfo.length - 1);
                var parameters = [codesNoInfo];
                var dataParameters = { MethodAlias: "MFRB_GetProductsBasicInfo", Parameter: parameters };
                AjaxRequest(ajaxSecureUnlockHandler, dataParameters, function (result) {
                    if (result && result.State == 0 && typeof result.Data === ‘object‘) {
                        //fill ProductsInfo;
                        $.each(result.Data, function (index, item) {
                            if (!ProductsBasicInfo.hasOwnProperty(item.WindCode))
                                ProductsBasicInfo[item.WindCode] = item;
                        });
                    }
                    $.each(windcodes, function (index, item) {
                        if (ProductsBasicInfo.hasOwnProperty(item))
                            reVal[item] = $.extend(true, {}, ProductsBasicInfo[item]);
                    });
                    callback(reVal);
                });
            }
            else {
                $.each(windcodes, function (index, item) {
                    if (ProductsBasicInfo.hasOwnProperty(item))
                        reVal[item] = $.extend(true, {}, ProductsBasicInfo[item]);
                })
                callback(reVal);
            }
        }
    }

    function getProductInfo(windcode, callback) {
        if (windcode && typeof (windcode) == ‘string‘) {
            getProductsBasicInfo([windcode], function (infos) {
                if (infos && infos[windcode]) {
                    callback(infos[windcode]);
                }
            });
        } else if ($.isArray(windcode)) {
            getProductsBasicInfo(windcode, callback);
        }
    }

    //反转chart里series的顺序,但legend顺序保持正序
    function reverseChartSeriesIndex(series) {
        if (series) {
            $.each(series, function (index, item) {
                item.index = series.length - index;
                item.legendIndex = index;
            });
        }
    }

    /* end of functions */


    $.widget("wfc.widgetResizable", {
        version: ‘1.0‘,
        options: {
            handles: "e"//e or s
            //zIndex: 1000
        },
        _create: function () {
            var self = this, opt = this.options, ele = this.element;
            this.handles = opt.handles;
            if (this.handles.constructor == String) {
                var n = this.handles.split(","); this.handles = {};
            }
            ele.addClass("wfc-widgetResizable");
            for (var i = 0; i < n.length; i++) {
                var handle = $.trim(n[i]), hname = ‘wfc-widgetResizable-‘ + handle;
                var axis = $(‘<div class="wfc-widgetResizable-handle ‘ + hname + ‘"></div>‘);

                //Insert into internal handles object and append to element
                this.handles[handle] = ‘.wfc-widgetResizable-‘ + handle;
                this.element.append(axis);
                var dragOpt = $.extend({}, opt, {
                    axis: handle === ‘e‘ ? ‘x‘ : ‘y‘,
                    start: function (event, ui) {
                        var drag = $(this).data("draggable"), o = drag.options;
                        var that = $(this).parent().data(‘widgetResizable‘);
                        $(‘body‘).css(‘cursur‘, o.axis === ‘x‘ ? ‘e-resize‘ : ‘s-resize‘);
                        that._trigger(‘start‘, event, ui);
                    },
                    stop: function (event, ui) {
                        $(‘body‘).css(‘cursur‘, ‘auto‘);
                        var drag = $(this).data("draggable"), o = drag.options;
                        var that = $(this).parent().data(‘widgetResizable‘);
                        if (o.axis === ‘x‘) {
                            that.element.width(ui.position.left);
                        } else if (o.axis === ‘y‘) {
                            that.element.height(ui.position.top);
                        }
                        that._trigger(‘stop‘, event, ui);
                    }
                });

                if (handle === ‘e‘) {
                    axis.css(‘left‘, ele.width());
                } else if (handle === ‘s‘) {
                    axis.css(‘top‘, ele.height());
                }
                axis.draggable(dragOpt);
            }
        },
        _destroy: function () {
            var self = this, opt = this.options, ele = this.element;
            ele.find(‘.wfc-widgetResizable-handle‘).draggable(‘destroy‘);
            ele.removeClass("wfc-widgetResizable");
        }
    });


    /*
    WFCFrame:框架,全局命名空间,包含对下列一系列对象的组织和调用
    Workspace:工作区域,一般为页面的主要内容区域,包含嵌套的多层容器(Container)
    Container:容器,包含一个Widget或两个Container
    Widget:控件,可添加到容器中,在容器限定的区域中展示自定义的业务界面,每个控件需实现预定义的API以与框架交互
    Compment:是否需要?
    Template:模板,包含一系列预定义配置和容器布局的工作区

    SettingProperty:设置的设置,一方面表示有哪些设置可用,另一方面其值有两种情况:一种为非object类型,则表示此设置的默认值,另一种则为复杂设置对象{opts:‘下拉选项‘,dVal:‘默认值‘}

    */

    /* WFCWorkspace define */
    (function ($) {
        $.widget(‘wfc.WFCWorkspace‘, {
            version: ‘2.0‘,
            options: {
                PageHeaderFooter: {
                    header: { sz: 30, content: [{ sz: 0.25, option: { type: 611 } }, { sz: 0.5, option: { type: 611 } }, { sz: 0.25, option: { type: 611 } }] },
                    footer: { sz: 30, content: [{ sz: 0.25, option: { type: 611 } }, { sz: 0.5, option: { type: 611 } }, { sz: 0.25, option: { type: 611 } }] }
                },
                PageIndex: 1,
                editable: true,
                //callback
                Update: null,
                PageHeaderFooterUpdate: null,
                ContainerUnSelect: null,
                ContainerSelect: null,
                Complete: null
            },
            _createWidget: function (option, element) {
                this.originalOption = option || {};
                this._super(option, element);
            },
            _create: function () {
                var self = this,
                options = this.options,
                $divWs = this.element,
                currentWorkspace = this;

                //以下内容注释,暂时仅让widget支持SettingPropertyGroup
                //replaceSettingPropertyGroup(WFCFrame.Report.SettingProperty);
                //replaceSettingPropertyGroup(options.SettingProperty);

                //合并SettingProperty待实现
                options.SettingProperty = $.extend({}, WFCFrame.Report.SettingProperty, options.SettingProperty);
                options.setting = $.extend({}, WFCFrame.Report.SettingObj, options.setting);
                $divWs.addClass(‘workspace‘).attr(‘WFCWorkspace‘, 1).attr(‘workspace-state‘, ‘loading‘);
                var setting = options.setting;
                //填补setting的默认值
                fillSettingBySettingProperty(setting, options.SettingProperty);

                //当用户点击非container和setting区域时,需要移除选中效果
                $(‘body‘).click(function (event) {
                    var $target = $(event.target);
                    if ($target.closest(‘.container,.setting-area,.win-widgetSetting,.ui-datepicker,.ui-datepicker-header,.ui-multiselect-menu‘).length == 0) {
                        $(‘.workspace[workspace-state=complete]:visible‘).WFCWorkspace(‘UnSelectContainer‘);
                        //removeSelected();
                    }
                });

                var dicWidgets = {};
                //widget设置存到workspace中,以避免复制等出现的问题
                //                if (options.Widgets && options.Widgets.length > 0) {
                //                    $.each(options.Widgets, function (index, item) {
                //                        if (!item.hasOwnProperty(‘setting‘))
                //                            item.setting = JSON2.parse(item.Setting || ‘{}‘);
                //                        dicWidgets[item.WidgetID] = item;
                //                    });
                //                }

                //init workspace size
                //var XinZhiSize = { width: 612, height: 792, padding: [24, 54, 24, 54], scale: 1.3333 }; //单位pt
                var paddingTandB = 3;
                var paddingMax = 200;
                var paddingTandBPixel = Math.round(paddingTandB * setting.scale);
                var paddingMaxPixel = Math.round(paddingMax * setting.scale);
                var pageW = Math.round(setting.width * setting.scale);
                var pageH = Math.round(setting.height * setting.scale);
                var pagePadding = setting.padding;
                if (pagePadding && pagePadding.length == 4) {
                    var pagePaddingPixel = [];
                    $.each(pagePadding, function (index, item) {
                        pagePaddingPixel.push(Math.round(item * setting.scale));
                    });
                    //pageW = pageW - pagePaddingPixel[1] - pagePaddingPixel[3];
                    pageH = pageH - paddingTandBPixel * 2;
                    $divWs.css({
                        padding: paddingTandBPixel + ‘px ‘ + 0 + ‘px ‘ + paddingTandBPixel + ‘px ‘ + 0 + ‘px‘
                    });
                }

                $divWs.css({
                    width: pageW + ‘px‘,
                    height: pageH + ‘px‘
                });

                $divWs.append(‘<div class="pageHeader horizontal"></div><div class="pageContent"></div><div class="pageFooter horizontal"></div>‘);
                $divWs.children(‘.pageContent‘).css({
                    marginLeft: (pagePaddingPixel[3] - 1) + ‘px‘,
                    marginRight: (pagePaddingPixel[1] - 1) + ‘px‘
                });
                //.resizable({//需要在content内容之前调用(否则e,s两边无法拉),估计跟内部的resizable冲突
                //handles: ‘n,s,e,w‘, helper: ‘ui-resizable-helper‘
                //,maxHeight:pageH
                //,minHeight:pageH - paddingMaxPixel * 2
                //,maxWidth:pageW - paddingTandBPixel * 2
                //, minWidth: pageW - paddingMaxPixel * 2
                //, start: function (evt, ui) {
                //    //saveSetting
                //    //console.log(evt.srcElement); has 
                //    //ui.element

                //}
                //, stop: function (evt, ui) {
                //    if (WFCFrame.Report) {
                //        var setting = WFCFrame.Report.SettingObj;
                //        var padding = setting.padding;
                //        var resizeHandler = $(evt.srcElement);

                //        if (resizeHandler.hasClass(‘.ui-resizable-n‘)) {

                //        } else if (resizeHandler.hasClass(‘.ui-resizable-s‘)) {

                //        } else if (resizeHandler.hasClass(‘.ui-resizable-w‘)) {

                //        } else if (resizeHandler.hasClass(‘.ui-resizable-e‘)) {

                //        }

                //        $(‘.workspace[WFCWorkspace=1]‘).WFCWorkspace(‘Resize‘);
                //    }
                //    //report.Setting 需要刷新reprot的其他workspace(也可以自己做)
                //    //这里的report目前通过wfcframe.report获取,如果考虑多个report的情况的话,还是应该根据上下文获取,
                //    //不过workspace中应该可以保存,但是需要注意的是,如果通过option传入,则option会完全复制一份report,这显然是不愿意看到的情况
                //    //当然,report中最好保存其对应的workspace,这样可以更新,也可以通过jquery选择器
                //    //report.SaveSetting({padding:[]}); 
                //}
                //});
                $divWs.children(‘.pageHeader,.pageFooter‘).css({
                    paddingLeft: ‘3px‘, // pagePaddingPixel[3] + ‘px‘,
                    paddingRight: ‘3px‘//pagePaddingPixel[1] + ‘px‘
                });

                //init page Header and Footer
                var pageHF = this.options.PageHeaderFooter;
                var pageContentH = pageH;

                $.each(pageHF, function (index, item) {
                    if (item) {
                        var pH = Math.round((index == ‘header‘ ? pagePadding[0] - paddingTandB : pagePadding[2] - paddingTandB) * setting.scale) - 1;
                        pageContentH -= pH;
                        var $pH = $divWs.find(index == ‘header‘ ? ‘.pageHeader‘ : ‘.pageFooter‘);
                        $pH.attr(‘sz‘, item.sz).height(pH);
                        if (item.content && item.content.length) {
                            var pW = $pH.width(), len = item.content.length, tW = 0;
                            $.each(item.content, function (index2, item2) {
                                var $c = $(‘<div class="container"></div>‘);
                                if (options.editable) {
                                    $c.click(containerClick);
                                }
                                if (item2.option) {
                                    $c.append(createWidget(item2.option, true));
                                }
                                if (index2 < len - 1) {
                                    var w = Math.round((item2.sz || 0) * pW);
                                    tW += w;
                                    $c.attr(‘size‘, item2.sz).width(w + ‘px‘);
                                    if (options.editable) {
                                        $c.resizable($.extend(resizable_option, { handles: ‘e‘, helper: ‘resizable-helper-e‘ }));
                                    }
                                } else {
                                    $c.attr(‘size‘, item2.sz).width((pW - tW) + ‘px‘);
                                }
                                $pH.append($c);
                            });
                        }
                    }
                });
                $divWs.children(‘.pageContent‘).height(pageContentH);

                var $divPageContent = $divWs.children(‘.pageContent‘);

                if (!options.ContentJson) {
                    $divPageContent.append(bindLeafContainerEvent($(‘<div class="container"></div>‘)));
                } else {
                    //init by options.content
                    var wsContent = $.parseJSON(options.ContentJson);
                    if (!!wsContent) {
                        createContainer($divPageContent, wsContent, true, dicWidgets, options.editable);
                    }
                }

                var $rootContainer = $divPageContent.children(‘.container‘);
                $rootContainer.addClass(‘container-root‘).css({
                    float: ‘none‘ //根container设置float为none,解决ie8下height:100%无效的问题
                    //width: $divPageContent.width() + ‘px‘, //显示设置width与height避免width为小数导致换行问题
                    //height: $divPageContent.height() + ‘px‘
                }).prepend(‘<div class="emptyContainerTip tip"><span class="iconfont">&#xe611;</span> 可拖拽控件至此</div>‘);

                if (options.ContentJson) {
                    resizeContainer($rootContainer);
                    $divWs.find(‘.widget‘).each(function () {
                        initWorkspaceWidget($(this), $divWs);
                    });
                }

                //                if (param.resizable || param.sortable) {
                //                    $ws.find(‘.ui-resizable-handle‘).mousedown(function () {
                //                        overlayIframe($(this).closest(‘.column‘));
                //                    }).mouseup(function () {
                //                        removeIframeOverlay($(this).closest(‘.column‘));
                //                    }); //释放鼠标事件在移动后不触发,因此ondrag_end和resizable stop事件里也要触发

                $divWs.attr(‘workspace-state‘, ‘initComplete‘);
                this.WidgetComplete();
            },
            _destroy: function () {
                this.CollectInfo(); //销毁前将修改内容更新至option,以防止修改丢失
                this.element.removeClass(‘wrokspace‘).removeAttr(‘WFCWorkspace‘).removeAttr(‘workspace-state‘).empty(); //remove widget div时,会自动调用,因此其实这里可以不调用,且removeWidget时也不必显式调用destroy
            },
            _init: function () {

            },
            originalOption: null,
            needSave: false,
            needCollect: false, //workspace中widget,setting,layout的变化没有完全收集(后期考虑通过传递引用直接修改源数据)
            OriginalOption: function () {
                return this.originalOption;
            },
            UnSelectContainer: function () {
                var self = this;
                var sel = self.element.find(‘.container.selected‘);
                sel.removeClass(‘selected‘);
                //解决控件中textarea无法失去焦点问题(跟控件整体draggable化有关),此方法触发的blur事件中document.activeElement依然为其自身
                //现在改为在widget的UnSelect中做
                //sel.find(‘textarea,input‘).blur();
                
                var $widget = sel.find(‘.widget‘);
                var SA = WFCFrame.Settings.widgetSetArea;

                $widget.WFCWidget(‘UnSelect‘);

                if (SA && SA.data(‘WFCSetting‘)) {
                    SA.WFCSetting(‘destroy‘);
                }
                self._trigger("ContainerUnSelect", null, null);
            },
            SelectContainer: function ($container) {
                var self = this;
                $container.addClass(‘selected‘).append(containerSelHelper);
                //_WFCFrame.Settings.Init(‘widget‘);

                //这里应该triggle一个选中事件 或者 通过WFCFrame设置传入一个settingarea
                var $widget = $container.find(‘.widget‘);
                var SA = WFCFrame.Settings.widgetSetArea;

                $widget.WFCWidget(‘Select‘);

                if (SA && $widget.length > 0) {
                    var isPageHeaderFooter = $container.closest(‘.pageHeader,.pageFooter‘).length > 0;
                    if (SA.data(‘WFCSetting‘)) {
                        SA.WFCSetting(‘destroy‘);
                    }

                    SA.WFCSetting({ level: ‘widget‘, target: $widget, isPageHeaderFooter: isPageHeaderFooter });
                }

                self._trigger("ContainerSelect", null, null);
            },
            Resize: function () {
                //Resize PageHeaderFooter
                var self = this,
                   options = this.options,
                   $divWs = this.element;
                //var padding = options.setting.padding;//注意options.setting可能为空


                this.element.find(‘.pageHeader,.pageFooter‘).each(function (index, item) {
                    var $cs = $(this).children(‘.container‘);
                    var len = $cs.length;
                    var pW = $(this).width();
                    var tW = 0;
                    var ix = 0;
                    $cs.each(function () {
                        var self = $(this);
                        if (ix < len - 1) {
                            var w = Math.round((self.attr(‘size‘) || 0) * pW);
                            tW += w;
                            self.width(w + ‘px‘);
                            ix++;
                        } else {
                            self.width((pW - tW) + ‘px‘);
                        }
                    });
                });
                this.element.find(‘.pageHeader .widget,.pageFooter .widget‘).WFCWidget(‘Resize‘);

                //Resize Content
                var $divWs = this.element;
                var $rootContainer = $divWs.find(‘.container-root‘);
                resizeContainer($rootContainer);
            },
            WidgetComplete: function (widgetId) {
                //若要提高效率,应该采用注册机制
                var self = this, ele = this.element;
                if (ele.attr(‘workspace-state‘) == ‘initComplete‘ && ele.find(‘.widget[widget-state!=complete]‘).length == 0) {
                    ele.attr(‘workspace-state‘, ‘complete‘);
                    self._trigger("Complete", null, null);
                }
            },
            GetContentObj: function () {
                var $divWs = this.element;
                return getContainerContentObj($divWs.find(‘.pageContent .container-root‘));
            },
            GetPageHeaderFooter: function () {
                var $divWs = this.element;
                var pHF = { header: null, footer: null };
                $divWs.find(‘.pageHeader,.pageFooter‘).each(function () {
                    var $this = $(this);
                    var isHeader = $this.hasClass(‘pageHeader‘);
                    var result = { sz: $this.attr(‘sz‘), content: [] };
                    $this.children(‘.container‘).each(function () {
                        var $widget = $(this).children(‘.widget‘);
                        var obj = { sz: $(this).attr(‘size‘) || 0 };
                        if ($widget.length > 0) {
                            obj.option = $widget.prop(‘WFCWidgetOption‘);
                        }
                        result.content.push(obj);
                    });
                    if (isHeader) {
                        pHF.header = result;
                    } else {
                        pHF.footer = result;
                    }
                });
                return pHF;
            },
            Update: function () { //当内容有改变时,调用此方法
                this.needCollect = true;
                this._trigger(‘Update‘, null, null);
            },
            PageHeaderFooterUpdate: function () {//页眉页脚等report相关内容更新
                var options = this.options;
                var oriOpt = this.originalOption;
                var phf = this.GetPageHeaderFooter();
                if (phf) {
                    options.PageHeaderFooter = phf;
                    oriOpt.PageHeaderFooter = phf;
                }
                //                if(WFCFrame.Report){//这里放在PageHeaderFooterUpdate中做
                //                    WFCFrame.Report.PageHeaderFooter = options.PageHeaderFooter;
                //                }
                this._trigger(‘PageHeaderFooterUpdate‘, null, { PageHeaderFooter: options.PageHeaderFooter });
            },
            Save: function (callback) {
                //目前的保存是全部保存,一般不调用这里
                var self = this,
                options = this.options;
                //self.Update();
                self.CollectInfo();

                //这里考虑遍历this.options.Widgets并保存,目前是放在widget中保存的,注意可能出现widget(新增)保存中,已经获取contentJSON的情况
                var parameters = [options.ReportPageId, options.Name, options.ContentJson, options.Setting];
                var dataParameters = { MethodAlias: "MFRB_UpdateReportPage", Parameter: parameters };
                AjaxRequest(ajaxSecureUnlockHandler, dataParameters, function (result) {
                    self.needSave = false;
                    if (typeof callback === ‘function‘) {
                        callback();
                    }
                });
            },
            RefreshPageHeaderFooter: function () {

            },
            //将内容改变更新至option
            CollectInfo: function () {
                var self = this,
                options = this.options;
                if (this.needCollect) {
                    //用于同步更新自身(workspace)状态
                    var contentObj = this.GetContentObj();
                    if (contentObj && contentObj.content) {
                        options.ContentJson = JSON2.stringify(contentObj.content);
                        //options.Widgets = contentObj.widgets;
                        if (this.originalOption) {
                            this.originalOption.ContentJson = JSON2.stringify(contentObj.content);
                            //this.originalOption.Widgets = contentObj.widgets;
                        }
                    }
                    this.needCollect = false;
                }
            },
            ReCreate: function () {
                this.CollectInfo();
                var opt = this.originalOption;
                this.element.WFCWorkspace(‘destroy‘).prop(‘wsOption‘, opt).WFCWorkspace(opt);
            }
        })
    })(jQuery);

    /* WFCWidget define */

    (function ($) {
        //调用各widget自定义的方法

        var WidgetKind = {
            singleFund: 1,
            multiFund: 2,
            portfolio: 3//(单)组合
        }

        //所有Widget定义都需要在此注册,并放在WFCFrame.Widgets命名空间下
        var WidgetDefine = {
            601: ‘FundPerformanceYieldChart‘
                            , 602: ‘FundPerformanceNetValueTable‘
                            , 603: ‘TextWidget‘
                            , 604: ‘ImageWidget‘
                            , 605: ‘FundHoldingStockStyle‘
                            , 606: ‘FundRiskAnalysisTable‘
                            , 607: ‘FundHeavilyStorehouseSecurity‘
                            , 608: ‘FundBasicInformation‘
                            , 609: ‘FundAssetAllocationChart‘
                            , 610: ‘PageNumber‘
                            , 611: ‘EmptyWidget‘
                            , 612: ‘FundHoldingAssetsConfigurationPie‘
                            , 613: ‘PurchaseInfomation‘
                            , 614: {
                                typeName: ‘GeneralReadonlyTextWidget‘,
                                option: {
                                    MethodAlias: ‘MFRB_GetInvestmentTargetData‘,
                                    Params: function (opts) {
                                        return [opts.setting.majorWindCode, opts.setting.endTime]
                                    },
                                    SettingProperty: {
                                        majorWindCode: null,
                                        title: ‘投资目标‘,
                                        hideHead: null
                                    }
                                }
                            }
                            , 615: ‘FundHistoricalReturnTable‘
                            , 616: ‘FundManagerChange‘
                            , 617: {
                                    //单基金-市场展望
                                    typeName: ‘GeneralReadonlyTextWidget‘,
                                    option: {
                                        MethodAlias: ‘MFRB_GetFundMarketOverlookData‘,
                                        Params: function (opts) {
                                            return [opts.setting.majorWindCode, opts.setting.endTime]
                                        },
                                        SettingProperty: {
                                            majorWindCode: null,
                                            title: ‘市场展望‘,
                                            hideHead: null
                                        }
                                }
                            }
                            , 618: {
                                typeName: ‘GeneralTableWidget‘,
                                option: {
                                    MethodAlias: ‘MFRB_GetFundHistoricalScaleTableData‘,
                                    Params: function (opts) {
                                        return [opts.setting.majorWindCode, opts.setting.beginTime, opts.setting.endTime]
                                    },
                                    SettingProperty: {
                                        title: ‘历年规模‘,
                                        hideHead: null,
                                        timeRange: null,
                                        showTimeRangeLabel: 1,
                                        dataColumns: {
                                            opts: [[
                                                { display: ‘报告期‘, name: ‘ReportDate‘, width: ‘60px‘, align: ‘left‘, essential: true }
                                                , { display: ‘资产净值(亿元)‘, name: ‘NetAsset‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘资产总值(亿元)‘, name: ‘TotalAsset‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘基金份额(百万份)‘, name: ‘Share‘, width: ‘30px‘, align: ‘right‘ }
                                            ]]
                                        },
                                        majorWindCode: null
                                    }
                                }
                            }
                            , 619: {
                                typeName: ‘FundHistoricalScaleChart‘,
                                option: {
                                    WidgetKind: 1
                                }
                            }
                            , 620: ‘FundHistoricalReturnChart‘
                            , 621: ‘FundHoldingAssetsConfigurationArea‘
                            , 622: ‘FundHoldingAssetsConfigurationTable‘
                            , 623: ‘PageHeaderFooterText‘
                            , 624: ‘FundMarket‘
                            , 625: ‘FundIndustDistribChart‘
                            , 626: ‘FundIndustDistribTable‘
                            , 627: {
                                //多基金-业绩表现(表格):
                                typeName: ‘GeneralTableWidget‘,
                                option: {
                                    MethodAlias: ‘MFRB_GetMultiFundPerformanceData‘,
                                    Params: function (opts) {
                                        var setting = opts.setting;
                                        var benchmarkCode = setting.benchmarks && setting.benchmarks.length ? setting.benchmarks[0].windCode : ‘‘;
                                        return [JSON2.stringify({
                                            windCodes: setting.windCodes,
                                            beginTime: setting.beginTime,
                                            calcCycle: setting.calcCycle,
                                            endTime: setting.endTime,
                                            benchmarkCode: benchmarkCode,
                                            yieldCalMethod: setting.yieldCalMethod
                                        })];
                                    },
                                    SettingProperty: {
                                        title: ‘业绩表现‘,
                                        hideHead: null,
                                        timeRange: null,
                                        showTimeRangeLabel: 1,
                                        yieldCalMethod: 1,
                                        calcCycle: 2,
                                        dataColumns: {
                                            opts: [/*[{ cs: 2, display: ‘种类‘ }, { cs: 3, display: ‘数据‘ }],*/[
                                                        { display: ‘基金名称‘, name: ‘Name‘, width: ‘60px‘, align: ‘left‘, essential: true }
                                                        , { display: ‘基金类型‘, name: ‘InvestType‘, width: ‘30px‘, align: ‘right‘ }
                                                        , { display: ‘收益率%‘, name: ‘AdjustedReturn‘, width: ‘30px‘, align: ‘right‘ }
                                                        , { display: ‘超额回报%‘, name: ‘ExcessReturn‘, width: ‘30px‘, align: ‘right‘ }
                                                        , { display: ‘标准差‘, name: ‘Stdev‘, width: ‘30px‘, align: ‘right‘ }
                                                        , { display: ‘夏普比‘, name: ‘Sharpe‘, width: ‘30px‘, align: ‘right‘ }
                                                        , { display: ‘下行风险‘, name: ‘DownsideRisk‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘信息比‘, name: ‘InfoRatio‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘索丁诺比‘, name: ‘Sortino‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘Alpha‘, name: ‘Alpha‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘Beta‘, name: ‘Beta‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘R平方‘, name: ‘R2‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘跟踪误差‘, name: ‘TrackError‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                            ]]
                                        }
                                    }
                                }
                            }
                            , 628: {
                                //多基金表格控件:相关系数
                                typeName: ‘MultiFundCorrelationCoefficient‘
                            }
                            , 629: {
                                //多基金-基本信息
                                typeName: ‘GeneralTableWidget‘,
                                option: {
                                    MethodAlias: ‘MFRB_GetMultiFundInformationData‘,
                                    Params: function (opts) {
                                        return [opts.setting.windCodes, opts.setting.endTime];
                                    },
                                    SettingProperty: {
                                        title: ‘基本信息‘,
                                        hideHead: null,
                                        dataColumns: {
                                            opts: [[
                                                        { display: ‘基金名称‘, name: ‘Name‘, width: ‘60px‘, align: ‘left‘, essential: true }
                                                        , { display: ‘证券代码‘, name: ‘Code‘, width: ‘30px‘, align: ‘right‘ }
                                                        , { display: ‘基金成立日‘, name: ‘SetupDate‘, width: ‘30px‘, align: ‘right‘ }
                                                        , { display: ‘基金类型‘, name: ‘InvestType‘, width: ‘30px‘, align: ‘right‘ }
                                                        , { display: ‘在管资产 (亿元)‘, name: ‘NetAsset‘, width: ‘45px‘, align: ‘right‘ }
                                                        , { display: ‘最新净值‘, name: ‘Unit‘, width: ‘30px‘, align: ‘right‘ }
                                                        , { display: ‘基金经理‘, name: ‘FundManager‘, width: ‘45px‘, align: ‘right‘ }
                                                        , { display: ‘Wind综合评级‘, name: ‘WindAvg‘, width: ‘45px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘申赎状态‘, name: ‘Status‘, width: ‘60px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘净值币种‘, name: ‘Navcur‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘投资风格‘, name: ‘InvestStyle‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘业绩比较基准‘, name: ‘Benchmark‘, width: ‘60px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘前端认购费‘, name: ‘SubScriptionFeeBefore‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘后端认购费‘, name: ‘SubScriptionFeeAfter‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘前端申购费‘, name: ‘PurChaseFeeBefore‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘后端申购费‘, name: ‘PurChaseFeeAfter‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘管理费‘, name: ‘ManagementFeeRatio‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘托管费‘, name: ‘CustodianFeeRatio‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘销售服务费‘, name: ‘SaleFeeRatio‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘管理人‘, name: ‘MgrComp‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                        , { display: ‘托管人‘, name: ‘CustodianBank‘, width: ‘30px‘, align: ‘right‘, hide: true }

                                            ]]
                                        }
                                    }
                                }
                            }
                            , 630: {
                                typeName: ‘FundPerformanceYieldChart‘,
                                option: {
                                    WidgetKind: 2
                                }
                            }
                            , 631: {
                                typeName: ‘FundHistoricalReturnChart‘,
                                option: {
                                    WidgetKind: 2
                                }
                            }
                            , 632: {
                                //多基金-阶段表现(表格)
                                typeName: ‘GeneralTableWidget‘,
                                option: {
                                    MethodAlias: ‘MFRB_GetMultiFundStagePerformanceTableData‘,
                                    Params: function (opts) {
                                        var peerGroupIndexName = opts.setting.peerGroupIndex ? opts.setting.peerGroupIndex.name : ‘‘;
                                        var benchmarkCode = opts.setting.benchmarks && opts.setting.benchmarks.length ? opts.setting.benchmarks[0].windCode : ‘‘;
                                        return [opts.setting.windCodes, benchmarkCode, peerGroupIndexName, opts.setting.endTime];
                                    },
                                    SettingProperty: {
                                        title: ‘阶段表现‘,
                                        hideHead: null,
                                        endTime: null,
                                        showTimeRangeLabel: 1,
                                        dataColumns: {
                                            opts: [[
                                                { display: ‘‘, name: ‘name‘, width: ‘60px‘, align: ‘left‘, essential: true }
                                                , { display: ‘1月‘, name: ‘oneMonth‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘3月‘, name: ‘threeMonth‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘6月‘, name: ‘sixMonth‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘YTD‘, name: ‘yTD‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘1年‘, name: ‘oneYear‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘3年‘, name: ‘threeYear‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘5年‘, name: ‘fiveYear‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘成立以来‘, name: ‘sinceEstablish‘, width: ‘30px‘, align: ‘right‘ }
                                            ]]
                                        }
                                    }
                                }
                            }
                            , 633: {
                                //单基金-阶段表现(图形)
                                typeName: ‘FundStagePerformanceChart‘,
                                option: {
                                    WidgetKind: 1
                                }
                            }
                            , 634: {
                                //多基金-阶段表现(图形)
                                typeName: ‘FundStagePerformanceChart‘,
                                option: {
                                    WidgetKind: 2
                                }
                            }
                            , 635: {
                                //多基金-历年规模(图形)
                                typeName: ‘FundHistoricalScaleChart‘,
                                option: {
                                    WidgetKind: 2
                                }
                            }
                            , 636: {
                                typeName: ‘FundRiskReturnChart‘
                            }
                            , 637: {
                                //多基金-资产配置(图形)
                                typeName: "MultiFundAssetAllocationChart"
                            }
                            , 638: {
                                //多基金-资产配置(表格)
                                typeName: ‘GeneralTableWidget‘,
                                option: {
                                    MethodAlias: ‘MFRB_GetMultiFundAssetAllocationTableData‘,
                                    Params: function (opts) {
                                        return [opts.setting.windCodes, opts.setting.reportPeriod];
                                    },
                                    SettingProperty: {
                                        title: ‘资产配置‘,
                                        hideHead: null,
                                        reportPeriod: null,
                                        showTimeRangeLabel: 1,
                                        dataColumns: {
                                            opts: [[
                                                { display: ‘‘, name: ‘name‘, width: ‘60px‘, align: ‘left‘, essential: true }
                                                , { display: ‘股票%‘, name: ‘stock‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘债券%‘, name: ‘bond‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘基金%‘, name: ‘fund‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘现金%‘, name: ‘money‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘其他%‘, name: ‘other‘, width: ‘30px‘, align: ‘right‘ }
                                            ]]
                                        }
                                    }
                                }
                            }
                            , 639: {
                                //多基金-持有人结构(图形)
                                typeName: ‘FundShareholderStructureChart‘
                            }
                            , 640: {
                                //多基金-行业配置(表格)
                                typeName: ‘MultiFundSectorAllocationTable‘
                            }
                            , 641: {
                                //多基金-风险分析(图)
                                typeName: "FundHistoricalRiskAnalysisChart"
                            }
                            , 642: {
                                //多基金-风险分析(表)
                                typeName: ‘GeneralTableWidget‘,
                                option: {
                                    MethodAlias: ‘MFRB_GetMultiFundIndicatorsData‘,
                                    Params: function (opts) {
                                        var setting = opts.setting;
                                        var cols = setting.dataColumns || opts.SettingProperty.dataColumns.opts;
                                        var indicator = ‘‘;
                                        if (cols && cols.length > 0 && cols[0].length > 0) {
                                            $.each(cols[0], function (index, item) {
                                                if (item.name != ‘name‘ && !item.hide) {
                                                    indicator += item.name + ‘,‘;
                                                }
                                            });
                                            if (indicator.length > 0) {
                                                indicator = indicator.substring(0, indicator.length - 1);
                                            } else {
                                                indicator = ‘f_info_firstinvesttype,f_risk_annustdev,f_risk_downsidestdev,f_risk_maxdownside,f_risk_annualpha,f_risk_beta,f_risk_r2,f_risk_annusharpe,f_risk_annutreynor,f_risk_annusortino,f_risk_annuinforatio‘;
                                            }
                                        }

                                        return [JSON2.stringify({
                                            windCodes: setting.windCodes, beginTime: setting.beginTime, calcCycle: setting.calcCycle
                                            , endTime: setting.endTime, benchmarkCode: setting.benchmarks && setting.benchmarks.length ? setting.benchmarks[0].windCode : ‘‘,
                                            yieldCalMethod: setting.yieldCalMethod
                                        }), indicator];
                                    },
                                    SettingProperty: {
                                        title: ‘风险分析‘,
                                        hideHead: null,
                                        timeRange: null,
                                        showTimeRangeLabel: 1,
                                        yieldCalMethod: 1,
                                        calcCycle: 2,
                                        dataColumns: {
                                            opts: [[
                                                { display: ‘名称‘, name: ‘Name‘, width: ‘60px‘, align: ‘left‘, essential: true }
                                                , { display: ‘基金类型‘, name: ‘f_info_firstinvesttype‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘标准差‘, name: ‘f_risk_annustdev‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘下行标准差‘, name: ‘f_risk_downsidestdev‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘最大回撤‘, name: ‘f_risk_maxdownside‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘Alpha‘, name: ‘f_risk_annualpha‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘Beta‘, name: ‘f_risk_beta‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘R平方‘, name: ‘f_risk_r2‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘夏普比‘, name: ‘f_risk_annusharpe‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘特雷诺比‘, name: ‘f_risk_annutreynor‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                , { display: ‘索丁诺比‘, name: ‘f_risk_annusortino‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                                , { display: ‘信息比‘, name: ‘f_risk_annuinforatio‘, width: ‘30px‘, align: ‘right‘, hide: true }
                                            ]]
                                        }
                                    }

                                }
                            }
                            , 643: {
                                //多基金-重仓证券(表)
                                typeName: "MultiFundTopHoldingsTable"
                            }
                            , 644: {
                                //多基金-市场绩效
                                typeName: ‘GeneralTableWidget‘,
                                option: {
                                    MethodAlias: ‘MFRB_GetMultiFundMarketPerformanceTableData‘,
                                    Params: function (opts) {
                                        var setting = opts.setting;
                                        return [setting.windCodes, setting.beginTime, setting.endTime];
                                    },
                                    SettingProperty: {
                                        title: ‘市场绩效‘,
                                        hideHead: null,
                                        timeRange: null,
                                        showTimeRangeLabel: 1,
                                        dataColumns: {
                                            opts: [[
                                                { display: ‘名称‘, name: ‘name‘, width: ‘60px‘, align: ‘left‘, essential: true }
                                                , { display: ‘基金类型‘, name: ‘investType‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘一年以来涨跌幅‘, name: ‘adjustedReturn‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘上涨月份平均收益‘, name: ‘avgIncome‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘下跌月份平均收益‘, name: ‘avgLoss‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘上涨期间百分比‘, name: ‘profitMonthPer‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘下跌期间百分比‘, name: ‘lossMonthPer‘, width: ‘30px‘, align: ‘right‘ }
                                                , { display: ‘最高单月回报‘, name: ‘highestMonthlyReturn‘, width: ‘40px‘, align: ‘right‘ }
                                                , { display: ‘最低单月回报‘, name: ‘lowestMonthlyReturn‘, width: ‘40px‘, align: ‘right‘ }
                                                , { display: ‘最高季度回报‘, name: ‘highestQuarterlyReturn‘, width: ‘40px‘, align: ‘right‘ }
                                                , { display: ‘最低季度回报‘, name: ‘lowestQuarterlyReturn‘, width: ‘40px‘, align: ‘right‘ }
                                            ]]
                                        }
                                    }
                                }
                            }
                            , 645: {
                                typeName: "FundAlphaComparisonChart"
                            }
                            , 646: {
                                typeName: "GeneralReadonlyTextWidget",
                                option: {
                                    MethodAlias: ‘MFRB_GetFundAnalysisComment‘,
                                    Params: function (opts) {
                                        return [JSON2.stringify({
                                            windCode: opts.setting.majorWindCode,
                                            endTime: opts.setting.endTime
                                        })];
                                    },
                                    SettingProperty: {
                                        majorWindCode: null,
                                        title: ‘分析评论‘,
                                        hideHead: null
                                    },
                                    ProcessData: function (analysisCommentInfo) {
                                        function compare2(num1, num2) {
                                            return (num1 > num2) ? "高于" : ((num1 == num2) ? "等于" : "低于");
                                        }
                                        var descri = ‘‘;
                                        if (analysisCommentInfo != null && typeof (analysisCommentInfo) === ‘object‘) {
                                            descri = "<p>" + analysisCommentInfo.FundName + "从" + analysisCommentInfo.FoundDate + "成立以来," +
           "已取得" + analysisCommentInfo.AllReturn + "%的收益," + compare2(analysisCommentInfo.AllReturn, analysisCommentInfo.SameTypeReturn) + "同类平均水平,同类排名" + analysisCommentInfo.SameTypeRank + ",期间资产净值" + analysisCommentInfo.AssetsChange + "。</p><p>" +
           "从各区间表现看,该基金今年以来表现" + analysisCommentInfo.YearPerformance + ",收益率" + analysisCommentInfo.Yield + ",同类排名" + analysisCommentInfo.YearRank + ";1年收益率" + analysisCommentInfo.YearYield + ",同类排名" + analysisCommentInfo.YearYieldSameTypeRank + ";" +
           "3年收益" + analysisCommentInfo.ThreeYearYield + ",同类排名" + analysisCommentInfo.ThreeYearYieldSameTypeRank + ";5年收益" + analysisCommentInfo.FiveYearYield + ",同类排名" + analysisCommentInfo.FiveYearYieldSameTypeRank + "。</p><p>" + analysisCommentInfo.RiskDescription + "</p>";
                                        }
                                        return descri;
                                    }
                                }
                            }
        };
        $.widget(‘wfc.WFCWidget‘, {
            version: ‘2.0‘,
            options: {
                //这里一般不要放任何设置
                //callbacks
                Update: null, //widget内容、设置更新时
                Complete: null//widget内容加载完成后
            },
            _createWidget: function (option, element) {
                //element.prop(‘WFCWidgetOption‘, option);//这句会导致bug
                this._super(option, element);
            },
            childWidget: null, //实现具体业务逻辑的widget子类,后来是用子类扩展本身,所以子类=本身
            typeName: ‘‘, //childWidget的类名
            defaultSetting: {},
            _create: function () {
                var self = this,
                options = this.options,
                $divWidget = this.element,
                isHF = $divWidget.closest(‘.pageHeader,.pageFooter‘).length > 0;
                if (WidgetDefine.hasOwnProperty(options.type)) {
                    var wDefine = WidgetDefine[options.type];
                    if (typeof wDefine === ‘object‘ && wDefine.typeName) {
                        this.typeName = wDefine.typeName;
                        $.extend(options, wDefine.option);
                    } else if (typeof wDefine === ‘string‘) {
                        this.typeName = wDefine;
                    }
                    if (this.typeName && WFCFrame.Widgets.hasOwnProperty(this.typeName)) {
                        this.childWidgetFunc = WFCFrame.Widgets[this.typeName];
                    }
                }

                //if (this.childWidgetFunc) {
                //    this.childWidget = new this.childWidgetFunc(self); //eval(‘ new WFCFrame.Widgets.‘ + this.typeName + ‘(self) ;‘);
                //}
                $divWidget.attr(‘widget-state‘, ‘init‘);
                if (this.typeName)
                    $divWidget.addClass(‘widget win-‘ + this.typeName);

                /* 处理options */

                //优先级:Report.SettingProperty < Widget.SettingProperty < Report.SettingObj < Widget.setting
                if (this.childWidgetFunc) {
                    this.defaultOption = typeof this.childWidgetFunc.defaultOption == ‘function‘ ? this.childWidgetFunc.defaultOption(this) : $.extend(true, {}, this.childWidgetFunc.defaultOption);
                } else if (!this.defaultOption) {
                    this.defaultOption = {};
                }

                replaceSettingPropertyGroup(options.SettingProperty);
                replaceSettingPropertyGroup(this.defaultOption.SettingProperty);

                //options.SettingProperty = $.extend({}, options.SettingProperty, this.defaultOption.SettingProperty);
                options.SettingProperty = mergeSettingProperty(options.SettingProperty, this.defaultOption.SettingProperty);
                //这里的setting应通过workspace获取,而不是report,待修改
                var SettingPropertyMerged = mergeSettingProperty({}, WFCFrame.Report.SettingProperty, options.SettingProperty);
                //将合并后的SettingProperty填入options.SettingProperty,以形成widget可设置的SettingProperty最终版
                $.each(options.SettingProperty, function (index, item) {
                    if (typeof item === ‘undefined‘ || item === null) {
                        options.SettingProperty[index] = SettingPropertyMerged[index];
                    }
                });

                //因为fillSettingBySettingProperty是直接赋值,所以不用担心复杂类型的setting值被篡改
                this.defaultSetting = $.extend({}, WFCFrame.Report.SettingObj, this.defaultOption ? this.defaultOption.setting : null);
                fillSettingBySettingProperty(this.defaultSetting, SettingPropertyMerged);

                //以后添加:将默认值传到widget.SettingProperty但不扩展widget.SettingProperty的属性
                //为方便使用,需要保存一份组合后的setting,但同时也要保存一份组合前的Option以区分开继承设置还是本身的设置
                options.setting = fillDefalutProperty(options.setting, this.defaultSetting); //$.extend({}, this.defaultSetting, options.setting);
                this.options = fillDefalutProperty(options, this.defaultOption); //浅层复制,应用默认option(除SettingProperty和setting(之前已合并)),另childWidgetFunc.defaultOption是否有存在必要?

                /* 处理options  end*/

                var setting = options.setting;
                /* 设置预处理 */

                if (setting.products && setting.products.length > 0) {
                    if (setting.majorWindCode) {
                        var isfound = false;
                        $.each(setting.products, function (index, item) {
                            if (item.windCode === setting.majorWindCode) {
                                isfound = true;
                                setting.majorProduct = item;
                                return false;
                            }
                        });
                        if (!isfound) {
                            setting.majorProduct = setting.products[0];
                            setting.majorWindCode = setting.products[0].windCode;
                        }
                    } else {
                        setting.majorProduct = setting.products[0];
                        setting.majorWindCode = setting.products[0].windCode;
                    }

                    setting.windCodes = setting.products[0].windCode;
                    for (var i = 1; i < setting.products.length; i++) {
                        setting.windCodes += "," + setting.products[i].windCode;
                    }
                }
                setting.majorWindCode = setting.majorWindCode || ‘000001.OF‘;
                //var majorProduct = setting.products && setting.products[0];
                //var majorWindCode = (setting.majorProduct && setting.majorProduct.windCode) || ‘000001.OF‘;
                var majorWindCode = setting.majorWindCode;//还是用windcode以保证颜色等设置一致
                WFCFrame.GetProductInfo([majorWindCode], function (infos) {
                    var foundingDate = "1900-01-01";
                    if (infos && infos.hasOwnProperty(majorWindCode)) {
                        foundingDate = infos[majorWindCode].FoundingDate;
                    }

                    if (setting.timeRange) {
                        var range = getTimeRange(setting.timeRange, foundingDate);
                        if (range) {
                            setting.beginTime = range.beginTime;
                            setting.endTime = range.endTime;
                        }
                    }

                    if (!setting.endTime) {
                        setting.endTime = (new Date()).format(‘yyyy-MM-dd‘);
                    }
                    if (!setting.beginTime || (setting.beginTime < foundingDate)) {
                        setting.beginTime = foundingDate;
                    }
                    if (!setting.reportPeriod) {
                        setting.reportPeriod = setting.endTime;
                    }
                    self._createAfter();
                })
                /* end of 设置预处理 */
            },
            //预处理结束后调用此方法create
            _createAfter: function () {
                var self = this,
                options = this.options,
                $divWidget = this.element,
                isHF = $divWidget.closest(‘.pageHeader,.pageFooter‘).length > 0,
                setting = options.setting;

                var objSetting = {
                    showTimeRangeLabel: setting.showTimeRangeLabel,
                    beginTime: setting.beginTime,
                    endTime: setting.endTime,
                    reportPeriod: setting.reportPeriod
                };
                $divWidget.append(‘<div class="widget-head ui-widget-header ui-corner-top ui-helper-clearfix">‘
                + ‘<span class="ui-dialog-title">‘ + (setting.title || ‘&nbsp;‘) + ‘</span>‘ + ‘<span class="timeRangeLabel">‘ + getTimeRangeLabelText(objSetting) + ‘</span>‘

                //+ ‘<div class="head-divider"></div>‘
                + ‘</div>‘
                + ‘<div class="widget-content ui-widget-content">‘);
                //操作菜单现在dom结构上与widget-head平行
                $divWidget.append(‘<span class="widget-head-operation">‘
                    + ‘<ul class="head-menuBar-custom"></ul>‘
                    + ‘<ul class="head-menuBar-system">‘
                    + ‘<li class="widget-setting" title="设置" style="display:none"><span class="ui-icon"></span></li>‘
                    + ‘<li class="widget-close"><span class="iconfont">&#xe602;</span></li>‘//
                    + ‘</ul>‘
                + ‘</span>‘);

                //应用设置(setting)
                if (isHF || setting.hideHead) {
                    $divWidget.addClass(‘hideHead‘);
                }
                //css方法传入‘‘会删除此属性,传入null/undefined等于不做设置
                if (!isHF) {
                    $divWidget.find(‘.widget-head‘).css({
                        fontFamily: setting.titleStyle_fontFamily || ‘‘,
                        fontSize: setting.titleStyle_fontSize || ‘‘,
                        height: setting.titleStyle_fontSize || ‘‘, //解决workspace hidden时初始化title高度获取不正确的问题
                        color: setting.titleStyle_fontColor || ‘‘,
                        backgroundColor: setting.titleStyle_bgColor || ‘‘,
                        borderTopWidth: setting.titleStyle_dividerLineWidth || ‘‘,
                        borderTopColor: setting.titleStyle_dividerLineColor || ‘‘
                    });

                    var inC = inverseColor(setting.titleStyle_bgColor || ‘‘);
                    $divWidget.find(‘.widget-head-operation‘).css({
                        color: inC
                    });

                    //                $divWidget.find(‘.head-divider‘).css({
                    //                    height: setting.titleStyle_dividerLineWidth || ‘2px‘,
                    //                    background: setting.titleStyle_dividerLineColor || ‘#EEEEEE‘
                    //                });
                }

                $divWidget.find(‘.widget-content‘).css({
                    top: $divWidget.find(‘.widget-head‘).outerHeight(true) + ‘px‘,
                    fontFamily: setting.fontFamily || ‘‘,
                    fontSize: setting.fontSize || ‘‘,
                    color: setting.fontColor || ‘‘,
                    textAlign: setting.textAlign || ‘‘
                });

                if (!isHF) {
                    $divWidget.find(‘.widget-content‘).css({
                        borderWidth: setting.contentStyle_borderWidth || ‘‘,
                        borderColor: setting.contentStyle_borderColor || ‘‘,
                        borderStyle: setting.contentStyle_borderStyle || ‘‘,
                        backgroundColor: setting.contentStyle_fillColor || ‘‘
                    });
                }


                //                $divWidget.find(‘.widget-head-operation‘).click(function (event) {
                //                    event.stopPropagation();
                //                });

                if (!setting.uncloseable) {//删除使用drop方式
                    $divWidget.find(‘.widget-close‘).click(function (event) {
                        var $w = $(this).closest(‘.widget‘);
                        var $c = $w.parent();
                        removeContainer($c);
                        event.stopPropagation();
                    });
                }

                this.content = $divWidget.find(‘.widget-content‘);
                this.title = $divWidget.find(‘.widget-head >.ui-dialog-title‘);
                if (this.childWidgetFunc) {
                    //this.childWidget = new this.childWidgetFunc(self); //eval(‘ new WFCFrame.Widgets.‘ + this.typeName + ‘(self) ;‘);
                    this.childWidgetFunc.call(this, self);
                    for (var func in this.childWidgetFunc.prototype) {
                        if (!self[func]) {
                            self[func] = this.childWidgetFunc.prototype[func];
                        }
                    }
                    this.callWidgetCustomFunc(‘Init‘);
                }
                var widgetState = $divWidget.attr(‘widget-state‘);
                if (widgetState == ‘init‘) {
                    //说明没有调用待ajax的getData
                    this.Complete();
                }
            },
            _init: function () {
            },
            _destroy: function () {
                this.callWidgetCustomFunc(‘destroy‘);
                this.element.removeProp(‘WFCWidgetOption‘).removeClass(‘hideHead widget win-‘ + this.typeName).empty(); //remove widget div时,会自动调用,因此其实这里可以不调用,且removeWidget时也不必显式调用destroy
            },
            callWidgetCustomFunc: function (funName, args) {
                //try {
                //                    if (this.childWidget && typeof (this.childWidget[funName]) == ‘function‘) {
                //                        this.childWidget[funName]();
                //                    }
                if (this.childWidgetFunc && typeof this.childWidgetFunc.prototype[funName] == ‘function‘) {
                    this.childWidgetFunc.prototype[funName].apply(this, args || []); //ie8下args不可传null
                }
                //}
                //catch (e) {
                //    showDebugMsg(‘widget(‘ + this.typeName + ‘).‘ + funName + ‘调用出错:‘ + e.message);
                //}
            },
            Resize: function () {
                this.callWidgetCustomFunc(‘Resize‘);
            },
            Refresh: function () {
                this.callWidgetCustomFunc(‘Refresh‘);
            },
            ReCreate: function () {
                var opt = this.OriginalOption();
                this.element.WFCWidget(‘destroy‘).prop(‘WFCWidgetOption‘, opt).WFCWidget(opt);
            },
            Complete: function () {
                //表示控件已经载入完成,包括ajax和数据的渲染
                if (this.element.attr(‘widget-state‘) != ‘complete‘) {
                    this.element.attr(‘widget-state‘, ‘complete‘);
                    this._trigger("Complete", null, null);
                }
            },
            GetData: function () {
                this.element.attr(‘widget-state‘, ‘getData‘);
                this.callWidgetCustomFunc(‘GetData‘, arguments);
            },
            BindData: function () {
                this.callWidgetCustomFunc(‘BindData‘, arguments);
                this.Complete(); //如果因为数据原因没有走到这里,说明ajax出现问题
            },
            CreateChart: function ($dom, chartOpt, callback) {
                var self = this;
                var setting = self.options.setting || {};
                var _alternateGridColor;
                //判断色彩若为白色则使用默认色为间隔色
                if (ColorHelper.isEqualColor(setting.contentStyle_fillColor, "#ffffff")) {
                    _alternateGridColor = "#f5f5f5";
                } else {
                    _alternateGridColor = ColorHelper.fadeColor(setting.contentStyle_fillColor, 0.7);
                }
                chartOpt = $.extend(true, {
                    chart: {
                        backgroundColor: setting.contentStyle_fillColor,
                        type: setting.chartType
                    },
                    yAxis: {
                        alternateGridColor: _alternateGridColor
                    }
                }, chartOpt);
                //x轴label旋转
                var xAxisLabelRotation = parseFloat(setting.xAxisLabelRotation);
                if (!isNaN(xAxisLabelRotation)) {
                    $.extend(true, chartOpt, {
                        xAxis: {
                            labels: {
                                rotation: xAxisLabelRotation
                            }
                        }
                    });
                }
                //x轴刻度间隔
                var xAxisLabelStep = parseFloat(setting.xAxisLabelStep);
                if (!isNaN(xAxisLabelStep)) {
                    $.extend(true, chartOpt, {
                        xAxis: {
                            tickInterval: xAxisLabelStep
                            //labels: {
                            //    step: xAxisLabelStep
                            //}
                        }
                    });
                }
                if (chartOpt && chartOpt.series && chartOpt.series.length) {
                    var products = setting.products || {};
                    var benchmarks = setting.benchmarks || {};
                    var peerGroupIndex = setting.peerGroupIndex || {};
                    var item = null, itemFind = null;
                    for (var j = 0; j < chartOpt.series.length; j++) {
                        item = chartOpt.series[j];
                        itemFind = null;
                        if (itemFind == null && item.name === "同类平均" || item.name === peerGroupIndex.name || item.windCode === peerGroupIndex.code) {
                            itemFind = peerGroupIndex;
                        }
                        if (itemFind == null && item.windCode) {
                            for (var i = 0; i < products.length; i++) {
                                if (item.windCode === products[i].windCode && products[i].color) {
                                    itemFind = products[i];
                                    break;
                                }
                            }
                        }

                        if (itemFind == null && item.windCode) {
                            for (var i = 0; i < benchmarks.length; i++) {
                                if (item.windCode === benchmarks[i].windCode && benchmarks[i].color) {
                                    itemFind = benchmarks[i];
                                    break;
                                }
                            }
                        }

                        if (itemFind != null) {
                            if (itemFind.hide) {
                                item.enabled = false;
                            }
                            else if (!item.color) {
                                item.color = itemFind.color;
                            }
                        }
                    }
                    //过滤掉隐藏的serie数据
                    chartOpt.series = $.grep(chartOpt.series, function (n, i) {
                        return n.enabled != false;
                    });
                }

                if (setting.chartType == "bar") {
                    //legend位置1的在最上面
                    reverseChartSeriesIndex(chartOpt.series);
                    //时间序列从下往上排列
                    if (chartOpt && chartOpt.xAxis && chartOpt.xAxis.type == ‘datetime‘ && !chartOpt.xAxis.hasOwnProperty(‘reversed‘)) {
                        chartOpt.xAxis.reversed = false;
                    }
                } else if (setting.chartType == "area") {
                    //area图进行特殊处理,stacking为percent的图需要颠倒series里项顺序,其他面积图除了第一个sery以area展示,其他sery以line图展示
                    if (chartOpt && chartOpt.plotOptions && chartOpt.plotOptions.area && chartOpt.plotOptions.area.stacking === "percent") {
                        reverseChartSeriesIndex(chartOpt.series);
                    } else {
                        //将除了第一个之外的sery展示修改为line
                        $.each(chartOpt.series, function (index, item) {
                            if (index === 0) {
                                //面积图增加色彩渐变
                                //Y轴上方渐变
                                item.fillColor = {
                                    linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
                                    stops: [
                                        [0, ColorHelper.fadeColor(item.color, 0.8)],
                                        [0.1, ColorHelper.fadeColor(item.color, 0.6)],
                                        [0.5, ColorHelper.fadeColor(item.color, 0.4)],
                                        [1, ColorHelper.fadeColor(item.color, 0.1)]
                                    ]
                                };
                                //Y轴下方渐变
                                item.negativeColor = {
                                    linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
                                    stops: [
                                        [0, ColorHelper.fadeColor(item.color, 0.1)],
                                        [0.1, ColorHelper.fadeColor(item.color, 0.4)],
                                        [0.5, ColorHelper.fadeColor(item.color, 0.6)],
                                        [1, ColorHelper.fadeColor(item.color, 0.8)]
                                    ]
                                };
                            } else {
                                item.type = "line";
                            }
                        });
                    }
                } else if (setting.chartType == "column" && chartOpt && chartOpt.plotOptions && chartOpt.plotOptions.column && (chartOpt.plotOptions.column.stacking == "normal" || chartOpt.plotOptions.column.stacking == "percent")) {
                    reverseChartSeriesIndex(chartOpt.series);
                }

                if ($dom instanceof jQuery) {
                    $dom.highcharts(chartOpt, callback);
                }
            },
            CreateTable: function ($dom, tableOpt) {
                //option中之保存columnname,完整信息放在SettingProperty.dataColumns.opts中,在这里组合起来
                //table的刷新与option改变放在哪里?
                var self = this,
                options = this.options,
                setting = options.setting,
                $divWidget = this.element,
                childWidgetFunc = this.childWidgetFunc;
                var optColumns = self.options.SettingProperty && self.options.SettingProperty.dataColumns ? self.options.SettingProperty.dataColumns.opts : null;
                var dataColumns = options.setting && options.setting.dataColumns ? options.setting.dataColumns : null;
                var colMs = tableOpt.colModel || [];

                if (optColumns && optColumns.length > 0) {
                    if (!dataColumns || dataColumns.length === 0) {
                        dataColumns = optColumns;
                    }
                    for (var i = 0; i < dataColumns.length; i++) {
                        if (colMs.length <= i) {
                            colMs.push([]);
                        }
                        //添加必需列
                        $.each(optColumns[i], function (index, item) {
                            if (item.essential) colMs[i].push($.extend({}, item));
                        });
                        if (dataColumns[i] && optColumns[i]) {
                            $.each(dataColumns[i], function (index, item) {
                                $.each(optColumns[i], function (index2, item2) {
                                    if (!item2.essential && !item.hide && item2.name == item.name) {
                                        colMs[i].push($.extend({}, item2, item));
                                        return false;
                                    }
                                });
                            })
                        }
                    }
                }
                var cbComplete = tableOpt.onComplete;
                tableOpt.onComplete = function (grid) {
                    //应用表格样式
                    var $t = $(grid.divGrid);
                    $t.addClass(setting.tableStyle).css({ background: setting.tableBgColor });
                    $t.find(".tbHead").css({
                        background: setting.tableHead,
                        fontWeight: setting.tableHeadFontStyle == 2 ? ‘bold‘ : ‘normal‘,
                        color: setting.tableHeadFontColor
                    });

                    $t.find(".tbBody").css({
                        lineHeight: setting.tableRowHeight
                    });

                    $t.css({
                        borderColor: setting.tableBorderColor
                    });

                    if (setting.tableInterlacedRowBgColor) {
                        $t.find(‘.tbBody .erow‘).css({ background: setting.tableInterlacedRowBgColor });
                    }

                    if (typeof cbComplete === "function") {
                        cbComplete(grid);
                    }

                    self.content.unblock();

                    if (!grid.d) {
                        self.content.block(WFCFrame.GetNoDataBlockOption(‘无数据‘));
                    }

                    self.Complete();
                };

                tableOpt.colModel = colMs;
                $dom.sflexigrid(tableOpt);
            },
            headMenuBarCustom: function () {
                return this.element.find(‘.head-menuBar-custom‘);
            },
            addHeadMenuItem: function (item/*domObj or jqueryObj or htmlString*/) {
                var $li = $(‘<li></li>‘).append(item);
                this.headMenuBarCustom().append($li);
                return $li;
            },
            addHeadHelp: function (helpContent) {
                var $help = $(‘<span class="widget-help" title=""></span>‘);
                this.title.after($help);
                $help.tooltip({
                    tooltipClass: "widget-help-tooltip",
                    content: function () {
                        return "<div class=‘widget-help-content‘>" + helpContent + "</div>";
                    }
                });
            },
            isSelected: function () {
                return this.element.parent().hasClass(‘selected‘);
            },
            SaveSetting: function (objSetting) {
                //修改设置并刷新widget/report
                var self = this;
                var oOption = this.OriginalOption();
                var $div = this.element;
                if (objSetting) {
                    //_setOption会把整个setting覆盖
                    $.extend(true, this.options, { setting: objSetting });
                    $.extend(true, oOption, { setting: objSetting });
                }

                var $pageHeaderFooter = $div.closest(‘.pageHeader,.pageFooter‘);
                if ($pageHeaderFooter.length > 0) {
                    var isPageHeader = $pageHeaderFooter.hasClass(‘pageHeader‘);
                    //这里利用了object引用传递了不同workspace之间相同widget的originalOption(含widgetId)
                    $(‘.workspace ‘ + (isPageHeader ? ‘.pageHeader‘ : ‘.pageFooter‘) + ‘ .container:nth-child(‘ + ($div.parent().index() + 1) + ‘) .widget‘).WFCWidget(‘ReCreate‘);
                }
                else {
                    this.ReCreate();
                }

                this._trigger(‘Update‘, null, { setting: objSetting });
            },
            OriginalOption: function () {
                return this.element.prop(‘WFCWidgetOption‘);
            },
            Workspace: function () {
                return this.element.closest(‘.workspace‘);
            },
            WidgetAjaxRequest: function (url, dataParameters, onSuccess, onError, onComplete) {
                var self = this;
                //方便监控程序监控ajax
                var method = "";
                if (dataParameters)
                    method = dataParameters.MethodAlias;
                $.ajax({
                    url: url + "?method=" + method,
                    type: "POST",
                    data: "data=" + encodeURIComponent(JSON2.stringify(dataParameters)),
                    success: onSuccess,
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        if (typeof (onError) == ‘function‘)
                            onError(XMLHttpRequest, textStatus, errorThrown);
                        else {
                            var errmsg = ‘ajax请求发生错误,url: ‘ + this.url + ‘,data: ‘ + this.data;
                            if (XMLHttpRequest && XMLHttpRequest.readyState >= 3)
                                errmsg += ‘,状态码: ‘ + XMLHttpRequest.status + ‘,返回值: ‘ + XMLHttpRequest.responseText;
                            if (textStatus)
                                errmsg += ‘,textStatus: ‘ + textStatus;
                            if (errorThrown)
                                errmsg += ‘,抛出异常: ‘ + errorThrown.toString();

                            showDebugMsg(errmsg);
                        }
                    },
                    onComplete: function () {
                        if (typeof (onComplete) == ‘function‘)
                            onComplete(arguments);
                        //self.Complete();
                    }
                });
            },
            Select: function () {
                this.callWidgetCustomFunc(‘Select‘);
            },
            UnSelect: function () {
                this.callWidgetCustomFunc(‘UnSelect‘);
            }
        })
    })(jQuery);


    /* 操作区域代码(控件区) */
    function initOperationArea($div, option) {
        $div.prepend(‘<div class="widgetKind-tabs ui-widget-header"><span class="tabs-anchor selected ui-state-active" tabIdnex="1">单基金</span><span class="tabs-anchor last" tabIdnex="2">多基金</span></div>‘);//<span class="tabs-anchor" tabIdnex="3">组合</span>
        var $widgetCaseBox = $div.find(‘.widgetCaseBox‘);
        if (option && option.length > 0) {
            $.each(option, function (index, item) {
                $widgetCaseBox.append(‘<h3>‘ + item.title + ‘</h3>‘);
                if (item.widgets && item.widgets.length) {
                    var $innerDiv = $(‘<div></div>‘);
                    $.each(item.widgets, function (index2, item2) {
                        $innerDiv.append($(‘<a class="widgetCase" tabIndex="‘ + (item2.tabIndex || 0) + ‘"><div class="widget-icon widget-icon-‘ + item2.type + ‘"></div>‘ + item2.title + ‘</a>‘).prop(‘WFCWidgetOption‘, $.extend({ type: item2.type }, item2.opt)));
                    });
                    $innerDiv.append("<div style=‘clear:both;‘></div>");
                    $widgetCaseBox.append($innerDiv);
                }
            });
        }
        $widgetCaseBox.accordion({ heightStyle: ‘fill‘ });

        $widgetCaseBox.find(‘.widgetCase‘).draggable(draggable_option);

        $div.find(‘.widgetKind-tabs > .tabs-anchor‘).mouseover(function () {
            $(this).parent().find(‘.selected‘).removeClass(‘selected ui-state-active‘);
            $(this).addClass(‘selected ui-state-active‘);
            $widgetCaseBox.find(‘.widgetCase‘).hide();
            $widgetCaseBox.find(‘.widgetCase[tabIndex=0],.widgetCase[tabIndex=‘ + $(this).attr(‘tabIdnex‘) + ‘]‘).show();
        });
        $div.find(‘.widgetKind-tabs > .tabs-anchor.selected‘).trigger(‘mouseover‘);
    }
    /*end of 操作区域代码(控件区)*/

    (function () {
        function initSetting(setting/*设置值(合并后)*/, settingProperty/* 设置选项 */, setEnumObj/* 设置初始化函数 */, $setArea/* 设置区域 */, level, target) {
            var setObj = setting || {};
            fillSettingBySettingProperty(setObj, settingProperty);
            $.each(settingProperty, function (index, item) {
                if (setEnumObj[index] && typeof (setEnumObj[index]._init) == ‘function‘) {

                    var $setAorG = $setArea;
                    var settingPropertyItem = item;
                    if ($.type(item) !== ‘object‘) {
                        settingPropertyItem = { dVal: item };
                    }
                    if (settingPropertyItem.groupId) {
                        $setAorG = $setArea.find(‘.sGroup-‘ + settingPropertyItem.groupId);
                        if ($setAorG.length == 0) {
                            $setAorG = $(‘<div class="uiCreate sGroup sGroup-‘ + settingPropertyItem.groupId + ‘"><span class="sGroup-name">‘ + settingPropertyItem.groupText + ‘</span></div>‘).appendTo($setArea);
                        }
                    }

                    var swapClass = ‘sWrap-‘ + index;
                    var setC = $setArea.find(‘.‘ + swapClass);
                    if (setC.length == 0) {
                        setC = $(‘<div class="sWrap uiCreate ‘ + swapClass + ‘"></div>‘).appendTo($setAorG);
                    }
                    //每次新建,防止内部使用时因为ui的变量改变而出现问题
                    var ui = {
                        element: setC,//setting对应的dom元素
                        level: level,//widget/report
                        target: target,//设置对应的目标widget或report
                        setArea: $setArea,//设置区域
                        settingPropertyItem: settingPropertyItem,//设置对应的SettingProperty
                        setting: setObj//设置完整对象
                    };

                    setEnumObj[index]._init(ui, setObj[index]);
                }
            });

            //function _initSetting(_setObj, _settingProperty, _setEnumObj, _setName) {
            //    if (!_setEnumObj)
            //        return;
            //    if (typeof (_setEnumObj._init) == ‘function‘) {
            //        //处理设置
            //        if (_setName) {
            //            var setC = ui.setArea.find(‘.‘ + _setName);
            //            if (setC.length == 0) {
            //                setC = $(‘<div class="sWrap ‘ + _setName + ‘"></div>‘).appendTo(ui.setArea);
            //            }
            //            ui.element = setC;
            //            _setEnumObj._init(ui, _setObj);
            //        }
            //    } else if (typeof (_settingProperty) == ‘object‘) {
            //        $.each(_settingProperty, function (index, item) {
            //            if (typeof (index) == ‘string‘ && index.charAt(0) == ‘_‘) {
            //                //下划线开头的为api函数
            //            } else {
            //                _initSetting(_setObj[index], item, _setEnumObj[index], _setName + ‘-‘ + index);
            //            }
            //        });
            //    }
            //}
        }

        function getSetting(setting/*设置值(合并后)*/, settingProperty/* 设置选项 */, setEnumObj/* 设置初始化函数 */, $setArea/* 设置区域 */, level, target) {
            var result = {};
            var ui = { element: $setArea, level: level, target: target, setArea: $setArea, setting: result };
            //var setObj = $.extend({}, settingProperty, setting);
            $.each(settingProperty, function (index, item) {
                //if (typeof (item) == ‘object‘)//为什么加这句?
                //_saveSetting(setting, settingProperty, index, setEnumObj[index], ‘sWrap-‘ + index);
                if (setEnumObj[index] && typeof (setEnumObj[index]._val) == ‘function‘) {
                    //处理设置
                    var swapClass = ‘sWrap-‘ + index;
                    ui.element = ui.setArea.find(‘.‘ + swapClass);
                    if (!ui.element.hasClass(‘loading‘)) {
                        //若设置处于加载中则不处理
                        var val = setEnumObj[index]._val(ui);
                        if (val != ‘_NotChange‘) {
                            if (!val && setting[index]) {
                                result[index] = val == undefined ? null : val;
                            }
                            else if (val && !IsObjEqual(val, setting[index])) {
                                //不为空且不为原值或默认值 (此处需要注意,修改系统默认值会影响采用默认配置的用户)
                                result[index] = val;
                            }
                        }
                    }
                }
            });
            return result;

            //function _saveSetting(_setObj, _sp, index, _setEnumObj, _setName) {
            //    if (!_setEnumObj)
            //        return;
            //    if (typeof (_setEnumObj._val) == ‘function‘) {
            //        //处理设置
            //        ui.element = ui.setArea.find(‘.‘ + _setName);
            //        var val = _setEnumObj._val(ui);
            //        if (val && !IsObjEqual(val, _sp[index])) {
            //            //不为空且不为默认值 (此处需要注意,修改系统默认值会影响采用默认配置的用户)
            //            _setObj[index] = val;
            //        } else {
            //            delete _setObj[index];
            //        }
            //    } else {
            //        if (!_setObj[index])
            //            _setObj[index] = {};
            //        $.each(_sp[index], function (_index, item) {
            //            _saveSetting(_setObj[index], _sp[index], _index, _setEnumObj[_index], _setName + ‘-‘ + _index);
            //        });
            //    }
            //}
        }

        $.widget(‘wfc.WFCSetting‘, {
            version: ‘2.0‘,
            options: {
                target: null,
                level: ‘widget‘,
                settingProperty: null,
                isPageHeaderFooter: false,

                //callback
                Update: null
            },
            originalOption: null, //原始option
            OriginalOption: function () {
                return this.originalOption;
            },
            _createWidget: function (option, element) {
                this.originalOption = option || {};
                this._super(option, element);
            },
            _create: function () {
                var self = this,
                options = this.options,
                $div = this.element;
                $div.addClass(‘setting-area‘);
                var SE = WFCFrame.Settings.SettingEnum;
                var target = options.target;
                if (!target || (level == ‘widget‘ && target.length == 0))
                    return;
                var level = options.level;
                var setting = null;
                if (level == ‘report‘) {
                    setting = $.extend(true, {}, target.SettingObj);
                    fillSettingBySettingProperty(setting, target.SettingProperty);
                    if (!options.settingProperty)
                        options.settingProperty = $.extend({}, target.SettingProperty);
                } else {
                    //var wOpt = target.WFCWidget(‘OriginalOption‘);
                    //setting = wOpt.setting;
                    setting = target.WFCWidget(‘option‘, ‘setting‘);
                    if (!options.settingProperty)
                        options.settingProperty = $.extend({}, target.WFCWidget(‘option‘, ‘SettingProperty‘));
                }

                if (options.isPageHeaderFooter) {
                    this._initPageHeaderFooterSetting();
                    if (options.settingProperty) {
                        //表头元素不可设置hidehead和title
                        delete options.settingProperty.hideHead;
                        delete options.settingProperty.title;
                    }
                }

                if (options.settingProperty) {
                    initSetting(setting, options.settingProperty, SE, $div, level, target);
                }
            },
            _initPageHeaderFooterSetting: function () {
                $div = this.element;
                var target = this.options.target;
                var targetOpt = target.WFCWidget(‘OriginalOption‘);
                var opts = [[611, ‘无‘], [623, ‘文字‘], [604, ‘图片‘], [610, ‘页码‘]];
                var htmlOpt = ‘‘;
                $.each(opts, function (index, item) {
                    htmlOpt += ‘<option value="‘ + item[0] + ‘">‘ + item[1] + ‘</option>‘;
                });
                $div.append(‘<div class="sWrap uiCreate sWrap-pageHeaderFooterWidgetType"><span class="setting-name">类型</span><span class="setting-item"><select class="s-pageHeaderFooterWidgetType">‘ + htmlOpt + ‘</select></span></div>‘);

                $div.find(‘.s-pageHeaderFooterWidgetType‘).val(targetOpt.type).change(function () {
                    var option = { type: $(this).val() };
                    var $ws = target.closest(‘.workspace‘);
                    target.WFCWidget(‘destroy‘).prop(‘WFCWidgetOption‘, option);
                    initWorkspaceWidget(target, $ws);
                    $div.WFCSetting(‘destroy‘).WFCSetting({ target: target, isPageHeaderFooter: true });
                    //保存widget(setting) and workspace(pageHeader/Footer)
                    $ws.WFCWorkspace(‘PageHeaderFooterUpdate‘);
                });
                WFCFrame.Settings.PackageSelect($div.find(‘.s-pageHeaderFooterWidgetType‘));
            },
            _destroy: function () {
                this.element.find(‘.ui-multiselect‘).each(function () {
                    $(this).prev(‘select‘).multiselect(‘destroy‘);
                });
                this.element.find(‘.sp-replacer‘).each(function () {
                    $(this).prev(‘input[type="text"]‘).spectrum(‘destroy‘);
                });

                this.element.removeClass(‘setting-area‘).find(‘.uiCreate‘).remove();
                this.element.find(‘.sWrap‘).empty();
            },
            Update: function (isGlobal/* 是否全局刷新(修改report设置时一般不需要单独刷新) */) {
                //更新设置到option, 修改控件/报告的设置并保存,然后调用update回调方法
                var self = this,
            options = this.options,
            $div = this.element;
                var SE = WFCFrame.Settings.SettingEnum;
                var target = this.originalOption.target; //获取原始的target数据而不是副本
                var level = options.level;
                if (!target || !options.settingProperty || (level == ‘widget‘ && target.length == 0))
                    return;

                if (level == ‘report‘ && !isGlobal) {
                    //report及只在isGlobal为true时应用设置
                    return;
                }

                var settingAfter = null; //合并后的设置
                var originalSetting = null;
                if (level == ‘report‘) {
                    if (!target.SettingObj)
                        target.SettingObj = {};
                    originalSetting = target.SettingObj;
                    settingAfter = $.extend(true, {}, target.SettingObj);
                    fillSettingBySettingProperty(settingAfter, target.SettingProperty);
                } else {
                    var wOpt = target.WFCWidget(‘OriginalOption‘);
                    if (!wOpt.setting)
                        wOpt.setting = {};
                    originalSetting = wOpt.setting;
                    settingAfter = target.WFCWidget(‘option‘, ‘setting‘);
                }
                var setResult = getSetting(settingAfter, options.settingProperty, SE, $div, level, target);

                //这里以后应该将setting传入widget.options中(setOption/setSetting),并判断两个setting是否相等,若相等则不必上传至服务器
                //setResult为empty表示未修改任何内容
                if (!$.isEmptyObject(setResult)) {
                    //                    $.each(setResult, function (index, item) {
                    //                        if (item) {
                    //                            originalSetting[index] = item;
                    //                        } else {
                    //                            delete originalSetting[index]; //这里是否需要删除待确定,这里不会出现与默认值相同的情况
                    //                        }
                    //                    });

                    $.extend(originalSetting, setResult);
                    //刷新
                    if (level == ‘report‘ && isGlobal) {
                        //更新fullSetting
                        target.fullSetting = $.extend(true, {}, target.SettingObj);
                        fillSettingBySettingProperty(target.fullSetting, target.SettingProperty);

                        if (target && typeof target.Update == ‘function‘) {
                            target.Update();
                        }
                        if (target && typeof target.Refresh == ‘function‘) {
                            target.Refresh();
                        }
                    } else if (level == ‘widget‘) {
                        target.WFCWidget(‘SaveSetting‘);
                    }
                }
                //update额外处理,目前没有用到
                this._trigger(‘Update‘, null, { setting: originalSetting });
                return setResult;
            }
            , ReCreate: function () {
                //                this.element.removeClass(‘setting-area‘).find(‘.sWrap.uiCreate‘).remove();
                //                this.element.find(‘.sWrap‘).empty();
                //                this._create();

                var opt = this.originalOption;
                this.element.WFCSetting(‘destroy‘).WFCSetting(opt);
            }
            //,Save: function () {
            //    var self = this,
            //    options = this.options,
            //    $div = this.element;
            //    var SE = WFCFrame.Settings.SettingEnum;
            //    var target = options.target;
            //    var level = options.level;

            //    if (level == ‘report‘) {
            //        //Report.SaveSetting 依赖this._trigger(‘Update‘)
            //    } else {
            //        //widget setting更新依赖对象引用传递至orignalOption,这一句主要起刷新的作用
            //        target.WFCWidget(‘SaveSetting‘);
            //    }
            //}
        });

    })();

    /* end of 设置相关代码(Setting)*/


    /* 菜单区(左侧) */



    /* end of 菜单区 */


    //WFCFrame init
    function _init() {
        //highcharts在WFCFrame下需做的统一配置
        if (typeof (Highcharts) != ‘undefined‘ && Highcharts.setOptions) {
            Highcharts.setOptions({
                chart: {
                    events: {
                        //解决无法捕获Highcharts内点击事件的问题
                        load: function () {
                            //.highcharts-container上的click事件会停止冒泡,故在其上绑定click事件调用父节点的click事件
                            $(this.container).click(function () {
                                $(this).parent().trigger(‘click‘);
                            });
                        }
                    }
                }
            });
        }

        //select helper
        containerSelHelper = initSelHelper();

        //$(‘head‘).append(‘<style id="FrameSettingStyle"></style>‘);

        $(‘body‘).keyup(function (event) {
            //console.log(‘keyup‘);
            //del键
            if (event.keyCode == ‘46‘) {
                var $sel = $(‘.workspace .container.selected‘);
                //页眉页脚不可删除,文本编辑状态下不可删除
                if ($sel.closest(‘.pageHeader,.pageFooter‘).length > 0 || event.srcElement.type == ‘textarea‘ || event.srcElement.type == ‘text‘)
                    return;
                removeContainer($sel);
            }
        })

        $.extend(_WFCFrame, {
            RegisterWidget: function (name, obj) {
                if (this.Widgets.hasOwnProperty(name)) {
                    showDebugMsg(‘名称为‘ + name + ‘的控件已存在‘);
                } else {
                    this.Widgets[name] = obj;
                }
            },
            Widgets: {},
            Param: param,
            Report: null, //当前对应的report,report相关内容通过此传入
            DivideContainerHorizontal: function () {
                divideContainer($(‘.workspace .selected‘), ‘vertical‘);
            },
            DivideContainerVertical: function () {
                divideContainer($(‘.workspace .selected‘), ‘horizontal‘);
            },
            GetNoDataBlockOption: getNoDataBlockOption,
            InitOperationArea: initOperationArea,
            GetContainerContentObj: getContainerContentObj,
            RefreshWidgetsByTypes: function (widgetTypeNameArray) {
                if ($.isArray(widgetTypeNameArray)) {
                    $.each(widgetTypeNameArray, function (index, item) {
                        $(‘.win-‘ + item).WFCWidget(‘Refresh‘);
                    });
                }
            },
            GetProductInfo: getProductInfo,
            FillSettingBySettingProperty: fillSettingBySettingProperty,
            RefreshWidget: function (obj) {
                var $widget = $(obj).hasClass(‘.widget‘) ? $(obj) : $(obj).closest(‘.widget‘);
                var objWidget = $widget.data(‘WFCWidget‘);
                if (objWidget && objWidget.Refresh) {
                    objWidget.Refresh();
                }
            }
        });
    }

    _init();


    /*WFCReport*/
    //var WFCReport = function (option) {
    //    this.option = $.extend(true, {

    //    }, option);
    //};

    //var proto = WFCReport.prototype;
    //proto.SaveSetting = function () {
    //    if(report)
    //}

    //window.WFCReport = WFCReport;


    window.WFCFrame = _WFCFrame;
})(window);

 

js分享3

原文:http://www.cnblogs.com/gongziwuji/p/5140630.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!