作者 潘浩文
1 个管道 的构建 通过 耗费 0 秒

1

@@ -139,7 +139,8 @@ class PrizeController extends WeChatBaseController @@ -139,7 +139,8 @@ class PrizeController extends WeChatBaseController
139 public function getScore(){ 139 public function getScore(){
140 $app = new Application($this->options); 140 $app = new Application($this->options);
141 $js = $app->js; 141 $js = $app->js;
142 - $this->assign('js',$js); 142 + $jss = $js->config(['chooseImage', 'uploadImage', 'previewImage'], $debug = false, $beta = false, $json = true);
  143 + $this->assign('js',$jss);
143 return $this->fetch('getScore'); 144 return $this->fetch('getScore');
144 } 145 }
145 146
@@ -66,67 +66,98 @@ @@ -66,67 +66,98 @@
66 </div> 66 </div>
67 <div class="footer">确定</div> 67 <div class="footer">确定</div>
68 <script type="text/javascript" src="__TMPL__/public/assets/js/jquery.min.js"></script> 68 <script type="text/javascript" src="__TMPL__/public/assets/js/jquery.min.js"></script>
69 - <!--<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>--> 69 + <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
70 <script> 70 <script>
71 - function clacImgZoomParam(maxWidth, maxHeight, width, height) {  
72 - var param = {  
73 - top: 0,  
74 - left: 0,  
75 - width: width,  
76 - height: height  
77 - };  
78 - if(width > maxWidth || height > maxHeight) {  
79 - rateWidth = width / maxWidth;  
80 - rateHeight = height / maxHeight;  
81 -  
82 - if(rateWidth > rateHeight) {  
83 - param.width = maxWidth;  
84 - param.height = Math.round(height / rateWidth);  
85 - } else {  
86 - param.width = Math.round(width / rateHeight);  
87 - param.height = maxHeight;  
88 - } 71 + wx.config(
  72 + {$jss}
  73 + );
  74 +// function clacImgZoomParam(maxWidth, maxHeight, width, height) {
  75 +// var param = {
  76 +// top: 0,
  77 +// left: 0,
  78 +// width: width,
  79 +// height: height
  80 +// };
  81 +// if(width > maxWidth || height > maxHeight) {
  82 +// rateWidth = width / maxWidth;
  83 +// rateHeight = height / maxHeight;
  84 +//
  85 +// if(rateWidth > rateHeight) {
  86 +// param.width = maxWidth;
  87 +// param.height = Math.round(height / rateWidth);
  88 +// } else {
  89 +// param.width = Math.round(width / rateHeight);
  90 +// param.height = maxHeight;
  91 +// }
  92 +// }
  93 +// param.left = Math.round((maxWidth - param.width) / 2);
  94 +// param.top = Math.round((maxHeight - param.height) / 2);
  95 +// return param;
  96 +// }
  97 +//
  98 +// function previewImage(file) {
  99 +// var MAXWIDTH = 50;
  100 +// var MAXHEIGHT = 50;
  101 +// var div = document.getElementById('preview');
  102 +// if(file.files && file.files[0]) {
  103 +// div.innerHTML = '<img id=imghead onclick=$("#previewImg").click()>';
  104 +// var img = document.getElementById('imghead');
  105 +// img.onload = function() {
  106 +// var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
  107 +// img.width = rect.width;
  108 +// img.height = rect.height;
  109 +// // img.style.marginLeft = rect.left+'px';
  110 +// img.style.marginTop = rect.top + 'px';
  111 +// }
  112 +// var reader = new FileReader();
  113 +// reader.onload = function(evt) {
  114 +// img.src = evt.target.result;
  115 +// }
  116 +// reader.readAsDataURL(file.files[0]);
  117 +// } else //兼容IE
  118 +// {
  119 +// var sFilter = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
  120 +// file.select();
  121 +// var src = document.selection.createRange().text;
  122 +// div.innerHTML = '<img id=imghead>';
  123 +// var img = document.getElementById('imghead');
  124 +// img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
  125 +// var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
  126 +// status = ('rect:' + rect.top + ',' + rect.left + ',' + rect.width + ',' + rect.height);
  127 +// div.innerHTML = "<div id=divhead style='width:" + rect.width + "px;height:" + rect.height + "px;margin-top:" + rect.top + "px;" + sFilter + src + "\"'></div>";
  128 +// }
  129 +//
  130 +// }
  131 +wx.ready(function () {
  132 + $('#previewImg').click(function () {
  133 +// var id = $(this).attr('id');
  134 +// if ($(this).find('img').length=="") {
  135 + wx.chooseImage({
  136 + count: 1, // 默认9
  137 + sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  138 + sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  139 + success: function (res) {
  140 + $('#previewImg').html('<img src="'+res.localIds+'" alt="" style="position:absolute;bottom:92px;left:46px" class="deleteimg"/>')
  141 + uploadImages(res.localIds, id)
89 } 142 }
90 - param.left = Math.round((maxWidth - param.width) / 2);  
91 - param.top = Math.round((maxHeight - param.height) / 2);  
92 - return param;  
93 - }  
94 -  
95 - function previewImage(file) {  
96 - var MAXWIDTH = 50;  
97 - var MAXHEIGHT = 50;  
98 - var div = document.getElementById('preview');  
99 - if(file.files && file.files[0]) {  
100 - div.innerHTML = '<img id=imghead onclick=$("#previewImg").click()>';  
101 - var img = document.getElementById('imghead');  
102 - img.onload = function() {  
103 - var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);  
104 - img.width = rect.width;  
105 - img.height = rect.height;  
106 - // img.style.marginLeft = rect.left+'px';  
107 - img.style.marginTop = rect.top + 'px';  
108 - }  
109 - var reader = new FileReader();  
110 - reader.onload = function(evt) {  
111 - img.src = evt.target.result;  
112 - }  
113 - reader.readAsDataURL(file.files[0]);  
114 - } else //兼容IE  
115 - {  
116 - var sFilter = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';  
117 - file.select();  
118 - var src = document.selection.createRange().text;  
119 - div.innerHTML = '<img id=imghead>';  
120 - var img = document.getElementById('imghead');  
121 - img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;  
122 - var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);  
123 - status = ('rect:' + rect.top + ',' + rect.left + ',' + rect.width + ',' + rect.height);  
124 - div.innerHTML = "<div id=divhead style='width:" + rect.width + "px;height:" + rect.height + "px;margin-top:" + rect.top + "px;" + sFilter + src + "\"'></div>";  
125 - alert(src); 143 + });
  144 +// }
  145 + });
  146 + function uploadImages(localIds,id) {
  147 +// var localId = localIds.pop();
  148 + wx.uploadImage({
  149 + localId: localIds,
  150 + isShowProgressTips: 1,
  151 + success: function (res) {
  152 + var serverId = res.serverId; // 返回图片的服务器端ID
  153 + serverIds += id+':'+serverId + ',';
  154 + },
  155 + fail: function (res) {
  156 + $modal.toast(JSON.stringify(res));
126 } 157 }
127 -  
128 - }  
129 - 158 + });
  159 + }
  160 +});
130 //确定上传小票 161 //确定上传小票
131 $(".footer").click(function(){ 162 $(".footer").click(function(){
132 window.location.href='successupload.html' 163 window.location.href='successupload.html'