Browse Source

设备管理添加编辑修改

hjs 1 year ago
parent
commit
e172644321

+ 1 - 6
src/views/device/add.vue

@@ -4,12 +4,7 @@
       添加设备
       <el-button type="primary" size="mini" style="margin-left: 20px;" @click="back">返回</el-button>
     </div>
-    <edit-device style="margin-left: 40px;" @finish="back" />
-    <div class="foot-layout">
-      <el-button style="margin-left: 20px;width: 120px;" @click="back">取 消</el-button>
-      <div style="width: 80px;" />
-      <el-button type="primary" style="width: 120px;" @click="submit">提 交</el-button>
-    </div>
+    <edit-device style="margin-left: 40px;" @finish="back" @back="back" />
   </div>
 </template>
 

+ 7 - 14
src/views/device/change.vue

@@ -4,12 +4,7 @@
       编辑设备
       <el-button type="primary" size="mini" style="margin-left: 20px;" @click="back">返回</el-button>
     </div>
-    <edit-device :obj="obj" style="margin-left: 40px;" @finish="back" />
-    <div class="foot-layout">
-      <el-button style="margin-left: 20px;width: 120px;" @click="back">取 消</el-button>
-      <div style="width: 80px;" />
-      <el-button type="primary" style="width: 120px;" @click="submit">提 交</el-button>
-    </div>
+    <edit-device :obj="obj" style="margin-left: 40px;" @finish="back" @back="back" />
   </div>
 </template>
 
