first commit
This commit is contained in:
1 parent
5b00bd10d0
commit
d15e8185bb
14 files changed
+203
-371
No files matched your search
@@ -1,69 +0,0 @@
|
||||
function onbuttonclick(idStr)
|
||||
{
|
||||
switch(idStr)
|
||||
{
|
||||
case "getDocName":{
|
||||
let doc = window.Application.ActiveDocument
|
||||
let textValue = ""
|
||||
if (!doc){
|
||||
textValue = textValue + "当前没有打开任何文档"
|
||||
return
|
||||
}
|
||||
textValue = textValue + doc.Name
|
||||
document.getElementById("text_p").innerHTML = textValue
|
||||
break
|
||||
}
|
||||
case "createTaskPane":{
|
||||
let tsId = window.Application.PluginStorage.getItem("taskpane_id")
|
||||
if (!tsId){
|
||||
let tskpane = window.Application.CreateTaskPane(GetUrlPath() + "/taskpane.html")
|
||||
let id = tskpane.ID
|
||||
window.Application.PluginStorage.setItem("taskpane_id", id)
|
||||
tskpane.Visible = true
|
||||
}else{
|
||||
let tskpane = window.Application.GetTaskPane(tsId)
|
||||
tskpane.Visible = true
|
||||
}
|
||||
break
|
||||
}
|
||||
case "newDoc":{
|
||||
window.Application.Documents.Add()
|
||||
break
|
||||
}
|
||||
case "addString":{
|
||||
let doc = window.Application.ActiveDocument
|
||||
if (doc){
|
||||
doc.Range(0, 0).Text="Hello, wps加载项!"
|
||||
//好像是wps的bug, 这两句话触发wps重绘
|
||||
let rgSel = window.Application.Selection.Range
|
||||
if (rgSel)
|
||||
rgSel.Select()
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "closeDoc":{
|
||||
if (window.Application.Documents.Count < 2)
|
||||
{
|
||||
alert("当前只有一个文档,别关了。")
|
||||
break
|
||||
}
|
||||
|
||||
let doc = window.Application.ActiveDocument
|
||||
if (doc)
|
||||
doc.Close()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
var xmlReq = WpsInvoke.CreateXHR();
|
||||
var url = location.origin + "/.debugTemp/NotifyDemoUrl"
|
||||
xmlReq.open("GET", url);
|
||||
xmlReq.onload = function (res) {
|
||||
var node = document.getElementById("DemoSpan");
|
||||
node.innerText = res.target.responseText;
|
||||
};
|
||||
xmlReq.send();
|
||||
}
|
||||
+13
-85
@@ -1,10 +1,10 @@
|
||||
|
||||
//这个函数在整个wps加载项中是第一个执行的
|
||||
function OnAddinLoad(ribbonUI){
|
||||
if (typeof (window.Application.ribbonUI) != "object"){
|
||||
window.Application.ribbonUI = ribbonUI
|
||||
function OnAddinLoad(ribbonUI) {
|
||||
if (typeof (window.Application.ribbonUI) != "object") {
|
||||
window.Application.ribbonUI = ribbonUI
|
||||
}
|
||||
|
||||
|
||||
if (typeof (window.Application.Enum) != "object") { // 如果没有内置枚举值
|
||||
window.Application.Enum = WPS_Enum
|
||||
}
|
||||
@@ -15,6 +15,7 @@ function OnAddinLoad(ribbonUI){
|
||||
}
|
||||
|
||||
var WebNotifycount = 0;
|
||||
|
||||
function OnAction(control) {
|
||||
const eleId = control.Id
|
||||
switch (eleId) {
|
||||
@@ -28,57 +29,6 @@ function OnAction(control) {
|
||||
alert(doc.Name)
|
||||
}
|
||||
break;
|
||||
case "btnIsEnbable":
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("EnableFlag")
|
||||
window.Application.PluginStorage.setItem("EnableFlag", !bFlag)
|
||||
|
||||
//通知wps刷新以下几个按饰的状态
|
||||
window.Application.ribbonUI.InvalidateControl("btnIsEnbable")
|
||||
window.Application.ribbonUI.InvalidateControl("btnShowDialog")
|
||||
window.Application.ribbonUI.InvalidateControl("btnShowTaskPane")
|
||||
//window.Application.ribbonUI.Invalidate(); 这行代码打开则是刷新所有的按钮状态
|
||||
break
|
||||
}
|
||||
case "btnShowDialog":
|
||||
window.Application.ShowDialog(GetUrlPath() + "/ui/dialog.html", "这是一个对话框网页", 400 * window.devicePixelRatio, 400 * window.devicePixelRatio, false)
|
||||
break
|
||||
case "btnShowTaskPane":
|
||||
{
|
||||
let tsId = window.Application.PluginStorage.getItem("taskpane_id")
|
||||
if (!tsId) {
|
||||
let tskpane = window.Application.CreateTaskPane(GetUrlPath() + "/ui/taskpane.html")
|
||||
let id = tskpane.ID
|
||||
window.Application.PluginStorage.setItem("taskpane_id", id)
|
||||
tskpane.Visible = true
|
||||
} else {
|
||||
let tskpane = window.Application.GetTaskPane(tsId)
|
||||
tskpane.Visible = !tskpane.Visible
|
||||
}
|
||||
}
|
||||
break
|
||||
case "btnApiEvent":
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("ApiEventFlag")
|
||||
let bRegister = bFlag ? false : true
|
||||
window.Application.PluginStorage.setItem("ApiEventFlag", bRegister)
|
||||
if (bRegister){
|
||||
window.Application.ApiEvent.AddApiEventListener('DocumentNew', OnNewDocumentApiEvent)
|
||||
}
|
||||
else{
|
||||
window.Application.ApiEvent.RemoveApiEventListener('DocumentNew', OnNewDocumentApiEvent)
|
||||
}
|
||||
|
||||
window.Application.ribbonUI.InvalidateControl("btnApiEvent")
|
||||
}
|
||||
break
|
||||
case "btnWebNotify":
|
||||
{
|
||||
let currentTime = new Date()
|
||||
let timeStr = currentTime.getHours() + ':' + currentTime.getMinutes() + ":" + currentTime.getSeconds()
|
||||
window.Application.OAAssist.WebNotify("这行内容由wps加载项主动送达给业务系统,可以任意自定义, 比如时间值:" + timeStr + ",次数:" + (++WebNotifycount), true)
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
@@ -90,10 +40,6 @@ function GetImage(control) {
|
||||
switch (eleId) {
|
||||
case "btnShowMsg":
|
||||
return "images/1.svg"
|
||||
case "btnShowDialog":
|
||||
return "images/2.svg"
|
||||
case "btnShowTaskPane":
|
||||
return "images/3.svg"
|
||||
default:
|
||||
;
|
||||
}
|
||||
@@ -106,47 +52,29 @@ function OnGetEnabled(control) {
|
||||
case "btnShowMsg":
|
||||
return true
|
||||
break
|
||||
case "btnShowDialog":
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("EnableFlag")
|
||||
return bFlag
|
||||
break
|
||||
}
|
||||
case "btnShowTaskPane":
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("EnableFlag")
|
||||
return bFlag
|
||||
break
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function OnGetVisible(control){
|
||||
function OnGetVisible(control) {
|
||||
return true
|
||||
}
|
||||
|
||||
function OnGetLabel(control){
|
||||
function OnGetLabel(control) {
|
||||
const eleId = control.Id
|
||||
switch (eleId) {
|
||||
case "btnIsEnbable":
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("EnableFlag")
|
||||
return bFlag ? "按钮Disable" : "按钮Enable"
|
||||
break
|
||||
}
|
||||
case "btnApiEvent":
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("ApiEventFlag")
|
||||
return bFlag ? "清除新建文件事件" : "注册新建文件事件"
|
||||
break
|
||||
}
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("EnableFlag")
|
||||
return bFlag ? "按钮Disable" : "按钮Enable"
|
||||
break
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
function OnNewDocumentApiEvent(doc){
|
||||
function OnNewDocumentApiEvent(doc) {
|
||||
alert("新建文件事件响应,取文件名: " + doc.Name)
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
|
||||
function openOfficeFileFromSystemDemo(param){
|
||||
let jsonObj = (typeof(param)=='string' ? JSON.parse(param) : param)
|
||||
alert("从业务系统传过来的参数为:" + JSON.stringify(jsonObj))
|
||||
return {wps加载项项返回: jsonObj.filepath + ", 这个地址给的不正确"}
|
||||
}
|
||||
|
||||
function InvokeFromSystemDemo(param){
|
||||
let jsonObj = (typeof(param)=='string' ? JSON.parse(param) : param)
|
||||
let handleInfo = jsonObj.Index
|
||||
switch (handleInfo){
|
||||
case "getDocumentName":{
|
||||
let docName = ""
|
||||
if (window.Application.ActiveDocument){
|
||||
docName = window.Application.ActiveDocument.Name
|
||||
}
|
||||
|
||||
return {当前打开的文件名为:docName}
|
||||
}
|
||||
|
||||
case "newDocument":{
|
||||
let newDocName=""
|
||||
let doc = window.Application.Documents.Add()
|
||||
newDocName = doc.Name
|
||||
|
||||
return {操作结果:"新建文档成功,文档名为:" + newDocName}
|
||||
}
|
||||
|
||||
case "OpenFile":{
|
||||
let filePath = jsonObj.filepath
|
||||
window.Application.Documents.OpenFromUrl(filePath)
|
||||
return {操作结果:"打开文件成功"}
|
||||
}
|
||||
}
|
||||
|
||||
return {其它xxx:""}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
function onbuttonclick(idStr)
|
||||
{
|
||||
if (typeof (window.Application.Enum) != "object") { // 如果没有内置枚举值
|
||||
window.Application.Enum = WPS_Enum
|
||||
}
|
||||
switch(idStr)
|
||||
{
|
||||
case "dockLeft":{
|
||||
let tsId = window.Application.PluginStorage.getItem("taskpane_id")
|
||||
if (tsId){
|
||||
let tskpane = window.Application.GetTaskPane(tsId)
|
||||
tskpane.DockPosition = window.Application.Enum.msoCTPDockPositionLeft
|
||||
}
|
||||
break
|
||||
}
|
||||
case "dockRight":{
|
||||
let tsId = window.Application.PluginStorage.getItem("taskpane_id")
|
||||
if (tsId){
|
||||
let tskpane = window.Application.GetTaskPane(tsId)
|
||||
tskpane.DockPosition = window.Application.Enum.msoCTPDockPositionRight
|
||||
}
|
||||
break
|
||||
}
|
||||
case "hideTaskPane":{
|
||||
let tsId = window.Application.PluginStorage.getItem("taskpane_id")
|
||||
if (tsId){
|
||||
let tskpane = window.Application.GetTaskPane(tsId)
|
||||
tskpane.Visible = false
|
||||
}
|
||||
break
|
||||
}
|
||||
case "addString":{
|
||||
let doc = window.Application.ActiveDocument
|
||||
if (doc){
|
||||
doc.Range(0, 0).Text="Hello, wps加载项!"
|
||||
//好像是wps的bug, 这两句话触发wps重绘
|
||||
let rgSel = window.Application.Selection.Range
|
||||
if (rgSel)
|
||||
rgSel.Select()
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "getDocName":{
|
||||
let doc = window.Application.ActiveDocument
|
||||
let textValue = "";
|
||||
if (!doc){
|
||||
textValue = textValue + "当前没有打开任何文档"
|
||||
return
|
||||
}
|
||||
textValue = textValue + doc.Name
|
||||
document.getElementById("text_p").innerHTML = textValue
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
var xmlReq = WpsInvoke.CreateXHR();
|
||||
var url = location.origin + "/.debugTemp/NotifyDemoUrl"
|
||||
xmlReq.open("GET", url);
|
||||
xmlReq.onload = function (res) {
|
||||
var node = document.getElementById("DemoSpan");
|
||||
node.innerText = res.target.responseText;
|
||||
};
|
||||
xmlReq.send();
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
|
||||
|
||||
function InvokeFromXbot(param) {
|
||||
let jsonObj = (typeof (param) == 'string' ? JSON.parse(param) : param)
|
||||
let func = jsonObj.Func;
|
||||
let args = jsonObj.Args;
|
||||
args = JSON.parse(args);
|
||||
console.log(func);
|
||||
console.log(args);
|
||||
switch (func) {
|
||||
case "getDocumentName": {
|
||||
const doc = wps.WpsApplication().ActiveDocument;
|
||||
alert(doc.Name);
|
||||
if (!doc) {
|
||||
return { currentDoc: null }
|
||||
}
|
||||
return { currentDoc: doc.Name }
|
||||
}
|
||||
|
||||
case "evalCode": {
|
||||
// 1. 注入 WPS 对象
|
||||
// 2. 执行函数, 获取返回值
|
||||
let code = args?.code;
|
||||
console.log("start eval code");
|
||||
console.log(code);
|
||||
// var result = eval(code);
|
||||
// const tmpCode = `return ${code}`; // 为了获取返回值,需要在代码前面加上 return
|
||||
const result = new Function(code)(); // 执行并获取返回值
|
||||
console.log(result);
|
||||
console.log("success eval code");
|
||||
return { message: "ok", data: result }
|
||||
}
|
||||
}
|
||||
|
||||
return { message: "ok" }
|
||||
}
|
||||
Reference in new issue
Block a user