index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. Page({
  2. data: {
  3. width: 300, height: 300,
  4. renderWidth: 300, renderHeight: 300,
  5. showDialog: false, name: '', text: '', bg: 'rgba(0, 0, 0, 0)',
  6. start: '', hint: '', end: '',
  7. showLightButton: false, lightButtonDisable: true, lightProgress: 1,
  8. nextAction: ''
  9. },
  10. onShow() {
  11. wx.hideHomeButton();
  12. },
  13. onHide() {
  14. wx.showHomeButton();
  15. },
  16. onLoad() {
  17. const info = wx.getSystemInfoSync();
  18. const width = info.windowWidth;
  19. const height = info.windowHeight;
  20. const dpi = info.pixelRatio;
  21. this.setData({
  22. width, height,
  23. renderWidth: width * dpi,
  24. renderHeight: height * dpi
  25. });
  26. },
  27. handleRequireLight: function({detail}) {
  28. const {state, wait} = detail;
  29. console.log('light', state, wait)
  30. if (state === 'hide') {
  31. this.setData({showLightButton: false});
  32. return;
  33. }
  34. this.setData({
  35. showLightButton: true,
  36. lightButtonDisable: state === 'cd',
  37. nextAction: '',
  38. lightProgress: state === 'cd' ? 1 - wait : 1
  39. });
  40. },
  41. handleRequireDialog: function({detail}) {
  42. const {texts, name, from} = detail;
  43. this.texts = texts;
  44. this.textIndex = 0;
  45. this.from = from;
  46. this.setData({
  47. name: name || '', text: texts[0], showDialog: true,
  48. bg: from === 'step' ? '#000' : 'rgba(0, 0, 0, 0)'
  49. });
  50. },
  51. handleClickDialog: function() {
  52. this.textIndex += 1;
  53. if (this.textIndex > this.texts.length) {
  54. return;
  55. }
  56. if (this.textIndex === this.texts.length) {
  57. this.setData({text: '', name: '', bg: '#000'});
  58. setTimeout(() => {
  59. this.textIndex = 0;
  60. this.setData({showDialog: false, nextAction: this.from});
  61. }, 1000);
  62. return;
  63. }
  64. const text = this.texts[this.textIndex];
  65. const tmp = /[\s\S]+?\{\{([\s\S]+?)\}\}[\s\S]+?/.exec(text);
  66. if (tmp) {
  67. const hint = tmp[1];
  68. const [start, end] = text.split("{{" + hint + "}}");
  69. console.log({start, hint, end})
  70. this.setData({start, hint, end});
  71. } else {
  72. this.setData({text: this.texts[this.textIndex], hint: ''});
  73. }
  74. },
  75. handleTriggerLight: function() {
  76. if (this.data.lightButtonDisable) {
  77. return;
  78. }
  79. this.setData({nextAction: 'light'});
  80. }
  81. })