pwhse.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. //【公共操作对象】
  2. var ActionObject= {
  3. /* AjaxSend-----Ajax发送*/
  4. "AjaxSend" :function(url,data,type='get'){
  5. var result;
  6. $.ajax({cache:true,type:type,url:url,data:data,async:false,dataType:"json",
  7. error : function(request) {alert("操作失败");},
  8. success : function(data) {result = data;}
  9. });
  10. return result;
  11. },
  12. /*常规事件------选项卡*/
  13. "Cevent" :function(e){
  14. $('[AT='+e.AT+']').on('click',function(){
  15. var obj = $('[Aobject='+e.AT+']['+e.CORID+'='+$(this).attr(e.CORID)+']');
  16. obj.siblings().hide();
  17. obj.show();
  18. $(this).addClass(e.CLASS).siblings().removeClass(e.CLASS);
  19. });
  20. $('[AT='+e.AT+']').eq(0).trigger('click');
  21. },
  22. /*列表删除事件*/
  23. "Delete":function(e){
  24. var self = this;
  25. $('[AT='+e.AT+']').on('click',function(){
  26. if(e.CORID) var ID = $(this).attr(e.CORID);
  27. layer.confirm('确认要删除吗?',function(index){
  28. if(ID != undefined){
  29. var result = self.AjaxSend(e.URL,{id:ID});
  30. if(result.code == 1) $('[AT='+e.AT+']['+e.CORID+'='+ID+']').parents(e.DLABEL).remove();
  31. }else{
  32. var Actiondata = $('input[Aobject='+e.AT+']');
  33. var data = '';
  34. for(var i=0;i<Actiondata.length;i++){
  35. if(Actiondata.eq(i).prop('checked') == true){
  36. data += Actiondata.eq(i).attr('data')+",";
  37. }
  38. }
  39. if(data.length != 0){
  40. data = data.substr(0,data.length - 1);
  41. var result = self.AjaxSend(e.URL,{data:data});
  42. if(result.code == 1){
  43. var arr = data.split(",");
  44. for(key in arr){
  45. $('input[Aobject='+e.AT+'][data='+arr[key]+']').parents(e.DLABEL).remove();
  46. }
  47. }
  48. }else{
  49. var result = {msg:'未选中节点',code:3};
  50. }
  51. }
  52. layer.msg(result.msg,{icon:result.code,time:2000});
  53. });
  54. });
  55. },
  56. // 全选事件
  57. "CheckAll":function(e){
  58. e.box.on('click',function(){
  59. var ID = $(this).attr(e.boxID);
  60. if($(this).prop('checked') == true){
  61. $('input['+e.sonID+'='+ID+']').prop('checked',true);
  62. }else{
  63. $('input['+e.sonID+'='+ID+']').prop('checked',false);
  64. }
  65. });
  66. },
  67. //表单阻止 (单个节点)
  68. "FormCode":function(e){
  69. e.FORM.submit(function(){
  70. var Code = $(this).find('input[name='+e.INPUT+']').val();
  71. if($.trim(Code).length == 0){
  72. layer.msg('输入不能为空',{icon:2,time:2000});
  73. return false;
  74. }
  75. });
  76. },
  77. // 设置状态
  78. "Upsate":function(e){
  79. var self = this;
  80. $('[AT='+e.AT+']').on('click',function(){
  81. var ID = $(this).attr(e.CORID);
  82. var state = $(this).find('.move');
  83. var result = self.AjaxSend(e.URL,{id:ID,state:state.attr('data-state')});
  84. if(result.state == "on"){
  85. state.animate({
  86. left: "21"
  87. }, 300, function() {
  88. state.attr("data-state",result.state);
  89. });
  90. state.parent().removeClass("off").addClass(result.state);
  91. }else if(result.state == "off"){
  92. state.animate({
  93. left: "0"
  94. }, 300, function() {
  95. state.attr("data-state",result.state);
  96. });
  97. state.parent().removeClass("on").addClass(result.state);
  98. }
  99. });
  100. },
  101. //本地单图预览
  102. "Preview_one_Local":function(e){
  103. var path;
  104. var data = e.imgFile;
  105. if(data.files[0]){
  106. e.preview.css('display','block');
  107. }else{
  108. e.preview.css('display','none');
  109. }
  110. path = window.URL.createObjectURL(data.files[0]);
  111. e.preview.attr('src',path);
  112. e.preview.parent().prev('input[path=filepath]').val(path);
  113. $('.close').show();
  114. },
  115. //本地多图预览
  116. "Preview_more_Local":function(e){
  117. var path;
  118. var data = e.imgFile;
  119. $('.atlas_start_up').hide();
  120. $('.atlas_more_action').show();
  121. e.preview.parent().show();
  122. for(var i=0;i<data.files.length;i++){
  123. path=window.URL.createObjectURL(data.files[i]);
  124. e.preview.append("<li id='imgdel"+e.preview.children().length+"'><span class='moreclose' data='atlas' onclick='PreviewImageDel("+e.preview.children().length+")'></span><img src='"+path+"'/><input type='text' name='alt[]' placeholder='图片标题'></li>");
  125. }
  126. },
  127. //单图片远程预览
  128. "PreviewRemote":function(e){
  129. e.imgFile.on('keyup',function(){
  130. e.preview.attr('src',this.value);
  131. $('.close').show();
  132. });
  133. },
  134. // 删除图集节点
  135. "Delatlasnode":function(id,key,action){
  136. var self = this;
  137. layer.confirm('确认要删除吗?',function(index){
  138. var reuslt = self.AjaxSend(action,{id:id,key:key});
  139. PreviewImageDel(key);
  140. layer.msg(reuslt,{icon:2,time:2000});
  141. });
  142. },
  143. // 修改 alt图集--------------------------------------------------------------------
  144. "Amendlasnode":function(e){
  145. var _index,txt,content,box,
  146. _Class = $(e.AT),
  147. _this = this;
  148. var TxtNumber;
  149. _Class.on('focus','input[type="text"]', function(){
  150. _index =$(this).parent().index()+1;
  151. txt = $(this).val();
  152. _this.FoundDiv({COUNT:_index,DATA:txt});
  153. TxtNumber=getStrLength(txt)
  154. $('#shot_text_box').find('i').html(TxtNumber);
  155. });
  156. },
  157. // 创建一个div盒子,插body中
  158. "FoundDiv":function(e){
  159. var ShotBox,
  160. _div ='',
  161. _self=this,
  162. Chooser = $('.atlas_preview ul li');
  163. _div +='<div id="shot_text_box"><span class="moreclose"></span>';
  164. _div +='<p class="txt_title" id="txt_title">第<span>'+e.COUNT+'</span>张缩略图</p>';
  165. _div +='<div class="textbox"><textarea rows="5" cols="20" autofocus="autofocus">'+e.DATA+'</textarea>';
  166. _div +='<span><i>0</i>/<em>30</em></span></div>'
  167. _div +='<p class="btn_box mt-5"><a class="btn" href="javascript:;">确定</a></p></div>'
  168. // 判断不存在才插入
  169. ShotBox = $('#shot_text_box').text();
  170. if(!ShotBox){
  171. $('body').append(_div);
  172. }else{
  173. $('#txt_title span').html(e.COUNT);
  174. $('.textbox textarea').val(e.DATA);
  175. }
  176. //获取当前坐标
  177. var CoordinateX = Chooser.eq(e.COUNT-1).find('input[type="text"]').offset().left;
  178. var CoordinateY = Chooser.eq(e.COUNT-1).find('input[type="text"]').offset().top;
  179. $('#shot_text_box').css({'top':CoordinateY,'left':CoordinateX});
  180. $('#shot_text_box .moreclose').on('click',function(){
  181. $(this).parent().remove();
  182. })
  183. $('#shot_text_box a.btn').on('click',function(){
  184. var i = $(this).parent().siblings('#txt_title').children().html()-1,
  185. NewContent = $(this).parent().siblings('.textbox').children().val();
  186. Chooser.eq(i).find('input[type="text"]').val(NewContent);
  187. var InitialData =e.DATA;
  188. var oURL=Chooser.eq(i).find('input[type="text"]').attr('url');
  189. var Aid=Chooser.eq(i).find('input[type="text"]').attr('aid');
  190. var Key=Chooser.eq(i).find('input[type="text"]').attr('key');
  191. if(oURL != undefined){
  192. if(NewContent != InitialData){
  193. var result = _self.AjaxSend(oURL,{id:Aid,key:Key,alt:NewContent});
  194. if(result == true){
  195. Chooser.eq(i).find('input[aid="'+Aid+'"][key="'+Key+'"]').val(NewContent);
  196. }else{
  197. layer.msg('修改失败!',{time:2000});
  198. }
  199. }
  200. }
  201. $(this).parents('#shot_text_box').remove();
  202. })
  203. // 添加两个输入框同时响应
  204. $('.textbox').on('keyup','textarea',function(){
  205. var txt = $(this).val();
  206. var i = $(this).parent().siblings('#txt_title').children().html()-1;
  207. var TxtNumber= getStrLength(txt);
  208. if(TxtNumber>30){
  209. txt = txt.substr(0,30);
  210. $(this).val(txt);
  211. }else{
  212. $(this).siblings('span').find('i').html(TxtNumber);
  213. }
  214. })
  215. },
  216. //多选框限制选中数量
  217. "Checkbox":function(id,Num,Num2){
  218. var wuye=$(id).find(":checkbox");
  219. if(wuye.size()>=Num){
  220. wuye.removeAttr("checked");
  221. wuye.attr("disabled","disabled");
  222. wuye.removeAttr("disabled");
  223. }
  224. var num = 0;
  225. wuye.each(function(){
  226. $(this).click(function(){
  227. if($(this)[0].checked) {
  228. ++num;
  229. if(num == Num) {
  230. //alert("最多选择 的上限已满, 其他选项将会变为不可选.");
  231. wuye.each(function(){
  232. if(!$(this)[0].checked) {
  233. $(this).attr("disabled", "disabled");
  234. }
  235. });
  236. }
  237. } else {
  238. --num;
  239. if(num <= Num2) {
  240. wuye.each(function(){
  241. if(!$(this)[0].checked) {
  242. $(this).removeAttr("disabled");
  243. }
  244. });
  245. }
  246. }
  247. });
  248. });
  249. }
  250. };
  251. // ActionObject END
  252. /*------------------------------------------------------------------------------------------------------------------------*/
  253. // 中文字符半角、全角判断
  254. function getStrLength(str) {
  255. var len = str.length;
  256. var reLen = 0;
  257. for (var i = 0; i < len; i++) {
  258. if (str.charCodeAt(i) < 27 || str.charCodeAt(i) > 126) {
  259. reLen += 1;
  260. } else {
  261. reLen++;
  262. }
  263. }
  264. return reLen;
  265. }
  266. //删除预览图
  267. function PreviewImageDel(e){
  268. if(typeof(e) == 'object'){
  269. $("."+e.className).parent().children('img').attr('src',"");
  270. $('input[name='+$("."+e.className).attr('data')+']').val("");
  271. $("."+e.className).parent().append("<input type='hidden' name='del[]' value=0 />");
  272. $(".close").hide();
  273. $(".mt-15 .input-text").attr("value","");
  274. }else if(typeof(e) == 'number'){
  275. var obj = $('#imgdel'+e);
  276. obj.parent().append("<input type='hidden' name='moredel[]' value="+e+" />");
  277. if(obj.siblings('li').length == 0){
  278. obj.parent().parent().hide()
  279. $('.atlas_start_up').show();
  280. $('.atlas_more_action').hide();
  281. }
  282. obj.remove();
  283. }
  284. }
  285. // 时间范围验证不为空。
  286. $('.Wdate').parent('form').submit(function(){
  287. var ctime = $(this).find('input[name=ctime]');
  288. var etime = $(this).find('input[name=etime]');
  289. if(ctime.val() && !etime.val()){
  290. layer.msg('请输入'+etime.attr('placeholder')+'时间',{icon:2,time:2000});
  291. return false;
  292. }
  293. if(etime.val() && !ctime.val()){
  294. layer.msg('请输入'+ctime.attr('placeholder')+'时间',{icon:2,time:2000});
  295. return false;
  296. }
  297. })