月夕花晨 7 месяцев назад
Родитель
Сommit
54f93f470c
100 измененных файлов: 6292 добавлений и 0 удалений
  1. +326
    -0
      test/oaassist/wps/LICENSE
  2. +82
    -0
      test/oaassist/wps/QRCode.html
  3. +27
    -0
      test/oaassist/wps/README.md
  4. +19
    -0
      test/oaassist/wps/icon/3.svg
  5. Двоичные данные
      test/oaassist/wps/icon/c_bookmark.png
  6. Двоичные данные
      test/oaassist/wps/icon/c_default.png
  7. Двоичные данные
      test/oaassist/wps/icon/c_printDoc.png
  8. Двоичные данные
      test/oaassist/wps/icon/c_seal.png
  9. +22
    -0
      test/oaassist/wps/icon/newFromTemp.svg
  10. Двоичные данные
      test/oaassist/wps/icon/w_AcceptRev.png
  11. Двоичные данные
      test/oaassist/wps/icon/w_BackDoc.png
  12. Двоичные данные
      test/oaassist/wps/icon/w_CloseRev.png
  13. Двоичные данные
      test/oaassist/wps/icon/w_CloseRev1 (2).png
  14. Двоичные данные
      test/oaassist/wps/icon/w_CloseRev3.png
  15. Двоичные данные
      test/oaassist/wps/icon/w_DeleteRev.png
  16. Двоичные данные
      test/oaassist/wps/icon/w_DocClear.png
  17. Двоичные данные
      test/oaassist/wps/icon/w_DocClound.png
  18. Двоичные данные
      test/oaassist/wps/icon/w_DocOFD.png
  19. Двоичные данные
      test/oaassist/wps/icon/w_DocQr.png
  20. Двоичные данные
      test/oaassist/wps/icon/w_DocQr1.png
  21. Двоичные данные
      test/oaassist/wps/icon/w_DocRevis.png
  22. Двоичные данные
      test/oaassist/wps/icon/w_DocUOF.png
  23. Двоичные данные
      test/oaassist/wps/icon/w_GovDoc.png
  24. Двоичные данные
      test/oaassist/wps/icon/w_ImportDoc.png
  25. Двоичные данные
      test/oaassist/wps/icon/w_ImportDoc1.png
  26. Двоичные данные
      test/oaassist/wps/icon/w_InsDate.png
  27. Двоичные данные
      test/oaassist/wps/icon/w_InsPicture.png
  28. Двоичные данные
      test/oaassist/wps/icon/w_InsPictures.png
  29. Двоичные данные
      test/oaassist/wps/icon/w_OpenRev.png
  30. Двоичные данные
      test/oaassist/wps/icon/w_OpenRev2.png
  31. Двоичные данные
      test/oaassist/wps/icon/w_PDF.png
  32. Двоичные данные
      test/oaassist/wps/icon/w_PageGear.png
  33. Двоичные данные
      test/oaassist/wps/icon/w_RejectRev.png
  34. Двоичные данные
      test/oaassist/wps/icon/w_Save.png
  35. Двоичные данные
      test/oaassist/wps/icon/w_SaveAs.png
  36. Двоичные данные
      test/oaassist/wps/icon/w_Scanner16.png
  37. Двоичные данные
      test/oaassist/wps/icon/w_WPSCloud.png
  38. +173
    -0
      test/oaassist/wps/importTemplate.html
  39. +5
    -0
      test/oaassist/wps/index.html
  40. +535
    -0
      test/oaassist/wps/js/common/common.js
  41. +115
    -0
      test/oaassist/wps/js/common/enum.js
  42. +232
    -0
      test/oaassist/wps/js/common/func_docEvents.js
  43. +904
    -0
      test/oaassist/wps/js/common/func_docProcess.js
  44. +146
    -0
      test/oaassist/wps/js/common/func_oastarter.js
  45. +1431
    -0
      test/oaassist/wps/js/common/func_tabcontrol.js
  46. +157
    -0
      test/oaassist/wps/js/common/time.js
  47. +12
    -0
      test/oaassist/wps/js/main.js
  48. +37
    -0
      test/oaassist/wps/otherslib/lib/formdata.js
  49. +6
    -0
      test/oaassist/wps/otherslib/lib/jquery.min.js
  50. +1
    -0
      test/oaassist/wps/otherslib/lib/qrcode.min.js
  51. +6
    -0
      test/oaassist/wps/otherslib/lib/vue.min.js
  52. +142
    -0
      test/oaassist/wps/redhead.html
  53. +148
    -0
      test/oaassist/wps/ribbon.xml
  54. +195
    -0
      test/oaassist/wps/selectBookmark.html
  55. +205
    -0
      test/oaassist/wps/selectSeal.html
  56. +34
    -0
      test/oaassist/wps/setUserName.html
  57. +143
    -0
      test/oaassist/wps/taskpane.html
  58. Двоичные данные
      test/oaassist/wps/template/OA模板公章.png
  59. Двоичные данные
      test/oaassist/wps/template/模板.docx
  60. Двоичные данные
      test/oaassist/wps/template/红头文件.docx
  61. +326
    -0
      test/oaassist/wps/wps-addon-build/LICENSE
  62. +82
    -0
      test/oaassist/wps/wps-addon-build/QRCode.html
  63. +27
    -0
      test/oaassist/wps/wps-addon-build/README.md
  64. +19
    -0
      test/oaassist/wps/wps-addon-build/icon/3.svg
  65. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/c_bookmark.png
  66. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/c_default.png
  67. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/c_printDoc.png
  68. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/c_seal.png
  69. +22
    -0
      test/oaassist/wps/wps-addon-build/icon/newFromTemp.svg
  70. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_AcceptRev.png
  71. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_BackDoc.png
  72. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_CloseRev.png
  73. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_CloseRev1 (2).png
  74. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_CloseRev3.png
  75. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_DeleteRev.png
  76. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_DocClear.png
  77. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_DocClound.png
  78. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_DocOFD.png
  79. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_DocQr.png
  80. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_DocQr1.png
  81. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_DocRevis.png
  82. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_DocUOF.png
  83. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_GovDoc.png
  84. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_ImportDoc.png
  85. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_ImportDoc1.png
  86. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_InsDate.png
  87. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_InsPicture.png
  88. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_InsPictures.png
  89. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_OpenRev.png
  90. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_OpenRev2.png
  91. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_PDF.png
  92. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_PageGear.png
  93. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_RejectRev.png
  94. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_Save.png
  95. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_SaveAs.png
  96. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_Scanner16.png
  97. Двоичные данные
      test/oaassist/wps/wps-addon-build/icon/w_WPSCloud.png
  98. +173
    -0
      test/oaassist/wps/wps-addon-build/importTemplate.html
  99. +5
    -0
      test/oaassist/wps/wps-addon-build/index.html
  100. +535
    -0
      test/oaassist/wps/wps-addon-build/js/common/common.js

+ 326
- 0
test/oaassist/wps/LICENSE Просмотреть файл

@@ -0,0 +1,326 @@
Copyright @ 2012-2019, Kingsoft office,All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, 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.
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.
************************************************************************************
QRCode.js
The MIT License (MIT)
---------------------
Copyright (c) 2012 davidshimjs
Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
************************************************************************************
Vue.js
The MIT License (MIT)
Copyright (c) 2013-present, Yuxi (Evan) You
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
************************************************************************************
bootstrap
The MIT License (MIT)
Copyright (c) 2011-2019 Twitter, Inc.
Copyright (c) 2011-2019 The Bootstrap Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
************************************************************************************
html5-formdata
MIT License
Copyright (c) 2010 François de Metz
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The MIT License (MIT)
************************************************************************************
iview
Copyright (c) 2016-present TalkingData
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT LICENSE
Copyright (c) 2015-present Alipay.com, https://www.alipay.com/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The MIT License (MIT)
Copyright (c) 2016 ElemeFE
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The MIT License (MIT)
Copyright (c) 2015 Koala
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The MIT License (MIT)
Copyright (c) 2016 vue-beauty
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2016-present, Airyland
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The MIT License (MIT)
Copyright (c) 2016 Drifty (http://drifty.com/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
The MIT License (MIT)
Copyright (c) 2015 greyby
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
************************************************************************************
jquery
Copyright JS Foundation and other contributors, https://js.foundation/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
************************************************************************************
zTree
The MIT License (MIT)
copyright (c) <2011> < hunter.z >
使用该许可证的软件被授予以下权限,免费,任何人可以得到这个软件及其相关文档的一个拷贝,并且经营该软件不受任何限制,包括无限制的使用、复制、修改、合并、出版、发行、发放从属证书、或者出售该软件的拷贝的权利。同时允许获得这些软件的用户享受这些权利,使其服从下面的条件:
以上的版权通知和权限通知应该包含在所有该软件的拷贝中或者是其他该软件的真实部分中。
该软件按本来的样子提供,没有任何形式的担保,不管是明确地或者暗含的,包含这些但是不受商业性质的担保的限制。适合一个特定的用途并且不受侵犯。作者和版权持有人在任何场合对使用该软件涉及的任何要求、损害或者其他责任都不应负责。不管它是正在起作用还是只是合同形式、民事侵权或是其他方式,如由它引起,在其作用范围内、与该软件有联系、该软件的使用或者有这个软件引起的其他行为。

+ 82
- 0
test/oaassist/wps/QRCode.html Просмотреть файл

@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>二维码生成</title>
<script type="text/javascript" src="./otherslib/lib/qrcode.min.js"></script>
<script type="text/javascript" src="./otherslib/lib/jquery.min.js"></script>
<style>
.box {
width: 110px;
height: 110px;
border: 1px solid #999;
}
#qrcode {
width: 100px;
height: 100px;
margin: 5px auto;
}
#tip{
font-size: 13px;
color: red;
}
</style>
</head>
<body>
<div class="box">
<div id="qrcode">
</div>
<img src="" id="imgData"></img>
</div>2+66
<input type="text" id="text" value="二维码文字"> &nbsp;<span id="tip"></span> <br>
<input type="button" id="btnMakeQRCode" value="生成二维码">
<input type="button" id="btnInsert" value="插入文档中">
</body>
<script>
var qrcode = new QRCode(document.getElementById("qrcode"), {
width : 100,//设置宽高
height : 100
});
document.getElementById('btnMakeQRCode').onclick = function () {
makeCode();
}
document.getElementById('btnInsert').onclick = function() {
let l_canvasImg = $("#qrcode").find("canvas")[0];
let l_DataURL = l_canvasImg.toDataURL("image/png");
//wps.WpsApplication().Selection.Goto();
let l_shapeQR=wps.WpsApplication().ActiveDocument.Shapes.AddBase64Picture(l_DataURL);
//l_shapeQR.Left =
l_shapeQR.Visible = true;
l_shapeQR.Select();
}
$("#text").on("blur", function () {
makeCode();
}).on("keydown", function (e) {
if (e.keyCode == 13) {
makeCode();
}
});
/**
*/
function makeCode () {
let elText = document.getElementById("text");
if (!elText.value) {
$("#tip").text("请输入二维码文字");
elText.focus();
return;
}
$("#tip").text("");
qrcode.makeCode(elText.value);
}
</script>
</html>

+ 27
- 0
test/oaassist/wps/README.md Просмотреть файл

@@ -0,0 +1,27 @@
## Welcome to WPS OAAssist Demo

### 这个项目是什么?

这个工程为WPS文字项目常见的OA场景集成下的WPS加载项——OA助手,项目使用了丰富的WPS API的功能,可以帮助大家能够快速理解并熟悉WPS加载项机制以及和浏览器调用交互的流程。

### 工程结构

* icon 图标文件。
* js WPS 加载项功能逻辑的js代码。
* otherslib vue,jQueryd等第三方库。
* template 示例模板文件。
* importTemplate.html 导入模板页面。
* index.html 加载项的默认加载页面。
* qrcode.html 插入二维码页面。
* redhead.html 插入红头页面。
* selectBookmark.html 插入标签页面。
* selectSeal.html 插入签章页面。
* setUserName.html 修改默认用户名页面。
* ribbon.xml 自定义选项卡配置。

### 注意事项

* 本工程只是演示demo
* 我们建议您结合具体的应用场景修改示例代码,这样更能够体现OA助手集成的应用场景
* 为了保护代码,建议对上线代码进行混淆
* 使用该工程的时候,必须要安装WPS专业版,请咨询QQ:3253920855

+ 19
- 0
test/oaassist/wps/icon/3.svg Просмотреть файл

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 21.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;" xml:space="preserve">
<style type="text/css">
.skinbaseDark{opacity:0.8;enable-background:new ;}
.skinthemeDark{fill:#5789D9;}
</style>
<path class="skinbaseDark" d="M13,23h-1.4c-0.1,0-0.2,0-0.3-0.1c-0.7-0.2-0.9-0.6-1.3-0.9l-5-5H1.6C0.7,17,0,16.3,0,15.4V8.6
C0,7.7,0.7,7,1.6,7H5l5-5c0.4-0.4,0.6-0.8,1.3-0.9C11.4,1,11.5,1,11.6,1H12l0,0l0,0h1c0.6,0,1,0.5,1,1v20C14,22.5,13.6,23,13,23z
M13,2.4C13,2.2,12.8,2,12.6,2H12c-0.5,0-0.9,0.2-1.1,0.4c0.1-0.1,0,0,0,0C10.8,2.6,7.3,6,5.3,8H1.6C1.3,8,1,8.3,1,8.6v6.8
C1,15.7,1.3,16,1.6,16h3.7c2,2,5.5,5.5,5.7,5.7c0.2,0.2,0.6,0.3,1,0.3h0.6c0.2,0,0.4-0.2,0.4-0.4V2.4z M10,2C10,2,9.9,2.1,10,2
C9.9,2,10,2,10,2z"/>
<path class="skinthemeDark" d="M18.5,20.9c-0.1,0.1-0.2,0.1-0.4,0.1c-0.3,0-0.5-0.2-0.5-0.5c0-0.2,0.1-0.4,0.3-0.5l0,0
c3-1.5,5.1-4.5,5.1-8.1s-2.1-6.6-5.1-8.1l0,0c-0.2-0.1-0.3-0.3-0.3-0.5c0-0.3,0.2-0.5,0.5-0.5c0.1,0,0.3,0.1,0.4,0.2
c3.3,1.6,5.5,5,5.5,8.9S21.8,19.3,18.5,20.9z M19,12c0,1.7-0.9,3.2-2.2,4.1c-0.1,0.1-0.2,0.2-0.4,0.2c-0.3,0-0.5-0.2-0.5-0.5
c0-0.2,0.1-0.4,0.3-0.5v0c1.1-0.7,1.8-1.9,1.8-3.3c0-1.4-0.7-2.6-1.8-3.3v0c-0.2-0.1-0.3-0.3-0.3-0.5c0-0.3,0.2-0.5,0.5-0.5
c0.2,0,0.3,0.1,0.4,0.2C18.1,8.8,19,10.3,19,12z"/>
</svg>

Двоичные данные
test/oaassist/wps/icon/c_bookmark.png Просмотреть файл

До После
Ширина: 128  |  Высота: 128  |  Размер: 14KB

Двоичные данные
test/oaassist/wps/icon/c_default.png Просмотреть файл

До После
Ширина: 230  |  Высота: 230  |  Размер: 2.5KB

Двоичные данные
test/oaassist/wps/icon/c_printDoc.png Просмотреть файл

До После
Ширина: 200  |  Высота: 200  |  Размер: 1.5KB

Двоичные данные
test/oaassist/wps/icon/c_seal.png Просмотреть файл

До После
Ширина: 210  |  Высота: 200  |  Размер: 2.0KB

+ 22
- 0
test/oaassist/wps/icon/newFromTemp.svg Просмотреть файл

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="21px" height="20px" viewBox="0 0 21 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 51.2 (57519) - http://www.bohemiancoding.com/sketch -->
<title>从模版新建</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Artboard" transform="translate(-31.000000, -26.000000)">
<g id="从模版新建" transform="translate(29.000000, 24.000000)">
<g id="Group" stroke-width="1">
<g id="新增节" transform="translate(2.000000, 2.000000)">
<path d="M19.9587402,10 L18.9587402,10 L18.9587402,2 C18.9587402,1.44771525 18.511025,1 17.9587402,1 L6.0300293,1 C5.47774455,1 5.0300293,1.44771525 5.0300293,2 L5.0300293,18 C5.0300293,18.5522847 5.47774455,19 6.0300293,19 L9.95874023,19 L9.95874023,20 L6.0300293,20 C4.9254598,20 4.0300293,19.1045695 4.0300293,18 L4.0300293,2 C4.0300293,0.8954305 4.9254598,2.02906125e-16 6.0300293,0 L17.9587402,0 C19.0633097,-2.02906125e-16 19.9587402,0.8954305 19.9587402,2 L19.9587402,10 Z" id="Combined-Shape" fill="#404040" fill-rule="nonzero"></path>
<path d="M6,1 L4,1 C3.44771525,1 3,1.44771525 3,2 L3,18 C3,18.5522847 3.44771525,19 4,19 L6,19 L6,20 L4,20 C2.8954305,20 2,19.1045695 2,18 L2,2 C2,0.8954305 2.8954305,2.02906125e-16 4,0 L6,0 L6,1 Z" id="Combined-Shape-Copy-2" fill="#404040" fill-rule="nonzero"></path>
<path d="M4,1 L2,1 C1.44771525,1 1,1.44771525 1,2 L1,18 C1,18.5522847 1.44771525,19 2,19 L4,19 L4,20 L2,20 C0.8954305,20 1.03797111e-16,19.1045695 0,18 L0,2 C-1.10284431e-16,0.8954305 0.8954305,2.02906125e-16 2,0 L4,0 L4,1 Z" id="Combined-Shape-Copy-3" fill="#404040" fill-rule="nonzero"></path>
<path d="M17,15 L20.5,15 C20.7761424,15 21,15.2238576 21,15.5 C21,15.7761424 20.7761424,16 20.5,16 L17,16 L17,19.5 C17,19.7761424 16.7761424,20 16.5,20 C16.2238576,20 16,19.7761424 16,19.5 L16,16 L12.5,16 C12.2238576,16 12,15.7761424 12,15.5 C12,15.2238576 12.2238576,15 12.5,15 L16,15 L16,11.5 C16,11.2238576 16.2238576,11 16.5,11 C16.7761424,11 17,11.2238576 17,11.5 L17,15 Z" id="Combined-Shape" fill="#5789D9"></path>
</g>
</g>
<rect id="Rectangle-15" fill="#404040" x="9" y="6" width="10" height="1"></rect>
</g>
</g>
</g>
</svg>

Двоичные данные
test/oaassist/wps/icon/w_AcceptRev.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 1.8KB

Двоичные данные
test/oaassist/wps/icon/w_BackDoc.png Просмотреть файл

До После
Ширина: 32  |  Высота: 32  |  Размер: 4.5KB

Двоичные данные
test/oaassist/wps/icon/w_CloseRev.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 1.6KB

Двоичные данные
test/oaassist/wps/icon/w_CloseRev1 (2).png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 861B

Двоичные данные
test/oaassist/wps/icon/w_CloseRev3.png Просмотреть файл

До После
Ширина: 28  |  Высота: 24  |  Размер: 767B

Двоичные данные
test/oaassist/wps/icon/w_DeleteRev.png Просмотреть файл

До После
Ширина: 16  |  Высота: 16  |  Размер: 610B

Двоичные данные
test/oaassist/wps/icon/w_DocClear.png Просмотреть файл

До После
Ширина: 26  |  Высота: 31  |  Размер: 1.1KB

Двоичные данные
test/oaassist/wps/icon/w_DocClound.png Просмотреть файл

До После
Ширина: 66  |  Высота: 48  |  Размер: 3.2KB

Двоичные данные
test/oaassist/wps/icon/w_DocOFD.png Просмотреть файл

До После
Ширина: 39  |  Высота: 48  |  Размер: 2.3KB

Двоичные данные
test/oaassist/wps/icon/w_DocQr.png Просмотреть файл

До После
Ширина: 16  |  Высота: 16  |  Размер: 834B

Двоичные данные
test/oaassist/wps/icon/w_DocQr1.png Просмотреть файл

До После
Ширина: 16  |  Высота: 16  |  Размер: 1.1KB

Двоичные данные
test/oaassist/wps/icon/w_DocRevis.png Просмотреть файл

До После
Ширина: 32  |  Высота: 32  |  Размер: 2.3KB

Двоичные данные
test/oaassist/wps/icon/w_DocUOF.png Просмотреть файл

До После
Ширина: 39  |  Высота: 48  |  Размер: 2.2KB

Двоичные данные
test/oaassist/wps/icon/w_GovDoc.png Просмотреть файл

До После
Ширина: 40  |  Высота: 40  |  Размер: 1.4KB

Двоичные данные
test/oaassist/wps/icon/w_ImportDoc.png Просмотреть файл

До После
Ширина: 21  |  Высота: 24  |  Размер: 1.6KB

Двоичные данные
test/oaassist/wps/icon/w_ImportDoc1.png Просмотреть файл

До После
Ширина: 27  |  Высота: 23  |  Размер: 1.1KB

Двоичные данные
test/oaassist/wps/icon/w_InsDate.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 1.8KB

Двоичные данные
test/oaassist/wps/icon/w_InsPicture.png Просмотреть файл

До После
Ширина: 20  |  Высота: 16  |  Размер: 1.1KB

Двоичные данные
test/oaassist/wps/icon/w_InsPictures.png Просмотреть файл

До После
Ширина: 16  |  Высота: 16  |  Размер: 1.4KB

Двоичные данные
test/oaassist/wps/icon/w_OpenRev.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 1.8KB

Двоичные данные
test/oaassist/wps/icon/w_OpenRev2.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 2.0KB

Двоичные данные
test/oaassist/wps/icon/w_PDF.png Просмотреть файл

До После
Ширина: 48  |  Высота: 48  |  Размер: 15KB

Двоичные данные
test/oaassist/wps/icon/w_PageGear.png Просмотреть файл

До После
Ширина: 16  |  Высота: 16  |  Размер: 1.8KB

Двоичные данные
test/oaassist/wps/icon/w_RejectRev.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 1.9KB

Двоичные данные
test/oaassist/wps/icon/w_Save.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 14KB

Двоичные данные
test/oaassist/wps/icon/w_SaveAs.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 14KB

Двоичные данные
test/oaassist/wps/icon/w_Scanner16.png Просмотреть файл

До После
Ширина: 16  |  Высота: 16  |  Размер: 1.3KB

Двоичные данные
test/oaassist/wps/icon/w_WPSCloud.png Просмотреть файл

До После
Ширина: 70  |  Высота: 47  |  Размер: 1.5KB

+ 173
- 0
test/oaassist/wps/importTemplate.html Просмотреть файл

@@ -0,0 +1,173 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>导入模板</title>
<meta charset="UTF-8">
<script type="text/javascript" src='js/main.js'></script>
<script type="text/javascript" src="otherslib/lib/vue.min.js"></script>
<style type="text/css">
* {
box-sizing: border-box;
}
/*清除浮动*/
.clear:after {
content: "";
display: block;
clear: both;
}
html,
body,
#template {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.row {
width: 100%;
border-top: 2px solid #e7e7e7;
}
.row>div {
height: 100%;
}
#file_select {
width: 100%;
padding-left: 5%;
}
.def_control {
height: 55%;
width: 100%;
font-size: 18px;
}
.btn_box {
width: 16%;
float: right;
line-height: 4.5em;
margin-right: 3%;
}
</style>
</head>
<body>
<div id="template">
<div class="row" style="height:50%;padding-top: 3%;">
<div id="file_select">
<span>文件名:</span>
<select class="def_control" style="width: 80%;" v-model="templateItem">
<option value="-1">请选择模板</option>
<option v-for="(item,key) in templates" :value="item.tempId" :key="key">{{item.tempName}}</option>
</select>
</div>
</div>
<div class="row" style="height: 50%;">
<div class="btn_box">
<button class="def_control" type="button" @click="cancel()">取消</button>
</div>
<div class="btn_box">
<button class="def_control" type="button" @click="OnImportTemplate()">导入</button>
</div>
</div>
</div>
</body>
</html>
<script>
/**
* 导入公文模板,并替换当前文档全部内容
* @param templateURL 模板路径
*/
function importTemlateFile(templateURL) {
var wpsApp = wps.WpsApplication();
var activeDoc = wpsApp.ActiveDocument;
if (!activeDoc) {
alert("文档不存在");
return;
}
var selection = wpsApp.ActiveWindow.Selection;
selection.WholeStory(); //选取全文
selection.Delete(); // 删除选中内容
selection.InsertFile(templateURL);
if (activeDoc.Revisions.Count > 0) { // 文档或区域中的修订
activeDoc.AcceptAllRevisions(); // 接受对指定文档的所有修订
}
}
// 获取选中项,拼接模板Url进行导入模板
function OnImportTemplate() {
var templateId = vm.templateItem;
console.log(vm);
if (templateId == -1) {
alert('请选中模板!!');
return;
}
// var p_Doc = wps.WpsApplication().ActiveDocument;
// var templatePath = GetDocParamsValue(p_Doc, "templatePath");
// if (templatePath == "") { templatePath = OA_DOOR.templateBaseURL; }
// var templateURL = templatePath + templateId;
var templateURL = getHtmlURL("template/模板.docx");
importTemlateFile(templateURL);
window.opener = null;
window.open('', '_self', '');
window.close();
wps.OAAssist.ShellExecute("ksowebstartupwps://");
}
function cancel() { // 取消按钮
window.close();
wps.OAAssist.ShellExecute("ksowebstartupwps://"); // 将WPS程序置前
}
var vm = new Vue({
el: "#template",
data: {
templateItem: -1,
templates: {}
},
methods: {
getAllTemplate: function () {
var _this = this
//通过接口拉取模板列表
// var p_Doc = wps.WpsApplication().ActiveDocument;
// var templateDataUrl = GetDocParamsValue(p_Doc, "templateDataUrl");
// if (templateDataUrl == "") { templateDataUrl = OA_DOOR.templateDataUrl; }
// $.ajax({
// url: templateDataUrl,
// async: false,
// method: "post",
// dataType: 'json',
// success: function (res) {
// _this.templates = res;
// console.log("模板列表数据:" + JSON.stringify(res));
// },
// error: function (res) {
// alert("获取响应失败");
// _this.templates = {}
// }
// });
//本地静态列表
this.templates=[{
tempName:'模板',
tempId:1
}]
}
},
mounted: function () {
this.getAllTemplate();
}
});
</script>

