vue3+webOffice合集

1、webOffice 初始化

1)officeType:

文档位置:https://solution.wps.cn/docs/web/quick-start.html#officetype

2)appId: 前端使用appId 后端需要用到AppSecret

3)fileId: 由后端返回,前端无法生成 ,与上传文件生成的文件id无关

4)mount: 前端挂载的div

5)mode: 显示模式,nomal为普通模式,simple为极简模式

文档位置:https://solution.wps.cn/docs/web/config.html#显示模式

6)wordOptions: 其他配置

文档位置:https://solution.wps.cn/docs/web/config.html#文字选项

javascript 复制代码
//注意:这里一定要设置宽高,否则不会显示
 <div id='wps' ref='wpsRef' style="width:600px;height:500px"></div>
 	
 const init = async ()=>{
 	const ele = document.getElementById('wps') 
    const instance = await webOfficeSDK.init({
      officeType: 'w', 
      appId: 'xxxx',  
      fileId: '2',
      mount: ele,
      mode: 'simple',
      wordOptions: {
        isShowDocMap: false,  //是否开启目录功能
        isBestScale: true  //打开文档默认以最佳比例显示
      } 
    })
    //注意:一定要等到ready完才做其他的操作 不然会出现模块未定义或找不到
    const ready = await this.instance.ready()
    if(ready){
      ...
      return ture
     }
     return false
   }


//初始化
onMounted(async()=>{
	const res = await init()
	if(res){
		// 其他操作 例如 请求接口数据回显到下拉组件
	}
})

2、修改wps的宽度样式

1)需求描述:与官方案例类似 ,但是需要添加一个收缩/展示按钮,当右侧表单收缩时,左侧的文档宽度应为100%,当右侧表单展示时,左侧文档恢复原样

2)实现思路

  • 左侧div设置固定的宽度和高度,例如80%,且div里面放挂载wps的div,右侧表单设置固定宽度和高度,例如20%,根据按钮的显示隐藏动态设置其宽度
javascript 复制代码
<div :style="flg?'width:80%':'width:100%'">
	<div id='wps' style="width:100%;height:100%"></div>
</div>
<div :style="flg?'width:20%':'width:0%'">
	<div id='wps'></div>
</div>

注意:按钮控件可以控制外层div的宽度动态变化,无法控制wps的宽度变化,需要使用到实例对象值的iframe对象

文档位置:https://solution.wps.cn/docs/web/instance.html

  • 设置iframe
javascript 复制代码
//上面初始化时有个ready状态
const iframe = ref(null)
 
if(ready){
 iframe = await instance.iframe
 return ture
}
//当按钮点击时(不管是收缩还是展开都设置为100%且文档自适应)
iframe.style.width = "100%"
//app 也是在ready后面获取 可参考官方文档
app.ActiveDocument.ActiveWindow.View.Zoom.Percentage = 100 //设置窗口缩放比例
app.ActiveDocument.ActiveWindow.View.Zoom.PageFit = 2  //缩放视图自适应文档窗口的尺寸
相关推荐
易朵朵11 小时前
CSS 格式化上下文
css·vue.js
雪芽蓝域zzs12 小时前
第6节:远程搜索弹窗(remote 模式),弹窗滚动加载分页
vue.js·elementui
Highcharts.js13 小时前
图表开发实战总结| 7 条“黄金法则”与“性能铁律”
前端·javascript·vue.js·编辑器·时序数据库·highcharts
Wx-bishekaifayuan16 小时前
springboot陨石鉴收系统96265-计算机课程设计、毕业设计
java·vue.js·spring boot·后端·python·spring·课程设计
FYKJ_201016 小时前
springboot家政服务平台66766-计算机课程设计、毕业设计
java·vue.js·spring boot·后端·mysql·spark·课程设计
墨鱼老师17 小时前
Go+Gin+Vue 毕设项目:Gin 框架搭建后端基础接口实战
vue.js·golang·go·gin·前后端分离·计算机毕业设计·go 后端
ym hyd 1111 天前
试题库管理系统源码 Java+SpringBoot+Vue3 前后分离
java·vue.js·spring boot·毕设
雪芽蓝域zzs1 天前
第4节:el-select 弹窗事件控制(打开 / 关闭、选中事件、弹窗滚动事件)
vue.js·elementui
web打印社区2 天前
HTML5 静默打印:前端页面怎么调用打印机且尽量不弹窗
前端·javascript·vue.js·pdf·html·html5
雪芽蓝域zzs2 天前
第3节:el-select 弹窗定位、滚动穿透与挂载容器(popper-append-to-body /teleported)
vue.js·elementui