Geen omschrijving

Setting-portrait.html 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>我的资料</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  7. <link href="../css/mui.min.css" rel="stylesheet" />
  8. <link href="../css/style.css" rel="stylesheet" />
  9. <style type="text/css">
  10. .head {
  11. height: 40px;
  12. }
  13. #head {
  14. line-height: 40px;
  15. }
  16. .head-img {
  17. width: 40px;
  18. height: 40px;
  19. }
  20. #head-img1 {
  21. position: absolute;
  22. bottom: 10px;
  23. right: 40px;
  24. width: 40px;
  25. height: 40px;
  26. }
  27. .mui-fullscreen {
  28. position: fixed;
  29. z-index: 20;
  30. background-color: #000;
  31. }
  32. .mui-content {
  33. position: absolute;
  34. left: 0;
  35. right: 0;
  36. top: 0;
  37. bottom: 0;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <header class="mui-bar mui-bar-nav" style="padding-right: 15px;color: #fff; background-color: #cd0000 !important;">
  43. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: #FFFFFF;"></a>
  44. <h1 class="mui-center mui-title"><span class="Totle-box">我的头像</span><span class="Totle"></span></h1>
  45. </header>
  46. <div class="mui-content">
  47. <ul class="mui-table-view">
  48. <li class="mui-table-view-cell">
  49. <a id="head" class="mui-navigate-right">个人头像
  50. <span class="mui-pull-right head">
  51. <img class="head-img mui-action-preview" id="head-img1" src=""/>
  52. </span>
  53. </a>
  54. </li>
  55. </ul>
  56. <div class="mui-input-row mui-margin-vertical">
  57. <h5 class="mui-margin-horizontal-xs">个人签名:</h5>
  58. <input class="mui-padding-lg" id="signature" type="text" placeholder="个人签名" />
  59. </div>
  60. </div>
  61. <script src="../js/mui.min.js"></script>
  62. <script src="../js/app.js"></script>
  63. <script type="text/javascript">
  64. (function($) {
  65. mui.init({
  66. swipeBack: true
  67. });
  68. $.plusReady(function() {
  69. //初始化头像,和预览图
  70. setTimeout(function() {
  71. defaultInfo();
  72. setTimeout(function() {
  73. initImgPreview();
  74. }, 200);
  75. }, 0);
  76. //弹出菜单
  77. mui(".mui-table-view-cell").on("tap", "#head", function(e) {
  78. if(mui.os.plus) {
  79. var a = [{
  80. title: "拍照"
  81. }, {
  82. title: "从手机相册选择"
  83. }];
  84. plus.nativeUI.actionSheet({
  85. title: "修改头像",
  86. cancel: "取消",
  87. buttons: a
  88. }, function(b) {
  89. switch(b.index) {
  90. case 0:
  91. break;
  92. case 1:
  93. getImage();
  94. break;
  95. case 2:
  96. galleryImg();
  97. break;
  98. default:
  99. break
  100. }
  101. })
  102. }
  103. });
  104. });
  105. //拍照
  106. function getImage() {
  107. var c = plus.camera.getCamera();
  108. c.captureImage(function(e) {
  109. //存储到本地
  110. plus.io.resolveLocalFileSystemURL(e, function(entry) {
  111. cutImage(entry.toLocalURL());
  112. }, function(e) {
  113. console.log("读取拍照文件错误:" + e.message);
  114. });
  115. }, function(s) {
  116. console.log("error" + s);
  117. }, {
  118. filename: "_doc/head.jpg"
  119. })
  120. }
  121. //相册
  122. function galleryImg() {
  123. plus.gallery.pick(function(a) {
  124. plus.io.resolveLocalFileSystemURL(a, function(entry) { //entry为图片原目录(相册)的句柄
  125. cutImage(entry.toLocalURL());
  126. }, function(e) {
  127. console.log("读取图片错误:" + e.message);
  128. });
  129. }, function(a) {}, {
  130. filter: "image"
  131. })
  132. };
  133. //设置默认头像
  134. function defaultInfo() {
  135. var my_icon = app.getHeadImg(); //头像
  136. var signature = app.getUserInfo().signature; //签名
  137. if(my_icon && my_icon != "") {
  138. document.getElementById("head-img1").src = my_icon;
  139. } else {
  140. document.getElementById("head-img1").src = '../img/3.png';
  141. }
  142. if(signature && signature != "") {
  143. document.getElementById("signature").value = signature;
  144. } else {
  145. document.getElementById("signature").value = "";
  146. }
  147. }
  148. //预览图像
  149. document.getElementById("head-img1").addEventListener('tap', function(e) {
  150. e.stopPropagation(); //阻止冒泡
  151. });
  152. function initImgPreview() {
  153. var imgs = document.querySelectorAll("img.mui-action-preview");
  154. imgs = mui.slice.call(imgs);
  155. if(imgs && imgs.length > 0) {
  156. var slider = document.createElement("div");
  157. slider.setAttribute("id", "__mui-imageview__");
  158. slider.classList.add("mui-slider");
  159. slider.classList.add("mui-fullscreen");
  160. slider.style.display = "none";
  161. slider.addEventListener("tap", function() {
  162. slider.style.display = "none";
  163. });
  164. slider.addEventListener("touchmove", function(event) {
  165. event.preventDefault();
  166. })
  167. var slider_group = document.createElement("div");
  168. slider_group.setAttribute("id", "__mui-imageview__group");
  169. slider_group.classList.add("mui-slider-group");
  170. imgs.forEach(function(value, index, array) {
  171. //给图片添加点击事件,触发预览显示;
  172. value.addEventListener('tap', function() {
  173. slider.style.display = "block";
  174. _slider.refresh();
  175. _slider.gotoItem(index, 0);
  176. })
  177. var item = document.createElement("div");
  178. item.classList.add("mui-slider-item");
  179. var a = document.createElement("a");
  180. var img = document.createElement("img");
  181. img.setAttribute("src", value.src);
  182. a.appendChild(img)
  183. item.appendChild(a);
  184. slider_group.appendChild(item);
  185. });
  186. slider.appendChild(slider_group);
  187. document.body.appendChild(slider);
  188. var _slider = mui(slider).slider();
  189. }
  190. }
  191. //裁剪图片
  192. function cutImage(path) {
  193. $.openWindow({
  194. url: 'index.html',
  195. id: 'index',
  196. extras: {
  197. path: path,
  198. },
  199. show: {
  200. aniShow: 'zoom-fade-in',
  201. duration: 800
  202. },
  203. waiting: {
  204. autoShow: true
  205. }
  206. });
  207. }
  208. //更新用户头像
  209. function update_head_img(e) {
  210. var my_icon = e.detail.img;
  211. //先上传
  212. app.request("User", "saveHeadImg", {
  213. 'my_icon': my_icon
  214. }, function(res) {
  215. if(res.login == 0) {
  216. mui.toast(res.info);
  217. app.clearToken();
  218. app.toLogin();
  219. return false;
  220. }
  221. if(res.status == 1) {
  222. app.setHeadImg(my_icon); //确认上传成功后存储到本地
  223. if(my_icon == "")
  224. my_icon = "../img/3.png";
  225. document.getElementById("head-img1").src = my_icon; //刷新小图
  226. document.querySelector("#__mui-imageview__group .mui-slider-item img").src = my_icon; //刷新预览图
  227. //顺带触发上一个页面的updateHeadInfo
  228. var view = plus.webview.getWebviewById("index");
  229. $.fire(view, "updateHeadInfo");
  230. mui.toast(res.info);
  231. } else {
  232. mui.toast(res.info);
  233. }
  234. });
  235. }
  236. window.addEventListener("updateHeadImg", update_head_img); //添加自定义事件,其他页面调用
  237. })(mui);
  238. </script>
  239. </body>
  240. </html>