nvue.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. export class Echarts {
  2. eventMap = new Map()
  3. constructor(webview) {
  4. this.webview = webview
  5. this.options = null
  6. }
  7. setOption() {
  8. this.options = arguments
  9. console.log('setOption1')
  10. this.webview.evalJs(`setOption(${JSON.stringify(arguments)})`);
  11. }
  12. getOption() {
  13. return this.options
  14. }
  15. showLoading() {
  16. this.webview.evalJs(`showLoading(${JSON.stringify(arguments)})`);
  17. }
  18. hideLoading() {
  19. this.webview.evalJs(`hideLoading()`);
  20. }
  21. clear() {
  22. this.webview.evalJs(`clear()`);
  23. }
  24. dispose() {
  25. this.webview.evalJs(`dispose()`);
  26. }
  27. resize(size) {
  28. if(size) {
  29. this.webview.evalJs(`resize(${JSON.stringify(size)})`);
  30. } else {
  31. this.webview.evalJs(`resize()`);
  32. }
  33. }
  34. on(type, ...args) {
  35. const query = args[0]
  36. const useQuery = query && typeof query != 'function'
  37. const param = useQuery ? [type, query] : [type]
  38. const key = `${type}${useQuery ? JSON.stringify(query): '' }`
  39. const callback = useQuery ? args[1]: args[0]
  40. if(typeof callback == 'function'){
  41. this.eventMap.set(key, callback)
  42. }
  43. this.webview.evalJs(`on(${JSON.stringify(param)})`);
  44. console.warn('nvue 暂不支持事件')
  45. }
  46. dispatchAction(type, options){
  47. const handler = this.eventMap.get(type)
  48. if(handler){
  49. handler(options)
  50. }
  51. }
  52. // 不让报错 无实际作用
  53. isDisposed() {
  54. return !!this.webview
  55. }
  56. }