Pārlūkot izejas kodu

refactor: transmitter

Casper Dai 3 gadi atpakaļ
vecāks
revīzija
d4d81cbe7f

+ 0 - 48
src/api/device.js

@@ -264,51 +264,3 @@ export function getDeviceAlarms (query) {
     }
   })
 }
-
-export function getSensors (options) {
-  return request({
-    url: '/device/sensorType',
-    method: 'GET',
-    ...options
-  })
-}
-
-export function getReceivingCardManufacturers () {
-  return request({
-    url: '/device/manufacturer/list',
-    method: 'GET'
-  })
-}
-
-export function getReceivingCard (id) {
-  return request({
-    url: `/device/information/${id}`,
-    method: 'GET'
-  })
-}
-
-export function addReceivingCard (id, data, onUploadProgress) {
-  return request({
-    url: `/device/information/${id}`,
-    method: 'POST',
-    timeout: 0,
-    data, onUploadProgress
-  })
-}
-
-export function updateReceivingCard (id, data, onUploadProgress) {
-  return update({
-    url: `/device/information/${id}`,
-    method: 'PUT',
-    timeout: 0,
-    data, onUploadProgress
-  })
-}
-
-export function getReceivingCardTopology (id, options) {
-  return request({
-    url: `/device/topology/${id}`,
-    method: 'GET',
-    ...options
-  })
-}

+ 108 - 0
src/api/external.js

@@ -0,0 +1,108 @@
+import request from '@/utils/request'
+import {
+  add,
+  update,
+  del,
+  messageSend
+} from './base'
+
+// export function addReceivingCard (id, data, onUploadProgress) {
+//   return request({
+//     url: `/device/information/${id}`,
+//     method: 'POST',
+//     timeout: 0,
+//     data, onUploadProgress
+//   })
+// }
+
+// export function getReceivingCardTopology (id, options) {
+//   return request({
+//     url: `/device/topology/${id}`,
+//     method: 'GET',
+//     ...options
+//   })
+// }
+
+export function getSensors (options) {
+  return request({
+    url: '/device/sensorType',
+    method: 'GET',
+    ...options
+  })
+}
+
+export function getSendCardManufacturers () {
+  return request({
+    url: '/device/thirdPartySendingCard/manufacturer',
+    method: 'GET'
+  })
+}
+
+export function getSendCards (query) {
+  const { pageNum: pageIndex, pageSize, ...params } = query
+  return request({
+    url: '/device/thirdPartySendingCard/list',
+    method: 'GET',
+    params: {
+      pageIndex, pageSize,
+      ...params
+    }
+  })
+}
+
+export function addSendCard (data) {
+  return add({
+    url: '/device/thirdPartySendingCard',
+    method: 'POST',
+    data
+  })
+}
+
+export function updateSendCard (data) {
+  return update({
+    url: '/device/thirdPartySendingCard',
+    method: 'PUT',
+    data
+  })
+}
+
+export function deleteSendCard ({ id, name }) {
+  return del({
+    url: `/device/thirdPartySendingCard/${id}`,
+    method: 'DELETE'
+  }, name)
+}
+
+export function getContentProtection (deviceId) {
+  return request({
+    url: `/device/contentProtect/${deviceId}`,
+    method: 'GET'
+  })
+}
+
+const contentProtectConfig = {
+  x: 0,
+  y: 0,
+  inputCard: [
+    { cardId: '01', srcId: '00' }
+  ],
+  colors: [
+    { order: 0, r: 0, g: 0, b: 0 },
+    { order: 1, r: 0, g: 0, b: 0 },
+    { order: 2, r: 0, g: 0, b: 0 },
+    { order: 3, r: 0, g: 0, b: 0 },
+    { order: 4, r: 0, g: 0, b: 0 },
+    { order: 5, r: 0, g: 0, b: 0 }
+  ]
+}
+
+export function updateContentProtection (deviceId, protect) {
+  return messageSend({
+    url: `/device/contentProtect/${deviceId}`,
+    method: 'POST',
+    data: {
+      deviceId, protect,
+      ...contentProtectConfig
+    }
+  }, protect ? '开启' : '关闭')
+}

+ 1 - 1
src/scss/bem/_utility.scss

@@ -70,7 +70,7 @@
   text-align: center;
 }
 
