function get_filename(filePath) {
if (!filePath) return "";
return filePath.split(/[/\\]/).pop();
}
function escapeAttr(s) {
if (s == null) return "";
return String(s).replace(/&/g, "&").replace(/"/g, """).replace(//g, ">");
}
var SOON_EMPTY_IMG = '../assets/images/web/empty-state.png';
function soonEmptyBlock(title, hint, extraHtml) {
var html = '
' +
'' +
'
' + escapeAttr(title) + '
';
if (hint) {
html += '
' + escapeAttr(hint) + '
';
}
if (extraHtml) html += extraHtml;
html += '
';
return html;
}
let s_lan = "zh";
function language_str(str) {
let t = {
"noFile": { zh: "当前文件不存在!", ozh: "This file does not exist!", en: "File not found!" },
"saveTime": { zh: "保存时间:", ozh: "保存時間:", en: "Saved on:" },
"selectFile": { zh: "请选择文件", ozh: "請選擇文件", en: "Please select a file" },
"comfirm": { zh: "确认", ozh: "確認", en: "Confirm" },
"cancel": { zh: "取消", ozh: "取消", en: "Cancel" },
"SDFile": { zh: "SoonDesign模板文件", ozh: "SoonDesign模闆文件", en: "SoonDesign Template File" },
"lost": { zh: "(文件已丢失)", ozh: "(文件已丟失)", en: "(File Lost)" },
"clickToDelete": { zh: "文件已丢失,点击删除此记录", ozh: "文件已丟失,點擊刪除此記錄", en: "File lost, click to remove" },
"deleted": { zh: "已删除", ozh: "已刪除", en: "Deleted" },
"whetherSave": { zh: "是否保存当前文件?", ozh: "是否保存當前文件?", en: "Save current file?" },
"delTitle": { zh: "警告", ozh: "警告", en: "Warning" },
"delContent": { zh: "文件已丢失,确认是否删除?", ozh: "文件已丟失,確認是否刪除?", en: "File lost, confirm delete?" },
"deleteFileConfirm": { zh: "确认删除该文件?删除后无法恢复。", ozh: "確認刪除該文件?刪除後無法恢復。", en: "Delete this file? This cannot be undone." },
"deleteBtn": { zh: "删除", ozh: "刪除", en: "Delete" }
};
return t[str][s_lan] || t[str]['zh'];
}
function openDesign(type, filePath) {
if (window.platformBridge && window.platformBridge.openDesignPage) {
window.platformBridge.openDesignPage(filePath || '', type);
}
}
layui.use(['layer', 'form', 'jquery'], function () {
var $ = layui.$;
var layer = layui.layer;
layer.config({ skin: 'soon-layer' });
if (window.sysAPI && window.sysAPI.getAppVersion) {
window.sysAPI.getAppVersion().then(function (ver) {
$("#app-version").text("v" + ver);
}).catch(function () {});
}
function langua_ge(lan) {
lan = lan || 'zh';
$("[language='m']").each(function () {
$(this).html($(this).attr(lan));
});
$("[language='t']").each(function () {
$(this).attr("title", $(this).attr(lan));
});
}
window.soonResolveLocale(function (code) {
s_lan = code;
langua_ge(s_lan);
$("#language_select").val(s_lan);
try { localStorage.setItem("lang", s_lan); } catch (e) {}
});
$('#language_select').on('change', function () {
langua_ge($(this).find('option:selected').val());
s_lan = $(this).find('option:selected').val();
localStorage.setItem("lang", s_lan);
loadHistory();
});
function hasCloudAuth() {
if (typeof window.soonGetAccessToken === 'function') return !!window.soonGetAccessToken();
try { return !!localStorage.getItem('soon_access'); } catch (e) { return false; }
}
var fileListState = { page: 1, size: 12, total: 0, items: [] };
var templateListState = { page: 1, size: 8, total: 0, items: [] };
function displayNameFromPath(path) {
if (!path) return 'design.soon';
if (typeof window.soonDisplayFileName === 'function') {
var fromHelper = window.soonDisplayFileName(path);
if (fromHelper) return fromHelper;
}
var sessionPrefix = 'soondesign_session:';
if (path.indexOf(sessionPrefix) === 0) {
var slug = path.substring(sessionPrefix.length).replace(/-\d{10,}$/, '');
return /\.soon$/i.test(slug) ? slug : (slug + '.soon');
}
if (path.indexOf('soondesign_file:') === 0) {
var meta = window._soonFileMeta;
if (meta && meta.name) return meta.name;
return path.replace(/^soondesign_file:(\d+).*/, '文件 #$1');
}
return get_filename(path) || 'design.soon';
}
async function fetchCloudItems() {
if (!hasCloudAuth() || !window.platformBridge || !window.platformBridge.listCloudFiles) return [];
try {
var data = await window.platformBridge.listCloudFiles({ page: 1, size: 50 });
return (data && data.items) ? data.items : [];
} catch (e) {
return [];
}
}
function removeLocalHistoryPath(path) {
if (!path) return Promise.resolve();
if (typeof window.soonRecentRemove === 'function') window.soonRecentRemove(path);
if (typeof window.soonLocalRemove === 'function') {
return window.soonLocalRemove(path);
}
return Promise.resolve();
}
function recentFallbackThumb(type) {
var t = Number(type) || 1;
return soonAsset(t === 2 ? 'bg_2.png' : 'bg_1.png');
}
async function resolveRecentThumb(item) {
var realType = item.type || 1;
var fallback = recentFallbackThumb(realType);
var thumbKey = item.thumbRef || item.filePath || item.key;
if (typeof window.soonLocalGetThumb === 'function' && thumbKey) {
var localThumb = await window.soonLocalGetThumb(thumbKey);
if (localThumb) {
return typeof soonSafeImageUrl === 'function'
? soonSafeImageUrl(localThumb, fallback)
: localThumb;
}
}
if (item.kind === 'template' && item.filePath) {
var tplMatch = String(item.filePath).match(/^soondesign_template:(\d+)/);
if (tplMatch) {
var base = (window.SOON_DEPLOY_CONFIG && window.SOON_DEPLOY_CONFIG.api_v1_base) || '';
if (base) {
var v = item.updated_at ? ('?v=' + encodeURIComponent(item.updated_at)) : '';
return base + '/templates/' + tplMatch[1] + '/thumb' + v;
}
}
}
if (item.kind === 'cloud' && item.fileId && hasCloudAuth()) {
var apiBase = (window.SOON_DEPLOY_CONFIG && window.SOON_DEPLOY_CONFIG.api_v1_base) || '';
if (apiBase) return apiBase + '/files/' + item.fileId + '/thumb';
}
return fallback;
}
function recentDownloadBtnHtml() {
return '';
}
function recentDeleteBtnHtml() {
return '';
}
function renderFilePager() {
var el = document.getElementById('filePager');
if (!el) return;
var page = fileListState.page;
var size = fileListState.size;
var total = fileListState.total;
var pages = Math.max(1, Math.ceil(total / size));
if (total === 0) {
el.innerHTML = '';
return;
}
el.innerHTML =
'