admin.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**
  2. * admin 后台js
  3. *
  4. */
  5. //字符串为空
  6. function isNull(str) {
  7. if (str == null || str == "" || str.length < 1)
  8. return true;
  9. else
  10. return false;
  11. }
  12. //获取 str 字符长度,中文单字2字符,英文1字符F
  13. function getblen(str) {
  14. var l = str.length;
  15. var blen = 0;
  16. for (i = 0; i < l; i++) {
  17. if ((str.charCodeAt(i) & 0xff00) != 0) {
  18. blen++;
  19. }
  20. blen++;
  21. }
  22. return blen;
  23. }
  24. //textarea 字数提示
  25. function textarealength(obj, toplength) {
  26. var note = $(obj).val();
  27. var blen = getblen(note);
  28. if (blen <= toplength) {
  29. $(".textarea-length").html(blen);
  30. } else {
  31. $(".textarea-length").css('color', 'red');
  32. $(".textarea-length").html(blen);
  33. }
  34. }
  35. // js 正则验证邮箱
  36. function testEmail(strEmail) {
  37. var myReg = /^[-a-z0-9\._]+@([-a-z0-9\-]+\.)+[a-z0-9]{2,3}$/i;
  38. if (myReg.test(strEmail)) return true;
  39. return false;
  40. }
  41. //检测邮箱格式
  42. function emailFormat(email) {
  43. return email.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/) ? true : false;
  44. }
  45. //检测手机格式
  46. function phoneFormat(phone) {
  47. return phone.match(/^1(3|4|5|6|7|8)\d{9}$/) ? true : false;
  48. }
  49. //检测密码规则--6位以上
  50. function pwdFormat(pwd) {
  51. return pwd.match(/^.*(?=.{6,})/) ? true : false;
  52. }
  53. //检测密码规则--6位以上数字字母组合
  54. function pwdFormat6Mix(pwd) {
  55. return pwd.match(/^.*(?=.{5,})(?=.*\d)(?=.*[a-z]).*$/) ? true : false;
  56. }
  57. //必须字母开头,长度在6-18之间,只能包含字符(或下划线)、数字
  58. function pwdFormat6MixNew(pwd) {
  59. return pwd.match(/^[a-zA-Z]\w{5,17}$/) ? true : false;
  60. }
  61. // 改变状态
  62. function status(obj, id) {
  63. $.post('status', {
  64. 'id': parseInt(id)
  65. }, function (res) {
  66. if (res.code == 0) {
  67. topalert({
  68. type: 0,
  69. content: res.msg,
  70. speed: 1000
  71. });
  72. if (res.status == 1) {
  73. var img_str = '<a href="javascript:;" onclick="status(this,' + id + ')" title="正常"><span class="f-20 c-primary"><i class="Hui-iconfont">&#xe601;</i></span></a>';
  74. } else {
  75. var img_str = '<a href="javascript:;" onclick="status(this,' + id + ')" title="停用"><span class="f-20 c-primary"><i class="Hui-iconfont">&#xe677;</i></span></a>';
  76. }
  77. $(obj).parents('td.td-status').append(img_str);
  78. $(obj).remove();
  79. } else {
  80. topalert({
  81. type: 1,
  82. content: res.msg,
  83. speed: 1000
  84. });
  85. return false;
  86. }
  87. }, 'json');
  88. }
  89. // 排序
  90. $(".input-sort").change(function () {
  91. var sort = $(this).val();
  92. var id = $(this).data('id');
  93. $.post('sort', {
  94. 'id': id,
  95. 'sort': sort
  96. }, function (data) {
  97. if (data.code == 0) {
  98. topalert({
  99. type: 0,
  100. content: data.msg,
  101. speed: 2000
  102. });
  103. } else {
  104. topalert({
  105. type: 1,
  106. content: data.msg,
  107. speed: 2000
  108. });
  109. return false;
  110. }
  111. }, 'json');
  112. });
  113. // 删除条目
  114. function del(obj, id) {
  115. layer.confirm('确认要删除吗?', function (index) {
  116. $.post('delete', {
  117. 'id': id
  118. }, function (res) {
  119. if (res.code == 0) {
  120. $(obj).parents("tr").remove();
  121. topalert({
  122. type: 0,
  123. content: res.msg,
  124. speed: 1000
  125. });
  126. } else {
  127. topalert({
  128. type: 2,
  129. content: res.msg,
  130. speed: 2000
  131. });
  132. }
  133. layer.close(layer.index);
  134. }, 'json');
  135. });
  136. }
  137. //列表多选删除条目
  138. function del_all() {
  139. var checkbox = $('.text-c input[name="checkbox[]"]');
  140. var ids = new Array();
  141. checkbox.each(function (x) {
  142. if (this.checked)
  143. ids.push(this.value);
  144. })
  145. var length = ids.length;
  146. if (length == 0) {
  147. layer.msg('请选择要删除的选项', {
  148. icon: 5,
  149. time: 1000
  150. });
  151. return false;
  152. }
  153. layer.confirm('确认要删除选中项吗?', function (index) {
  154. $.post('delete', {
  155. 'id': ids
  156. }, function (data) {
  157. if (data.code == 0) {
  158. layer.msg(data.msg, {
  159. icon: 1,
  160. time: 2000
  161. });
  162. window.location.reload();
  163. } else {
  164. layer.msg(data.msg, {
  165. icon: 5,
  166. time: 2000
  167. });
  168. return false;
  169. }
  170. }, 'json');
  171. });
  172. }
  173. // 右上角提示框
  174. function topalert(options, callback) {
  175. var defaults = {
  176. type: 0,
  177. content: '弹窗内容',
  178. speed: "0",
  179. };
  180. var types = ['success', 'danger', 'error', 'info'];
  181. var options = $.extend(defaults, options);
  182. var length = $('.topalert').length;
  183. var htmlstr = '<div class="Huialert Huialert-' + types[defaults.type] + ' topalert topalert' + length + '"><i class="Hui-iconfont">&#xe6a6;</i>' + options.content + '</div>';
  184. if (options.speed == 0) {
  185. $(document.body).addClass("modal-open").append(htmlstr);
  186. $(".topalert" + length).fadeIn();
  187. } else {
  188. $(document.body).addClass("modal-open").append(htmlstr);
  189. $(".topalert" + length).fadeIn();
  190. setTimeout(function () {
  191. $(".topalert" + length).fadeOut("normal", complete => {
  192. $(".topalert" + length).remove();
  193. });
  194. }, options.speed);
  195. }
  196. if (callback) {
  197. callback();
  198. }
  199. }
  200. $(function () {
  201. // 图片预览
  202. $('.pictureview').hover(function () {
  203. console.log($(this).children('img').attr('src'));
  204. var url = $(this).children('img').attr('src');
  205. var img = '<img class="thumbnail" id="thumbview" src="' + url + '">';
  206. $(this).append(img);
  207. }, function () {
  208. $('#thumbview').remove();
  209. });
  210. });