截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. var lock = {};
  2. var load = {};
  3. layui.define(["jquery", "form", "upload"], function (exports) {
  4. $ = layui.$;
  5. upload = layui.upload;
  6. var ojb = {
  7. ajax: function (json) {
  8. var load_index = null;
  9. if (json.beforeSend === undefined) {
  10. if (lock[json.url.replace("/", "_")] !== undefined) {
  11. return
  12. }
  13. lock[json.url.replace("/", "_")] = true;
  14. json.beforeSend = function () {
  15. load[json.url.replace("/", "_")] = setTimeout(function () {
  16. load_index = layer.load(1, {shade: [0.1, "#fff"]})
  17. }, 1500)
  18. }
  19. }
  20. if (json.error === undefined) {
  21. json.error = function (res) {
  22. layer.msg("网络错误", {offset: "240px", icon: 2, time: 1500}, function () {
  23. return
  24. })
  25. }
  26. }
  27. if (json.timeout === undefined) {
  28. json.timeout = 30000
  29. }
  30. if (json.type === undefined) {
  31. json.type = "get"
  32. }
  33. json.complete = function (xhr, status) {
  34. delete lock[json.url.replace("/", "_")];
  35. if (status == "timeout") {
  36. layer.msg("请求超时,请重试", {offset: "240px", icon: 2, time: 1500}, function () {
  37. if (load_index !== undefined) {
  38. layer.close(load_index)
  39. }
  40. return
  41. });
  42. return
  43. }
  44. clearTimeout(load[json.url.replace("/", "_")]);
  45. if (load_index !== undefined) {
  46. layer.close(load_index)
  47. }
  48. res = xhr.responseJSON;
  49. if (res !== undefined && res.code == -1) {
  50. window.location.href = window.location.href
  51. }
  52. if (res !== undefined && res.code == 0 && res.show == 1) {
  53. layer.msg(res.msg, {offset: "240px", icon: 2, time: 1500}, function () {
  54. return;
  55. })
  56. }
  57. };
  58. $.ajax(json)
  59. }, imageUpload: function (element, upload_call_back,css, area, title) {
  60. var area = (area === undefined) ? ["90%", "90%"] : area;
  61. var title = (title === undefined) ? "上传图片" : title;
  62. var css = css === undefined ? false : css;
  63. var click_element = element;
  64. if(css === true){
  65. $(element).addClass('upload-image-div');
  66. $(element).html(' <a class="upload-image-a" > + 添加图片</a>');
  67. click_element = element+ ' .upload-image-a';
  68. }
  69. $(document).on("click", click_element, function () {
  70. var click_element = $(this);
  71. if(css === true){
  72. click_element = click_element.parent();
  73. }
  74. var windows = layer.open({type: 2, title: title, content: image_upload_url, area: area});
  75. window.callback = function (uri) {
  76. upload_call_back(uri, click_element);
  77. return uri
  78. };
  79. window.callbackSetUri = function (uri) {
  80. upload_call_back(uri, click_element);
  81. layer.close(windows);
  82. return uri
  83. }
  84. })
  85. }, showImg: function (url, xp) {
  86. function getImageWidth(url, callback) {
  87. var img = new Image();
  88. img.src = url;
  89. if (img.complete) {
  90. callback(img.width, img.height)
  91. } else {
  92. img.onload = function () {
  93. callback(img.width, img.height)
  94. }
  95. }
  96. }
  97. xp === undefined ? 500 : xp;
  98. getImageWidth(url, function (width, height) {
  99. if (height > xp) {
  100. var ratio = width / height;
  101. height = xp;
  102. width = height * ratio
  103. }
  104. if (width > xp) {
  105. var ratio = height / width;
  106. width = xp;
  107. height = width * ratio
  108. }
  109. layer.closeAll();
  110. layer.open({
  111. type: 1,
  112. closeBtn: 1,
  113. shade: false,
  114. title: false,
  115. shadeClose: false,
  116. area: ["auth", "auth"],
  117. content: '<img src="' + url + '" width="' + width + 'px" height="' + height + 'px">'
  118. })
  119. })
  120. },
  121. // 从URL中取出文件名(除去http网址, 根据存储对象)
  122. getUrlFileName: function(url, domain) {
  123. return url.replace(domain, '');
  124. // var data = url.split('/');
  125. // return data[data.length - 3] + '/' + data[data.length - 2] + '/' + data[data.length - 1];
  126. },
  127. videoUpload: function (element,url) {
  128. $(element).addClass('upload-video-div');
  129. $(element).html(' <a class="upload-video-a" > + 添加视频</a>');
  130. upload.render({ //允许上传的文件后缀
  131. elem: element
  132. ,url: url //改成您自己的上传接口
  133. ,accept: 'file' //普通文件
  134. ,exts: 'mp3|mp4|AVI|mov|rmvb|rm|FLV|3GP|wav'
  135. ,done: function(res){
  136. if (res.code === 1){
  137. var video = '<div class="show-video">' +
  138. ' <video width="160" height="160" src="'+res.data.domain+res.data.uri+'"controls autoplay></video>'
  139. +'<a class="goods-video-del-x goods-video-del">x</a>'
  140. + '<input type="hidden" name="video" value="/'+res.data.uri+'">'
  141. '</div>';
  142. $(element).after(video);
  143. $(element).hide();
  144. layer.msg('上传成功');
  145. } else {
  146. layer.msg(res.msg);
  147. }
  148. }
  149. });
  150. }
  151. ,certUpload:function (element, url, domain) {
  152. console.log('aaa')
  153. upload.render({
  154. elem: element
  155. ,url: url
  156. ,accept:'file'
  157. ,exts:'pem|txt|doc'
  158. ,done: function(res, index, upload) {
  159. var html = '<div class="pay-li">\n' +
  160. '<img class="pay-img" ' +
  161. 'src="/static/common/image/default/upload.png">' +
  162. '<a class="pay-img-del-x" style="display: none">x</a>' +
  163. '</div>';
  164. $(element).prev().val(res.data.uri.replace(domain, ''));
  165. $(element).after(html);
  166. $(element).css('display','none');
  167. }
  168. });
  169. }
  170. };
  171. exports("like", ojb)
  172. });