Browse Source

feat(oss): 增加文件上传大小限制并添加复制地址功能

- 将文件上传大小限制从5MB增加到500MB
- 在OSS管理界面添加复制文件地址功能
- 优化代码格式化和引号统一
- 修复按钮标签闭合问题
- 添加Base64解码支持用于短信接口
JX.Li 4 hours ago
parent
commit
42507b6715

+ 8 - 2
nexo-example/nexo-demo/src/main/java/com/nexo/demo/controller/SmsController.java

@@ -2,6 +2,7 @@ package com.nexo.demo.controller;
 
 import com.alibaba.fastjson2.JSONObject;
 import com.nexo.common.core.domain.R;
+import jdk.nashorn.internal.scripts.JS;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.dromara.sms4j.api.SmsBlend;
@@ -11,6 +12,8 @@ import org.dromara.sms4j.provider.enumerate.SupplierType;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
 import java.util.LinkedHashMap;
 
 /**
@@ -28,8 +31,11 @@ import java.util.LinkedHashMap;
 public class SmsController {
 
     @PostMapping("wxtest")
-    public R<?> wxtest(@RequestBody JSONObject json) {
-        log.info(json.toJSONString());
+    public R<?> wxtest(@RequestBody String base64String) {
+        byte[] decodedBytes = Base64.getDecoder().decode(base64String);
+        String decodedString = new String(decodedBytes, StandardCharsets.UTF_8);
+        JSONObject parsed = JSONObject.parseObject(decodedString);
+        log.info(parsed.toJSONString());
         return R.ok();
     }
 

+ 1 - 1
nexo-ui/src/components/FileUpload/index.vue

@@ -56,7 +56,7 @@ export default {
     // 大小限制(MB)
     fileSize: {
       type: Number,
-      default: 5,
+      default: 500,
     },
     // 文件类型, 例如['png', 'jpg', 'jpeg']
     fileType: {

+ 13 - 1
nexo-ui/src/utils/nexo.js

@@ -1,4 +1,16 @@
-
+import { Message } from 'element-ui'
+
+export function copyText(text) {
+  console.log(text);
+  navigator.clipboard
+    .writeText(text)
+    .then(() => {
+      Message.success('复制成功');
+    })
+    .catch((err) => {
+      Message.error('复制失败');
+    })
+}
 
 /**
  * 通用js方法封装处理

+ 117 - 95
nexo-ui/src/views/system/oss/index.vue

@@ -74,7 +74,8 @@
           size="mini"
           @click="handleFile"
           v-hasPermi="['system:oss:upload']"
-        >上传文件</el-button>
+        >上传文件
+        </el-button>
       </el-col>
       <el-col :span="1.5">
         <el-button
@@ -84,7 +85,8 @@
           size="mini"
           @click="handleImage"
           v-hasPermi="['system:oss:upload']"
-        >上传图片</el-button>
+        >上传图片
+        </el-button>
       </el-col>
       <el-col :span="1.5">
         <el-button
@@ -95,7 +97,8 @@
           :disabled="multiple"
           @click="handleDelete"
           v-hasPermi="['system:oss:remove']"
-        >删除</el-button>
+        >删除
+        </el-button>
       </el-col>
       <el-col :span="1.5">
         <el-button
@@ -104,7 +107,8 @@
           size="mini"
           @click="handlePreviewListResource(!previewListResource)"
           v-hasPermi="['system:oss:edit']"
-        >预览开关 : {{previewListResource ? "禁用" : "启用"}}</el-button>
+        >预览开关 : {{ previewListResource ? '禁用' : '启用' }}
+        </el-button>
       </el-col>
       <el-col :span="1.5">
         <el-button
@@ -114,7 +118,8 @@
           size="mini"
           @click="handleOssConfig"
           v-hasPermi="['system:oss:list']"
-        >配置管理</el-button>
+        >配置管理
+        </el-button>
       </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
@@ -122,32 +127,37 @@
     <el-table v-loading="loading" :data="ossList" @selection-change="handleSelectionChange"
               :header-cell-class-name="handleHeaderClass"
               @header-click="handleHeaderCLick"
-              v-if="showTable">
-      <el-table-column type="selection" width="55" align="center" />
+              v-if="showTable"
+    >
+      <el-table-column type="selection" width="55" align="center"/>
       <el-table-column label="对象存储主键" align="center" prop="ossId" v-if="false"/>
-      <el-table-column label="文件名" align="center" prop="fileName" />
-      <el-table-column label="原名" align="center" prop="originalName" />
-      <el-table-column label="文件后缀" align="center" prop="fileSuffix" />
+      <el-table-column label="文件名" align="center" prop="fileName"/>
+      <el-table-column label="原名" align="center" prop="originalName"/>
+      <el-table-column label="文件后缀" align="center" prop="fileSuffix"/>
       <el-table-column label="文件展示" align="center" prop="url">
         <template slot-scope="scope">
           <ImagePreview
             v-if="previewListResource && checkFileSuffix(scope.row.fileSuffix)"
             :width=100 :height=100
             :src="scope.row.url"
-            :preview-src-list="[scope.row.url]"/>
+            :preview-src-list="[scope.row.url]"
+          />
           <span v-text="scope.row.url"
-                v-if="!checkFileSuffix(scope.row.fileSuffix) || !previewListResource"/>
+                v-if="!checkFileSuffix(scope.row.fileSuffix) || !previewListResource"
+          />
         </template>
       </el-table-column>
       <el-table-column label="创建时间" align="center" prop="createTime" width="180"
-                       sortable="custom" >
+                       sortable="custom"
+      >
         <template slot-scope="scope">
           <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
         </template>
       </el-table-column>
-      <el-table-column label="上传人" align="center" prop="createBy" />
+      <el-table-column label="上传人" align="center" prop="createBy"/>
       <el-table-column label="服务商" align="center" prop="service"
-                       sortable="custom"/>
+                       sortable="custom"
+      />
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
         <template slot-scope="scope">
           <el-button
@@ -156,14 +166,23 @@
             icon="el-icon-edit"
             @click="handleDownload(scope.row)"
             v-hasPermi="['system:oss:download']"
-          >下载</el-button>
+          >下载
+          </el-button>
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-edit"
+            @click="copyText(scope.row.url)"
+          >复制地址
+          </el-button>
           <el-button
             size="mini"
             type="text"
             icon="el-icon-delete"
             @click="handleDelete(scope.row)"
             v-hasPermi="['system:oss:remove']"
-          >删除</el-button>
+          >删除
+          </el-button>
         </template>
       </el-table-column>
     </el-table>
@@ -180,7 +199,7 @@
     <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
       <el-form ref="form" :model="form" :rules="rules" label-width="80px">
         <el-form-item label="文件名">
-          <fileUpload v-model="form.file" v-if="type === 0"/>
+          <fileUpload v-model="form.file" v-if="type === 0" :file-type="null"/>
           <imageUpload v-model="form.file" v-if="type === 1"/>
         </el-form-item>
       </el-form>
@@ -193,10 +212,11 @@
 </template>
 
 <script>
-import { listOss, delOss } from "@/api/system/oss";
+import { listOss, delOss } from '@/api/system/oss'
+import { copyText } from '@/utils/nexo'
 
 export default {
-  name: "Oss",
+  name: 'Oss',
   data() {
     return {
       showTable: true,
@@ -219,7 +239,7 @@ export default {
       // OSS对象存储表格数据
       ossList: [],
       // 弹出层标题
-      title: "",
+      title: '',
       // 弹出层标题
       type: 0,
       // 是否显示弹出层
@@ -229,7 +249,7 @@ export default {
       // 创建时间时间范围
       daterangeCreateTime: [],
       // 默认排序
-      defaultSort: {prop: 'createTime', order: 'ascending'},
+      defaultSort: { prop: 'createTime', order: 'ascending' },
       // 查询参数
       queryParams: {
         pageNum: 1,
@@ -247,73 +267,74 @@ export default {
       // 表单校验
       rules: {
         file: [
-          { required: true, message: "文件不能为空", trigger: "blur" }
+          { required: true, message: '文件不能为空', trigger: 'blur' }
         ]
       }
-    };
+    }
   },
   created() {
-    this.getList();
+    this.getList()
   },
   methods: {
+    copyText,
     /** 查询OSS对象存储列表 */
     getList() {
-      this.loading = true;
-      this.queryParams.params = {};
+      this.loading = true
+      this.queryParams.params = {}
       if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
-        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
-        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
+        this.queryParams.params['beginCreateTime'] = this.daterangeCreateTime[0]
+        this.queryParams.params['endCreateTime'] = this.daterangeCreateTime[1]
       }
