personalinfo.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  7. <link href="../css/mui.min.css" rel="stylesheet" />
  8. <link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
  9. <link rel="stylesheet" type="text/css" href="../css/common.css" />
  10. <style type="text/css">
  11. #account {
  12. height: 200px;
  13. background: #82c0fa;
  14. position: relative;
  15. }
  16. .userMsg {
  17. text-align: center;
  18. }
  19. .userMsg img {
  20. border-radius: 50%;
  21. margin: 30px 0 0;
  22. }
  23. #username {
  24. color: #fff;
  25. line-height: 32px;
  26. font-size: 18px;
  27. }
  28. .waveWrapper{
  29. background: url(../images/shadow.png);
  30. height: 52px;
  31. background-color: #82c0fa;
  32. position: absolute;
  33. left: 0;
  34. right: 0;
  35. bottom: 0;
  36. background-size: cover;
  37. }
  38. .option{
  39. margin-bottom:17px;
  40. }
  41. .option .iconfont {
  42. font-size: 16px;
  43. color: #666;
  44. }
  45. .option span {
  46. color: #666;
  47. font-size: 16px;
  48. margin-left: 10px;
  49. }
  50. #userImg{
  51. width: 70px;
  52. height: 70px;
  53. }
  54. .failed{
  55. display: none;
  56. position: absolute;
  57. left: 0;
  58. right: 0;
  59. top: 0;
  60. bottom: 0;
  61. z-index: 10;
  62. }
  63. .failed img{
  64. width: 70%;
  65. position: absolute;
  66. top: 21%;
  67. left: 50%;
  68. margin-left: -35%;
  69. }
  70. .failed p{
  71. width: 100%;
  72. font-size: 16px;
  73. text-align: center;
  74. position: absolute;
  75. top: 54%;
  76. left: 0;
  77. right: 0;
  78. }
  79. .failed button{
  80. width: 34%;
  81. position: absolute;
  82. top: 61%;
  83. left: 50%;
  84. margin-left: -15%;
  85. }
  86. .header{
  87. display: none;
  88. }
  89. .mui-bar-nav~.mui-content {
  90. padding-top: 0;
  91. }
  92. </style>
  93. </head>
  94. <body>
  95. <header class="mui-bar mui-bar-nav header">
  96. <h1 class="mui-title">我的</h1>
  97. </header>
  98. <div class="mui-content">
  99. <div id="account">
  100. <div class="userMsg">
  101. <a class="" id="" href="#">
  102. <img id="userImg" src="" />
  103. </a>
  104. <p id="username"></p>
  105. </div>
  106. <div class="waveWrapper"></div>
  107. </div>
  108. <ul class="mui-table-view option">
  109. <li class="mui-table-view-cell">
  110. <a class="mui-navigate-right" href="../personalinfo/userinfo.html">
  111. <i class="iconfont">&#xe620;</i>
  112. <span>个人信息</span>
  113. </a>
  114. </li>
  115. <li class="mui-table-view-cell">
  116. <a class="mui-navigate-right" href="../personalinfo/feedback.html">
  117. <i class="iconfont">&#xe62c;</i>
  118. <span>反馈</span>
  119. </a>
  120. </li>
  121. <li class="mui-table-view-cell">
  122. <a class="mui-navigate-right" href="../personalinfo/about.html">
  123. <i class="iconfont">&#xe608;</i>
  124. <span>关于</span>
  125. </a>
  126. </li>
  127. <li class="mui-table-view-cell">
  128. <a class="mui-navigate-right" href="../personalinfo/refresh.html">
  129. <i class="iconfont">&#xe6f3;</i>
  130. <span>系统</span>
  131. </a>
  132. </li>
  133. <!--<li class="mui-table-view-cell">
  134. <a class="mui-navigate-right" id="refresh">
  135. <i class="iconfont">&#xe6f3;</i>
  136. <span>更新</span>
  137. </a>
  138. </li>-->
  139. </ul>
  140. <ul class="mui-table-view option" style="margin-bottom: 0;">
  141. <li class="mui-table-view-cell">
  142. <a class="mui-navigate-right" href="../personalinfo/setting.html">
  143. <i class="iconfont">&#xe607;</i>
  144. <span>设置</span>
  145. </a>
  146. </li>
  147. </ul>
  148. </div>
  149. <div class="failed">
  150. <img src="../images/againLoad.png"/>
  151. <p>数据加载失败</p>
  152. <button id="loadBtn">重新加载</button>
  153. </div>
  154. <script src="../js/jquery-2.1.0.js"></script>
  155. <script src="../js/mui.min.js"></script>
  156. <script type="text/javascript">
  157. mui.init();
  158. $('.mui-content').hide();
  159. var userinfoData;
  160. mui.plusReady(function() {
  161. var username = plus.storage.getItem('username');
  162. console.log(username);
  163. getuserinfo();
  164. $('#loadBtn').on('tap',getuserinfo);
  165. function getuserinfo(){
  166. mui.ajax('http://120.27.222.26/app_user_info', {
  167. data: {
  168. req:'info'
  169. },
  170. dataType: 'json', //服务器返回json格式数据
  171. type: 'post', //HTTP请求类型
  172. timeout: 10000, //超时时间设置为10秒;
  173. beforeSend: function() {
  174. plus.nativeUI.showWaiting('请求中...');
  175. },
  176. complete: function() {
  177. plus.nativeUI.closeWaiting();
  178. },
  179. success: function(data) {
  180. userinfoData = data;
  181. $('#userImg').attr('src','http://120.27.222.26/'+data.user_picture);
  182. $('#username').html(data.username);
  183. $('.failed').hide();
  184. $('.header').hide();
  185. $('.mui-content').show();
  186. },
  187. error: function(xhr, type, errorThrown) {
  188. console.log(type)
  189. console.log(errorThrown)
  190. mui.toast('个人信息获取失败');
  191. $('.mui-content').hide();
  192. $('.failed').show();
  193. $('.header').show();
  194. }
  195. });
  196. }
  197. mui('.option').on('tap', 'a', function() {
  198. var src = this.getAttribute('href');
  199. var id = (this.href.substr(this.href.lastIndexOf('/') + 1)).split('.')[0];
  200. console.log(id)
  201. if(id){
  202. if(id == 'userinfo'){
  203. mui.openWindow({
  204. url:src,
  205. id:id,
  206. extras: {
  207. data: userinfoData //扩展参数
  208. }
  209. })
  210. }else{
  211. mui.openWindow({
  212. url:src,
  213. id:id
  214. })
  215. }
  216. }else{
  217. mui.openWindow({
  218. url:src,
  219. id:id
  220. })
  221. }
  222. })
  223. //刷新
  224. // document.getElementById('refresh').addEventListener('tap', function() {
  225. // var btnArray = ['确定', '取消'];
  226. // mui.confirm('确定更新到最新版本?', '版本更新', btnArray, function(e) {
  227. // if(e.index == 0) {
  228. // console.log('是');
  229. // } else {
  230. // console.log('否');
  231. // }
  232. // })
  233. //获取当前版本号
  234. // plus.runtime.getProperty(plus.runtime.appid, function(inf) {
  235. // wgtVer = inf.version;//获取版本号
  236. // console.log(wgtVer)
  237. // var wait = plus.nativeUI.showWaiting('下载更新中,请勿关闭');
  238. // //创建一个下载任务
  239. // var dtask = plus.downloader.createDownload( "", {method:"GET"}, function ( d, status ) {
  240. // if ( status == 200 ) {
  241. // console.log( "Download success: " + d.filename );
  242. // plus.runtime.install(d.filename); // 安装下载的apk文件
  243. // }else{
  244. // mui.alert('更新失败')
  245. //// plus.runtime.install('../H5B2852C7_0925104810.apk'); // 安装下载的apk文件
  246. // }
  247. // wait.close();
  248. // });
  249. // //开始下载
  250. // dtask.start();
  251. // });
  252. // })
  253. //更换头像
  254. document.getElementById('userImg').addEventListener('tap', function() {
  255. if(mui.os.plus) {
  256. var a = [{
  257. title: '查看大图'
  258. },{
  259. title: '拍照'
  260. }, {
  261. title: '从手机相册选择'
  262. }];
  263. plus.nativeUI.actionSheet({
  264. title: '修改头像',
  265. cancel: '取消',
  266. buttons: a
  267. }, function(b) {
  268. console.log(b.index)
  269. switch(b.index) {
  270. case 0:
  271. break;
  272. case 1:
  273. lookBigImg();
  274. break;
  275. case 2:
  276. //拍照
  277. getImages();
  278. break;
  279. case 3:
  280. //打开相册
  281. galleryImages();
  282. break;
  283. default:
  284. break;
  285. }
  286. }, false);
  287. }
  288. });
  289. //查看大图
  290. function lookBigImg(){
  291. var imgsrc = document.getElementById('userImg').getAttribute('src');
  292. console.log(imgsrc)
  293. plus.nativeUI.previewImage([
  294. imgsrc
  295. ]);
  296. }
  297. //拍照
  298. function getImages() {
  299. var mobileCamera = plus.camera.getCamera();
  300. mobileCamera.captureImage(function(e) {
  301. plus.io.resolveLocalFileSystemURL(e, function(entry) {
  302. var path = entry.toLocalURL() + '?version=' + new Date().getTime();
  303. uploadHeadImg(path);
  304. }, function(e) {
  305. console.log("读取拍照文件错误");
  306. });
  307. }, function(e) {
  308. console.log("er", e.message);
  309. }, function() {
  310. filename: '_doc/head.png';
  311. });
  312. }
  313. //从本地相册选择
  314. function galleryImages() {
  315. console.log("你选择了从相册选择");
  316. plus.gallery.pick(function(a) {
  317. plus.io.resolveLocalFileSystemURL(a, function(entry) {
  318. plus.io.resolveLocalFileSystemURL('_doc/', function(root) {
  319. root.getFile('head.png', {}, function(file) {
  320. //文件已经存在
  321. file.remove(function() {
  322. console.log("文件移除成功");
  323. entry.copyTo(root, 'head.png', function(e) {
  324. var path = e.fullPath + '?version=' + new Date().getTime();
  325. uploadHeadImg(path);
  326. }, function(err) {
  327. console.log("copy image fail: ", err);
  328. });
  329. }, function(err) {
  330. console.log("删除图片失败:(" + JSON.stringify(err) + ")");
  331. });
  332. }, function(err) {
  333. //打开文件失败
  334. entry.copyTo(root, 'head.png', function(e) {
  335. var path = e.fullPath + '?version=' + new Date().getTime();
  336. uploadHeadImg(path);
  337. }, function(err) {
  338. console.log("上传图片失败:(" + JSON.stringify(err) + ")");
  339. });
  340. });
  341. }, function(e) {
  342. console.log("读取文件夹失败:(" + JSON.stringify(e) + ")");
  343. });
  344. });
  345. }, function(err) {
  346. console.log("读取拍照文件失败: ", err);
  347. }, {
  348. filter: 'image'
  349. });
  350. };
  351. //上传图片
  352. function uploadHeadImg(imgPath) {
  353. //服务端接口路径
  354. var server = "http://120.27.222.26/app_user_info";
  355. //获取图片元素
  356. var files = document.getElementById('userImg');
  357. console.log(files.src);
  358. var wt = plus.nativeUI.showWaiting('上传中...');
  359. var task = plus.uploader.createUpload(server, {
  360. method: "POST",
  361. // timeout:10
  362. },
  363. function(t, status) { //上传完成
  364. if(status == 200) {
  365. alert("上传成功:" + t.responseText);
  366. wt.close(); //关闭等待提示按钮
  367. document.getElementById('userImg').src = imgPath;
  368. } else {
  369. alert("上传失败:" + status);
  370. wt.close(); //关闭等待提示按钮
  371. }
  372. }
  373. );
  374. //添加其他参数
  375. // task.addData("name", "test");
  376. task.addData("req", "change_photo");
  377. task.addFile(imgPath, {
  378. key: "file"
  379. });
  380. task.start();
  381. }
  382. });
  383. </script>
  384. </body>
  385. </html>