Browse Source

一些bug修复

laiguoran 6 năm trước cách đây
mục cha
commit
bfc7f26bb3

+ 13 - 2
app/controller/change_controller.js

@@ -215,7 +215,7 @@ module.exports = app => {
                 }
                 const data = JSON.parse(ctx.request.body.data);
                 if (!data.code || data.code === '' || !data.name || data.name === '') {
-                    throw '提交数据错误';
+                    throw '变更令名称不能为空';
                 }
 
                 const change = await ctx.service.change.add(tenderId, ctx.session.sessionUser.accountId, data.code, data.name);
@@ -596,9 +596,20 @@ module.exports = app => {
                     const fileInfo = await ctx.service.changeAtt.getDataById(id);
                     if (fileInfo !== undefined && fileInfo !== '') {
                         const fileName = path.join(this.app.baseDir, fileInfo.filepath);
+                        // 解决中文无法下载问题
+                        const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
+                        let disposition = '';
+                        if (userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
+                            disposition = 'attachment; filename=' + encodeURIComponent(fileInfo.filename + fileInfo.fileext);
+                        } else if (userAgent.indexOf('firefox') >= 0) {
+                            disposition = 'attachment; filename*="utf8\'\'' + encodeURIComponent(fileInfo.filename + fileInfo.fileext) + '"';
+                        } else {
+                            /* safari等其他非主流浏览器只能自求多福了 */
+                            disposition = 'attachment; filename=' + new Buffer(fileInfo.filename + fileInfo.fileext).toString('binary');
+                        }
                         ctx.response.set({
                             'Content-Type': 'application/octet-stream',
-                            'Content-Disposition': 'attachment; filename=' + fileInfo.filename + fileInfo.fileext,
+                            'Content-Disposition': disposition,
                             'Content-Length': fileInfo.filesize,
                         });
                         ctx.body = await fs.createReadStream(fileName);

+ 1 - 1
app/extend/helper.js

@@ -65,7 +65,7 @@ module.exports = {
      * @return {string} - 大小
      */
     bytesToSize(bytes) {
-        if (bytes === 0) return '0 B';
+        if (parseInt(bytes) === 0) return '0 B';
         const k = 1024;
         const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
         const i = Math.floor(Math.log(bytes) / Math.log(k));

+ 2 - 0
app/public/js/change.js

@@ -12,6 +12,8 @@ function getNewCode() {
     postData('/tender/'+ $('#tenderId').val() +'/change/newCode', null, function (code) {
         if (code !== '') {
             $('#bj-code').val(code);
+        } else {
+            $('#bj-code').val('变更申请编号');
         }
     });
 }

+ 1 - 1
app/view/change/info.ejs

@@ -179,7 +179,7 @@
                     <div class="col-md-4">
                         <div class="form-group">
                             <label><b class="text-danger">*&nbsp;</b>申请编号</label>
-                            <% if (tender.c_rule !== null && JSON.parse(tender.c_rule).length !== 0) { %><a href="javascript:void(0);" class="pull-right reduction-code" data-toggle="tooltip" data-placement="bottom" title="" data-code="<%- change.code %>" data-original-title="自动编号"><i class="fa fa-repeat"></i></a><% } %>
+                            <a href="javascript:void(0);" class="pull-right reduction-code" data-toggle="tooltip" data-placement="bottom" title="" data-code="<%- change.code %>" data-original-title="自动编号"><i class="fa fa-repeat"></i></a>
                             <input class="form-control" name="code" value="<%- change.code %>" type="text">
                         </div>
                         <div class="form-group">