spa.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /** Yue_admin-v1.1.0 MIT License By http://Yue/zhengjinfan.cn e-mail:zheng_jinfan@126.com */
  2. ;/**
  3. * Name:spa.js
  4. * Author:Van
  5. * E-mail:zheng_jinfan@126.com
  6. * Website:http://Yue.zhengjinfan.cn/
  7. * LICENSE:MIT
  8. */
  9. layui.define(['layer', 'nprogress', 'utils'], function (exports) {
  10. var $ = layui.jquery,
  11. layer = layui.layer,
  12. _modName = 'spa',
  13. utils = layui.utils;
  14. var Spa = function () {
  15. this.config = {
  16. elem: '#container',
  17. openWait: true
  18. };
  19. this.v = '1.0.0';
  20. };
  21. Spa.fn = Spa.prototype;
  22. Spa.fn.set = function (options) {
  23. var that = this;
  24. $.extend(true, that.config, options);
  25. return that;
  26. };
  27. Spa.fn.render = function (url, callback) {
  28. var that = this,
  29. _config = that.config,
  30. _elem = $(_config.elem),
  31. loadIndex = undefined;
  32. NProgress.start();
  33. if (_config.openWait)
  34. loadIndex = utils.load();
  35. var html = utils.getBodyContent(utils.loadHtml(url + '?v=' + new Date().getTime(), function () {
  36. setTimeout(function () {
  37. NProgress.done();
  38. _config.openWait && loadIndex && layer.close(loadIndex);
  39. }, 500);
  40. typeof callback === 'function' && callback();
  41. }));
  42. _elem.html(html);
  43. };
  44. var t = new Spa();
  45. exports('spa', t);
  46. });