| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068 |
- <%@ page language="java" pageEncoding="UTF-8" isELIgnored="false" %>
- <%@ taglib uri="/ssTag" prefix="ss"%>
- <% pageContext.setAttribute(ss.page.PageC.PAGE_objName,"ws");%>
- <%pageContext.setAttribute("wdpageinformation","{'hastab':'0'}");%>
- <!DOCTYPE html>
- <!-- 引入必要的JavaScript库 -->
- <script type="text/javascript" src="/ss/jquery/jquery1.11.3.min.js"></script>
- <script type="text/javascript" src="/ss/jquery/jquery.form.min.js"></script>
- <script type="text/javascript" src="/ss/js/upload.js"></script>
- <div class='content-div' ssFith="true">
- <table class='form'>
- <tr>
- <th>上传原件</th>
- <td>
- <!-- 上传按钮 - upload.js会绑定点击事件 -->
- <input type="button" id="scyjEdit" class="content-button" value="选择文件..."/>
- <!-- 文件信息显示区域 - upload.js必需的元素 -->
- <span id="scyjBaseName" class="file-info"></span>
- <!-- 操作按钮区域 - upload.js控制显示/隐藏 -->
- <span class="file-action">
- <button id="checkScyj" style="display:none;" onclick="checkFile('scyj')">查看</button>
- <button id="qxScyj" style="display:none;" onclick="uploadFileClean('scyj')">删除</button>
- </span>
- </td>
- <th>上传后路径</th>
- <td>
- <!-- upload.js上传成功后会将路径填充到这里 -->
- <input mc="mc" name="scyjwj" id="scyjpath" value="" style="width: 300px;"/>
- <!-- 隐藏的文件名输入框,upload.js需要 -->
- <input type="hidden" name="scyjBaseName" value=""/>
- </td>
- <td>
- <input id="path" name='uploadPath' style="width: 200px;"/>
- </td>
- </tr>
- <!-- 新增:生成原件行 -->
- <tr>
- <th>生成原件</th>
- <td colspan="4">
- <input type="button" id="generateDocumentBtn" class="content-button" value="生成原件"
- onclick="generateOfficialDocument()"
- style="background-color: #1890ff; color: white; border: 1px solid #1890ff;"/>
- <span id="generateStatus" style="margin-left: 10px; color: #666; font-size: 12px;"></span>
- </td>
- </tr>
- <!-- Vue 桥接 API 测试按钮(可删除) -->
- <tr>
- <th>桥接API测试</th>
- <td colspan="4">
- <b>编辑器操作:</b><br/>
- <input type="button" class="content-button" value="读取内容"
- onclick="readEditorContent()"
- style="margin: 2px 5px 2px 0;"/>
- <input type="button" class="content-button" value="写入示例"
- onclick="writeEditorContent()"
- style="margin: 2px 5px 2px 0;"/>
- <input type="button" class="content-button" value="清空编辑器"
- onclick="clearEditorWithConfirm()"
- style="margin: 2px 5px 2px 0;"/>
- <br/>
- <b>普通字段:</b><br/>
- <input type="button" class="content-button" value="读取标题"
- onclick="alert('标题: ' + (readFormTitle() || '未填写'))"
- style="margin: 2px 5px 2px 0;"/>
- <input type="button" class="content-button" value="设置标题"
- onclick="setFormTitle()"
- style="margin: 2px 5px 2px 0;"/>
- <br/>
- <b>下拉框操作:</b><br/>
- <input type="button" class="content-button" value="读取文书类别"
- onclick="readDocumentType()"
- style="margin: 2px 5px 2px 0;"/>
- <input type="button" class="content-button" value="随机设置文书类别"
- onclick="setDocumentType()"
- style="margin: 2px 5px 2px 0;"/>
- <input type="button" class="content-button" value="自动匹配文书类别"
- onclick="autoSelectDocumentType()"
- style="margin: 2px 5px 2px 0;"/>
- <br/>
- <b>批量操作:</b><br/>
- <input type="button" class="content-button" value="读取所有下拉框"
- onclick="readAllDropdowns()"
- style="margin: 2px 5px 2px 0;"/>
- <input type="button" class="content-button" value="批量设置数据"
- onclick="batchSetFormData()"
- style="margin: 2px 5px 2px 0;"/>
- <input type="button" class="content-button" value="读取完整表单"
- onclick="readFullFormData()"
- style="margin: 2px 5px 2px 0;"/>
- <br/>
- <span style="color: #999; font-size: 12px;">详见函数定义及 /docs/普通JS读写Vue数据方法.md</span>
- </td>
- </tr>
- <tr>
- <th>文书类别</th>
- <td>
- <script>
- ss.dom.formElemConfig.wslbm={val:'${ws.wslbm}',type:window.ss.dom.TYPE.OBJP};
- </script>
- <ss-objp
- :opt="wslbmOption"
- placeholder="请选择文书类别"
- :inp="false"
- url="<ss:serv name='loadObjpOpt' parm='{"objectpickerdropdown1":"1"}' />"
- cb="wslb"
- v-model="wslbm"
- name="wslbm"
- :readonly="false"
- style="width: 200px;"
- >
- </ss-objp>
- </td>
- <th>密级</th>
- <td>
- <script>
- ss.dom.formElemConfig.wsmjm={val:'${ws.wsmjm}',type:window.ss.dom.TYPE.OBJP};
- </script>
- <ss-objp
- :opt="wsmjmOption"
- placeholder="请选择文书密级"
- :inp="false"
- url="<ss:serv name='loadObjpOpt' parm='{"objectpickerdropdown1":"1"}' />"
- cb="wsmj"
- v-model="wsmjm"
- name="wsmjm"
- :readonly="false"
- style="width: 200px;"
- >
- </ss-objp>
- </td>
- </tr>
- <tr>
- <th>范围</th>
- <td>
- <script>
- ss.dom.formElemConfig.wsfwm={val:'${ws.wsfwm}',type:window.ss.dom.TYPE.OBJP};
- </script>
- <ss-objp
- :opt="wsfwmOption"
- placeholder="请选择文书范围"
- :inp="false"
- url="<ss:serv name='loadObjpOpt' parm='{"objectpickerdropdown1":"1"}' />"
- cb="wsfw"
- v-model="wsfwm"
- name="wsfwm"
- :readonly="false"
- style="width: 200px;"
- >
- </ss-objp>
- </td>
- <th>管理类别</th>
- <td>
- <script>
- ss.dom.formElemConfig.gllbm={val:'${ws.gllbm}',type:window.ss.dom.TYPE.OBJP};
- </script>
- <ss-objp
- :opt="gllbmOption"
- placeholder="请选择管理类别"
- :inp="false"
- url="<ss:serv name='loadObjpOpt' parm='{"objectpickerdropdown1":"1"}' />"
- cb="gllb"
- v-model="gllbm"
- name="gllbm"
- :readonly="false"
- style="width: 200px;"
- >
- </ss-objp>
- </td>
- </tr>
- <tr>
- <th>标题</th>
- <td colspan="3">
- <%--自动生成:ws.bt--%>
- <script>
- ss.dom.formElemConfig.bt={val:'<ss:txt val='${ws.bt}'/>',type:window.ss.dom.TYPE.INPUT};
- </script>
- <ss-inp
- placeholder="请输入标题"
- v-model="bt"
- name="bt"
- :readonly="false"
- style="width: 100%;"
- >
- </ss-inp>
- </td>
- </tr>
- <tr>
- <th>摘要</th>
- <td colspan="3">
- <%--自动生成:ws.zy--%>
- <script>
- ss.dom.formElemConfig.zy={val:'<ss:txt val='${ws.zy}'/>',type:window.ss.dom.TYPE.INPUT};
- </script>
- <ss-inp
- placeholder="请输入摘要"
- v-model="zy"
- name="zy"
- :readonly="false"
- style="width: 100%;"
- >
- </ss-inp>
- </td>
- </tr>
- <tr>
- <th>正文</th>
- <td colspan="3">
-
- <script>
- // 处理函数定义
- window.handleInsertTemplate = function(context) {
- var templateHtml = '<div style="border: 1px solid #ccc; padding: 20px; margin: 10px 0; background: #f5f5f5;">' +
- '<h3 style="text-align: center;">公文模板</h3>' +
- '<p> 请输入正文内容...</p>' +
- '<p style="text-align: right;">(此段落为模板示例)</p>' +
- '</div>';
- var currentContent = context.getValue() || '';
- context.setValue(currentContent + templateHtml);
- if (context.editor && context.editor.insertHTML) {
- context.editor.insertHTML(templateHtml);
- }
- alert('已插入公文模板!');
- };
- window.handleClearEditor = function(context) {
- if (confirm('确定要清空正文内容吗?')) {
- context.setValue('');
- if (window.ss && window.ss.dom && window.ss.dom.set) {
- window.ss.dom.set('zwwjHtml', '');
- }
- alert('正文内容已清空!');
- }
- };
- // zwwj 配置(按钮移到 param 中)
- ss.dom.formElemConfig.zwwj = {
- val: '${ws.zwwj}',
- type: window.ss.dom.TYPE.HTML
- };
- ss.dom.formElemConfig.zwwjHtml = {val: '', type: window.ss.dom.TYPE.INPUT};
- </script>
- <ss-editor
- :height="420"
- url="<ss:serv name='loadEditorBody' />"
- :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}'}"
- v-model="zwwj"
- :html="zwwjHtml"
- name="zwwj"
- mode="edit"
- width="700px"
- >
- </ss-editor>
- <!-- 【TEST】mode="play" 只读模式测试 by xu 20250402 -->
- <tr>
- <th>正文(只读模式测试)</th>
- <td colspan="3">
- <script>
- // 只读模式测试:带默认 HTML 内容 by xu 20250402
- ss.dom.formElemConfig.zwwjTest = {val: '${ws.zwwj}', type: window.ss.dom.TYPE.HTML};
- ss.dom.formElemConfig.zwwjTestHtml = {
- val: '<h2 style="color: #333; border-bottom: 2px solid #1890ff; padding-bottom: 10px;">测试文书标题</h2>' +
- '<p style="line-height: 1.8; color: #666;">这是一段测试内容,用于展示 <strong>mode="play"</strong> 只读模式的效果。</p>' +
- '<p style="line-height: 1.8; color: #666;">在只读模式下:</p>' +
- '<ul style="color: #666;">' +
- '<li>不加载 Jodit 编辑器</li>' +
- '<li>直接渲染 HTML 内容</li>' +
- '<li>保留附件按钮功能</li>' +
- '</ul>' +
- '<p style="margin-top: 20px; padding: 10px; background: #f5f5f5; border-left: 3px solid #1890ff;">' +
- '<strong>备注:</strong>此区域为只读展示,如需编辑请使用上方的编辑器。' +
- '</p>',
- type: window.ss.dom.TYPE.INPUT
- };
- </script>
- <ss-editor
- mode="play"
- :height="300"
- url="<ss:serv name='loadEditorBody' />"
- :param="{'mode':'view','obj':'ws','jlztm':'${ws.jlztm}','button':[{'desc':'附件','name':'fjid','val':'${ws.fjid}','cmsUpdUrl':'<ss:serv name='regCms' dest='cmsHome' />','cmsAddUrl':'<ss:serv name='makeAttCms' />'}]}"
- v-model="zwwjTest"
- :html="zwwjTestHtml"
- name="zwwjTest"
- width="700px"
- >
- </ss-editor>
- </td>
- </tr>
- </td>
- </tr>
- <tr>
- <th>拟稿人员</th>
- <td>
- <script>
- ss.dom.formElemConfig.ngryid={val:'${ws.ngryid}',type:window.ss.dom.TYPE.OBJP};
- </script>
- <ss-objp
- :opt="ngryidOption"
- placeholder="请选择拟稿人员"
- :inp="false"
- url="<ss:serv name='loadObjpOpt' parm='{"objectpickerdropdown1":"1"}' />"
- cb="ry"
- v-model="ngryid"
- name="ngryid"
- :readonly="false"
- style="width: 170px;"
- >
- </ss-objp>
- </td>
- <th>拟稿部门</th>
- <td>
- <script>
- ss.dom.formElemConfig.ngbmid={val:'${ws.ngbmid}',type:window.ss.dom.TYPE.OBJP};
- </script>
- <ss-objp
- :opt="ngbmidOption"
- placeholder="请选择拟稿部门"
- :inp="false"
- url="<ss:serv name='loadObjpOpt' parm='{"objectpickerdropdown1":"1"}' />"
- cb="bm"
- v-model="ngbmid"
- name="ngbmid"
- :readonly="false"
- style="width: 170px;"
- >
- </ss-objp>
- </td>
- </tr>
- </table>
- </div>
- <!-- 将所有JavaScript函数和初始化代码集中放在这里 -->
- <script>
- // 全局变量定义
- var wd = window.wd || {};
- wd.app = wd.app || {name: 'defaultApp'};
- // 生成原件按钮状态
- var isGenerating = false;
- // 获取账户信息函数
- function getAccountInfo() {
- return {
- xmmc: 'defaultProject'
- };
- }
- function checkFile(fileId) {
- var filePath = $('input[name="' + fileId + 'wj"]').val();
- if (!filePath) {
- alert('请先上传文件');
- return;
- }
- alert('文件路径:' + filePath + '\n点击确定后将尝试打开文件');
- window.open(filePath, '_blank');
- }
- // upload.js 需要的清理文件函数
- function uploadFileClean(id) {
- $('#' + id + 'Name').html('');
- $('input[name="' + id + 'wj"]').val('');
- $('#' + id + 'Edit_File').val('');
- $('#' + id + 'path').val('');
- $("#qx" + id).hide();
- $("#check" + id).hide();
- // 同时清空文件名显示
- $('#' + id + 'BaseName').html('');
- $('input[name="' + id + 'BaseName"]').val('');
- };
- // 生成原件函数
- function generateOfficialDocument() {
- if (isGenerating) {
- return; // 防止重复点击
- }
- var title = "1233333";
- // 使用桥接 API 读取 Vue 数据(方式2:从 zwwjHtml 读取编辑器内容)
- // 文档:/docs/普通JS读写Vue数据方法.md
- var htmlContent = window.ss.dom.get('zwwjHtml') || '';
- if (!htmlContent || htmlContent.trim() === '') {
- if (!confirm('正文内容为空,确定要生成空白公文吗?')) {
- return;
- }
- }
- // 收集生成参数
- var params = {
- institutionName: '广州工商学院',
- documentNumber: '数教函〔2026〕2号',
- documentTitle: title,
- htmlContent: htmlContent,
- sender: '数字教育与装备中心',
- receiver: '各学院、各部门:',
- hasAttachment: false,
- attachmentInfo: '',
- sealImagePath: 'D:\\tmp\\seal\\yz2.png',
- enableSeal: true
- };
- // 开始生成
- generateAndUploadDocument(params);
- }
- // 生成并上传公文
- function generateAndUploadDocument(params) {
- isGenerating = true;
- $('#generateStatus').html('正在生成公文...').css('color', '#1890ff');
- $('#generateDocumentBtn').prop('disabled', true).css('opacity', 0.7);
- // 使用XMLHttpRequest来获取二进制数据
- var xhr = new XMLHttpRequest();
- xhr.open('POST', "<ss:serv name='ws_zh_schtwj'/>", true);
- xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
- xhr.responseType = 'arraybuffer';
- // 构建请求参数
- var formData = new URLSearchParams();
- formData.append('institutionName', params.institutionName);
- formData.append('documentNumber', params.documentNumber);
- formData.append('documentTitle', params.documentTitle);
- formData.append('htmlContent', params.htmlContent);
- formData.append('sealImagePath', params.sealImagePath);
- formData.append('sender', params.sender);
- formData.append('receiver', params.receiver);
- formData.append('hasAttachment', params.hasAttachment);
- formData.append('attachmentInfo', params.attachmentInfo);
- formData.append('enableSeal', params.enableSeal);
- // 监听进度事件
- xhr.addEventListener('progress', function(e) {
- if (e.lengthComputable) {
- var percentComplete = (e.loaded / e.total) * 100;
- $('#generateStatus').html('生成中... ' + Math.round(percentComplete) + '%');
- }
- }, false);
- xhr.onload = function() {
- if (xhr.status === 200) {
- // 检查响应类型
- var contentType = xhr.getResponseHeader('Content-Type');
- if (contentType && contentType.indexOf('application/pdf') !== -1) {
- // 获取ArrayBuffer
- var arrayBuffer = xhr.response;
- if (!arrayBuffer || arrayBuffer.byteLength === 0) {
- $('#generateStatus').html('PDF文件流为空').css('color', '#ff4d4f');
- alert('生成的PDF文件为空,请检查服务器端');
- return;
- }
- // 创建Blob
- var blob = new Blob([arrayBuffer], { type: 'application/pdf' });
- var fileName = params.documentTitle.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g, '_') + '.pdf';
- if (blob.size === 0) {
- $('#generateStatus').html('Blob对象为空').css('color', '#ff4d4f');
- alert('生成的PDF文件为空,请检查服务器端');
- return;
- }
- // 上传生成的PDF文件
- uploadGeneratedPdf(blob, fileName, function(uploadResult) {
- if (uploadResult && uploadResult.fileList && uploadResult.fileList.length > 0) {
- var filePath = uploadResult.fileList[0].path;
- var fileName = uploadResult.fileList[0].fileName;
- // 回填到上传路径输入框
- var fullFilePath = filePath;
- $('#scyjpath').val(fullFilePath);
- $('input[name="scyjwj"]').val(fullFilePath);
- $('input[name="uploadPath"]').val(fullFilePath);
- $('#scyjBaseName').text(fileName);
- $('input[name="scyjBaseName"]').val(fileName);
- $('#checkScyj').show();
- $('#qxScyj').show();
- $('#generateStatus').html('生成并上传成功!').css('color', '#52c41a');
- alert('公文生成并上传成功!文件路径:' + fullFilePath);
- } else {
- $('#generateStatus').html('上传失败').css('color', '#ff4d4f');
- alert('上传失败,请重试');
- }
- });
- } else {
- // 尝试将响应解析为JSON
- try {
- var decoder = new TextDecoder('utf-8');
- var text = decoder.decode(new Uint8Array(xhr.response));
- var result = JSON.parse(text);
- if (result.success === false) {
- $('#generateStatus').html('生成失败:' + (result.message || '未知错误')).css('color', '#ff4d4f');
- alert('生成失败:' + (result.message || '未知错误'));
- } else {
- $('#generateStatus').html('未知响应格式').css('color', '#ff4d4f');
- alert('未知响应格式,请检查接口');
- }
- } catch (e) {
- $('#generateStatus').html('响应解析失败').css('color', '#ff4d4f');
- alert('服务器响应异常:' + e.message);
- }
- }
- } else {
- $('#generateStatus').html('生成失败,状态码:' + xhr.status).css('color', '#ff4d4f');
- alert('生成失败,HTTP状态码:' + xhr.status);
- }
- };
- xhr.onerror = function() {
- $('#generateStatus').html('生成失败:网络错误').css('color', '#ff4d4f');
- alert('生成失败:网络错误,请检查网络连接');
- };
- xhr.onloadend = function() {
- isGenerating = false;
- $('#generateDocumentBtn').prop('disabled', false).css('opacity', 1);
- };
- xhr.send(formData.toString());
- }
- // 上传生成的PDF文件
- function uploadGeneratedPdf(blob, fileName, callback) {
- $('#generateStatus').html('正在上传文件...').css('color', '#1890ff');
- if (blob.size === 0) {
- alert('要上传的文件为空,无法上传');
- callback(null);
- return;
- }
- // 创建FormData
- var formData = new FormData();
- formData.append('file', blob, fileName);
- formData.append('name', fileName);
- formData.append('type', 'document');
- formData.append('app', wd.app ? wd.app.name : getAccountInfo().xmmc);
- // 使用原有的上传接口
- $.ajax({
- url: "/service?ssServ=ulByHttp&type=document",
- type: 'POST',
- data: formData,
- processData: false,
- contentType: false,
- xhr: function() {
- var xhr = new XMLHttpRequest();
- xhr.upload.addEventListener('progress', function(e) {
- if (e.lengthComputable) {
- var percentComplete = (e.loaded / e.total) * 100;
- $('#generateStatus').html('上传中... ' + Math.round(percentComplete) + '%');
- }
- }, false);
- return xhr;
- },
- beforeSend: function() {
- },
- success: function(result) {
- try {
- if (typeof result === 'string') {
- result = JSON.parse(result);
- }
- if (result && result.fileList && result.fileList.length > 0) {
- callback(result);
- } else {
- callback(result);
- }
- } catch (e) {
- console.error('解析上传响应失败:', e);
- callback(null);
- }
- },
- error: function(xhr, status, error) {
- console.error('文件上传失败:', error);
- alert('文件上传失败:' + error);
- callback(null);
- }
- });
- }
- // 页面加载完成后初始化上传功能
- $(document).ready(function () {
- // 检查upload.js是否已加载
- if (typeof $.fn.uploadFile === 'undefined') {
- console.error('upload.js 未正确加载');
- alert('文件上传插件加载失败,请联系管理员');
- return;
- }
- // 调试:检查按钮是否存在
- // 初始化上传插件
- try {
- // 使用upload.js插件
- $('#scyjEdit').uploadFile({
- name: 'scyj', // 必须与页面中的元素ID前缀一致
- type: 'document', // 上传类型,可根据需要设置
- validation: 'jpg,jpeg,png,pdf,doc,docx,xls,xlsx,ppt,pptx,txt,zip,rar', // 允许上传的文件类型
- size: 10240, // 文件大小限制,单位KB(10MB)
- app: wd.app ? wd.app.name : getAccountInfo().xmmc, // 应用名称
- action: "/service?ssServ=ulByHttp&type=document", // 明确指定action
- beforeClick: function () {
- return true;
- },
- onchange: function (settings) {
- },
- callback: function (result) {
- if (result && result.fileList && result.fileList.length > 0) {
- // 显示成功消息
- var fileName = result.fileList[0].fileName;
- alert('文件 "' + fileName + '" 上传成功!');
- // 自动填充上传路径输入框
- var filePath = result.fileList[0].path;
- if (filePath) {
- $('input[name="uploadPath"]').val(filePath);
- }
- // 文件上传成功之后, 获取对应的文件 , 并且将pdf文件解析出正文内容
- // 获取文件路径, 然后调用后端代码
- // if (filePath && filePath.toLowerCase().endsWith('.pdf')) {
- if (filePath) {
- $.ajax({
- url: "<ss:serv name='ws_zh_pdf2html'/>",
- type: 'post',
- data: {
- path: filePath,
- fileName: fileName
- },
- success: function (result) {
- // 提取成功后, 将正文内容传输到正文控件中
- try {
- var parse = typeof result === 'string' ? JSON.parse(result) : result;
- // 使用桥接 API 写入 Vue 数据(推荐方式)
- // 文档:/docs/普通JS读写Vue数据方法.md
- // 这会自动更新编辑器内容
- window.ss.dom.set('zwwjHtml', parse.data || '');
- } catch (e) {
- console.warn('PDF解析结果处理失败:', e);
- }
- },
- error: function(xhr, status, error) {
- }
- });
- }
- }
- }
- });
- } catch (error) {
- alert('上传插件初始化失败: ' + error.message);
- // 如果upload.js插件失败,使用简单方法
- $('#scyjEdit').off('click.simple').on('click.simple', function () {
- // 创建一个临时的文件input
- var fileInput = $('#scyjEdit_File');
- if (fileInput.length === 0) {
- $('body').append('<input type="file" id="scyjEdit_File" style="display:none;">');
- fileInput = $('#scyjEdit_File');
- }
- fileInput.off('change').on('change', function () {
- if (this.files.length > 0) {
- var fileName = this.files[0].name;
- $('#scyjBaseName').text(fileName);
- $('input[name="scyjBaseName"]').val(fileName);
- $('#checkScyj').show();
- $('#qxScyj').show();
- alert('已选择文件: ' + fileName);
- }
- });
- fileInput.click();
- });
- }
- // 添加上传路径输入框的点击事件
- $('#scyjpath').click(function () {
- var currentPath = $(this).val();
- if (currentPath) {
- $(this).select();
- }
- });
- // 为删除按钮添加确认提示
- $('body').on('click', '#qxScyj', function (e) {
- if (!confirm('确定要删除已上传的文件吗?')) {
- e.preventDefault();
- return false;
- }
- });
- // 初始化页面时检查是否有已上传的文件
- var existingFile = $('input[name="scyjwj"]').val();
- if (existingFile) {
- var fileName = existingFile.split('/').pop();
- $('#scyjBaseName').text(fileName);
- $('input[name="scyjBaseName"]').val(fileName);
- $('#checkScyj').show();
- $('#qxScyj').show();
- $('input[name="uploadPath"]').val(existingFile);
- }
- });
- // 表单提交前的验证函数
- function validateForm() {
- var filePath = $('input[name="scyjwj"]').val();
- var title = $('input[name="bt"]').val();
- if (!title || title.trim() === '') {
- alert('请填写标题');
- $('input[name="bt"]').focus();
- return false;
- }
- if (!filePath || filePath.trim() === '') {
- if (!confirm('您尚未上传原件,确定要继续提交吗?')) {
- $('#scyjEdit').focus();
- return false;
- }
- }
- return true;
- }
- // ==================== Vue 桥接 API 使用示例 ====================
- // 文档:/docs/普通JS读写Vue数据方法.md
- /**
- * 示例1:读取编辑器内容
- * 使用 window.ss.dom.get() 从 Vue 实例读取数据
- */
- function readEditorContent() {
- // 方式1:通过桥接 API 读取(推荐)
- var htmlContent = window.ss.dom.get('zwwjHtml') || '';
- console.log('读取到编辑器内容,长度:', htmlContent.length);
- alert('编辑器内容长度: ' + htmlContent.length + '\n前100字: ' + htmlContent.substring(0, 100));
- return htmlContent;
- }
- /**
- * 示例2:写入编辑器内容
- * 使用 window.ss.dom.set() 向 Vue 实例写入数据
- */
- function writeEditorContent() {
- var sampleHtml = '<p style="color: blue;">这是通过桥接 API 插入的内容</p>' +
- '<p>当前时间: ' + new Date().toLocaleString() + '</p>';
- // 通过桥接 API 设置 Vue 数据,编辑器会自动更新
- window.ss.dom.set('zwwjHtml', sampleHtml);
- console.log('已写入编辑器内容');
- alert('已向编辑器写入示例内容');
- }
- /**
- * 示例3:读取和设置表单标题
- * 演示如何读写普通输入字段
- */
- function readFormTitle() {
- // 读取标题字段
- var title = window.ss.dom.get('bt') || '';
- console.log('当前标题:', title);
- return title;
- }
- /**
- * 示例3b:设置表单标题
- */
- function setFormTitle() {
- var newTitle = '新标题_' + new Date().getTime();
- window.ss.dom.set('bt', newTitle);
- console.log('已设置标题:', newTitle);
- alert('标题已设置为: ' + newTitle);
- }
- /**
- * 示例4:读取和设置下拉框(文书类别)
- * 演示如何操作下拉选择框(ss-objp 组件)
- */
- function readDocumentType() {
- // 读取文书类别代码
- var typeCode = window.ss.dom.get('wslbm') || '';
- // 定义选项映射
- var typeMap = {
- "1": "函",
- "11": "通知",
- "21": "请示",
- "31": "批复",
- "41": "报告",
- "81": "个人书信",
- "91": "其他"
- };
- var typeName = typeMap[typeCode] || '未选择';
- console.log('文书类别代码:', typeCode, '名称:', typeName);
- alert('当前文书类别:\n代码: ' + typeCode + '\n名称: ' + typeName);
- return { code: typeCode, name: typeName };
- }
- /**
- * 示例4b:设置下拉框值(文书类别)
- * 注意:下拉框通过 v-model 绑定,设置 code 即可
- */
- function setDocumentType() {
- // 定义选项
- var typeOptions = [
- { code: '1', name: '函' },
- { code: '11', name: '通知' },
- { code: '21', name: '请示' },
- { code: '31', name: '批复' },
- { code: '41', name: '报告' },
- { code: '81', name: '个人书信' },
- { code: '91', name: '其他' }
- ];
- // 随机选择一个(实际应用中是用户选择)
- var randomType = typeOptions[Math.floor(Math.random() * typeOptions.length)];
- // 设置下拉框的值(设置 code,组件自动显示对应文本)
- window.ss.dom.set('wslbm', randomType.code);
- console.log('已设置文书类别:', randomType);
- alert('已设置文书类别为: ' + randomType.name + ' (代码: ' + randomType.code + ')');
- }
- /**
- * 示例4d:读取所有下拉框值
- * 批量读取多个下拉框字段
- */
- function readAllDropdowns() {
- // 读取各个下拉框的值
- var values = {
- wslbm: window.ss.dom.get('wslbm') || '', // 文书类别
- wsmjm: window.ss.dom.get('wsmjm') || '', // 密级
- wsfwm: window.ss.dom.get('wsfwm') || '', // 范围
- gllbm: window.ss.dom.get('gllbm') || '' // 管理类别
- };
- // 定义映射表
- var maps = {
- wslbm: { "1": "函", "11": "通知", "21": "请示", "31": "批复", "41": "报告", "81": "个人书信", "91": "其他" },
- wsmjm: { "1": "公开", "2": "内部", "3": "秘密", "4": "机密", "5": "绝密" },
- wsfwm: { "1": "全局", "2": "部门", "3": "个人" },
- gllbm: { "1": "行政", "2": "人事", "3": "财务", "4": "业务" }
- };
- var result = '下拉框取值:\n';
- for (var key in values) {
- var code = values[key];
- var name = maps[key] && maps[key][code] ? maps[key][code] : code;
- result += key + ': ' + name + ' (代码: ' + code + ')\n';
- }
- alert(result);
- return values;
- }
- /**
- * 示例5:批量设置表单数据
- * 实际应用场景:快速填充表单
- */
- function batchSetFormData() {
- // 批量设置多个字段
- window.ss.dom.set('bt', '关于2026年度工作总结的通知');
- window.ss.dom.set('zy', '本文总结了2026年度的工作情况...');
- window.ss.dom.set('wslbm', '11'); // 通知
- window.ss.dom.set('wsmjm', '2'); // 内部
- alert('已批量设置:\n标题、摘要、文书类别(通知)、密级(内部)');
- }
- /**
- * 示例6:读取完整表单数据
- * 用于提交前预览或生成文档
- */
- function readFullFormData() {
- var formData = {
- // 基本信息
- title: window.ss.dom.get('bt') || '',
- summary: window.ss.dom.get('zy') || '',
- // 下拉框
- docType: window.ss.dom.get('wslbm') || '',
- secretLevel: window.ss.dom.get('wsmjm') || '',
- scope: window.ss.dom.get('wsfwm') || '',
- manageType: window.ss.dom.get('gllbm') || '',
- // 编辑器内容
- content: window.ss.dom.get('zwwjHtml') || '',
- // 人员部门
- draftPerson: window.ss.dom.get('ngryid') || '',
- draftDept: window.ss.dom.get('ngbmid') || ''
- };
- console.log('完整表单数据:', formData);
- // 生成预览文本
- var preview = '表单数据预览:\n' +
- '标题: ' + formData.title + '\n' +
- '文书类别: ' + formData.docType + '\n' +
- '密级: ' + formData.secretLevel + '\n' +
- '内容长度: ' + formData.content.length + ' 字符\n';
- alert(preview);
- return formData;
- }
- /**
- * 示例4:清空编辑器并显示提示
- * 结合读写操作
- */
- function clearEditorWithConfirm() {
- // 先读取当前内容
- var currentContent = window.ss.dom.get('zwwjHtml') || '';
- if (currentContent.length === 0) {
- alert('编辑器已经是空的');
- return;
- }
- if (confirm('确定要清空编辑器内容吗?当前有 ' + currentContent.length + ' 个字符')) {
- // 清空内容
- window.ss.dom.set('zwwjHtml', '');
- alert('已清空');
- }
- }
- /**
- * 示例5:生成公文时读取编辑器内容
- * 实际应用场景
- */
- function generateDocWithContent() {
- // 从 Vue 读取编辑器内容
- var htmlContent = window.ss.dom.get('zwwjHtml') || '';
- var title = window.ss.dom.get('bt') || '未命名';
- if (!htmlContent || htmlContent.trim() === '') {
- if (!confirm('正文内容为空,确定要生成空白公文吗?')) {
- return;
- }
- }
- console.log('准备生成公文:', {
- title: title,
- contentLength: htmlContent.length
- });
- // 这里调用生成公文的接口...
- alert('标题: ' + title + '\n内容长度: ' + htmlContent.length + '\n\n可以在这里调用生成接口');
- }
- // ==================== 示例结束 ====================
- // 修复uploadFile插件的问题
- function fixUploadPlugin() {
- // 检查是否有必要的CSS样式
- if (!$('.content-button').length) {
- $('#scyjEdit').addClass('content-button');
- }
- // 确保文件输入框存在
- if (!$('#scyjEdit_File').length) {
- $('body').append('<input type="file" id="scyjEdit_File" name="fileEdit" style="display:none;">');
- }
- // 手动绑定点击事件
- $('#scyjEdit').off('click.manual').on('click.manual', function () {
- $('#scyjEdit_File').click();
- });
- // 监听文件选择
- $('#scyjEdit_File').off('change').on('change', function (e) {
- if (this.files && this.files.length > 0) {
- var fileName = this.files[0].name;
- var fileSize = this.files[0].size;
- var fileType = this.files[0].type;
- // 显示文件信息
- $('#scyjBaseName').text(fileName);
- $('input[name="scyjBaseName"]').val(fileName);
- // 模拟上传
- simulateUpload(fileName, fileSize);
- }
- });
- }
- // 模拟文件上传
- function simulateUpload(fileName, fileSize) {
- // 显示进度条
- $('#scyjBaseName').html('<div class="progress"><div class="bar"></div><div class="percent">0%</div></div>');
- // 模拟上传进度
- var progress = 0;
- var interval = setInterval(function () {
- progress += 10;
- if (progress <= 100) {
- $('.bar').width(progress + '%');
- $('.percent').text(progress + '%');
- if (progress === 100) {
- clearInterval(interval);
- // 模拟上传完成
- setTimeout(function () {
- // 生成模拟文件路径
- var timestamp = new Date().getTime();
- var filePath = '/uploads/' + timestamp + '_' + fileName;
- // 更新页面
- $('#scyjBaseName').text(fileName);
- $('input[name="scyjwj"]').val(filePath);
- $('input[name="uploadPath"]').val(filePath);
- $('#checkScyj').show();
- $('#qxScyj').show();
- alert('文件 "' + fileName + '" 上传成功!');
- }, 500);
- }
- }
- }, 200);
- }
- // 页面完全加载后修复插件
- $(window).on('load', function () {
- // 如果upload.js插件没有正常工作,使用修复方法
- setTimeout(function () {
- if ($('#scyjEdit').length && !$('#scyjEdit').data('upload-initialized')) {
- fixUploadPlugin();
- }
- }, 1000);
- });
- </script>
- <ss:ichk name='ws_inp'/>
- <script> addRemoveToken('<%= pageContext.getAttribute(ss.page.PageC.PAGE_tokenList)%>');</script>
|