import common from '../../utils/util'; import main from '../../utils/main'; const app = getApp(); var keyHeight=0; var isCloseKeyboard=1; var tempCursor = undefined; var btnName=""; var isEdit = true; Page({ data: { ImagePath: app.globalData.uploadImageUrl, InputHeight1: 157, InputHeight2: 157, BtnArray:[ {Name:"分数",Content:"\\frac{a}{b} ",FontSize:"24"}, {Name:"平方根",Content:"\\sqrt{a} ",FontSize:"24"}, {Name:"换行",Content:"\\\\",FontSize:"24"}, {Name:"空格",Content:"\\, ",FontSize:"24"}, {Name:"等距空格",Content:"\\quad ",FontSize:"24"}, {Name:"∵",Content:"∵",FontSize:"36"}, {Name:"∴",Content:"∴",FontSize:"36"}, {Name:"∠",Content:"∠",FontSize:"36"}, {Name:"∥",Content:"∥",FontSize:"36"}, {Name:"⟂",Content:"⟂",FontSize:"36"}, {Name:"▵",Content:"▵",FontSize:"36"}, {Name:"▱",Content:"▱",FontSize:"36"}, {Name:"⊙",Content:"⊙",FontSize:"36"}, {Name:"∼",Content:"∼",FontSize:"36"}, {Name:"≅",Content:"≅",FontSize:"36"}, {Name:"×",Content:"×",FontSize:"36"}, {Name:"÷",Content:"÷",FontSize:"36"}, {Name:"·",Content:"\\cdot",FontSize:"36"}, {Name:"±",Content:"±",FontSize:"36"}, {Name:"≠",Content:"≠",FontSize:"36"}, {Name:"≥",Content:"≥",FontSize:"36"}, {Name:"≤",Content:"≤",FontSize:"36"}, {Name:"π",Content:"π",FontSize:"36"}, {Name:"°",Content:"°",FontSize:"36"}, {Name:"⇒",Content:"⇒",FontSize:"36"}, {Name:"⇔",Content:"⇔",FontSize:"36"}, {Name:"+∞",Content:"+∞",FontSize:"36"}, {Name:"²",Content:"²",FontSize:"36"}, {Name:"³",Content:"³",FontSize:"36"}, {Name:"N次方",Content:"x^{n} ",FontSize:"24"}, {Name:"N次方根",Content:"\\sqrt[n]{a} ",FontSize:"24"}, {Name:"x₁",Content:"x₁",FontSize:"36"}, {Name:"x₂",Content:"x₂",FontSize:"36"}, {Name:"下标n",Content:"x_{n} ",FontSize:"24"}, {Name:"α",Content:"α",FontSize:"36"}, {Name:"β",Content:"β",FontSize:"36"}, {Name:"γ",Content:"γ",FontSize:"36"}, {Name:"θ",Content:"θ",FontSize:"36"}, {Name:"圆弧AB",Content:"\\widehat{AB}",FontSize:"24"}, {Name:"向量a",Content:"\\overrightarrow{a}",FontSize:"24"}, ], }, onLoad: function (options) { var that = this; that.setData({ Containnerheight: main.getWindowHeight(), Focus: true, }); that.clear(); }, onShow:function(e){ var that = this; var obj=app.globalData.Latex; if (obj){ that.setData({ KeyContent: obj.Content, LatexContent:"$$"+obj.Content+"$$", LatexName:obj.Name, FontSize:obj.FontSize, }); obj=null; } if (app.globalData.IsIPhoneX) { that.setData({ InputHeight1: 240, InputHeight2: 240, }); } }, //字段输入 bindinputField: function (e) { var that = this; if (app.globalData.IsAndroid && !isEdit) { return; } var value=e.detail.value; value=value.replace("}","}"); value=value.replace("{","{"); that.setData({ KeyContent: value, LatexContent:"$$"+value+"$$", }); }, setLatex:function(e){ console.log("setLatex"); var that=this; isEdit = true; var value=e.currentTarget.dataset.value; btnName=value; if (!that.data.Focus) { var obj = { detail: { cursor: tempCursor } }; that.onBindblur(obj); } setTimeout(function () { that.setData({ Focus: true, }); }, 300); }, //焦点聚焦 onBindFocus: function () { //console.log("onBindFocus"); btnName = ""; this.setData({ Focus: true, }); }, //失焦 onBindblur: function (e) { //console.log("onBindblur:" + isEdit + " Filed:" + this.data.KeyContent); var that = this; //debugger; if (app.globalData.IsAndroid && !isEdit) { setTimeout(function () { isEdit = true; //console.log("onBindblur2:" + isEdit); }, 500); return; } isEdit = false; if (app.globalData.IsAndroid && !isEdit) { setTimeout(function () { isEdit = true; //console.log("onBindblur2:" + isEdit); }, 500); } //console.log("onBindblur:"+isEdit); tempCursor = e.detail.cursor; if (tempCursor == undefined) tempCursor = this.data["KeyContent"].length; var str1 = "", str2 = ""; if (this.data.KeyContent.length > 0) { str1 = this.data.KeyContent.substr(0, tempCursor); str2 = this.data.KeyContent.substring(tempCursor, this.data.KeyContent.length); } var cur = 0; if (btnName) { cur = btnName.length; } that.data.KeyContent = str1 + btnName + str2; that.setData({ KeyContent: that.data.KeyContent, LatexContent:"$$"+that.data.KeyContent+"$$", Focus: false, Cursor: tempCursor + cur, }); btnName=""; }, bindscrollHandler: function () { //console.log("bindscrollHandler"); btnName = ""; }, onLatexError(e){ var that = this; //console.log(e); }, clear:function(){ var that = this; that.setData({ KeyContent:"", LatexContent:"", Focus: true, Cursor: 0, }); btnName=""; }, close: function (e) { var that=this; var value=e.currentTarget.dataset.value; if (value==1){ app.globalData.Latex="\n[公式"; if (that.data.LatexName) app.globalData.Latex+=" N=\""+that.data.LatexName+"\""; if (that.data.FontSize) app.globalData.Latex+=" FS=\""+that.data.FontSize+"\""; app.globalData.Latex+="]"+that.data.KeyContent+"[/公式]\n"; } else app.globalData.Latex=""; wx.navigateBack({ delta: 1, }); }, goto: function (e) { var url = e.currentTarget.dataset.url; wx.navigateTo({ url: url, }); }, onShareAppMessage: function () { return { title: app.globalData.ShareTitle, path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID, imageUrl: app.globalData.ShareImage, } }, })