1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | let Yox = require("./lib/yox");
|
19 | let jQuery = require("jquery");
|
20 | let _ = require("lodash");
|
21 | let Store = require("./lib/store");
|
22 | let Router = require("./lib/yox-router");
|
23 |
|
24 | let shortid = require("shortid");
|
25 |
|
26 | let dayjs = require("./lib/dayjs").dayjs;
|
27 | let pkg = require("../package.json");
|
28 |
|
29 | Yox.uuid = shortid;
|
30 |
|
31 | Yox.prototype.getSlot = function (name) {
|
32 | return this.get(`$slot_${name}`);
|
33 | };
|
34 |
|
35 | Yox.prototype.hasSlot = function (name) {
|
36 | return typeof this.getSlot(name) !== "undefined";
|
37 | };
|
38 |
|
39 | Yox.prototype.$store = function (name) {
|
40 | return typeof this.getSlot(name) !== "undefined";
|
41 | };
|
42 |
|
43 |
|
44 | Yox.prototype.$http = function (options) {
|
45 | return jQuery.ajax(options);
|
46 | };
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | let FireBird = (function () {
|
111 | function FireBird(options) {
|
112 | return new Yox(options);
|
113 | }
|
114 |
|
115 | return FireBird;
|
116 | })();
|
117 |
|
118 | FireBird.findComponentUpward = function (parent, componentName) {
|
119 | if (typeof componentName === 'string') {
|
120 | componentName = [componentName]
|
121 | } else {
|
122 | componentName = componentName
|
123 | }
|
124 |
|
125 | while (parent) {
|
126 | let {name} = parent.$options
|
127 | if (name && _.indexOf(componentName, name) >= 0) {
|
128 | break
|
129 | } else {
|
130 | parent = parent.$parent
|
131 | }
|
132 | }
|
133 |
|
134 | return parent
|
135 | };
|
136 |
|
137 | FireBird.prototype = Yox.prototype;
|
138 |
|
139 | _.each(Yox, (func, name) => {
|
140 | FireBird[name] = func;
|
141 | });
|
142 |
|
143 |
|
144 | FireBird.log = (msg) => {
|
145 | console.log(`[FireBird info]: ${msg}`);
|
146 | };
|
147 | FireBird.warn = (msg) => {
|
148 | console.warn(`[FireBird warn]: ${msg}`);
|
149 | };
|
150 | FireBird.error = (msg) => {
|
151 | console.error(`[FireBird error]: ${msg}`);
|
152 | };
|
153 |
|
154 |
|
155 | FireBird.components = {};
|
156 |
|
157 | FireBird.classes = {};
|
158 |
|
159 | FireBird.namespace = function () {
|
160 | var a = arguments, o, i = 0, j, d, arg;
|
161 | for (; i < a.length; i++) {
|
162 | o = this;
|
163 | arg = a[i];
|
164 | if (arg.indexOf(".") > -1) {
|
165 | d = arg.split(".");
|
166 | for (j = (d[0] == 'FireBird') ? 1 : 0; j < d.length; j++) {
|
167 | o[d[j]] = o[d[j]] || {};
|
168 | o = o[d[j]];
|
169 | }
|
170 | } else {
|
171 | o[arg] = o[arg] || {};
|
172 | o = o[arg];
|
173 | }
|
174 | }
|
175 | return o;
|
176 | };
|
177 |
|
178 | FireBird.create = (name, options) => {
|
179 | return new FireBird($.extend(true, {}, FireBird.components[name], options));
|
180 | };
|
181 |
|
182 | FireBird.addMember = function (name, member) {
|
183 | Yox.prototype[name] = member;
|
184 | return this;
|
185 | };
|
186 |
|
187 |
|
188 | FireBird.component = (name, options) => {
|
189 | if (typeof name === "string") {
|
190 | if (typeof options === "function") {
|
191 |
|
192 | } else {
|
193 | options.$$name = name;
|
194 | if (options.extend) {
|
195 |
|
196 | if (typeof options.extend === "string") {
|
197 | options.extend = FireBird.components[options.extend] || null;
|
198 | }
|
199 |
|
200 | options = $.extend(true, {}, options.extend, options, {
|
201 | "$$parent": options.extend.$$name
|
202 | });
|
203 | }
|
204 | }
|
205 |
|
206 | Yox.component(name, options);
|
207 | FireBird.log(`组件 ${name} 已注册`);
|
208 | FireBird.components[name] = options;
|
209 |
|
210 | FireBird.namespace(name);
|
211 | return options;
|
212 | }
|
213 | if (typeof name === "object") {
|
214 | _.each(name, (options, comp) => {
|
215 | FireBird.component(comp, options);
|
216 | });
|
217 | }
|
218 | };
|
219 |
|
220 | FireBird.partials = {};
|
221 |
|
222 | FireBird.partial = (name, template) => {
|
223 | if (typeof name === "string") {
|
224 | Yox.partial(name, template);
|
225 | FireBird.log(`模版 ${name} 已注册`);
|
226 | FireBird.partials[name] = template;
|
227 | return template;
|
228 | }
|
229 | if (typeof name === "object") {
|
230 | _.each(name, (template, partial) => {
|
231 | FireBird.partial(partial, template);
|
232 | });
|
233 | }
|
234 | };
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 | FireBird.css = (cssObject = {}) => {
|
248 | let classes = [];
|
249 | _.each(cssObject, (value, cssName) => {
|
250 | if (value === true) {
|
251 | classes.push(cssName);
|
252 | }
|
253 | });
|
254 | return classes.join(" ");
|
255 | };
|
256 |
|
257 |
|
258 | FireBird.style = (styleObject = {}) => {
|
259 | let style = [];
|
260 |
|
261 | _.each(styleObject, (v, k) => {
|
262 | switch (k) {
|
263 | case "width":
|
264 | case "height":
|
265 | case "min-height":
|
266 | case "min-width":
|
267 | case "top":
|
268 | case "left":
|
269 | case "bottom":
|
270 | case "right":
|
271 | case "line-height":
|
272 | if (_.isNumber(v)) {
|
273 | style.push(`${k}: ${v}px`);
|
274 | } else {
|
275 | style.push(`${k}: ${v}`);
|
276 | }
|
277 | break;
|
278 | default:
|
279 | style.push(`${k}: ${v}`);
|
280 | }
|
281 |
|
282 | });
|
283 |
|
284 | return style.join("; ");
|
285 | };
|
286 |
|
287 | FireBird.oneOf = (value, defaults, array = []) => {
|
288 | if (!FireBird.array.has(array, value)) {
|
289 | return defaults;
|
290 | }
|
291 | return value;
|
292 | };
|
293 |
|
294 | FireBird.filter("css", FireBird.css);
|
295 |
|
296 | FireBird.filter("style", FireBird.style);
|
297 |
|
298 | FireBird.filter("oneOf", FireBird.oneOf);
|
299 |
|
300 | FireBird.compile = Yox.compile;
|
301 |
|
302 | FireBird.filter("_defaults", function (val, def) {
|
303 | return typeof val === "undefined" ? (typeof def === "undefined" ? "" : def) : val;
|
304 | });
|
305 |
|
306 | FireBird.filter("Function", function (val, def) {
|
307 | return (new Function(
|
308 | "//this data from FireBird Filter 'Function' Wrapper; \n return " + (typeof val === "undefined" ? (typeof def === "undefined" ? "" : def) : val)))();
|
309 | });
|
310 |
|
311 | FireBird.filter("JSON_parse", function (val, def) {
|
312 | return JSON.parse(typeof val === "undefined" ? (typeof def === "undefined" ? "" : def) : val);
|
313 | });
|
314 |
|
315 | FireBird.filter("JSON_stringify", function (val, def, replacer, space) {
|
316 | return JSON.stringify(typeof val === "undefined" ? (typeof def === "undefined" ? "" : def) : val, replacer, space);
|
317 | });
|
318 |
|
319 | FireBird.filter("dayjs_fromNow", function (withoutSuffix) {
|
320 | return dayjs.fromNow(withoutSuffix);
|
321 | });
|
322 | FireBird.filter("dayjs_from", function (val, withoutSuffix) {
|
323 | return dayjs.from(val, withoutSuffix);
|
324 | });
|
325 | FireBird.filter("dayjs_toNow", function (withoutSuffix) {
|
326 | return dayjs.toNow(withoutSuffix);
|
327 | });
|
328 | FireBird.filter("dayjs_to", function (val, withoutSuffix) {
|
329 | return dayjs.to(val, withoutSuffix);
|
330 | });
|
331 |
|
332 | FireBird.directive = Yox.directive;
|
333 |
|
334 |
|
335 | FireBird.filter(_);
|
336 |
|
337 | Store.install(FireBird);
|
338 | Router.install(FireBird);
|
339 |
|
340 | FireBird.component("PageApp", {
|
341 | template: "<div></div>",
|
342 | data() {
|
343 | return {};
|
344 | }
|
345 | });
|
346 |
|
347 | FireBird.App = function () {
|
348 | console.log("FireBird.App")
|
349 | };
|
350 |
|
351 | global.FireBird = FireBird;
|
352 |
|
353 | let version = pkg.version;
|
354 | console.log(" _______________________________________________________________________");
|
355 | console.log("| |");
|
356 | console.log("| ######## #### ######## ######## ######## #### ######## ######## |");
|
357 | console.log("| ## ## ## ## ## ## ## ## ## ## ## ## |");
|
358 | console.log("| ## ## ## ## ## ## ## ## ## ## ## ## |");
|
359 | console.log("| ###### ## ######## ###### ######## ## ######## ## ## |");
|
360 | console.log("| ## ## ## ## ## ## ## ## ## ## ## ## |");
|
361 | console.log("| ## ## ## ## ## ## ## ## ## ## ## ## |");
|
362 | console.log("| ## #### ## ## ######## ######## #### ## ## ######## |");
|
363 | console.log("| |");
|
364 | console.log(`|${_.pad("", 71)}|`);
|
365 | console.log(`|${_.pad("Version: " + version, 71)}|`);
|
366 | console.log(`|${_.pad("Date: {{build-date}}", 71)}|`);
|
367 | console.log(`|${_.pad("Author: lincong1987@gmail.com", 71)}|`);
|
368 |
|
369 | console.log("|_______________________________________________________________________|");
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 | let $ = jQuery, lodash = _;
|
398 |
|
399 | module.exports = {
|
400 | FireBird,
|
401 | Store: Store.Store,
|
402 | Router,
|
403 | jQuery,
|
404 | $,
|
405 | _,
|
406 | lodash,
|
407 | dayjs,
|
408 | uuid: shortid,
|
409 | version
|
410 | };
|