@@ -34,6 +29,12 @@ export default {
       if (this.$route.query && this.$route.query.obj) {
         try {
           this.obj = JSON.parse(decodeURIComponent(this.$route.query.obj))
+          delete this.obj.tenantMachineAppId
+          delete this.obj.tenantName
+          delete this.obj.tenantServiceAddress
+          delete this.obj.tenantServiceAppId
+          delete this.obj.groupId
+          delete this.obj.sceneName
         } catch (e) {
           this.obj = null
         }
@@ -50,12 +51,4 @@ export default {
   font-size: 18px;
   color: #333333;
 }
-.foot-layout {
-  display: flex;
-  align-items: center;
-  justify-content: center;
-  margin-top: 34px;
-  padding-right: 180px;
-  margin-bottom: 20px;
-}
 </style>

+ 106 - 21
src/views/device/components/edit.vue

@@ -148,15 +148,15 @@
               class="avatar-uploader"
               action="#"
               :show-file-list="false"
-              :http-request="(event) => { doUploadAvatar(event, 'homeImgUrl'); }"
+              :http-request="(event) => { doUploadAvatar(event, 'homePageUrl'); }"
               :before-upload="beforeAvatarUpload"
               :auto-upload="true"
               accept="image/png,image/gif,image/jpg,image/jpeg"
             >
-              <img v-if="!form.homeImgUrl" class="upload-img" src="../../../assets/default-img-home.jpg" alt="">
+              <img v-if="!form.homePageUrl" class="upload-img" src="../../../assets/default-img-home.jpg" alt="">
               <div v-else class="upload-img">
-                <img :src="form.homeImgUrl">
-                <span class="del-img" @click.stop="handleRemove('homeImgUrl')">x</span>
+                <img :src="form.homePageUrl">
+                <span class="del-img" @click.stop="handleRemove('homePageUrl')">x</span>
               </div>
             </el-upload>
           </el-form-item>
@@ -171,11 +171,11 @@
               :auto-upload="true"
               accept="image/png,image/gif,image/jpg,image/jpeg"
             >
-              <!-- <view v-if="!form.transitionPageUrl">
-                <i class="el-icon-upload" />
+              <div v-if="!form.transitionPageUrl" class="upload-default">
+                <i class="avatar-uploader-icon el-icon-picture-outline" />
                 <div class="el-upload__text">上传图片</div>
-              </view> -->
-              <i v-if="!form.transitionPageUrl" class="el-icon-plus avatar-uploader-icon" />
+              </div>
+              <!-- <i v-if="!form.transitionPageUrl" class="el-icon-plus avatar-uploader-icon" /> -->
               <div v-else class="upload-img">
                 <img :src="form.transitionPageUrl">
                 <span class="del-img" @click.stop="handleRemove('transitionPageUrl')">x</span>
@@ -236,6 +236,11 @@
         </div>
       </div>
     </el-form>
+    <div class="foot-layout">
+      <el-button style="margin-left: 20px;width: 120px;" @click="back">取 消</el-button>
+      <div style="width: 80px;" />
+      <el-button type="primary" style="width: 120px;" :loading="submitLoading" @click="submit">提 交</el-button>
+    </div>
   </div>
 </template>
 
@@ -297,7 +302,7 @@ export default {
         forbidPullDown: false,
         // 隐藏底部导航栏 默认: false
         hideNavigationBar: false,
-        // 首页图片
+        // 首页图片配置
         homePageUrl: null,
         id: null,
         // 是否抓拍人脸 默认:false
@@ -360,15 +365,49 @@ export default {
       },
       rules: {
         sn: [
-          {
-            required: true,
-            message: '请输入设备sn',
-            trigger: 'blur'
-          }
+          { required: true, whitespace: true, message: '不能为空!', trigger: ['change', 'blur'] }
+        ],
+        tenantId: [
+          { required: true, type: 'number', whitespace: true, message: '不能为空!', trigger: ['change', 'blur'] }
+        ],
+        company: [
+          { required: true, whitespace: true, message: '不能为空!', trigger: ['change', 'blur'] }
+        ],
+        mode: [
+          { required: true, whitespace: true, message: '不能为空!', trigger: ['change', 'blur'] }
+        ],
+        useAlipayFace: [
+          { required: true, type: 'boolean', whitespace: true, message: '不能为空!', trigger: 'blur' }
         ]
       }
     }
   },
+  watch: {
+    'form.mode': {
+      handler(value) {
+        if (!value || value === 'public') {
+          this.form.userLibId = null
+        }
+      },
+      immediate: true
+    }
+  },
+  // watch: {
+  //   obj: {
+  //     handler(value) {
+  //       let temp = null
+  //       if (value) {
+  //         temp = value
+  //         if (!temp.zoloConfig) {
+  //           temp.zoloConfig = this.form.zoloConfig
+  //         }
+  //       }
+  //       this.form = temp
+  //       console.info('obj-->', this.form)
+  //     },
+  //     immediate: true
+  //   }
+  // },
   mounted() {
     this.initData()
   },
@@ -377,9 +416,17 @@ export default {
       this.getMerchantList()
       this.getSceneList()
       this.getUserlibList()
-      if (this.obj) {
-        this.form = this.obj
-      }
+      this.$nextTick(() => {
+        if (this.obj) {
+          if (!this.obj.zoloConfig) {
+            this.obj.zoloConfig = this.form.zoloConfig
+          }
+          this.form = this.obj
+        }
+      })
+    },
+    back() {
+      this.$emit('back')
     },
     getMerchantList() {
       getAllList().then(res => {
@@ -458,11 +505,15 @@ export default {
           }
 
           // 开门信号
-          // if (this.form.useSerialPort !== 'RS232') {
-          //   this.form.
-          // }
+          if (this.form.useSerialPort !== 'RS232') {
+            this.form.signalNo = null
+          }
           await add(this.form)
-          this.$emit('finish')
+          this.$message({
+            message: `${this.form.id ? '修改' : '添加'}成功!`,
+            type: 'success'
+          })
+          this.$emit('back')
         } catch (e) {
           console.info('add', e)
         } finally {
@@ -523,6 +574,30 @@ export default {
       .overlength ::v-deep .el-form-item__label {
         line-height: 1.4;
       }
+      .avatar-uploader .upload-default {
+        border: 1px dashed #d9d9d9;
+        border-radius: 0;
+        cursor: pointer;
+        width: 70px;
+        overflow: hidden;
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+        justify-content: center;
+      }
+      .upload-default .avatar-uploader-icon {
+        color: #8c939d;
+        width: 22px;
+        height: 18px;
+        font-size: 20px;
+        margin-top: 24px;
+      }
+      .upload-default .el-upload__text {
+        margin-top: 8px;
+        font-size: 14px;
+        font-weight: 400;
+        color: #CED3E3;
+      }
       .upload-img {
         width: 63px;
         height: 91px;
@@ -560,5 +635,15 @@ export default {
       }
     }
   }
+
+  .foot-layout {
+    width: 100%;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    margin-top: 34px;
+    padding-right: 180px;
+    margin-bottom: 20px;
+  }
 }
 </style>

+ 4 - 4
src/views/device/index.vue

@@ -1,7 +1,7 @@
 <template>
   <div class="app-container">
-    <!-- <addModal ref="addModel" @success="modalSuccess" />
-    <uploadModal ref="uploadModal" @finish="modalSuccess(false)" /> -->
+    <!-- <addModal ref="addModel" @success="modalSuccess" /> -->
+    <uploadModal ref="uploadModal" @finish="modalSuccess(false)" />
     <div class="search-layout" style="margin-bottom: 0px;margin-top: -10px;">
       <el-input v-model="form.sn" placeholder="设备sn" style="width: 256px;" class="filter-item" />
       <el-input v-model="form.company" placeholder="公司名" style="width: 256px;" class="filter-item" />
@@ -124,7 +124,7 @@
 
 <script>
 // import AddModal from './modal/AddModal.vue'
-// import UploadModal from './modal/UploadModal.vue'
+import UploadModal from './modal/UploadModal.vue'
 import tableMixins from '@/mixins/tableMixins'
 import { getList, deleteById, autoById, autoCancelById } from '@/api/device'
 import { getAllList as getMerchantList } from '@/api/merchant'
@@ -133,7 +133,7 @@ import { getList as getUserlibList } from '@/api/userlib'
 import Pagination from '@/components/Pagination'
 
 export default {
-  components: { Pagination },
+  components: { Pagination, UploadModal },
   filters: {
     statusFilter(status) {
       return status ? 'success' : 'info'