+ 5
- 0
test/oaassist/wps/index.html Просмотреть файл

@@ -0,0 +1,5 @@
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<script type="text/javascript" src="js/main.js"></script>
</html>

+ 535
- 0
test/oaassist/wps/js/common/common.js Просмотреть файл

@@ -0,0 +1,535 @@
// -------------------------- 通用常量 ---------------------------
//OA门户网站用接口,配置默认服务器接口
var OA_DOOR = {
templateDataUrl: undefined, //正文模板列表接口
templateBaseURL: undefined, //指定正文模板基础接口
redHeadsPath: undefined, //默认红头模板列表获取路径
getRedHeadPath: undefined, //默认获取红头文件路径
bookmarkPath: undefined, //书签列表接口
redHeadsPath: undefined, //默认红头模板列表获取路径
}
// -------------------------- 通用方法 ---------------------------
//去除字符串左边空格
String.prototype.ltrim = function () {
return this.replace(/(^\s*)/g, "");
}
//去除字符串右边空格
String.prototype.rtrim = function () {
return this.replace(/(\s*$)/g, "");
}
//扩展js string endwith,startwith方法
String.prototype.endWith = function (str) {
if (str == null || str == "" || this.length == 0 || str.length > this.length)
return false;
if (this.substring(this.length - str.length) == str)
return true;
else
return false;
}
String.prototype.startWith = function (str) {
if (str == null || str == "" || this.length == 0 || str.length > this.length)
return false;
if (this.substr(0, str.length) == str)
return true;
else
return false;
}
//UTF-16转UTF-8
function utf16ToUtf8(s) {
if (!s) {
return;
}
var i, code, ret = [],
len = s.length;
for (i = 0; i < len; i++) {
code = s.charCodeAt(i);
if (code > 0x0 && code <= 0x7f) {
//单字节
//UTF-16 0000 - 007F
//UTF-8 0xxxxxxx
ret.push(s.charAt(i));
} else if (code >= 0x80 && code <= 0x7ff) {
//双字节
//UTF-16 0080 - 07FF
//UTF-8 110xxxxx 10xxxxxx
ret.push(
//110xxxxx
String.fromCharCode(0xc0 | ((code >> 6) & 0x1f)),
//10xxxxxx
String.fromCharCode(0x80 | (code & 0x3f))
);
} else if (code >= 0x800 && code <= 0xffff) {
//三字节
//UTF-16 0800 - FFFF
//UTF-8 1110xxxx 10xxxxxx 10xxxxxx
ret.push(
//1110xxxx
String.fromCharCode(0xe0 | ((code >> 12) & 0xf)),
//10xxxxxx
String.fromCharCode(0x80 | ((code >> 6) & 0x3f)),
//10xxxxxx
String.fromCharCode(0x80 | (code & 0x3f))
);
}
}
return ret.join('');
}
var Base64 = {
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function(e) {
var t = "";
var n, r, i, s, o, u, a;
var f = 0;
e = Base64._utf8_encode(e);
while (f < e.length) {
n = e.charCodeAt(f++);
r = e.charCodeAt(f++);
i = e.charCodeAt(f++);
s = n >> 2;
o = (n & 3) << 4 | r >> 4;
u = (r & 15) << 2 | i >> 6;
a = i & 63;
if (isNaN(r)) {
u = a = 64
} else if (isNaN(i)) {
a = 64
}
t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a)
}
return t
},
decode: function(e) {
var t = "";
var n, r, i;
var s, o, u, a;
var f = 0;
e = e.replace(/[^A-Za-z0-9+/=]/g, "");
while (f < e.length) {
s = this._keyStr.indexOf(e.charAt(f++));
o = this._keyStr.indexOf(e.charAt(f++));
u = this._keyStr.indexOf(e.charAt(f++));
a = this._keyStr.indexOf(e.charAt(f++));
n = s << 2 | o >> 4;
r = (o & 15) << 4 | u >> 2;
i = (u & 3) << 6 | a;
t = t + String.fromCharCode(n);
if (u != 64) {
t = t + String.fromCharCode(r)
}
if (a != 64) {
t = t + String.fromCharCode(i)
}
}
t = Base64._utf8_decode(t);
return t
},
_utf8_encode: function(e) {
e = e.replace(/rn/g, "n");
var t = "";
for (var n = 0; n < e.length; n++) {
var r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r)
} else if (r > 127 && r < 2048) {
t += String.fromCharCode(r >> 6 | 192);
t += String.fromCharCode(r & 63 | 128)
} else {
t += String.fromCharCode(r >> 12 | 224);
t += String.fromCharCode(r >> 6 & 63 | 128);
t += String.fromCharCode(r & 63 | 128)
}
}
return t
},
_utf8_decode: function(e) {
var t = "";
var n = 0;
var r = c1 = c2 = 0;
while (n < e.length) {
r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r);
n++
} else if (r > 191 && r < 224) {
c2 = e.charCodeAt(n + 1);
t += String.fromCharCode((r & 31) << 6 | c2 & 63);
n += 2
} else {
c2 = e.charCodeAt(n + 1);
c3 = e.charCodeAt(n + 2);
t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
n += 3
}
}
return t
}
}
//UTF-8转UTF-16
function utf8ToUtf16(s) {
if (!s) {
return;
}
var i, codes, bytes, ret = [],
len = s.length;
for (i = 0; i < len; i++) {
codes = [];
codes.push(s.charCodeAt(i));
if (((codes[0] >> 7) & 0xff) == 0x0) {
//单字节 0xxxxxxx
ret.push(s.charAt(i));
} else if (((codes[0] >> 5) & 0xff) == 0x6) {
//双字节 110xxxxx 10xxxxxx
codes.push(s.charCodeAt(++i));
bytes = [];
bytes.push(codes[0] & 0x1f);
bytes.push(codes[1] & 0x3f);
ret.push(String.fromCharCode((bytes[0] << 6) | bytes[1]));
} else if (((codes[0] >> 4) & 0xff) == 0xe) {
//三字节 1110xxxx 10xxxxxx 10xxxxxx
codes.push(s.charCodeAt(++i));
codes.push(s.charCodeAt(++i));
bytes = [];
bytes.push((codes[0] << 4) | ((codes[1] >> 2) & 0xf));
bytes.push(((codes[1] & 0x3) << 6) | (codes[2] & 0x3f));
ret.push(String.fromCharCode((bytes[0] << 8) | bytes[1]));
}
}
return ret.join('');
}
function currentTime() {
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var ss = now.getSeconds();
var clock = year + "";
if (month < 10)
clock += "0";
clock += month + "";
if (day < 10)
clock += "0";
clock += day + "";
if (hh < 10)
clock += "0";
clock += hh + "";
if (mm < 10) clock += '0';
clock += mm;
if (ss < 10) clock += '0';
clock += ss;
return (clock);
}
/**
* 获取文件路径
* @param {*} html 文件全称
*/
function getHtmlURL(html) {
//弹出辅助窗格框
var GetUrlPath = ()=> {
var e = document.location.toString();
return -1 != (e = decodeURI(e)).indexOf("/") && (e = e.substring(0, e.lastIndexOf("/"))), e
}
var url = GetUrlPath();
if (url.length != 0) {
url = url.concat("/" + html);
} else {
url = url.concat("./" + html);
}
return url;
}
/**
* wps内弹出web页面
* @param {*} html 文件名
* @param {*} title 窗口标题
* @param {*} hight 窗口高
* @param {*} width 窗口宽
*/
function OnShowDialog(html, title, height, width, bModal) {
var l_ActiveDoc = wps.WpsApplication().ActiveDocument;
if (!l_ActiveDoc) {
alert("WPS当前没有可操作文档!")
return;
}
if (typeof bModal == "undefined" || bModal == null) {
bModal = true;
}
width *= window.devicePixelRatio;
height *= window.devicePixelRatio;
var url = getHtmlURL(html);
wps.ShowDialog(url, title, height, width, bModal);
}
/**
* 解析返回response的参数
* @param {*} resp
* @return {*} body
*/
function handleResultBody(resp) {
var result = "";
if (resp.Body) {
// 解析返回response的参数
}
return result;
}
/**
* 判断WPS中的文件个数是否为0,若为0则关闭WPS函数
* @param {*} name
*/
function closeWpsIfNoDocument() {
var wpsApp = wps.WpsApplication();
var docs = wpsApp.Documents;
if (!docs || docs.Count == 0) {
wps.ApiEvent.Cancel = true;
//根据业务可以选择是否退出进程 wpsApp.Quit();
}
}
function activeTab() {
//启动WPS程序后,默认显示的工具栏选项卡为ribbon.xml中某一tab
if (wps.ribbonUI)
wps.ribbonUI.ActivateTab('WPSWorkExtTab');
}
function showOATab() {
wps.PluginStorage.setItem("ShowOATabDocActive", pCheckIfOADoc()); //根据文件是否为OA文件来显示OA菜单
wps.ribbonUI.Invalidate(); // 刷新Ribbon自定义按钮的状态
}
function getDemoTemplatePath() {
var url = document.location.toString();
url = decodeURI(url);
if (url.indexOf("/") != -1) {
url = url.substring(0, url.lastIndexOf("/"));
}
if (url.length !== 0)
url = url.concat("/template/红头文件.docx");
if (url.startsWith("file:///"))
url = url.substr("file:///".length);
return url;
}
function getDemoSealPath() {
var url = document.location.toString();
url = decodeURI(url);
if (url.indexOf("/") != -1) {
url = url.substring(0, url.lastIndexOf("/"));
}
if (url.length !== 0)
url = url.concat("/template/OA模板:公章.png");
if (url.startsWith("file:///"))
url = url.substr("file:///".length);
return url;
}
function pGetParamName(data, attr) {
var start = data.indexOf(attr);
data = data.substring(start + attr.length);
return data;
}
/**
* 从requst中获取文件名(确保请求中有filename这个参数)
* @param {*} request
* @param {*} url
*/
function pGetFileName(request, url) {
var disposition = request.getResponseHeader("Content-Disposition");
var filename = "";
if (disposition) {
var matchs = pGetParamName(disposition, "filename=");
if (matchs) {
filename = decodeURIComponent(matchs);
} else {
filename = "petro" + Date.getTime();
}
} else {
filename = url.substring(url.lastIndexOf("/") + 1);
filename=filename.split("?")[0]
}
return filename;
}
function StringToUint8Array(string) {
var binLen, buffer, chars, i, _i;
binLen = string.length;
buffer = new ArrayBuffer(binLen);
chars = new Uint8Array(buffer);
for (var i = 0; i < binLen; ++i) {
chars[i] = String.prototype.charCodeAt.call(string, i);
}
return buffer;
}
/**
* WPS下载文件到本地打开(业务系统可根据实际情况进行修改)
* @param {*} url 文件流的下载路径
* @param {*} callback 下载后的回调
*/
function DownloadFile(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
//需要业务系统的服务端在传递文件流时,确保请求中的参数有filename
var fileName = pGetFileName(xhr, url)
//落地打开模式下,WPS会将文件下载到本地的临时目录,在关闭后会进行清理
var path = wps.Env.GetTempPath() + "/" + fileName
var reader = new FileReader();
reader.onload = function () {
wps.FileSystem.writeAsBinaryString(path, reader.result);
callback(path);
};
reader.readAsBinaryString(xhr.response);
}
}
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
}
/**
* WPS上传文件到服务端(业务系统可根据实际情况进行修改,为了兼容中文,服务端约定用UTF-8编码格式)
* @param {*} strFileName 上传到服务端的文件名称(包含文件后缀)
* @param {*} strPath 上传文件的文件路径(文件在操作系统的绝对路径)
* @param {*} uploadPath 上传文件的服务端地址
* @param {*} strFieldName 业务调用方自定义的一些内容可通过此字段传递,默认赋值'file'
* @param {*} OnSuccess 上传成功后的回调
* @param {*} OnFail 上传失败后的回调
*/
function UploadFile(strFileName, strPath, uploadPath, strFieldName, OnSuccess, OnFail) {
var xhr = new XMLHttpRequest();
xhr.open('POST', uploadPath);
var fileData = wps.FileSystem.readAsBinaryString(strPath);
var data = new FakeFormData();
if (strFieldName == "" || typeof strFieldName == "undefined"){//如果业务方没定义,默认设置为'file'
strFieldName = 'file';
}
data.append(strFieldName, {
name: utf16ToUtf8(strFileName), //主要是考虑中文名的情况,服务端约定用utf-8来解码。
type: "application/octet-stream",
getAsBinary: function () {
return fileData;
}
});
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200)
OnSuccess(xhr.response)
else
OnFail(xhr.response);
}
};
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
if (data.fake) {
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + data.boundary);
var arr = StringToUint8Array(data.toString());
xhr.send(arr);
} else {
xhr.send(data);
}
}
/**
* 打开WPS后通知到业务系统,可根据需求扩展
* @param {*} p_Url 业务方接受请求的地址
*/
function NotifyToServer(p_Url) {
$.ajax({
url: p_Url, // URL + '/wps/wpsCanOpen',
async: true,
method: "post",
dataType: 'json'
});
}
/**
* 更新编辑状态
* @param {*} p_Url 要传入OA端,通知业务系统,当前文档所处的编辑状态的URL地址路径
* @param {*} p_OpenUrl 当前文档从业务系统打开时的入口URL,这个URL包含业务系统开发者需要传入的ID等参数
* @param {*} docId 文档id
* @param {*} state 0-正在编辑中 1-文件保存 2-文件关闭 状态可根据需要进行自定义扩展
*/
function UpdateEditState(p_Url, p_OpenUrl, docId, state) {
var formData = {
"openUrl": p_OpenUrl,
"docId": docId,
"state": state
};
$.ajax({
url: p_Url, //URL + '/document/stateMonitor',
async: false,
data: formData,
method: "post",
dataType: 'json',
success: function (response) {
if (response == "success") {
console.log(response);
}
},
error: function (response) {
console.log(response);
}
});
}
/**
* 作用:判断文档关闭后,如果系统已经没有打开的文档了,则设置回初始用户名
*/
function pSetWPSAppUserName() {
//文档全部关闭的情况下,把WPS初始启动的用户名设置回去
if (wps.WpsApplication().Documents.Count == 1) {
var l_strUserName = wps.PluginStorage.getItem(constStrEnum.WPSInitUserName);
wps.WpsApplication().UserName = l_strUserName;
}
}
/**
* 设置文档参数的属性值
* @param {*} Doc
* @param {*} Key
* @param {*} Value
*/
function SetDocParamsValue(Doc, Key, Value) {
if (!Doc || !Key) {
return;
}
var l_Params = wps.PluginStorage.getItem(Doc.DocID);
if (!l_Params) {
return;
}
var l_objParams = JSON.parse(l_Params);
if (!(typeof(l_objParams) == "undefined")) {
l_objParams[Key] = Value;
}
//把属性值整体再写回原来的文档ID中
wps.PluginStorage.setItem(Doc.DocID, JSON.stringify(l_objParams));
}

