vue项目在浏览器嵌入wps进行操作,这里记录两种方式,本地载入这个能匹配内网使用

先整几个参考文档:
wps开放平台
开发文档:
https://www.kdocs.cn/l/cmd0fQ9SjcsS
https://www.kdocs.cn/l/cvItn7DFoX99
https://www.kdocs.cn/l/cqVyOOjyWmm8

效果图:copy了个网上的效果图,本地项目的wps做的Linux国产化系统适配,打不开
在这里插入图片描述
目前项目是中途需要使用wps相关功能,只能人工给他载进去,下面先说官网介绍的vue使用方式。

如果是vue项目需要使用wps,建议在项目脚手架阶段就通过wps加载项的方式导入项目,这样比较方便开发,少写很多js。
准备开发环境:wps、Node.js
具体步骤:

//通过npm全局安装wpsjs开发工具包
npm install -g wpsjs
//更新wpsjs的命令
npm update -g wpsjs
//新建一个wps加载项
wpsjs create project
//调试命令
wpsjs debug

选择UI框架的时候,选择Vue就好,"Vue"代表生成的示例代码集成了Vue相关的脚手架,实际开发的时候更适合工程化开发,
视图

我本地单独载入的方式
示例

<script type="text/javascript" src="wps_general.js"></script>

这里js源码文件不知道怎么load进来,copy了一份在下面(中文编码有问题,但是不影响使用)

/** 
 * @file common.js
 * @desc WPSһЩͨ�õķ���������ƽ̨ͨ��
 * @author wps-developer
 */

/**
 * @desc WPS���ú�����Ĺ��캯��
 */
function WPSFrame() {
   
	this.elementObj = null;
	// ������󣬰���һЩ��װ�ķ������Լ����ӹ��ı�׼�ӿ�
	this.pluginObj = null;
	// WPS��Application���󣬵���WPS�ڲ�API��ڵ㣬��MicroSoft Office APIͨ��
	this.Application = null;
	// �������Ϣ
	this.browserInfo = getBrowserInfo();
}

WPSFrame.prototype = {
   
	constructor: WPSFrame,
	/**
	 * @desc ��ȡ���Ԫ�ض���
	 * @param { String } tagID ���������divԪ��id
	 * @returns objectԪ�ض��󣬼�WPS�������
	 */
	getElementObj: function (tagID) {
   
		var iframe;
		var codes = [];

		iframe = document.getElementById(tagID);
		if (isWindowsPlatform()) {
   
			codes.push('<object height="100%" width="100%" ');
			codes.push('classid=clsid:8E7DA7EC-07EC-4343-8141-88A2ADB63A5F></object> ');
			iframe.innerHTML = codes.join("");
			this.elementObj = iframe.children[0];
		} else {
   
			if (iframe.innerHTML.indexOf("application/x-wps") > -1) {
   
				iframe.innerHTML = "";
			}
			codes.push("<object type='application/x-wps'  width='100%'  height='100%'></object>");
			iframe.innerHTML = codes.join("");
			this.elementObj = iframe.children[0];
			window.onbeforeunload = function () {
   
				this.elementObj.Application.Quit();
			};
		}

		return this.elementObj;
	},

	/**
	 * @param { String } id ���������divԪ��id
	 * @param { Function } callback ��ʼ�����֮��Ļص�����
	 * @desc ��ʼ��WPS������ʼ����������WPS��Application����
	 */
	initPlugin: function (id, callback) {
   
		this.pluginObj = this.getElementObj(id);
		if (!isWindowsPlatform()) {
   
			if (undefined != this.browserInfo.chrome) {
   
				this.pluginObj = this.elementObj.Application;
				if (null == this.pluginObj) {
   
					this.elementObj.setAttribute('data', '../../../file/Normal.dotm');
					var Interval_control = setInterval(
						function () {
   
							this.pluginObj = this.elementObj.Application;
							if (this.pluginObj && this.pluginObj.IsLoad()) {
   
								clearInterval(Interval_control);
								this.Application = this.pluginObj;
								
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值