网页端:平台桥与部署修复(宝塔/Nginx)
- lib/platform:网页 Electron 统一 bridge/web/electron,子目录 API 基路径、返回首页跳站点根、路径末尾斜杠兼容 - index/design*.web.html:网页入口,web.js 加缓存参数避免旧脚本缓存 - api:PHP 读写 soon;文档说明目录权限与 Nginx - lib/design*、lib/index:与 platformBridge 对接及网页侧逻辑 - 公共资源 JsBarcode/jr-qrcode;文档与 package/README/.gitignore 等同步更新 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+44
-26
@@ -1,6 +1,6 @@
|
||||
// design2.js - 主入口文件
|
||||
// 导入公共模块(不依赖jQuery的部分)
|
||||
require('./common/fabric-ext.js');
|
||||
// 导入公共模块(不依赖jQuery的部分);网页端由页面 script 标签提前加载
|
||||
if (typeof require !== 'undefined') { try { require('./common/fabric-ext.js'); } catch (e) {} }
|
||||
|
||||
// 过滤 Canvas2D willReadFrequently 警告(不影响功能,只是性能提示)
|
||||
if (typeof console !== 'undefined' && console.warn) {
|
||||
@@ -15,25 +15,29 @@ if (typeof console !== 'undefined' && console.warn) {
|
||||
};
|
||||
}
|
||||
|
||||
// Electron相关导入
|
||||
const remote = require('@electron/remote');
|
||||
var path = require('path');
|
||||
const exePath = remote.app.getPath('userData');
|
||||
const { ipcRenderer } = require('electron');
|
||||
const { dialog } = require('@electron/remote');
|
||||
var jrQrcode = require('jr-qrcode');
|
||||
var JsBarcode = require('jsbarcode');
|
||||
const { clipboard } = require('electron');
|
||||
// 使用平台桥(桌面端由 design2.html 先加载 lib/platform/electron.js 注入)
|
||||
var remote = typeof window !== 'undefined' ? window.remote : null;
|
||||
var path = typeof window !== 'undefined' ? window.path : null;
|
||||
var exePath = typeof window !== 'undefined' ? window.exePath : '';
|
||||
var ipcRenderer = typeof window !== 'undefined' ? window.ipcRenderer : null;
|
||||
var dialog = typeof window !== 'undefined' ? window.dialog : null;
|
||||
var clipboard = typeof window !== 'undefined' ? window.clipboard : null;
|
||||
var jrQrcode, JsBarcode;
|
||||
if (typeof require !== 'undefined') {
|
||||
try { jrQrcode = require('jr-qrcode'); } catch (e) {}
|
||||
try { JsBarcode = require('jsbarcode'); } catch (e) {}
|
||||
}
|
||||
|
||||
// 发送IPC消息
|
||||
ipcRenderer.send('get-sys-fonts');
|
||||
ipcRenderer.send('get-scale-rate');
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.send('get-sys-fonts');
|
||||
ipcRenderer.send('get-scale-rate');
|
||||
}
|
||||
|
||||
// 使用layui
|
||||
layui.use(['layer', 'slider', 'form', 'colorpicker'], function () {
|
||||
let myDate = new Date();
|
||||
let s_lan = "";
|
||||
ipcRenderer.send('get-sys-language');
|
||||
if (ipcRenderer) ipcRenderer.send('get-sys-language');
|
||||
|
||||
var $ = layui.$;
|
||||
var layer = layui.layer;
|
||||
@@ -81,7 +85,7 @@ ipcRenderer.send('get-scale-rate');
|
||||
var colorpicker = layui.colorpicker;
|
||||
|
||||
// 历史记录文件路径(供 output.js 使用)
|
||||
var fullPath = path.join(exePath, 'data.json');
|
||||
var fullPath = (path && exePath) ? path.join(exePath, 'data.json') : (typeof window !== 'undefined' ? window.fullPath : '');
|
||||
// 确保 fullPath 在全局作用域中可用(用于 .jsc 文件加载)
|
||||
if (typeof window !== 'undefined') {
|
||||
window.fullPath = fullPath;
|
||||
@@ -482,25 +486,39 @@ ipcRenderer.send('get-scale-rate');
|
||||
var ctx2 = window.ctx2;
|
||||
let is_bgi_add = window.is_bgi_add;
|
||||
|
||||
// 加载design2模块
|
||||
const fs = require('fs');
|
||||
const appPath = (() => { try { return remote.app.getAppPath(); } catch(e) { return __dirname || process.cwd(); } })();
|
||||
|
||||
// 加载 design2 模块:网页端在回调内动态加载(保证 $ 已存在),桌面端用 require+eval
|
||||
var fs = typeof window !== 'undefined' ? window.fs : null;
|
||||
var appPath = (remote && remote.app && remote.app.getAppPath) ? remote.app.getAppPath() : (typeof __dirname !== 'undefined' ? __dirname : '.');
|
||||
|
||||
if (typeof require === 'undefined') {
|
||||
function loadScript(src, next) {
|
||||
var s = document.createElement('script');
|
||||
s.src = src;
|
||||
s.onload = s.onerror = function () { if (typeof next === 'function') next(); };
|
||||
document.body.appendChild(s);
|
||||
}
|
||||
loadScript('./lib/design2/output.js', function () {
|
||||
loadScript('./lib/design2/core.js', function () {
|
||||
loadScript('./lib/design2/ui.js', function () {});
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const loadModule = (moduleName) => {
|
||||
const jsPath = path.join(appPath, 'lib', 'design2', `${moduleName}.js`);
|
||||
|
||||
// 加载 .js 源文件
|
||||
if (!path || !fs) return;
|
||||
const jsPath = path.join(appPath, 'lib', 'design2', moduleName + '.js');
|
||||
if (fs.existsSync(jsPath)) {
|
||||
try {
|
||||
eval(fs.readFileSync(jsPath, 'utf8'));
|
||||
} catch (e) {
|
||||
alert(`加载 ${moduleName} 失败!\n\n错误: ${e.message}`);
|
||||
alert('加载 ' + moduleName + ' 失败!\n\n错误: ' + e.message);
|
||||
}
|
||||
} else {
|
||||
alert(`文件不存在!\n\n请检查:${jsPath}`);
|
||||
alert('文件不存在!\n\n请检查:' + jsPath);
|
||||
}
|
||||
};
|
||||
loadModule('output'); // 先加载 output,因为 core 中的 addBackground() 需要调用 output 中的 open()
|
||||
loadModule('output');
|
||||
loadModule('core');
|
||||
loadModule('ui');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user