在线编辑优化-识别其他编码FIX
This commit is contained in:
parent
2eceff82e8
commit
1284ddd1af
|
|
@ -652,7 +652,7 @@ class files_api:
|
|||
return mw.returnJson(False, '文件不存在', (path,))
|
||||
|
||||
if os.path.getsize(path) > 2097152:
|
||||
return mw.returnJson(False, u'不能在线编辑大于2MB的文件!')
|
||||
return mw.returnJson(False, '不能在线编辑大于2MB的文件!')
|
||||
|
||||
fp = open(path, 'rb')
|
||||
data = {}
|
||||
|
|
@ -676,8 +676,10 @@ class files_api:
|
|||
data['encoding'] = 'utf-8'
|
||||
if char['encoding'] == 'Big5':
|
||||
data['encoding'] = 'BIG5'
|
||||
if not char['encoding'] in ['GBK', 'utf-8', 'BIG5']:
|
||||
|
||||
if not data['encoding'] in ['GBK', 'utf-8', 'BIG5']:
|
||||
data['encoding'] = 'utf-8'
|
||||
|
||||
try:
|
||||
if sys.version_info[0] == 2:
|
||||
data['data'] = srcBody.decode(
|
||||
|
|
@ -691,16 +693,17 @@ class files_api:
|
|||
data['encoding']).encode('utf-8', errors='ignore')
|
||||
else:
|
||||
data['data'] = srcBody.decode(data['encoding'])
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
else:
|
||||
if sys.version_info[0] == 2:
|
||||
data['data'] = srcBody.decode('utf-8').encode('utf-8')
|
||||
else:
|
||||
data['data'] = srcBody.decode('utf-8')
|
||||
data['encoding'] = u'utf-8'
|
||||
data['encoding'] = 'utf-8'
|
||||
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
except Exception as ex:
|
||||
return mw.returnJson(False, u'文件编码不被兼容,无法正确读取文件!' + str(ex))
|
||||
return mw.returnJson(False, '文件编码不被兼容,无法正确读取文件!' + str(ex))
|
||||
|
||||
def saveBody(self, path, data, encoding='utf-8'):
|
||||
if not os.path.exists(path):
|
||||
|
|
@ -724,7 +727,7 @@ class files_api:
|
|||
mw.writeLog('文件管理', '文件保存成功', (path,))
|
||||
return mw.returnJson(True, '文件保存成功')
|
||||
except Exception as ex:
|
||||
return mw.returnJson(False, 'FILE_SAVE_ERR:' + str(ex))
|
||||
return mw.returnJson(False, '文件保存错误:' + str(ex))
|
||||
|
||||
def zip(self, sfile, dfile, stype, path):
|
||||
if sfile.find(',') == -1:
|
||||
|
|
|
|||
|
|
@ -548,8 +548,8 @@ function onlineEditFile(k, f) {
|
|||
var m = "";
|
||||
var o = "";
|
||||
for(var p = 0; p < u.length; p++) {
|
||||
m = s.encoding == u[p] ? "selected" : "";
|
||||
n += '<option value="' + u[p] + '" ' + m + ">" + u[p] + "</option>"
|
||||
m = s.data.encoding == u[p] ? "selected" : "";
|
||||
n += '<option value="' + u[p] + '" ' + m + ">" + u[p] + "</option>";
|
||||
}
|
||||
var r = layer.open({
|
||||
type: 1,
|
||||
|
|
@ -557,7 +557,18 @@ function onlineEditFile(k, f) {
|
|||
closeBtn: 1,
|
||||
area: ["90%", "90%"],
|
||||
title: lan.bt.edit_title+"[" + f + "]",
|
||||
content: '<form class="bt-form pd20 pb70"><div class="line"><p style="color:red;margin-bottom:10px">'+lan.bt.edit_ps+' <select class="bt-input-text" name="encoding" style="width: 74px;position: absolute;top: 31px;right: 19px;height: 22px;z-index: 9999;border-radius: 0;">' + n + '</select></p><textarea class="mCustomScrollbar bt-input-text" id="textBody" style="width:100%;margin:0 auto;line-height: 1.8;position: relative;top: 10px;" value="" /> </div> <div class="bt-form-submit-btn" style="position:absolute; bottom:0; width:100%"> <button type="button" class="btn btn-danger btn-sm btn-editor-close">'+lan.public.close+'</button> <button id="OnlineEditFileBtn" type="button" class="btn btn-success btn-sm">'+lan.public.save+'</button> </div> </form>'
|
||||
content: '<form class="bt-form pd20 pb70">\
|
||||
<div class="line">\
|
||||
<p style="color:red;margin-bottom:10px">' + lan.bt.edit_ps + '\
|
||||
<select class="bt-input-text" name="encoding" style="width: 74px;position: absolute;top: 31px;right: 19px;height: 22px;z-index: 9999;border-radius: 0;">' + n + '</select>\
|
||||
</p>\
|
||||
<textarea class="mCustomScrollbar bt-input-text" id="textBody" style="width:100%;margin:0 auto;line-height: 1.8;position: relative;top: 10px;" value="" />\
|
||||
</div>\
|
||||
<div class="bt-form-submit-btn" style="position:absolute; bottom:0; width:100%">\
|
||||
<button type="button" class="btn btn-danger btn-sm btn-editor-close">'+lan.public.close+'</button>\
|
||||
<button id="OnlineEditFileBtn" type="button" class="btn btn-success btn-sm">'+lan.public.save+'</button>\
|
||||
</div>\
|
||||
</form>'
|
||||
});
|
||||
$("#textBody").text(s.data.data);
|
||||
var q = $(window).height() * 0.9;
|
||||
|
|
|
|||
Loading…
Reference in New Issue