avatar.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>{$site_info.site_name}</title>
  5. <meta name="keywords" content=""/>
  6. <meta name="description" content="">
  7. <include file="public@head"/>
  8. <style type="text/css">
  9. .tab-content {
  10. overflow: visible;
  11. }
  12. .uploaded_avatar_area {
  13. margin-top: 20px;
  14. }
  15. .uploaded_avatar_btns {
  16. margin-top: 20px;
  17. }
  18. .uploaded_avatar_area .uploaded_avatar_btns {
  19. display: none;
  20. }
  21. </style>
  22. </head>
  23. <body class="body-white" id="top">
  24. <include file="public@nav"/>
  25. <div class="container tc-main">
  26. <div class="row">
  27. <div class="col-md-3">
  28. <include file="public@usernav"/>
  29. </div>
  30. <div class="col-md-9">
  31. <div class="tabs">
  32. <ul class="nav nav-tabs">
  33. <li class="active"><a href="#one" data-toggle="tab"><i class="fa fa-user"></i> 修改头像</a></li>
  34. </ul>
  35. <div class="tab-content">
  36. <div class="tab-pane active" id="one">
  37. <br>
  38. <if condition="empty($avatar)">
  39. <img src="__TMPL__/public/assets/images/headicon_128.png" class="headicon" width="128"/>
  40. <else/>
  41. <img src="{:cmf_get_user_avatar_url($avatar)}?t={:time()}" class="headicon" width="128"/>
  42. </if>
  43. <br><br>
  44. <input type="file" onchange="avatar_upload(this)" id="avatar_uploder" name="file"/>
  45. <div class="uploaded_avatar_area">
  46. <div class="uploaded_avatar_btns">
  47. <a class="btn btn-primary confirm_avatar_btn" onclick="update_avatar()">确定</a>
  48. <a class="btn" onclick="reloadPage()">取消</a>
  49. </div>
  50. </div>
  51. <p class="help-block">头像支持jpg,png,jpeg格式,文件大小最大不能超过1M</p>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. <include file="public@footer"/>
  58. </div>
  59. <!-- /container -->
  60. <include file="public@scripts"/>
  61. <script type="text/javascript">
  62. function update_avatar() {
  63. var area = $(".uploaded_avatar_area img").data("area");
  64. $.post("{:url('Profile/avatarUpdate')}", area, function (data) {
  65. if (data.code == 1) {
  66. reloadPage(window);
  67. }
  68. }, "json");
  69. }
  70. function avatar_upload(obj) {
  71. var $fileinput = $(obj);
  72. /* $(obj)
  73. .show()
  74. .ajaxComplete(function(){
  75. $(this).hide();
  76. }); */
  77. Wind.css("jcrop");
  78. Wind.use("ajaxfileupload", "jcrop", "noty", function () {
  79. $.ajaxFileUpload({
  80. url: "{:url('Profile/avatarUpload')}",
  81. secureuri: false,
  82. fileElementId: "avatar_uploder",
  83. dataType: 'json',
  84. data: {},
  85. success: function (data, status) {
  86. if (data.code == 1) {
  87. $("#avatar_uploder").hide();
  88. var $uploaded_area = $(".uploaded_avatar_area");
  89. $uploaded_area.find("img").remove();
  90. var src = "__ROOT__/upload/" + data.data.file;
  91. var $img = $("<img/>").attr("src", src);
  92. $img.prependTo($uploaded_area);
  93. $(".uploaded_avatar_btns").show();
  94. var img = new Image();
  95. img.src = src;
  96. var callback = function () {
  97. $img.Jcrop({
  98. aspectRatio: 1,
  99. trueSize: [img.width, img.height],
  100. setSelect: [0, 0, 100, 100],
  101. onSelect: function (c) {
  102. $img.data("area", c);
  103. }
  104. });
  105. }
  106. if (img.complete) {
  107. callback();
  108. } else {
  109. img.onload = callback;
  110. }
  111. } else {
  112. noty({
  113. text: data.msg,
  114. type: 'error',
  115. layout: 'center',
  116. callback: {
  117. afterClose: function () {
  118. reloadPage(window);
  119. }
  120. }
  121. });
  122. }
  123. },
  124. error: function (data, status, e) {
  125. }
  126. });
  127. });
  128. return false;
  129. }
  130. </script>
  131. </body>
  132. </html>