暂无描述

upload-avatar.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*头像上传*/
  2. var userimg = document.getElementById("userimg");
  3. var flag;
  4. mui.plusReady(function() {
  5. var ws = plus.webview.currentWebview();
  6. var resourceId = ws.resourceId;
  7. console.log(resourceId)
  8. var web = plus.webview.getWebviewById("html/proinforupdate.html");
  9. var web1 = plus.webview.getWebviewById("resinforupdate.html");
  10. if(ws == web) {
  11. flag = 0;
  12. }
  13. if(ws == web1) {
  14. flag = 1;
  15. }
  16. userimg.addEventListener("click", function() {
  17. if(mui.os.plus) {
  18. var a = [{
  19. title: "拍照"
  20. }, {
  21. title: "从手机相册选择"
  22. }];
  23. plus.nativeUI.actionSheet({
  24. title: "修改头像",
  25. cancel: "取消",
  26. buttons: a
  27. }, function(b) {
  28. switch(b.index) {
  29. case 0:
  30. break;
  31. case 1:
  32. getImage(); //照相机
  33. break;
  34. case 2:
  35. galleryImg(); //相册
  36. break;
  37. default:
  38. break
  39. }
  40. })
  41. }
  42. })
  43. /*摄像头拍照*/
  44. function getImage() {
  45. var c = plus.camera.getCamera();
  46. c.captureImage(function(e) {
  47. plus.io.resolveLocalFileSystemURL(e, function(entry) {
  48. var filPage = plus.webview.getWebviewById('../html/fillinfo.html');
  49. var dyPage = plus.webview.currentWebview();
  50. if(dyPage == filPage) {
  51. var imgvar = '<img src="' + entry.toLocalURL() + '" style="width:100%"/>';
  52. //console.log(imgvar)
  53. document.getElementById('imgshow').innerHTML = imgvar;
  54. }
  55. mui.openWindow({
  56. url: '../html/picture-upload.html',
  57. id: 'html/picture-upload.html',
  58. show: {
  59. aniShow: "slide-in-right"
  60. },
  61. extras: {
  62. imgurl: entry.toLocalURL(),
  63. flag: flag,
  64. resourceId: resourceId
  65. }
  66. });
  67. }, function(e) {
  68. plus.nativeUI.toast("读取拍照文件错误", toastStyle);
  69. });
  70. }, function(s) {
  71. console.log("error" + s);
  72. }, {
  73. filename: "_doc/head.jpg"
  74. })
  75. }
  76. /*相册获取照片*/
  77. function galleryImg() {
  78. plus.gallery.pick(function(file) {
  79. changeToLocalUrl(file);
  80. }, function(err) {
  81. console.log(JSON.stringify(err));
  82. }, {
  83. filter: 'image',
  84. multiple: false
  85. });
  86. }
  87. function changeToLocalUrl(path) {
  88. plus.io.resolveLocalFileSystemURL(path, function(entry) {
  89. var filPage = plus.webview.getWebviewById('../html/fillinfo.html');
  90. var dyPage = plus.webview.currentWebview();
  91. if(dyPage == filPage) {
  92. var imgvar = '<img src="' + entry.toLocalURL() + '" style="width:100%"/>';
  93. //console.log(imgvar)
  94. document.getElementById('imgshow').innerHTML = imgvar;
  95. }
  96. mui.openWindow({
  97. url: '../html/picture-upload.html',
  98. id: 'html/picture-upload.html',
  99. show: {
  100. aniShow: "slide-in-right"
  101. },
  102. extras: {
  103. imgurl: entry.toLocalURL(),
  104. flag: flag,
  105. resourceId: resourceId
  106. }
  107. });
  108. });
  109. }
  110. })