shaoyongjun 57cdbdba50 to:sync
2024-11-08 10:09:31 +08:00

148 lines
4.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
define(function (require, exports, module) {
console.log(("import ctx"))
class MyCtx {
#MyRoot = null;
constructor() {
console.log(("ctx init"));
//可以修改的
let editFrontSize = localStorage.getItem('editFrontSize');
if (editFrontSize !== undefined && editFrontSize !== null) {
this.editFrontSize = editFrontSize;
} else {
this.editFrontSize = 14;
}
this.usn = "syjSyj";
this.docType = 0;
// 获取 User-Agent 字符串
const userAgent = window.navigator.userAgent;
// 判断是否是手机
this.isMobile = /mobi|android|iphone|ipad|ipod/i.test(userAgent.toLocaleLowerCase()) || this.getScreenWidth() < 768;
this.isIOS = /iphone|ipad|ipod/i.test(userAgent.toLocaleLowerCase()) || this.getScreenWidth() < 768;
this.isAndroid = /android/i.test(userAgent.toLocaleLowerCase()) || this.getScreenWidth() < 768;
// 判断是否是平板电脑
this.isTablet = /tablet/i.test(userAgent.toLocaleLowerCase()) || (this.getScreenWidth() >= 768 && this.getScreenWidth() < 1024);
//屏幕宽高
this.screenWidth = 0;
this.screenHeight = 0;
//默认a4 纸
const a4Utils = require('./a4Utils');
this.designWith = a4Utils.width;
//h5 this.MyRoot
//文档map
this.doc = new Map();
//行号
this.rowNo = 0;
//是否开始输入中文
this.inCompositionEvent = false;
//最近一次操作
this.latestOpDoc = null;
//Compositionstart
this.Compositionstart = false
//初始化
}
MyRoot() {
if (this.#MyRoot === null) {
this.#MyRoot = document.getElementById("yxl_note");
}
return this.#MyRoot
}
getMapItem(orderNo) {
return this.docMap.get(orderNo);
}
incrementNumThenReturn() {
return this.rowNo++;
}
getCurRowNo() {
return this.rowNo
}
getScreenWidth() {
//vh 和 vw 都是相对于视窗的宽高度“视窗”所指为浏览器内部的可视区域大小即window.innerWidth/window.innerHeight大小
//不包含任务栏标题栏以及底部工具栏的浏览器区域大小。可以简单理解为屏幕百分比1vh = 屏幕的1%
//移动端浏览器对于 vh 单位的计算,是不包含地址栏的,也就是说 100vh 的高度会使带有地址栏的视图溢出。
return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
}
getScreenHeight() {
return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
}
/**
* 新增一个元素
* @param newParagraph
*/
addNewParagraph(newParagraph) {
//docRoot
this.MyRoot.appendChild(newParagraph);
//mapRoot
let myP = new MyDocItem(newParagraph);
let curOrder = myP.parseOrder();
let uuid = myP.parseUuid();
this.doc.set(curOrder, new MyMapItem(uuid))
//收起选区到一个点,光标落在一个可编辑元素上
window.myEdit.utils.GetSelection().setPosition(newParagraph, 0);
}
/**
* 同步某一行数据到对应的 map节点
* @param docP
* @constructor
*/
SyncMapItemChildrenStyle(docP) {
//子元素为空不处理
let items = docP.childNodes;
if (items.length <= 0) {
return
}
//构造参数
let curMyP = new MyDocItem(docP);
let mapItem = window.myEdit.ctx.getMapItem(curMyP.parseOrder());
//清空重置
// console.log(mapItem);
mapItem.getStyle().setChildrenStyleMapNull();
//遍历
for (let i = 0; i < items.length; i++) {
let curItem = items[i];
let tmpClassList = curItem.classList;
if (tmpClassList != null && tmpClassList.length > 0) {
mapItem.getStyle().setChildrenStyle(i, tmpClassList);
}
}
// console.log("sync docP : ", docP, " children: ", docP.children, " childrenMap: ", mapItem.getStyle().getChildrenStyleMap())
}
/**
*
*/
showTestText() {
}
}
// 初始化一次
module.exports = new MyCtx();
})