HomeDirective.js
15.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
"use strict";
var homeDirective = angular.module('homeDirective',[]);
var img_id_upload=[];//初始化数组,存储已经上传的图片名
var i=0;//初始化数组下标
homeDirective.directive('onChangePage', [
'$rootScope',
'$location',
'BaseService',
function ($rootScope, $location, BaseService) {
return {
restrict:'A',
link:function(scope, el, attr) {
el.on('click', function(){
var getoPage = attr.onChangePage;
var obj = $rootScope.$stateParams;
switch(getoPage) {
case 'orderinfo':
//首页查看商品详情
obj.orderid = attr.defaultValue;
obj.ordertype = attr.typeValue;
break;
case 'childrenmemberinfo':
obj.memberid = attr.defaultValue;
break;
}
BaseService.onChangePage(getoPage, obj);
});
}
}
}
]);
homeDirective.directive('deleteImg', [
'$rootScope',
'$location',
'BaseService',
function ($rootScope, $location, BaseService) {
return {
restrict:'EA',
link:function(scope, el, attr) {
el.on('click', function(){
var imgIndex = attr.imgIndex;
});
}
}
}
]);
homeDirective.directive('fileUpload', function () {
return {
restrict: 'EA',
//scope: {
// numPages: '=',
// currentPage: '=',
// onSelectPage: '&'
//},
link: function (scope, element, attrs) {
$('#file_upload').uploadify({
'auto' : false,//关闭自动上传
'removeTimeout' : 1,//文件队列上传完成1秒后删除
'swf' : './uploadfile/css/uploadify.swf',
'uploader' : '../fileupload/fdfsUpload',
'fileObjName' : 'attachs',
'method' : 'post',//方法,服务端可以用$_POST数组获取数据
'buttonText' : '选择图片',//设置按钮文本
'multi' : false,//允许同时上传多张图片
'uploadLimit' : 5,//一次最多只允许上传10张图片
'height' : 30,
'width' : 80,
'fileTypeDesc' : 'Image Files',//只允许上传图像
'fileTypeExts' : '*.gif; *.jpg; *.png',//限制允许上传的图片后缀
'fileSizeLimit' : '20000KB',
'onUploadSuccess' : function(file, data, response) {//每次成功上传后执行的回调函数,从服务端返回数据到前端
var json = eval("(" + data + ")");
i = scope.imgs.length;
scope.imgs[i]=json.data.url;
//i++;
$("#img_lists").append("<img src='"+json.data.url+"' style='width:800px; height:800px; margin-left:10px;' />");
// $("#img_lists").append("<img src='"+json.data.url+"' style='width:100px; height:100px; margin-left:10px;'/><span class='delete_icon' delete-img img-index="+i+"></span>");
},
'onQueueComplete' : function(queueData) {//上传队列全部完成后执行的回调函数
//scope.imgs = img_id_upload;
}
});
element.on("change", function() {
$('#file_upload').uploadify({
'auto' : false,//关闭自动上传
'removeTimeout' : 1,//文件队列上传完成1秒后删除
'swf' : './uploadfile/css/uploadify.swf',
'uploader' : '../fileupload/fdfsUpload',
'fileObjName' : 'attachs',
'method' : 'post',//方法,服务端可以用$_POST数组获取数据
'buttonText' : '选择图片',//设置按钮文本
'multi' : false,//允许同时上传多张图片
'uploadLimit' : 5,//一次最多只允许上传10张图片
'height' : 30,
'width' : 80,
'fileTypeDesc' : 'Image Files',//只允许上传图像
'fileTypeExts' : '*.gif; *.jpg; *.png',//限制允许上传的图片后缀
'fileSizeLimit' : '20000KB',
'onUploadSuccess' : function(file, data, response) {//每次成功上传后执行的回调函数,从服务端返回数据到前端
var json = eval("(" + data + ")");
i = scope.imgs.length;
scope.imgs[i]=json.data.url;
$("#img_lists").append("<img src='"+json.data.url+"' style='width:800px; height:800px; margin-left:10px;' />");
// $("#img_lists").append("<img src='"+json.data.url+"' style='width:100px; height:100px; margin-left:10px;' /><span class='delete_icon' delete-img img-index="+i+"></span>");
},
'onQueueComplete' : function(queueData) {//上传队列全部完成后执行的回调函数
//scope.imgs = img_id_upload;
}
// Put your options here
});
});
}
};
});
homeDirective.directive('uploadFile', function () {
return {
restrict: 'EA',
link: function (scope, element, attrs) {
element.on("change", function() {
var bar = $('.bar');
var percent = $('.percent');
var showimg = $('#showimg');
var progress = $(".progress");
var files = $(".files");
var btn = $(".btnfile span");
if($("#myupload").length<=0) {
$("#fileupload").wrap("<form id='myupload' action='../fileupload/fdfsUpload' method='post' enctype='multipart/form-data'></form>");
}
$("#myupload").ajaxSubmit({
dataType:'json',
beforeSend: function() {
//progress.show();
progress.css({'display':'inline-block'});
var percentVal = '0%';
bar.width(percentVal);
percent.html(percentVal);
btn.html("上传中...");
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal);
percent.html(percentVal);
},
success: function(data) {
files.html("<b>"+data.data.name+"("+data.data.size+"k)</b> <span class='delimg' rel='"+data.data.url+"'>删除</span>");
var img = data.data.url;
showimg.html("<img src='"+img+"' style='width:200px; height:200px;'>");
$("#new_img_default").attr("src", img);
//$("#news_img_path").val(img);
scope.imageUrl = img;
$("#oldImgDefault").hide();
$(".appmsg_thumb").show();
btn.html("上传成功");
},
error:function(xhr){
btn.html("上传失败");
bar.width('0');
files.html(xhr.responseText);
}
});
});
}
};
});
homeDirective.directive('paging', function () {
return {
restrict: 'E',
//scope: {
// numPages: '=',
// currentPage: '=',
// onSelectPage: '&'
//},
template: '',
replace: true,
link: function (scope, element, attrs) {
function totalNums(value) {
scope.pages = [];
var index = 1, maxIndex = scope.numPages;
if(value>=7) {
index = value - 5;
maxIndex = value + 4;
} else {
maxIndex = scope.numPages < 10 ? scope.numPages : 10;
}
if(maxIndex > scope.numPages) {
maxIndex = scope.numPages;
}
for (var i = index; i <= maxIndex; i++) {
scope.pages.push(i);
}
if (scope.currentPage > value && value) {
scope.selectPage(value);
}
}
scope.$watch('numPages', function (value) { //value为总页数
totalNums(scope.currentPage);
});
scope.$watch('currentPage', function (value) { //value为总页数
totalNums(value);
});
scope.isActive = function (page) {
return scope.currentPage === page;
};
scope.selectPage = function (page) {
if (!scope.isActive(page)) {
scope.currentPage = page;
scope.onSelectPage(page);
}
};
scope.selectPrevious = function () {
if (!scope.noPrevious()) {
scope.selectPage(scope.currentPage - 1);
}
};
scope.selectNext = function () {
if (!scope.noNext()) {
scope.selectPage(scope.currentPage + 1);
}
};
scope.noPrevious = function () {
return scope.currentPage == 1;
};
scope.noNext = function () {
return scope.currentPage == scope.numPages;
};
}
};
});
homeDirective.directive('uploadImage', [
'$rootScope',
function($rootScope){
return {
restrict:"EA",
link:function(scope,el,attr){
//var imgLen = scope.payImages.length
var action = attr.action;
var name = attr.name;
$(el).on("change",function(e){
var data = new FormData;
data.append(name || 'attachs',e.target.files[0]);
$.ajax({
url:action,
type:'POST',
data:data,
cache: false,
contentType: false, //不可缺
processData: false, //不可缺
success:function(data){
data = JSON.parse(data);
if(data.code==0){
var obj;
scope.hotel.hotelImgs.push({
"imageUrl":data.data.url
});
$rootScope.$apply();
}
},
error:function(data){
}
});
});
}
}
}
]);
homeDirective.directive('uploadProductImage', [
'$rootScope',
function($rootScope){
return {
restrict:"EA",
link:function(scope,el,attr){
//var imgLen = scope.payImages.length
var action = attr.action;
var name = attr.name;
var number=attr.num;
$(el).on("change",function(e){
var data = new FormData;
data.append(name || 'attachs',e.target.files[0]);
var img_len = scope.productIms.length;
if(img_len < number) {
$.ajax({
url:action,
type:'POST',
data:data,
cache: false,
contentType: false, //不可缺
processData: false, //不可缺
success:function(data){
data = JSON.parse(data);
if(data.code==0){
scope.productIms[img_len] = data.data.url;
$rootScope.$apply();
}
},
error:function(data){
}
});
} else {
alert("上传图片不能超过"+number+"张");
}
});
}
}
}
]);
homeDirective.directive('uploadExcelFile', [
'$rootScope',
function($rootScope){
return {
restrict:"EA",
link:function(scope,el,attr){
var action = attr.action;
var name = attr.name;
$(el).on("change",function(e){
$("#upload_msg_excel").text("正在上传文件,请稍后");
$("#upload_btn_excel").css({"background-color":"#c0c0c0"});
var data = new FormData;
data.append(name || 'attachs',e.target.files[0]);
$.ajax({
url:action,
type:'POST',
data:data,
cache: false,
contentType: false, //不可缺
processData: false, //不可缺
success:function(data) {
if(data.code==0) {
$("#upload_msg_excel").text("上传成功");
//$("#upload_msg_excel").text("继续上传");
$("#excel_msg").text("上传成功总数:"+data.data.successCount+",失败总数:"+data.data.faileCount+";请查看下面信息" );
$("#upload_btn_excel").css({"background-color":"#5bb75b"});
scope.deliveryInfos = data.data.excelExpressList;
scope.actualPayOrderInfos = data.data.excelExpressList;
$rootScope.$apply();
} else {
$("#upload_msg_excel").text("上传Excel文件");
$("#upload_btn_excel").css({"background-color":"#5bb75b"});
scope.errorMsg = data.message;
$rootScope.$apply();
}
},
error:function(data){
$rootScope.$apply();
$("#upload_btn_excel").css({"background-color":"red"});
$("#upload_msg_excel").text("上传失败,请重试");
}
});
});
}
}
}
]);
homeDirective.directive('uploadThumbImage', [
'$rootScope',
function($rootScope){
return {
restrict:"EA",
link:function(scope,el,attr){
//var imgLen = scope.payImages.length
var action = attr.action;
var name = attr.name;
var number=attr.num;
$(el).on("change",function(e){
var data = new FormData;
data.append(name || 'attachs',e.target.files[0]);
var img_len = scope.imageUrls.length;
if(img_len < number) {
$.ajax({
url:action,
type:'POST',
data:data,
cache: false,
contentType: false, //不可缺
processData: false, //不可缺
success:function(data){
data = JSON.parse(data);
if(data.code==0){
scope.imageUrls[img_len] = data.data.url;
$rootScope.$apply();
}
},
error:function(data){
}
});
} else {
alert("上传图片不能超过"+number+"张");
}
});
}
}
}
]);
homeDirective.directive('dateFormat', ['$filter',function($filter) {
var dateFilter = $filter('date');
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
function formatter(value) {
return dateFilter(value, 'yyyy-MM-dd HH:mm:ss'); //format
}
function parser() {
return ctrl.$modelValue;
}
ctrl.$formatters.push(formatter);
ctrl.$parsers.unshift(parser);
}
};
}]);