|
51 | 51 | addPage: $("addPage"), |
52 | 52 | btnLive: $("btnLive"), |
53 | 53 | btnExport: $("btnExport"), |
| 54 | + edSwitch: $("edSwitch"), |
54 | 55 | fileImg: $("fileImg"), |
55 | 56 | fileHc: $("fileHc"), |
56 | 57 | fileApp: $("fileApp"), |
|
112 | 113 | }); |
113 | 114 | } |
114 | 115 |
|
| 116 | + /* ---- 三版切换(M 轻量 / R 标准 / X 全能) ---- */ |
| 117 | + // 网页端可随时切换版本:切换后引擎可编译语言、预览与导出页面均按所选版本执行 |
| 118 | + const ED_NAME = { m: "M·轻量版", r: "R·标准版", x: "X·全能版" }; |
| 119 | + const ED_DESC = { m: "仅 HIC 内核", r: "内核 + Python 编译", x: "内核 + Python + C++ 编译" }; |
| 120 | + function edNorm(ed) { |
| 121 | + const c = String(ed || "").toLowerCase()[0]; |
| 122 | + return (c === "m" || c === "r" || c === "x") ? c : "x"; |
| 123 | + } |
| 124 | + function currentEdition() { return state.edition || "x"; } |
| 125 | + // 把当前版本应用到:引擎(HC.setEdition)、全局标记(window.HIC_EDITION)、 |
| 126 | + // 顶栏版本徽标、切换器高亮、代码片段按钮(+ Python / + C++)显隐 |
| 127 | + function applyEditionUI() { |
| 128 | + const ed = currentEdition(); |
| 129 | + if (typeof HC !== "undefined" && HC.setEdition) HC.setEdition(ed); |
| 130 | + try { window.HIC_EDITION = ed; } catch (e) {} |
| 131 | + const VT = document.getElementById("verTag"); |
| 132 | + if (VT) VT.textContent = "v3.66 · " + ED_NAME[ed]; |
| 133 | + if (el.edSwitch) Array.prototype.forEach.call(el.edSwitch.querySelectorAll(".ed-btn"), function (b) { |
| 134 | + b.classList.toggle("on", b.getAttribute("data-ed") === ed); |
| 135 | + }); |
| 136 | + Array.prototype.forEach.call(document.querySelectorAll(".snippet"), function (b) { |
| 137 | + const needEd = (b.getAttribute("data-ed") || "").toLowerCase(); |
| 138 | + if (!needEd) return; |
| 139 | + let visible = false; |
| 140 | + if (needEd === "rx") visible = (ed === "r" || ed === "x"); |
| 141 | + else if (needEd === "x") visible = (ed === "x"); |
| 142 | + b.style.display = visible ? "" : "none"; |
| 143 | + }); |
| 144 | + } |
| 145 | + function setEdition(ed, silent) { |
| 146 | + const v = edNorm(ed); |
| 147 | + if (v === state.edition) return; |
| 148 | + state.edition = v; |
| 149 | + try { localStorage.setItem("HIC_EDITION_PREF", v); } catch (e) {} |
| 150 | + applyEditionUI(); |
| 151 | + if (!silent) { |
| 152 | + logConsole("output", "已切换到 " + ED_NAME[v] + "(" + ED_DESC[v] + ");预览与导出页面将按此版本编译"); |
| 153 | + doLive(); |
| 154 | + } |
| 155 | + } |
| 156 | + |
115 | 157 | /* ---- 首页引导 ---- */ |
116 | 158 | function showHome() { |
117 | 159 | saveNow(); |
|
811 | 853 | }); |
812 | 854 | // 可下载文件上传 |
813 | 855 | el.fileApp.onchange = onFileApp; |
| 856 | + // 三版切换器:M 轻量 / R 标准 / X 全能(切换后立即按新版本重新转译) |
| 857 | + if (el.edSwitch) el.edSwitch.addEventListener("click", function (e) { |
| 858 | + const b = e.target.closest ? e.target.closest("[data-ed]") : null; |
| 859 | + if (b) setEdition(b.getAttribute("data-ed")); |
| 860 | + }); |
814 | 861 | // 快捷代码片段:触发区域 / use / 下载文件 / 原生HTML / 编译语言块 |
815 | | - const _ed = (window.HIC_EDITION || "x").toLowerCase(); // m=仅HIC r=+py x=+py+cpp |
| 862 | + // (「+ Python / + C++」按钮随版本显隐由 applyEditionUI 统一处理) |
816 | 863 | Array.prototype.forEach.call(document.querySelectorAll(".snippet"), function (b) { |
817 | | - const needEd = (b.getAttribute("data-ed") || "").toLowerCase(); |
818 | | - if (needEd) { |
819 | | - let ok = false; |
820 | | - if (needEd === "rx") ok = (_ed === "r" || _ed === "x"); |
821 | | - else if (needEd === "x") ok = (_ed === "x"); |
822 | | - if (!ok) { b.style.display = "none"; } |
823 | | - } |
824 | 864 | b.onclick = function () { |
825 | 865 | const snip = b.getAttribute("data-snip"); |
826 | 866 | const code = el.code, s = code.selectionStart; |
|
850 | 890 | function boot() { |
851 | 891 | bind(); |
852 | 892 | bindNoBarPref(); |
853 | | - // 三版发布:按 HIC_EDITION 设置引擎可编译语言并在顶栏显示版本号 |
854 | | - const ed = (window.HIC_EDITION || "x").toLowerCase(); |
855 | | - if (HC.setEdition) HC.setEdition(ed); |
856 | | - const ED_NAME = { m: "M·轻量版", r: "R·标准版", x: "X·全能版" }[ed] || "X·全能版"; |
857 | | - const VT = document.getElementById("verTag"); |
858 | | - if (VT) VT.textContent = "v3.66 · " + ED_NAME; |
| 893 | + // 三版发布:网页端可直接切换 M/R/X。优先级: |
| 894 | + // ① URL 参数 ?edition=m|r|x(下载页「在线体验三版」直达) |
| 895 | + // ② localStorage 记忆的上次选择 |
| 896 | + // ③ 默认 X 全能版 |
| 897 | + let ed = "x"; |
| 898 | + try { |
| 899 | + const q = new URLSearchParams(window.location.search || "").get("edition"); |
| 900 | + ed = q || localStorage.getItem("HIC_EDITION_PREF") || "x"; |
| 901 | + } catch (e) {} |
| 902 | + state.edition = edNorm(ed); |
| 903 | + applyEditionUI(); |
859 | 904 | // 轻量编辑器:语法高亮 + 行号 + 自动缩进 + 括号补全 |
860 | 905 | if (window.HICED) window.hiced = HICED.create(el.code); |
861 | | - if (typeof HC !== "undefined" && HC.APP) logConsole("output", "HiCode " + HC.APP.version + " " + ED_NAME + "(HIC " + (ed === "m" ? "仅 HIC 内核" : ed === "r" ? "内核 + Python" : "内核 + Python + C++") + ")已启动 · 就绪"); |
| 906 | + if (typeof HC !== "undefined" && HC.APP) logConsole("output", "HiCode " + HC.APP.version + " " + ED_NAME[currentEdition()] + "(HIC " + ED_DESC[currentEdition()] + ")已启动 · 就绪"); |
862 | 907 | else logConsole("output", "HiCode IDE 已启动 · 就绪"); |
863 | 908 | if (!Store.hasAnyProject()) { showHome(); return; } |
864 | 909 | showHome(); // 默认先回首页引导;也可自动恢复 |
|
0 commit comments