File size: 2,787 Bytes
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
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") 
                break
            }
        case "btnShowcx":
            wps.ShowDialog(GetUrlPath() + "/ui/cx.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"
        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
            }
        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)
}