common.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. var ns = window.ns_url;
  2. /**
  3. * 解析URL
  4. * @param {string} url 被解析的URL
  5. * @return {object} 解析后的数据
  6. */
  7. ns.parse_url = function (url) {
  8. var parse = url.match(/^(?:([0-9a-zA-Z]+):\/\/)?([\w-]+(?:\.[\w-]+)+)?(?::(\d+))?([\w-\/]+)?(?:\?((?:\w+=[^#&=\/]*)?(?:&\w+=[^#&=\/]*)*))?(?:#([\w-]+))?$/i);
  9. parse || $.error("url格式不正确!");
  10. return {
  11. "scheme": parse[1],
  12. "host": parse[2],
  13. "port": parse[3],
  14. "path": parse[4],
  15. "query": parse[5],
  16. "fragment": parse[6]
  17. };
  18. };
  19. ns.parse_str = function (str) {
  20. var value = str.split("&"), vars = {}, param;
  21. for (var i = 0; i < value.length; i++) {
  22. param = value[i].split("=");
  23. vars[param[0]] = param[1];
  24. }
  25. return vars;
  26. };
  27. ns.parse_name = function (name, type) {
  28. if (type) {
  29. /* 下划线转驼峰 */
  30. name = name.replace(/_([a-z])/g, function ($0, $1) {
  31. return $1.toUpperCase();
  32. });
  33. /* 首字母大写 */
  34. name = name.replace(/[a-z]/, function ($0) {
  35. return $0.toUpperCase();
  36. });
  37. } else {
  38. /* 大写字母转小写 */
  39. name = name.replace(/[A-Z]/g, function ($0) {
  40. return "_" + $0.toLowerCase();
  41. });
  42. /* 去掉首字符的下划线 */
  43. if (0 === name.indexOf("_")) {
  44. name = name.substr(1);
  45. }
  46. }
  47. return name;
  48. };
  49. //scheme://host:port/path?query#fragment
  50. ns.url = function (url, vars, suffix) {
  51. if (url.indexOf('http://') != -1 || url.indexOf('https://') != -1) {
  52. return url;
  53. }
  54. var info = this.parse_url(url), path = [], param = {}, reg;
  55. /* 验证info */
  56. info.path || alert("url格式错误!");
  57. url = info.path;
  58. // /* 解析URL */
  59. // path = url.split("/");
  60. // path = [path.pop(), path.pop(), path.pop()].reverse();
  61. // path[1] = path[1] || this.route[1];
  62. // path[0] = path[0] || this.route[0];
  63. // param[this.route[0]] = path[0];
  64. // param[this.route[1]] = path[1];
  65. // param[this.route[2]] = path[2].toLowerCase();
  66. // url = param[this.route[0]] + '/' + param[this.route[1]] + '/' + param[this.route[2]];
  67. // param[this.route[2]] = path[0];
  68. // param[this.route[3]] = path[1];
  69. // param[this.route[4]] = path[2].toLowerCase();
  70. // url = param[this.route[2]] + '/' + param[this.route[3]] + '/' + param[this.route[4]];
  71. /* 解析参数 */
  72. if (typeof vars === "string") {
  73. vars = this.parse_str(vars);
  74. } else if (!$.isPlainObject(vars)) {
  75. vars = {};
  76. }
  77. /* 添加伪静态后缀 */
  78. if (false !== suffix) {
  79. suffix = suffix || 'html';
  80. if (suffix) {
  81. url += "." + suffix;
  82. }
  83. }
  84. /* 解析URL自带的参数 */
  85. info.query && $.extend(vars, this.parse_str(info.query));
  86. var addon = '';
  87. if (info.scheme != '' && info.scheme != undefined) {
  88. addon = info.scheme + '/';
  89. }
  90. url = addon + url;
  91. if (vars) {
  92. var param_str = $.param(vars);
  93. if ('' !== param_str) {
  94. url += ((this.baseUrl + url).indexOf('?') !== -1 ? '&' : '?') + param_str;
  95. }
  96. }
  97. url = this.baseUrl + url;
  98. return url;
  99. };
  100. /**
  101. * 处理图片路径
  102. * type 类型 big、mid、small
  103. */
  104. ns.img = function (path, type = '') {
  105. var start = path.lastIndexOf('.');
  106. type = type ? '_' + type : '';
  107. var suffix = path.substring(start);
  108. var path = path.substring(0, start);
  109. var first = path.split("/");
  110. path += type + suffix;
  111. if (path.indexOf("http://") == -1 && path.indexOf("https://") == -1) {
  112. var base_url = this.baseUrl.replace('/?s=', '');
  113. var base_url = base_url.replace('/index.php', '');
  114. if (isNaN(first[0])) {
  115. var true_path = base_url + path;
  116. } else {
  117. var true_path = base_url + 'attachment/' + path;
  118. }
  119. } else {
  120. var true_path = path;
  121. }
  122. return true_path;
  123. };
  124. /**
  125. * 时间戳转时间
  126. *
  127. */
  128. var default_time_format = 'YYYY-MM-DD h:m:s';
  129. ns.time_to_date = function (timeStamp, time_format = '') {
  130. time_format = time_format == '' ? default_time_format : time_format;
  131. if (timeStamp > 0) {
  132. var date = new Date();
  133. date.setTime(timeStamp * 1000);
  134. var y = date.getFullYear();
  135. var m = date.getMonth() + 1;
  136. m = m < 10 ? ('0' + m) : m;
  137. var d = date.getDate();
  138. d = d < 10 ? ('0' + d) : d;
  139. var h = date.getHours();
  140. h = h < 10 ? ('0' + h) : h;
  141. var minute = date.getMinutes();
  142. var second = date.getSeconds();
  143. minute = minute < 10 ? ('0' + minute) : minute;
  144. second = second < 10 ? ('0' + second) : second;
  145. var time = '';
  146. time += time_format.indexOf('Y') > -1 ? y : '';
  147. time += time_format.indexOf('M') > -1 ? '-' + m : '';
  148. time += time_format.indexOf('D') > -1 ? '-' + d : '';
  149. time += time_format.indexOf('h') > -1 ? ' ' + h : '';
  150. time += time_format.indexOf('m') > -1 ? ':' + minute : '';
  151. time += time_format.indexOf('s') > -1 ? ':' + second : '';
  152. return time;
  153. } else {
  154. return "";
  155. }
  156. };
  157. /**
  158. * 日期 转换为 Unix时间戳
  159. * @param <string> 2014-01-01 20:20:20 日期格式
  160. * @return <int> unix时间戳(秒)
  161. */
  162. ns.date_to_time = function (string) {
  163. var f = string.split(' ', 2);
  164. var d = (f[0] ? f[0] : '').split('-', 3);
  165. var t = (f[1] ? f[1] : '').split(':', 3);
  166. return (new Date(
  167. parseInt(d[0], 10) || null,
  168. (parseInt(d[1], 10) || 1) - 1,
  169. parseInt(d[2], 10) || null,
  170. parseInt(t[0], 10) || null,
  171. parseInt(t[1], 10) || null,
  172. parseInt(t[2], 10) || null
  173. )).getTime() / 1000;
  174. };
  175. /**
  176. * url 反转义
  177. * @param url
  178. */
  179. ns.urlReplace = function (url) {
  180. var url = decodeURIComponent(url);
  181. var new_url = url.replace(/%2B/g, "+");//"+"转义
  182. new_url = new_url.replace(/%26/g, "&");//"&"
  183. new_url = new_url.replace(/%23/g, "#");//"#"
  184. new_url = new_url.replace(/%20/g, " ");//" "
  185. new_url = new_url.replace(/%3F/g, "?");//"#"
  186. new_url = new_url.replace(/%25/g, "%");//"#"
  187. new_url = new_url.replace(/&3D/g, "=");//"#"
  188. new_url = new_url.replace(/%2F/g, "/");//"#"
  189. return new_url;
  190. };
  191. /**
  192. * 需要定义APP_KEY,API_URL
  193. * method 插件名.控制器.方法
  194. * data json对象
  195. * async 是否异步,默认true 异步,false 同步
  196. */
  197. ns.api = function (method, param, callback, async) {
  198. // async true为异步请求 false为同步请求
  199. var async = async != undefined ? async : true;
  200. param.app_key = APP_KEY;
  201. $.ajax({
  202. type: 'get',
  203. url: API_URL + '?s=/api/index/get/method/' + method + '/version/1.0',
  204. dataType: "JSON",
  205. async: async,
  206. data: {'param': JSON.stringify(param), method: method},
  207. success: function (res) {
  208. if (callback) callback(eval("(" + res + ")"));
  209. }
  210. });
  211. };
  212. /**
  213. * url 反转义
  214. * @param url
  215. */
  216. ns.append_url_params = function (url, params) {
  217. if (params != undefined) {
  218. var url_params = '';
  219. for (var k in params) {
  220. url_params += "&" + k + "=" + params[k];
  221. }
  222. url += url_params;
  223. }
  224. return url;
  225. };
  226. /**
  227. * 生成随机不重复字符串
  228. * @param len
  229. * @returns {string}
  230. */
  231. ns.gen_non_duplicate = function (len) {
  232. return Number(Math.random().toString().substr(3, len) + Date.now()).toString(36);
  233. };
  234. /**
  235. * 获取分页参数
  236. * @param param 参数
  237. * @returns {{layout: string[]}}
  238. */
  239. ns.get_page_param = function (param) {
  240. var obj = {
  241. layout: ['count', 'limit', 'prev', 'page', 'next']
  242. };
  243. if (param != undefined) {
  244. if (param.limit != undefined) {
  245. obj.limit = param.limit;
  246. }
  247. }
  248. return obj;
  249. };
  250. /**
  251. * 弹出框,暂时没有使用
  252. * @param options 参数,参考layui:https://www.layui.com/doc/modules/layer.html
  253. */
  254. ns.open = function (options) {
  255. if (!options) options = {};
  256. options.type = options.type || 1;
  257. //宽高,小、中、大
  258. // options.size
  259. options.area = options.area || ['500px'];
  260. layer.open(options);
  261. };
  262. /**
  263. * 上传
  264. * @param id
  265. * @param method
  266. * @param param
  267. * @param callback
  268. * @param async
  269. */
  270. ns.upload_api = function (id, method, param, callback, async) {
  271. // async true为异步请求 false为同步请求
  272. var async = async != undefined ? async : true;
  273. param.app_key = APP_KEY;
  274. var file = document.getElementById(id).files[0];
  275. var formData = new FormData();
  276. formData.append("file", file);
  277. formData.append("method", method);
  278. formData.append("param", JSON.stringify(param));
  279. $.ajax({
  280. url: API_URL + '?s=/api/index/get/method/' + method + '/version/1.0',
  281. type: "post",
  282. data: formData,
  283. dataType: "JSON",
  284. contentType: false,
  285. processData: false,
  286. async: async,
  287. mimeType: "multipart/form-data",
  288. success: function (res) {
  289. if (callback) callback(eval("(" + res + ")"));
  290. },
  291. // error: function (data) {
  292. // console.log(data);
  293. // }
  294. });
  295. };
  296. /**
  297. * 复制
  298. * @param dom
  299. * @param callback
  300. */
  301. ns.copy = function JScopy(dom, callback) {
  302. var url = document.getElementById(dom);
  303. url.select();
  304. document.execCommand("Copy");
  305. var o = {
  306. url: url.value
  307. };
  308. if (callback) callback.call(this, o);
  309. layer.msg('复制成功');
  310. };
  311. ns.int_to_float = function (val){
  312. return new Number(val).toFixed(2);
  313. }
  314. var show_link_box_flag = true;
  315. /**
  316. * 弹出框-->选择链接
  317. * @param link
  318. * @param support_diy_view
  319. * @param callback
  320. * @param post 端口:admin、shop
  321. */
  322. ns.select_link = function (link, support_diy_view, callback, link_url) {
  323. var url = ns.url(link_url);
  324. if (show_link_box_flag) {
  325. show_link_box_flag = false;
  326. $.post(url, {link: JSON.stringify(link), support_diy_view: support_diy_view}, function (str) {
  327. window.linkIndex = layer.open({
  328. type: 1,
  329. title: "选择链接",
  330. content: str,
  331. btn: [],
  332. area: ['600px', '630px'], //宽高
  333. maxWidth: 1920,
  334. cancel: function (index, layero) {
  335. show_link_box_flag = true;
  336. },
  337. end: function () {
  338. if (window.linkData) {
  339. if (callback) callback(window.linkData);
  340. }
  341. show_link_box_flag = true;
  342. }
  343. });
  344. });
  345. }
  346. };
  347. var show_promote_flag = true;
  348. /**
  349. * 推广链接
  350. * @param data
  351. */
  352. ns.page_promote = function (data) {
  353. var url = ns.url("admin/diy/promote");
  354. if (show_promote_flag) {
  355. show_promote_flag = false;
  356. $.post(url, {data: JSON.stringify(data)}, function (str) {
  357. window.promoteIndex = layer.open({
  358. type: 1,
  359. title: "推广链接",
  360. content: str,
  361. btn: [],
  362. area: ['680px', '600px'], //宽高
  363. maxWidth: 1920,
  364. cancel: function (index, layero) {
  365. show_promote_flag = true;
  366. },
  367. end: function () {
  368. show_promote_flag = true;
  369. }
  370. });
  371. });
  372. }
  373. };
  374. //存储单元单位转换
  375. ns.sizeformat = function (limit) {
  376. if (limit == null || limit == "") {
  377. return "0KB"
  378. }
  379. var index = 0;
  380. var limit = limit.toUpperCase();//转换为小写
  381. if (limit.indexOf('B') == -1) { //如果无单位,加单位递归转换
  382. limit = limit + "B";
  383. //unitConver(limit);
  384. }
  385. var reCat = /[0-9]*[A-Z]B/;
  386. if (!reCat.test(limit) && limit.indexOf('B') != -1) { //如果单位是b,转换为kb加单位递归
  387. limit = limit.substring(0, limit.indexOf('B')); //去除单位,转换为数字格式
  388. limit = (limit / 1024) + 'KB'; //换算舍入加单位
  389. //unitConver(limit);
  390. }
  391. var array = new Array('KB', 'MB', 'GB', 'TB', 'PT');
  392. for (var i = 0; i < array.length; i++) { //记录所在的位置
  393. if (limit.indexOf(array[i]) != -1) {
  394. index = i;
  395. break;
  396. }
  397. }
  398. var limit = parseFloat(limit.substring(0, (limit.length - 2))); //得到纯数字
  399. while (limit >= 1024) {//数字部分1到1024之间
  400. limit /= 1024;
  401. index += 1;
  402. }
  403. limit = limit.toFixed(2) + array[index]
  404. return limit;
  405. }
  406. /**
  407. * 数据表格
  408. * layui官方文档:https://www.layui.com/doc/modules/table.html
  409. * @param options
  410. * @constructor
  411. */
  412. function Table(options) {
  413. if (!options) return;
  414. var _self = this;
  415. options.parseData = options.parseData || function (data) {
  416. return {
  417. "code": data.code,
  418. "msg": data.message,
  419. "count": data.data.count,
  420. "data": data.data.list
  421. };
  422. };
  423. options.request = options.request || {
  424. limitName: 'page_size' //每页数据量的参数名,默认:limit
  425. };
  426. if (options.page == undefined) {
  427. options.page = {
  428. layout: ['count', 'limit', 'prev', 'page', 'next'],
  429. limit: 10
  430. };
  431. }
  432. options.defaultToolbar = options.defaultToolbar || [];//'filter', 'print', 'exports'
  433. options.toolbar = options.toolbar || "";//头工具栏事件
  434. options.skin = options.skin || 'line';
  435. options.size = options.size || 'lg';
  436. options.async = (options.async != undefined) ? options.async : true;
  437. options.done = function (res, curr, count) {
  438. //加载图片放大
  439. loadImgMagnify();
  440. if (options.callback) options.callback();
  441. };
  442. layui.use('table', function () {
  443. _self._table = layui.table;
  444. _self._table.render(options);
  445. });
  446. this.filter = options.filter || options.elem.replace(/#/g, "");
  447. this.elem = options.elem;
  448. //获取当前选中的数据
  449. this.checkStatus = function () {
  450. return this._table.checkStatus(_self.elem.replace(/#/g, ""));
  451. };
  452. }
  453. /**
  454. * 监听头工具栏事件
  455. * @param callback 回调
  456. */
  457. Table.prototype.toolbar = function (callback) {
  458. var _self = this;
  459. var interval = setInterval(function () {
  460. if (_self._table) {
  461. _self._table.on('toolbar(' + _self.filter + ')', function (obj) {
  462. var checkStatus = _self._table.checkStatus(obj.config.id);
  463. obj.data = checkStatus.data;
  464. obj.isAll = checkStatus.isAll;
  465. if (callback) callback.call(this, obj);
  466. });
  467. clearInterval(interval);
  468. }
  469. }, 50);
  470. };
  471. /**
  472. * 监听底部工具栏事件
  473. * @param callback 回调
  474. */
  475. Table.prototype.bottomToolbar = function (callback) {
  476. var _self = this;
  477. var interval = setInterval(function () {
  478. if (_self._table) {
  479. _self._table.on('bottomToolbar(' + _self.filter + ')', function (obj) {
  480. var checkStatus = _self._table.checkStatus(obj.config.id);
  481. obj.data = checkStatus.data;
  482. obj.isAll = checkStatus.isAll;
  483. if (callback) callback.call(this, obj);
  484. });
  485. clearInterval(interval);
  486. }
  487. }, 50);
  488. };
  489. /**
  490. * 绑定layui的on事件
  491. * @param name
  492. * @param callback
  493. */
  494. Table.prototype.on = function (name, callback) {
  495. var _self = this;
  496. var interval = setInterval(function () {
  497. if (_self._table) {
  498. _self._table.on(name + '(' + _self.filter + ')', function (obj) {
  499. if (callback) callback.call(this, obj);
  500. });
  501. clearInterval(interval);
  502. }
  503. }, 50);
  504. };
  505. /**
  506. * //监听行工具事件
  507. * @param callback 回调
  508. */
  509. Table.prototype.tool = function (callback) {
  510. var _self = this;
  511. var interval = setInterval(function () {
  512. if (_self._table) {
  513. _self._table.on('tool(' + _self.filter + ')', function (obj) {
  514. if (callback) callback.call(this, obj);
  515. });
  516. clearInterval(interval);
  517. }
  518. }, 50);
  519. };
  520. /**
  521. * 刷新数据
  522. * @param options 参数,参考layui数据表格参数
  523. */
  524. Table.prototype.reload = function (options) {
  525. options = options || {
  526. page: {
  527. curr: 1
  528. }
  529. };
  530. var _self = this;
  531. var interval = setInterval(function () {
  532. if (_self._table) {
  533. _self._table.reload(_self.elem.replace(/#/g, ""), options);
  534. clearInterval(interval);
  535. }
  536. }, 50);
  537. };
  538. var layedit;
  539. /**
  540. * 富文本编辑器
  541. * https://www.layui.com/v1/doc/modules/layedit.html
  542. * @param id
  543. * @param options 参数,参考layui
  544. * @param callback 监听输入回调
  545. * @constructor
  546. */
  547. function Editor(id, options, callback) {
  548. options = options || {};
  549. this.id = id;
  550. var _self = this;
  551. layui.use(['layedit'], function () {
  552. layedit = layui.layedit;
  553. layedit.set({
  554. uploadImage: {
  555. url: ns.url("file://common/File/image")
  556. },
  557. callback: callback
  558. });
  559. _self.index = layedit.build(id, options);
  560. });
  561. }
  562. /**
  563. * 设置内容
  564. * @param content 内容
  565. * @param append 是否追加
  566. */
  567. Editor.prototype.setContent = function (content, append) {
  568. var _self = this;
  569. var time = setInterval(function () {
  570. layedit.setContent(_self.index, content, append);
  571. clearInterval(time);
  572. }, 150);
  573. };
  574. Editor.prototype.getContent = function () {
  575. return layedit.getContent(this.index);
  576. };
  577. Editor.prototype.getText = function () {
  578. return layedit.getText(this.index);
  579. };
  580. $(function () {
  581. loadImgMagnify();
  582. });
  583. //图片最大递归次数
  584. var IMG_MAX_RECURSIVE_COUNT = 6;
  585. var count = 0;
  586. /**
  587. * //加载图片放大
  588. */
  589. function loadImgMagnify() {
  590. setTimeout(function () {
  591. try {
  592. if (layer) {
  593. $("img[src!=''][layer-src]").each(function () {
  594. var id = getId($(this).parent());
  595. // console.log("id",id);
  596. layer.photos({
  597. photos: "#" + id,
  598. anim: 5
  599. });
  600. count = 0;
  601. });
  602. }
  603. } catch (e) {
  604. }
  605. }, 200);
  606. }
  607. function getId(o) {
  608. count++;
  609. var id = o.attr("id");
  610. // console.log("递归次数:", count,id);
  611. if (id == undefined && count < IMG_MAX_RECURSIVE_COUNT) {
  612. id = getId(o.parent());
  613. }
  614. if (id == undefined) {
  615. id = ns.gen_non_duplicate(10);
  616. o.attr("id", id);
  617. }
  618. return id;
  619. }
  620. // 返回(关闭弹窗)
  621. function back() {
  622. layer.closeAll('page');
  623. }
  624. /**
  625. * 自定义分页
  626. * @param options
  627. * @constructor
  628. */
  629. function Page(options) {
  630. if (!options) return;
  631. var _self = this;
  632. options.elem = options.elem.replace(/#/g, "");// 注意:这里不能加 # 号
  633. options.count = options.count || 0;// 数据总数。一般通过服务端得到
  634. options.limit = options.limit || 10;// 每页显示的条数。laypage将会借助 count 和 limit 计算出分页数。
  635. options.limits = options.limits || [];// 每页条数的选择项。如果 layout 参数开启了 limit,则会出现每页条数的select选择框
  636. options.curr = location.hash.replace('#!page=', '');// 起始页。一般用于刷新类型的跳页以及HASH跳页
  637. options.hash = options.hash || 'page';// 开启location.hash,并自定义 hash 值。如果开启,在触发分页时,会自动对url追加:#!hash值={curr} 利用这个,可以在页面载入时就定位到指定页
  638. options.groups = options.groups || 5;// 连续出现的页码个数
  639. options.prev = options.prev || '<i class="layui-icon layui-icon-left"></i>';// 自定义“上一页”的内容,支持传入普通文本和HTML
  640. options.next = options.next || '<i class="layui-icon layui-icon-right"></i>';// 自定义“下一页”的内容,同上
  641. options.first = options.first || 1;// 自定义“首页”的内容,同上
  642. // 自定义排版。可选值有:count(总条目输区域)、prev(上一页区域)、page(分页区域)、next(下一页区域)、limit(条目选项区域)、refresh(页面刷新区域。注意:layui 2.3.0 新增) 、skip(快捷跳页区域)
  643. options.layout = options.layout || ['count', 'prev', 'page', 'next'];
  644. options.jump = function (obj, first) {
  645. //首次不执行,一定要加此判断,否则初始时会无限刷新
  646. if (!first) {
  647. obj.page = obj.curr;
  648. options.callback.call(this, obj);
  649. }
  650. };
  651. layui.use('laypage', function () {
  652. _self._page = layui.laypage;
  653. _self._page.render(options);
  654. });
  655. }
  656. /**
  657. * 表单验证
  658. * @value options
  659. * @item
  660. */
  661. layui.use('form', function () {
  662. var form = layui.form;
  663. form.verify({
  664. required: function (value, item) {
  665. var str = $(item).parents(".layui-form-item").find("label").text().split("*").join("");
  666. str = str.substring(0, str.length - 1);
  667. if (value.trim() == "" || value == undefined || value == null) return str + "不能为空";
  668. }
  669. });
  670. });
  671. /**
  672. * 面板折叠
  673. * @value options
  674. * @item
  675. */
  676. layui.use('element', function () {
  677. var element = layui.element;
  678. element.on('collapse(selection_panel)', function (data) {
  679. if (data.show) {
  680. $(data.title).find("i").removeClass("layui-icon-up").addClass("layui-icon-down");
  681. } else {
  682. $(data.title).find("i").removeClass("layui-icon-down").addClass("layui-icon-up");
  683. }
  684. $(data.title).find("i").text('');
  685. });
  686. });