No Description

upload-avatar.js 2.6KB

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