验证中...
开源中国 2018 年度最后一场技术盛会邀你来约~错过就要等明年啦!点此立即预约
Snippet 1 Snippet 2 Snippet 3
前台oa-demo代码FillDoc.vue
Raw Copy
<template>
<common-demo :title="title" :button-content="buttonContent" :left-content="left" :right-content="right" @button-click="fillTemplate">
<div slot="funcDemo" class="demonstration">
<h2>
{{title}}
</h2>
<Row style="padding-top: 20px;">
<i-col span="5" offset="1">
<p style=" padding-top: 5px">请获取文档:</p>
</i-col>
<i-col span="16" offset="1">
<Input v-model="docmodel" placeholder="获取文档数据接口"></Input>
</i-col>
</Row>
<Row style="padding-top: 20px;">
<i-col span="5" offset="1">
<p style=" padding-top: 5px">请选择模板:</p>
</i-col>
<i-col span="16" offset="1">
<i-select v-model="formItem3.select" placeholder="选择模板">
<Option v-for="(item,key) in templates" :value="item.tempId">{{item.tempName}}</Option>
</i-select>
</i-col>
</Row>
<Row style="padding-top: 20px;">
<i-col span="24">
<Button type="success" class="start-button" @click="fillTemplate">{{buttonContent}}</Button>
</i-col>
</Row>
</div>
</common-demo>
</template>
<script>
import codeDetail from "../../docs/填充模板.md";
import funcDetail from "../../docs/填充模板text.md";
import CommonDemo from "./common/CommonDemo";
export default {
name: "NewDoc",
components: {
CommonDemo
},
data() {
return {
title: "填充模板",
buttonContent: "填充模板",
right: codeDetail,
left: funcDetail,
doc: {},
docs: {},
openType: "",
templates: {},
formItem3: {},
docmodel: ""
};
},
methods: {
uploadSuccess: function(response, file, fileList) {
this.$Message.info("上传成功");
},
getAllTemplate() {
var _this = this;
this.$ajax
.get("/template/paging")
.then(res => {
_this.templates = res.data;
})
.catch(res => {
console.log(res);
});
},
getDoc() {
var _this = this;
this.$ajax
.post("/document/getOriginDoc")
.then(res => {
console.log(res);
_this.docs = res.data;
_this.docmodel = JSON.stringify(_this.docs);
})
.catch(res => {
console.log(res);
});
},
fillTemplate() {
var templateId = null;
var _this = this;
templateId = _this.formItem3.select;
var URL = "http://localhost:8080/";
var startData = {
name: "oaassist",
function: "UseTemplate2",
info: {
templateURL: URL + "template/getFileData/" + templateId, //访问服务器模板接口
filename: URL + "document/getOriginDoc/", //获取服务器文档接口
uploadPath: URL + "document/upload/" //保存文档接口
}
};
var data = JSON.stringify(startData);
var result = new Buffer(data).toString("base64");
window.location.href = "ksowebstartupwps://" + result;
}
},
mounted() {
this.getAllTemplate();
this.getDoc();
}
};
</script>
<style scoped>
.demonstration {
height: 230px;
border-bottom: 2px dotted rgba(132, 163, 230, 0.322);
text-align: center;
}
.start-button {
margin-top: 0px;
/* height: 20px;
width: 30px; */
font-size: 25px;
}
</style>
插件中的JS代码
Raw Copy
//电子十五所项目填充模板接口(动态获取模板并上传)
function UseTemplate2(info) {
//获取模板
var templatePath = window.OAAssist.DownloadFile(info.templateURL);
var template = window.WpsApplication().Documents.Open(templatePath);
//获取文档内容
var filename = info.filename;
$.ajax({
url: filename,
async: false,
method: "post",
dataType: 'json',
success: function (res) {
var data = res;
data.forEach(function (it) {
var bookmark = template.Bookmarks.Item(it.name);
if (it.type === "text") {
bookmark.Range.Select();
bookmark.Range.Text = it.text;
} else if (it.type === "link") {
bookmark.Range.Select();
bookmark.Range.Text = "";
bookmark.Range.InsertFile(it.text)
} else if (it.type === "pic") {
bookmark.Range.Select();
bookmark.Range.Text = "";
bookmark.Range.InsertFile(it.text)
}
}
)
}
});
//保存上传路径
var uploadPath = template.CustomDocumentProperties.Item("uploadPath");
if (uploadPath) {
uploadPath.Delete();
}
template.CustomDocumentProperties.Add("uploadPath", info.uploadPath);
if (template) {
alert(template.FullName.split(".")[0])
window.oaFiles.push(template.FullName.split(".")[0]);
}
window.ApiEvent.AddApiEventListener("DocumentBeforeSave", OnDocumentBeforeSave);
}
后台获取文件数据接口
Raw Copy
@RequestMapping("/getOriginDoc")
public String getOriginDoc() throws Exception {
List<Map<String, String>> list = new ArrayList<Map<String,String>>();
Map<String,String> map1 = new HashMap<String,String>();
map1.put("name", "FirstTitle");
map1.put("text", "秘");
map1.put("type","text");
list.add(map1);
Map<String,String> map2 = new HashMap<String,String>();
map2.put("name", "TopTitle1");
map2.put("text", "军参谋");
map2.put("type","link");
list.add(map2);
Map<String,String> map3 = new HashMap<String,String>();
map3.put("name", "TopTitle2");
map3.put("text", "通信");
map3.put("type","text");
list.add(map3);
Map<String,String> map4 = new HashMap<String,String>();
map4.put("name", "ContentTitle");
map4.put("text", "空军内部使用办文助手");
map4.put("type","text");
list.add(map4);
Map<String,String> map5 = new HashMap<String,String>();
map5.put("name", "Company");
map5.put("text", "空军参谋部");
map5.put("type","text");
list.add(map5);
Map<String,String> map6 = new HashMap<String,String>();
map6.put("name", "Contactor");
map6.put("text", "李四");
map6.put("type","text");
list.add(map6);
Map<String,String> map7 = new HashMap<String,String>();
map7.put("name", "Telephone");
map7.put("text", "26874");
map7.put("type","text");
list.add(map7);
//return JSONObject.toJSONString(list,SerializerFeature.DisableCircularReferenceDetect);
return JSONObject.toJSONString(list);
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search

12_float_left_people 12_float_left_close