app.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * UI v1.1.0
  3. * Copyright 2017-2018 Muyao
  4. * Licensed under the Muyao License 1.0
  5. */
  6. (function (window, document, $) {
  7. 'use strict';
  8. // 父级dom节点
  9. $.parentFrame = $(window.parent.document);
  10. // 父级方法&属性
  11. var parentFrame = window.parentFrame = window.parent;
  12. // 项目名称
  13. $.ctx = parentFrame.$.ctx;
  14. // 配置颜色获取方法
  15. $.colors = parentFrame.$.colors;
  16. // 注册组件默认配置参数获取方法
  17. $.po = parentFrame.$.po;
  18. // 本地存储对象操作
  19. $.storage = parentFrame.$.storage;
  20. $.sessionStorage = parentFrame.$.sessionStorage;
  21. // 网址基础设置对象
  22. $.site = parentFrame.$.site;
  23. if ($.site && $.site.contentTabs)
  24. $.site.contentTabs.ifameTabs(document);
  25. // 配置信息存储管理
  26. $.configs = parentFrame.$.configs;
  27. // 注册组件初始化
  28. if (parentFrame.$.components)
  29. parentFrame.$.components.init(document, window);
  30. // 公用对象
  31. window.Breakpoints = parentFrame.Breakpoints;
  32. window.toastr = parentFrame.toastr;
  33. window.layer = parentFrame.layer;
  34. window.haoutil = parentFrame.haoutil;
  35. window.notifyFn = parentFrame.$.notifyFn;
  36. // 自定义扩展对象
  37. var _objExtend = _objExtend || {};
  38. $.extend(_objExtend, {
  39. _queue: {
  40. prepare: [],
  41. run: [],
  42. complete: []
  43. },
  44. run: function () {
  45. var self = this;
  46. this._dequeue('prepare', function () {
  47. self._trigger('before.run', self);
  48. });
  49. this._dequeue('run', function () {
  50. self._dequeue('complete', function () {
  51. self._trigger('after.run', self);
  52. });
  53. });
  54. },
  55. _dequeue: function (name, done) { // 队列当前状态离队,进行下一步操作
  56. var self = this,
  57. queue = this._getQueue(name),
  58. fn = queue.shift(),
  59. next = function () {
  60. self._dequeue(name, done);
  61. };
  62. if (fn) {
  63. fn.call(this, next);
  64. } else if ($.isFunction(done)) {
  65. done.call(this);
  66. }
  67. },
  68. _getQueue: function (name) { // 获取队列状态信息
  69. if (!$.isArray(this._queue[name])) {
  70. this._queue[name] = [];
  71. }
  72. return this._queue[name];
  73. },
  74. extend: function (obj) { // 公用模块对象扩展方法
  75. $.each(this._queue, function (name, queue) {
  76. if ($.isFunction(obj[name])) {
  77. queue.unshift(obj[name]);
  78. delete obj[name];
  79. }
  80. });
  81. $.extend(this, obj);
  82. return this;
  83. },
  84. _trigger: function (name, data, $el) { // 离队状态执行动作
  85. if (typeof name === 'undefined') {
  86. return;
  87. }
  88. if (typeof $el === 'undefined') {
  89. $el = $("#admui-pageContent");
  90. }
  91. $el.trigger(name + '.app', data);
  92. }
  93. });
  94. // 通用功能对象(可配置增加,也可扩展)
  95. var _app = {
  96. pageAside: function () { // 小屏幕下侧边栏(展开&收起)操作
  97. var pageAside = $(".page-aside"),
  98. isOpen = pageAside.hasClass('open');
  99. pageAside.toggleClass('open', !isOpen);
  100. },
  101. run: function (next) {
  102. var self = this;
  103. // 侧边栏开关
  104. $(document).on('click', '.page-aside-switch', function (e) {
  105. self.pageAside();
  106. e.stopPropagation();
  107. });
  108. next();
  109. }
  110. };
  111. window.App = $.extend({}, _objExtend);
  112. App.extend(_app);
  113. })(window, document, jQuery);