|
楼主 |
发表于 2018-1-4 14:46:04
|
显示全部楼层
- Model.prototype.button5Click = function(event){
- var me = this;
- var id = window.localStorage.getItem("id");
- me.comp("chooseOver").hide();
- document.addEventListener("deviceready", onDeviceReady, false);
- function onDeviceReady(){
- navigator.camera.getPicture(onLoadImageSuccess, onLoadImageFail, {
- quality:50,
- targetWidth:500,
- targetHeight:500,
- destinationType : navigator.camera.DestinationType.DATA_URL,
- sourceType : navigator.camera.PictureSourceType.PHOTOLIBRARY,
- saveToPhotoAlbum:true//将拍照好照片存储到本地 saveToPhotoLibrary
- });
- function onLoadImageSuccess(imageData) {
- localStorage.setItem("headimage","data:image/jpeg;base64,"+imageData);
- me._url = "data:image/jpeg;base64,"+imageData;
- var smallImage = document.getElementById(me.getIDByXID('showImage'));
- var image7 = document.getElementById(me.getIDByXID('image7'));
- // 取消隐藏的图像元素
- /* smallImage.style.display = 'block';
- smallImage.src = me._url;*/
- //alert(me._url);
- $(me.getElementByXid("photoBtn")).hide();
- var params = {
- "image" : me._url,
- "PicName" : id+'img.jpg',
- "id" : id
- };
- justep.Baas.sendRequest({
- "url" : "/justep/lawrance", // servlet请求地址
- "action" : "lawrance", // action
- "params" : params, // action对应的参数
- "success" : function(data) {// 请求成功后的回调方法
- if (data.success == "上传文件成功!") {
- justep.Baas.sendRequest({
- "url" : "/hongkou/hongkou",
- "action" : "updateHeaderImg",
- "async" : false,
- "params" : {
- "id" : id,
- "url" : me._url
- },
- "success" : function(ret) {
- if(ret.state == 1){
- // 取消隐藏的图像元素
- smallImage.style.display = 'block';
- smallImage.src = me._url;
- image7.src = me._url;
- localStorage.setItem("headimage", me._url);
- justep.Util.hint("头像上传成功");
- }else{
- smallImage.style.display = 'none';
- $(me.getElementByXid("photoBtn")).show();
- justep.Util.hint({"text":"头像上传失败,请重试","type":"danger"});
- }
- }
- });
- } else {
- justep.Util.hint({"text":"未知错误","type":"danger"});
- }
- }
- });
- }
- function onLoadImageFail(message) {
- return message;
- }
- }
- };
复制代码
以上是选择照片的代码。
iPhone 7 plus iOS 11.2闪退,iOS10正常,安卓正常 |
|