萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網路程式設計 >> PHP 程式設計

ECShop 後台編輯器替換為 UEditor 完整教程(含 jQuery 衝突修復)

ECShop 預設使用 FCKeditor,體驗落後且不支援現代瀏覽器。本文記錄替換為百度 UEditor 1.4.3 的完整流程,含 jQuery 衝突解決、圖片上傳路徑配置、商品編輯頁 Bug 修復。

一、準備工作

  1. 下載 UEditor 1.4.3:官方下載頁
  2. 下載 jQuery 衝突修復包(含 config.json 路徑已調整):百度網盤(密碼:fflu)

二、部署檔案

# 解壓 UEditor 到網站根目錄
/unzip ueditor.zip -d /var/www/html/includes/ueditor

# 解壓修復包並覆蓋
/unzip fix_jquery.zip -d /var/www/html/includes/ueditor/

目錄結構:

includes/
└── ueditor/
    ├── ueditor.config.js
    ├── ueditor.all.min.js
    ├── fix_jquery/
    │   ├── jquery.min.js
    │   ├── jquery.json-1.3.js
    │   └── transport_json.js
    └── php/
        └── config.json  # 已修改圖片儲存路徑

三、修改後台編輯器生成函數

檔案:/admin/includes/lib_main.php

找到 create_html_editor() 函數,完整替換為:

function create_html_editor($input_name, $input_value = '') {
    global $smarty;
    $kindeditor = "<script id='editor' name='$input_name' type='text/plain' style='width:1024px;height:500px;'>$input_value</script>
<script charset='utf-8' src='../includes/ueditor/ueditor.config.js'></script>
<script charset='utf-8' src='../includes/ueditor/ueditor.all.min.js'></script>
<script>
var ue = UE.getEditor('editor');
</script>";
    $smarty->assign('FCKeditor', $kindeditor);
}

四、修改頁面頭部引入修復 jQuery

檔案:/admin/templates/pageheader.htm

找到:

{insert_scripts files="../js/transport.js,common.js,../js/utils.js"}

替換為:

<script src="../includes/ueditor/fix_jquery/jquery.min.js"></script>
<script src="../includes/ueditor/fix_jquery/jquery.json-1.3.js"></script>
<script src="js/common.js"></script>
<script src="../includes/ueditor/fix_jquery/transport_json.js"></script>
{insert_scripts files="../js/utils.js"}

原理:UEditor 依賴 jQuery,但 ECShop 後台原有 JS 可能版本衝突。修復包提供獨立 jQuery 實例與 JSON 處理,避免污染全域命名空間。

五、修復商品編輯頁編輯器重置 Bug

檔案:/admin/templates/goods_info.htm

找到並註釋:

// document.forms['theForm'].reset();

原因:表單重置會清空 UEditor 的隱藏 textarea,導致內容無法提交。

六、配置圖片上傳路徑

編輯 includes/ueditor/php/config.json:

"imagePathFormat": "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}",
"imageUrlPrefix": "https://your-domain.com",  // 若需 CDN 域名
"imageManagerListPath": "/ueditor/php/upload/image/"

確保 php/upload/ 目錄可寫入:

chmod -R 777 includes/ueditor/php/upload/

七、驗證測試

  1. 進入後台商品編輯/文章發布頁
  2. 確認編輯器正常載入、工具列完整
  3. 上傳圖片、插入表格、原始碼視圖切換
  4. 提交表單,檢查資料庫欄位內容正確

完成替換後,後台編輯體驗大幅提升,支援現代 HTML5 標籤、拖拽上傳、全螢幕編輯等功能。

copyright © 萬盛學電腦網 all rights reserved