-.u-flex-self {
+.u-align-self {
   &--center {
     align-self: center;
   }

+ 1 - 1
src/views/device/detail/monitor.js

@@ -1,4 +1,4 @@
-import { getSensors } from '@/api/device'
+import { getSensors } from '@/api/external'
 import {
   publish,
   subscribe,

+ 131 - 113
src/views/external/transmitter/index.vue

@@ -20,12 +20,12 @@
           </button>
         </div>
         <el-select
-          v-model="options.params.manufacturerId"
-          class="l-flex__fill c-info__value"
+          v-model="options.params.manufacturerKey"
+          class="l-flex__none c-sibling-item"
           placeholder="请选择厂家"
           :loading="manufacturers.loading"
-          @visible-change="getReceivingCardManufacturers"
-          @change="onChangeProp('manufacturerId')"
+          @visible-change="getManufacturers"
+          @change="search"
         >
           <el-option
             v-for="manufacturer in manufacturerList"
@@ -36,7 +36,7 @@
         </el-select>
       </template>
       <el-table-column
-        prop="manufacturer"
+        prop="manufacturerName"
         label="厂商"
         align="center"
         show-overflow-tooltip
@@ -48,20 +48,14 @@
         show-overflow-tooltip
       />
       <el-table-column
-        prop="model"
+        prop="type"
         label="设备型号"
         align="center"
         show-overflow-tooltip
       />
       <el-table-column
-        prop="isSync"
-        label="异步盒"
-        align="center"
-        show-overflow-tooltip
-      />
-      <el-table-column
-        prop="通信方式"
-        label="protocal"
+        prop="remark"
+        label="备注"
         align="center"
         show-overflow-tooltip
       />
@@ -86,104 +80,66 @@
         </template>
       </el-table-column>
     </c-table>
-    <el-dialog
-      title="添加发送控制设备"
-      :visible.sync="show"
-      custom-class="c-dialog"
-      :close-on-click-modal="false"
-      :before-close="close"
+    <confirm-dialog
+      ref="editDialog"
+      :title="dialogTitle"
+      @confirm="onConfirm"
     >
-      <div class="c-form">
-        <div class="c-form__section">
-          <span class="c-form__label large required">厂家:</span>
-          <el-select
-            v-model="transmitter.manufacturerId"
-            class="c-form__item"
-            placeholder="请选择厂家"
-            :loading="manufacturers.loading"
-            @visible-change="getReceivingCardManufacturers"
-          >
-            <el-option
-              v-for="manufacturer in manufacturers.list"
-              :key="manufacturer.value"
-              :label="manufacturer.label"
-              :value="manufacturer.value"
-            />
-          </el-select>
-        </div>
-        <div class="c-form__section">
-          <span class="c-form__label large required">设备名称:</span>
-          <el-input
-            v-model.trim="transmitter.name"
-            class="c-form__item"
-            maxlength="50"
-            show-word-limit
-          />
-        </div>
-        <div class="c-form__section">
-          <span class="c-form__label large required">设备型号:</span>
-          <el-input
-            v-model.trim="transmitter.model"
-            class="c-form__item"
-            maxlength="50"
-            show-word-limit
-          />
-        </div>
-        <div class="c-form__section">
-          <span class="c-form__label large required">通信类型:</span>
-          <el-select
-            v-model="transmitter.protocol"
-            class="c-form__item"
-            placeholder="请选择"
-          >
-            <el-option
-              v-for="protocol in protocols"
-              :key="protocol.value"
-              :label="protocol.label"
-              :value="protocol.value"
-            />
-          </el-select>
-        </div>
-        <div class="c-form__section">
-          <span class="c-form__label large">是否为异步盒:</span>
-          <el-switch
-            v-model="transmitter.async"
-            class="c-form__item"
-            active-color="#13ce66"
-            inactive-color="#ff4949"
+      <div class="c-grid-form u-align-self--center">
+        <span class="c-grid-form__label required">厂商:</span>
+        <el-select
+          v-model="transmitter.manufacturerKey"
+          placeholder="请选择厂家"
+          :loading="manufacturers.loading"
+          @visible-change="getManufacturers"
+        >
+          <el-option
+            v-for="manufacturer in manufacturers.list"
+            :key="manufacturer.value"
+            :label="manufacturer.label"
+            :value="manufacturer.value"
           />
-        </div>
+        </el-select>
+        <span class="c-grid-form__label required">设备名称:</span>
+        <el-input
+          v-model.trim="transmitter.name"
+          maxlength="50"
+          show-word-limit
+        />
+        <span class="c-grid-form__label required">设备型号:</span>
+        <el-input
+          v-model.trim="transmitter.type"
+          maxlength="50"
+          show-word-limit
+        />
+        <span class="c-grid-form__label">备注:</span>
+        <el-input
+          v-model="transmitter.remark"
+          type="textarea"
+          :rows="3"
+          maxlength="100"
+          show-word-limit
+        />
       </div>
-      <template #footer>
-        <button
-          class="o-button"
-          @click="save"
-        >
-          确定
-        </button>
-        <button
-          class="o-button cancel"
-          @click="close"
-        >
-          取消
-        </button>
-      </template>
-    </el-dialog>
+    </confirm-dialog>
   </wrapper>
 </template>
 
 <script>
 import {
-  getDevices,
-  getReceivingCardManufacturers
-} from '@/api/device'
+  getSendCardManufacturers,
+  getSendCards,
+  addSendCard,
+  updateSendCard,
+  deleteSendCard
+} from '@/api/external'
 import { createListOptions } from '@/utils'
 
 export default {
   name: 'Transmitter',
   data () {
     return {
-      options: createListOptions({ manufacturerId: '' }),
+      options: createListOptions({ manufacturerKey: void 0 }),
       manufacturers: {
         loading: false,
         loaded: false,
@@ -199,7 +155,17 @@ export default {
   },
   computed: {
     manufacturerList () {
-      return [{ value: '', label: '全部厂家' }]
+      return [{ value: void 0, label: '全部厂家' }].concat(this.manufacturers.list)
+    },
+    manufacturerKeys () {
+      return this.manufacturers.loaded
+        ? this.manufacturers.list
+        : this.transmitter.id
+          ? []
+          : [{ value: this.transmitter.manufacturerKey, label: this.manufacturerName }]
+    },
+    dialogTitle () {
+      return this.transmitter.id ? '添加发送控制设备' : '修改发送控制设备'
     }
   },
   created () {
@@ -217,7 +183,7 @@ export default {
       const options = this.options
       options.error = false
       options.loading = true
-      return getDevices(options).then(({ data, totalCount }) => {
+      return getSendCards(options.params).then(({ data, totalCount }) => {
         options.list = data
         options.totalCount = totalCount
       }, () => {
@@ -227,12 +193,12 @@ export default {
         options.loading = false
       })
     },
-    getReceivingCardManufacturers (visible) {
+    getManufacturers (visible) {
       if (visible && !this.manufacturers.loading && !this.manufacturers.loaded) {
         this.manufacturers.loading = true
-        getReceivingCardManufacturers().then(({ data }) => {
-          this.manufacturers.list = data.map(({ id, name }) => {
-            return { value: id, label: name }
+        getSendCardManufacturers().then(({ data }) => {
+          this.manufacturers.list = data.map(({ manufacturerKey, manufacturerName }) => {
+            return { value: manufacturerKey, label: manufacturerName }
           })
           this.manufacturers.loading = false
           this.manufacturers.loaded = true
@@ -243,19 +209,71 @@ export default {
     },
     onAdd () {
       this.transmitter = {
-        manufacturerId: '',
+        manufacturerKey: '',
         name: '',
-        model: '',
-        protocol: '',
-        async: false
+        type: '',
+        flag: 0,
+        remark: ''
       }
-      this.show = true
+      this.$refs.editDialog.show()
     },
-    close () {
-      this.show = false
+    onEdit ({ id, manufacturerKey, manufacturerName, name, type, flag, remark }) {
+      this.manufacturerName = manufacturerName
+      this.transmitter = { id, manufacturerKey, name, type, flag, remark }
+      this.$refs.editDialog.show()
     },
-    save () {
-
+    onConfirm (done) {
+      if (!this.transmitter.manufacturerKey) {
+        this.$message({
+          type: 'warning',
+          message: '请选择厂商'
+        })
+        return
+      }
+      if (!this.transmitter.name) {
+        this.$message({
+          type: 'warning',
+          message: '请填写设备名称'
+        })
+        return
+      }
+      if (!this.transmitter.type) {
+        this.$message({
+          type: 'warning',
+          message: '请填写设备型号'
+        })
+        return
+      }
+      if (this.transmitter.id) {
+        this.onConfirmEdit(done)
+      } else {
+        this.onConfirmAdd(done)
+      }
+    },
+    onConfirmAdd (done) {
+      addSendCard(this.transmitter).then(() => {
+        done()
+        const params = this.options.params
+        if (params.manufacturerKey && params.manufacturerKey !== this.transmitter.manufacturerKey) {
+          params.manufacturerKey = void 0
+        }
+        this.search()
+      })
+    },
+    onConfirmEdit (done) {
+      updateSendCard(this.transmitter).then(() => {
+        done()
+        this.getList()
+      })
+    },
+    onDel (item) {
+      deleteSendCard(item).then(() => {
+        const options = this.options
+        if (options.list.length === 1 && options.params.pageNum > 1) {
+          options.params.pageNum -= 1
+        }
+        this.getList()
+      })
     }
   }
 }

+ 1 - 1
src/views/review/index.vue

@@ -39,7 +39,7 @@
       title="驳回"
       @confirm="onConfirmReject"
     >
-      <div class="c-grid-form u-flex-self--center">
+      <div class="c-grid-form u-align-self--center">
         <span class="c-grid-form__label">审核意见:</span>
         <el-select
           v-model="review.type"