view.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. 
  2. /** layuiAdmin-v1.0.0-beta6 LPPL License By http://www.layui.com/admin/ */
  3. ;
  4. layui.define(["laytpl", "layer"],
  5. function(e) {
  6. var t = layui.jquery,
  7. a = layui.laytpl,
  8. n = layui.layer,
  9. r = layui.setter,
  10. o = (layui.device(), layui.hint()),
  11. i = function(e) {
  12. return new d(e);
  13. },
  14. s = "LAY_app_body",
  15. d = function(e) {
  16. this.id = e,
  17. this.container = t("#" + (e || s));
  18. };
  19. i.loading = function(e) {
  20. e.append(this
  21. .elemLoad =
  22. t('<i class="layui-anim layui-anim-rotate layui-anim-loop layui-icon layui-icon-loading layadmin-loading"></i>'))
  23. },
  24. i.removeLoad = function() {
  25. this.elemLoad && this.elemLoad.remove()
  26. },
  27. i.exit = function() {
  28. layui.data(r.tableName,
  29. {
  30. key: r.request.tokenName,
  31. remove: !0
  32. }),
  33. location.hash = "/user/login"
  34. },
  35. i.req = function(e) {
  36. var a = e.success,
  37. n = (e.error, r.request),
  38. o = r.response,
  39. s = function() {
  40. return r.debug ? "<br><cite>URL:</cite>" + e.url : ""
  41. };
  42. return e.data = e.data || {},
  43. e.headers = e.headers || {},
  44. n.tokenName &&
  45. (e.data[n.tokenName] = n
  46. .tokenName in
  47. e.data
  48. ? e.data[n.tokenName]
  49. : layui.data(r.tableName)[n.tokenName] || "", e.headers[n
  50. .tokenName] = n.tokenName in e.headers ? e.headers[n.tokenName] : layui.data(r.tableName)[n.tokenName] || ""),
  51. delete e.success,
  52. delete e.error,
  53. t.ajax(t.extend({
  54. type: "get",
  55. dataType: "json",
  56. success: function(t) {
  57. var n = o.statusCode;
  58. if (t[o.statusName] == n.ok) "function" == typeof e.done && e.done(t);
  59. else if (t[o.statusName] == n.logout) i.exit();
  60. else {
  61. var r = ["<cite>Error:</cite> " + (t[o.msgName] || "返回状态码异常"), s()].join("");
  62. i.error(r)
  63. }
  64. "function" == typeof a && a(t)
  65. },
  66. error: function(e, t) {
  67. var a = ["请求异常,请重试<br><cite>错误信息:</cite>" + t, s()].join("");
  68. i.error(a),
  69. "function" == typeof a && a(res)
  70. }
  71. },
  72. e))
  73. },
  74. i.popup = function(e) {
  75. var a = e.success,
  76. r = e.skin;
  77. delete e.success,
  78. delete e.skin,
  79. n.open(t.extend({
  80. type: 1,
  81. title: "提示",
  82. content: "",
  83. id: "LAY-system-view-popup",
  84. skin: "layui-layer-admin" + (r ? " " + r : ""),
  85. shadeClose: !0,
  86. closeBtn: !1,
  87. success: function(e, r) {
  88. var o = t('<i class="layui-icon" close>&#x1006;</i>');
  89. e.append(o),
  90. o.on("click",
  91. function() {
  92. n.close(r)
  93. }),
  94. "function" == typeof a && a.apply(this, arguments)
  95. }
  96. },
  97. e))
  98. },
  99. i.error = function(e, a) {
  100. return i.popup(t.extend({
  101. content: e,
  102. maxWidth: 300,
  103. offset: "t",
  104. anim: 6,
  105. id: "LAY_adminError"
  106. },
  107. a))
  108. },
  109. d.prototype.render = function(e, a) {
  110. var n = this;
  111. layui.router();
  112. return e = r.views + e + r.engine,
  113. t("#" + s).children(".layadmin-loading").remove(),
  114. i.loading(n.container),
  115. t.ajax({
  116. url: e,
  117. type: "get",
  118. dataType: "html",
  119. data: {
  120. v: layui.cache.version
  121. },
  122. success: function(e) {
  123. e = "<div>" + e + "</div>";
  124. var r = t(e).find("title"),
  125. o = r.text(),
  126. s = {
  127. title: o,
  128. body: e
  129. };
  130. r.remove(),
  131. n.params = a || {},
  132. n.then && (n.then(s), delete n.then),
  133. n.parse(e),
  134. i.removeLoad(),
  135. n.done && (n.done(s), delete n.done)
  136. },
  137. error: function(e) {
  138. return i.removeLoad(),
  139. n.render.isError
  140. ? i.error("请求视图文件异常,状态:" + e.status)
  141. : (404 === e.status ? n.render("template/tips/404") : n.render("template/tips/error"), void(n.render.isError = !
  142. 0)
  143. )
  144. }
  145. }),
  146. n
  147. },
  148. d.prototype.parse = function(e, n, r) {
  149. var s = this,
  150. d = "object" == typeof e,
  151. l = d ? e : t(e),
  152. u = d ? e : l.find("*[template]"),
  153. c = function(e) {
  154. var n = a(e.dataElem.html());
  155. e.dataElem.after(n.render(t.extend({
  156. params: y.params
  157. },
  158. e.res))),
  159. "function" == typeof r && r();
  160. try {
  161. e.done && new Function("d", e.done)(e.res)
  162. } catch (o) {
  163. console.error(e.dataElem[0], "\n存在错误回调脚本\n\n", o)
  164. }
  165. },
  166. y = layui.router();
  167. l.find("title").remove(),
  168. s.container[n ? "after" : "html"](l.children()),
  169. y.params = s.params || {};
  170. for (var p = u.length; p > 0; p--)
  171. !
  172. function() {
  173. var e = u.eq(p - 1),
  174. t = e.attr("lay-done") || e.attr("lay-then"),
  175. n = a(e.attr("lay-url") || "").render(y),
  176. r = a(e.attr("lay-data") || "").render(y),
  177. s = a(e.attr("lay-headers") || "").render(y);
  178. try {
  179. r = new Function("return " + r + ";")()
  180. } catch (d) {
  181. o.error("lay-data: " + d.message),
  182. r = {}
  183. }
  184. try {
  185. s = new Function("return " + s + ";")()
  186. } catch (d) {
  187. o.error("lay-headers: " + d.message),
  188. s = s || {}
  189. }
  190. n
  191. ? i.req({
  192. type: e.data("lay-type") || "get",
  193. url: n,
  194. data: r,
  195. dataType: "json",
  196. headers: s,
  197. success: function(a) {
  198. c({
  199. dataElem: e,
  200. res: a,
  201. done: t
  202. })
  203. }
  204. })
  205. : c({
  206. dataElem: e,
  207. done: t
  208. })
  209. }();
  210. return s
  211. },
  212. d.prototype.send = function(e, t) {
  213. var n = a(e || this.container.html()).render(t || {});
  214. return this.container.html(n),
  215. this
  216. },
  217. d.prototype.refresh = function(e) {
  218. var t = this,
  219. a = t.container.next(),
  220. n = a.attr("lay-templateid");
  221. return t.id != n
  222. ? t
  223. : (t.parse(t.container,
  224. "refresh",
  225. function() {
  226. t.container.siblings('[lay-templateid="' + t.id + '"]:last').remove(),
  227. "function" == typeof e && e()
  228. }), t)
  229. },
  230. d.prototype.then = function(e) {
  231. return this.then = e,
  232. this
  233. },
  234. d.prototype.done = function(e) {
  235. return this.done = e,
  236. this
  237. },
  238. e("view", i);
  239. });
  240. ;
  241. //data: (unavailable);
  242. //data[i].children: (unavailable);