uvue.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. overflow: hidden;
  13. /* 隐藏滚动条 */
  14. overscroll-behavior: none;
  15. /* 禁止橡皮筋效果 */
  16. }
  17. html,
  18. body,
  19. .canvas {
  20. padding: 0;
  21. margin: 0;
  22. overflow-y: hidden;
  23. background-color: transparent;
  24. width: 100%;
  25. height: 100%;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <div class="canvas" id="limeChart"></div>
  31. <script type="text/javascript" src="./uni.webview.1.5.5.js"></script>
  32. <script type="text/javascript" src="./echarts.min.js"></script>
  33. <script type="text/javascript" src="./ecStat.min.js"></script>
  34. <!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts-liquidfill@latest/dist/echarts-liquidfill.min.js"></script> -->
  35. <script>
  36. let chart = null;
  37. let cache = [];
  38. console.log = function() {
  39. emit('log', {
  40. log: arguments,
  41. })
  42. }
  43. function emit(event, data) {
  44. postMessage({
  45. event,
  46. data
  47. })
  48. cache = []
  49. }
  50. function postMessage(data) {
  51. uni.webView.postMessage({
  52. data
  53. })
  54. // window.__uniapp_x_.postMessage(JSON.stringify(data))
  55. };
  56. function stringify(key, value) {
  57. if (typeof value === 'object' && value !== null) {
  58. if (cache.indexOf(value) !== -1) {
  59. return;
  60. }
  61. cache.push(value);
  62. }
  63. return value;
  64. }
  65. function parse(name, callback, options) {
  66. const optionNameReg = /[\w]+\.setOption\(([\w]+\.)?([\w]+)\)/
  67. if (optionNameReg.test(callback)) {
  68. const optionNames = callback.match(optionNameReg)
  69. if (optionNames[1]) {
  70. const _this = optionNames[1].split('.')[0]
  71. window[_this] = {}
  72. window[_this][optionNames[2]] = options
  73. return optionNames[2]
  74. } else {
  75. return null
  76. }
  77. }
  78. return null
  79. }
  80. function init(callback, options, opts, theme) {
  81. if (!chart) {
  82. chart = echarts.init(document.getElementById('limeChart'), theme, opts)
  83. if (options) {
  84. chart.setOption(options)
  85. }
  86. }
  87. }
  88. function on(data) {
  89. if (chart && data.length > 0) {
  90. const [type, query] = data
  91. const key = `${type}${JSON.stringify(query||'')}`
  92. if (query) {
  93. chart.on(type, query, function(options) {
  94. var obj = {};
  95. Object.keys(options).forEach(function(key) {
  96. if (key != 'event') {
  97. obj[key] = options[key];
  98. }
  99. });
  100. emit(key, {
  101. event: key,
  102. options: obj,
  103. });
  104. });
  105. } else {
  106. chart.on(type, function(options) {
  107. var obj = {};
  108. Object.keys(options).forEach(function(key) {
  109. if (key != 'event') {
  110. obj[key] = options[key];
  111. }
  112. });
  113. emit(key, {
  114. event: key,
  115. options: obj,
  116. });
  117. });
  118. }
  119. }
  120. }
  121. function setChart(callback, options) {
  122. if (!callback) return
  123. if (chart && callback && options) {
  124. var r = null
  125. const name = parse('r', callback, options)
  126. if (name) this[name] = options
  127. eval(`r = ${callback};`)
  128. if (r) {
  129. r(chart)
  130. }
  131. }
  132. }
  133. function setOption(data) {
  134. if (chart) chart.setOption(data[0], data[1])
  135. }
  136. function showLoading(data) {
  137. if (chart) chart.showLoading(data[0], data[1])
  138. }
  139. function hideLoading() {
  140. if (chart) chart.hideLoading()
  141. }
  142. function clear() {
  143. if (chart) chart.clear()
  144. }
  145. function dispose() {
  146. if (chart) chart.dispose()
  147. }
  148. function resize(size) {
  149. if (chart) chart.resize(size)
  150. }
  151. function canvasToTempFilePath(opt) {
  152. if (chart) {
  153. delete opt.success
  154. const src = chart.getDataURL(opt)
  155. postMessage({
  156. // event: 'file',
  157. file: src
  158. })
  159. }
  160. }
  161. document.addEventListener('touchmove', () => {
  162. })
  163. </script>
  164. </body>
  165. </html>