Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit e3f4fe2

Browse files
committed
修改前后端交互
1 parent 598ccec commit e3f4fe2

File tree

16 files changed

+10150
-258
lines changed

16 files changed

+10150
-258
lines changed

_src/core/Editor.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,13 @@
263263

264264
/* 尝试异步加载后台配置 */
265265
try{
266-
var serverUrl = me.options.serverUrl || me.options.imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2') || '';
266+
me.options.imageUrl && me.setOpt(me.options.imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2'));
267+
268+
var configUrl = me.getActionUrl('config');
267269

268270
/* 发出ajax请求 */
269271
me._serverConfigLoaded = false;
270-
serverUrl && UE.ajax.request(serverUrl,{
272+
configUrl && UE.ajax.request(configUrl,{
271273
'method': 'GET',
272274
'data': {
273275
'action': 'config'
@@ -1535,6 +1537,34 @@
15351537
for (var i = 0, ci; ci = this.outputRules[i++];) {
15361538
ci.call(this, root)
15371539
}
1540+
},
1541+
1542+
/**
1543+
* 根据action名称获取请求的路径
1544+
* @method getActionUrl
1545+
* @remind 假如没有设置serverUrl,会根据imageUrl设置默认的controller路径
1546+
* @param { String } action action名称
1547+
* @example
1548+
* ```javascript
1549+
* editor.getActionUrl('config'); //返回 "/ueditor/php/controller.php?action=config"
1550+
* editor.getActionUrl('image'); //返回 "/ueditor/php/controller.php?action=uplaodimage"
1551+
* editor.getActionUrl('scrawl'); //返回 "/ueditor/php/controller.php?action=uplaodscrawl"
1552+
* editor.getActionUrl('imageManager'); //返回 "/ueditor/php/controller.php?action=listimage"
1553+
* ```
1554+
*/
1555+
getActionUrl: function(action){
1556+
var imageUrl = this.getOpt('imageUrl'),
1557+
serverUrl = this.getOpt('serverUrl');
1558+
1559+
if(!serverUrl && imageUrl) {
1560+
serverUrl = imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2');
1561+
}
1562+
1563+
if(serverUrl) {
1564+
return serverUrl + (serverUrl.indexOf('?') ? '?':'&') + 'action=' + action;
1565+
} else {
1566+
return '';
1567+
}
15381568
}
15391569
};
15401570
utils.inherits(Editor, EventBase);

_src/plugins/autoupload.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ UE.plugin.register('autoupload', function (){
1212
var fd = new FormData();
1313
fd.append(editor.options.imageFieldName, file, file.name || ('blob.' + file.type.substr('image/'.length)));
1414
fd.append('type', 'ajax');
15-
var xhr = new XMLHttpRequest();
16-
xhr.open("post", me.options.imageUrl, true);
15+
var xhr = new XMLHttpRequest(),
16+
url = editor.getActionUrl(editor.getOpt('imageActionName'));
17+
xhr.open("post", url, true);
1718
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
1819
xhr.addEventListener('load', function (e) {
1920
try{
2021
var json = (new Function("return " + e.target.response))(),
21-
picLink = me.options.imagePath + json.url;
22+
picLink = me.getOpt('imageUrlPrefix') + json.url;
2223
editor.execCommand('insertimage', {
2324
src: picLink,
2425
_src: picLink

_src/plugins/catchremoteimage.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ UE.plugins['catchremoteimage'] = function () {
2323
me.addListener("catchRemoteImage", function () {
2424

2525
var catcherLocalDomain = me.getOpt('catcherLocalDomain'),
26-
catcherUrl = me.getOpt('catcherUrl'),
27-
catcherPath = me.getOpt('catcherPath'),
26+
catcherActionUrl = me.getActionUrl(me.getOpt('imageActionName')),
27+
catcherUrlPrefix = me.getOpt('catcherUrlPrefix'),
2828
catcherFieldName = me.getOpt('catcherFieldName');
2929

3030
var remoteImages = [],
@@ -68,7 +68,7 @@ UE.plugins['catchremoteimage'] = function () {
6868
console.log(cj.source);
6969
console.log(cj.state);
7070
if (oldSrc == cj.source && cj.state == "SUCCESS") { //抓取失败时不做替换处理
71-
newSrc = catcherPath + cj.url;
71+
newSrc = catcherUrlPrefix + cj.url;
7272
domUtils.setAttributes(ci, {
7373
"src": newSrc,
7474
"_src": newSrc
@@ -93,7 +93,7 @@ UE.plugins['catchremoteimage'] = function () {
9393
onerror: callbacks["error"]
9494
};
9595
opt[catcherFieldName] = imgs;
96-
ajax.request(catcherUrl, opt);
96+
ajax.request(catcherActionUrl, opt);
9797
}
9898

9999
});

_src/plugins/simpleupload.js

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,57 +11,78 @@ UE.plugin.register('simpleupload', function (){
1111

1212
// 创建webupoaler实例
1313
var uploader = me.webuploader = WebUploader.create({
14-
15-
// swf文件路径
1614
swf: me.options.uploaderSwfUrl,
17-
18-
// 文件接收服务端。
19-
server: me.options.imageUrl,
20-
21-
// 选择文件的按钮。可选。
22-
// 内部根据当前运行是创建,可能是input元素,也可能是flash.
23-
// pick: '#' + id,
24-
25-
// 不压缩image, 默认如果是jpeg,文件上传前会压缩一把再上传!
15+
accept: {
16+
title: 'Images',
17+
extensions: me.getOpt('imageAllowFiles').join('').replace(/\./g, ',').replace(/^[,]/, ''),
18+
mimeTypes: 'image/*'
19+
},
20+
chunked: true,
21+
server: me.getActionUrl(me.getOpt('imageActionName')),
2622
resize: false,
27-
28-
threads: 3,
29-
fileVal: me.options.imageFieldName,
23+
fileVal: me.getOpt('imageFieldName'),
24+
duplicate: true,
3025
formdata: {},
31-
duplicate: true
26+
threads: 3,
27+
fileSingleSizeLimit: me.getOpt('imageMaxSize'), // 默认 2 M
28+
compress: me.getOpt('imageCompressEnable') ? {
29+
width: me.getOpt('imageCompressBorder'),
30+
height: me.getOpt('imageCompressBorder'),
31+
// 图片质量,只有type为`image/jpeg`的时候才有效。
32+
quality: 90,
33+
// 是否允许放大,如果想要生成小图的时候不失真,此选项应该设置为false.
34+
allowMagnify: false,
35+
// 是否允许裁剪。
36+
crop: false,
37+
// 是否保留头部meta信息。
38+
preserveHeaders: true
39+
}:false
3240

3341
});
3442

3543
// 当有文件被添加进队列的时候
36-
uploader.on('filesQueued', function (a, b) {
44+
uploader.on('fileQueued', function (file) {
45+
file.on('statuschange', function (cur, prev) {
46+
if (cur === 'error' || cur === 'invalid' || cur === 'cancelled') {
47+
var msg = file.statusText;
48+
if(msg == 'exceed_size') {
49+
showError(me.getLang('simpleupload.exceedSizeError'));
50+
} else if(cur == 'error') {
51+
showError(msg + ' Error!');
52+
} else {
53+
showError(msg);
54+
}
55+
}
56+
});
57+
});
58+
uploader.on('filesQueued', function (files) {
3759
uploader.upload();
3860
});
3961
uploader.on('uploadSuccess', function (file, ret) {
4062
try{
4163
var json = (new Function("return " + ret._raw))();
42-
var picLink = me.options.imagePath + json.url;
43-
if(json.url) {
64+
var picLink = me.getOpt('imageUrlPrefix') + json.url;
65+
if(json.state == 'SUCCESS' && json.url) {
4466
me.execCommand('insertimage', {
4567
src: picLink,
4668
_src: picLink
4769
});
4870
} else {
49-
showError('server error: ' + json.state);
71+
showError(json.state);
5072
}
5173
}catch(er){
52-
showError('parseError: ' + ret._raw);
74+
showError(me.getLang('simpleupload.jsonEncodeError'));
5375
}
5476
});
55-
uploader.on('uploadError', function (file) {
56-
showError('uploadError!');
77+
uploader.on('uploadError', function (file, msg) {
5778
});
5879
uploader.on('uploadComplete', function (file) {
5980
});
6081

6182
me.fireEvent('initWebUploader');
6283

6384
function showError(msg){
64-
alert(msg || '上传错误!');
85+
alert(msg);
6586
}
6687

6788
}

dialogs/attachment/attachment.js

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
function initButtons() {
3333

3434
dialog.onok = function () {
35-
var remote = false, list = [], id, tabs = $G('tabhead').children;
35+
var list = [], id, tabs = $G('tabhead').children;
3636
for (var i = 0; i < tabs.length; i++) {
3737
if (domUtils.hasClass(tabs[i], 'focus')) {
3838
id = tabs[i].getAttribute('data-content-id');
@@ -49,10 +49,15 @@
4949
break;
5050
}
5151

52-
if(list) {
53-
editor.execCommand('insertimage', list);
54-
remote && editor.fireEvent("catchRemoteImage");
55-
}
52+
utils.each(utils.isArray(list) ? list:[list], function(item, i){
53+
if(item && item.url) {
54+
editor.execCommand('inserthtml',
55+
'<p style="line-height: 16px;">' +
56+
'<img src="'+ item.icon + '" _src="' + item.icon + '" />' +
57+
'<a href="' + item.url +'">"' + item.url + '"</a>' +
58+
'</p>');
59+
}
60+
});
5661
};
5762
}
5863

@@ -154,7 +159,7 @@
154159
swf: '../../third-party/webuploader/Uploader.swf',
155160
disableGlobalDnd: true,
156161
chunked: true,
157-
server: editor.getOpt('fileUrl'),
162+
server: editor.getActionUrl(editor.getOpt('imageActionName')),
158163
fileVal: editor.getOpt('fileFieldName'),
159164
duplicate: true,
160165
fileNumLimit: 300,
@@ -619,7 +624,6 @@
619624
})(preview));
620625
preview.width = '100';
621626
preview.setAttribute('src', editor.getOpt('fileManagerPath') + list[i].url + (list[i].url.indexOf('?') == -1 ? '?noCache=':'&noCache=') + (+new Date()).toString(36) );
622-
preview.setAttribute('_src', editor.getOpt('fileManagerPath') + list[i].url);
623627
} else {
624628
var ic = document.createElement('i'),
625629
textSpan = document.createElement('span');
@@ -632,6 +636,7 @@
632636
domUtils.addClass(ic, 'file-preview');
633637
}
634638
domUtils.addClass(icon, 'icon');
639+
item.setAttribute('data-url', list[i].url);
635640

636641
item.appendChild(preview);
637642
item.appendChild(icon);
@@ -666,18 +671,42 @@
666671
}
667672
}
668673
},
674+
getFileIcon: function(url){
675+
var ext = url.substr(url.lastIndexOf('.') + 1),
676+
maps = {
677+
"rar":"icon_rar.gif",
678+
"zip":"icon_rar.gif",
679+
"doc":"icon_doc.gif",
680+
"docx":"icon_doc.gif",
681+
"pdf":"icon_pdf.gif",
682+
"mp3":"icon_mp3.gif",
683+
"xls":"icon_xls.gif",
684+
"chm":"icon_chm.gif",
685+
"ppt":"icon_ppt.gif",
686+
"pptx":"icon_ppt.gif",
687+
"avi":"icon_mv.gif",
688+
"rmvb":"icon_mv.gif",
689+
"wmv":"icon_mv.gif",
690+
"flv":"icon_mv.gif",
691+
"swf":"icon_mv.gif",
692+
"rm":"icon_mv.gif",
693+
"exe":"icon_exe.gif",
694+
"psd":"icon_psd.gif",
695+
"txt":"icon_txt.gif"
696+
};
697+
return maps[ext] ? maps[ext]:maps['txt'];
698+
},
669699
getInsertList: function () {
670700
var i, lis = this.list.children, list = [];
671701
for (i = 0; i < lis.length; i++) {
672702
if (domUtils.hasClass(lis[i], 'selected')) {
673-
var img = lis[i].firstChild,
674-
src = img.getAttribute('_src');
703+
var url = lis[i].getAttribute('data-url');
675704
list.push({
676-
src: src,
677-
_src: src
705+
icon: this.getFileIcon(url),
706+
title: url.substr(url.lastIndexOf('/') + 1),
707+
url: editor.options.fileUrlPrefix + url
678708
});
679709
}
680-
681710
}
682711
return list;
683712
}

dialogs/image/image.js

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dialogs/scrawl/scrawl.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ var scrawl = function (options) {
4040
},
4141

4242
originalState:function (options) {
43-
var me = this,
44-
url = editor.options.scrawlUrl;
43+
var me = this;
4544

4645
me.brushWidth = options.drawBrushSize;//同步画笔粗细
4746
me.brushColor = options.drawBrushColor;//同步画笔颜色
4847

49-
$G("fileForm").action = url + (url.indexOf("?") == -1 ? "?" : "&") + "action=tmpImg";//初始form提交地址
5048
context.lineWidth = me.brushWidth;//初始画笔大小
5149
context.strokeStyle = me.brushColor;//初始画笔颜色
5250
context.fillStyle = "transparent";//初始画布背景颜色
@@ -636,7 +634,7 @@ function exec(scrawlObj) {
636634
responseObj = eval("(" + xhr.responseText + ")");
637635
if (responseObj.state == "SUCCESS") {
638636
var imgObj = {},
639-
url = editor.options.scrawlPath + responseObj.url;
637+
url = editor.options.scrawlUrlPrefix + responseObj.url;
640638
imgObj.src = url;
641639
imgObj._src = url;
642640
editor.execCommand("insertImage", imgObj);
@@ -653,7 +651,7 @@ function exec(scrawlObj) {
653651
}
654652
};
655653
options[editor.getOpt('scrawlFieldName')] = base64;
656-
ajax.request(editor.getOpt('scrawlUrl'), options);
654+
ajax.request(editor.getActionUrl(editor.getOpt('scrawlActionName')), options);
657655
}
658656
} else {
659657
addMaskLayer(lang.noScarwl + "&nbsp;&nbsp;&nbsp;<input type='button' value='" + lang.continueBtn + "' onclick='removeMaskLayer()'/>");

lang/en/en.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ UE.I18N['en'] = {
6161
'impact':'Impact',
6262
'timesNewRoman':'Times new roman'
6363
},
64+
'simpleupload':{
65+
'exceedSizeError': 'File Size Exceed',
66+
'jsonEncodeError': 'Server Return Format Error'
67+
},
6468
'customstyle':{
6569
'tc':'Title center',
6670
'tl':'Title left',

0 commit comments

Comments
 (0)