fastman2 2.9.0 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/baseman.js CHANGED
@@ -1 +1,115 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.fastman=t():e.fastman=t()}(this,function(){return webpackJsonpfastman([28],{215:function(e,t,n){e.exports=n(29)},29:function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r={};r.cache={};var i=function(e,t,n){var o=/[^\w\-\.:]/.test(e)?function(e,t){var n,r=[],i=[];for(n in e)r.push(n),i.push(e[n]);return new Function(r,o.code).apply(t||e,i)}:r.cache[e]=r.cache[e]||(void 0).get(document.getElementById(e).innerHTML);return o.code=o.code||"var $parts=[]; $parts.push('"+e.replace(/\\/g,"\\\\").replace(/[\r\t\n]/g," ").split("<%").join("\t").replace(/(^|%>)[^\t]*/g,function(e){return e.replace(/'/g,"\\'")}).replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("$parts.push('")+"'); return $parts.join('');",t?o(t,n):o},a=function(e,t,n,r,a,p){var c=e;if("string"!=typeof n){var f=$.extend({},t,"object"==(void 0===n?"undefined":o(n))&&n),s=void 0==f.container?"body":f.container,u=!1;$.isArray(c)&&c.length&&"script"==$(c)[0].nodeName.toLowerCase()?(c=$(i(c[0].innerHTML,f)).appendTo($(s)),u=!0):$.isArray(c)&&c.length&&""==c.selector?(c=$(i(c[0].outerHTML,f)).appendTo($(s)),u=!0):$.isArray(c)||(c=$(i(r,f)).appendTo($(s)),u=!0)}return c.each(function(){var e=$(this),r=e.data("fz."+p);r||e.data("fz."+p,r=new a(this,$.extend({},t,"object"==(void 0===n?"undefined":o(n))&&n),u)),"string"==typeof n&&r[n]()})};t.tpl=i,t.adaptObject=a}},[215])});
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["fastman"] = factory();
8
+ else
9
+ root["fastman"] = factory();
10
+ })(this, function() {
11
+ return webpackJsonpfastman([28],{
12
+
13
+ /***/ 215:
14
+ /***/ (function(module, exports, __webpack_require__) {
15
+
16
+ module.exports = __webpack_require__(29);
17
+
18
+
19
+ /***/ }),
20
+
21
+ /***/ 29:
22
+ /***/ (function(module, exports, __webpack_require__) {
23
+
24
+ "use strict";
25
+
26
+
27
+ Object.defineProperty(exports, "__esModule", {
28
+ value: true
29
+ });
30
+
31
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
32
+
33
+ /**
34
+ * Created by linyiqing on 2017/3/23.
35
+ */
36
+ var _private = {};
37
+ _private.cache = {};
38
+
39
+ var tpl = function tpl(str, data, env) {
40
+ // 判断str参数,如str为script标签的id,则取该标签的innerHTML,再递归调用自身
41
+ // 如str为HTML文本,则分析文本并构造渲染函数
42
+ var fn = !/[^\w\-\.:]/.test(str) ? _private.cache[str] = _private.cache[str] || undefined.get(document.getElementById(str).innerHTML) : function (data, env) {
43
+ var i,
44
+ variable = [],
45
+ value = []; // variable数组存放变量名,对应data结构的成员变量;value数组存放各变量的值
46
+ for (i in data) {
47
+ variable.push(i);
48
+ value.push(data[i]);
49
+ }
50
+ return new Function(variable, fn.code).apply(env || data, value); // 此处的new Function是由下面fn.code产生的渲染函数;执行后即返回渲染结果HTML
51
+ };
52
+
53
+ fn.code = fn.code || "var $parts=[]; $parts.push('" + str.replace(/\\/g, '\\\\') // 处理模板中的\转义
54
+ .replace(/[\r\t\n]/g, " ") // 去掉换行符和tab符,将模板合并为一行
55
+ .split("<%").join("\t") // 将模板左标签<%替换为tab,起到分割作用
56
+ .replace(/(^|%>)[^\t]*/g, function (str) {
57
+ return str.replace(/'/g, "\\'");
58
+ }) // 将模板中文本部分的单引号替换为\'
59
+ .replace(/\t=(.*?)%>/g, "',$1,'") // 将模板中<%= %>的直接数据引用(无逻辑代码)与两侧的文本用'和,隔开,同时去掉了左标签产生的tab符
60
+ .split("\t").join("');") // 将tab符(上面替换左标签产生)替换为'); 由于上一步已经把<%=产生的tab符去掉,因此这里实际替换的只有逻辑代码的左标签
61
+ .split("%>").join("$parts.push('") // 把剩下的右标签%>(逻辑代码的)替换为"$parts.push('"
62
+ + "'); return $parts.join('');"; // 最后得到的就是一段JS代码,保留模板中的逻辑,并依次把模板中的常量和变量压入$parts数组
63
+
64
+ return data ? fn(data, env) : fn; // 如果传入了数据,则直接返回渲染结果HTML文本,否则返回一个渲染函数
65
+ };
66
+
67
+ var adaptObject = function adaptObject(element, defaults, option, template, plugin, pluginName) {
68
+ var $this = element;
69
+
70
+ if (typeof option != 'string') {
71
+
72
+ // 获得配置信息
73
+ var context = $.extend({}, defaults, (typeof option === "undefined" ? "undefined" : _typeof(option)) == 'object' && option);
74
+
75
+ var $container = context.container == undefined ? 'body' : context.container;
76
+
77
+ var isFromTpl = false;
78
+ // 如果传入script标签的选择器
79
+ if ($.isArray($this) && $this.length && $($this)[0].nodeName.toLowerCase() == "script") {
80
+ // 根据模板获得对象并插入到body中
81
+ $this = $(tpl($this[0].innerHTML, context)).appendTo($($container));
82
+ isFromTpl = true;
83
+ }
84
+ // 如果传入模板字符串
85
+ else if ($.isArray($this) && $this.length && $this.selector == "") {
86
+ // 根据模板获得对象并插入到body中
87
+ $this = $(tpl($this[0].outerHTML, context)).appendTo($($container));
88
+ isFromTpl = true;
89
+ }
90
+ // 如果通过$.dialog()的方式调用
91
+ else if (!$.isArray($this)) {
92
+ // 根据模板获得对象并插入到body中
93
+ $this = $(tpl(template, context)).appendTo($($container));
94
+ isFromTpl = true;
95
+ }
96
+ }
97
+
98
+ return $this.each(function () {
99
+ var el = $(this);
100
+ // 读取对象缓存
101
+ var data = el.data('fz.' + pluginName);
102
+
103
+ if (!data) el.data('fz.' + pluginName, data = new plugin(this, $.extend({}, defaults, (typeof option === "undefined" ? "undefined" : _typeof(option)) == 'object' && option), isFromTpl));
104
+
105
+ if (typeof option == 'string') data[option]();
106
+ });
107
+ };
108
+
109
+ exports.tpl = tpl;
110
+ exports.adaptObject = adaptObject;
111
+
112
+ /***/ })
113
+
114
+ },[215]);
115
+ });
package/blankpageman.js CHANGED
@@ -1 +1,171 @@
1
- !function(t,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.fastman=o():t.fastman=o()}(this,function(){return webpackJsonpfastman([27],{216:function(t,o,n){t.exports=n(84)},84:function(t,o,n){"use strict";function e(t){t.children().not("script")&&t.children().not("script").hide(),t.find("section.ui-notice").remove()}function i(t,o){var o=o||{};for(var n in t)"object"===c(t[n])?(o[n]=t[n].constructor===Array?[]:{},i(t[n],o[n])):o[n]=t[n];return o}function r(t){var o=$.extend({},a,t),n=$(o.container),r=function(t){var o=window.document.documentElement.getAttribute("data-scale")||1,e=n.height()*o<n.width()*o?n.height()*o:n.width()*o,i=window.document.documentElement.getBoundingClientRect().width*o/16;return e*t/(window.document.documentElement.getBoundingClientRect().width*o)/i},c={};c=i(o,c),c.props.iconFontSize=r(c.props.iconFontSize*c.iconScale),c.props.iconFontSize=0==c.props.iconFontSize?"inherit":c.props.iconFontSize,c.props.tipFontSize=r(c.props.tipFontSize*c.fontScale),c.props.tipFontSize=0==c.props.tipFontSize?"inherit":c.props.tipFontSize,$("<style>"+c.container+" .ui-notice > i:before{font-size: "+c.props.iconFontSize+"rem</style>").appendTo("head"),e(n);var u=(0,p.adaptObject)(this,a,c,s,l,"blankPage");return u.destory=function(){u.remove(),n.children().not("script")&&n.children().not("script").show(),n=null},u}Object.defineProperty(o,"__esModule",{value:!0}),o.blankPage=void 0;var c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},p=n(29),s='<section <% if(container != "body"){ %> style="position:relative;" <% }else{ %> style="height:100%;" <% } %> class="ui-notice"><i class="<%=font%>-icon animate-<%=icon%> icon-<%=icon%>" <% if(!title){%>style="margin-bottom:0;"<%} %>></i><% if(title) { %> <p style="font-size: <%=props.tipFontSize%>rem"><%=title%></p> <% } %><div data-role="button" class="ui-notice-btn" style="font-size: <%=props.tipFontSize%>rem"><%=buttonText%></div></section>',a={title:"正在加载...",icon:"loading",buttonText:"重新载入",button:!1,type:"click",font:"fontello",container:"body",fontScale:1,iconScale:1,props:{iconFontSize:65,tipFontSize:28}},l=function(t,o,n){this.option=$.extend({},a,o),this.button=$(t).find('[data-role="button"]'),this.element=$(t),this._bindEvent()};l.prototype={_bindEvent:function(){var t=this;this.option.button?t.button.on(this.option.type,function(o){var n=$(t.button).index($(this)),e=$.Event("blankPage:action");e.index=n,t.element.trigger(e),o.stopPropagation()}):t.button.remove()}},o.blankPage=r}},[216])});
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["fastman"] = factory();
8
+ else
9
+ root["fastman"] = factory();
10
+ })(this, function() {
11
+ return webpackJsonpfastman([27],{
12
+
13
+ /***/ 216:
14
+ /***/ (function(module, exports, __webpack_require__) {
15
+
16
+ module.exports = __webpack_require__(84);
17
+
18
+
19
+ /***/ }),
20
+
21
+ /***/ 84:
22
+ /***/ (function(module, exports, __webpack_require__) {
23
+
24
+ "use strict";
25
+
26
+
27
+ Object.defineProperty(exports, "__esModule", {
28
+ value: true
29
+ });
30
+ exports.blankPage = undefined;
31
+
32
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
33
+
34
+ var _base = __webpack_require__(29);
35
+
36
+ // 删除当前容器内的一些不必要的DOM
37
+ function init(container) {
38
+
39
+ // 对当前container中所有子集隐藏
40
+ if (container.children().not("script")) container.children().not("script").hide();
41
+
42
+ // 对当前container中已声明的blankPage进行去重
43
+ container.find('section.ui-notice').remove();
44
+ }
45
+
46
+ // 默认模板
47
+ var _blankPageTpl = '<section <% if(container != "body"){ %> style="position:relative;" <% }else{ %> style="height:100%;" <% } %> class="ui-notice">' + '<i class="<%=font%>-icon animate-<%=icon%> icon-<%=icon%>" <% if(!title){%>style="margin-bottom:0;"<%} %>></i>' + '<% if(title) { %> <p style="font-size: <%=props.tipFontSize%>rem"><%=title%></p> <% } %>' + '<div data-role="button" class="ui-notice-btn" style="font-size: <%=props.tipFontSize%>rem"><%=buttonText%></div>' + '</section>';
48
+
49
+ // 默认参数
50
+ var defaults = {
51
+ title: '正在加载...',
52
+ icon: 'loading',
53
+ buttonText: '重新载入',
54
+ button: false,
55
+ type: 'click',
56
+ font: 'fontello', // 所使用的字体,目前支持fontello和ui
57
+ container: 'body',
58
+ fontScale: 1, // 文字尺寸,默认为1
59
+ iconScale: 1, // 图标尺寸,默认为1
60
+ props: { // 自有属性,不参与组件配置,实现内部逻辑用,单位px
61
+ iconFontSize: 65, // 图标大小,iphone6尺寸在以65px作为基准值
62
+ tipFontSize: 28 // 文字大小,iphone6尺寸在以28px作为基准值
63
+ // containerHeight: 667, // 容器高度大小,iphone6尺寸在以667px作为基准值,这也是i6的高度
64
+ }
65
+ };
66
+
67
+ /**
68
+ * 深复制实现
69
+ * @returns {Object}
70
+ */
71
+ function copy(obj1, obj2) {
72
+ var obj2 = obj2 || {}; //最初的时候给它一个初始值=它自己或者是一个json
73
+ for (var name in obj1) {
74
+ if (_typeof(obj1[name]) === "object") {
75
+ //先判断一下obj[name]是不是一个对象
76
+ obj2[name] = obj1[name].constructor === Array ? [] : {}; //我们让要复制的对象的name项=数组或者是json
77
+ copy(obj1[name], obj2[name]); //然后来无限调用函数自己 递归思想
78
+ } else {
79
+ obj2[name] = obj1[name]; //如果不是对象,直接等于即可,不会发生引用。
80
+ }
81
+ }
82
+ return obj2; //然后在把复制好的对象给return出去
83
+ }
84
+
85
+ function Plugin(option) {
86
+ var options = $.extend({}, defaults, option);
87
+ var container = $(options.container);
88
+
89
+ /**
90
+ * px转化为rem单位
91
+ * @param originVal 原始px值
92
+ */
93
+ var px2rem = function px2rem(originVal) {
94
+ // 获取实际容器大小
95
+ var $scale = window.document.documentElement.getAttribute('data-scale') || 1;
96
+ // 当前容器相对值
97
+ var containerRelativeVal = container.height() * $scale < container.width() * $scale ? container.height() * $scale : container.width() * $scale;
98
+ // 计算原始容器的基准fontSize
99
+ var originFontSize = window.document.documentElement.getBoundingClientRect().width * $scale / 16;
100
+ // // 计算当前容器的基准fontSize
101
+ // let fontSize = containerRelativeVal / 16
102
+ return containerRelativeVal * originVal / (window.document.documentElement.getBoundingClientRect().width * $scale) / originFontSize;
103
+ };
104
+
105
+ // 获取原始单位的相对容器大小(换算后)
106
+ var proxyOptions = {};
107
+ proxyOptions = copy(options, proxyOptions);
108
+ proxyOptions.props.iconFontSize = px2rem(proxyOptions.props.iconFontSize * proxyOptions.iconScale);
109
+ // 计算如果还未结束documentContentLoaded,是计算不出外层容器的尺寸的,因此给予默认容错处理
110
+ proxyOptions.props.iconFontSize = proxyOptions.props.iconFontSize == 0 ? 'inherit' : proxyOptions.props.iconFontSize;
111
+ proxyOptions.props.tipFontSize = px2rem(proxyOptions.props.tipFontSize * proxyOptions.fontScale);
112
+ proxyOptions.props.tipFontSize = proxyOptions.props.tipFontSize == 0 ? 'inherit' : proxyOptions.props.tipFontSize;
113
+ //proxyOptions.props.containerHeight = px2rem(proxyOptions.props.containerHeight)
114
+
115
+ // 根据外层容器大小动态改变图标和字体大小
116
+ $("<style>" + proxyOptions.container + " .ui-notice > i:before{font-size: " + proxyOptions.props.iconFontSize + "rem</style>").appendTo('head');
117
+
118
+ // 初始化容器
119
+ init(container);
120
+
121
+ // 开始构建组件
122
+ var plugin = (0, _base.adaptObject)(this, defaults, proxyOptions, _blankPageTpl, BlankPage, "blankPage");
123
+
124
+ // 摧毁事件
125
+ plugin.destory = function () {
126
+ plugin.remove();
127
+
128
+ if (container.children().not("script")) container.children().not("script").show();
129
+
130
+ container = null;
131
+ };
132
+
133
+ return plugin;
134
+ }
135
+
136
+ // 构造函数
137
+ var BlankPage = function BlankPage(el, option, isFromTpl) {
138
+ this.option = $.extend({}, defaults, option);
139
+ this.button = $(el).find('[data-role="button"]');
140
+ // 当前_blankPageTpl对应的DOM
141
+ this.element = $(el);
142
+
143
+ this._bindEvent();
144
+ };
145
+
146
+ BlankPage.prototype = {
147
+ _bindEvent: function _bindEvent() {
148
+ var self = this;
149
+
150
+ if (this.option.button) {
151
+ self.button.on(this.option.type, function (ex) {
152
+ var index = $(self.button).index($(this));
153
+ // 使用AOP的思想注入事件
154
+ var e = $.Event("blankPage:action");
155
+ e.index = index;
156
+ self.element.trigger(e);
157
+ ex.stopPropagation();
158
+ });
159
+ } else {
160
+ // 彻底清除按钮的所在层
161
+ self.button.remove();
162
+ }
163
+ }
164
+ };
165
+
166
+ exports.blankPage = Plugin;
167
+
168
+ /***/ })
169
+
170
+ },[216]);
171
+ });
@@ -1 +1,322 @@
1
- !function(e,a){"object"==typeof exports&&"object"==typeof module?module.exports=a():"function"==typeof define&&define.amd?define([],a):"object"==typeof exports?exports.fastman=a():e.fastman=a()}(this,function(){return webpackJsonpfastman([26],{217:function(e,a,l){e.exports=l(85)},85:function(e,a,l){"use strict";Object.defineProperty(a,"__esModule",{value:!0});var u=l(30),s=function(e){return e&&e.__esModule?e:{default:e}}(u),t=function(e){for(var a=0,l=0;l<e.length;l++){0===a&&(a=1);var u=e[l].sub;if(u)for(var s=0;s<u.length;s++){1===a&&(a=2);var t=u[s].sub;if(t)for(var n=0;n<t.length;n++)return 3}}return a};a.default=function(e,a){var l=$(e);if(l.length&&a.data){var u=a.data,n=function(e,a){for(var l=[],u=0;u<e.length;u++){var s=e[u];l.push(s[a])}return l.length?l:[""]},r=function(e,a){return e.sub?n(e.sub,a):[""]},o=function(e,a){for(var l=0;l<u.length;l++)if(u[l].value===e)return r(u[l],a);return[""]},c=function(e,a,l){for(var s=0;s<u.length;s++)if(u[s].value===e)for(var t=0;t<u[s].sub.length;t++)if(u[s].sub[t].value===a)return r(u[s].sub[t],l);return[""]},v=t(u);if(0!==v){var i=[""];v>0&&(i=u.map(function(e){return e.name}));var f=[""];v>0&&(f=u.map(function(e,a){return e.value}));var p=[""];v>1&&(p=r(u[0],"name"));var d=[""];v>1&&(d=r(u[0],"value"));var h=[""],g=[""];v>2&&(u[0].sub?(h=r(u[0].sub[0],"name"),g=r(u[0].sub[0],"value")):(h=[""],g=[""]));var m,b=f[0],y=d[0],x=g[0],V={cssClass:"city-picker",rotateEffect:!1,onChange:function(e,a,l){var u,s=e.cols[0].value;if(s!==b)return clearTimeout(m),void(m=setTimeout(function(){if(v>1){var a=o(s,"name"),l=o(s,"value");u=l[0],e.cols[1].replaceValues(l,a),y=u}if(v>2){var t=c(s,u,"name"),n=c(s,u,"value");e.cols[2].replaceValues(n,t)}b=s,e.updateValue()},200));3===v&&(u=e.cols[1].value)!==y&&(e.cols[2].replaceValues(c(s,u,"value"),c(s,u,"name")),y=u,e.updateValue())},cols:[]};return 1===v?V.cols.push({textAlign:"center",displayValues:i,values:f,cssClass:"col-province"}):2===v?(V.cols.push({textAlign:"center",displayValues:i,values:f,cssClass:"col-province"}),V.cols.push({textAlign:"center",displayValues:p,values:d,cssClass:"col-city"})):3===v&&(V.cols.push({textAlign:"center",displayValues:i,values:f,cssClass:"col-province"}),V.cols.push({textAlign:"center",displayValues:p,values:d,cssClass:"col-city"}),V.cols.push({textAlign:"center",displayValues:h,values:g,cssClass:"col-district"})),l.each(function(){var l=$.extend(V,a);if(l.value)$(this).val(l.value.join(" "));else{var u=$(this).val();u&&(l.value=u.split(" "))}l.value&&(l.value[0]&&(b=l.value[0],l.cols[1].values=o(l.value[0])),l.value[1]?(y=l.value[1],l.cols[2].values=c(l.value[0],l.value[1])):l.cols[2].values=c(l.value[0],l.cols[1].values[0]),!l.value[2]&&(l.value[2]=""),x=l.value[2]),(0,s.default)(e,l)})}}}}},[217])});
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["fastman"] = factory();
8
+ else
9
+ root["fastman"] = factory();
10
+ })(this, function() {
11
+ return webpackJsonpfastman([26],{
12
+
13
+ /***/ 217:
14
+ /***/ (function(module, exports, __webpack_require__) {
15
+
16
+ module.exports = __webpack_require__(85);
17
+
18
+
19
+ /***/ }),
20
+
21
+ /***/ 85:
22
+ /***/ (function(module, exports, __webpack_require__) {
23
+
24
+ "use strict";
25
+
26
+
27
+ Object.defineProperty(exports, "__esModule", {
28
+ value: true
29
+ });
30
+
31
+ var _picker = __webpack_require__(30);
32
+
33
+ var _picker2 = _interopRequireDefault(_picker);
34
+
35
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
+
37
+ /**
38
+ * 获取数据结构的级联层级
39
+ * @param data 数据结构
40
+ * @returns {number}
41
+ */
42
+ var getCascadeLayer = function getCascadeLayer(data) {
43
+ var layer = 0;
44
+ // 第一层
45
+ for (var i = 0; i < data.length; i++) {
46
+ if (layer === 0) {
47
+ layer = 1;
48
+ }
49
+
50
+ var ds = data[i].sub;
51
+ if (ds) {
52
+ // 第二层
53
+ for (var j = 0; j < ds.length; j++) {
54
+ if (layer === 1) {
55
+ layer = 2;
56
+ }
57
+
58
+ var dss = ds[j].sub;
59
+ if (dss) {
60
+ // 第三层
61
+ for (var k = 0; k < dss.length; k++) {
62
+ return 3;
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ return layer;
69
+ }; /**
70
+ * 级联选择器
71
+ * Created by dfzq on 2018/5/30.
72
+ */
73
+
74
+ exports.default = function (seletor, params) {
75
+ var $this = $(seletor);
76
+ // 检查选择器是否存在
77
+ if (!$this.length) {
78
+ return;
79
+ }
80
+ // 如果没有数据则不进行组件渲染
81
+ if (!params.data) {
82
+ return;
83
+ }
84
+
85
+ // 数据源
86
+ var raw = params.data;
87
+
88
+ /**
89
+ * 数据块解析函数
90
+ * @param data 数据中的sub块
91
+ * @param name 待解析的数据字段名
92
+ * @returns {*}
93
+ */
94
+ var format = function format(data, name) {
95
+ var result = [];
96
+ for (var i = 0; i < data.length; i++) {
97
+ var d = data[i];
98
+ result.push(d[name]);
99
+ }
100
+ if (result.length) return result;
101
+ return [""];
102
+ };
103
+
104
+ /**
105
+ * 获取数据中的sub数据块进行解析
106
+ * @param data 数据
107
+ * @param name 数据字段名
108
+ * @returns {[string]}
109
+ */
110
+ var sub = function sub(data, name) {
111
+ if (!data.sub) return [""];
112
+ return format(data.sub, name);
113
+ };
114
+
115
+ /**
116
+ * 获取二级数据块
117
+ * @param d 一级数据
118
+ * @param name 数据字段名
119
+ * @returns {*}
120
+ */
121
+ var getCities = function getCities(d, name) {
122
+ for (var i = 0; i < raw.length; i++) {
123
+ if (raw[i].value === d) return sub(raw[i], name);
124
+ }
125
+ return [""];
126
+ };
127
+
128
+ /**
129
+ * 获取三级数据块
130
+ * @param p 一级数据
131
+ * @param c 二级数据
132
+ * @param name 数据字段名
133
+ * @returns {*}
134
+ */
135
+ var getDistricts = function getDistricts(p, c, name) {
136
+ for (var i = 0; i < raw.length; i++) {
137
+ if (raw[i].value === p) {
138
+ for (var j = 0; j < raw[i].sub.length; j++) {
139
+ if (raw[i].sub[j].value === c) {
140
+ return sub(raw[i].sub[j], name);
141
+ }
142
+ }
143
+ }
144
+ }
145
+ return [""];
146
+ };
147
+
148
+ // 检查数据源有几层(共3层,空数组为0层)
149
+ var cascadeLayer = getCascadeLayer(raw);
150
+ if (cascadeLayer === 0) {
151
+ return;
152
+ }
153
+
154
+ // 一级元素显示名列表
155
+ var provinces = [''];
156
+ if (cascadeLayer > 0) {
157
+ provinces = raw.map(function (d) {
158
+ return d.name;
159
+ });
160
+ }
161
+
162
+ // 一级元素显示值列表
163
+ // 对value值进行追加,以保证防重名的处理
164
+ var provincesValue = [''];
165
+ if (cascadeLayer > 0) {
166
+ provincesValue = raw.map(function (d, i) {
167
+ return d.value;
168
+ });
169
+ }
170
+
171
+ // 初始化二级元素显示名列表
172
+ var initCities = [''];
173
+ if (cascadeLayer > 1) {
174
+ initCities = sub(raw[0], 'name');
175
+ }
176
+
177
+ // 初始化二级元素显示值列表
178
+ var initCitiesValue = [''];
179
+ if (cascadeLayer > 1) {
180
+ initCitiesValue = sub(raw[0], 'value');
181
+ }
182
+
183
+ // 初始化三级元素显示名列表
184
+ var initDistricts = [""];
185
+ // 初始化三级元素显示值列表
186
+ var initDistrictsValue = [""];
187
+ if (cascadeLayer > 2) {
188
+ if (!raw[0].sub) {
189
+ initDistricts = [""];
190
+ initDistrictsValue = [""];
191
+ } else {
192
+ initDistricts = sub(raw[0].sub[0], 'name');
193
+ initDistrictsValue = sub(raw[0].sub[0], 'value');
194
+ }
195
+ }
196
+
197
+ var currentProvince = provincesValue[0];
198
+ var currentCity = initCitiesValue[0];
199
+ var currentDistrict = initDistrictsValue[0];
200
+
201
+ // 默认配置
202
+ var t;
203
+ var defaults = {
204
+
205
+ cssClass: "city-picker",
206
+ rotateEffect: false, //为了性能
207
+
208
+ onChange: function onChange(picker, values, displayValues) {
209
+ var newProvince = picker.cols[0].value;
210
+ var newCity;
211
+ if (newProvince !== currentProvince) {
212
+ // 如果Province变化,节流以提高reRender性能
213
+ clearTimeout(t);
214
+
215
+ t = setTimeout(function () {
216
+ if (cascadeLayer > 1) {
217
+ var newCities = getCities(newProvince, 'name');
218
+ var newCitiesValue = getCities(newProvince, 'value');
219
+ newCity = newCitiesValue[0];
220
+ picker.cols[1].replaceValues(newCitiesValue, newCities);
221
+ currentCity = newCity;
222
+ }
223
+
224
+ if (cascadeLayer > 2) {
225
+ var newDistricts = getDistricts(newProvince, newCity, 'name');
226
+ var newDistrictsValue = getDistricts(newProvince, newCity, 'value');
227
+ picker.cols[2].replaceValues(newDistrictsValue, newDistricts);
228
+ }
229
+ currentProvince = newProvince;
230
+ picker.updateValue();
231
+ }, 200);
232
+ return;
233
+ }
234
+
235
+ if (cascadeLayer === 3) {
236
+ newCity = picker.cols[1].value;
237
+ if (newCity !== currentCity) {
238
+ picker.cols[2].replaceValues(getDistricts(newProvince, newCity, 'value'), getDistricts(newProvince, newCity, 'name'));
239
+ currentCity = newCity;
240
+ picker.updateValue();
241
+ }
242
+ }
243
+ },
244
+
245
+ cols: []
246
+ };
247
+ if (cascadeLayer === 1) {
248
+ defaults.cols.push({
249
+ textAlign: 'center',
250
+ displayValues: provinces,
251
+ values: provincesValue,
252
+ cssClass: "col-province"
253
+ });
254
+ } else if (cascadeLayer === 2) {
255
+ defaults.cols.push({
256
+ textAlign: 'center',
257
+ displayValues: provinces,
258
+ values: provincesValue,
259
+ cssClass: "col-province"
260
+ });
261
+ defaults.cols.push({
262
+ textAlign: 'center',
263
+ displayValues: initCities,
264
+ values: initCitiesValue,
265
+ cssClass: "col-city"
266
+ });
267
+ } else if (cascadeLayer === 3) {
268
+ defaults.cols.push({
269
+ textAlign: 'center',
270
+ displayValues: provinces,
271
+ values: provincesValue,
272
+ cssClass: "col-province"
273
+ });
274
+ defaults.cols.push({
275
+ textAlign: 'center',
276
+ displayValues: initCities,
277
+ values: initCitiesValue,
278
+ cssClass: "col-city"
279
+ });
280
+ defaults.cols.push({
281
+ textAlign: 'center',
282
+ displayValues: initDistricts,
283
+ values: initDistrictsValue,
284
+ cssClass: "col-district"
285
+ });
286
+ }
287
+
288
+ return $this.each(function () {
289
+ // 继承默认配置参数
290
+ var p = $.extend(defaults, params);
291
+
292
+ //计算value
293
+ if (p.value) {
294
+ $(this).val(p.value.join(' '));
295
+ } else {
296
+ var val = $(this).val();
297
+ val && (p.value = val.split(' '));
298
+ }
299
+
300
+ if (p.value) {
301
+ //p.value = val.split(" ");
302
+ if (p.value[0]) {
303
+ currentProvince = p.value[0];
304
+ p.cols[1].values = getCities(p.value[0]);
305
+ }
306
+ if (p.value[1]) {
307
+ currentCity = p.value[1];
308
+ p.cols[2].values = getDistricts(p.value[0], p.value[1]);
309
+ } else {
310
+ p.cols[2].values = getDistricts(p.value[0], p.cols[1].values[0]);
311
+ }
312
+ !p.value[2] && (p.value[2] = '');
313
+ currentDistrict = p.value[2];
314
+ }
315
+ (0, _picker2.default)(seletor, p);
316
+ });
317
+ };
318
+
319
+ /***/ })
320
+
321
+ },[217]);
322
+ });