File size: 3,787 Bytes
64ed785
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c136aec
 
64ed785
 
 
 
 
840ae39
 
1202084
c136aec
 
840ae39
64ed785
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88bf077
 
c136aec
 
64ed785
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88bf077
 
 
 
 
 
dd2489b
 
 
 
 
 
64ed785
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function OnAddinLoad(ribbonUI){
    if (typeof (wps.ribbonUI) != "object"){wps.ribbonUI = ribbonUI}
    if (typeof (wps.Enum) != "object") {wps.Enum = WPS_Enum}
    wps.PluginStorage.setItem("EnableFlag", false) 
    return true
}

var WebNotifycount = 0;
function fx(n){
    var a=1,b=1;
    for(i=2;i<=n;i++){[a,b]=[b,a+b]};
    return a
}

function OnAction(control) {
    const eleId = control.Id
    switch (eleId) {
        case "btnShowMsg":
            {
                const doc = wps.EtApplication().ActiveWorkbook
                alert(`畅心提醒您当前打开的文件名为${doc.Name},当前时间:${Date()}`)
            }
            break;
        case "fbnq":
            {
                const doc = wps.EtApplication().ActiveSheet
                const x=wps.EtApplication().InputBox('请输入需要生成的项序号','测试','5',200,200)
                doc.Cells.Item(1, 1).Formula=fx(Number(x))
            }
            break;
        case "btnIsEnbable":
            {
                let bFlag = wps.PluginStorage.getItem("EnableFlag")
                wps.PluginStorage.setItem("EnableFlag", !bFlag)
                wps.ribbonUI.InvalidateControl("btnIsEnbable")
                wps.ribbonUI.InvalidateControl("btnShowcx") 
                wps.ribbonUI.InvalidateControl("btnShowcx2")
                wps.ribbonUI.InvalidateControl("btnShowcx3") 
                break
            }
        case "btnShowcx":
            wps.ShowDialog(GetUrlPath() + "/ui/cx.html", "调用网页对话框", 400 * window.devicePixelRatio, 400 * window.devicePixelRatio, false)
            break
        case "btnShowcx2":
            wps.ShowDialog(GetUrlPath() + "/ui/chartjs.html", "调用网页对话框", 400 * window.devicePixelRatio, 400 * window.devicePixelRatio, false)
            break
        case "btnShowcx3":
            wps.ShowDialog(GetUrlPath() + "/ui/chartjs2.html", "调用网页对话框", 400 * window.devicePixelRatio, 400 * window.devicePixelRatio, false)
            break
        default:
            break
    }
    return true
}

function GetImage(control) {
    const eleId = control.Id
    switch (eleId) {
        case "btnShowMsg":
            return "images/1.svg"
        case "fbnq":
            return "images/M.svg"
        case "btnShowcx":
            return "images/M.svg"
        case "btnShowcx2":
            return "images/M.svg"
        case "btnShowcx3":
            return "images/M.svg"    
        default:
            ;
    }
    return "images/newFromTemp.svg"
}

function OnGetEnabled(control) {
    const eleId = control.Id
    switch (eleId) {
        case "btnShowMsg":
            return true
            break
        case "fbnq":
            return true
            break
        case "btnShowcx":
            {
                let bFlag = wps.PluginStorage.getItem("EnableFlag")
                return bFlag
                break
            }
        case "btnShowcx2":
            {
                let bFlag = wps.PluginStorage.getItem("EnableFlag")
                return bFlag
                break
            }
        case "btnShowcx3":
            {
                let bFlag = wps.PluginStorage.getItem("EnableFlag")
                return bFlag
                break
            }
        default:
            break
    }
    return true
}

function OnGetVisible(control){
    return true
}

function OnGetLabel(control){
    const eleId = control.Id
    switch (eleId) {
        case "btnIsEnbable":
        {
            let bFlag = wps.PluginStorage.getItem("EnableFlag")
            return bFlag ?  "按钮不可用" : "按钮可用"
            break
        }  
    }
    return ""
}

function OnNewDocumentApiEvent(doc){
    alert("新建文件事件响应,取文件名: " + doc.Name)
}