123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*
- *上传附件
- *form flie元素ID容
- *option 上传附件的参数
- *fun 上传成功回调函数
- *before 上传附件前回调函数
- *going 执行上传附件时显示内容(默认为"请稍后...")
- */
- /*(function($){
- $.isUp = 0;
- $.upload = function(form,option,fun,before,going){
- var settings = {
- type:'image'
- },
- upload = function(){
- $.isUp=1;
- $.ajaxFileUpload({
- url: qscms.root + '/?c=upload&a=attach',
- type: 'POST',
- data:settings,
- secureuri:false,
- fileElementId:form,
- dataType:'json',
- success:function(result){
- if(result.status==1){
- fun && fun(result);
- }else{
- alert(result.msg);
- if(result.dialog) location.reload();
- }
- $.isUp = 0;
- }
- });
- };
- if(option) $.extend(settings,option);
- $(form).off().on({
- 'click':function(){
- //if($.isUp) return !1;
- if(before && !1 == before()) return !1;
- },
- 'change':function(){
- //if($.isUp || !$.trim($(this).val())) return !1;
- if(!$.trim($(this).val())) return !1;
- upload();
- }
- });
- };
- })(jQuery);*/
- (function($){
- $.upload = function(form,option,fun,before,going){
- var settings = {
- type:'image'
- };
- if(option){
- var path = option.path;
- if(path.indexOf("images") >= 0 ) {
- var url = '/api/common/upload/image';
- }
- if(path.indexOf("files") >= 0 ) {
- var url = '/api/common/upload/file';
- }
- $.extend(settings,option)
- }
- new AjaxUpload(form,{
- action:url,
- name:$(form).attr('name'),
- data:settings,
- responseType:'json',
- /*onChange:function(file,ext){
- alert('vdvdvd');
- if(!$.trim($(file).val())) return !1;
- },*/
- onSubmit:function(file,ext){
- if(ext && /^(doc|xls)$/.test(ext)){
- var af = this._input.files;
- var byteSize = af[0].size;
- if ((byteSize / 1024) > (10 * 1024)) {
- disapperTooltip("remind", '文件大小超出范围');
- return false;
- } else {
- if(before && !1 == before()) return !1;
- //ext是后缀名
- form.disabled = "disabled";
- }
- if(before && !1 == before()) return !1;
- form.disabled = "disabled";
- } else {
- disapperTooltip("remind", '仅支持doc,xls文件');
- return false;
- }
- if(before && !1 == before()) return !1;
- form.disabled = "disabled";
- },
- onComplete:function(file,result){
- form.disabled = "";
- if(result.message=='OK'){
- fun && fun(result);
- }else{
- $.each(result,function (key,val) {
- disapperTooltip("remind", val[0]);
- return false;
- });
- }
- }
- });
- };
- })(jQuery);
|