/*! ***************************************************************************** Copyright @ 2012-2019, Kingsoft office,All rights reserved. Redistribution and use in source and binary forms ,without modification and selling solely, are permitted provided that the following conditions are met: 1.Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2.Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3.Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. SPECIAL NOTE:THIS SOFTWARE IS NOT PERMITTED TO BE MODIFIED OR SOLD SOLELY AT ANY TIME AND UNDER ANY CIRCUMSTANCES, EXCEPT WITH THE WRITTEN PERMISSION OF KINGSOFT OFFICE THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************************************************************************** */ /// /// type WPSMergedRoot = WPS.AddonRoot & WPS.WppAddonRoot & Wpp.Application; /** * 推荐使用此方式:获取当前应用程序的Application对象 */ declare const Application: WPSMergedRoot; declare const wps: WPSMergedRoot; interface Window { readonly Application: WPSMergedRoot; readonly wps: WPSMergedRoot; } declare function confirm(text: string, showWpsCustomDialog?: boolean): 1 | 0; declare namespace WPS { interface AddonRoot { /** * @deprecated 已废弃,请使用全局Application对象 */ WppApplication: Wpp.Application; /** * 用于对ribbon界面进行更新 * @param id */ UpdateRibbon(id?: number): void; /** * 弹出对话框 * @param url html文件的路径 * @param title 对话框标题 * @param width 对话框宽度 * @param height 对话框高度 * @param isModal 是否模态 */ ShowDialog(url: string, title?: string, width?: number, height?: number, isModal?: boolean): void; /** * 创建一个taskpane对象 * 创建完这个taskpane后,需要将Visible属性置为true, 即可显示出来 * @param url 需要加载的网页的url * @param title 任务窗格的标题,此参数可选 */ CreateTaskPane(url: string, title?: string): CustomTaskpane; /** * 根据taskpane的ID来取到之前创建的taskpane * @param id id */ GetTaskPane(id: number): CustomTaskpane; /** * 此函数已废弃,不要再使用 * @param funcname 方法名称 * * @deprecated This function is deprecated. */ ExecFunc(funcname: string): void; /** 此函数已废弃,不要再使用 * @param id * * @deprecated This function is deprecated. */ UpdateRibbon(id?: number): void; readonly ShowDevTools: boolean; /** * 返回一个 Env 对象,该对象代表获取系统环境相关的操作对象。 */ Env: Env; /** * 返回一个FileSystem对象,该对象包含了对文件和文件夹的常见操作。 */ FileSystem: FileSystem; OAAssist: OAAssist; /** * 返回一个PluginStorage对象,该对象与LocalStorage的用法类似,但该对象的数据不会被持久化,在wps的jsapi插件中,该对象在一个插件中对应着同一个实例,因此该对象可以在一个jsapi插件的不同网页间共享数据。 */ readonly PluginStorage: PluginStorage; readonly TabPages: TabPages; readonly WPSCloudService: WPSCloudService; readonly ribbonUI: RibbonUi; readonly ThisBrowser: WebBrowser; readonly BrowserGroup: WebGroup; Enum: Record; } interface RibbonUi { /** * 将自定义功能区的数据缓存置为无效,WPS 应用程序会在下一次显示时再次获取更新 */ Invalidate(): void; /** * 指定更新一个控件,参数是控件Id */ InvalidateControl(ControlID: string): void; /** * 指定更新一个内置控件,参数是内置控件Id */ InvalidateControlMso(ControlID: string): void; /** * 使 WPS 应用程序激活显示当前自定义功能区。 */ ActivateTab(ControlID: string): void; /** * 激活内置的功能区,参数为指定的功能区名称。 */ ActivateTabMso(ControlID: string): void; /** * 激活自定义功能区,参数为自定义功能区名称及命名控件 */ ActivateTabQ(ControlID: string, Namespace: string): void; ExpandOrCollapseRibbon(state: boolean): void; SetEnabledCloudSync(enable: boolean): boolean; } /** * ApiEvent对象提供Office事件回调相关的服务 */ interface ApiEvent { /** * 如果事件是询问型事件,用这个属性来控制对wps的应答 */ Cancel: boolean; RightsInfo: number; } interface CustomTaskpane { /** * 删除一个创建好的TaskPane */ Delete(): void; /** * TaskPane 对象的固定位置 */ DockPosition: Kso.MsoCTPDockPosition; Height: number; ID: number; Visible: boolean; /** * 让TaskPane显示URL对应的网页内容 * @param url url */ Navigate(url: string): void; Width: number; MaxWidth: number; MinWidth: number; MaxHeight: number; MinHeight: number; } interface Env { /** * 获取本机%TEMP%目录路径 */ GetTempPath(): string; /** * 取系统DPI */ GetDesktopDpi(): number; /** * 获取本机根目录路径 */ GetRootPath(): string; /** * 获取本机用户home目录路径 */ GetHomePath(): string; /** * 获取本机%APPDATA%目录路径 */ GetAppDataPath(): string; /** * 获取本机%ProgramFiles%目录路径 */ GetProgramFilesPath(): string; /** * 获取本机%ALLUSERSPROFILE%目录路径 */ GetProgramDataPath(): string; /** * 获取用户的桌面目录路径 */ GetDesktopPath(): string; /** * 获取用户的下载目录路径 */ GetDownloadPath(): string; } /** * FileSystem */ interface FileSystem { /** * 往文件末尾添加数据 */ AppendFile(path: string, data: string): boolean; /** * 判断文件是否存在 */ Exists(path: string): boolean; /** * 创建文件夹 * @param path path */ Mkdir(path: string): void; /** * 读取文件 * @param path path */ ReadFile(path: string): string; /** * 删除文件 * @param path path */ Remove(path: string): void; WriteFile(path: string, data: string): boolean; ReadFileAsArrayBuffer(path: string): ArrayBuffer; readFileString(path: string): string; writeFileString(path: string, data: string): boolean; readAsBinaryString(path: string): string; writeAsBinaryString(path: string, data: string): boolean; /** * 复制文件 * @param flags libuv 库的uv_fs_copyfile函数的flag参数 */ copyFileSync(src: string, dest: string, flags?: number): boolean; unlinkSync(path: string): boolean; existsSync(path: string): boolean; mkdtempSync(name: string): string; /** * 创建一个目录 * @param path 目录路径 * @param mode 目录权限, linux权限数字格式,默认0777 */ mkdirSync(path: string, mode?: number): boolean; rmdirSync(path: string): boolean; readdirSync(path: string): string[]; tmpdir(): string; stat(path: string): FileStat; constants: FsConstants; /** * 文件绝对路径 */ absoluteFilePath(path: string): string; /** * 文件所在目录路径 */ absolutePath(path: string): string; isWritable(path: string): boolean; toNativeSeparators(path: string): string; } interface FsConstants { readonly COPYFILE_EXCL: number readonly COPYFILE_FICLONE: number readonly COPYFILE_FICLONE_FORCE: number readonly F_OK: number readonly R_OK: number readonly W_OK: number readonly X_OK: number } interface FileStat { readonly dev: number; readonly ino: number; readonly mode: number; readonly nlink: number; readonly uid: number; readonly gid: number; readonly rdev: number; readonly size: number; readonly blksize: number; readonly blocks: number; readonly atimeMs: number; readonly mtimeMs: number; readonly ctimeMs: number; readonly atime: number; readonly mtime: number; readonly ctime: number; readonly birthtime: number; isBlockDevice(): boolean; isCharacterDevice(): boolean; isDirectory(): boolean; isFIFO(): boolean; isFile(): boolean; isSocket(): boolean; isSymbolicLink(): boolean; } /** * OAAsist对象是为OA助手扩展的js对象 */ interface OAAssist { /** * 从远程下载一个文件到本地 * 第一个参数为下载地址 * 第二、第三个参数可选,分别为下载成功和失败的回调函数名称 * 没有指定时同步调用,并返回下载到本地的文件绝对路径,失败返回空 * 指定后异步下载,下载完成后调用回调函数,传入封装返回值的JSON数据 * @param url url */ DownloadFile(url: string): string; DownloadFile(url: string, onSuccess?: Function, onFail?: Function): void; /** * 上传一个文件到远程服务器 * @param name 上传后的文件名称 * @param path 文件绝对路径 * @param url 上传地址 * @param field 请求中name的值 * @param onSuccess 下载成功的回调函数 * @param onFail 下载失败的回调函数 */ UploadFile(name: string, path: string, url: string, field: string, onSuccess: Function, onFail: Function): void; /** * 执行一个本地程序,或者从浏览器打开一个网页等,类似于winapi的ShellExecute函数的功能 * @param file 文件名称 * @param params 执行参数 */ ShellExecute(file: string, params?: string): void; /** * 向业务系统发送消息 * @param msgText 消息的内容 * @param bForce 当业务系统关闭后,消息是否会被缓存,被缓存的消息一定会被送达,等业务系统下次启动时会接收缓存的消息 */ WebNotify(msgText: string, bForce?: boolean): void; /** * 根据给定的程序标识符从注册表找出对应的类标识符,再创建对应类的实例。 */ CoCreateInstance(progID: string): object | undefined; } /** * PluginStorage对象 * 每个wps加载项都有一个不同网页间共享的PluginStorage对象 * 通过该对象可以在同一个插件的不同网页间来传递数据 * 例如可以在对话框的网页中存入一个数据,然后在TaskPane所在的网页中取到这个数据 */ interface PluginStorage { /** * 往容器中存入一个数据 * @param key key * @param value value */ setItem(key: string, value: number | boolean | string): void; /** * 根据指定的key得到对应的value * @param key key */ getItem(key: string): string; /** * 删除key对应的value * @param key key */ removeItem(key: string): void; /** * 清除所有的数据 */ clear(): void; /** * 返回第idx个位置对应的key * @param idx idx */ key(idx: number): string; /** * 容器中的数据条数 */ readonly length: number; } /** * TabPages */ interface TabPages { /** * 增加一个url页面的TabPage * @param url url */ Add(url: string): TabPage; /** * 获取第id个TabPage * @param id id */ Item(id: number): TabPage; /** * TabPage的总数 */ readonly Count: number; /** * 跳转到新的文档Tab页 */ GotoNewDocTab(): number; } interface TabPage { /** * 更新TabPage的页面,参数为新页面的url * @param url url */ Navigate(url: string): void; /** * 关闭TabPage的页面 */ Close(): void; } interface WPSCloudService { /** * 调用wps云服务登录 */ Login(): void; /** * 调用wps云服务登出 */ Logout(): void; /** * 获取wps云服务用户信息 */ readonly UserInfo: string; } /** * 表示浏览器对象 */ interface WebBrowser { /** * 获取浏览器的url。 */ readonly Url: string; /** * 获取浏览器的子浏览器个数。 */ readonly Count: number; /** * 获取浏览器的父级浏览器。 */ Parent: WebBrowser | null; /** * 返回或设置浏览器的名字。 */ Name: string; /** * 获取浏览器所属的浏览器组。 */ readonly Group: WebGroup; /** * 设置或返回浏览器是否能打开弹窗网页。 */ AllowPopup: boolean; /** * 根据索引从浏览器中获取对应的子浏览器,索引从1开始。 */ Item(index: number): WebBrowser | null; /** * 打开浏览器的调试器。 */ ShowDevTools(): void; /** * 在浏览器执行js语句。 */ ExecFunc(jscode: string): void; } /** * 浏览器组对象。 */ interface WebGroup { /** * 获取该浏览器组下的浏览器的个数。 */ readonly Count: number; /** * 获取该浏览器组的名字。 */ readonly Name: string; /** * 根据索引从浏览器组对象中获取对应的浏览器,索引从1开始。 */ Item(index: number): WebBrowser | null; /** * 根据浏览器名字从浏览器组对象中获取对应的浏览器。 */ GetBrowserByName(name: string): WebBrowser | null; } /** * 所有浏览器组的集合对象。 */ interface WebGroups { /** * 获取浏览器组的个数。 */ Count: number; /** * 根据索引从浏览器组集合对象中获取对应的浏览器组,索引从1开始。 */ Item(index: number): WebGroup | null; } }