From ec62df1867f7d5d6e7cf6783401412274c824dae Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 15 May 2017 11:20:37 +0800 Subject: [PATCH] add --- bi/polyfill.js | 93 +++++++++++++++++++ demo/js/config/widget.js | 8 ++ .../tree/demo.multilayer_select_tree_combo.js | 69 ++++++++++++++ docs/demo.js | 78 +++++++++++++++- docs/polyfill.js | 93 +++++++++++++++++++ 5 files changed, 340 insertions(+), 1 deletion(-) create mode 100644 bi/polyfill.js create mode 100644 demo/js/widget/tree/demo.multilayer_select_tree_combo.js create mode 100644 docs/polyfill.js diff --git a/bi/polyfill.js b/bi/polyfill.js new file mode 100644 index 000000000..854ed288f --- /dev/null +++ b/bi/polyfill.js @@ -0,0 +1,93 @@ +if(![].indexOf){ + /** + * 检查指定的值是否在数组中 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].indexOf = function (o) { + for (var i = 0, len = this.length; i < len; i++) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +} +if(![].lastIndexOf){ + /** + * 检查指定的值是否在数组中 + * ie67不支持数组的这个方法 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].lastIndexOf = function (o) { + for (var len = this.length, i = len - 1; i >= 0; i--) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +}/** + * 特殊情况 + * Created by wang on 15/6/23. + */ +//解决console未定义问题 guy +window.console = window.console || (function () { + var c = {}; + c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile + = c.clear = c.exception = c.trace = c.assert = function () { + }; + return c; + })(); +/* + * 前端缓存 + */ +window.localStorage || (window.localStorage = { + items: {}, + setItem: function (k, v) { + BI.Cache.addCookie(k, v); + }, + getItem: function (k) { + return BI.Cache.getCookie(k); + }, + removeItem: function (k) { + BI.Cache.deleteCookie(k); + }, + key: function () { + + }, + clear: function () { + this.items = {}; + } +});//修复ie9下sort方法的bug +!function (window) { + var ua = window.navigator.userAgent.toLowerCase(), + reg = /msie|applewebkit.+safari/; + if (reg.test(ua)) { + var _sort = Array.prototype.sort; + Array.prototype.sort = function (fn) { + if (!!fn && typeof fn === 'function') { + if (this.length < 2) { + return this; + } + var i = 0, j = i + 1, l = this.length, tmp, r = false, t = 0; + for (; i < l; i++) { + for (j = i + 1; j < l; j++) { + t = fn.call(this, this[i], this[j]); + r = (typeof t === 'number' ? t : + !!t ? 1 : 0) > 0; + if (r === true) { + tmp = this[i]; + this[i] = this[j]; + this[j] = tmp; + } + } + } + return this; + } else { + return _sort.call(this); + } + }; + } +}(window); \ No newline at end of file diff --git a/demo/js/config/widget.js b/demo/js/config/widget.js index 423892244..003cadc12 100644 --- a/demo/js/config/widget.js +++ b/demo/js/config/widget.js @@ -21,6 +21,14 @@ Demo.WIDGET_CONFIG = [{ pId: 401, text: "bi.page_table", value: "demo.page_table" +}, { + id: 402, + pId: 4, + text: "tree" +}, { + pId: 402, + text: "bi.multilayer_select_tree_combo", + value: "demo.multilayer_select_tree_combo" }, { pId: 4, text: "bi.multi_select_combo", diff --git a/demo/js/widget/tree/demo.multilayer_select_tree_combo.js b/demo/js/widget/tree/demo.multilayer_select_tree_combo.js new file mode 100644 index 000000000..580587289 --- /dev/null +++ b/demo/js/widget/tree/demo.multilayer_select_tree_combo.js @@ -0,0 +1,69 @@ +/** + * Created by User on 2017/3/22. + */ +Demo.MultiSelectCombo = BI.inherit(BI.Widget, { + props: {}, + + render: function (vessel) { + var TREEWITHCHILDREN = [{ + id: -1, value: "根目录", text: "根目录", children: [ + { + id: 1, value: "第一级目录1", text: "第一级目录1", children: [ + {id: 11, value: "第二级文件1", text: "第二级文件1"}, + { + id: 12, value: "第二级目录2", text: "第二级目录2", children: [ + { + id: 121, value: "第三级目录1", text: "第三级目录1", children: [ + { + id: 1211, value: "第四级目录1", text: "第四级目录1", children: [ + {id: 12111, value: "第五级文件1", text: "第五级文件1"} + ] + } + ] + }, + {id: 122, value: "第三级文件1", text: "第三级文件1"} + ] + } + ] + }, + { + id: 2, value: "第一级目录2", text: "第一级目录2", children: [ + { + id: 21, value: "第二级目录3", text: "第二级目录3", children: [ + { + id: 211, value: "第三级目录2", text: "第三级目录2", children: [ + {id: 2111, value: "第四级文件1", text: "第四级文件1"} + ] + }, + {id: 212, value: "第三级文件2", text: "第三级文件2"} + ] + }, + {id: 22, value: "第二级文件2", text: "第二级文件2"} + ] + } + ] + }]; + var items = BI.deepClone(TREEWITHCHILDREN); + var combo = BI.createWidget({ + type: "bi.multilayer_select_tree_combo", + itemsCreator: function (op, callback) { + debugger; + } + }); + + combo.populate(); + return { + type: "bi.vertical", + items: [combo, { + type: "bi.button", + width: 100, + text: "getValue", + handler: function () { + BI.Msg.alert("", JSON.stringify(combo.getValue())); + } + }], + vgap: 100 + } + } +}); +BI.shortcut("demo.multilayer_select_tree_combo", Demo.MultiSelectCombo); \ No newline at end of file diff --git a/docs/demo.js b/docs/demo.js index a5ba8e542..3c93eef27 100644 --- a/docs/demo.js +++ b/docs/demo.js @@ -3112,6 +3112,14 @@ Demo.COMPONENT_CONFIG = [{ pId: 401, text: "bi.page_table", value: "demo.page_table" +}, { + id: 402, + pId: 4, + text: "tree" +}, { + pId: 402, + text: "bi.multilayer_select_tree_combo", + value: "demo.multilayer_select_tree_combo" }, { pId: 4, text: "bi.multi_select_combo", @@ -6725,7 +6733,75 @@ BI.shortcut("demo.responsive_table", Demo.Func);Demo.Func = BI.inherit(BI.Widget }) } }); -BI.shortcut("demo.sequence_table", Demo.Func);Demo.CONFIG = Demo.CORE_CONFIG.concat(Demo.BASE_CONFIG).concat(Demo.CASE_CONFIG).concat(Demo.WIDGET_CONFIG).concat(Demo.COMPONENT_CONFIG).concat(Demo.CHART_CONFIG); +BI.shortcut("demo.sequence_table", Demo.Func);/** + * Created by User on 2017/3/22. + */ +Demo.MultiSelectCombo = BI.inherit(BI.Widget, { + props: {}, + + render: function (vessel) { + var TREEWITHCHILDREN = [{ + id: -1, value: "根目录", text: "根目录", children: [ + { + id: 1, value: "第一级目录1", text: "第一级目录1", children: [ + {id: 11, value: "第二级文件1", text: "第二级文件1"}, + { + id: 12, value: "第二级目录2", text: "第二级目录2", children: [ + { + id: 121, value: "第三级目录1", text: "第三级目录1", children: [ + { + id: 1211, value: "第四级目录1", text: "第四级目录1", children: [ + {id: 12111, value: "第五级文件1", text: "第五级文件1"} + ] + } + ] + }, + {id: 122, value: "第三级文件1", text: "第三级文件1"} + ] + } + ] + }, + { + id: 2, value: "第一级目录2", text: "第一级目录2", children: [ + { + id: 21, value: "第二级目录3", text: "第二级目录3", children: [ + { + id: 211, value: "第三级目录2", text: "第三级目录2", children: [ + {id: 2111, value: "第四级文件1", text: "第四级文件1"} + ] + }, + {id: 212, value: "第三级文件2", text: "第三级文件2"} + ] + }, + {id: 22, value: "第二级文件2", text: "第二级文件2"} + ] + } + ] + }]; + var items = BI.deepClone(TREEWITHCHILDREN); + var combo = BI.createWidget({ + type: "bi.multilayer_select_tree_combo", + itemsCreator: function (op, callback) { + debugger; + } + }); + + combo.populate(); + return { + type: "bi.vertical", + items: [combo, { + type: "bi.button", + width: 100, + text: "getValue", + handler: function () { + BI.Msg.alert("", JSON.stringify(combo.getValue())); + } + }], + vgap: 100 + } + } +}); +BI.shortcut("demo.multilayer_select_tree_combo", Demo.MultiSelectCombo);Demo.CONFIG = Demo.CORE_CONFIG.concat(Demo.BASE_CONFIG).concat(Demo.CASE_CONFIG).concat(Demo.WIDGET_CONFIG).concat(Demo.COMPONENT_CONFIG).concat(Demo.CHART_CONFIG); Demo.CONSTANTS = { diff --git a/docs/polyfill.js b/docs/polyfill.js new file mode 100644 index 000000000..854ed288f --- /dev/null +++ b/docs/polyfill.js @@ -0,0 +1,93 @@ +if(![].indexOf){ + /** + * 检查指定的值是否在数组中 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].indexOf = function (o) { + for (var i = 0, len = this.length; i < len; i++) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +} +if(![].lastIndexOf){ + /** + * 检查指定的值是否在数组中 + * ie67不支持数组的这个方法 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].lastIndexOf = function (o) { + for (var len = this.length, i = len - 1; i >= 0; i--) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +}/** + * 特殊情况 + * Created by wang on 15/6/23. + */ +//解决console未定义问题 guy +window.console = window.console || (function () { + var c = {}; + c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile + = c.clear = c.exception = c.trace = c.assert = function () { + }; + return c; + })(); +/* + * 前端缓存 + */ +window.localStorage || (window.localStorage = { + items: {}, + setItem: function (k, v) { + BI.Cache.addCookie(k, v); + }, + getItem: function (k) { + return BI.Cache.getCookie(k); + }, + removeItem: function (k) { + BI.Cache.deleteCookie(k); + }, + key: function () { + + }, + clear: function () { + this.items = {}; + } +});//修复ie9下sort方法的bug +!function (window) { + var ua = window.navigator.userAgent.toLowerCase(), + reg = /msie|applewebkit.+safari/; + if (reg.test(ua)) { + var _sort = Array.prototype.sort; + Array.prototype.sort = function (fn) { + if (!!fn && typeof fn === 'function') { + if (this.length < 2) { + return this; + } + var i = 0, j = i + 1, l = this.length, tmp, r = false, t = 0; + for (; i < l; i++) { + for (j = i + 1; j < l; j++) { + t = fn.call(this, this[i], this[j]); + r = (typeof t === 'number' ? t : + !!t ? 1 : 0) > 0; + if (r === true) { + tmp = this[i]; + this[i] = this[j]; + this[j] = tmp; + } + } + } + return this; + } else { + return _sort.call(this); + } + }; + } +}(window); \ No newline at end of file