+ 115
- 0
test/oaassist/wps/js/common/enum.js Просмотреть файл

@@ -0,0 +1,115 @@
/**
* WPS常用的API枚举值,具体参与API文档
*/
var WPS_Enum = {
wdDoNotSaveChanges: 0,
wdFormatPDF: 17,
wdFormatOpenDocumentText: 23,
wdFieldFormTextInput: 70,
wdAlertsNone: 0,
wdDialogFilePageSetup: 178,
wdDialogFilePrint: 88,
wdRelativeHorizontalPositionPage: 1,
wdGoToPage: 1,
wdPropertyPages: 14,
wdRDIComments: 1,
wdDialogInsertDateTime: 165,
msoCTPDockPositionLeft: 0,
msoCTPDockPositionRight: 2,
/**
* 将形状嵌入到文字中。
*/
wdWrapInline: 7,
/**
* 将形状放在文字前面。 请参阅 wdWrapFront。
*/
wdWrapNone: 3,
/**
* 使文字环绕形状。 行在形状的另一侧延续。
*/
wdWrapSquare: 0,
/**
* 使文字环绕形状。
*/
wdWrapThrough: 2,
/**
* 使文字紧密地环绕形状。
*/
wdWrapTight: 1,
/**
* 将文字放在形状的上方和下方。
*/
wdWrapTopBottom: 4,
/**
* 将形状放在文字后面。
*/
wdWrapBehind: 5,
/**
* 将形状放在文字前面。
*/
wdWrapFront: 6
}
/**
* WPS加载项自定义的枚举值
*/
var constStrEnum = {
AllowOADocReOpen: "AllowOADocReOpen",
AutoSaveToServerTime: "AutoSaveToServerTime",
bkInsertFile: "bkInsertFile",
buttonGroups: "buttonGroups",
CanSaveAs: "CanSaveAs",
copyUrl: "copyUrl",
DefaultUploadFieldName: "DefaultUploadFieldName",
disableBtns: "disableBtns",
insertFileUrl: "insertFileUrl",
IsInCurrOADocOpen: "IsInCurrOADocOpen",
IsInCurrOADocSaveAs: "IsInCurrOADocSaveAs",
isOA: "isOA",
notifyUrl: "notifyUrl",
OADocCanSaveAs: "OADocCanSaveAs",
OADocLandMode: "OADocLandMode",
OADocUserSave: "OADocUserSave",
openType: "openType",
picPath: "picPath",
picHeight: "picHeight",
picWidth: "picWidth",
redFileElement: "redFileElement",
revisionCtrl: "revisionCtrl",
ShowOATabDocActive: "ShowOATabDocActive",
SourcePath: "SourcePath",
/**
* 保存文档到业务系统服务端时,另存一份其他格式到服务端,其他格式支持:.pdf .ofd .uot .uof
*/
suffix: "suffix",
templateDataUrl: "templateDataUrl",
TempTimerID: "TempTimerID",
/**
* 文档上传到业务系统的保存地址:服务端接收文件流的地址
*/
uploadPath: "uploadPath",
/**
* 文档上传到服务端后的名称
*/
uploadFieldName: "uploadFieldName",
/**
* 文档上传时的名称,默认取当前活动文档的名称
*/
uploadFileName: "uploadFileName",
uploadAppendPath: "uploadAppendPath",
/**
* 标志位: 1 在保存到业务系统时再保存一份suffix格式的文档, 需要和suffix参数配合使用
*/
uploadWithAppendPath: "uploadWithAppendPath",
userName: "userName",
WPSInitUserName: "WPSInitUserName",
taskpaneid: "taskpaneid",
/**
* 是否弹出上传前确认和成功后的确认信息:true|弹出,false|不弹出
*/
Save2OAShowConfirm: "Save2OAShowConfirm",
/**
* 修订状态标志位
*/
RevisionEnableFlag: "RevisionEnableFlag"
}

+ 232
- 0
test/oaassist/wps/js/common/func_docEvents.js Просмотреть файл

@@ -0,0 +1,232 @@
// 打印前监听事件
function OnDocumentBeforePrint(doc) {
return;
}
//切换窗口时触发的事件
function OnWindowActivate() {
var l_doc = wps.WpsApplication().ActiveDocument;
SetCurrDocEnvProp(l_doc); // 设置当前文档对应的用户名
showOATab(); // 根据文件是否为OA文件来显示OA菜单再进行刷新按钮
setTimeout(activeTab, 2000); // 激活页面必须要页签显示出来,所以做1秒延迟
return;
}
/**
* 作用:判断OA文档是否被另存为了
*/
function CheckIfOADocSaveAs(doc) {
if (!doc) {
return;
}
// 获取OA文档的原始保存路径
var l_Path = GetDocParamsValue(doc, constStrEnum.SourcePath);
// 原路径和当前文件的路径对比
return l_Path == doc.FullName;
}
// 当文件保存前触发的事件
function OnDocumentBeforeSave(doc) {
//设置变量,判断是否当前用户按了自定义的OA文件保存按钮
if(wps.WpsApplication().ActiveDocument&&doc.DocID==wps.WpsApplication().ActiveDocument.DocID){
var l_IsOADocButtonSave = false;
l_IsOADocButtonSave = wps.PluginStorage.getItem(constStrEnum.OADocUserSave);
//根据传入参数判断当前文档是否能另存为,默认不能另存为
if (pCheckCurrOADocCanSaveAs(doc) == false) { //先根据OA助手的默认设置判断是否允许OA文档另存为操作
//0.如果配置文件:OA文档不允许另存为,则再判断
//1.先判断是否是在线文档且是通过WPS自身按钮或快捷键保存,则取消弹出另存到本地的弹出框
if (pIsOnlineOADoc(doc) == true && l_IsOADocButtonSave == false) {
alert("来自OA的不落地文档,禁止另存为本地文档!");
//如果是OA文档,则禁止另存为
wps.ApiEvent.Cancel = true;
}
//2.如果是落地打开的OA文档并且通过WPS自身按钮或者快捷键保存,则执行保存到本地临时目录,取消弹出对话框
if (pIsOnlineOADoc(doc) == false && l_IsOADocButtonSave == false){
//用户手动另存为操作时,在这里被屏蔽掉
doc.Save();
//如果是OA文档,则禁止另存为
wps.ApiEvent.Cancel = true;
}
}
//保存文档后,也要刷新一下Ribbon按钮的状态
showOATab();
}else{
wps.ApiEvent.Cancel=true;
}
return;
}
//文档保存前关闭事件
/**
* 作用:
* @param {*} doc
*/
function OnDocumentBeforeClose(doc) {
console.log('OnDocumentBeforeClose');
var l_fullName = doc.FullName;
var l_bIsOADoc = false;
l_bIsOADoc = CheckIfDocIsOADoc(doc); //判断是否OA文档要关闭
if (l_bIsOADoc == false) { // 非OA文档不做处理
return;
}
//判断是否只读的文档,或受保护的文档,对于只读的文档,不给予保存提示
if (pISOADocReadOnly(doc) == false) {
if (doc.Saved == false) { //如果OA文档关闭前,有未保存的数据
if (wps.confirm("系统文件有改动,是否提交后关闭?" + "\n" + "确认后请按上传按钮执行上传操作。取消则继续关闭文档。")) {
wps.ApiEvent.Cancel = true;
return;
}
}
}
// 有未保存的数据,确认无需保存直接关闭
doc.Close(wps.Enum&&wps.Enum.wdDoNotSaveChanges||0); // 不保存待定的更改。枚举值兼容性写法
closeWpsIfNoDocument(); // 判断WPS中的文件个数是否为0,若为0则关闭WPS函数
wps.FileSystem.Remove(l_fullName);
}
//文档保存后关闭事件
function OnDocumentAfterClose(doc) {
console.log("OnDocumentAfterClose");
var l_NofityURL = GetDocParamsValue(doc, constStrEnum.notifyUrl);
if (l_NofityURL) {
l_NofityURL = l_NofityURL.replace("{?}", "3"); //约定:参数为3则文档关闭
console.log("" + l_NofityURL);
NotifyToServer(l_NofityURL);
}
pRemoveDocParam(doc); // 关闭文档时,移除PluginStorage对象的参数
pSetWPSAppUserName(); // 判断文档关闭后,如果系统已经没有打开的文档了,则设置回初始用户名
}
//文档打开事件
function OnDocumentOpen(doc) {
//设置当前新增文档是否来自OA的文档
// if (wps.PluginStorage.getItem(constStrEnum.IsInCurrOADocOpen) == false) {
// //如果是用户自己在WPS环境打开文档,则设置非OA文档标识
// console.log(wps.PluginStorage.getItem(wps.WpsApplication().ActiveDocument.DocID))
// pSetNoneOADocFlag(doc);
// console.log(wps.PluginStorage.getItem(wps.WpsApplication().ActiveDocument.DocID))
// }
OnWindowActivate();
ChangeOATabOnDocOpen(); //打开文档后,默认打开Tab页
setTimeout(activeTab,2000); // 激活OA助手菜单
}
//新建文档事件
function OnDocumentNew(doc) {
//设置当前新增文档是否来自OA的文档
// if (wps.PluginStorage.getItem(constStrEnum.IsInCurrOADocOpen) == false) {
// //如果是用户自己在WPS环境打开文档,则设置非OA文档标识
// pSetNoneOADocFlag(doc);
// }
ChangeOATabOnDocOpen(); // 打开OA助手Tab菜单页
wps.ribbonUI.Invalidate(); // 刷新Ribbon按钮的状态
}
/**
* 作用:判断当前文档是否是只读文档
* 返回值:布尔
*/
function pISOADocReadOnly(doc) {
if (!doc) {
return false;
}
var l_openType = GetDocParamsValue(doc, constStrEnum.openType); // 获取OA传入的参数 openType
if (l_openType == "") {
return false;
}
try {
if (l_openType.protectType != -1) { // -1 为未保护
return true;
}
} catch (err) {
return false;
}
}
/**
* 作用:根据当前活动文档的情况判断,当前文档适用的系统参数,例如:当前文档对应的用户名称等
*/
function SetCurrDocEnvProp(doc) {
if (!doc) return;
var l_bIsOADoc = false;
l_bIsOADoc = pCheckIfOADoc(doc);
//如果是OA文件,则按OA传来的用户名设置WPS OA助手WPS用户名设置按钮冲突
if (l_bIsOADoc == true) {
var l_userName = GetDocParamsValue(doc, constStrEnum.userName);
if (l_userName != "") {
wps.WpsApplication().UserName = l_userName;
return;
}
}
//如果是非OA文件或者参数的值是空值,则按WPS安装默认用户名设置
wps.WpsApplication().UserName = wps.PluginStorage.getItem(constStrEnum.WPSInitUserName);
}
/*
入口参数:doc
功能说明:判断当前文档是否能另存为本地文件
返回值:布尔值true or false
*/
function pCheckCurrOADocCanSaveAs(doc) {
//如果是非OA文档,则允许另存为
if (CheckIfDocIsOADoc(doc) == false) return true;
//对于来自OA系统的文档,则获取该文档对应的属性参数
var l_CanSaveAs = GetDocParamsValue(doc, constStrEnum.CanSaveAs);
//判断OA传入的参数
if (typeof (l_CanSaveAs) == "boolean") {
return l_CanSaveAs;
}
return false;
}
/**
* 作用:文档关闭后,删除对应的PluginStorage内的参数信息
* 返回值:没有返回值
* @param {*} doc
*/
function pRemoveDocParam(doc) {
if (!doc) return;
wps.PluginStorage.removeItem(doc.DocID);
return;
}
/**
* 作用:判断当前文档是否从OA来的文档,如果非OA文档(就是本地新建或打开的文档,则设置EnumOAFlag 标识)
* 作用:设置非OA文档的标识状态
* @param {*} doc
* 返回值:无
*/
function pSetNoneOADocFlag(doc) {
if (!doc) return;
var l_param = wps.PluginStorage.getItem(doc.DocID); //定义JSON文档参数
var l_objParams = new Object();
if (l_param) {
l_objParams = JSON.parse(l_param);
}
l_objParams.isOA = EnumOAFlag.DocFromNoOA; // 新增非OA打开文档属性
wps.PluginStorage.setItem(doc.DocID, JSON.stringify(l_objParams)); // 存入内存中
}
/**
* 作用:根据设置判断打开文件是否默认激活OA助手工具Tab菜单
* 返回值:无
*/
function ChangeOATabOnDocOpen() {
var l_ShowOATab = true; //默认打开
l_ShowOATab = wps.PluginStorage.getItem(constStrEnum.ShowOATabDocActive);
if (l_ShowOATab == true) {
setTimeout(activeTab,500);
// wps.ribbonUI.ActivateTab("WPSWorkExtTab"); //新建文档时,自动切换到OA助手状态
}
}

+ 904
- 0
test/oaassist/wps/js/common/func_docProcess.js Просмотреть файл