-      this.getConfigKey("sys.oss.previewListResource").then(response => {
-        this.previewListResource = response.msg === undefined ? true : response.msg === 'true';
-      });
+      this.getConfigKey('sys.oss.previewListResource').then(response => {
+        this.previewListResource = response.msg === undefined ? true : response.msg === 'true'
+      })
       listOss(this.queryParams).then(response => {
-        this.ossList = response.rows;
-        this.total = response.total;
-        this.loading = false;
-        this.showTable = true;
-      });
+        this.ossList = response.rows
+        this.total = response.total
+        this.loading = false
+        this.showTable = true
+      })
     },
     checkFileSuffix(fileSuffix) {
-      let arr = ["png", "jpg", "jpeg"];
+      let arr = ['png', 'jpg', 'jpeg']
       return arr.some(type => {
-        return fileSuffix.indexOf(type) > -1;
-      });
+        return fileSuffix.indexOf(type) > -1
+      })
     },
     // 取消按钮
     cancel() {
-      this.open = false;
-      this.reset();
+      this.open = false
+      this.reset()
     },
     // 表单重置
     reset() {
       this.form = {
-        file: undefined,
-      };
-      this.resetForm("form");
+        file: undefined
+      }
+      this.resetForm('form')
     },
     /** 搜索按钮操作 */
     handleQuery() {
-      this.queryParams.pageNum = 1;
-      this.getList();
+      this.queryParams.pageNum = 1
+      this.getList()
     },
     /** 重置按钮操作 */
     resetQuery() {
-      this.showTable = false;
-      this.daterangeCreateTime = [];
-      this.resetForm("queryForm");
-      this.queryParams.orderByColumn = this.defaultSort.prop;
-      this.queryParams.isAsc = this.defaultSort.order;
-      this.handleQuery();
+      this.showTable = false
+      this.daterangeCreateTime = []
+      this.resetForm('queryForm')
+      this.queryParams.orderByColumn = this.defaultSort.prop
+      this.queryParams.isAsc = this.defaultSort.order
+      this.handleQuery()
     },
     // 多选框选中数据
     handleSelectionChange(selection) {
       this.ids = selection.map(item => item.ossId)
-      this.single = selection.length!==1
+      this.single = selection.length !== 1
       this.multiple = !selection.length
     },
     // 设置列的排序为我们自定义的排序
