Browse Source

修改文件名

laiguoran 3 years ago
parent
commit
6dd6b35b8d

+ 27 - 0
app/controller/wap_controller.js

@@ -677,6 +677,33 @@ module.exports = app => {
         }
 
         /**
+         * 编辑附件
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        async shoufangEditFile(ctx) {
+            const responseData = {
+                err: 0,
+                msg: '',
+                data: '',
+            };
+            try {
+
+                const data = JSON.parse(ctx.request.body.data);
+                const fileInfo = await ctx.service.stageShoufangAtt.getDataById(data.id);
+                if (!fileInfo || !Object.keys(fileInfo).length) {
+                    throw '该文件不存在';
+                }
+                await ctx.service.stageShoufangAtt.edit(data);
+            } catch (err) {
+                responseData.err = 1;
+                responseData.msg = err;
+            }
+
+            ctx.body = responseData;
+        }
+
+        /**
          * 下载附件
          * @param {Object} ctx - egg全局变量
          * @return {void}

+ 62 - 2
app/public/js/stage.js

@@ -4356,11 +4356,12 @@ $(document).ready(() => {
         $('#shoufang-flie-list').html(html);
         postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
             for (const att of result) {
-                html += `<tr><td>${att.filename}${att.fileext}</td><td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
+                html += `<tr><td>${att.filename}${att.fileext} ` + makeEditHtml(att.id, att.filename, att.fileext, att.extra_upload) +
+                    `<td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
                     `<a href="${att.filepath}" target="_blank"><i class="fa fa-download"></i></a>` + makeDelHtml(att.id, att.extra_upload) +`</td></tr>`;
             }
             $('#shoufang-flie-list').html(html);
-            $('[data-toggle="tooltip"]').tooltip();
+            $('[data-toggle="tooltip"]').tooltip()
         });
 
         function makeDelHtml(fid, extra_upload) {
@@ -4370,6 +4371,65 @@ $(document).ready(() => {
                 '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
         }
     });
+    function makeEditHtml(fid, filename, fileext, extra_upload) {
+        return sfAttDelPower &&
+        (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
+            '<a href="javascript:void(0)" data-filename="' + filename + '" data-fileext="'+ fileext +'" data-id="'+ fid +'" class="edit-shoufang-att ml-1">' +
+            '<i data-toggle="tooltip" data-placement="left" data-original-title="修改文件名" class="fa fa-pencil"></i></a></td>' : ''
+    }
+    // 修改收方单附件文件名
+    $('body').on('click', '.edit-shoufang-att', function () {
+        $(this).children('i').tooltip('hide');
+        const fid = $(this).data('id');
+        const filename = $(this).data('filename');
+        const fileext = $(this).data('fileext');
+        const html = `<div class="input-group input-group-sm">
+            <input type="text" class="form-control" value="${filename}" placeholder="输入文件名" aria-describedby="button-${fid}" style="width:50px">
+            <div class="input-group-append" id="button-${fid}">
+                <button class="btn btn-outline-primary shoufang-att-confirm-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">确认</button>
+                <button class="btn btn-outline-secondary shoufang-att-cancel-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">取消</button>
+            </div>
+            </div>`;
+        $(this).parents('td').html(html);
+    });
+    // 确认修改文件名
+    $('body').on('click', '.shoufang-att-confirm-btn', function () {
+        const validText = $.trim($(this).parents('td').find('input').val());
+        const orgValue = $.trim($(this).data('filename'));
+        const fileext = $(this).data('fileext');
+        const fid = $(this).data('fid');
+        if (!validText) {
+            toastr.error('文件名不能为空');
+            return;
+        }
+        // const reg = /^[0-9a-zA-Z\-_\u4e00-\u9fa5]+$/;
+        if(validText.indexOf('.') !== -1 || validText.indexOf(' ') !== -1) {
+            toastr.error('文件名中不能包含.字符和空格');
+            return;
+        }
+        if(validText == orgValue) {
+            const html = `${orgValue}${fileext} ` + makeEditHtml(fid, orgValue, fileext, 1);
+            $(this).parents('td').html(html);
+            return;
+        }
+        const data = {
+            id: fid,
+            filename: validText,
+        };
+        const _self = $(this);
+        postData('/wap/shoufang/editfile', data, function (result) {
+            const html = `${validText}${fileext} ` + makeEditHtml(fid, validText, fileext, 1);
+            _self.parents('td').html(html);
+        });
+    });
+    // 取消修改文件名
+    $('body').on('click', '.shoufang-att-cancel-btn', function () {
+        const fid = $(this).data('fid');
+        const filename = $(this).data('filename');
+        const fileext = $(this).data('fileext');
+        const html = `${filename}${fileext} ` + makeEditHtml(fid, filename, fileext, 1);
+        $(this).parents('td').html(html);
+    });
     // 删除收方单附件
     $('body').on('click', '.del-shoufang-att', function () {
         const id = $(this).data('id');

+ 1 - 0
app/router.js

@@ -547,6 +547,7 @@ module.exports = app => {
     app.get('/wap/shoufang/upload', 'wapController.shoufangUpload');
     app.post('/wap/shoufang/upfile', 'wapController.shoufangUpFile');
     app.post('/wap/shoufang/delfile', 'wapController.shoufangDeleteFile');
+    app.post('/wap/shoufang/editfile', 'wapController.shoufangEditFile');
     app.get('/wap/shoufang/download/file/:fid', 'wapController.shoufangDownloadFile');
 
     // 决策大屏

+ 12 - 0
app/service/stage_shoufang_att.js

@@ -43,6 +43,18 @@ module.exports = app => {
         }
 
         /**
+         * 修改附件
+         * @param {Object} postData - 表单信息
+         * @param {Object} fileData - 文件信息
+         * @param {int} uid - 上传者id
+         * @return {void}
+         */
+        async edit(data) {
+            const result = await this.db.update(this.tableName, data);
+            return result.affectedRows === 1;
+        }
+
+        /**
          * 添加附件
          * @param {Object} postData - 表单信息
          * @param {Object} fileData - 文件信息

+ 3 - 3
app/view/stage/modal.ejs

@@ -545,9 +545,9 @@
             <div class="modal-header">
                 <h5 class="modal-title">收方单附件</h5>
             </div>
-            <div class="modal-body modal-height-300" style="overflow: auto">
-                <table class="table table-bordered">
-                    <tr><th>文件名</th><th>上传时间</th><th>下载</th></tr>
+            <div class="modal-body modal-height-300" style="overflow: auto;overflow-x:hidden;">
+                <table class="table table-sm table-bordered table-hover" style="word-break:break-all; table-layout: fixed">
+                    <tr><th>文件名</th><th width="120">上传时间</th><th width="50">下载</th></tr>
                     <tbody id="shoufang-flie-list">
 
                     </tbody>