| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- 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,
- }
- },
- })
|