@@ -0,0 +1,904 @@
/**
* 从OA调用传来的指令,打开本地新建文件
* @param {*} fileUrl 文件url路径
*/
function NewFile(params) {
//获取WPS Application 对象
var wpsApp = wps.WpsApplication();
wps.PluginStorage.setItem(constStrEnum.IsInCurrOADocOpen, true); //设置OA打开文档的临时状态
//判断一下isOfficialDocument是否通过公文写作打开
var doc;
if (params.isOfficialDocument) {
wps.Application.GetApplicationEx().NewOfficialDocument(); //新增使用公文写作打开的公文
doc = wpsApp.ActiveDocument;
} else {
doc = wpsApp.Documents.Add(); //新增OA端文档
}
wps.PluginStorage.setItem(constStrEnum.IsInCurrOADocOpen, false);
//检查系统临时文件目录是否能访问
if (wps.Env && wps.Env.GetTempPath) {
if (params.newFileName) {
//按OA传入的文件名称保存
doc.SaveAs2($FileName = wps.Env.GetTempPath() + "/" + params.newFileName, undefined, undefined, undefined, false);
} else {
//OA传入空文件名称,则保存成系统时间文件
if (params.isOfficialDocument) {
doc.SaveAs2($FileName = wps.Env.GetTempPath() + "/OA_" + currentTime(), 0, undefined, undefined, false);
} else {
doc.SaveAs2($FileName = wps.Env.GetTempPath() + "/OA_" + currentTime(), undefined, undefined, undefined, false);
}
}
} else {
alert("文档保存临时目录出错!不能保存新建文档!请联系系统开发商。");
}
var l_NofityURL = GetParamsValue(params, constStrEnum.notifyUrl);
if (l_NofityURL) {
NotifyToServer(l_NofityURL.replace("{?}", "1"));
}
//Office文件打开后,设置该文件属性:从服务端来的OA文件
pSetOADocumentFlag(doc, params);
//设置当前文档为 本地磁盘落地模式
DoSetOADocLandMode(doc, EnumDocLandMode.DLM_LocalDoc);
//强制执行一次Activate事件
OnWindowActivate();
wps.WpsApplication().WindowState=1;
wps.WpsApplication().Activate(); //把WPS对象置前
return doc; //返回新创建的Document对象
}
/**
* 打开服务器上的文件
* @param {*} fileUrl 文件url路径
*/
function OpenFile(params) {
var l_strFileUrl = params.fileName; //来自OA网页端的OA文件下载路径
var doc;
var l_IsOnlineDoc = false; //默认打开的是不落地文档
if (l_strFileUrl) {
//下载文档之前,判断是否已下载该文件
if (pCheckIsExistOpenOADoc(l_strFileUrl) == true) {
//如果找到相同OA地址文档,则给予提示
wps.WpsApplication().WindowState=1;
wps.WpsApplication().Activate(); //把WPS对象置前
//根据OA助手对是否允许再次打开相同文件的判断处理
var l_AllowOADocReOpen = false;
l_AllowOADocReOpen = wps.PluginStorage.getItem(constStrEnum.AllowOADocReOpen);
if (l_AllowOADocReOpen == false) {
alert("已打开相同的OA文件,请关闭之前的文件,再次打开。");
wps.WpsApplication().Activate();
return null;
} else {
//处理重复打开相同OA 文件的方法
var nDocCount = wps.WpsApplication().Documents.Count;
pReOpenOADoc(l_strFileUrl);
//重复打开的文档采用不落地的方式打开
// 不落地方式打开文档判断落地比较多,V1版本先暂时关闭
l_IsOnlineDoc = true;
var nDocCount_New = wps.WpsApplication().Documents.Count;
if (nDocCount_New > nDocCount) {
doc = wps.WpsApplication().ActiveDocument;
}
}
} else {
//如果当前没有打开文档,则另存为本地文件,再打开
if (l_strFileUrl.startWith("http")) { // 网络文档
DownloadFile(l_strFileUrl, function(path) {
if (path == "") {
alert("从服务端下载路径:" + l_strFileUrl + "\n" + "获取文件下载失败!");
return null;
}
doc = pDoOpenOADocProcess(params, path);
pOpenFile(doc, params, l_IsOnlineDoc);
});
return;
} else { //本地文档
doc = pDoOpenOADocProcess(params, l_strFileUrl);
if (doc)
doc.SaveAs2($FileName = wps.Env.GetTempPath() + "/" + doc.Name, undefined, undefined, undefined, false);
}
}
} else {
//fileURL 如果为空,则按新建OA本地文件处理
NewFile(params);
}
//如果打开pdf等其他非Office文档,则doc对象为空
if (!doc) {
return null;
}
pOpenFile(doc, params, l_IsOnlineDoc);
}
/**
* 作用:文档打开后执行的动作集合
* @param {*} doc 文档对象
* @param {*} params 前端传递的参数集合
* @param {*} isOnlineDoc 在线打开/落地打开
*/
function pOpenFile(doc, params, isOnlineDoc) {
var l_IsOnlineDoc = isOnlineDoc
//Office文件打开后,设置该文件属性:从服务端来的OA文件
pSetOADocumentFlag(doc, params)
//设置当前文档为 本地磁盘落地模式
if (l_IsOnlineDoc == true) {
DoSetOADocLandMode(doc, EnumDocLandMode.DLM_OnlineDoc);
} else {
DoSetOADocLandMode(doc, EnumDocLandMode.DLM_LocalDoc);
}
if (GetParamsValue(params, constStrEnum.templateDataUrl)) {
GetServerTemplateData(doc, params[constStrEnum.templateDataUrl]);
}
if (GetParamsValue(params, constStrEnum.insertFileUrl)) {
InsertRedHeadDoc(doc);
}
var l_NofityURL = GetParamsValue(params, constStrEnum.notifyUrl);
if (l_NofityURL) {
l_NofityURL = l_NofityURL.replace("{?}", "1"); //约定:参数为1则代码打开状态
NotifyToServer(l_NofityURL);
}
//重新设置工具条按钮的显示状态
pDoResetRibbonGroups();
// 触发切换窗口事件
OnWindowActivate();
// 把WPS对象置前
wps.WpsApplication().WindowState=1;
wps.WpsApplication().Activate();
return doc;
}
/**
* 套用模板插入文字/图片/文档
* * params参数结构
* params:{
* 'docId': docId, //文档ID
* 'templateURL':'',获取模板接口
* 'fileName':'',获取文档接口
* 'uploadPath':'',文档保存上传接口
* }
* 这个功能要求服务端传来的模板JSON数据字符串,支持三种类型定义:
* text 类型:直接插入对应的书签位置
* link 类型: 把对应的URL的文件插入到指定的书签位置
* pic 类型: 把对应的URL的图片文件插入到指定的书签位置
* @param {*} params
*/
function GetServerTemplateData(template, pTemplateDataUrl) {
//获取文档内容
$.ajax({
url: pTemplateDataUrl,
async: false,
method: "get",
dataType: 'json',
success: function(res) {
var data = res;
let Bookmarks = template.Bookmarks;
data.forEach(function(it) {
var bookmark = Bookmarks.Item(it.name);
let bookStart = bookmark.Range.Start;
let bookEnd = bookmark.Range.End;
let start = template.Range().End
//方案1,直接替换,手动添加书签
// if (bookmark) {
// if (!it.type || it.type === "text") {
// bookmark.Range.Text = it.text;
// } else if (it.type === "link") {
// bookmark.Range.InsertFile(it.text);
// } else if (it.type === "pic") {
// bookmark.Range.InlineShapes.AddPicture(it.text);
// }
// }
// let end = template.Range().End
// let range=bookmark.Range;
// if (!Bookmarks.Exists(bookmark.Name))
// Bookmarks.Add(bookmark.Name, range.SetRange(bookStart, bookEnd + (end - start)))
//方案2,不完全替换
if(bookmark){
if (!it.type || it.type === "text") {
bookmark.Range.InsertBefore(it.text);
} else if (it.type === "link") {
bookmark.Range.InsertFile(it.text);
} else if (it.type === "pic") {
bookmark.Range.InlineShapes.AddPicture(it.text);
}
}
var selection=wps.WpsApplication().ActiveWindow.Selection;
if (bookmark.Range.Text) {
selection.Start = bookmark.Range.End - (bookEnd - bookStart);
selection.End = bookmark.Range.End;
selection.Cut();
} else {
selection.Start = bookmark.Range.End;
selection.End = bookmark.Range.End+it.text.length;
ActiveDocument.Bookmarks.Add(bookmark.Name, selection.Range);
}
})
}
});
}
/**
* 打开服务端的文档(不落地)
* @param {*} fileUrl 文件url路径
*/
function OpenOnLineFile(OAParams) {
//OA参数如果为空的话退出
if (!OAParams) return;
//获取在线文档URL
var l_OAFileUrl = OAParams.fileName;
var l_doc;
if (l_OAFileUrl) {
//下载文档不落地(16版WPS的925后支持)
wps.WpsApplication().Documents.OpenFromUrl(l_OAFileUrl, "OnOpenOnLineDocSuccess", "OnOpenOnLineDocDownFail");
l_doc = wps.WpsApplication().ActiveDocument;
}
//执行文档打开后的方法
pOpenFile(l_doc, OAParams, true);
return l_doc;
}
/**
* 打开在线文档成功后触发事件
* @param {*} resp
*/
function OnOpenOnLineDocSuccess(resp) {
}
/**
* 打开在线不落地文档出现失败时,给予错误提示
*/
function OnOpenOnLineDocDownFail(res) {
var err={}
try{
res=JSON.parse(res)
err.Body=Base64.decode(res.Body)
err.Headers=Base64.decode(JSON.stringify(res.Headers))
console.log(err)
}catch(err){
}
alert("打开在线不落地文档失败!请尝试重新打开。");
return;
}
/**
* 参数:
* doc : 当前OA文档的Document对象
* DocLandMode : 落地模式设置
*/
function DoSetOADocLandMode(doc, DocLandMode) {
if (!doc) return;
var l_Param = wps.PluginStorage.getItem(doc.DocID);
var l_objParam = JSON.parse(l_Param);
//增加属性,或设置
l_objParam.OADocLandMode = DocLandMode; //设置OA文档的落地标志
var l_p = JSON.stringify(l_objParam);
//将OA文档落地模式标志存入系统变量对象保存
wps.PluginStorage.setItem(doc.DocID, l_p);
}
/**
* 作用:设置Ribbon工具条的按钮显示状态
* @param {*} paramsGroups
*/
function pDoResetRibbonGroups(paramsGroups) {
}
/**
* 作用:打开文档处理的各种过程,包含:打开带密码的文档,保护方式打开文档,修订方式打开文档等种种情况
* params Object OA Web端传来的请求JSON字符串,具体参数说明看下面数据
* TempLocalFile : 字符串 先把文档从OA系统下载并保存在Temp临时目录,这个参数指已经下载下来的本地文档地址
* ----------------------以下是OA参数的一些具体规范名称
* docId String 文档ID
* uploadPath String 保存文档接口
* fileName String 获取服务器文档接口(不传即为新建空文档)
* suffix String ".pdf|.uot",可传多个,用“|”分割,保存时会按照所传的值转成对应的格式文档并上传
* userName String 用于更改显示修改人的用户名
* strBookmarkDataPath string 书签列表 (可不传,可以在OA助手config.js中配置)
* templatePath string 模板列表 (可不传,可以在OA助手config.js中配置)
* buttonGroups string 自定义按钮组 (可不传,不传显示所有按钮)
* revisionCtrl String 痕迹控制 ,不传正常打开
* bOpenRevision String true(打开)false(关闭)修订
* bShowRevision String true(显示)/false(关闭)痕迹
* openType String 文档打开方式 ,不传正常打开
* protectType String 文档保护类型,-1:不启用保护模式,0:只允许对现有内容进行修订,1:只允许添加批注,2:只允许修改窗体域,3:只读
* password String密码
*/
function pDoOpenOADocProcess(params, TempLocalFile) {
var l_ProtectType = -1; //默认文档保护类型 -1 为不启用保护
var l_ProtectPassword = ""; //默认文档密码为空
var l_strDocPassword = ""; //打开文档密码参数
var l_bOpenRevision = false; //初始化关闭修订模式
var l_bShowRevision = false; //初始化不显示修订气泡样式
for (var key = "" in params) {
switch (key.toUpperCase()) //
{
case "userName".toUpperCase(): //修改当前文档用户名
wps.WpsApplication().UserName = params[key];
break;
case "openType".toUpperCase():
l_ProtectType = params[key].protectType; //获取OA传来的文档保护类型
l_ProtectPassword = params[key].password; //获取OA传来的保护模式下的文档密码
break;
case "revisionCtrl".toUpperCase(): //限制修订状态
l_bOpenRevision = params[key].bOpenRevision;
l_bShowRevision = params[key].bShowRevision;
break;
case "buttonGroups".toUpperCase(): //按钮组合
break;
case "docPassword".toUpperCase(): //传入打开文件的密码
l_strDocPassword = params[key].docPassword;
break;
}
}
var l_Doc;
// Open方法的参数说明如下
//Function Open(FileName, [ConfirmConversions], [ReadOnly], [AddToRecentFiles],
// [PasswordDocument], [PasswordTemplate], [Revert], [WritePasswordDocument],
// [WritePasswordTemplate], [Format], [Encoding], [Visible],
// [OpenAndRepair], [DocumentDirection], [NoEncodingDialog], [XMLTransform]) As Document
l_Doc = wps.WpsApplication().Documents.Open(TempLocalFile, false, false, false, l_strDocPassword);
//设置文档修订状态
DoOADocOpenRevision(l_Doc, l_bOpenRevision, l_bShowRevision);
//打开文档后,根据保护类型设置文档保护
if (l_ProtectType > -1) // -1 :不设置文档保护
SetOADocProtect(l_Doc, l_ProtectType, l_ProtectPassword);
return l_Doc;
}
/**
* protectType: '', 文档保护模式( -1:不启用保护模式,
* 0:只允许对现有内容进行修订,
* 1:只允许添加批注,
* 2:只允许修改窗体域,
* 3:只读)
* @param {*} protectType
* @param {*} doc
*/
function SetOADocProtect(doc, protectType, ProtectPassword) {
if (!doc) return; //校验文档是否存在
if ([0, 1, 2, 3].indexOf(protectType) !== -1) {
// 保护文档如果之前有被保护,再次保护会出问题,需要先解除保护
doc.Unprotect();
// ** 方法参数
// ** Protect(Type As WdProtectionType, [NoReset], [Password], [UseIRM], [EnforceStyleLock])
doc.Protect(protectType, false, ProtectPassword, false);
}
return;
}
/**
* 打开/关闭修订
* @param {*} doc :传入文档对象
* @param {*} bOpenRevision : 布尔值,是否允许打开修订模式,true:打开/false:关闭
* @param {*} bOpenRevision : 布尔值,是否显示修订痕迹状态
* 返回值:无
*/
function DoOADocOpenRevision(doc, bOpenRevision, bShowRevision) {
if (!doc) return;
doc.TrackRevisions = bOpenRevision; //如果标记对指定文档的修改,则该属性值为True
var l_v = doc.ActiveWindow.View;
l_v.ShowRevisionsAndComments = bShowRevision; //如果为True,则 WPS 显示使用“修订”功能对文档所作的修订和批注
l_v.RevisionsBalloonShowConnectingLines = bShowRevision; //如果为 True,则 WPS 显示从文本到修订和批注气球之间的连接线
wps.WpsApplication().CommandBars.ExecuteMso("KsoEx_RevisionCommentModify_Disable"); //去掉修改痕迹信息框中的接受修订和拒绝修订勾叉,使其不可用
if (bShowRevision) {
doc.ActiveWindow.ActivePane.View.RevisionsMode = 2; //2为不支持气泡显示。
}
//如果关闭修订,关闭显示痕迹并将按钮至灰
wps.ribbonUI.InvalidateControl("btnOpenRevision");
wps.ribbonUI.InvalidateControl("btnShowRevision");
return;
}
/**
* 描述:如何处理再次打开相同的OA文件
* 返回值:打开的Document对象
*/
function pReOpenOADoc(OADocURL) {
if (wps.confirm("当前环境已打开该文件,是否重新再打开一份?")) {
//如果用户选择再次打开,则用在线方式打开
wps.WpsApplication().Documents.OpenFromUrl(OADocURL, "", "");
}
}
/**
* 功能说明:判断是否已存在来自OA的已打开的文档
* @param {字符串} FileURL
*/
function pCheckIsExistOpenOADoc(FileURL) {
var l_DocCount = wps.WpsApplication().Documents.Count;
if (l_DocCount <= 0) return false;
//轮询检查当前已打开的WPS文档中,是否存在OA相同的文件
if (l_DocCount >= 1) {
for (var l_index = 1; l_index <= l_DocCount; l_index++) {
var l_objDoc = wps.WpsApplication().Documents.Item(l_index);
var l_strParam = wps.PluginStorage.getItem(l_objDoc.DocID);
if (l_strParam == null)
continue;
var l_objParam = JSON.parse(l_strParam)
if (l_objParam.fileName == FileURL) {
return true;
}
}
return false;
}
}
//Office文件打开后,设置该文件属性:从服务端来的OA文件
function pSetOADocumentFlag(doc, params) {
if (!doc) {
return; //
}
var l_Param = params;
l_Param.isOA = EnumOAFlag.DocFromOA; //设置OA打开文档的标志
l_Param.SourcePath = doc.FullName; //保存OA的原始文件路径,用于保存时分析,是否进行了另存为操作
//console.log(l_Param.SourcePath);
if (doc) {
var l_p = JSON.stringify(l_Param);
//将OA文档标志存入系统变量对象保存
wps.PluginStorage.setItem(doc.DocID, l_p);
}
}
/**
* 作用:
* @param {*} suffix :文档后缀明:.pdf 或 .uot 或 .uof
* @param {*} doc
* @param {*} uploadPath
* @param {} FieldName : 上传到服务器端的字段名称,可由OA传入的参数设置
*
* 返回值:是否执行了上传操作,布尔值
*/
function handleFileAndUpload(suffix, doc, uploadPath, FieldName) {
var l_strChangeFileName = ""; // 转换格式后的文件名称
var l_strPath = ""; // 转换格式后的文件路径
var l_FieldName = FieldName;
if (!doc) {
return false;
}
if (!l_FieldName) {
l_FieldName = "file"; //默认情况下,设置为 file 字段名称
}
var l_DocSourcePath = doc.FullName; //保留当前文档明,在SaveAs使用后再保存回原来的文件明
//Sub ExportAsFixedFormat(OutputFileName As String, ExportFormat As WdExportFormat,
// [OpenAfterExport As Boolean = False],
// [OptimizeFor As WdExportOptimizeFor = wdExportOptimizeForPrint],
// [Range As WdExportRange = wdExportAllDocument], [From As Long = 1],
// [To As Long = 1], [Item As WdExportItem = wdExportDocumentContent],
// [IncludeDocProps As Boolean = False], [KeepIRM As Boolean = True],
// [CreateBookmarks As WdExportCreateBookmarks = wdExportCreateNoBookmarks],
// [DocStructureTags As Boolean = True], [BitmapMissingFonts As Boolean = True],
// [UseISO19005_1 As Boolean = False], [FixedFormatExtClassPtr])
// Const wdExportFormatPDF = 17 (&H11)
// Const wdExportFormatXPS = 18 (&H12)
//
//根据传入的 后缀文件名称进行不同的转换文档操作
switch (suffix.toLocaleLowerCase()) {
case '.pdf':
l_strPath = pGetValidDocTempPath(doc) + ".pdf"; //获取有效输出路径
wps.FileSystem.Remove(l_strPath); //先删除之前可能存在的临时文件
doc.ExportAsFixedFormat(l_strPath, wps.Enum&&wps.Enum.wdFormatPDF||17, true); //文档另存为PDF格式
l_strChangeFileName = doc.Name.split(".")[0] + ".pdf";
UploadFile(l_strChangeFileName, l_strPath, uploadPath, l_FieldName, OnChangeSuffixUploadSuccess, OnChangeSuffixUploadFail);
break;
case '.uof':
l_strPath = pGetValidDocTempPath(doc) + suffix;
wps.FileSystem.Remove(l_strPath); //先删除之前可能存在的临时文件
doc.ExportAsFixedFormat(l_strPath, wps.Enum&&wps.Enum.wdFormatOpenDocumentText||23, true); //转换文件格式
doc.SaveAs2(l_strPath);
l_strChangeFileName = doc.Name.split(".")[0] + suffix;
UploadFile(l_strChangeFileName, l_strPath, uploadPath, l_FieldName, OnChangeSuffixUploadSuccess, OnChangeSuffixUploadFail);
doc.SaveAs2(l_DocSourcePath); //保存回原来的文档内容
break;
case '.uot':
l_strPath = pGetValidDocTempPath(doc) + suffix;
wps.FileSystem.Remove(l_strPath); //先删除之前可能存在的临时文件
doc.ExportAsFixedFormat(l_strPath, wps.Enum&&wps.Enum.wdFormatOpenDocumentText||23, true);
doc.SaveAs2(l_strPath);
l_strChangeFileName = doc.Name.split(".")[0] + suffix;
UploadFile(l_strChangeFileName, l_strPath, uploadPath, l_FieldName, OnChangeSuffixUploadSuccess, OnChangeSuffixUploadFail);
doc.SaveAs2(l_DocSourcePath); //保存回原来的文档内容
break;
case '.ofd':
l_strPath = pGetValidDocTempPath(doc) + suffix;
wps.FileSystem.Remove(l_strPath); //先删除之前可能存在的临时文件
doc.ExportAsFixedFormat(l_strPath, wps.Enum&&wps.Enum.wdFormatOpenDocumentText||23, true);
doc.SaveAs2(l_strPath,102);
l_strChangeFileName = doc.Name.split(".")[0] + suffix;
UploadFile(l_strChangeFileName, l_strPath, uploadPath, l_FieldName, OnChangeSuffixUploadSuccess, OnChangeSuffixUploadFail);
doc.SaveAs2(l_DocSourcePath); //保存回原来的文档内容
break;
default:
l_strPath = pGetValidDocTempPath(doc) + suffix;
wps.FileSystem.Remove(l_strPath); //先删除之前可能存在的临时文件
doc.SaveAs2(l_strPath);
l_strChangeFileName = doc.Name.split(".")[0] + suffix;
UploadFile(l_strChangeFileName, l_strPath, uploadPath, l_FieldName, OnChangeSuffixUploadSuccess, OnChangeSuffixUploadFail);
doc.SaveAs2(l_DocSourcePath); //保存回原来的文档内容
break;
}
wps.FileSystem.Remove(l_strPath); //上载完成后,删除临时文件
return true;
}
/**
* 作用:获取一个有效的临时文档路径,用于保存转换格式后的文档
* @param {*} doc
*/
function pGetValidDocTempPath(doc) {
if (!doc) {
return;
}
if (doc.Path == "") { //对于不落地文档,文档路径为空
return wps.Env.GetTempPath()+"/"+doc.Name.split(".")[0];
} else {
return doc.FullName.split(".")[0]
}
}
/**
* 作用:转格式保存上传成功后,触发这个事件的回调
* @param {} response
*/
function OnChangeSuffixUploadSuccess(response) {
l_result = handleResultBody(response);
alert("文件转格式保存成功!");
}
/**
* 作用:转格式保存失败,触发失败事件回调
* @param {*} response
*/
function OnChangeSuffixUploadFail(response) {
var l_result = "";
l_result = handleResultBody(response);
alert("保存失败" + "\n" + +"系统返回数据:" + +JSON.stringify(l_result));
}
/**
* 解析返回response的参数
* @param {*} resp
* @return {*} body
*/
function handleResultBody(resp) {
var l_result = "";
if (resp.Body) {
//解析返回response的参数
}
return l_result;
}
/**
* 把OA文件的当前编辑内容,自动提交到OA后台
*/
function pAutoUploadToServer(p_Doc) {
if (!p_Doc) {
return;
}
/**
* 参数定义:OAAsist.UploadFile(name, path, url, field, "OnSuccess", "OnFail")
* 上传一个文件到远程服务器。
* name:为上传后的文件名称;
* path:是文件绝对路径;
* url:为上传地址;
* field:为请求中name的值;
* 最后两个参数为回调函数名称;
*/
var l_uploadPath = GetDocParamsValue(p_Doc, constStrEnum.uploadPath); // 文件上载路径
if (l_uploadPath == "") {
//wps.alert("系统未传入文件上载路径,不能执行上传操作!");
return;
}
var l_FieldName = GetDocParamsValue(p_Doc, constStrEnum.uploadFieldName); //上载到后台的字段名称
if (l_FieldName == "") {
l_FieldName = wps.PluginStorage.getItem(constStrEnum.DefaultUploadFieldName); // 默认为‘file’
}
var l_UploadName = GetDocParamsValue(p_Doc, constStrEnum.uploadFileName); //设置OA传入的文件名称参数
if (l_UploadName == "") {
l_UploadName = p_Doc.Name; //默认文件名称就是当前文件编辑名称
}
var l_DocPath = p_Doc.FullName; // 文件所在路径
if (pIsOnlineOADoc(p_Doc) == false) {
console.log("落地文档自动保存");
//对于本地磁盘文件上传OA,先用Save方法保存后,在上传
//设置用户保存按钮标志,避免出现禁止OA文件保存的干扰信息
wps.PluginStorage.setItem(constStrEnum.OADocUserSave, EnumDocSaveFlag.OADocSave);
p_Doc.Save(); //执行一次保存方法
//设置用户保存按钮标志
wps.PluginStorage.setItem(constStrEnum.OADocUserSave, EnumDocSaveFlag.NoneOADocSave);
//落地文档,调用UploadFile方法上传到OA后台
try {
//调用OA助手的上传方法
UploadFile(l_UploadName, l_DocPath, l_uploadPath, l_FieldName, OnAutoUploadSuccess, OnAutoUploadFail);
} catch (err) {
alert("上传文件失败!请检查系统上传参数及网络环境!");
}
} else {
console.log("不落地文档自动保存");
// 不落地的文档,调用 Document 对象的不落地上传方法
wps.PluginStorage.setItem(constStrEnum.OADocUserSave, EnumDocSaveFlag.OADocSave);
try {
//调用不落地上传方法
p_Doc.SaveAsUrl(l_UploadName, l_uploadPath, l_FieldName, "OnAutoUploadSuccess", "OnAutoUploadFail");
} catch (err) {}
wps.PluginStorage.setItem(constStrEnum.OADocUserSave, EnumDocSaveFlag.NoneOADocSave);
}
}
/**
* 作用:自动上传到OA后台成功后出发事件
*/
function OnAutoUploadSuccess(resp) {
return;
}
/**
* 作用:自动上传到OA后台成功后出发事件
*/
function OnAutoUploadFail(resp) {
return;
}
/**
* 按照定时器的时间,自动执行所有文档的自动保存事件
*/
function OnDocSaveByAutoTimer() {
var l_Doc;
var l_Count = 0
var l_docCounts = wps.WpsApplication().Documents.Count;
for (l_Count = 0; l_Count < l_docCounts; l_Count++) {
l_Doc = wps.WpsApplication().Documents.Item(l_Count);
if (l_Doc) {
if (pCheckIfOADoc(l_Doc) == true) { // 是否为OA文件
if (pISOADocReadOnly(l_Doc) == false) { // 是否为只读文档
//执行自动上传到OA服务器端的操作
pAutoUploadToServer(l_Doc);
//保存该文档对应的访问过程记录信息
}
}
}
}
}
/**
* 实现一个定时器
*/
function OpenTimerRun(funcCallBack) {
var l_mCount = 0; //设置一个计时器,按每分钟执行一次; 10分钟后重复执行
var l_timeID = 0; //用于保存计时器ID值
// 对间隔时间做处理
var l_AutoSaveToServerTime = wps.PluginStorage.getItem(constStrEnum.AutoSaveToServerTime);
if (l_AutoSaveToServerTime == 0) { // 设置为0则不启动定时器
l_timeID = wps.PluginStorage.getItem(constStrEnum.TempTimerID);
clearInterval(l_timeID);
return;
} else if (l_AutoSaveToServerTime < 3) {
l_AutoSaveToServerTime = 3;
}
l_timeID = setInterval(function() {
l_mCount = l_mCount + 1;
if (l_mCount > l_AutoSaveToServerTime) { //l_AutoSaveToServerTime 值由系统配置时设定,见pInitParameters()函数
l_mCount = 0;
funcCallBack(); //每隔l_AutoSaveToServerTime 分钟(例如10分钟)执行一次回调函数
}
}, 60000); //60000 每隔1分钟,执行一次操作(1000*60)
wps.PluginStorage.setItem(constStrEnum.TempTimerID, l_timeID); //保存计时器ID值
}
/**
* 从OA-web端点击套红头
* params : 需要存在以下参数
* 'insertFileUrl':'',获取红头模板接口
* 'bkInsertFile':'' ,正文书签
*/
function InsertRedHead(params) {
var wpsApp = wps.WpsApplication();
var activeDoc = wpsApp.ActiveDocument;
if (!activeDoc) {
alert('文档不存在,请先新建一个文档!');
return;
}
var bookmark = GetParamsValue(params, constStrEnum.bkInsertFile);
var strFile = GetParamsValue(params, constStrEnum.insertFileUrl);
if (strFile == "") {
alert("未获取到传入的红头模板URL路径,不能正常套红");
return;
}
if (bookmark == "") {
alert("获取到传入的正文书签,不能正常套红");
return;
}
pInsertRInedHead(activeDoc, strFile, bookmark);
}
/**
* 套红头
* doc :套红头的文档
* strFile :获取红头模板接口
* bookmark :,正文书签
*/
function pInsertRInedHead(doc, strFile, bookmark) {
var bookMarks = doc.Bookmarks;
if (bookMarks.Item("quanwen")) { // 当前文档存在"quanwen"书签时候表示已经套过红头
alert("当前文档已套过红头,请勿重复操作!");
return;
}
var wpsApp = wps.WpsApplication();
var activeDoc = wpsApp.ActiveDocument;
var selection = wpsApp.ActiveWindow.Selection;
// 准备以非批注的模式插入红头文件(剪切/粘贴等操作会留有痕迹,故先关闭修订)
activeDoc.TrackRevisions = false;
selection.WholeStory(); //选取全文
bookMarks.Add("quanwen", selection.Range)
selection.Cut();
selection.InsertFile(strFile);
if (bookMarks.Exists(bookmark)) {
var bookmark1 = bookMarks.Item(bookmark);
bookmark1.Range.Select(); //获取指定书签位置
var s = activeDoc.ActiveWindow.Selection;
s.Paste();
} else {
alert("套红头失败,您选择的红头模板没有对应书签:" + bookmark);
}
// 轮询插入书签
var elements = GetDocParamsValue(doc, constStrEnum.redFileElement);
if (elements != "") {
for (var key in elements) {
console.log(key + "----" + elements[key])
if (bookMarks.Exists(key)) {
// 直接插入
var eleBookmark = bookMarks.Item(key);
eleBookmark.Range.Text = elements[key];
}
}
}
// 恢复修订模式(根据传入参数决定)
var l_revisionCtrl = GetDocParamsValue(activeDoc, constStrEnum.revisionCtrl);
activeDoc.TrackRevisions = l_revisionCtrl == "" ? false : l_revisionCtrl.bOpenRevision;
//取消WPS关闭时的提示信息
wps.WpsApplication().DisplayAlerts = wps.Enum&&wps.Enum.wdAlertsNone||0;
}
/**
* 从OA-web端点击套红头
* doc : 需要存在以下属性
* 'insertFileUrl':'',获取红头模板接口
* 'bkInsertFile':'' ,正文书签
*/
function InsertRedHeadDoc(doc) { //插入红头
if (!doc) {
alert('文档不存在!');
return;
}
var bookmark = GetDocParamsValue(doc, constStrEnum.bkInsertFile);
var strFile = GetDocParamsValue(doc, constStrEnum.insertFileUrl);
if (strFile == "") {
alert("未获取到系统传入的红头模板URL路径,不能正常套红");
return;
}
if (bookmark == "") {
alert("套红头失败,您选择的红头模板没有正文书签!");
return;
}
pInsertRInedHead(doc, strFile, bookmark)
}
/**
* 打开本地文档,并插入文档
*/
function OpenLocalFile() {
var l_FileName = "";
//msoFileDialogFilePicker = 3
var l_FileDialog = wps.WpsApplication().FileDialog(3);
if (l_FileDialog.Show()) {
l_FileName = l_FileDialog.SelectedItems;
if (l_FileName.Count > 0) {
wps.WpsApplication().Selection.InsertFile(l_FileName.Item(1));
}
}
}
/**
* 作用:OA的正文备份按钮操作功能,把OA文件备份一份到指定的OA后台copyUrl路径中
*/
function OnUploadOABackupClicked() {
var doc = wps.WpsApplication().ActiveDocument;
if (!doc) {
alert("当前没有打开任何文档");
return;
}
var l_copyUrl = GetDocParamsValue(doc, constStrEnum.copyUrl);
var l_uploadFieldName = GetDocParamsValue(doc, constStrEnum.uploadFieldName);
if (!l_copyUrl) {
alert("系统未传入备份URL路径,不能执行备份!");
return;
}
if (!l_uploadFieldName) {
l_uploadFieldName = "file";
}
// 默认保存为新文档,走上传文档的接口
UploadFile(doc.Name, doc.FullName, l_copyUrl, l_uploadFieldName, OnBackupSuccess, OnBackupFail);
}
/**
* 备份成功后的回调
*/
function OnBackupSuccess() {
wps.alert("备份上传成功");
}
/**
* 备份失败后的回调
*/
function OnBackupFail() {
wps.alert("备份失败");
}

