ws_inp.jsp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. <%@ page language="java" pageEncoding="UTF-8" isELIgnored="false" %>
  2. <%@ taglib uri="/ssTag" prefix="ss"%>
  3. <% pageContext.setAttribute(ss.page.PageC.PAGE_objName,"ws");%>
  4. <%pageContext.setAttribute("wdpageinformation","{'hastab':'0'}");%>
  5. <!DOCTYPE html>
  6. <!-- 引入必要的JavaScript库 -->
  7. <script type="text/javascript" src="/ss/jquery/jquery1.11.3.min.js"></script>
  8. <script type="text/javascript" src="/ss/jquery/jquery.form.min.js"></script>
  9. <script type="text/javascript" src="/ss/js/upload.js"></script>
  10. <div class='content-div' ssFith="true">
  11. <table class='form'>
  12. <tr>
  13. <th>上传原件</th>
  14. <td>
  15. <!-- 上传按钮 - upload.js会绑定点击事件 -->
  16. <input type="button" id="scyjEdit" class="content-button" value="选择文件..."/>
  17. <!-- 文件信息显示区域 - upload.js必需的元素 -->
  18. <span id="scyjBaseName" class="file-info"></span>
  19. <!-- 操作按钮区域 - upload.js控制显示/隐藏 -->
  20. <span class="file-action">
  21. <button id="checkScyj" style="display:none;" onclick="checkFile('scyj')">查看</button>
  22. <button id="qxScyj" style="display:none;" onclick="uploadFileClean('scyj')">删除</button>
  23. </span>
  24. </td>
  25. <th>上传后路径</th>
  26. <td>
  27. <!-- upload.js上传成功后会将路径填充到这里 -->
  28. <input mc="mc" name="scyjwj" id="scyjpath" value="" style="width: 300px;"/>
  29. <!-- 隐藏的文件名输入框,upload.js需要 -->
  30. <input type="hidden" name="scyjBaseName" value=""/>
  31. </td>
  32. <td>
  33. <input id="path" name='uploadPath' style="width: 200px;"/>
  34. </td>
  35. </tr>
  36. <!-- 新增:生成原件行 -->
  37. <tr>
  38. <th>生成原件</th>
  39. <td colspan="4">
  40. <input type="button" id="generateDocumentBtn" class="content-button" value="生成原件"
  41. onclick="generateOfficialDocument()"
  42. style="background-color: #1890ff; color: white; border: 1px solid #1890ff;"/>
  43. <span id="generateStatus" style="margin-left: 10px; color: #666; font-size: 12px;"></span>
  44. </td>
  45. </tr>
  46. <!-- Vue 桥接 API 测试按钮(可删除) -->
  47. <tr>
  48. <th>桥接API测试</th>
  49. <td colspan="4">
  50. <b>编辑器操作:</b><br/>
  51. <input type="button" class="content-button" value="读取内容"
  52. onclick="readEditorContent()"
  53. style="margin: 2px 5px 2px 0;"/>
  54. <input type="button" class="content-button" value="写入示例"
  55. onclick="writeEditorContent()"
  56. style="margin: 2px 5px 2px 0;"/>
  57. <input type="button" class="content-button" value="清空编辑器"
  58. onclick="clearEditorWithConfirm()"
  59. style="margin: 2px 5px 2px 0;"/>
  60. <br/>
  61. <b>普通字段:</b><br/>
  62. <input type="button" class="content-button" value="读取标题"
  63. onclick="alert('标题: ' + (readFormTitle() || '未填写'))"
  64. style="margin: 2px 5px 2px 0;"/>
  65. <input type="button" class="content-button" value="设置标题"
  66. onclick="setFormTitle()"
  67. style="margin: 2px 5px 2px 0;"/>
  68. <br/>
  69. <b>下拉框操作:</b><br/>
  70. <input type="button" class="content-button" value="读取文书类别"
  71. onclick="readDocumentType()"
  72. style="margin: 2px 5px 2px 0;"/>
  73. <input type="button" class="content-button" value="随机设置文书类别"
  74. onclick="setDocumentType()"
  75. style="margin: 2px 5px 2px 0;"/>
  76. <input type="button" class="content-button" value="自动匹配文书类别"
  77. onclick="autoSelectDocumentType()"
  78. style="margin: 2px 5px 2px 0;"/>
  79. <br/>
  80. <b>批量操作:</b><br/>
  81. <input type="button" class="content-button" value="读取所有下拉框"
  82. onclick="readAllDropdowns()"
  83. style="margin: 2px 5px 2px 0;"/>
  84. <input type="button" class="content-button" value="批量设置数据"
  85. onclick="batchSetFormData()"
  86. style="margin: 2px 5px 2px 0;"/>
  87. <input type="button" class="content-button" value="读取完整表单"
  88. onclick="readFullFormData()"
  89. style="margin: 2px 5px 2px 0;"/>
  90. <br/>
  91. <span style="color: #999; font-size: 12px;">详见函数定义及 /docs/普通JS读写Vue数据方法.md</span>
  92. </td>
  93. </tr>
  94. <tr>
  95. <th>文书类别</th>
  96. <td>
  97. <script>
  98. ss.dom.formElemConfig.wslbm={val:'${ws.wslbm}',type:window.ss.dom.TYPE.OBJP};
  99. </script>
  100. <ss-objp
  101. :opt="wslbmOption"
  102. placeholder="请选择文书类别"
  103. :inp="false"
  104. url="<ss:serv name='loadObjpOpt' parm='{"objectpickerdropdown1":"1"}' />"
  105. cb="wslb"
  106. v-model="wslbm"
  107. name="wslbm"
  108. :readonly="false"
  109. style="width: 200px;"
  110. >
  111. </ss-objp>
  112. </td>
  113. <th>密级</th>
  114. <td>
  115. <script>
  116. ss.dom.formElemConfig.wsmjm={val:'${ws.wsmjm}',type:window.ss.dom.TYPE.OBJP};
  117. </script>
  118. <ss-objp
  119. :opt="wsmjmOption"
  120. placeholder="请选择文书密级"
  121. :inp="false"
  122. url="<ss:serv name='loadObjpOpt' parm='{"objectpickerdropdown1":"1"}' />"
  123. cb="wsmj"
  124. v-model="wsmjm"
  125. name="wsmjm"
  126. :readonly="false"
  127. style="width: 200px;"
  128. >
  129. </ss-objp>
  130. </td>
  131. </tr>
  132. <tr>
  133. <th>范围</th>
  134. <td>
  135. <script>
  136. ss.dom.formElemConfig.wsfwm={val:'${ws.wsfwm}',type:window.ss.dom.TYPE.OBJP};
  137. </script>
  138. <ss-objp
  139. :opt="wsfwmOption"
  140. placeholder="请选择文书范围"
  141. :inp="false"
  142. url="<ss:serv name='loadObjpOpt' parm='{"objectpickerdropdown1":"1"}' />"
  143. cb="wsfw"
  144. v-model="wsfwm"
  145. name="wsfwm"
  146. :readonly="false"
  147. style="width: 200px;"
  148. >
  149. </ss-objp>
  150. </td>
  151. <th>管理类别</th>
  152. <td>
  153. <script>
  154. ss.dom.formElemConfig.gllbm={val:'${ws.gllbm}',type:window.ss.dom.TYPE.OBJP};
  155. </script>
  156. <ss-objp
  157. :opt="gllbmOption"
  158. placeholder="请选择管理类别"
  159. :inp="false"
  160. url="<ss:serv name='loadObjpOpt' parm='{"objectpickerdropdown1":"1"}' />"
  161. cb="gllb"
  162. v-model="gllbm"
  163. name="gllbm"
  164. :readonly="false"
  165. style="width: 200px;"
  166. >
  167. </ss-objp>
  168. </td>
  169. </tr>
  170. <tr>
  171. <th>标题</th>
  172. <td colspan="3">
  173. <%--自动生成:ws.bt--%>
  174. <script>
  175. ss.dom.formElemConfig.bt={val:'<ss:txt val='${ws.bt}'/>',type:window.ss.dom.TYPE.INPUT};
  176. </script>
  177. <ss-inp
  178. placeholder="请输入标题"
  179. v-model="bt"
  180. name="bt"
  181. :readonly="false"
  182. style="width: 100%;"
  183. >
  184. </ss-inp>
  185. </td>
  186. </tr>
  187. <tr>
  188. <th>摘要</th>
  189. <td colspan="3">
  190. <%--自动生成:ws.zy--%>
  191. <script>
  192. ss.dom.formElemConfig.zy={val:'<ss:txt val='${ws.zy}'/>',type:window.ss.dom.TYPE.INPUT};
  193. </script>
  194. <ss-inp
  195. placeholder="请输入摘要"
  196. v-model="zy"
  197. name="zy"
  198. :readonly="false"
  199. style="width: 100%;"
  200. >
  201. </ss-inp>
  202. </td>
  203. </tr>
  204. <tr>
  205. <th>正文</th>
  206. <td colspan="3">
  207. <script>
  208. // 处理函数定义
  209. window.handleInsertTemplate = function(context) {
  210. var templateHtml = '<div style="border: 1px solid #ccc; padding: 20px; margin: 10px 0; background: #f5f5f5;">' +
  211. '<h3 style="text-align: center;">公文模板</h3>' +
  212. '<p> 请输入正文内容...</p>' +
  213. '<p style="text-align: right;">(此段落为模板示例)</p>' +
  214. '</div>';
  215. var currentContent = context.getValue() || '';
  216. context.setValue(currentContent + templateHtml);
  217. if (context.editor && context.editor.insertHTML) {
  218. context.editor.insertHTML(templateHtml);
  219. }
  220. alert('已插入公文模板!');
  221. };
  222. window.handleClearEditor = function(context) {
  223. if (confirm('确定要清空正文内容吗?')) {
  224. context.setValue('');
  225. if (window.ss && window.ss.dom && window.ss.dom.set) {
  226. window.ss.dom.set('zwwjHtml', '');
  227. }
  228. alert('正文内容已清空!');
  229. }
  230. };
  231. // zwwj 配置(按钮移到 param 中)
  232. ss.dom.formElemConfig.zwwj = {
  233. val: '${ws.zwwj}',
  234. type: window.ss.dom.TYPE.HTML
  235. };
  236. ss.dom.formElemConfig.zwwjHtml = {val: '', type: window.ss.dom.TYPE.INPUT};
  237. </script>
  238. <ss-editor
  239. :height="420"
  240. url="<ss:serv name='loadEditorBody' />"
  241. :param="{'mode':'${dataType=='change'?'change':'edit'}','button':[{'desc':'附件','name':'fjid','val':'${ws.fjid}','cmsUpdUrl':'<ss:serv name='regCms' dest='cmsHome' />','cmsAddUrl':'<ss:serv name='makeAttCms' />'},{'desc':'插入模板','name':'insertTemplate','icon':'editor-icon-file','func':'window.handleInsertTemplate'},{'desc':'清空','name':'clearContent','icon':'editor-icon-eraser','func':'window.handleClearEditor'}],'obj':'ws','jlztm':'${ws.jlztm}'}"
  242. v-model="zwwj"
  243. :html="zwwjHtml"
  244. name="zwwj"
  245. :readonly="false"
  246. width="700px"
  247. >
  248. </ss-editor>
  249. </td>
  250. </tr>
  251. <tr>
  252. <th>拟稿人员</th>
  253. <td>
  254. <script>
  255. ss.dom.formElemConfig.ngryid={val:'${ws.ngryid}',type:window.ss.dom.TYPE.OBJP};
  256. </script>
  257. <ss-objp
  258. :opt="ngryidOption"
  259. placeholder="请选择拟稿人员"
  260. :inp="false"
  261. url="<ss:serv name='loadObjpOpt' parm='{"objectpickerdropdown1":"1"}' />"
  262. cb="ry"
  263. v-model="ngryid"
  264. name="ngryid"
  265. :readonly="false"
  266. style="width: 170px;"
  267. >
  268. </ss-objp>
  269. </td>
  270. <th>拟稿部门</th>
  271. <td>
  272. <script>
  273. ss.dom.formElemConfig.ngbmid={val:'${ws.ngbmid}',type:window.ss.dom.TYPE.OBJP};
  274. </script>
  275. <ss-objp
  276. :opt="ngbmidOption"
  277. placeholder="请选择拟稿部门"
  278. :inp="false"
  279. url="<ss:serv name='loadObjpOpt' parm='{"objectpickerdropdown1":"1"}' />"
  280. cb="bm"
  281. v-model="ngbmid"
  282. name="ngbmid"
  283. :readonly="false"
  284. style="width: 170px;"
  285. >
  286. </ss-objp>
  287. </td>
  288. </tr>
  289. </table>
  290. </div>
  291. <!-- 将所有JavaScript函数和初始化代码集中放在这里 -->
  292. <script>
  293. // 全局变量定义
  294. var wd = window.wd || {};
  295. wd.app = wd.app || {name: 'defaultApp'};
  296. // 生成原件按钮状态
  297. var isGenerating = false;
  298. // 获取账户信息函数
  299. function getAccountInfo() {
  300. return {
  301. xmmc: 'defaultProject'
  302. };
  303. }
  304. function checkFile(fileId) {
  305. var filePath = $('input[name="' + fileId + 'wj"]').val();
  306. if (!filePath) {
  307. alert('请先上传文件');
  308. return;
  309. }
  310. alert('文件路径:' + filePath + '\n点击确定后将尝试打开文件');
  311. window.open(filePath, '_blank');
  312. }
  313. // upload.js 需要的清理文件函数
  314. function uploadFileClean(id) {
  315. $('#' + id + 'Name').html('');
  316. $('input[name="' + id + 'wj"]').val('');
  317. $('#' + id + 'Edit_File').val('');
  318. $('#' + id + 'path').val('');
  319. $("#qx" + id).hide();
  320. $("#check" + id).hide();
  321. // 同时清空文件名显示
  322. $('#' + id + 'BaseName').html('');
  323. $('input[name="' + id + 'BaseName"]').val('');
  324. };
  325. // 生成原件函数
  326. function generateOfficialDocument() {
  327. if (isGenerating) {
  328. return; // 防止重复点击
  329. }
  330. var title = "1233333";
  331. // 使用桥接 API 读取 Vue 数据(方式2:从 zwwjHtml 读取编辑器内容)
  332. // 文档:/docs/普通JS读写Vue数据方法.md
  333. var htmlContent = window.ss.dom.get('zwwjHtml') || '';
  334. if (!htmlContent || htmlContent.trim() === '') {
  335. if (!confirm('正文内容为空,确定要生成空白公文吗?')) {
  336. return;
  337. }
  338. }
  339. // 收集生成参数
  340. var params = {
  341. institutionName: '广州工商学院',
  342. documentNumber: '数教函〔2026〕2号',
  343. documentTitle: title,
  344. htmlContent: htmlContent,
  345. sender: '数字教育与装备中心',
  346. receiver: '各学院、各部门:',
  347. hasAttachment: false,
  348. attachmentInfo: '',
  349. sealImagePath: 'D:\\tmp\\seal\\yz2.png',
  350. enableSeal: true
  351. };
  352. // 开始生成
  353. generateAndUploadDocument(params);
  354. }
  355. // 生成并上传公文
  356. function generateAndUploadDocument(params) {
  357. isGenerating = true;
  358. $('#generateStatus').html('正在生成公文...').css('color', '#1890ff');
  359. $('#generateDocumentBtn').prop('disabled', true).css('opacity', 0.7);
  360. // 使用XMLHttpRequest来获取二进制数据
  361. var xhr = new XMLHttpRequest();
  362. xhr.open('POST', "<ss:serv name='ws_zh_schtwj'/>", true);
  363. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
  364. xhr.responseType = 'arraybuffer';
  365. // 构建请求参数
  366. var formData = new URLSearchParams();
  367. formData.append('institutionName', params.institutionName);
  368. formData.append('documentNumber', params.documentNumber);
  369. formData.append('documentTitle', params.documentTitle);
  370. formData.append('htmlContent', params.htmlContent);
  371. formData.append('sealImagePath', params.sealImagePath);
  372. formData.append('sender', params.sender);
  373. formData.append('receiver', params.receiver);
  374. formData.append('hasAttachment', params.hasAttachment);
  375. formData.append('attachmentInfo', params.attachmentInfo);
  376. formData.append('enableSeal', params.enableSeal);
  377. // 监听进度事件
  378. xhr.addEventListener('progress', function(e) {
  379. if (e.lengthComputable) {
  380. var percentComplete = (e.loaded / e.total) * 100;
  381. $('#generateStatus').html('生成中... ' + Math.round(percentComplete) + '%');
  382. }
  383. }, false);
  384. xhr.onload = function() {
  385. if (xhr.status === 200) {
  386. // 检查响应类型
  387. var contentType = xhr.getResponseHeader('Content-Type');
  388. if (contentType && contentType.indexOf('application/pdf') !== -1) {
  389. // 获取ArrayBuffer
  390. var arrayBuffer = xhr.response;
  391. if (!arrayBuffer || arrayBuffer.byteLength === 0) {
  392. $('#generateStatus').html('PDF文件流为空').css('color', '#ff4d4f');
  393. alert('生成的PDF文件为空,请检查服务器端');
  394. return;
  395. }
  396. // 创建Blob
  397. var blob = new Blob([arrayBuffer], { type: 'application/pdf' });
  398. var fileName = params.documentTitle.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g, '_') + '.pdf';
  399. if (blob.size === 0) {
  400. $('#generateStatus').html('Blob对象为空').css('color', '#ff4d4f');
  401. alert('生成的PDF文件为空,请检查服务器端');
  402. return;
  403. }
  404. // 上传生成的PDF文件
  405. uploadGeneratedPdf(blob, fileName, function(uploadResult) {
  406. if (uploadResult && uploadResult.fileList && uploadResult.fileList.length > 0) {
  407. var filePath = uploadResult.fileList[0].path;
  408. var fileName = uploadResult.fileList[0].fileName;
  409. // 回填到上传路径输入框
  410. var fullFilePath = filePath;
  411. $('#scyjpath').val(fullFilePath);
  412. $('input[name="scyjwj"]').val(fullFilePath);
  413. $('input[name="uploadPath"]').val(fullFilePath);
  414. $('#scyjBaseName').text(fileName);
  415. $('input[name="scyjBaseName"]').val(fileName);
  416. $('#checkScyj').show();
  417. $('#qxScyj').show();
  418. $('#generateStatus').html('生成并上传成功!').css('color', '#52c41a');
  419. alert('公文生成并上传成功!文件路径:' + fullFilePath);
  420. } else {
  421. $('#generateStatus').html('上传失败').css('color', '#ff4d4f');
  422. alert('上传失败,请重试');
  423. }
  424. });
  425. } else {
  426. // 尝试将响应解析为JSON
  427. try {
  428. var decoder = new TextDecoder('utf-8');
  429. var text = decoder.decode(new Uint8Array(xhr.response));
  430. var result = JSON.parse(text);
  431. if (result.success === false) {
  432. $('#generateStatus').html('生成失败:' + (result.message || '未知错误')).css('color', '#ff4d4f');
  433. alert('生成失败:' + (result.message || '未知错误'));
  434. } else {
  435. $('#generateStatus').html('未知响应格式').css('color', '#ff4d4f');
  436. alert('未知响应格式,请检查接口');
  437. }
  438. } catch (e) {
  439. $('#generateStatus').html('响应解析失败').css('color', '#ff4d4f');
  440. alert('服务器响应异常:' + e.message);
  441. }
  442. }
  443. } else {
  444. $('#generateStatus').html('生成失败,状态码:' + xhr.status).css('color', '#ff4d4f');
  445. alert('生成失败,HTTP状态码:' + xhr.status);
  446. }
  447. };
  448. xhr.onerror = function() {
  449. $('#generateStatus').html('生成失败:网络错误').css('color', '#ff4d4f');
  450. alert('生成失败:网络错误,请检查网络连接');
  451. };
  452. xhr.onloadend = function() {
  453. isGenerating = false;
  454. $('#generateDocumentBtn').prop('disabled', false).css('opacity', 1);
  455. };
  456. xhr.send(formData.toString());
  457. }
  458. // 上传生成的PDF文件
  459. function uploadGeneratedPdf(blob, fileName, callback) {
  460. $('#generateStatus').html('正在上传文件...').css('color', '#1890ff');
  461. if (blob.size === 0) {
  462. alert('要上传的文件为空,无法上传');
  463. callback(null);
  464. return;
  465. }
  466. // 创建FormData
  467. var formData = new FormData();
  468. formData.append('file', blob, fileName);
  469. formData.append('name', fileName);
  470. formData.append('type', 'document');
  471. formData.append('app', wd.app ? wd.app.name : getAccountInfo().xmmc);
  472. // 使用原有的上传接口
  473. $.ajax({
  474. url: "/service?ssServ=ulByHttp&type=document",
  475. type: 'POST',
  476. data: formData,
  477. processData: false,
  478. contentType: false,
  479. xhr: function() {
  480. var xhr = new XMLHttpRequest();
  481. xhr.upload.addEventListener('progress', function(e) {
  482. if (e.lengthComputable) {
  483. var percentComplete = (e.loaded / e.total) * 100;
  484. $('#generateStatus').html('上传中... ' + Math.round(percentComplete) + '%');
  485. }
  486. }, false);
  487. return xhr;
  488. },
  489. beforeSend: function() {
  490. },
  491. success: function(result) {
  492. try {
  493. if (typeof result === 'string') {
  494. result = JSON.parse(result);
  495. }
  496. if (result && result.fileList && result.fileList.length > 0) {
  497. callback(result);
  498. } else {
  499. callback(result);
  500. }
  501. } catch (e) {
  502. console.error('解析上传响应失败:', e);
  503. callback(null);
  504. }
  505. },
  506. error: function(xhr, status, error) {
  507. console.error('文件上传失败:', error);
  508. alert('文件上传失败:' + error);
  509. callback(null);
  510. }
  511. });
  512. }
  513. // 页面加载完成后初始化上传功能
  514. $(document).ready(function () {
  515. // 检查upload.js是否已加载
  516. if (typeof $.fn.uploadFile === 'undefined') {
  517. console.error('upload.js 未正确加载');
  518. alert('文件上传插件加载失败,请联系管理员');
  519. return;
  520. }
  521. // 调试:检查按钮是否存在
  522. // 初始化上传插件
  523. try {
  524. // 使用upload.js插件
  525. $('#scyjEdit').uploadFile({
  526. name: 'scyj', // 必须与页面中的元素ID前缀一致
  527. type: 'document', // 上传类型,可根据需要设置
  528. validation: 'jpg,jpeg,png,pdf,doc,docx,xls,xlsx,ppt,pptx,txt,zip,rar', // 允许上传的文件类型
  529. size: 10240, // 文件大小限制,单位KB(10MB)
  530. app: wd.app ? wd.app.name : getAccountInfo().xmmc, // 应用名称
  531. action: "/service?ssServ=ulByHttp&type=document", // 明确指定action
  532. beforeClick: function () {
  533. return true;
  534. },
  535. onchange: function (settings) {
  536. },
  537. callback: function (result) {
  538. if (result && result.fileList && result.fileList.length > 0) {
  539. // 显示成功消息
  540. var fileName = result.fileList[0].fileName;
  541. alert('文件 "' + fileName + '" 上传成功!');
  542. // 自动填充上传路径输入框
  543. var filePath = result.fileList[0].path;
  544. if (filePath) {
  545. $('input[name="uploadPath"]').val(filePath);
  546. }
  547. // 文件上传成功之后, 获取对应的文件 , 并且将pdf文件解析出正文内容
  548. // 获取文件路径, 然后调用后端代码
  549. // if (filePath && filePath.toLowerCase().endsWith('.pdf')) {
  550. if (filePath) {
  551. $.ajax({
  552. url: "<ss:serv name='ws_zh_pdf2html'/>",
  553. type: 'post',
  554. data: {
  555. path: filePath,
  556. fileName: fileName
  557. },
  558. success: function (result) {
  559. // 提取成功后, 将正文内容传输到正文控件中
  560. try {
  561. var parse = typeof result === 'string' ? JSON.parse(result) : result;
  562. // 使用桥接 API 写入 Vue 数据(推荐方式)
  563. // 文档:/docs/普通JS读写Vue数据方法.md
  564. // 这会自动更新编辑器内容
  565. window.ss.dom.set('zwwjHtml', parse.data || '');
  566. } catch (e) {
  567. console.warn('PDF解析结果处理失败:', e);
  568. }
  569. },
  570. error: function(xhr, status, error) {
  571. }
  572. });
  573. }
  574. }
  575. }
  576. });
  577. } catch (error) {
  578. alert('上传插件初始化失败: ' + error.message);
  579. // 如果upload.js插件失败,使用简单方法
  580. $('#scyjEdit').off('click.simple').on('click.simple', function () {
  581. // 创建一个临时的文件input
  582. var fileInput = $('#scyjEdit_File');
  583. if (fileInput.length === 0) {
  584. $('body').append('<input type="file" id="scyjEdit_File" style="display:none;">');
  585. fileInput = $('#scyjEdit_File');
  586. }
  587. fileInput.off('change').on('change', function () {
  588. if (this.files.length > 0) {
  589. var fileName = this.files[0].name;
  590. $('#scyjBaseName').text(fileName);
  591. $('input[name="scyjBaseName"]').val(fileName);
  592. $('#checkScyj').show();
  593. $('#qxScyj').show();
  594. alert('已选择文件: ' + fileName);
  595. }
  596. });
  597. fileInput.click();
  598. });
  599. }
  600. // 添加上传路径输入框的点击事件
  601. $('#scyjpath').click(function () {
  602. var currentPath = $(this).val();
  603. if (currentPath) {
  604. $(this).select();
  605. }
  606. });
  607. // 为删除按钮添加确认提示
  608. $('body').on('click', '#qxScyj', function (e) {
  609. if (!confirm('确定要删除已上传的文件吗?')) {
  610. e.preventDefault();
  611. return false;
  612. }
  613. });
  614. // 初始化页面时检查是否有已上传的文件
  615. var existingFile = $('input[name="scyjwj"]').val();
  616. if (existingFile) {
  617. var fileName = existingFile.split('/').pop();
  618. $('#scyjBaseName').text(fileName);
  619. $('input[name="scyjBaseName"]').val(fileName);
  620. $('#checkScyj').show();
  621. $('#qxScyj').show();
  622. $('input[name="uploadPath"]').val(existingFile);
  623. }
  624. });
  625. // 表单提交前的验证函数
  626. function validateForm() {
  627. var filePath = $('input[name="scyjwj"]').val();
  628. var title = $('input[name="bt"]').val();
  629. if (!title || title.trim() === '') {
  630. alert('请填写标题');
  631. $('input[name="bt"]').focus();
  632. return false;
  633. }
  634. if (!filePath || filePath.trim() === '') {
  635. if (!confirm('您尚未上传原件,确定要继续提交吗?')) {
  636. $('#scyjEdit').focus();
  637. return false;
  638. }
  639. }
  640. return true;
  641. }
  642. // ==================== Vue 桥接 API 使用示例 ====================
  643. // 文档:/docs/普通JS读写Vue数据方法.md
  644. /**
  645. * 示例1:读取编辑器内容
  646. * 使用 window.ss.dom.get() 从 Vue 实例读取数据
  647. */
  648. function readEditorContent() {
  649. // 方式1:通过桥接 API 读取(推荐)
  650. var htmlContent = window.ss.dom.get('zwwjHtml') || '';
  651. console.log('读取到编辑器内容,长度:', htmlContent.length);
  652. alert('编辑器内容长度: ' + htmlContent.length + '\n前100字: ' + htmlContent.substring(0, 100));
  653. return htmlContent;
  654. }
  655. /**
  656. * 示例2:写入编辑器内容
  657. * 使用 window.ss.dom.set() 向 Vue 实例写入数据
  658. */
  659. function writeEditorContent() {
  660. var sampleHtml = '<p style="color: blue;">这是通过桥接 API 插入的内容</p>' +
  661. '<p>当前时间: ' + new Date().toLocaleString() + '</p>';
  662. // 通过桥接 API 设置 Vue 数据,编辑器会自动更新
  663. window.ss.dom.set('zwwjHtml', sampleHtml);
  664. console.log('已写入编辑器内容');
  665. alert('已向编辑器写入示例内容');
  666. }
  667. /**
  668. * 示例3:读取和设置表单标题
  669. * 演示如何读写普通输入字段
  670. */
  671. function readFormTitle() {
  672. // 读取标题字段
  673. var title = window.ss.dom.get('bt') || '';
  674. console.log('当前标题:', title);
  675. return title;
  676. }
  677. /**
  678. * 示例3b:设置表单标题
  679. */
  680. function setFormTitle() {
  681. var newTitle = '新标题_' + new Date().getTime();
  682. window.ss.dom.set('bt', newTitle);
  683. console.log('已设置标题:', newTitle);
  684. alert('标题已设置为: ' + newTitle);
  685. }
  686. /**
  687. * 示例4:读取和设置下拉框(文书类别)
  688. * 演示如何操作下拉选择框(ss-objp 组件)
  689. */
  690. function readDocumentType() {
  691. // 读取文书类别代码
  692. var typeCode = window.ss.dom.get('wslbm') || '';
  693. // 定义选项映射
  694. var typeMap = {
  695. "1": "函",
  696. "11": "通知",
  697. "21": "请示",
  698. "31": "批复",
  699. "41": "报告",
  700. "81": "个人书信",
  701. "91": "其他"
  702. };
  703. var typeName = typeMap[typeCode] || '未选择';
  704. console.log('文书类别代码:', typeCode, '名称:', typeName);
  705. alert('当前文书类别:\n代码: ' + typeCode + '\n名称: ' + typeName);
  706. return { code: typeCode, name: typeName };
  707. }
  708. /**
  709. * 示例4b:设置下拉框值(文书类别)
  710. * 注意:下拉框通过 v-model 绑定,设置 code 即可
  711. */
  712. function setDocumentType() {
  713. // 定义选项
  714. var typeOptions = [
  715. { code: '1', name: '函' },
  716. { code: '11', name: '通知' },
  717. { code: '21', name: '请示' },
  718. { code: '31', name: '批复' },
  719. { code: '41', name: '报告' },
  720. { code: '81', name: '个人书信' },
  721. { code: '91', name: '其他' }
  722. ];
  723. // 随机选择一个(实际应用中是用户选择)
  724. var randomType = typeOptions[Math.floor(Math.random() * typeOptions.length)];
  725. // 设置下拉框的值(设置 code,组件自动显示对应文本)
  726. window.ss.dom.set('wslbm', randomType.code);
  727. console.log('已设置文书类别:', randomType);
  728. alert('已设置文书类别为: ' + randomType.name + ' (代码: ' + randomType.code + ')');
  729. }
  730. /**
  731. * 示例4d:读取所有下拉框值
  732. * 批量读取多个下拉框字段
  733. */
  734. function readAllDropdowns() {
  735. // 读取各个下拉框的值
  736. var values = {
  737. wslbm: window.ss.dom.get('wslbm') || '', // 文书类别
  738. wsmjm: window.ss.dom.get('wsmjm') || '', // 密级
  739. wsfwm: window.ss.dom.get('wsfwm') || '', // 范围
  740. gllbm: window.ss.dom.get('gllbm') || '' // 管理类别
  741. };
  742. // 定义映射表
  743. var maps = {
  744. wslbm: { "1": "函", "11": "通知", "21": "请示", "31": "批复", "41": "报告", "81": "个人书信", "91": "其他" },
  745. wsmjm: { "1": "公开", "2": "内部", "3": "秘密", "4": "机密", "5": "绝密" },
  746. wsfwm: { "1": "全局", "2": "部门", "3": "个人" },
  747. gllbm: { "1": "行政", "2": "人事", "3": "财务", "4": "业务" }
  748. };
  749. var result = '下拉框取值:\n';
  750. for (var key in values) {
  751. var code = values[key];
  752. var name = maps[key] && maps[key][code] ? maps[key][code] : code;
  753. result += key + ': ' + name + ' (代码: ' + code + ')\n';
  754. }
  755. alert(result);
  756. return values;
  757. }
  758. /**
  759. * 示例5:批量设置表单数据
  760. * 实际应用场景:快速填充表单
  761. */
  762. function batchSetFormData() {
  763. // 批量设置多个字段
  764. window.ss.dom.set('bt', '关于2026年度工作总结的通知');
  765. window.ss.dom.set('zy', '本文总结了2026年度的工作情况...');
  766. window.ss.dom.set('wslbm', '11'); // 通知
  767. window.ss.dom.set('wsmjm', '2'); // 内部
  768. alert('已批量设置:\n标题、摘要、文书类别(通知)、密级(内部)');
  769. }
  770. /**
  771. * 示例6:读取完整表单数据
  772. * 用于提交前预览或生成文档
  773. */
  774. function readFullFormData() {
  775. var formData = {
  776. // 基本信息
  777. title: window.ss.dom.get('bt') || '',
  778. summary: window.ss.dom.get('zy') || '',
  779. // 下拉框
  780. docType: window.ss.dom.get('wslbm') || '',
  781. secretLevel: window.ss.dom.get('wsmjm') || '',
  782. scope: window.ss.dom.get('wsfwm') || '',
  783. manageType: window.ss.dom.get('gllbm') || '',
  784. // 编辑器内容
  785. content: window.ss.dom.get('zwwjHtml') || '',
  786. // 人员部门
  787. draftPerson: window.ss.dom.get('ngryid') || '',
  788. draftDept: window.ss.dom.get('ngbmid') || ''
  789. };
  790. console.log('完整表单数据:', formData);
  791. // 生成预览文本
  792. var preview = '表单数据预览:\n' +
  793. '标题: ' + formData.title + '\n' +
  794. '文书类别: ' + formData.docType + '\n' +
  795. '密级: ' + formData.secretLevel + '\n' +
  796. '内容长度: ' + formData.content.length + ' 字符\n';
  797. alert(preview);
  798. return formData;
  799. }
  800. /**
  801. * 示例4:清空编辑器并显示提示
  802. * 结合读写操作
  803. */
  804. function clearEditorWithConfirm() {
  805. // 先读取当前内容
  806. var currentContent = window.ss.dom.get('zwwjHtml') || '';
  807. if (currentContent.length === 0) {
  808. alert('编辑器已经是空的');
  809. return;
  810. }
  811. if (confirm('确定要清空编辑器内容吗?当前有 ' + currentContent.length + ' 个字符')) {
  812. // 清空内容
  813. window.ss.dom.set('zwwjHtml', '');
  814. alert('已清空');
  815. }
  816. }
  817. /**
  818. * 示例5:生成公文时读取编辑器内容
  819. * 实际应用场景
  820. */
  821. function generateDocWithContent() {
  822. // 从 Vue 读取编辑器内容
  823. var htmlContent = window.ss.dom.get('zwwjHtml') || '';
  824. var title = window.ss.dom.get('bt') || '未命名';
  825. if (!htmlContent || htmlContent.trim() === '') {
  826. if (!confirm('正文内容为空,确定要生成空白公文吗?')) {
  827. return;
  828. }
  829. }
  830. console.log('准备生成公文:', {
  831. title: title,
  832. contentLength: htmlContent.length
  833. });
  834. // 这里调用生成公文的接口...
  835. alert('标题: ' + title + '\n内容长度: ' + htmlContent.length + '\n\n可以在这里调用生成接口');
  836. }
  837. // ==================== 示例结束 ====================
  838. // 修复uploadFile插件的问题
  839. function fixUploadPlugin() {
  840. // 检查是否有必要的CSS样式
  841. if (!$('.content-button').length) {
  842. $('#scyjEdit').addClass('content-button');
  843. }
  844. // 确保文件输入框存在
  845. if (!$('#scyjEdit_File').length) {
  846. $('body').append('<input type="file" id="scyjEdit_File" name="fileEdit" style="display:none;">');
  847. }
  848. // 手动绑定点击事件
  849. $('#scyjEdit').off('click.manual').on('click.manual', function () {
  850. $('#scyjEdit_File').click();
  851. });
  852. // 监听文件选择
  853. $('#scyjEdit_File').off('change').on('change', function (e) {
  854. if (this.files && this.files.length > 0) {
  855. var fileName = this.files[0].name;
  856. var fileSize = this.files[0].size;
  857. var fileType = this.files[0].type;
  858. // 显示文件信息
  859. $('#scyjBaseName').text(fileName);
  860. $('input[name="scyjBaseName"]').val(fileName);
  861. // 模拟上传
  862. simulateUpload(fileName, fileSize);
  863. }
  864. });
  865. }
  866. // 模拟文件上传
  867. function simulateUpload(fileName, fileSize) {
  868. // 显示进度条
  869. $('#scyjBaseName').html('<div class="progress"><div class="bar"></div><div class="percent">0%</div></div>');
  870. // 模拟上传进度
  871. var progress = 0;
  872. var interval = setInterval(function () {
  873. progress += 10;
  874. if (progress <= 100) {
  875. $('.bar').width(progress + '%');
  876. $('.percent').text(progress + '%');
  877. if (progress === 100) {
  878. clearInterval(interval);
  879. // 模拟上传完成
  880. setTimeout(function () {
  881. // 生成模拟文件路径
  882. var timestamp = new Date().getTime();
  883. var filePath = '/uploads/' + timestamp + '_' + fileName;
  884. // 更新页面
  885. $('#scyjBaseName').text(fileName);
  886. $('input[name="scyjwj"]').val(filePath);
  887. $('input[name="uploadPath"]').val(filePath);
  888. $('#checkScyj').show();
  889. $('#qxScyj').show();
  890. alert('文件 "' + fileName + '" 上传成功!');
  891. }, 500);
  892. }
  893. }
  894. }, 200);
  895. }
  896. // 页面完全加载后修复插件
  897. $(window).on('load', function () {
  898. // 如果upload.js插件没有正常工作,使用修复方法
  899. setTimeout(function () {
  900. if ($('#scyjEdit').length && !$('#scyjEdit').data('upload-initialized')) {
  901. fixUploadPlugin();
  902. }
  903. }, 1000);
  904. });
  905. </script>
  906. <ss:ichk name='ws_inp'/>
  907. <script> addRemoveToken('<%= pageContext.getAttribute(ss.page.PageC.PAGE_tokenList)%>');</script>