index.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title></title>
  9. <style type="text/css">
  10. html,
  11. body,
  12. .canvas {
  13. padding: 0;
  14. margin: 0;
  15. overflow-y: hidden;
  16. background-color: transparent;
  17. width: 100%;
  18. height: 100%;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div class="canvas" id="limeChart"></div>
  24. <script type="text/javascript" src="./uni.webview.1.5.3.js"></script>
  25. <script type="text/javascript" src="./echarts.min.js"></script>
  26. <script type="text/javascript" src="./ecStat.min.js"></script>
  27. <!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts-liquidfill@latest/dist/echarts-liquidfill.min.js"></script> -->
  28. <script>
  29. let chart = null;
  30. let cache = [];
  31. console.log = function(...agrs) {
  32. postMessage(agrs)
  33. }
  34. function emit(event, data) {
  35. let dataStr = JSON.stringify(data, stringify)
  36. postMessage({
  37. event,
  38. data: dataStr
  39. })
  40. cache = []
  41. }
  42. function postMessage(data) {
  43. uni.postMessage({
  44. data
  45. });
  46. }
  47. function stringify(key, value) {
  48. if (typeof value === 'object' && value !== null) {
  49. if (cache.indexOf(value) !== -1) {
  50. return;
  51. }
  52. cache.push(value);
  53. }
  54. return value;
  55. }
  56. function parse(name, callback, options) {
  57. const optionNameReg = /[\w]+\.setOption\(([\w]+\.)?([\w]+)\)/
  58. if (optionNameReg.test(callback)) {
  59. const optionNames = callback.match(optionNameReg)
  60. if(optionNames[1]) {
  61. const _this = optionNames[1].split('.')[0]
  62. window[_this] = {}
  63. window[_this][optionNames[2]] = options
  64. return optionNames[2]
  65. } else {
  66. return null
  67. }
  68. }
  69. return null
  70. }
  71. function init(callback, options, opts = {}, theme = null) {
  72. if(!chart) {
  73. chart = echarts.init(document.getElementById('limeChart'), theme, opts)
  74. if(options) {
  75. chart.setOption(options)
  76. }
  77. // const name = parse('a', callback, options)
  78. // console.log('options::', callback)
  79. // if(name) this[name] = options
  80. // eval(`a = ${callback};`)
  81. // if(a) {a(chart)}
  82. }
  83. }
  84. function setChart(callback, options) {
  85. if(!callback) return
  86. if(chart && callback && options) {
  87. var r = null
  88. const name = parse('r', callback, options)
  89. if(name) this[name] = options
  90. eval(`r = ${callback};`)
  91. if(r) {r(chart)}
  92. }
  93. }
  94. function setOption(data) {
  95. if (chart) chart.setOption(data[0], data[1])
  96. }
  97. function showLoading(data) {
  98. if (chart) chart.showLoading(data[0], data[1])
  99. }
  100. function hideLoading() {
  101. if (chart) chart.hideLoading()
  102. }
  103. function clear() {
  104. if (chart) chart.clear()
  105. }
  106. function dispose() {
  107. if (chart) chart.dispose()
  108. }
  109. function resize(size) {
  110. if (chart) chart.resize(size)
  111. }
  112. function canvasToTempFilePath(opt = {}) {
  113. if (chart) {
  114. const src = chart.getDataURL(opt)
  115. postMessage({
  116. file: true,
  117. data: src
  118. })
  119. }
  120. }
  121. </script>
  122. </body>
  123. </html>