+ 146
- 0
test/oaassist/wps/js/common/func_oastarter.js Просмотреть файл

@@ -0,0 +1,146 @@
/**
* 在这个js中,集中处理来自OA的传入参数
*
*/
/**
* web页面调用WPS的方法入口
* * info参数结构
* info:[
* {
* '方法名':'方法参数',需要执行的方法
* },
* ...
* ]
* @param {*} info
*/
let testFuncs=null;
function dispatcher(info) {
var funcs = info.funcs;
wps.WpsApplication().Options.UseLocalUserInfo=true//修订时,不使用登录名
//解析参数
/**
* 分两种情况解析:
* 1、业务系统依赖客户端返回:做同步处理,直接在for循环中返回
*/
for (var index = 0; index < funcs.length; index++) {
var func = funcs[index];
for (var key in func) {
if (key === "GetDocStatus") {
return GetDocStatus(func[key])
} else if (key === "ExitWPS") {
ExitWPS(func[key])
}
}
}
/**
* 2、业务系统不依赖客户端返回:
* 做异步处理,先返回接收状态,再在setTimeout中做打开文档的一系列业务逻辑
*/
setTimeout(function(){
for (var index = 0; index < funcs.length; index++) {
testFuncs=funcs;
var func = funcs[index];
for (var key in func) {
func[key].isOA=true;
if (key === "OpenDoc") { // OpenDoc 属于普通的打开文档的操作方式,文档落地操作
OpenDoc(func[key]); //进入打开文档处理函数
} else if (key === "OnlineEditDoc") { //在线方式打开文档,属于文档不落地的方式打开
OnlineEditDoc(func[key]);
} else if (key === "NewDoc") {
OpenDoc(func[key]);
} else if (key === "UseTemplate") {
OpenDoc(func[key]);
} else if (key === "InsertRedHead") {
InsertRedHead(func[key]);
} else if (key === "taskPaneBookMark"){
taskPaneBookMark(func[key])
} else if (key === "NewOfficialDocument"){
return OpenDoc(func[key])
}
}
}
},100)
return {message:"ok", app:wps.WpsApplication().Name}
}
/**
* 获取活动文档的状态
*/
function GetDocStatus() {
let l_doc = wps.WpsApplication().ActiveDocument
if (l_doc && pCheckIfOADoc()) {//此方法还可根据需要进行扩展
return{
message: "GetDocStatus",
docstatus:{
words: l_doc.Words.Count,
saved: l_doc.Saved,
pages: l_doc.ActiveWindow.Panes.Item(1).Pages.Count
}
}
}
}
/**
* 关闭WPS活动文档并退出WPS进程
*/
function ExitWPS() {
//为了接下来的用户确认操作,先将WPS界面激活显示在最前
wps.WpsApplication().Activate();
let l_doc = wps.WpsApplication().ActiveDocument
if (l_doc && pCheckIfOADoc()) {//此方法还可根据需要进行扩展
l_doc.Close();
}
if(wps.confirm("要关闭WPS软件,请确认文档都已保存。\n点击确定后关闭WPS,点击取消继续编辑。")){
wps.WpsApplication().Quit();
}
}
/**
*
* @param {*} params OA端传入的参数
*/
function OnlineEditDoc(OaParams) {
if (OaParams.fileName == "") {
NewFile(OaParams);
} else {
//OA传来下载文件的URL地址,调用openFile 方法打开
OpenOnLineFile(OaParams);
}
}
///打开来自OA端传递来的文档
function OpenDoc(OaParams) {
if (OaParams.fileName == "") {
NewFile(OaParams);
} else {
//OA传来下载文件的URL地址,调用openFile 方法打开
OpenFile(OaParams);
}
}
function taskPaneBookMark(OaParams){
let filePath = OaParams.fileName
if (filePath == "")
return
OpenFile(OaParams);
//创建taskpane,只创建一次
let id = wps.PluginStorage.getItem(constStrEnum.taskpaneid)
if (id){
let tp = wps.GetTaskPane(id)
tp.Width = 300
tp.Visible = true
}
else{
let url = getHtmlURL("taskpane.html");
let tp = wps.CreateTaskPane(url, "书签操作")
if (tp){
tp.DockPosition = WPS_Enum.msoCTPDockPositionRight //这里可以设置taskapne是在左边还是右边
tp.Width = 300
tp.Visible = true
wps.PluginStorage.setItem(constStrEnum.taskpaneid, tp.ID)
}
}
}

+ 1431
- 0
test/oaassist/wps/js/common/func_tabcontrol.js
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 157
- 0
test/oaassist/wps/js/common/time.js Просмотреть файл

@@ -0,0 +1,157 @@
var MAX_DATE = 2958465 // about year 9999
var MAX_DATE_1904 = 2957003
// Half a second, expressed in days
var HALF_SECOND = (1.0 / 172800.0)
// Half a millisecond
var HALF_MILLISECOND = (1.0 / 2000.0)
// 从 0000/1/1 到 1900/1/1 的时间序数值
var SERIAL_BASE_NUM = 693959
// 从 0000/1/1 到 1904/1/1 的时间序数值
var SERIAL_BASE_NUM_1904 = 695421
// 指示是否假定 1900 年为润年(兼容 Excel)
var YEAR1900_ISLEAP = 0
// One-based array of days in year at month start
var _afxMonthDays =
[0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
var b1904 = false;
var bDisable1900Year = false;
function toTime(dtSrc, b1904) {
var tmDest = {};
var nDays = 0; // Number of days since Dec. 30, 1899
var nDaysAbsolute = 0; // Number of days since 1/1/0
var nSecsInDay = 0; // Time in seconds since midnight
var nMinutesInDay = 0; // Minutes in day
var n400Years = 0; // Number of 400 year increments since 1/1/0
var n400Century = 0; // Century within 400 year block (0,1,2 or 3)
var n4Years = 0; // Number of 4 year increments since 1/1/0
var n4Day = 0; // Day within 4 year block
// (0 is 1/1/yr1, 1460 is 12/31/yr4)
var n4Yr = 0; // Year within 4 year block (0,1,2 or 3)
var bLeap4 = true; // true if 4 year block includes leap year
var bIs1900Year = false; // true if this year is 1900
var dblDate = dtSrc; // tempory serial date
// Round to the second
if (0 == 0)
dblDate += ((dtSrc > 0.0) ? HALF_SECOND : -HALF_SECOND);
// If a valid date, then this conversion should not overflow
nDays = Math.floor(dblDate);
nDaysAbsolute = Math.floor(dblDate) + (b1904 ? SERIAL_BASE_NUM_1904 : SERIAL_BASE_NUM); // Add days from 1/1/0 to 12/30/1899
dblDate = Math.abs(dblDate);
var dblSecsInDay = (dblDate - Math.floor(dblDate)) * 86400.0;
nSecsInDay = Math.floor(dblSecsInDay);
// modified by tsingbo:
// Calculate the day of week (sun=0, mon=1...)
// -1 because 1/1/0 is Sat.
tmDest.tm_wday = Math.floor((nDaysAbsolute - 1) % 7);
if (!bDisable1900Year && !b1904 &&
nDaysAbsolute >= SERIAL_BASE_NUM &&
nDaysAbsolute < SERIAL_BASE_NUM + 367) {
bIs1900Year = true;
n4Day = nDaysAbsolute - SERIAL_BASE_NUM;
bLeap4 = true;
n400Years = 4;
n400Century = 3;
n4Yr = 0;
}
else {
// Leap years every 4 yrs except centuries not multiples of 400.
n400Years = Math.floor(nDaysAbsolute / 146097);
// Set nDaysAbsolute to day within 400-year block
nDaysAbsolute %= 146097;
// -1 because first century has extra day
n400Century = Math.floor((nDaysAbsolute - 1) / 36524);
// Non-leap century
if (n400Century != 0) {
// Set nDaysAbsolute to day within century
nDaysAbsolute = (nDaysAbsolute - 1) % 36524;
// +1 because 1st 4 year increment has 1460 days
n4Years = Math.floor((nDaysAbsolute + 1) / 1461);
if (n4Years != 0)
n4Day = Math.floor((nDaysAbsolute + 1) % 1461);
else {
bLeap4 = false;
n4Day = Math.floornDaysAbsolute;
}
}
else {
// Leap century - not special case!
n4Years = Math.floor(nDaysAbsolute / 1461);
n4Day = Math.floor(nDaysAbsolute % 1461);
}
if (bLeap4) {
// -1 because first year has 366 days
n4Yr = (n4Day - 1) / 365;
if (n4Yr != 0)
n4Day = (n4Day - 1) % 365;
}
else {
n4Yr = n4Day / 365;
n4Day %= 365;
}
}
// n4Day is now 0-based day of year. Save 1-based day of year, year number
tmDest.tm_yday = Math.floor(n4Day) + 1;
tmDest.tm_year = Math.floor(n400Years * 400 + n400Century * 100 + n4Years * 4 + n4Yr);
// Handle leap year: before, on, and after Feb. 29.
if (n4Yr == 0 && bLeap4) {
// Leap Year
if ((!bIs1900Year && n4Day == 59) ||
(bIs1900Year && n4Day == 60)) {
/* Feb. 29 */
tmDest.tm_mon = 2;
tmDest.tm_mday = 29;
}
else {
// Pretend it's not a leap year for month/day comp.
if (n4Day >= 60)
--n4Day;
}
} else {
// Make n4DaY a 1-based day of non-leap year and compute
// month/day for everything but Feb. 29.
if (!bIs1900Year)
++n4Day;
// Month number always >= n/32, so save some loop time */
for (tmDest.tm_mon = (n4Day >> 5) + 1;
n4Day > _afxMonthDays[tmDest.tm_mon]; tmDest.tm_mon++);
tmDest.tm_mday = Math.floor(n4Day - _afxMonthDays[tmDest.tm_mon - 1]);
}
if (nSecsInDay == 0)
tmDest.tm_hour = tmDest.tm_min = tmDest.tm_sec = 0;
else {
tmDest.tm_sec = Math.floor(nSecsInDay % 60);
nMinutesInDay = nSecsInDay / 60;
tmDest.tm_min = Math.floor(nMinutesInDay % 60);
tmDest.tm_hour = Math.floor(nMinutesInDay / 60);
}
return new Date(tmDest.tm_year, tmDest.tm_mon + 1, tmDest.tm_mday, tmDest.tm_mday, tmDest.tm_min, tmDest.tm_sec);
}

+ 12
- 0
test/oaassist/wps/js/main.js Просмотреть файл

@@ -0,0 +1,12 @@
//=======================依赖的第三方库=======================
var time=new Date().getTime()
document.write("<script language='javascript' src='otherslib/lib/jquery.min.js?time="+time+"'></script>");
document.write("<script language='javascript' src='otherslib/lib/formdata.js?time="+time+"'></script>");
//======================wps api常用枚举值=====================
document.write("<script language='javascript' src='js/common/enum.js?time="+time+"'></script>");
//=======================业务代码============================
document.write("<script language='javascript' src='js/common/common.js?time="+time+"'></script>");
document.write("<script language='javascript' src='js/common/func_oastarter.js?time="+time+"'></script>");
document.write("<script language='javascript' src='js/common/func_docProcess.js?time="+time+"'></script>");
document.write("<script language='javascript' src='js/common/func_tabcontrol.js?time="+time+"'></script>");
document.write("<script language='javascript' src='js/common/func_docEvents.js?time="+time+"'></script>");

+ 37
- 0
test/oaassist/wps/otherslib/lib/formdata.js Просмотреть файл

@@ -0,0 +1,37 @@
/**
* Emulate FormData for some browsers
* MIT License
* (c) 2010 François de Metz
*/
(function(w) {
if (w.FakeFormData)
return;
function FormData() {
this.fake = true;
this.boundary = "--------FormData" + Math.random();
this._fields = [];
}
FormData.prototype.append = function(key, value) {
this._fields.push([key, value]);
}
FormData.prototype.toString = function() {
var boundary = this.boundary;
var body = "";
this._fields.forEach(function(field) {
body += "--" + boundary + "\r\n";
// file upload
if (field[1].name) {
var file = field[1];
body += "Content-Disposition: form-data; name=\""+ field[0] +"\"; filename=\""+ file.name +"\"\r\n";
body += "Content-Type: "+ file.type +"\r\n\r\n";
body += file.getAsBinary() + "\r\n";
} else {
body += "Content-Disposition: form-data; name=\""+ field[0] +"\";\r\n\r\n";
body += field[1] + "\r\n";
}
});
body += "--" + boundary +"--";
return body;
}
w.FakeFormData = FormData;
})(window);

+ 6
- 0
test/oaassist/wps/otherslib/lib/jquery.min.js
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 1
- 0
test/oaassist/wps/otherslib/lib/qrcode.min.js
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 6
- 0
test/oaassist/wps/otherslib/lib/vue.min.js
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 142
- 0
test/oaassist/wps/redhead.html Просмотреть файл

@@ -0,0 +1,142 @@
<html>
<meta charset="utf-8">
<title>套用红头</title>
</head>
<body onload="getAllTemplelists()">
<script type="text/javascript" src='js/main.js'></script>
<div id="search">
<span>关键词:</span>
<input id="content" type="text" style="width:245px">
<button type="button" onClick="search()">查询</button>
<br />
<br />
</div>
<select id="templates" size=5 style='width:360px'>
<!--这里ajax动态拉取。-->
</select>
<br />
<br />
<button type="button" onClick="selectTemplate()">套红头</button>
</body>
</html>
<script>
function selectTemplate() {
var wpsApp = wps.WpsApplication();
var obj = document.getElementById("templates");
var index = obj.selectedIndex;
if (index == -1) { //添加未选中数据时的异常处理
alert("请先选择红头文件后再进行套红头!");
return;
}
var redId = obj.options[index].getAttribute("value");
var activeDoc = wpsApp.ActiveDocument;
var base = wps.PluginStorage.getItem("getRedHeadPath") || OA_DOOR.getRedHeadPath;
if (base == undefined) { //未配置则模拟服务端返回
SetDocParamsValue(activeDoc, "insertFileUrl", getDemoTemplatePath());
SetDocParamsValue(activeDoc, "bkInsertFile", "Content");
InsertRedHeadDoc(activeDoc);
window.opener = null;
window.open('', '_self', '');
window.close();
return
}
var path = base + redId;
SetDocParamsValue(activeDoc, "insertFileUrl", path);
InsertRedHeadDoc(activeDoc);
window.opener = null;
window.open('', '_self', '');
window.close();
}
//判断是否是word文档
function isWord(suffix) {
var suffixArray = ["doc", "dot", "wps", "wpt", "docx", "docm", "dotm"];
for (var f1 in suffixArray) {
if (suffixArray[f1].indexOf(suffix) > -1) {
return true;
}
}
return false;
}
function getAllTemplelists() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
//当接受到响应时回调该方法
if (xmlhttp.readyState == 4 && (xmlhttp.status == 200 || xmlhttp.status == 0)) {
var text = xmlhttp.responseText; //使用接口返回内容,响应内容
var resultJson = JSON.parse(text) //将json字符串转换成对象
for (var i = 0; i < resultJson.length; i++) {
var element = resultJson[i]
var myOption = document.createElement("option"); //动态创建option标签
var suffix = element.tempName.split('.')[1];
if (isWord(suffix)) {
myOption.value = element.tempId; //红头文档id
myOption.text = element.tempName; //红头文档名称
templates.add(myOption);
}
}
}
}
var redHeadsPath = wps.PluginStorage.getItem("redHeadsPath") || OA_DOOR.redHeadsPath
if (redHeadsPath == undefined) { //未配置则模拟服务端返回
var strData =
'[{"tempId":23,"tempName":"广东省xx局.docx"},{"tempId":24,"tempName":"广东省xx局 - 副本.docx"},{"tempId":25,"tempName":"红头.docx"}]'
resultJson = JSON.parse(strData);
for (var i = 0; i < resultJson.length; i++) {
var element = resultJson[i]
var myOption = document.createElement("option"); //动态创建option标签
var suffix = element.tempName.split('.')[1];
if (isWord(suffix)) {
myOption.value = element.tempId; //红头文档id
myOption.text = element.tempName; //红头文档名称
templates.add(myOption);
}
}
document.getElementById("search").style.display = "none";
return
}
xmlhttp.open("POST", redHeadsPath, true); //以POST方式请求该接口
xmlhttp.setRequestHeader("Content-type",
"application/x-www-form-urlencoded;charset=UTF-16LE"); //添加Content-type
xmlhttp.send(); //发送请求参数间用&分割
if (!wps.PluginStorage.getItem("searchRedHeadPath")) {
document.getElementById("search").style.display = "none";
}
}
function search() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
//当接受到响应时回调该方法
if (xmlhttp.readyState == 4 && (xmlhttp.status == 200 || xmlhttp.status == 0)) {
var text = xmlhttp.responseText; //使用接口返回内容,响应内容
var resultJson = JSON.parse(text) //将json字符串转换成对象
templates.options.length = 0;
for (var i = 0; i < resultJson.length; i++) {
var element = resultJson[i]
var myOption = document.createElement("option"); //动态创建option标签
myOption.value = element.tempId; //红头文档id
myOption.text = element.tempName; //红头文档名称
templates.add(myOption);
}
}
}
var searchPath = wps.PluginStorage.getItem("searchRedHeadPath") || OA_DOOR.redHeadsPath
var totalPath = searchPath + "?content=" + document.getElementById("content").value;
xmlhttp.open("get", totalPath, true); //以POST方式请求该接口
xmlhttp.setRequestHeader("Content-type",
"application/x-www-form-urlencoded;charset=UTF-16LE"); //添加Content-type
xmlhttp.send(); //发送请求参数间用&分割
}
</script>

