Prechádzať zdrojové kódy

优化修改资产信息新增修改功能

LinWuTai 1 rok pred
rodič
commit
41b8955de0

+ 16 - 0
ruoyi-admin/src/main/java/com/ruoyi/asset/controller/TbAssetInformationController.java

@@ -72,6 +72,10 @@ public class TbAssetInformationController extends BaseController
         return success(tbAssetInformationService.selectTbAssetInformationById(id));
     }
 
+    private boolean checkNumber(String number) {
+        return number.matches("^[A-Fa-f0-9]+$");
+    }
+
     /**
      * 新增资产信息
      */
@@ -80,6 +84,12 @@ public class TbAssetInformationController extends BaseController
     @PostMapping
     public AjaxResult add(@RequestBody TbAssetInformation tbAssetInformation)
     {
+        String number = tbAssetInformation.getNumber();
+        boolean flag = checkNumber(number);
+        if (!flag) {
+            return error("资产编号格式仅限[A-Fa-f0-9]");
+        }
+        tbAssetInformation.setCode(number);
         return toAjax(tbAssetInformationService.insertTbAssetInformation(tbAssetInformation));
     }
 
@@ -91,6 +101,12 @@ public class TbAssetInformationController extends BaseController
     @PutMapping
     public AjaxResult edit(@RequestBody TbAssetInformation tbAssetInformation)
     {
+        String number = tbAssetInformation.getNumber();
+        boolean flag = checkNumber(number);
+        if (!flag) {
+            return error("资产编号格式仅限[A-Fa-f0-9]");
+        }
+        tbAssetInformation.setCode(number);
         return toAjax(tbAssetInformationService.updateTbAssetInformation(tbAssetInformation));
     }
 

+ 4 - 3
ruoyi-ui/src/views/asset/information/index.vue

@@ -538,9 +538,9 @@
     <!-- 添加或修改资产信息对话框 -->
     <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="资产条码" prop="code">
+        <!-- <el-form-item  label="资产条码" prop="code">
           <el-input v-model="form.code" placeholder="请输入资产条码" />
-        </el-form-item>
+        </el-form-item> -->
         <el-form-item label="资产名称" prop="name">
           <el-input v-model="form.name" placeholder="请输入资产名称" />
         </el-form-item>
@@ -910,7 +910,8 @@ export default {
       // 表单校验
       rules: {
         number: [
-          { required: true, message: "资产编号不能为空", trigger: "blur" }
+          { required: true, message: "资产编号不能为空", trigger: "blur" },
+          { pattern: /^[A-Fa-f0-9]+$/, message: '资产编号格式仅限[A-Fa-f0-9]' }
         ],
         specificationsModel: [
           { required: true, message: "规格型号不能为空", trigger: "blur" }