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