home_set.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. if ($('.content').height() > 750) {
  2. $('#iframe-main', parent.document).css('height', $('.content').height() + 20)
  3. } else {
  4. $('#iframe-main', parent.document).css('height', '750px')
  5. }
  6. function submit_info() {
  7. var header = $("#header").val();
  8. var footer = $("#footer").val();
  9. var group = $("#group").val();
  10. // if (footer == '') {
  11. // layer.alert("footer不能为空!");
  12. // return false;
  13. // }
  14. console.log(footer)
  15. console.log(group)
  16. $.ajax({
  17. type: "post",
  18. url: "home_set",
  19. data: {
  20. 'req':'footer',
  21. header: header,
  22. footer: footer,
  23. group:group
  24. },
  25. dataType: "json",
  26. success: function (data) {
  27. if (data == 0) {
  28. layer.msg("修改成功!");
  29. window.location.href = '/systemmanage_role'
  30. } else if (data == 1) {
  31. layer.msg("修改失败!");
  32. }
  33. }
  34. });
  35. return false;
  36. }
  37. // file 文件
  38. // divId div id
  39. // imgId 图片id
  40. // fileId 文件id
  41. // width 图片宽
  42. // height 图片高
  43. function previewImage(file, divId, imgId, fileId, width, height) {
  44. var div = document.getElementById(divId);
  45. if (file.files && file.files[0]) {
  46. if (file.files[0].size / 1024 / 1024 < 4) {
  47. div.innerHTML = '<img id=' + imgId + ' onclick=$("#' + fileId + '").click()>';
  48. var img = document.getElementById(imgId);
  49. img.onload = function () {
  50. // var rect = clacImgZoomParam(width, height, img.offsetWidth, img.offsetHeight);
  51. img.width = width;
  52. img.height = height;
  53. // img.style.marginTop = rect.top+'px';
  54. }
  55. var reader = new FileReader();
  56. reader.onload = function (evt) {
  57. img.src = evt.target.result;
  58. // $(window.parent.document).find('.nav-user-photo').attr('src',evt.target.result);
  59. }
  60. reader.readAsDataURL(file.files[0]);
  61. // $('#userPhoto').submit();
  62. send_logo();
  63. } else {
  64. $(file).val('');
  65. layer.alert("图片过大!");
  66. }
  67. } else {//兼容IE
  68. var sFilter = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
  69. file.select();
  70. if (document.selection != undefined) {
  71. var src = document.selection.createRange().text;
  72. div.innerHTML = '<img id=' + imgId + '>';
  73. var img = document.getElementById(imgId);
  74. img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
  75. var rect = clacImgZoomParam(width, height, img.offsetWidth, img.offsetHeight);
  76. status = ('rect:' + rect.top + ',' + rect.left + ',' + rect.width + ',' + rect.height);
  77. div.innerHTML = "<div id=divhead style='width:" + rect.width + "px;height:" + rect.height + "px;" + sFilter + src + "\"'></div>";
  78. }
  79. }
  80. }
  81. function clacImgZoomParam(maxWidth, maxHeight, width, height) {
  82. var param = { top: 0, left: 0, width: width, height: height };
  83. if (width > maxWidth || height > maxHeight) {
  84. var rateWidth = width / maxWidth;
  85. var rateHeight = height / maxHeight;
  86. if (rateWidth > rateHeight) {
  87. param.width = maxWidth;
  88. param.height = Math.round(height / rateWidth);
  89. } else {
  90. param.width = Math.round(width / rateHeight);
  91. param.height = maxHeight;
  92. }
  93. }
  94. param.left = Math.round((maxWidth - param.width) / 2);
  95. param.top = Math.round((maxHeight - param.height) / 2);
  96. return param;
  97. }
  98. // 上传图片
  99. function send_logo() {
  100. var formData = new FormData($("#userPhoto")[0]);
  101. $.ajax({
  102. type: 'post',
  103. url: 'home_set',
  104. data: formData,
  105. contentType: false,
  106. processData: false,
  107. success: function (data) {
  108. if (data == 0) {
  109. $(window.parent.document).find('.fa fa-leaf').attr('src', $('#viewPhoto').prop('src'));
  110. }
  111. else { layer.msg("上传失败!"); }
  112. }
  113. });
  114. }