+ 148
- 0
test/oaassist/wps/ribbon.xml Просмотреть файл

@@ -0,0 +1,148 @@
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnWPSWorkTabLoad">
<ribbon startFromScratch="false">
<tabs>
<!-- OA菜单开启显隐处理, insertBeforeMso表示要在WPS自身某个tab之前显示,insertAfterMso表示在某个WPS自身tab之后显示-->
<!--在如下的tab定义中,id是WPSWorkExtTab,显示标签是OA辅助,有控制显隐的事件设置getVisible,设置在「开始」(TabHome)页签之前-->
<tab id="WPSWorkExtTab" label="OA辅助" getVisible="OnGetVisible" insertBeforeMso="TabHome">
<group id="grpWPSClound" label="WPS云文档相关功能" getVisible="OnGetVisible">
<box id="boxBoxCloud1" boxStyle="horizontal" visible="true">
<button id="btnOpenWPSYUN" label="WPS云文档" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
</box>
<box id="boxBoxCloud1" boxStyle="horizontal" visible="true">
<button id="btnOpenLocalWPSYUN" label="导入文件" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
</box>
<separator id="sepWPSClound"/>
</group>
<group id="grpWPSWork" label="OA助手文档操作功能组" getVisible="OnGetVisible">
<button id="btnSaveToServer" label="保存到OAa" onAction="OnAction" getEnabled="OnGetEnabled" getImage="GetImage" size="large"/>
<button id="btnSaveAsFile" label="保存本地" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large" />
<box id="boxWPSWorkEx" boxStyle="vertical" visible="true">
<button id="btnChangeToPDF" label="转PDF上传" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
<button id="btnChangeToUOT" label="转UOT上传" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
<button id="btnChangeToOFD" label="转OFD上传" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
</box>
<separator id="sepWPSWork" getVisible="OnGetVisible" />
</group>
<group id="grpOAExtend" label="扩展功能组" getVisible="OnGetVisible">
<button id="btnInsertRedHeader" label="套红头" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
<button id="btnInsertSeal" label="印章" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large" />
<button id="btnUploadOABackup" label="备份正文" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
<button id="btnClearRevDoc" label="清稿" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large" />
<button id="btnInsertBookmark" label="导入书签" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large" />
<button id="btnImportTemplate" label="导入模板" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
<separator id="sepOAExtend" getVisible="OnGetVisible" />
</group>
<group id="grpRevision" label="OA修订功能按钮组" getVisible="OnGetVisible">
<box id="boxRevsion1" boxStyle="horizontal" visible="true">
<button id="btnOpenRevision" label="打开修订" onAction="OnAction" getLabel="OnGetLabel" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large" />
<button id="btnCloseRevision" label="关闭修订" onAction="OnAction" getLabel="OnGetLabel" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large" />
</box>
<box id="boxRevsion2" boxStyle="horizontal" visible="true">
<button id="btnAcceptAllRevisions" label="接收修订" getLabel="OnGetLabel" getEnabled="OnGetEnabled" getVisible="OnGetVisible" onAction="OnAction" getImage="GetImage" size="large" />
<button id="btnRejectAllRevisions" label="拒绝修订" getLabel="OnGetLabel" getEnabled="OnGetEnabled" getVisible="OnGetVisible" onAction="OnAction" getImage="GetImage" size="large" />
</box>
<separator id="sepWPSRevision" getVisible="OnGetVisible" />
</group>
<group id="grpFreqUsed" label="常用功能组" getVisible="OnGetVisible">
<box id="boxFreqUsed1" boxStyle="horizontal" visible="true">
<button id="btnInsertPic" label="插入图片" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
<button id="btnInsertDate" label="插入日期" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
<button id="btnPageSetup" label="页面设置" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
</box>
<box id="boxFreqUsed2" boxStyle="horizontal" visible="true">
<button id="btnInsertWater" label="插入水印" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
<button id="btnOpenScan" label="打开扫描仪" getLabel="OnGetLabel" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
<button id="btnQRCode" label="二维码" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
<button id="btnPrintDOC" label="打印设置" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
</box>
<separator id="sepWPSFreqUsed" getVisible="OnGetVisible" />
</group>
<group id="grpDocSource" label="文件来源" getVisible="OnGetVisible">
<box id="boxFileSource" boxStyle="horizontal" visible="true">
<labelControl id="lblDocSourceTitle" label="文件来源:" />
<button id="lblDocSourceValue" label="ddddd" onAction="OnAction" getLabel="OnGetLabel" />
</box>
<labelControl id="lblDocLandMode" label="" getLabel="OnGetLabel" getVisible="OnGetVisible" />
<box id="boxUserName" boxStyle="horizontal" visible="true">
<labelControl id="lblUserName" label="用户" getLabel="OnGetLabel" />
<button id="btnUserName" label="用户" onAction="OnAction" getLabel="OnGetLabel" />
</box>
</group>
<group id="grpNotice" label="通知消息" getVisible="OnGetVisible">
<box id="boxNotice" boxStyle="vertical" visible="true">
<button id="btnSendMessage1" label="执行业务系统函数handleOaFunc1" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
<button id="btnSendMessage2" label="执行业务系统函数handleOaFunc2" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
</box>
<button id="btnAddWebShape" label="插入活动对象" onAction="OnAction" getEnabled="OnGetEnabled" getVisible="OnGetVisible" getImage="GetImage" size="large"/>
</group>
</tab>
<!-- 在这里可以定义WPS自身的tab页签的一些行为,页签的getEnabled和getVisible等效,无onAction事件-->
<!-- 全集可以去open.wps.cn/docs/office的idMso列表查询-->
<!--WPS自身功能常见tab的idMso如下-->
<!--开始-->
<!-- <tab idMso="TabHome" getEnabled="OnGetEnabled"/> -->
<!--插入-->
<!-- <tab idMso="TabInsert" getEnabled="OnGetEnabled"/> -->
<!--页面布局-->
<!-- <tab idMso="TabPageLayoutWord" getEnabled="OnGetEnabled"/> -->
<!--引用-->
<!-- <tab idMso="TabReferences" getEnabled="OnGetEnabled"/> -->
<!--审阅-->
<!-- <tab idMso="TabReviewWord" getEnabled="OnGetEnabled"/> -->
<!--视图-->
<!-- <tab idMso="TabView" getEnabled="OnGetEnabled"/> -->
<!--章节 bug-->
<!-- <tab idMso="TabSection" getEnabled="OnGetEnabled"/> -->
<!--安全 bug-->
<!-- <tab idMso="TabSecurity" getEnabled="OnGetEnabled"/> -->
<!--开发工具-->
<!-- <tab idMso="TabDeveloper" getEnabled="OnGetEnabled"/> -->
<!--云服务 bug-->
<!-- <tab idMso="TabWorkSpace" getEnabled="OnGetEnabled"/> -->
</tabs>
</ribbon>
<commands>
<!-- idMso支持getEnabled和onAction,不支持visible属性和事件-->
<!-- 文档复制和剪切控制-->
<command idMso="Copy" getEnabled="OnGetEnabled" />
<command idMso="Cut" getEnabled="OnGetEnabled" />
<!-- 文档保存和另存控制-->
<command idMso="FileSave" getEnabled="OnGetEnabled" onAction="OnAction"/>
<command idMso="SaveAll" getEnabled="OnGetEnabled" />
<command idMso="FileSaveAsMenu" getEnabled="OnGetEnabled" onAction="OnAction"/>
<command idMso="FileSaveAs" getEnabled="OnGetEnabled" onAction="OnAction"/>
<command idMso="FileSaveAsPicture" getEnabled="OnGetEnabled" />
<command idMso="SaveAsPicture" getEnabled="OnGetEnabled" />
<command idMso="FileMenuSendMail" getEnabled="OnGetEnabled" />
<!-- 输出PDF控制-->
<command idMso="SaveAsPDF" getEnabled="OnGetEnabled"/>
<command idMso="FileSaveAsPDF" getEnabled="OnGetEnabled"/>
<command idMso="ExportToPDF" getEnabled="OnGetEnabled"/>
<command idMso="FileSaveAsPdfOrXps" getEnabled="OnGetEnabled"/>
<!-- 输出OFD控制-->
<command idMso="SaveAsOfd" getEnabled="OnGetEnabled"/>
<command idMso="FileSaveAsOfd" getEnabled="OnGetEnabled"/>
<!--文档打印控制-->
<command idMso="FilePrint" getEnabled="OnGetEnabled"/>
<command idMso="FilePrintMenu" getEnabled="OnGetEnabled"/>
<command idMso="FilePrintPreview" getEnabled="OnGetEnabled"/>
<!--文档修订控制-->
<command idMso="ReviewTrackChangesMenu" getEnabled="OnGetEnabled"/>
<command idMso="ReviewRejectChangeMenu" getEnabled="OnGetEnabled"/>
<command idMso="ReviewAcceptChangeMenu" getEnabled="OnGetEnabled"/>
<!--文档新建控制-->
<command idMso="FileNewMenu" getEnabled="OnGetEnabled" onAction="OnAction"/>
<command idMso="FileNew" getEnabled="OnGetEnabled" onAction="OnAction"/>
<command idMso="WindowNew" getEnabled="OnGetEnabled" onAction="OnAction"/>
<command idMso="FileNewBlankDocument" getEnabled="OnGetEnabled" onAction="OnAction"/>
</commands>
<contextMenus>
<contextMenu idMso="ContextMenuText">
<menu id="Menu_ContextMenuText" label="测试右键" visible="true">
<button id="ShowAlert_ContextMenuText" label="弹出一个警告框" onAction="OnAction" getImage="GetImage" visible="true"/>
</menu>
</contextMenu>
</contextMenus>
</customUI>

+ 195
- 0
test/oaassist/wps/selectBookmark.html Просмотреть файл

@@ -0,0 +1,195 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>自定义书签</title>
<meta charset="UTF-8">
<script type="text/javascript" src='js/main.js'></script>
<script type="text/javascript" src="otherslib/lib/vue.min.js"></script>
<style type="text/css">
* {
box-sizing: border-box;
}
/*清除浮动*/
.clear:after {
content: "";
display: block;
clear: both;
}
html,
body,
#bookmark {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.row {
width: 100%;
border-top: 2px solid #e7e7e7;
}
.row>div {
height: 100%;
}
#bk_select {
width: 100%;
padding-left: 5%;
}
.def_control {
height: 65%;
width: 100%;
font-size: 18px;
}
.btn_box {
width: 12%;
float: left;
line-height: 3.3em;
margin-left: 2%;
}
.btn_box:last-of-type {
float: right;
margin-right: 2%;
}
</style>
</head>
<body>
<div id="bookmark">
<div class="row" style="height:20%;padding-top: 3%;">
<div id="bk_select">
<span>书签名称:</span>
<select class="def_control" style="width: 80%;" v-model="bookItem" @change="vm.getBookMark()">
<option value="-1">请选择书签</option>
<option v-for="(item,index) in bookmarks" :value="index" :key="index">{{item.bookmarkname}}</option>
</select>
</div>
</div>
<div class="row" style="height: 65%;padding-top: 3%;">
<p id="showResult">请先从上方的下拉列表中选择指定书签后,再进行添加或删除操作!</p>
</div>
<div class="row clear" style="height: 15%;">
<div class="btn_box">
<button class="def_control" type="button" disabled="disabled" id="add" @click="vm.addBookMark()">添加</button>
</div>
<div class="btn_box">
<button class="def_control" type="button" disabled="disabled" id="del" @click="vm.delBookMark()">删除</button>
</div>
<div class="btn_box">
<button class="def_control" type="button" @click="vm.cancel()">取消</button>
</div>
</div>
</div>
</body>
</html>
<script>
var vm = new Vue({
el: "#bookmark",
data: {
bookmarks: [], // 书签下拉框数据
bookItem: -1, // 选中的书签下标
bookmarksign: "", // 书签对象
bookmarkname: "", // 书签名称
},
methods: {
cancel: function () { // 取消按钮
window.close();
wps.OAAssist.ShellExecute("ksowebstartupwps://"); // 将WPS程序置前
},
getAllBookMark: function () { // 加载下拉框数据
var doc = wps.WpsApplication().ActiveDocument;
var bookmarkData = GetDocParamsValue(doc, "bookmarkData");
if (typeof (bookmarkData) == undefined || bookmarkData == null || bookmarkData == "") {
// alert("未传入有效的书签数据,下拉框加载失败!");
// return;
bookmarkData=[{
bookmarksign:'bookmark1',
bookmarkname:"我是测试书签1"
},{
bookmarksign:'bookmark2',
bookmarkname:"我是测试书签2"
}]
}
this.bookmarks = bookmarkData; // 书签列表赋值
console.log("数据:" + vm.bookmarks);
},
getBookMark: function () { // 获取选中书签的信息并保存在vue中
// var _this = this;
var bookmarkindex = vm.bookItem; // 获取选中下拉框的坐标
if (bookmarkindex == -1) {
$("#showResult").html("请先从上方的下拉列表中选择指定书签后,再进行添加或删除操作!");
$("#add").attr('disabled', true);
$("#del").attr('disabled', true);
return;
}
vm.bookmarksign = vm.bookmarks[bookmarkindex].bookmarksign; // 选中书签对象的书签名
vm.bookmarkname = vm.bookmarks[bookmarkindex].bookmarkname; // 选中书签对象的内容
$("#showResult").html(""); // 隐藏文本
if (vm.bookmarksign != "" || vm.bookmarkname != "") { // 打开添加及删除按钮
$("#add").attr('disabled', false);
$("#del").attr('disabled', false);
}
},
addBookMark: function () { // 添加书签到文档中
if (vm.bookmarksign == "" || vm.bookmarkname == "") {
alert("书签不存在,操作失败");
return;
}
// 插入文字型窗体域
var wpsApp = wps.WpsApplication();
var doc = wpsApp.ActiveDocument;
var selection = wpsApp.ActiveWindow.Selection;
var range = selection.Range;
var fields = doc.FormFields;
fields.Shaded = true; // 显示底纹
var formField = fields.Add(range, wps.Enum&&wps.Enum.wdFieldFormTextInput||70);//枚举值兼容性写法,70为枚举表中wps.Enum.wdFieldFormTextInput的值
formField.Name = vm.bookmarksign; // 书签名称设置
formField.Result = vm.bookmarkname; // 窗体域的显示结果设置
//选中,主动触发刷新
wps.WpsApplication().ActiveDocument.Range(selection.Start,selection.Start).Select()
// 添加成功给予提示
$("#showResult").html("书签【" + vm.bookmarksign + "】添加成功!");
},
delBookMark: function () { // 删除书签
if (vm.bookmarksign == "") {
alert("书签标记不存在,操作失误");
return;
}
// 删除指定窗体域
var doc = wps.WpsApplication().ActiveDocument;
var fields = doc.FormFields;
var flag = false;
if (fields.Count > 0) {
for (var i = 1; i <= fields.Count; i++) {
var formField = fields.Item(i);
if (formField.Name == vm.bookmarksign) {
flag = true;
formField.Delete();
//选中,主动触发刷新
wps.WpsApplication().ActiveDocument.Range(selection.Start,selection.Start).Select()
}
}
}
if (flag) {
$("#showResult").html("书签【" + vm.bookmarksign + "】删除成功!");
} else {
alert("此书签不存在,请重新选择要删除的书签!");
}
}
},
created: function () {
this.getAllBookMark();
}
});
</script>

+ 205
- 0
test/oaassist/wps/selectSeal.html Просмотреть файл

@@ -0,0 +1,205 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>印章页面</title>
<script type="text/javascript" src='js/main.js'></script>
<script type="text/javascript" src="otherslib/lib/vue.min.js"></script>
<style type="text/css">
* {
box-sizing: border-box;
}
/*清除浮动*/
.clear:after {
content: "";
display: block;
clear: both;
}
html,
body,
#seal {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.row {
width: 100%;
border-top: 2px solid #e7e7e7;
}
.row>div {
height: 100%;
}
#seal_name,
#seal_password {
width: 38%;
float: left;
margin-left: 15px;
}
.seal_control {
height: 60%;
font-size: 16px;
}
#seal_load {
width: 13%;
float: right;
margin-right: 35px;
}
#seal_load>button {
width: 100%;
}
#btnBox {
padding-left: 75%;
line-height: 4em;
}
#btnBox>div {
display: inline-block;
width: 47%;
}
#btnBox button {
height: 60%;
width: 90%;
font-size: 14px;
}
</style>
</head>
<body>
<div id="seal">
<div class="row clear" style="height: 15%;padding-top: 2%;">
<div id="seal_name">
<span>印章名称:</span>
<select class="seal_control" v-model="sealItem" style="width: 60%;" @change="vm.loadSeal()">
<option value="-1">请选择印章</option>
<option v-for="(item,index) in seals" :key="index" :value="item.signatureID">{{item.MarkName}}</option>
</select>
</div>
<!-- <div id="seal_password">
<span>密码:</span>
<input class="seal_control" type="password" v-model="sealPassword" placeholder="请输入密码" />
</div>
<div id="seal_load">
<button class="seal_control" @click="vm.loadSeal()">盖章</button>
</div> -->
</div>
<div id="seal_preview" class="row" style="height: 70%;padding-top: 5%;overflow: auto;">
<img :src="seal" v-if="visible" style="width: 50%;height: 85%;" draggable="false">
</div>
<div id="btnBox" class="row" style="height: 15%;">
<div>
<button type="button" @click="vm.doSeal()">确定</button>
</div>
<div>
<button type="button" @click="vm.cancle()">取消</button>
</div>
</div>
</div>
</body>
</html>
<script>
var vm = new Vue({
el: "#seal",
data: {
seals: [], //印章下拉框数据
sealItem: -1, // 选中的印章
sealPassword: "", // 印章密码
seal: "", // 中间区域显示的印章图片路径
visible: false, // 是否显示中间区域的印章图片
picPath: "" // 印章图片路径(插入文档使用)
},
methods: {
// 取消按钮
cancle: function () {
window.close(); // 大概率引发WPS程序窗口最小化
wps.OAAssist.ShellExecute("ksowebstartupwps://"); // 将WPS程序置前
},
// 获取印章下拉框数据
getAllSeal: function () {
var l_doc = wps.WpsApplication().ActiveDocument;
var l_sealData = GetDocParamsValue(l_doc, "sealData");
if (typeof (l_sealData) == undefined || l_sealData == null || l_sealData == "") {
// alert("未传入有效的印章数据,下拉框加载失败!");
// return;
l_sealData=[{
MarkName:"测试印章1",
signatureID:1
},{
MarkName:"测试印章2",
signatureID:2
}]
}
this.seals = l_sealData;
console.log("数据:",l_sealData);
},
loadSeal: function () {
if (this.sealItem == "" || this.sealItem == -1) {
this.visible = false;
this.picPath = "";
this.seal = "";
alert("请选择印章!");
return;
}
//静态印章
this.visible = true;
this.picPath = getHtmlURL("template/OA模板公章.png");
this.seal = getHtmlURL("template/OA模板公章.png");
//后台获取 印章
// if (this.sealPassword == "") {
// alert("请输入密码!");
// return;
// }
// var doc = wps.WpsApplication().ActiveDocument;
// var url = GetDocParamsValue(doc, "validatePath");//印章验证接口
// if (url == "") {
// alert("未传入有效的印章验证URL,盖章失败!");
// return;
// }
// url += "&signatureID=" + this.sealItem + "&passwd=" + this.sealPassword;
// this.$http.get(url).then(function (res) {
// var data = res.body;
// if (data.code == "0") {
// this.visible = true;
// this.picPath = data.url;
// this.seal = this.picPath;
// } else {
// this.picPath = "";
// this.$Message.error(data.message);
// }
// }, function () {
// console.log("获取响应失败");
// });
},
doSeal: function () {
var l_doc = wps.WpsApplication().ActiveDocument;
if (!l_doc) {
return;
}
OnInsertPicToDoc(l_doc, this.picPath, 95, 95,()=>{
window.opener = null;
window.open('', '_self', '');
window.close();
}); // 调用插入图片函数
}
},
mounted: function () {
this.getAllSeal();
}
});
</script>

