|
- <!DOCTYPE html>
- <html>
-
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
- <title></title>
- <script src="../js/mui.min.js"></script>
- <link href="../css/mui.min.css" rel="stylesheet" />
- <link href="../css/style.css" rel="stylesheet" />
- <script type="text/javascript" src="../js/serverurl.js"></script>
- <script type="text/javascript" src="../js/userinfos.js"></script>
- <link rel="stylesheet" href="../css/jquery.Jcrop.min.css" />
- </head>
-
- <body>
- <header class="mui-bar mui-bar-nav" style="position:relative;">
- <button type="button" class="mui-left mui-action-back mui-btn mui-btn-link mui-btn-nav">
- <span class="mui-icon mui-icon-left-nav"></span>取消
- </button>
- <h1 class="mui-title">裁剪</h1>
- <button class="mui-pull-right" style="margin-top: 5px;" id="btdocut">确定</button>
- </header>
- <div class="mui-content" id="headcontent" style="padding:5px 5px 5px 5px;">
- <img src="" id="target" alt="" />
- <input type="hidden" id="px">
- <input type="hidden" id="py">
- <input type="hidden" id="pw">
- <input type="hidden" id="ph">
- </div>
- <script type="text/javascript" src="../js/jquery-1.10.2.min.js"></script>
- <script src="../js/jquery.Jcrop.min.js"></script>
- <script type="text/javascript" charset="utf-8">
- function clipImage(bigphoto, smallphoto, x, y, w, h) {
- plus.nativeUI.showWaiting("正在保存头像...");
- plus.zip.compressImage({
- src: bigphoto,
- dst: smallphoto,
- overwrite: true,
- quality: 100,
- // width:plus.screen.resolutionWidth-10+"px",
- // height:plus.screen.resolutionHeight-80+"px",
- clip: {
- top: y,
- left: x,
- width: w,
- height: h
- }
- },
- function(ep) {
- DoUpload(ep.target);
- },
- function(error) {
- console.log("error" + error.message);
- });
- }
-
- function DoUpload(fileurl) {
- var task = plus.uploader.createUpload(api + "/user/uploadStudent", {
- method: "POST",
- blocksize: 0,
- priority: 100
- },
- function(t, status) {
- // 上传完成
- if(status == 200) {
- var entity=JSON.parse(t.responseText);
- var path = entity.info;
-
- console.log("上传成功!地址:"+path);
- users.photo=path;
- localStorage.setItem('taigangstudentUserModel', JSON.stringify(users));
- plus.webview.currentWebview().opener().evalJS("document.getElementById('photo').src='" +web+'/'+ path + "';document.getElementById('hidphoto').value='" + path + "';");
- plus.webview.currentWebview().opener().opener().evalJS("document.getElementById('photo').src='" +web+'/'+ path + "';");
- plus.nativeUI.closeWaiting();
- plus.webview.currentWebview().close();//
- } else {
- console.log("Upload failed: " + t.message);
- }
- }
- );
- task.addFile("" + fileurl + "", {
- key: "UPhoto"
- });
- task.addData("data", "" + users.ID + "");
- //task.addEventListener("statechanged", onStateChanged, false);
- task.start();
- }
- var jcrop_api;
-
- function initJcrop(rw, rh) {
- jQuery("#target").Jcrop({
- trueSize: [rw, rh],
- aspectRatio: 1,
- allowSelect: false,
- onChange: function(selection) {
- document.getElementById("px").value = selection.x;
- document.getElementById("py").value = selection.y;
- document.getElementById("pw").value = selection.w;
- document.getElementById("ph").value = selection.h;
- },
- onSelect: function(selection) {
- document.getElementById("px").value = selection.x;
- document.getElementById("py").value = selection.y;
- document.getElementById("pw").value = selection.w;
- document.getElementById("ph").value = selection.h;
- }
- }, function() {
- jcrop_api = this;
- jcrop_api.setSelect([0, 0, 600, 600]);
- });
- }
- (function($, doc) {
- $.init();
- $.plusReady(function() {
- CheckLogin();
- var self = plus.webview.currentWebview();
- var headsrc = self.headsrc;
- var img = document.getElementById("target");
- img.src = headsrc;
- initJcrop(self.realwidth, self.realheight);
- img.style.width = plus.screen.resolutionWidth - 10 + "px";
- img.style.maxHeight = plus.screen.resolutionHeight - 80 + "px";
- document.getElementById("btdocut").addEventListener("tap", function() {
- clipImage(headsrc, "_doc/smallhead.jpg", document.getElementById("px").value, document.getElementById("py").value, document.getElementById("pw").value, document.getElementById("ph").value);
- });
- });
- }(mui, document));
- </script>
- </body>
-
- </html>
|