FastAdmin又拍云插件源码


/*
又拍云插件--Power by Andiff  weixin:andiff424    QQ:165607361
 */
(function (factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as anonymous module.
        define(['jquery'], factory);
    } else if (typeof exports === 'object') {
        // Node / CommonJS
        factory(require('jquery'));
    } else {
        // Browser globals.
        factory(jQuery);
    }
})(function ($) {
	'use strict';
	//常量
    var UPYUNURL = 'http://v0.api.upyun.com/cunzhang';
    //上传接口地址
    var BUCKET = '你的BUCKET';
    //Bucket
    var FORMAPI = '你的FORMAPI';
    //formapi
    var SAVEPATH = '服务器保存的文件夹';
    //请求的地址
    var URL = '/addons/upyun/index/rentoupyun.html?savepath=';

    var upyun = {
        //类似朋友圈上传多张图片
        uploadPicsByAjax:function(index,ul,dir){
            $.getJSON(URL+dir, function (data) {
                var uploadData = new FormData();
                uploadData.append('file', $('#files'+index)[0].files[0]);
                uploadData.append('policy', data.policy);
                uploadData.append('authorization', data.authorization);
                $.ajax({
                    url: UPYUNURL,
                    type: 'POST',
                    data: uploadData,
                    cache: false,
                    processData: false,
                    contentType: false,
                }).done(function(data, textStatus) {
                    //alert(JSON.stringify(data));
                    var body = jQuery.parseJSON(data);
                    var img = '<img width="100%" src="http://cz.andiff.wang/'+body.url+'" />';
                    img = img + '<img class="imgcommon" src="/images/cha.png" />';
                    img = img + '<input type="hidden" name="row[picurl]" value="'+body.url+'" />';
                    $("#"+ul+" li").eq(index).html(img);
                }).fail(function(res, textStatus, error) {
                    try {
                        var body = JSON.parse(res.responseText);
                        alert('error: ' + body.message);
                    } catch(e) {
                        console.error(e);
                    }
                });
            });
        },
        //普通的上传文件
        uploadByAjax: function (file1,show1,dir) {
            $.getJSON(URL+dir, function (data) {
                var uploadData = new FormData();
                uploadData.append('file', $('#'+file1)[0].files[0]);
                uploadData.append('policy', data.policy);
                uploadData.append('authorization', data.authorization);
                
                $.ajax({
                    url: UPYUNURL,
                    type: 'POST',
                    data: uploadData,
                    cache: false,
                    processData: false,
                    contentType: false,
                }).done(function(data, textStatus) {
                    //alert(JSON.stringify(data));
                    var body = jQuery.parseJSON(data);
                    $("#"+show1).val(body.url);
                }).fail(function(res, textStatus, error) {
                    try {
                        var body = JSON.parse(res.responseText);
                        alert('error: ' + body.message);
                    } catch(e) {
                        console.error(e);
                    }
                });
            });
        },
        //summernote文字编辑器里面上传图片
        uploadForSummerNote: function (file1,show1) {
            $.getJSON(URL+'summernote', function (data) {
                var uploadData = new FormData();
                uploadData.append("file", file1); 
                uploadData.append('policy', data.policy);
                uploadData.append('authorization', data.authorization); 
                $.ajax({
                    url: UPYUNURL,
                    //url: '/index/rentoupyun',
                    type: 'POST',
                    data: uploadData,
                    cache: false,
                    processData: false,
                    contentType: false,
                }).done(function(data, textStatus) {
                    var body = jQuery.parseJSON(data);
                    $("#"+show1).summernote('insertImage', 'http://cz.andiff.wang/'+body.url, 'image name'); 
                }).fail(function(res, textStatus, error) {
                    try {
                        var body = JSON.parse(res.responseText);
                        alert('error: ' + body.message);
                    } catch(e) {
                        console.error(e);
                    }
                });
            });
            //return $.inArray(type, this.dems) !== -1;
        },
    };
    return upyun; 
});


引用示例:

$("#upyun_upload").bind('change',function(){
                UpYun.uploadByAjax('upyun_upload','c-logo','store');
});

如何绑定Summernote

$('#c-intro').summernote({
              height: 150,   //set editable area's height
              codemirror: { // codemirror options
                  theme: 'monokai'
              },
              callbacks: {  
                  onImageUpload: function(files) { //the onImageUpload API  
                      //img = sendFile(files[0]);  
                      UpYun.uploadForSummerNote(files[0],'c-intro');
                  }  
              }  
  });

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值