latex.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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:"\\frac{a}{b} ",FontSize:"24"},
  16. {Name:"平方根",Content:"\\sqrt{a} ",FontSize:"24"},
  17. {Name:"换行",Content:"\\\\",FontSize:"24"},
  18. {Name:"空格",Content:"\\, ",FontSize:"24"},
  19. {Name:"等距空格",Content:"\\quad ",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:"×",FontSize:"36"},
  31. {Name:"÷",Content:"÷",FontSize:"36"},
  32. {Name:"·",Content:"\\cdot",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:"²",Content:"²",FontSize:"36"},
  43. {Name:"³",Content:"³",FontSize:"36"},
  44. {Name:"N次方",Content:"x^{n} ",FontSize:"24"},
  45. {Name:"N次方根",Content:"\\sqrt[n]{a} ",FontSize:"24"},
  46. {Name:"x₁",Content:"x₁",FontSize:"36"},
  47. {Name:"x₂",Content:"x₂",FontSize:"36"},
  48. {Name:"下标n",Content:"x_{n} ",FontSize:"24"},
  49. {Name:"α",Content:"α",FontSize:"36"},
  50. {Name:"β",Content:"β",FontSize:"36"},
  51. {Name:"γ",Content:"γ",FontSize:"36"},
  52. {Name:"θ",Content:"θ",FontSize:"36"},
  53. {Name:"圆弧AB",Content:"\\widehat{AB}",FontSize:"24"},
  54. {Name:"向量a",Content:"\\overrightarrow{a}",FontSize:"24"},
  55. ],
  56. },
  57. onLoad: function (options) {
  58. var that = this;
  59. that.setData({
  60. Containnerheight: main.getWindowHeight(),
  61. Focus: true,
  62. });
  63. that.clear();
  64. },
  65. onShow:function(e){
  66. var that = this;
  67. var obj=app.globalData.Latex;
  68. if (obj){
  69. that.setData({
  70. KeyContent: obj.Content,
  71. LatexContent:"$$"+obj.Content+"$$",
  72. LatexName:obj.Name,
  73. FontSize:obj.FontSize,
  74. });
  75. obj=null;
  76. }
  77. if (app.globalData.IsIPhoneX) {
  78. that.setData({
  79. InputHeight1: 240,
  80. InputHeight2: 240,
  81. });
  82. }
  83. },
  84. //字段输入
  85. bindinputField: function (e) {
  86. var that = this;
  87. if (app.globalData.IsAndroid && !isEdit) {
  88. return;
  89. }
  90. var value=e.detail.value;
  91. value=value.replace("}","}");
  92. value=value.replace("{","{");
  93. that.setData({
  94. KeyContent: value,
  95. LatexContent:"$$"+value+"$$",
  96. });
  97. },
  98. setLatex:function(e){
  99. console.log("setLatex");
  100. var that=this;
  101. isEdit = true;
  102. var value=e.currentTarget.dataset.value;
  103. btnName=value;
  104. if (!that.data.Focus) {
  105. var obj = {
  106. detail: {
  107. cursor: tempCursor
  108. }
  109. };
  110. that.onBindblur(obj);
  111. }
  112. setTimeout(function () {
  113. that.setData({
  114. Focus: true,
  115. });
  116. }, 300);
  117. },
  118. //焦点聚焦
  119. onBindFocus: function () {
  120. //console.log("onBindFocus");
  121. btnName = "";
  122. this.setData({
  123. Focus: true,
  124. });
  125. },
  126. //失焦
  127. onBindblur: function (e) {
  128. //console.log("onBindblur:" + isEdit + " Filed:" + this.data.KeyContent);
  129. var that = this;
  130. //debugger;
  131. if (app.globalData.IsAndroid && !isEdit) {
  132. setTimeout(function () {
  133. isEdit = true;
  134. //console.log("onBindblur2:" + isEdit);
  135. }, 500);
  136. return;
  137. }
  138. isEdit = false;
  139. if (app.globalData.IsAndroid && !isEdit) {
  140. setTimeout(function () {
  141. isEdit = true;
  142. //console.log("onBindblur2:" + isEdit);
  143. }, 500);
  144. }
  145. //console.log("onBindblur:"+isEdit);
  146. tempCursor = e.detail.cursor;
  147. if (tempCursor == undefined)
  148. tempCursor = this.data["KeyContent"].length;
  149. var str1 = "",
  150. str2 = "";
  151. if (this.data.KeyContent.length > 0) {
  152. str1 = this.data.KeyContent.substr(0, tempCursor);
  153. str2 = this.data.KeyContent.substring(tempCursor, this.data.KeyContent.length);
  154. }
  155. var cur = 0;
  156. if (btnName) {
  157. cur = btnName.length;
  158. }
  159. that.data.KeyContent = str1 + btnName + str2;
  160. that.setData({
  161. KeyContent: that.data.KeyContent,
  162. LatexContent:"$$"+that.data.KeyContent+"$$",
  163. Focus: false,
  164. Cursor: tempCursor + cur,
  165. });
  166. btnName="";
  167. },
  168. bindscrollHandler: function () {
  169. //console.log("bindscrollHandler");
  170. btnName = "";
  171. },
  172. onLatexError(e){
  173. var that = this;
  174. //console.log(e);
  175. },
  176. clear:function(){
  177. var that = this;
  178. that.setData({
  179. KeyContent:"",
  180. LatexContent:"",
  181. Focus: true,
  182. Cursor: 0,
  183. });
  184. btnName="";
  185. },
  186. close: function (e) {
  187. var that=this;
  188. var value=e.currentTarget.dataset.value;
  189. if (value==1){
  190. app.globalData.Latex="\n[公式";
  191. if (that.data.LatexName)
  192. app.globalData.Latex+=" N=\""+that.data.LatexName+"\"";
  193. if (that.data.FontSize)
  194. app.globalData.Latex+=" FS=\""+that.data.FontSize+"\"";
  195. app.globalData.Latex+="]"+that.data.KeyContent+"[/公式]\n";
  196. }
  197. else
  198. app.globalData.Latex="";
  199. wx.navigateBack({
  200. delta: 1,
  201. });
  202. },
  203. goto: function (e) {
  204. var url = e.currentTarget.dataset.url;
  205. wx.navigateTo({
  206. url: url,
  207. });
  208. },
  209. onShareAppMessage: function () {
  210. return {
  211. title: app.globalData.ShareTitle,
  212. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  213. imageUrl: app.globalData.ShareImage,
  214. }
  215. },
  216. })