No Description
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.

global.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. //工具栏上的所有的功能按钮和下拉框,可以在new编辑器的实例时选择自己需要的重新定义
  2. var ueditor_toolbars = [[
  3. 'fullscreen', 'source', '|', 'undo', 'redo', '|',
  4. 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', '|',
  5. 'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
  6. 'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
  7. 'directionalityltr', 'directionalityrtl', 'indent', '|',
  8. 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
  9. 'link', 'unlink', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
  10. 'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'insertframe', 'insertcode', 'pagebreak', 'background', '|',
  11. 'horizontal', 'spechars', '|',
  12. 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
  13. 'preview', 'searchreplace', 'drafts'
  14. ]];
  15. var layer_tips; // 全局提示框的对象
  16. $(function(){
  17. auto_notic_tips();
  18. /**
  19. * 自动小提示
  20. */
  21. function auto_notic_tips()
  22. {
  23. var html = '<a class="ui_tips" href="javascript:void(0);" onmouseover="layer_tips = layer.tips($(this).parent().find(\'p.notic\').html(), this, {time:100000});" onmouseout="layer.close(layer_tips);">提示</a>';
  24. $.each($('dd.opt > p.notic'), function(index, item){
  25. if ($(item).html() != '') {
  26. $(item).before(html);
  27. }
  28. });
  29. }
  30. });
  31. /**
  32. * 批量删除提交
  33. */
  34. function batch_del(obj, name) {
  35. var a = [];
  36. $('input[name^='+name+']').each(function(i,o){
  37. if($(o).is(':checked')){
  38. a.push($(o).val());
  39. }
  40. })
  41. if(a.length == 0){
  42. layer.alert('请至少选择一项', {icon: 2});
  43. return;
  44. }
  45. // 删除按钮
  46. layer.confirm('此操作不可逆,确认批量删除?', {
  47. btn: ['确定', '取消'] //按钮
  48. }, function () {
  49. layer_loading('正在处理');
  50. $.ajax({
  51. type: "POST",
  52. url: $(obj).attr('data-url'),
  53. data: {del_id:a},
  54. dataType: 'json',
  55. success: function (data) {
  56. layer.closeAll();
  57. if(parseInt(data.code) == 1){
  58. layer.msg(data.msg, {icon: 1});
  59. window.location.reload();
  60. }else{
  61. layer.alert(data.msg, {icon: 2});
  62. }
  63. },
  64. error:function(){
  65. layer.closeAll();
  66. layer.alert('网络失败,请刷新页面后重试', {icon: 2});
  67. }
  68. });
  69. }, function (index) {
  70. layer.closeAll(index);
  71. });
  72. }
  73. /**
  74. * 单个删除
  75. */
  76. function delfun(obj) {
  77. layer.confirm('此操作不可逆,确认删除?', {
  78. btn: ['确定','取消'] //按钮
  79. }, function(){
  80. // 确定
  81. layer_loading('正在处理');
  82. $.ajax({
  83. type : 'post',
  84. url : $(obj).attr('data-url'),
  85. data : {del_id:$(obj).attr('data-id')},
  86. dataType : 'json',
  87. success : function(data){
  88. layer.closeAll();
  89. if(parseInt(data.code) == 1){
  90. layer.msg(data.msg, {icon: 1});
  91. window.location.reload();
  92. }else{
  93. layer.alert(data.msg, {icon: 2});
  94. }
  95. }
  96. })
  97. }, function(index){
  98. layer.close(index);
  99. return false;// 取消
  100. }
  101. );
  102. }
  103. /**
  104. * 全选
  105. */
  106. function selectAll(name,obj){
  107. $('input[name*='+name+']').prop('checked', $(obj).checked);
  108. }
  109. /**
  110. * 远程/本地上传图片切换
  111. */
  112. function clickRemote(obj, id)
  113. {
  114. if ($(obj).is(':checked')) {
  115. $('#'+id+'_remote').show();
  116. $('.div_'+id+'_local').hide();
  117. } else {
  118. $('.div_'+id+'_local').show();
  119. $('#'+id+'_remote').hide();
  120. }
  121. }
  122. /**
  123. * 批量移动操作
  124. */
  125. function batch_move(obj, name) {
  126. var a = [];
  127. $('input[name^='+name+']').each(function(i,o){
  128. if($(o).is(':checked')){
  129. a.push($(o).val());
  130. }
  131. })
  132. if(a.length == 0){
  133. layer.alert('请至少选择一项', {icon: 2});
  134. return;
  135. }
  136. // 删除按钮
  137. layer.confirm('确认批量移动?', {
  138. btn: ['确定', '取消'] //按钮
  139. }, function () {
  140. layer_loading('正在处理');
  141. $.ajax({
  142. type: "POST",
  143. url: $(obj).attr('data-url'),
  144. data: {move_id:a},
  145. dataType: 'json',
  146. success: function (data) {
  147. layer.closeAll();
  148. if(data.status == 1){
  149. layer.msg(data.msg, {icon: 1});
  150. window.location.reload();
  151. }else{
  152. layer.alert(data.msg, {icon: 2});
  153. }
  154. },
  155. error:function(){
  156. layer.closeAll();
  157. layer.alert('网络失败,请刷新页面后重试', {icon: 2});
  158. }
  159. });
  160. }, function (index) {
  161. layer.closeAll(index);
  162. });
  163. }
  164. // 修改指定表的指定字段值 包括有按钮点击切换是否 或者 排序 或者输入框文字
  165. function changeTableVal(table,id_name,id_value,field,obj)
  166. {
  167. var src = "";
  168. if($(obj).hasClass('no')) // 图片点击是否操作
  169. {
  170. //src = '/public/images/yes.png';
  171. $(obj).removeClass('no').addClass('yes');
  172. $(obj).html("<i class='fa fa-check-circle'></i>是");
  173. var value = 1;
  174. try {
  175. if ($(obj).attr('data-value')) {
  176. value = $(obj).attr('data-value');
  177. }
  178. } catch(e) {
  179. // 出现异常以后执行的代码
  180. // e:exception,用来捕获异常的信息
  181. }
  182. }else if($(obj).hasClass('yes')){ // 图片点击是否操作
  183. $(obj).removeClass('yes').addClass('no');
  184. $(obj).html("<i class='fa fa-ban'></i>否");
  185. var value = 0;
  186. try {
  187. if ($(obj).attr('data-value')) {
  188. value = $(obj).attr('data-value');
  189. }
  190. } catch(e) {
  191. // 出现异常以后执行的代码
  192. // e:exception,用来捕获异常的信息
  193. }
  194. }else{ // 其他输入框操作
  195. var value = $(obj).val();
  196. }
  197. $.ajax({
  198. type:'POST',
  199. url: eyou_basefile + "?m="+module_name+"&c=Index&a=changeTableVal&table="+table+"&id_name="+id_name+"&id_value="+id_value+"&field="+field+'&value='+value,
  200. success: function(data){
  201. if(!$(obj).hasClass('no') && !$(obj).hasClass('yes')){
  202. layer.msg('更新成功', {icon: 1});
  203. } else {
  204. if (0 == data.code) {
  205. layer.msg(data.msg, {icon: 2});
  206. }
  207. }
  208. }
  209. });
  210. }
  211. /**
  212. * 输入为空检查
  213. * @param name '#id' '.id' (name模式直接写名称)
  214. * @param type 类型 0 默认是id或者class方式 1 name='X'模式
  215. */
  216. function is_empty(name,type){
  217. if(type == 1){
  218. if($('input[name="'+name+'"]').val() == ''){
  219. return true;
  220. }
  221. }else{
  222. if($(name).val() == ''){
  223. return true;
  224. }
  225. }
  226. return false;
  227. }
  228. /**
  229. * 邮箱格式判断
  230. * @param str
  231. */
  232. function checkEmail(str){
  233. var reg = /^[a-z0-9]([a-z0-9\\.]*[-_]{0,4}?[a-z0-9-_\\.]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+([\.][\w_-]+){1,5}$/i;
  234. if(reg.test(str)){
  235. return true;
  236. }else{
  237. return false;
  238. }
  239. }
  240. /**
  241. * 手机号码格式判断
  242. * @param tel
  243. * @returns {boolean}
  244. */
  245. function checkMobile(tel) {
  246. var reg = /(^1{10}$)/;
  247. if (reg.test(tel)) {
  248. return true;
  249. }else{
  250. return false;
  251. };
  252. }
  253. /*
  254. * 上传图片 后台专用
  255. * @access public
  256. * @null int 一次上传图片张图
  257. * @elementid string 上传成功后返回路径插入指定ID元素内
  258. * @path string 指定上传保存文件夹,默认存在public/upload/temp/目录
  259. * @callback string 回调函数(单张图片返回保存路径字符串,多张则为路径数组 )
  260. */
  261. var layer_GetUploadify;
  262. function GetUploadify(num,elementid,path,callback,url)
  263. {
  264. if (layer_GetUploadify){
  265. layer.close(layer_GetUploadify);
  266. }
  267. if (num > 0) {
  268. if (!url) {
  269. url = GetUploadify_url;
  270. }
  271. if (url.indexOf('?') > -1) {
  272. url += '&';
  273. } else {
  274. url += '?';
  275. }
  276. var upurl = url+'num='+num+'&input='+elementid+'&path='+path+'&func='+callback;
  277. layer_GetUploadify = layer.open({
  278. type: 2,
  279. title: '上传图片',
  280. shadeClose: false,
  281. shade: 0.3,
  282. maxmin: true, //开启最大化最小化按钮
  283. area: ['50%', '60%'],
  284. content: upurl
  285. });
  286. } else {
  287. layer.alert('允许上传0张图片', {icon:2});
  288. return false;
  289. }
  290. }
  291. // 读取 cookie
  292. function getCookie(c_name)
  293. {
  294. if (document.cookie.length>0)
  295. {
  296. c_start = document.cookie.indexOf(c_name + "=")
  297. if (c_start!=-1)
  298. {
  299. c_start=c_start + c_name.length+1
  300. c_end=document.cookie.indexOf(";",c_start)
  301. if (c_end==-1) c_end=document.cookie.length
  302. return unescape(document.cookie.substring(c_start,c_end))
  303. }
  304. }
  305. return "";
  306. }
  307. function setCookie(name, value, time)
  308. {
  309. var cookieString = name + "=" + escape(value) + ";";
  310. if (time != 0) {
  311. var Times = new Date();
  312. Times.setTime(Times.getTime() + time);
  313. cookieString += "expires="+Times.toGMTString()+";"
  314. }
  315. document.cookie = cookieString+"path=/";
  316. }
  317. function delCookie(name){
  318. var exp=new Date();
  319. exp.setTime(exp.getTime()-1);
  320. var cval=getCookie(name);
  321. if(cval!=null){
  322. document.cookie=name+"="+cval+";expires="+exp.toGMTString() +"path=/";
  323. }
  324. }
  325. function showErrorMsg(msg){
  326. // layer.open({content:msg,time:2000});
  327. layer.msg(msg, {icon: 2,time: 2000});
  328. }
  329. /**
  330. * 封装的加载层
  331. */
  332. function layer_loading(msg){
  333. var loading = layer.msg(
  334. msg+'...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请勿刷新页面',
  335. {
  336. icon: 1,
  337. time: 3600000, //1小时后后自动关闭
  338. shade: [0.2] //0.1透明度的白色背景
  339. });
  340. //loading层
  341. var index = layer.load(3, {
  342. shade: [0.1,'#fff'] //0.1透明度的白色背景
  343. });
  344. return loading;
  345. }
  346. function tipsText(){
  347. $('.ui-text').each(function(){
  348. var _this = $(this);
  349. var elm = _this.find('.ui-input');
  350. var txtElm = _this.find('.ui-textTips');
  351. var maxNum = _this.find('.ui-input').attr('data-num') || 500;
  352. // console.log($.support.leadingWhitespace);
  353. changeNum(elm,txtElm,maxNum);
  354. if(!$.support.leadingWhitespace){
  355. _this.find('textarea').on('propertychange',function(){
  356. changeNum(elm,txtElm,maxNum);
  357. });
  358. _this.find('input').on('propertychange',function(){
  359. changeNum(elm,txtElm,maxNum);
  360. });
  361. } else {
  362. _this.on('input',function(){
  363. changeNum(elm,txtElm,maxNum);
  364. });
  365. }
  366. });
  367. }
  368. //获取文字输出字数,可以遍历使用
  369. //txtElm动态改变的dom,maxNum获取data-num值默认为120个字,ps数字为最大字数*2
  370. function changeNum(elm,txtElm,maxNum) {
  371. //汉字的个数
  372. //var str = (elm.val().replace(/\w/g, "")).length;
  373. //非汉字的个数
  374. //var abcnum = elm.val().length - str;
  375. total = elm.val().length;
  376. if(total <= maxNum ){
  377. texts = maxNum - total;
  378. txtElm.html('还可以输入<em>'+texts+'</em>个字');
  379. }else{
  380. texts = total - maxNum ;
  381. txtElm.html('已超出<em class="error">'+texts+'</em>个字');
  382. }
  383. return ;
  384. }