nvue.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. this.webview.evalJs(`setOption(${JSON.stringify(arguments)})`);
  10. }
  11. getOption() {
  12. return this.options
  13. }
  14. showLoading() {
  15. this.webview.evalJs(`showLoading(${JSON.stringify(arguments)})`);
  16. }
  17. hideLoading() {
  18. this.webview.evalJs(`hideLoading()`);
  19. }
  20. clear() {
  21. this.webview.evalJs(`clear()`);
  22. }
  23. dispose() {
  24. this.webview.evalJs(`dispose()`);
  25. }
  26. resize(size) {
  27. if(size) {
  28. this.webview.evalJs(`resize(${JSON.stringify(size)})`);
  29. } else {
  30. this.webview.evalJs(`resize()`);
  31. }
  32. }
  33. on(type, ...args) {
  34. const query = args[0]
  35. const useQuery = query && typeof query != 'function'
  36. const param = useQuery ? [type, query] : [type]
  37. const key = `${type}${useQuery ? JSON.stringify(query): '' }`
  38. const callback = useQuery ? args[1]: args[0]
  39. if(typeof callback == 'function'){
  40. this.eventMap.set(key, callback)
  41. }
  42. this.webview.evalJs(`on(${JSON.stringify(param)})`);
  43. console.warn('nvue 暂不支持事件')
  44. }
  45. dispatchAction(type, options){
  46. const handler = this.eventMap.get(type)
  47. if(handler){
  48. handler(options)
  49. }
  50. }
  51. }