+ 34
- 0
test/oaassist/wps/setUserName.html Просмотреть файл

@@ -0,0 +1,34 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" ;>
<meta charset="utf-8">
<title>OA助手WPS用户名设置</title>
<script type="text/javascript" src="js/common/enum.js"></script>
<script type="text/javascript" src="js/common/common.js"></script>
<script type="text/javascript">
function changeUserName(){
var l_Name = document.getElementById("txtUserName").value
if (l_Name === "") {
alert("请输入有效的用户名称");
return;
}
wps.PluginStorage.setItem(constStrEnum.WPSInitUserName, l_Name);
SetDocParamsValue(wps.WpsApplication().ActiveDocument,"userName",l_Name)
pSetWPSAppUserName();
wps.UpdateRibbon("btnUserName")
//wps.WpsApplication().ActiveDocument.Activate();
window.close();
}
</script>
</head>
<body>
<p>请在下面输入WPS Office的用户名称:</p>
<hr>
<form method="POST" action="">
<p>WPS用户名:<input type="text" id="txtUserName" size="20"></p>
<p><input id="btnSet" type="button" value="确认" name="B1" onclick="changeUserName()"></p>
</form>
</body>
</html>

+ 143
- 0
test/oaassist/wps/taskpane.html Просмотреть файл

@@ -0,0 +1,143 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>操作书签</title>
<style type="text/css">
.content {
font-size: 15px;
color: darkslategray;
margin: 5px;
}
.content_red {
font-weight: bold;
color: red;
}
.li {
cursor: pointer;
color: blueviolet;
margin: 10px;
}
.def_control {
height: 100%;
width: 100%;
font-size: 18px;
}
.btn_box {
float: left;
line-height: 3.3em;
margin-left: 2%;
}
</style>
</head>
<body onload="bookMarkList()">
<script type="text/javascript" src='js/main.js'></script>
<div class="content">这是一个网页,按f12可以打开调试器</div>
<div class="content">书签列表如下:</div>
<div id="bookMarkDiv">
</div>
<div id="repleaseBookMarkDiv" class="content">
<div class="content">选择的书签是:</div>
<div class="content_red" id="selectBookMarkId"></div>
<div class="content">替换的内容是:</div>
<div class="content">
<textarea id="repleaseBookMarkContent" style="margin: 0px; width: 220px; height: 90px;"></textarea></div>
<div class="btn_box">
<button class="def_control" type="button" id="repleaseBookMarkButton"
onclick="repleaseBookMarkClick()">书签内容替换</button>
</div>
<div class="btn_box">
<button class="def_control" type="button" id="insertLocalFileButton"
onclick="insertLocalFileClick()">本地文件替换已选择书签</button>
</div>
</div>
</body>
</html>
<script>
wps.ApiEvent.AddApiEventListener("WindowActivate", onDocActiveChange) //当前文档切换后的事件回调通知
//当前文档切换到其它文档时,重新获取新的文档的书签列表
function onDocActiveChange(doc, docwin){
bookMarkList()
clearSelectionBookmark()
}
//获取文档中的书签列表并定义列表项的点击事件
function bookMarkList(){
let doc = wps.WpsApplication().ActiveDocument
if (!doc)
return
document.getElementById('bookMarkDiv').innerHTML = ""
let innerHtml = ""
let bookMarkCount = doc.Bookmarks.Count
for (let i = 1; i <= bookMarkCount; ++i) {
let bookMakrItem = doc.Bookmarks.Item(i)
let bookMarkName = bookMakrItem.Name
innerHtml = innerHtml + "<li class='li' onclick=\"bookMarkClick('" + bookMarkName + "')\">" + bookMarkName +
"</li>"
}
document.getElementById('bookMarkDiv').innerHTML = innerHtml
}
//书签列表项的点击事件
function bookMarkClick(bookMarkName) {
let doc = wps.WpsApplication().ActiveDocument
document.getElementById('selectBookMarkId').innerHTML = bookMarkName
if (!doc)
return
let bookMark = doc.Bookmarks.Item(bookMarkName)
if (bookMark)
bookMark.Range.Select()
}
//书签内容替换按钮点击事件
function repleaseBookMarkClick() {
getPositionInsert('text')
}
//本地文件替换已选择书签点击事件
function insertLocalFileClick() {
getPositionInsert('file')
}
//定位到选择的书签位置的最末,插入文本内容或本地文件
function getPositionInsert(textOrFile) {
let doc = wps.WpsApplication().ActiveDocument
let bookMarks = doc.Bookmarks
let selectBookMarkId = document.getElementById("selectBookMarkId").innerHTML
let textareaStr = document.getElementById("repleaseBookMarkContent").value
if (!doc)
return
if (selectBookMarkId.length == 0) {
alert('请选择需要替换的书签')
return
} else {
let bookMarkItem = bookMarks.Item(selectBookMarkId)
if (bookMarkItem) {
let bookMarkName = bookMarkItem.Name
let bookMarkRange = bookMarkItem.Range
if (textOrFile == 'text') {
bookMarkRange.Text = textareaStr
bookMarkRange.Select() //内容替换后不会刷新,让wps作一次刷新,这可能是wps的bug
} else {
OpenLocalFile()
}
//检测一下bookmark是不是失效了
if (!bookMarks.Item(bookMarkName)){
bookMarks.Add(bookMarkName, bookMarkRange)
}
bookMarkList() //执行完内容替换后刷新任务窗格的书签列表
}
}
}
//清空选择的书签
function clearSelectionBookmark(){
document.getElementById('selectBookMarkId').innerHTML = ''
}
</script>

Двоичные данные
test/oaassist/wps/template/OA模板公章.png Просмотреть файл

До После
Ширина: 300  |  Высота: 300  |  Размер: 10.0KB

Двоичные данные
test/oaassist/wps/template/模板.docx Просмотреть файл


Двоичные данные
test/oaassist/wps/template/红头文件.docx Просмотреть файл


+ 326
- 0
test/oaassist/wps/wps-addon-build/LICENSE Просмотреть файл

@@ -0,0 +1,326 @@
Copyright @ 2012-2019, Kingsoft office,All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, 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.
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.
************************************************************************************
QRCode.js
The MIT License (MIT)
---------------------
Copyright (c) 2012 davidshimjs
Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
************************************************************************************
Vue.js
The MIT License (MIT)
Copyright (c) 2013-present, Yuxi (Evan) You
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
************************************************************************************
bootstrap
The MIT License (MIT)
Copyright (c) 2011-2019 Twitter, Inc.
Copyright (c) 2011-2019 The Bootstrap Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
************************************************************************************
html5-formdata
MIT License
Copyright (c) 2010 François de Metz
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The MIT License (MIT)
************************************************************************************
iview
Copyright (c) 2016-present TalkingData
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT LICENSE
Copyright (c) 2015-present Alipay.com, https://www.alipay.com/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The MIT License (MIT)
Copyright (c) 2016 ElemeFE
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The MIT License (MIT)
Copyright (c) 2015 Koala
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The MIT License (MIT)
Copyright (c) 2016 vue-beauty
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2016-present, Airyland
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The MIT License (MIT)
Copyright (c) 2016 Drifty (http://drifty.com/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
The MIT License (MIT)
Copyright (c) 2015 greyby
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
************************************************************************************
jquery
Copyright JS Foundation and other contributors, https://js.foundation/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
************************************************************************************
zTree
The MIT License (MIT)
copyright (c) <2011> < hunter.z >
使用该许可证的软件被授予以下权限,免费,任何人可以得到这个软件及其相关文档的一个拷贝,并且经营该软件不受任何限制,包括无限制的使用、复制、修改、合并、出版、发行、发放从属证书、或者出售该软件的拷贝的权利。同时允许获得这些软件的用户享受这些权利,使其服从下面的条件:
以上的版权通知和权限通知应该包含在所有该软件的拷贝中或者是其他该软件的真实部分中。
该软件按本来的样子提供,没有任何形式的担保,不管是明确地或者暗含的,包含这些但是不受商业性质的担保的限制。适合一个特定的用途并且不受侵犯。作者和版权持有人在任何场合对使用该软件涉及的任何要求、损害或者其他责任都不应负责。不管它是正在起作用还是只是合同形式、民事侵权或是其他方式,如由它引起,在其作用范围内、与该软件有联系、该软件的使用或者有这个软件引起的其他行为。

+ 82
- 0
test/oaassist/wps/wps-addon-build/QRCode.html Просмотреть файл

@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>二维码生成</title>
<script type="text/javascript" src="./otherslib/lib/qrcode.min.js"></script>
<script type="text/javascript" src="./otherslib/lib/jquery.min.js"></script>
<style>
.box {
width: 110px;
height: 110px;
border: 1px solid #999;
}
#qrcode {
width: 100px;
height: 100px;
margin: 5px auto;
}
#tip{
font-size: 13px;
color: red;
}
</style>
</head>
<body>
<div class="box">
<div id="qrcode">
</div>
<img src="" id="imgData"></img>
</div>2+66
<input type="text" id="text" value="二维码文字"> &nbsp;<span id="tip"></span> <br>
<input type="button" id="btnMakeQRCode" value="生成二维码">
<input type="button" id="btnInsert" value="插入文档中">
</body>
<script>
var qrcode = new QRCode(document.getElementById("qrcode"), {
width : 100,//设置宽高
height : 100
});
document.getElementById('btnMakeQRCode').onclick = function () {
makeCode();
}
document.getElementById('btnInsert').onclick = function() {
let l_canvasImg = $("#qrcode").find("canvas")[0];
let l_DataURL = l_canvasImg.toDataURL("image/png");
//wps.WpsApplication().Selection.Goto();
let l_shapeQR=wps.WpsApplication().ActiveDocument.Shapes.AddBase64Picture(l_DataURL);
//l_shapeQR.Left =
l_shapeQR.Visible = true;
l_shapeQR.Select();
}
$("#text").on("blur", function () {
makeCode();
}).on("keydown", function (e) {
if (e.keyCode == 13) {
makeCode();
}
});
/**
*/
function makeCode () {
let elText = document.getElementById("text");
if (!elText.value) {
$("#tip").text("请输入二维码文字");
elText.focus();
return;
}
$("#tip").text("");
qrcode.makeCode(elText.value);
}
</script>
</html>

+ 27
- 0
test/oaassist/wps/wps-addon-build/README.md Просмотреть файл

@@ -0,0 +1,27 @@
## Welcome to WPS OAAssist Demo

### 这个项目是什么?

这个工程为WPS文字项目常见的OA场景集成下的WPS加载项——OA助手,项目使用了丰富的WPS API的功能,可以帮助大家能够快速理解并熟悉WPS加载项机制以及和浏览器调用交互的流程。

### 工程结构

* icon 图标文件。
* js WPS 加载项功能逻辑的js代码。
* otherslib vue,jQueryd等第三方库。
* template 示例模板文件。
* importTemplate.html 导入模板页面。
* index.html 加载项的默认加载页面。
* qrcode.html 插入二维码页面。
* redhead.html 插入红头页面。
* selectBookmark.html 插入标签页面。
* selectSeal.html 插入签章页面。
* setUserName.html 修改默认用户名页面。
* ribbon.xml 自定义选项卡配置。

### 注意事项

* 本工程只是演示demo
* 我们建议您结合具体的应用场景修改示例代码,这样更能够体现OA助手集成的应用场景
* 为了保护代码,建议对上线代码进行混淆
* 使用该工程的时候,必须要安装WPS专业版,请咨询QQ:3253920855

+ 19
- 0
test/oaassist/wps/wps-addon-build/icon/3.svg Просмотреть файл

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 21.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;" xml:space="preserve">
<style type="text/css">
.skinbaseDark{opacity:0.8;enable-background:new ;}
.skinthemeDark{fill:#5789D9;}
</style>
<path class="skinbaseDark" d="M13,23h-1.4c-0.1,0-0.2,0-0.3-0.1c-0.7-0.2-0.9-0.6-1.3-0.9l-5-5H1.6C0.7,17,0,16.3,0,15.4V8.6
C0,7.7,0.7,7,1.6,7H5l5-5c0.4-0.4,0.6-0.8,1.3-0.9C11.4,1,11.5,1,11.6,1H12l0,0l0,0h1c0.6,0,1,0.5,1,1v20C14,22.5,13.6,23,13,23z
M13,2.4C13,2.2,12.8,2,12.6,2H12c-0.5,0-0.9,0.2-1.1,0.4c0.1-0.1,0,0,0,0C10.8,2.6,7.3,6,5.3,8H1.6C1.3,8,1,8.3,1,8.6v6.8
C1,15.7,1.3,16,1.6,16h3.7c2,2,5.5,5.5,5.7,5.7c0.2,0.2,0.6,0.3,1,0.3h0.6c0.2,0,0.4-0.2,0.4-0.4V2.4z M10,2C10,2,9.9,2.1,10,2
C9.9,2,10,2,10,2z"/>
<path class="skinthemeDark" d="M18.5,20.9c-0.1,0.1-0.2,0.1-0.4,0.1c-0.3,0-0.5-0.2-0.5-0.5c0-0.2,0.1-0.4,0.3-0.5l0,0
c3-1.5,5.1-4.5,5.1-8.1s-2.1-6.6-5.1-8.1l0,0c-0.2-0.1-0.3-0.3-0.3-0.5c0-0.3,0.2-0.5,0.5-0.5c0.1,0,0.3,0.1,0.4,0.2
c3.3,1.6,5.5,5,5.5,8.9S21.8,19.3,18.5,20.9z M19,12c0,1.7-0.9,3.2-2.2,4.1c-0.1,0.1-0.2,0.2-0.4,0.2c-0.3,0-0.5-0.2-0.5-0.5
c0-0.2,0.1-0.4,0.3-0.5v0c1.1-0.7,1.8-1.9,1.8-3.3c0-1.4-0.7-2.6-1.8-3.3v0c-0.2-0.1-0.3-0.3-0.3-0.5c0-0.3,0.2-0.5,0.5-0.5
c0.2,0,0.3,0.1,0.4,0.2C18.1,8.8,19,10.3,19,12z"/>
</svg>

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/c_bookmark.png Просмотреть файл

До После
Ширина: 128  |  Высота: 128  |  Размер: 14KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/c_default.png Просмотреть файл

До После
Ширина: 230  |  Высота: 230  |  Размер: 2.5KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/c_printDoc.png Просмотреть файл

До После
Ширина: 200  |  Высота: 200  |  Размер: 1.5KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/c_seal.png Просмотреть файл

До После
Ширина: 210  |  Высота: 200  |  Размер: 2.0KB

+ 22
- 0
test/oaassist/wps/wps-addon-build/icon/newFromTemp.svg Просмотреть файл

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="21px" height="20px" viewBox="0 0 21 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 51.2 (57519) - http://www.bohemiancoding.com/sketch -->
<title>从模版新建</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Artboard" transform="translate(-31.000000, -26.000000)">
<g id="从模版新建" transform="translate(29.000000, 24.000000)">
<g id="Group" stroke-width="1">
<g id="新增节" transform="translate(2.000000, 2.000000)">
<path d="M19.9587402,10 L18.9587402,10 L18.9587402,2 C18.9587402,1.44771525 18.511025,1 17.9587402,1 L6.0300293,1 C5.47774455,1 5.0300293,1.44771525 5.0300293,2 L5.0300293,18 C5.0300293,18.5522847 5.47774455,19 6.0300293,19 L9.95874023,19 L9.95874023,20 L6.0300293,20 C4.9254598,20 4.0300293,19.1045695 4.0300293,18 L4.0300293,2 C4.0300293,0.8954305 4.9254598,2.02906125e-16 6.0300293,0 L17.9587402,0 C19.0633097,-2.02906125e-16 19.9587402,0.8954305 19.9587402,2 L19.9587402,10 Z" id="Combined-Shape" fill="#404040" fill-rule="nonzero"></path>
<path d="M6,1 L4,1 C3.44771525,1 3,1.44771525 3,2 L3,18 C3,18.5522847 3.44771525,19 4,19 L6,19 L6,20 L4,20 C2.8954305,20 2,19.1045695 2,18 L2,2 C2,0.8954305 2.8954305,2.02906125e-16 4,0 L6,0 L6,1 Z" id="Combined-Shape-Copy-2" fill="#404040" fill-rule="nonzero"></path>
<path d="M4,1 L2,1 C1.44771525,1 1,1.44771525 1,2 L1,18 C1,18.5522847 1.44771525,19 2,19 L4,19 L4,20 L2,20 C0.8954305,20 1.03797111e-16,19.1045695 0,18 L0,2 C-1.10284431e-16,0.8954305 0.8954305,2.02906125e-16 2,0 L4,0 L4,1 Z" id="Combined-Shape-Copy-3" fill="#404040" fill-rule="nonzero"></path>
<path d="M17,15 L20.5,15 C20.7761424,15 21,15.2238576 21,15.5 C21,15.7761424 20.7761424,16 20.5,16 L17,16 L17,19.5 C17,19.7761424 16.7761424,20 16.5,20 C16.2238576,20 16,19.7761424 16,19.5 L16,16 L12.5,16 C12.2238576,16 12,15.7761424 12,15.5 C12,15.2238576 12.2238576,15 12.5,15 L16,15 L16,11.5 C16,11.2238576 16.2238576,11 16.5,11 C16.7761424,11 17,11.2238576 17,11.5 L17,15 Z" id="Combined-Shape" fill="#5789D9"></path>
</g>
</g>
<rect id="Rectangle-15" fill="#404040" x="9" y="6" width="10" height="1"></rect>
</g>
</g>
</g>
</svg>

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_AcceptRev.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 1.8KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_BackDoc.png Просмотреть файл

До После
Ширина: 32  |  Высота: 32  |  Размер: 4.5KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_CloseRev.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 1.6KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_CloseRev1 (2).png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 861B

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_CloseRev3.png Просмотреть файл

До После
Ширина: 28  |  Высота: 24  |  Размер: 767B

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_DeleteRev.png Просмотреть файл

До После
Ширина: 16  |  Высота: 16  |  Размер: 610B

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_DocClear.png Просмотреть файл

До После
Ширина: 26  |  Высота: 31  |  Размер: 1.1KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_DocClound.png Просмотреть файл

До После
Ширина: 66  |  Высота: 48  |  Размер: 3.2KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_DocOFD.png Просмотреть файл

До После
Ширина: 39  |  Высота: 48  |  Размер: 2.3KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_DocQr.png Просмотреть файл

До После
Ширина: 16  |  Высота: 16  |  Размер: 834B

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_DocQr1.png Просмотреть файл

До После
Ширина: 16  |  Высота: 16  |  Размер: 1.1KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_DocRevis.png Просмотреть файл

До После
Ширина: 32  |  Высота: 32  |  Размер: 2.3KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_DocUOF.png Просмотреть файл

До После
Ширина: 39  |  Высота: 48  |  Размер: 2.2KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_GovDoc.png Просмотреть файл

До После
Ширина: 40  |  Высота: 40  |  Размер: 1.4KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_ImportDoc.png Просмотреть файл

До После
Ширина: 21  |  Высота: 24  |  Размер: 1.6KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_ImportDoc1.png Просмотреть файл

До После
Ширина: 27  |  Высота: 23  |  Размер: 1.1KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_InsDate.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 1.8KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_InsPicture.png Просмотреть файл

До После
Ширина: 20  |  Высота: 16  |  Размер: 1.1KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_InsPictures.png Просмотреть файл

До После
Ширина: 16  |  Высота: 16  |  Размер: 1.4KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_OpenRev.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 1.8KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_OpenRev2.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 2.0KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_PDF.png Просмотреть файл

До После
Ширина: 48  |  Высота: 48  |  Размер: 15KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_PageGear.png Просмотреть файл

До После
Ширина: 16  |  Высота: 16  |  Размер: 1.8KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_RejectRev.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 1.9KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_Save.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 14KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_SaveAs.png Просмотреть файл

До После
Ширина: 24  |  Высота: 24  |  Размер: 14KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_Scanner16.png Просмотреть файл

До После
Ширина: 16  |  Высота: 16  |  Размер: 1.3KB

Двоичные данные
test/oaassist/wps/wps-addon-build/icon/w_WPSCloud.png Просмотреть файл

До После
Ширина: 70  |  Высота: 47  |  Размер: 1.5KB

+ 173
- 0
test/oaassist/wps/wps-addon-build/importTemplate.html Просмотреть файл

@@ -0,0 +1,173 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>导入模板</title>
<meta charset="UTF-8">
<script type="text/javascript" src='js/main.js'></script>
<script type="text/javascript" src="otherslib/lib/vue.min.js"></script>
<style type="text/css">
* {
box-sizing: border-box;
}
/*清除浮动*/
.clear:after {
content: "";
display: block;
clear: both;
}
html,
body,
#template {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.row {
width: 100%;
border-top: 2px solid #e7e7e7;
}
.row>div {
height: 100%;
}
#file_select {
width: 100%;
padding-left: 5%;
}
.def_control {
height: 55%;
width: 100%;
font-size: 18px;
}
.btn_box {
width: 16%;
float: right;
line-height: 4.5em;
margin-right: 3%;
}
</style>
</head>
<body>
<div id="template">
<div class="row" style="height:50%;padding-top: 3%;">
<div id="file_select">
<span>文件名:</span>
<select class="def_control" style="width: 80%;" v-model="templateItem">
<option value="-1">请选择模板</option>
<option v-for="(item,key) in templates" :value="item.tempId" :key="key">{{item.tempName}}</option>
</select>
</div>
</div>
<div class="row" style="height: 50%;">
<div class="btn_box">
<button class="def_control" type="button" @click="cancel()">取消</button>
</div>
<div class="btn_box">
<button class="def_control" type="button" @click="OnImportTemplate()">导入</button>
</div>
</div>
</div>
</body>
</html>
<script>
/**
* 导入公文模板,并替换当前文档全部内容
* @param templateURL 模板路径
*/
function importTemlateFile(templateURL) {
var wpsApp = wps.WpsApplication();
var activeDoc = wpsApp.ActiveDocument;
if (!activeDoc) {
alert("文档不存在");
return;
}
var selection = wpsApp.ActiveWindow.Selection;
selection.WholeStory(); //选取全文
selection.Delete(); // 删除选中内容
selection.InsertFile(templateURL);
if (activeDoc.Revisions.Count > 0) { // 文档或区域中的修订
activeDoc.AcceptAllRevisions(); // 接受对指定文档的所有修订
}
}
// 获取选中项,拼接模板Url进行导入模板
function OnImportTemplate() {
var templateId = vm.templateItem;
console.log(vm);
if (templateId == -1) {
alert('请选中模板!!');
return;
}
// var p_Doc = wps.WpsApplication().ActiveDocument;
// var templatePath = GetDocParamsValue(p_Doc, "templatePath");
// if (templatePath == "") { templatePath = OA_DOOR.templateBaseURL; }
// var templateURL = templatePath + templateId;
var templateURL = getHtmlURL("template/模板.docx");
importTemlateFile(templateURL);
window.opener = null;
window.open('', '_self', '');
window.close();
wps.OAAssist.ShellExecute("ksowebstartupwps://");
}
function cancel() { // 取消按钮
window.close();
wps.OAAssist.ShellExecute("ksowebstartupwps://"); // 将WPS程序置前
}
var vm = new Vue({
el: "#template",
data: {
templateItem: -1,
templates: {}
},
methods: {
getAllTemplate: function () {
var _this = this
//通过接口拉取模板列表
// var p_Doc = wps.WpsApplication().ActiveDocument;
// var templateDataUrl = GetDocParamsValue(p_Doc, "templateDataUrl");
// if (templateDataUrl == "") { templateDataUrl = OA_DOOR.templateDataUrl; }
// $.ajax({
// url: templateDataUrl,
// async: false,
// method: "post",
// dataType: 'json',
// success: function (res) {
// _this.templates = res;
// console.log("模板列表数据:" + JSON.stringify(res));
// },
// error: function (res) {
// alert("获取响应失败");
// _this.templates = {}
// }
// });
//本地静态列表
this.templates=[{
tempName:'模板',
tempId:1
}]
}
},
mounted: function () {
this.getAllTemplate();
}
});
</script>

