latex.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var keyHeight=0;
  5. var isCloseKeyboard=1;
  6. var tempCursor = undefined;
  7. var btnName="";
  8. var isEdit = true;
  9. Page({
  10. data: {
  11. ImagePath: app.globalData.uploadImageUrl,
  12. InputHeight1: 157,
  13. InputHeight2: 157,
  14. BtnArray:[
  15. {Name:"换行",Content:"\\\\",FontSize:"24"},
  16. {Name:"空格",Content:"\\, ",FontSize:"24"},
  17. {Name:"等距空格",Content:"\\quad ",FontSize:"24"},
  18. {Name:"分数",Content:"\\frac{a}{b} ",FontSize:"24"},
  19. {Name:"平方根",Content:"\\sqrt{a} ",FontSize:"24"},
  20. {Name:"∵",Content:"∵",FontSize:"36"},
  21. {Name:"∴",Content:"∴",FontSize:"36"},
  22. {Name:"∠",Content:"∠",FontSize:"36"},
  23. {Name:"∥",Content:"∥",FontSize:"36"},
  24. {Name:"⟂",Content:"⟂",FontSize:"36"},
  25. {Name:"▵",Content:"▵",FontSize:"36"},
  26. {Name:"∼",Content:"∼",FontSize:"36"},
  27. {Name:"≅",Content:"≅",FontSize:"36"},
  28. {Name:"×",Content:"×",FontSize:"36"},
  29. {Name:"÷",Content:"÷",FontSize:"36"},
  30. {Name:"·",Content:"\\cdot",FontSize:"36"},
  31. {Name:"±",Content:"±",FontSize:"36"},
  32. {Name:"≠",Content:"≠",FontSize:"36"},
  33. {Name:"≥",Content:"≥",FontSize:"36"},
  34. {Name:"≤",Content:"≤",FontSize:"36"},
  35. {Name:"π",Content:"π",FontSize:"36"},
  36. {Name:"°",Content:"°",FontSize:"36"},
  37. {Name:"⇒",Content:"⇒",FontSize:"36"},
  38. {Name:"⇔",Content:"⇔",FontSize:"36"},
  39. {Name:"∞",Content:"∞",FontSize:"36"},
  40. {Name:"²",Content:"²",FontSize:"36"},
  41. {Name:"³",Content:"³",FontSize:"36"},
  42. {Name:"N次方",Content:"x^{n} ",FontSize:"24"},
  43. {Name:"N次方根",Content:"\\sqrt[n]{a} ",FontSize:"24"},
  44. {Name:"x₁",Content:"x₁",FontSize:"36"},
  45. {Name:"x₂",Content:"x₂",FontSize:"36"},
  46. {Name:"下标n",Content:"x_{n} ",FontSize:"24"},
  47. ],
  48. },
  49. onLoad: function (options) {
  50. var that = this;
  51. that.setData({
  52. Containnerheight: main.getWindowHeight(),
  53. Focus: true,
  54. });
  55. that.clear();
  56. },
  57. onShow:function(e){
  58. var that = this;
  59. var obj=app.globalData.Latex;
  60. if (obj){
  61. that.setData({
  62. KeyContent: obj.Content,
  63. LatexContent:"$$"+obj.Content+"$$",
  64. LatexName:obj.Name,
  65. FontSize:obj.FontSize,
  66. });
  67. obj=null;
  68. }
  69. if (app.globalData.IsIPhoneX) {
  70. that.setData({
  71. InputHeight1: 240,
  72. InputHeight2: 240,
  73. });
  74. }
  75. },
  76. //字段输入
  77. bindinputField: function (e) {
  78. var that = this;
  79. if (app.globalData.IsAndroid && !isEdit) {
  80. return;
  81. }
  82. var value=e.detail.value;
  83. value=value.replace("}","}");
  84. value=value.replace("{","{");
  85. that.setData({
  86. KeyContent: value,
  87. LatexContent:"$$"+value+"$$",
  88. });
  89. },
  90. setLatex:function(e){
  91. console.log("setLatex");
  92. var that=this;
  93. isEdit = true;
  94. var value=e.currentTarget.dataset.value;
  95. btnName=value;
  96. if (!that.data.Focus) {
  97. var obj = {
  98. detail: {
  99. cursor: tempCursor
  100. }
  101. };
  102. that.onBindblur(obj);
  103. }
  104. setTimeout(function () {
  105. that.setData({
  106. Focus: true,
  107. });
  108. }, 300);
  109. },
  110. //焦点聚焦
  111. onBindFocus: function () {
  112. //console.log("onBindFocus");
  113. btnName = "";
  114. this.setData({
  115. Focus: true,
  116. });
  117. },
  118. //失焦
  119. onBindblur: function (e) {
  120. //console.log("onBindblur:" + isEdit + " Filed:" + this.data.KeyContent);
  121. var that = this;
  122. //debugger;
  123. if (app.globalData.IsAndroid && !isEdit) {
  124. setTimeout(function () {
  125. isEdit = true;
  126. //console.log("onBindblur2:" + isEdit);
  127. }, 500);
  128. return;
  129. }
  130. isEdit = false;
  131. if (app.globalData.IsAndroid && !isEdit) {
  132. setTimeout(function () {
  133. isEdit = true;
  134. //console.log("onBindblur2:" + isEdit);
  135. }, 500);
  136. }
  137. //console.log("onBindblur:"+isEdit);
  138. tempCursor = e.detail.cursor;
  139. if (tempCursor == undefined)
  140. tempCursor = this.data["KeyContent"].length;
  141. var str1 = "",
  142. str2 = "";
  143. if (this.data.KeyContent.length > 0) {
  144. str1 = this.data.KeyContent.substr(0, tempCursor);
  145. str2 = this.data.KeyContent.substring(tempCursor, this.data.KeyContent.length);
  146. }
  147. var cur = 0;
  148. if (btnName) {
  149. cur = btnName.length;
  150. }
  151. that.data.KeyContent = str1 + btnName + str2;
  152. that.setData({
  153. KeyContent: that.data.KeyContent,
  154. LatexContent:"$$"+that.data.KeyContent+"$$",
  155. Focus: false,
  156. Cursor: tempCursor + cur,
  157. });
  158. btnName="";
  159. },
  160. bindscrollHandler: function () {
  161. //console.log("bindscrollHandler");
  162. btnName = "";
  163. },
  164. onLatexError(e){
  165. var that = this;
  166. //console.log(e);
  167. },
  168. clear:function(){
  169. var that = this;
  170. that.setData({
  171. KeyContent:"",
  172. LatexContent:"",
  173. Focus: true,
  174. Cursor: 0,
  175. });
  176. btnName="";
  177. },
  178. close: function (e) {
  179. var that=this;
  180. var value=e.currentTarget.dataset.value;
  181. if (value==1){
  182. app.globalData.Latex="\n[公式";
  183. if (that.data.LatexName)
  184. app.globalData.Latex+=" N=\""+that.data.LatexName+"\"";
  185. if (that.data.FontSize)
  186. app.globalData.Latex+=" FS=\""+that.data.FontSize+"\"";
  187. app.globalData.Latex+="]"+that.data.KeyContent+"[/公式]\n";
  188. }
  189. else
  190. app.globalData.Latex="";
  191. wx.navigateBack({
  192. delta: 1,
  193. });
  194. },
  195. goto: function (e) {
  196. var url = e.currentTarget.dataset.url;
  197. wx.navigateTo({
  198. url: url,
  199. });
  200. },
  201. onShareAppMessage: function () {
  202. return {
  203. title: app.globalData.ShareTitle,
  204. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  205. imageUrl: app.globalData.ShareImage,
  206. }
  207. },
  208. })