2024-11-05 22:43:34 +08:00
|
|
|
|
"use strict";
|
|
|
|
|
define(function (require, exports, module) {
|
|
|
|
|
|
|
|
|
|
function handle(e) {
|
|
|
|
|
const ctx = require("../../common/ctx");
|
|
|
|
|
let historyScreenW = ctx.screenWidth;
|
|
|
|
|
let curScreenW = ctx.getScreenWidth();
|
|
|
|
|
if (historyScreenW === curScreenW) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//调整
|
|
|
|
|
refreshEditFrontSize()
|
|
|
|
|
refreshRootFrontSize();
|
|
|
|
|
|
|
|
|
|
//更新
|
|
|
|
|
ctx.screenWidth = ctx.getScreenWidth();
|
|
|
|
|
ctx.screenHeight = ctx.getScreenHeight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-11-08 10:09:31 +08:00
|
|
|
|
* 刷新跟节点 front-size for 全局盒子尺寸
|
2024-11-05 22:43:34 +08:00
|
|
|
|
* @constructor
|
|
|
|
|
*/
|
|
|
|
|
function refreshRootFrontSize() {
|
|
|
|
|
const ctx = require("../../common/ctx");
|
2024-11-10 22:57:28 +08:00
|
|
|
|
const utils = require("../../common/utils");
|
2024-11-08 10:09:31 +08:00
|
|
|
|
let designWidth = ctx.designWith;
|
2024-11-05 22:43:34 +08:00
|
|
|
|
let curDoc = document.documentElement;//当前文档的 root 元素
|
|
|
|
|
let curClientW = ctx.getScreenWidth();
|
|
|
|
|
if (!curClientW) {
|
2024-11-08 10:09:31 +08:00
|
|
|
|
curClientW = designWidth;
|
2024-11-05 22:43:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-09 18:59:45 +08:00
|
|
|
|
//纸张
|
2024-11-09 00:35:41 +08:00
|
|
|
|
if (curClientW >= designWidth) {
|
2024-11-09 18:59:45 +08:00
|
|
|
|
ctx.MyRoot().style.width = designWidth + "px";
|
2024-11-09 00:35:41 +08:00
|
|
|
|
} else {
|
|
|
|
|
ctx.MyRoot().style.width = "100%";
|
|
|
|
|
}
|
2024-11-08 10:09:31 +08:00
|
|
|
|
|
2024-11-10 22:57:28 +08:00
|
|
|
|
let dpr = utils.GetDpr();
|
2024-11-08 10:09:31 +08:00
|
|
|
|
//set 1rem = curClientW / designWidth (支持响应式)
|
2024-11-08 10:35:10 +08:00
|
|
|
|
let nowFrontSize = '1px';
|
2024-11-08 10:25:30 +08:00
|
|
|
|
if (ctx.isTablet || ctx.isMobile || ctx.isIOS || ctx.isAndroid) {
|
2024-11-08 10:35:10 +08:00
|
|
|
|
nowFrontSize = (curClientW / designWidth) * dpr + 'px';
|
2024-11-08 10:25:30 +08:00
|
|
|
|
} else {
|
2024-11-08 10:35:10 +08:00
|
|
|
|
nowFrontSize = (curClientW / designWidth) + 'px';
|
2024-11-08 10:25:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-10 22:57:28 +08:00
|
|
|
|
console.log(
|
|
|
|
|
"\nuserAgent: ", window.navigator.userAgent,
|
|
|
|
|
"\nisTablet: ", ctx.isTablet,
|
|
|
|
|
"\nisMobile: ", ctx.isMobile,
|
|
|
|
|
"\nisIOS: ", ctx.isIOS,
|
|
|
|
|
"\nisAndroid: ", ctx.isAndroid,
|
|
|
|
|
"\nwindow.innerWidth: ", window.innerWidth,
|
|
|
|
|
"\ngetScreenWidth: ", ctx.getScreenWidth(),
|
|
|
|
|
"curClientW : ", curClientW,
|
|
|
|
|
"\ndesignWidth: ", designWidth,
|
|
|
|
|
"\n1rem = ", nowFrontSize,
|
|
|
|
|
"\nnowFrontSize: ", nowFrontSize);
|
2024-11-08 10:35:10 +08:00
|
|
|
|
// curDoc.style.fontSize = dpr * nowFrontSize;
|
|
|
|
|
|
2024-11-10 22:57:28 +08:00
|
|
|
|
curDoc.style.fontSize = nowFrontSize;
|
2024-11-10 01:51:52 +08:00
|
|
|
|
// let testDiv = document.getElementById("testDevice");
|
|
|
|
|
// testDiv.innerText += "\ncurClientW: " + curClientW;
|
|
|
|
|
// testDiv.innerText += "\ndesignWith: " + designWidth;
|
|
|
|
|
// testDiv.innerText += "\n1rem =: " + nowFrontSize;
|
|
|
|
|
// testDiv.innerText += "\nwindow.screen.width =: " + window.screen.width;
|
|
|
|
|
// testDiv.innerText += "\nwindow.screen.height =: " + window.screen.height;
|
2024-11-05 22:43:34 +08:00
|
|
|
|
// testDiv.innerText = testDiv.innerText +
|
|
|
|
|
// // "\n navigator_userAgent :" + navigator.userAgent.toLocaleLowerCase() +
|
|
|
|
|
// "\n isMobile :" + /mobi|android|iphone|ipad|ipod/i.test(navigator.userAgent.toLocaleLowerCase()) +
|
|
|
|
|
// "\n isIOS :" + /iphone|ipad|ipod/.test(window.navigator.userAgent.toLocaleLowerCase()) +
|
|
|
|
|
// "\n isAndroid :" + /android/.test(window.navigator.userAgent.toLocaleLowerCase()) +
|
|
|
|
|
// "\n window.width :" + window.innerWidth +
|
|
|
|
|
// "\n curClientW :" + curClientW +
|
|
|
|
|
// " \n designWidth: " + designWidth +
|
|
|
|
|
// "\n 1rem = " + nowFrontSize;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-08 10:25:30 +08:00
|
|
|
|
|
|
|
|
|
function refreshEditFrontSize() {
|
|
|
|
|
const ctx = require("../../common/ctx");
|
2024-11-10 22:57:28 +08:00
|
|
|
|
const utils = require("../../common/utils");
|
2024-11-08 10:25:30 +08:00
|
|
|
|
let curClientW = ctx.getScreenWidth();
|
|
|
|
|
if (!curClientW) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//字体尺寸 https://www.shejidaren.com/zihao-daxiao-sheji-bilv.html
|
|
|
|
|
//12~72 px 建议最大字体是48px
|
|
|
|
|
|
2024-11-10 22:57:28 +08:00
|
|
|
|
let dpr = utils.GetDpr();
|
2024-11-05 22:43:34 +08:00
|
|
|
|
|
|
|
|
|
let myEditFrontSize = document.getElementById("myEdit_main");
|
|
|
|
|
if (ctx.isTablet) {
|
|
|
|
|
myEditFrontSize.style.fontSize = ctx.editFrontSize * dpr + 'px';
|
|
|
|
|
} else {
|
|
|
|
|
myEditFrontSize.style.fontSize = ctx.editFrontSize + 'px';
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-10 01:51:52 +08:00
|
|
|
|
//show
|
2024-11-10 22:57:28 +08:00
|
|
|
|
let curMyFontSizeEl = document.getElementById("cur_my_font_size");
|
|
|
|
|
curMyFontSizeEl.textContent = ctx.editFrontSize + "px";
|
|
|
|
|
//更新默认值
|
|
|
|
|
let liList = curMyFontSizeEl.parentElement.nextElementSibling.querySelectorAll("ul li");
|
|
|
|
|
for (let i = 0; i < liList.length; i++) {
|
|
|
|
|
let tmpLi = liList[i];
|
|
|
|
|
if (tmpLi.getAttribute("data-my-style-v") === ctx.editFrontSize) {
|
|
|
|
|
tmpLi.setAttribute("data-my-select", "true");
|
|
|
|
|
tmpLi.setAttribute("data-my-select-v", tmpLi.parentElement.getAttribute("data-my-select-v"));
|
|
|
|
|
} else {
|
|
|
|
|
tmpLi.removeAttribute("data-my-select");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-05 22:43:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//导出
|
|
|
|
|
exports.handle = handle;
|
|
|
|
|
exports.refreshEditFrontSize = refreshEditFrontSize;
|
|
|
|
|
});
|