+ 5
- 0
test/oaassist/wps/wps-addon-build/index.html Просмотреть файл

@@ -0,0 +1,5 @@
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<script type="text/javascript" src="js/main.js"></script>
</html>

+ 535
- 0
test/oaassist/wps/wps-addon-build/js/common/common.js Просмотреть файл

@@ -0,0 +1,535 @@
// -------------------------- 通用常量 ---------------------------
//OA门户网站用接口,配置默认服务器接口
var OA_DOOR = {
templateDataUrl: undefined, //正文模板列表接口
templateBaseURL: undefined, //指定正文模板基础接口
redHeadsPath: undefined, //默认红头模板列表获取路径
getRedHeadPath: undefined, //默认获取红头文件路径
bookmarkPath: undefined, //书签列表接口
redHeadsPath: undefined, //默认红头模板列表获取路径
}
// -------------------------- 通用方法 ---------------------------
//去除字符串左边空格
String.prototype.ltrim = function () {
return this.replace(/(^\s*)/g, "");
}
//去除字符串右边空格
String.prototype.rtrim = function () {
return this.replace(/(\s*$)/g, "");
}
//扩展js string endwith,startwith方法
String.prototype.endWith = function (str) {
if (str == null || str == "" || this.length == 0 || str.length > this.length)
return false;
if (this.substring(this.length - str.length) == str)
return true;
else
return false;
}
String.prototype.startWith = function (str) {
if (str == null || str == "" || this.length == 0 || str.length > this.length)
return false;
if (this.substr(0, str.length) == str)
return true;
else
return false;
}
//UTF-16转UTF-8
function utf16ToUtf8(s) {
if (!s) {
return;
}
var i, code, ret = [],
len = s.length;
for (i = 0; i < len; i++) {
code = s.charCodeAt(i);
if (code > 0x0 && code <= 0x7f) {
//单字节
//UTF-16 0000 - 007F
//UTF-8 0xxxxxxx
ret.push(s.charAt(i));
} else if (code >= 0x80 && code <= 0x7ff) {
//双字节
//UTF-16 0080 - 07FF
//UTF-8 110xxxxx 10xxxxxx
ret.push(
//110xxxxx
String.fromCharCode(0xc0 | ((code >> 6) & 0x1f)),
//10xxxxxx
String.fromCharCode(0x80 | (code & 0x3f))
);
} else if (code >= 0x800 && code <= 0xffff) {
//三字节
//UTF-16 0800 - FFFF
//UTF-8 1110xxxx 10xxxxxx 10xxxxxx
ret.push(
//1110xxxx
String.fromCharCode(0xe0 | ((code >> 12) & 0xf)),
//10xxxxxx
String.fromCharCode(0x80 | ((code >> 6) & 0x3f)),
//10xxxxxx
String.fromCharCode(0x80 | (code & 0x3f))
);
}
}
return ret.join('');
}
var Base64 = {
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function(e) {
var t = "";
var n, r, i, s, o, u, a;
var f = 0;
e = Base64._utf8_encode(e);
while (f < e.length) {
n = e.charCodeAt(f++);
r = e.charCodeAt(f++);
i = e.charCodeAt(f++);
s = n >> 2;
o = (n & 3) << 4 | r >> 4;
u = (r & 15) << 2 | i >> 6;
a = i & 63;
if (isNaN(r)) {
u = a = 64
} else if (isNaN(i)) {
a = 64
}
t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a)
}
return t
},
decode: function(e) {
var t = "";
var n, r, i;
var s, o, u, a;
var f = 0;
e = e.replace(/[^A-Za-z0-9+/=]/g, "");
while (f < e.length) {
s = this._keyStr.indexOf(e.charAt(f++));
o = this._keyStr.indexOf(e.charAt(f++));
u = this._keyStr.indexOf(e.charAt(f++));
a = this._keyStr.indexOf(e.charAt(f++));
n = s << 2 | o >> 4;
r = (o & 15) << 4 | u >> 2;
i = (u & 3) << 6 | a;
t = t + String.fromCharCode(n);
if (u != 64) {
t = t + String.fromCharCode(r)
}
if (a != 64) {
t = t + String.fromCharCode(i)
}
}
t = Base64._utf8_decode(t);
return t
},
_utf8_encode: function(e) {
e = e.replace(/rn/g, "n");
var t = "";
for (var n = 0; n < e.length; n++) {
var r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r)
} else if (r > 127 && r < 2048) {
t += String.fromCharCode(r >> 6 | 192);
t += String.fromCharCode(r & 63 | 128)
} else {
t += String.fromCharCode(r >> 12 | 224);
t += String.fromCharCode(r >> 6 & 63 | 128);
t += String.fromCharCode(r & 63 | 128)
}
}
return t
},
_utf8_decode: function(e) {
var t = "";
var n = 0;
var r = c1 = c2 = 0;
while (n < e.length) {
r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r);
n++
} else if (r > 191 && r < 224) {
c2 = e.charCodeAt(n + 1);
t += String.fromCharCode((r & 31) << 6 | c2 & 63);
n += 2
} else {
c2 = e.charCodeAt(n + 1);
c3 = e.charCodeAt(n + 2);
t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
n += 3
}
}
return t
}
}
//UTF-8转UTF-16
function utf8ToUtf16(s) {
if (!s) {
return;
}
var i, codes, bytes, ret = [],
len = s.length;
for (i = 0; i < len; i++) {
codes = [];
codes.push(s.charCodeAt(i));
if (((codes[0] >> 7) & 0xff) == 0x0) {
//单字节 0xxxxxxx
ret.push(s.charAt(i));
} else if (((codes[0] >> 5) & 0xff) == 0x6) {
//双字节 110xxxxx 10xxxxxx
codes.push(s.charCodeAt(++i));
bytes = [];
bytes.push(codes[0] & 0x1f);
bytes.push(codes[1] & 0x3f);
ret.push(String.fromCharCode((bytes[0] << 6) | bytes[1]));
} else if (((codes[0] >> 4) & 0xff) == 0xe) {
//三字节 1110xxxx 10xxxxxx 10xxxxxx
codes.push(s.charCodeAt(++i));
codes.push(s.charCodeAt(++i));
bytes = [];
bytes.push((codes[0] << 4) | ((codes[1] >> 2) & 0xf));
bytes.push(((codes[1] & 0x3) << 6) | (codes[2] & 0x3f));
ret.push(String.fromCharCode((bytes[0] << 8) | bytes[1]));
}
}
return ret.join('');
}
function currentTime() {
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var ss = now.getSeconds();
var clock = year + "";
if (month < 10)
clock += "0";
clock += month + "";
if (day < 10)
clock += "0";
clock += day + "";
if (hh < 10)
clock += "0";
clock += hh + "";
if (mm < 10) clock += '0';
clock += mm;
if (ss < 10) clock += '0';
clock += ss;
return (clock);
}
/**
* 获取文件路径
* @param {*} html 文件全称
*/
function getHtmlURL(html) {
//弹出辅助窗格框
var GetUrlPath = ()=> {
var e = document.location.toString();
return -1 != (e = decodeURI(e)).indexOf("/") && (e = e.substring(0, e.lastIndexOf("/"))), e
}
var url = GetUrlPath();
if (url.length != 0) {
url = url.concat("/" + html);
} else {
url = url.concat("./" + html);
}
return url;
}
/**
* wps内弹出web页面
* @param {*} html 文件名
* @param {*} title 窗口标题
* @param {*} hight 窗口高
* @param {*} width 窗口宽
*/
function OnShowDialog(html, title, height, width, bModal) {
var l_ActiveDoc = wps.WpsApplication().ActiveDocument;
if (!l_ActiveDoc) {
alert("WPS当前没有可操作文档!")
return;
}
if (typeof bModal == "undefined" || bModal == null) {
bModal = true;
}
width *= window.devicePixelRatio;
height *= window.devicePixelRatio;
var url = getHtmlURL(html);
wps.ShowDialog(url, title, height, width, bModal);
}
/**
* 解析返回response的参数
* @param {*} resp
* @return {*} body
*/
function handleResultBody(resp) {
var result = "";
if (resp.Body) {
// 解析返回response的参数
}
return result;
}
/**
* 判断WPS中的文件个数是否为0,若为0则关闭WPS函数
* @param {*} name
*/
function closeWpsIfNoDocument() {
var wpsApp = wps.WpsApplication();
var docs = wpsApp.Documents;
if (!docs || docs.Count == 0) {
wps.ApiEvent.Cancel = true;
//根据业务可以选择是否退出进程 wpsApp.Quit();
}
}
function activeTab() {
//启动WPS程序后,默认显示的工具栏选项卡为ribbon.xml中某一tab
if (wps.ribbonUI)
wps.ribbonUI.ActivateTab('WPSWorkExtTab');
}
function showOATab() {
wps.PluginStorage.setItem("ShowOATabDocActive", pCheckIfOADoc()); //根据文件是否为OA文件来显示OA菜单
wps.ribbonUI.Invalidate(); // 刷新Ribbon自定义按钮的状态
}
function getDemoTemplatePath() {
var url = document.location.toString();
url = decodeURI(url);
if (url.indexOf("/") != -1) {
url = url.substring(0, url.lastIndexOf("/"));
}
if (url.length !== 0)
url = url.concat("/template/红头文件.docx");
if (url.startsWith("file:///"))
url = url.substr("file:///".length);
return url;
}
function getDemoSealPath() {
var url = document.location.toString();
url = decodeURI(url);
if (url.indexOf("/") != -1) {
url = url.substring(0, url.lastIndexOf("/"));
}
if (url.length !== 0)
url = url.concat("/template/OA模板:公章.png");
if (url.startsWith("file:///"))
url = url.substr("file:///".length);
return url;
}
function pGetParamName(data, attr) {
var start = data.indexOf(attr);
data = data.substring(start + attr.length);
return data;
}
/**
* 从requst中获取文件名(确保请求中有filename这个参数)
* @param {*} request
* @param {*} url
*/
function pGetFileName(request, url) {
var disposition = request.getResponseHeader("Content-Disposition");
var filename = "";
if (disposition) {
var matchs = pGetParamName(disposition, "filename=");
if (matchs) {
filename = decodeURIComponent(matchs);
} else {
filename = "petro" + Date.getTime();
}
} else {
filename = url.substring(url.lastIndexOf("/") + 1);
filename=filename.split("?")[0]
}
return filename;
}
function StringToUint8Array(string) {
var binLen, buffer, chars, i, _i;
binLen = string.length;
buffer = new ArrayBuffer(binLen);
chars = new Uint8Array(buffer);
for (var i = 0; i < binLen; ++i) {
chars[i] = String.prototype.charCodeAt.call(string, i);
}
return buffer;
}
/**
* WPS下载文件到本地打开(业务系统可根据实际情况进行修改)
* @param {*} url 文件流的下载路径
* @param {*} callback 下载后的回调
*/
function DownloadFile(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
//需要业务系统的服务端在传递文件流时,确保请求中的参数有filename
var fileName = pGetFileName(xhr, url)
//落地打开模式下,WPS会将文件下载到本地的临时目录,在关闭后会进行清理
var path = wps.Env.GetTempPath() + "/" + fileName
var reader = new FileReader();
reader.onload = function () {
wps.FileSystem.writeAsBinaryString(path, reader.result);
callback(path);
};
reader.readAsBinaryString(xhr.response);
}
}
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
}
/**
* WPS上传文件到服务端(业务系统可根据实际情况进行修改,为了兼容中文,服务端约定用UTF-8编码格式)
* @param {*} strFileName 上传到服务端的文件名称(包含文件后缀)
* @param {*} strPath 上传文件的文件路径(文件在操作系统的绝对路径)
* @param {*} uploadPath 上传文件的服务端地址
* @param {*} strFieldName 业务调用方自定义的一些内容可通过此字段传递,默认赋值'file'
* @param {*} OnSuccess 上传成功后的回调
* @param {*} OnFail 上传失败后的回调
*/
function UploadFile(strFileName, strPath, uploadPath, strFieldName, OnSuccess, OnFail) {
var xhr = new XMLHttpRequest();
xhr.open('POST', uploadPath);
var fileData = wps.FileSystem.readAsBinaryString(strPath);
var data = new FakeFormData();
if (strFieldName == "" || typeof strFieldName == "undefined"){//如果业务方没定义,默认设置为'file'
strFieldName = 'file';
}
data.append(strFieldName, {
name: utf16ToUtf8(strFileName), //主要是考虑中文名的情况,服务端约定用utf-8来解码。
type: "application/octet-stream",
getAsBinary: function () {
return fileData;
}
});
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200)
OnSuccess(xhr.response)
else
OnFail(xhr.response);
}
};
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
if (data.fake) {
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + data.boundary);
var arr = StringToUint8Array(data.toString());
xhr.send(arr);
} else {
xhr.send(data);
}
}
/**
* 打开WPS后通知到业务系统,可根据需求扩展
* @param {*} p_Url 业务方接受请求的地址
*/
function NotifyToServer(p_Url) {
$.ajax({
url: p_Url, // URL + '/wps/wpsCanOpen',
async: true,
method: "post",
dataType: 'json'
});
}
/**
* 更新编辑状态
* @param {*} p_Url 要传入OA端,通知业务系统,当前文档所处的编辑状态的URL地址路径
* @param {*} p_OpenUrl 当前文档从业务系统打开时的入口URL,这个URL包含业务系统开发者需要传入的ID等参数
* @param {*} docId 文档id
* @param {*} state 0-正在编辑中 1-文件保存 2-文件关闭 状态可根据需要进行自定义扩展
*/
function UpdateEditState(p_Url, p_OpenUrl, docId, state) {
var formData = {
"openUrl": p_OpenUrl,
"docId": docId,
"state": state
};
$.ajax({
url: p_Url, //URL + '/document/stateMonitor',
async: false,
data: formData,
method: "post",
dataType: 'json',
success: function (response) {
if (response == "success") {
console.log(response);
}
},
error: function (response) {
console.log(response);
}
});
}
/**
* 作用:判断文档关闭后,如果系统已经没有打开的文档了,则设置回初始用户名
*/
function pSetWPSAppUserName() {
//文档全部关闭的情况下,把WPS初始启动的用户名设置回去
if (wps.WpsApplication().Documents.Count == 1) {
var l_strUserName = wps.PluginStorage.getItem(constStrEnum.WPSInitUserName);
wps.WpsApplication().UserName = l_strUserName;
}
}
/**
* 设置文档参数的属性值
* @param {*} Doc
* @param {*} Key
* @param {*} Value
*/
function SetDocParamsValue(Doc, Key, Value) {
if (!Doc || !Key) {
return;
}
var l_Params = wps.PluginStorage.getItem(Doc.DocID);
if (!l_Params) {
return;
}
var l_objParams = JSON.parse(l_Params);
if (!(typeof(l_objParams) == "undefined")) {
l_objParams[Key] = Value;
}
//把属性值整体再写回原来的文档ID中
wps.PluginStorage.setItem(Doc.DocID, JSON.stringify(l_objParams));
}

Некоторые файлы не были показаны из-за большого количества измененных файлов

Загрузка…
Отмена
Сохранить