core.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. /* ================================================================================
  2. * dever.js v1.0
  3. * http://git.shemic.com/dever/script
  4. * ================================================================================
  5. * Copyright 2017-2018 Dever(dever.cc)
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * ================================================================================
  19. */
  20. //<filter><script src="../script/lib/jquery/jquery.min.js"></script><script src="../script/dever/core.js"></script></filter>
  21. $(function()
  22. {
  23. Dever.Init();
  24. });
  25. //公共类库
  26. var Dever =
  27. {
  28. countdown : -1,
  29. modal : false,
  30. Init : function()
  31. {
  32. this.Import();
  33. this.Page().Init();
  34. this.User().Init();
  35. this.Editor().Init();
  36. this.Upload().Init();
  37. this.Change();
  38. this.LoadPage();
  39. this.Extend();
  40. //this.Target();
  41. //this.Pjax();
  42. }
  43. ,Pjax : function()
  44. {
  45. $(document).pjax('a', '.container');
  46. //$.pjax.reload('.container');
  47. }
  48. ,Page : function()
  49. {
  50. return _Dever_Page;
  51. }
  52. ,Template : function()
  53. {
  54. return _Dever_Template;
  55. }
  56. ,Editor : function()
  57. {
  58. return _Dever_Editor;
  59. }
  60. ,User : function()
  61. {
  62. return _Dever_User;
  63. }
  64. ,Modal : function()
  65. {
  66. return _Dever_Modal;
  67. }
  68. ,Upload : function()
  69. {
  70. return _Dever_Upload;
  71. }
  72. ,Proxy : function(uri)
  73. {
  74. return config.proxy + 'proxy_method=' + encodeURIComponent(uri);
  75. }
  76. ,Jump : function(url)
  77. {
  78. location.href = url;
  79. }
  80. ,BackRun : function(url)
  81. {
  82. $.post(url);
  83. }
  84. ,Reload : function(e)
  85. {
  86. e.attr('src', e.attr('src'));
  87. }
  88. ,Target : function()
  89. {
  90. var link = config.host;
  91. $("a").each(function() {
  92. if (!$(this).attr('onclick')) {
  93. var url = $(this).attr('href');
  94. if (url && url.indexOf(link) == -1) {
  95. //$(this).attr('target', '_blank');
  96. }
  97. }
  98. })
  99. }
  100. ,Time : function(e, time, text)
  101. {
  102. var self = this;
  103. if (this.countdown < 0) {
  104. this.countdown = time;
  105. }
  106. if (this.countdown == 0) {
  107. e.attr("disabled", false);
  108. e.html(text);
  109. self.Init();
  110. this.countdown = time;
  111. } else {
  112. e.attr("disabled", true);
  113. e.html(this.countdown + 's后' + text);
  114. this.countdown--;
  115. e.unbind('click');
  116. setTimeout(function() {
  117. self.Time(e, time, text)
  118. },1000)
  119. }
  120. }
  121. ,Import : function()
  122. {
  123. var self = this;
  124. var include = $("include");
  125. var count = include.length-1;
  126. if (include.length) {
  127. include.each(function(i){
  128. var dom = $(this);
  129. var system = dom.attr('system');
  130. var path = dom.attr('path');
  131. var name = dom.attr('file');
  132. var file = '';
  133. if(path) file = path;
  134. if(system) file = file + '/' + system;
  135. file += name + '.html';
  136. dom.load(file, function(){
  137. $("html").find("include").eq(i).get(0).outerHTML = dom.html();
  138. if (i == count) {
  139. self.Template().Init();
  140. }
  141. });
  142. })
  143. } else {
  144. self.Template().Init();
  145. }
  146. }
  147. ,LoadPage : function()
  148. {
  149. if ($('.dever-loadpage').length) {
  150. $('.dever-loadpage').each(function() {
  151. var url = $(this).attr('dever-url');
  152. var self = $(this);
  153. $.getJSON(Dever.CallUrl(url), function(t) {
  154. self.html(t.msg);
  155. _Dever_Page.Ajax(self);
  156. });
  157. });
  158. }
  159. }
  160. ,CallUrl : function(url)
  161. {
  162. if (url.indexOf('callback') == -1) {
  163. if (url.indexOf('=') != -1) {
  164. url += '&json=1&callback=?';
  165. } else {
  166. url += '?json=1&callback=?';
  167. }
  168. }
  169. return url;
  170. }
  171. ,Change : function()
  172. {
  173. if ($('.dever-change').length) {
  174. $('.dever-change').change(function() {
  175. Dever.Jump($(this).attr('dever-change')+$(this).val());
  176. });
  177. //$('.dever-change').val($('.dever-change').attr('dever-value'));
  178. }
  179. }
  180. ,Host : function(host, uri)
  181. {
  182. var result = '';
  183. uri = uri ? uri : '';
  184. result = config.host.replace('www', host);
  185. result = result.replace('main', host);
  186. if (config.proxy) {
  187. return this.Proxy(host + '/' + uri);
  188. }
  189. return result + uri;
  190. }
  191. // 输出数据,提示框
  192. ,Out : function(content, callback, title)
  193. {
  194. if (content && content.indexOf('登录') != -1 && $("#login_url").length) {
  195. var href = $("#login_url").val();
  196. location.href = href;
  197. return;
  198. } else {
  199. if (this.modal) {
  200. this.model.Alert(content, {'yes':callback, 'no':callback}, title);
  201. } else {
  202. this.Modal().Alert(content, {'yes':callback, 'no':callback}, title);
  203. }
  204. }
  205. }
  206. // 将数据解析,并进行下一步操作
  207. ,Msg : function(result, error_callback, success_callback)
  208. {
  209. if (result.status == 2) {
  210. if (result.data) {
  211. if (result.data.element) {
  212. if (result.data.attr) {
  213. $(result.data.element).attr(result.data.attr, result.data.value);
  214. } else {
  215. $(result.data.element).val(result.data.value);
  216. }
  217. } else if (result.data.url) {
  218. location.href = result.data.url;
  219. }
  220. }
  221. if (error_callback) {
  222. return error_callback(result.msg);
  223. }
  224. this.Out(result.msg);
  225. } else {
  226. if (typeof(result.data) == 'string') {
  227. result.msg = result.data;
  228. }
  229. if (success_callback) {
  230. return success_callback(result.msg);
  231. }
  232. if (result.msg.indexOf('http://') != -1) {
  233. this.Jump(result.msg);
  234. } else if (parseInt(result.msg) > 0) {
  235. this.Out('操作成功', function() {
  236. location.reload();
  237. });
  238. } else {
  239. this.Out(result.msg);
  240. }
  241. }
  242. }
  243. ,Confirm : function(content, callback, title)
  244. {
  245. if (this.modal) {
  246. this.model.Confirm(content, {'yes':callback}, title);
  247. } else {
  248. this.Modal().Confirm(content, {'yes':callback}, title);
  249. }
  250. }
  251. ,Extend : function()
  252. {
  253. Array.prototype.indexIn = function(val) {
  254. for (var i = 0; i < this.length; i++) {
  255. if (this[i] == val) return i;
  256. }
  257. return -1;
  258. };
  259. Array.prototype.remove = function(val) {
  260. var index = this.indexIn(val);
  261. if (index > -1) {
  262. this.splice(index, 1);
  263. }
  264. };
  265. $("select option").each(function() {
  266. if ($(this).attr('select') && $(this).attr('select') == 'true') {
  267. $(this).attr('selected', 'true');
  268. } else {
  269. $(this).removeAttr('selected');
  270. }
  271. });
  272. }
  273. ,Ucfirst : function(str)
  274. {
  275. var str = str.toLowerCase();
  276. var strarr = str.split(' ');
  277. var result = '';
  278. for (var i in strarr){
  279. result += strarr[i].substring(0,1).toUpperCase()+strarr[i].substring(1)+' ';
  280. }
  281. return result;
  282. }
  283. };
  284. //瀑布流分页
  285. var _Dever_Page =
  286. {
  287. name : '',
  288. Init : function()
  289. {
  290. if ($(this.name).length) {
  291. var self = this;
  292. $(window).scroll(function() {
  293. if ($(window).scrollTop() >= $(document).height() - $(window).height()) {
  294. self.Start(self.name);
  295. }
  296. });
  297. }
  298. }
  299. ,Start : function(page)
  300. {
  301. page = page ? page : this.name;
  302. if ($(page).length) {
  303. $(page).hide();
  304. var url = $(page).attr('link');
  305. if (url) {
  306. var key = $(page).attr('dever-list');
  307. $.get(url, function(t) {
  308. t = '<div>' + t + '</div>';
  309. var c = $(t).find(key).html();
  310. if (c) {
  311. $(key).append(c);
  312. var l = $(t).find(page).attr('link');
  313. $(page).attr('link', l);
  314. }
  315. });
  316. }
  317. }
  318. }
  319. ,Ajax : function(e)
  320. {
  321. var self = this;
  322. e.find('a').each(function() {
  323. var url = $(this).attr('href');
  324. $(this).attr('href', 'javascript:;');
  325. $(this).unbind('click').bind('click', function() {
  326. $.get(url.replace('callback', ''), function(t) {
  327. e.html(t);
  328. self.Ajax(e);
  329. });
  330. });
  331. });
  332. }
  333. }
  334. //模态框
  335. var _Dever_Modal =
  336. {
  337. state : false,
  338. html : '',
  339. box : '',
  340. title : '',
  341. content : '',
  342. yes : '',
  343. no : '',
  344. setting : '',
  345. confirm : '',
  346. Init : function()
  347. {
  348. this.state = false;
  349. if (this.html) {
  350. $('body').append(this.html);
  351. }
  352. if (this.box && this.content) {
  353. this.box = $(this.box);
  354. if (this.box.length) {
  355. this.box.hide();
  356. this.content = $(this.content);
  357. if(this.title) this.title = $(this.title);
  358. if(this.yes) this.yes = $(this.yes);
  359. if(this.no) this.no = $(this.no);
  360. if(this.setting) this.setting = $(this.setting);
  361. if(this.confirm) this.confirm = $(this.confirm);
  362. if(!this.timeout) this.timeout = 3000;
  363. this.state = true;
  364. }
  365. }
  366. }
  367. ,Alert : function(content, callback, title)
  368. {
  369. if (this.state == false) {
  370. alert(content);
  371. if (callback) {
  372. callback.yes();
  373. }
  374. } else {
  375. if (this.setting.length && this.setting.html()) {
  376. if (this.confirm) this.confirm.hide();
  377. this.setting.show();
  378. } else {
  379. if (this.setting) this.setting.hide();
  380. if (this.confirm) this.confirm.show();
  381. }
  382. this.content.html(content);
  383. if (title) {
  384. this.title.html(title);
  385. }
  386. this.box.show();
  387. if (callback.yes) {
  388. this.Bind(callback);
  389. } else {
  390. this.TimeOut();
  391. }
  392. }
  393. }
  394. ,Confirm : function(content, callback, title)
  395. {
  396. if (this.state == false) {
  397. if (confirm(content)) {
  398. callback.yes();
  399. }
  400. } else {
  401. if (this.confirm) this.confirm.show();
  402. if (this.setting) this.setting.hide();
  403. this.content.html(content);
  404. if (title) {
  405. this.title.html(title);
  406. }
  407. this.box.show();
  408. if (callback.yes) {
  409. this.Bind(callback);
  410. }
  411. }
  412. }
  413. ,Bind : function(callback)
  414. {
  415. if (this.yes.length && callback.yes) {
  416. this.yes.unbind('click').bind('click', callback.yes);
  417. }
  418. if (this.no.length) {
  419. if (callback.no) {
  420. this.no.unbind('click').bind('click', callback.no);
  421. } else {
  422. var self = this;
  423. this.no.unbind('click').bind('click', function()
  424. {
  425. self.Close();
  426. });
  427. }
  428. }
  429. }
  430. ,TimeOut : function()
  431. {
  432. var self = this;
  433. setTimeout(function(){self.Close()}, self.timeout);
  434. }
  435. ,Close : function()
  436. {
  437. this.box.hide();
  438. }
  439. }
  440. //用户相关
  441. var _Dever_User =
  442. {
  443. config : [],
  444. uid : -1,
  445. name : '匿名用户',
  446. Init : function()
  447. {
  448. var self = this;
  449. if (this.config.click) {
  450. for (var i in this.config.click) {
  451. var e = self.config.click[i];
  452. var c = 1;
  453. if (e.indexOf('|') != -1) {
  454. var t = e.split('|');
  455. e = t[0];
  456. c = 2;
  457. }
  458. if ($(e).length) {
  459. $(e).attr('data-i', i);
  460. $(e).attr('data-c', c);
  461. $(e).unbind('click').bind('click', function() {
  462. if ($(this).attr('data-c') == 2) {
  463. var t1 = $(this);
  464. Dever.Confirm(function() {
  465. self.Save($(this).attr('data-i'), t1, config);
  466. });
  467. } else {
  468. self.Save($(this).attr('data-i'), $(this), config);
  469. }
  470. });
  471. }
  472. }
  473. }
  474. }
  475. //通用的保存数据功能
  476. ,Save : function(key, e, setting)
  477. {
  478. var self = this;
  479. var config = self.config[key];
  480. if (config.start) {
  481. config.start.call();
  482. }
  483. var send = {};
  484. var callback = function(msg,state) {
  485. if (config.status && $(config.status).length) {
  486. //$(config.status).html(msg).css('visibility','initial');
  487. state ? $(config.status).html(msg).hide() : $(config.status).html(msg).show();
  488. } else if(!state) {
  489. Dever.Out(msg);
  490. }
  491. }
  492. if (typeof(config.input) != 'undefined') {
  493. if (typeof(config.input) == 'string' && config.input == 'parent') {
  494. if (e.attr('dever-send')) {
  495. send[e.attr('dever-send')] = e.attr('dever-' + e.attr('dever-send'));
  496. }
  497. send.id = e.attr('dever-id');
  498. send.value = e.parent().find('input').val();
  499. if (!send.id || !send.value) {
  500. callback(config.error);
  501. return;
  502. }
  503. } else if (typeof(config.input) == 'string' && config.input == 'click') {
  504. if (e.attr('dever-send')) {
  505. var a = e.attr('dever-send').split('&');
  506. for (var i in a) {
  507. if (typeof(a[i]) == 'string') {
  508. var b = a[i].split('=');
  509. send[b[0]] = b[1];
  510. }
  511. }
  512. }
  513. } else if (typeof(config.input) == 'object') {
  514. for (var i in config.input) {
  515. var option = false;
  516. var input = config.input[i];
  517. if (typeof(input) == 'object') {
  518. send[i] = input();
  519. } else {
  520. if (input.indexOf('|') != -1) {
  521. var t = input.split('|');
  522. input = t[0];
  523. option = true;
  524. }
  525. var m = true;
  526. var el = $(input);
  527. //e.get(0).tagName == 'TEXTAREA'
  528. send[i] = el.val();
  529. if (option == false) {
  530. if (send[i] && el.attr('dever-match')) {
  531. var r = new RegExp(el.attr('dever-match'));
  532. m = r.test(send[i]);
  533. }
  534. if (send[i] && el.attr('dever-value')) {
  535. m = $(el.attr('dever-value')).val() == send[i];
  536. }
  537. if (!send[i] || m != true) {
  538. var error = el.attr('dever-error') ? el.attr('dever-error') : config.error;
  539. callback(error);
  540. return;
  541. }
  542. }
  543. }
  544. }
  545. }
  546. }
  547. if (!send) {
  548. callback(config.error);
  549. return;
  550. }
  551. if (!config.url) {
  552. config.url = e.attr('dever-send');
  553. }
  554. if (e.attr('dever-refresh')) {
  555. config.url = e.attr('dever-refresh');
  556. }
  557. callback(1,1);
  558. config.url = Dever.CallUrl(config.url);
  559. if (setting.proxy) {
  560. $.post(config.url, send, function(t) {
  561. t = eval('(' + t + ')');
  562. Dever.Msg(t, callback, (config.callback ? function(msg){config.callback(e,msg,t)} : false));
  563. });
  564. } else {
  565. $.getJSON(config.url, send, function(t) {
  566. Dever.Msg(t, callback, (config.callback ? function(msg){config.callback(e,msg,t)} : false));
  567. });
  568. }
  569. }
  570. };
  571. //编辑器相关
  572. var _Dever_Editor =
  573. {
  574. state : false,
  575. editors : [],
  576. Init : function()
  577. {
  578. if (typeof marked == 'function') {
  579. this.state = true;
  580. } else {
  581. this.state = false;
  582. }
  583. this.SetMark();
  584. var self = this;
  585. if ($('.dever-note').length) {
  586. $('.dever-note').each(function() {
  587. self.InitEditor($(this));
  588. })
  589. }
  590. }
  591. ,InitEditor : function(e)
  592. {
  593. var id = e.attr('id');
  594. var key = e.attr('key');
  595. if (config.uid && config.uid > 0) {
  596. var toolbar = [
  597. 'title'
  598. ,'bold'
  599. ,'italic'
  600. ,'underline'
  601. ,'strikethrough'
  602. ,'fontScale'
  603. ,'color'
  604. ,'ol'
  605. ,'ul'
  606. ,'blockquote'
  607. ,'code'
  608. ,'table'
  609. ,'link'
  610. ,'image'
  611. ,'hr'
  612. ,'indent'
  613. ,'outdent'
  614. ,'alignment'
  615. //,'emoji'
  616. ];
  617. } else {
  618. var toolbar = [
  619. 'title'
  620. ,'bold'
  621. ,'fontScale'
  622. ,'color'
  623. ,'ol'
  624. ,'ul'
  625. ,'blockquote'
  626. ,'indent'
  627. ,'outdent'
  628. ,'alignment'
  629. ];
  630. }
  631. if (typeof(this.editors[id]) == "undefined") {
  632. this.editors[id] = new Simditor({
  633. textarea: e,
  634. upload:
  635. {
  636. url: config.upload + '.simditor',
  637. params: {key:key},
  638. fileKey: 'file',
  639. connectionCount: 10,
  640. leaveConfirm: 'Uploading is in progress, are you sure to leave this page?'
  641. },
  642. toolbar : toolbar
  643. /*
  644. ,emoji:
  645. {
  646. imagePath: config.lib + 'simditor/plugins/emoji/images/emoji/'
  647. }
  648. */
  649. });
  650. }
  651. }
  652. ,SetMark : function()
  653. {
  654. return;
  655. }
  656. ,GetMark : function(content)
  657. {
  658. if (this.state == true) {
  659. return marked(content);
  660. }
  661. return content;
  662. }
  663. };
  664. //模板
  665. var _Dever_Template =
  666. {
  667. state : false,
  668. method : '',
  669. element : '',
  670. data : '',
  671. param : '',
  672. attr : '',
  673. Init : function()
  674. {
  675. if (this.Check()) {
  676. var url = config.proxyTemplateUrl;
  677. var send = {};
  678. var parsing = [];
  679. $("dever").each(function(){
  680. parsing.push($(this).html());
  681. $(this).remove();
  682. });
  683. send.url = location.href;
  684. send.parsing = parsing.join('');
  685. send.html = $("html").html();
  686. //$("html").html('dever template loading...');
  687. $.ajax({
  688. type: "POST",
  689. url: url,
  690. data: send,
  691. dataType: "json",
  692. success: function(result){
  693. $("html").html(result.data);
  694. }
  695. });
  696. }
  697. }
  698. ,Check : function()
  699. {
  700. if ($("dever").length) {
  701. this.state = true;
  702. } else {
  703. this.state = false;
  704. }
  705. return this.state;
  706. }
  707. }
  708. //上传 请载入layui
  709. var _Dever_Upload =
  710. {
  711. upload : [],
  712. upload_file : [],
  713. upload_pic : [],
  714. callback : {},
  715. Init : function()
  716. {
  717. var self = this;
  718. if ($(".dever-upload-drag").length) {
  719. $(".dever-upload-drag").each(function() {
  720. var key = $(this).attr('key');
  721. if (config.proxy) {
  722. var url = Dever.Proxy('upload/save.drag') + '&key=' + key;
  723. } else {
  724. var url = config.upload + '.drag?key='+ key;
  725. }
  726. $(this).inlineattachment({
  727. uploadUrl: url,
  728. progressText: '![文件上传中...]()',
  729. urlText: "![文件描述]({filename})\n",
  730. errorText: '上传失败'
  731. });
  732. });
  733. }
  734. if ($(".dever-upload").length) {
  735. $(".dever-upload").each(function(i) {
  736. self.Load(i,$(this));
  737. })
  738. }
  739. }
  740. ,Load : function(i,e)
  741. {
  742. var self = this;
  743. var id = e.attr('id');
  744. var value = e.attr('dever-upload-value');
  745. var key = e.attr('dever-upload-key');
  746. var url = config.upload + '.start';
  747. if (typeof(this.upload[value]) != "undefined") {
  748. return;
  749. }
  750. if (!key) {
  751. key = 1;
  752. }
  753. self.upload[value] = true;
  754. self.upload_pic[value] = [];
  755. self.upload_file[value] = [];
  756. layui.use(['upload','layer'], function() {
  757. var layer = layui.layer;
  758. var layuiUpload = layui.upload;
  759. var uploadInst = layuiUpload.render({
  760. elem: '#' + id
  761. ,data: {'key' : key}
  762. ,field: 'file'
  763. ,url: url
  764. ,multiple: true
  765. ,before: function(obj) {
  766. layer.load();
  767. }
  768. ,done: function(data) {
  769. layer.closeAll('loading');
  770. if (data.status == 1) {
  771. var type = e.attr('dever-upload-type');
  772. var html = '';
  773. var callback = e.attr('dever-upload-callback');
  774. if (type == 'mul') {
  775. if (self.upload_pic[value].length <= 0 && $("#" + value).val()) {
  776. self.upload_pic[value] = $("#" + value).val().split(',');
  777. }
  778. if (self.callback && self.callback[callback]) {
  779. html += self.callback[callback].call(self, e, data.url, 'dever-upload-close');
  780. } else {
  781. html += '<li><img src="'+data.url+'" class="pics"><em class="dever-upload-close"></em></li>';
  782. }
  783. if (html) {
  784. e.before(html);
  785. }
  786. self.Close(value);
  787. self.upload_pic[value].push(data.url);
  788. $("#" + value).val(self.upload_pic[value].join(','));
  789. } else {
  790. if (self.callback && self.callback[callback]) {
  791. html = self.callback[callback].call(self, e, data.url, 'dever-upload-close');
  792. } else {
  793. html = '<img src="'+data.url+'" class="pics">';
  794. }
  795. if (html) {
  796. e.html(html);
  797. }
  798. }
  799. } else {
  800. layer.msg(data.msg, {icon: 4});
  801. return false;
  802. }
  803. }
  804. ,error: function() {
  805. layer.msg('上传失败', {icon: 4});
  806. return false;
  807. }
  808. });
  809. });
  810. }
  811. ,Close : function(v)
  812. {
  813. var self = this;
  814. $('.dever-upload-close').each(function()
  815. {
  816. $(this).unbind('click').bind('click', function() {
  817. var e = $(this).parent();
  818. var p = e.find('img').attr('src');
  819. e.remove();
  820. self.upload_pic[v].remove(p);
  821. $("#" + v).val(self.upload_pic[v].join(','));
  822. });
  823. });
  824. }
  825. }