-    handleHeaderClass({column}) {
+    handleHeaderClass({ column }) {
       column.order = column.multiOrder
     },
     // 点击表头进行排序
@@ -323,62 +344,62 @@ export default {
       }
       switch (column.multiOrder) {
         case 'descending':
-          column.multiOrder = 'ascending';
-          break;
+          column.multiOrder = 'ascending'
+          break
         case 'ascending':
-          column.multiOrder = '';
-          break;
+          column.multiOrder = ''
+          break
         default:
-          column.multiOrder = 'descending';
-          break;
+          column.multiOrder = 'descending'
+          break
       }
       this.handleOrderChange(column.property, column.multiOrder)
     },
     handleOrderChange(prop, order) {
-      let orderByArr = this.queryParams.orderByColumn ? this.queryParams.orderByColumn.split(",") : [];
-      let isAscArr = this.queryParams.isAsc ? this.queryParams.isAsc.split(",") : [];
+      let orderByArr = this.queryParams.orderByColumn ? this.queryParams.orderByColumn.split(',') : []
+      let isAscArr = this.queryParams.isAsc ? this.queryParams.isAsc.split(',') : []
       let propIndex = orderByArr.indexOf(prop)
       if (propIndex !== -1) {
         if (order) {
           //排序里已存在 只修改排序
-          isAscArr[propIndex] = order;
+          isAscArr[propIndex] = order
         } else {
           //如果order为null 则删除排序字段和属性
-          isAscArr.splice(propIndex, 1);//删除排序
-          orderByArr.splice(propIndex, 1);//删除属性
+          isAscArr.splice(propIndex, 1)//删除排序
+          orderByArr.splice(propIndex, 1)//删除属性
         }
       } else {
         //排序里不存在则新增排序
-        orderByArr.push(prop);
-        isAscArr.push(order);
+        orderByArr.push(prop)
+        isAscArr.push(order)
       }
       //合并排序
-      this.queryParams.orderByColumn = orderByArr.join(",");
-      this.queryParams.isAsc = isAscArr.join(",");
-      this.getList();
+      this.queryParams.orderByColumn = orderByArr.join(',')
+      this.queryParams.isAsc = isAscArr.join(',')
+      this.getList()
     },
     /** 任务日志列表查询 */
     handleOssConfig() {
-      this.$router.push({ path: '/system/oss-config/index'})
+      this.$router.push({ path: '/system/oss-config/index' })
     },
     /** 文件按钮操作 */
     handleFile() {
-      this.reset();
-      this.open = true;
-      this.title = "上传文件";
-      this.type = 0;
+      this.reset()
+      this.open = true
+      this.title = '上传文件'
+      this.type = 0
     },
     /** 图片按钮操作 */
     handleImage() {
-      this.reset();
-      this.open = true;
-      this.title = "上传图片";
-      this.type = 1;
+      this.reset()
+      this.open = true
+      this.title = '上传图片'
+      this.type = 1
     },
     /** 提交按钮 */
     submitForm() {
-      this.open = false;
-      this.getList();
+      this.open = false
+      this.getList()
     },
     /** 下载按钮操作 */
     handleDownload(row) {
@@ -386,28 +407,29 @@ export default {
     },
     /** 删除按钮操作 */
     handleDelete(row) {
-      const ossIds = row.ossId || this.ids;
+      const ossIds = row.ossId || this.ids
       this.$modal.confirm('是否确认删除OSS对象存储编号为"' + ossIds + '"的数据项?').then(() => {
-        this.loading = true;
-        return delOss(ossIds);
+        this.loading = true
+        return delOss(ossIds)
       }).then(() => {
-        this.loading = false;
-        this.getList();
-        this.$modal.msgSuccess("删除成功");
+        this.loading = false
+        this.getList()
+        this.$modal.msgSuccess('删除成功')
       }).finally(() => {
-        this.loading = false;
-      });
+        this.loading = false
+      })
     },
     // 预览列表图片状态修改
     handlePreviewListResource(previewListResource) {
-      let text = previewListResource ? "启用" : "停用";
+      let text = previewListResource ? '启用' : '停用'
       this.$modal.confirm('确认要"' + text + '""预览列表图片"配置吗?').then(() => {
-        return this.updateConfigByKey("sys.oss.previewListResource", previewListResource);
+        return this.updateConfigByKey('sys.oss.previewListResource', previewListResource)
       }).then(() => {
         this.getList()
-        this.$modal.msgSuccess(text + "成功");
-      }).catch(() => {})
+        this.$modal.msgSuccess(text + '成功')
+      }).catch(() => {
+      })
     }
   }
-};
+}
 </script>