Selaa lähdekoodia

refactor(device): migrate openTime and closeTime to device table

Casper Dai 3 vuotta sitten
vanhempi
sitoutus
a5bab54735

+ 3 - 3
src/components/service/EventPicker/index.vue

@@ -293,13 +293,13 @@ export default {
       const { start, until } = this.eventOptions
       if (this.isOnce) {
         if (!start) {
-          return this.onError('请选择生效时间')
+          return this.onError('请选择开始时间')
         }
         if (!until) {
-          return this.onError('请选择失效时间')
+          return this.onError('请选择结束时间')
         }
         if (start === until) {
-          return this.onError('生效时间与失效时间不能一样')
+          return this.onError('开始时间与结束时间不能一样')
         }
       }
       if (this.isWeekly) {

+ 1 - 1
src/global-api.js

@@ -7,7 +7,7 @@ export function injectGlobalApi (Vue) {
   Vue.config.productionTip = false
   Vue.config.errorHandler = err => {
     closeLoading()
-    throw err
+    throw (err || 'custom reject')
   }
 
   Vue.prototype.__PLACEHOLDER__ = __PLACEHOLDER__

+ 2 - 7
src/utils/index.js

@@ -145,13 +145,8 @@ export function getAssetThumb (asset) {
   return null
 }
 
-export function getAssetDiff ({ type, keyName, duration }) {
-  switch (type) {
-    case AssetType.STREAMING_MEDIA:
-      return keyName
-    default:
-      return parseDuration(duration)
-  }
+export function getAssetDiff ({ duration }) {
+  return parseDuration(duration)
 }
 
 export function getAssetDuration ({ type, duration }) {

+ 34 - 67
src/views/dashboard/components/Device.vue

@@ -3,7 +3,7 @@
     class="o-device u-pointer"
     @click="onClick"
   >
-    <div class="l-flex__none l-flex--row o-device__header">
+    <div class="l-flex__none l-flex--row c-sibling-item--v o-device__header u-font-size u-bold">
       <auto-text
         class="l-flex__fill"
         :text="name"
@@ -21,18 +21,18 @@
         />
       </template>
       <div
-        class="l-flex__none o-device__tip"
+        class="l-flex__none o-device__tip u-font-size--xs"
         :class="statusClass"
       >
         <span class="u-color--white">{{ statusTip }}</span>
       </div>
     </div>
     <div
-      class="l-flex__fill o-device__preview u-size--contain"
+      class="l-flex__none c-sibling-item--v o-device__preview u-size--contain"
       :class="{ offline: !isOnline, empty: !shot }"
       :style="styles"
     />
-    <div class="l-flex__auto l-flex--col center o-device__info">
+    <div class="l-flex__none l-flex--col center c-sibling-item--v o-device__info">
       <template v-if="isOnline">
         <i
           v-if="loadingTimeline"
@@ -40,42 +40,46 @@
         />
         <template v-else-if="current">
           <auto-text
-            class="l-flex__none o-device__current"
+            class="l-flex__none u-align-self--stretch c-sibling-item--v u-font-size--md u-bold u-text-center"
             :text="current.name"
           />
-          <div class="l-flex__none l-flex--row has-top-padding">
-            <span class="o-device__hms">
-              {{ current.startTime }}
-              <span class="o-device__ymd">{{ current.startDate }}</span>
-            </span>
+          <div class="l-flex__none l-flex--row c-sibling-item--v">
+            <div class="u-relative">
+              <span class="u-font-size--md u-bold">{{ current.startTime }}</span>
+              <span class="o-device__ymd u-color--info light u-font-size--xs">{{ current.startDate }}</span>
+            </div>
             <template v-if="current.endDate">
               <span class="o-device__line" />
-              <span class="o-device__hms">
-                {{ current.endTime }}
-                <span class="o-device__ymd">{{ current.endDate }}</span>
-              </span>
+              <div class="u-relative">
+                <span class="u-font-size--md u-bold">{{ current.endTime }}</span>
+                <span class="o-device__ymd u-color--info light u-font-size--xs">{{ current.endDate }}</span>
+              </div>
             </template>
           </div>
         </template>
         <span
           v-else
-          class="l-flex__auto l-flex--row u-bold"
+          class="l-flex__auto l-flex--row u-font-size u-bold"
         >
           当前暂无节目
         </span>
       </template>
-      <template v-else>
-        <span class="l-flex__auto l-flex--row u-bold">{{ lastOnline }}</span>
-      </template>
+      <span
+        v-else
+        class="l-flex__auto l-flex--row u-font-size u-bold"
+      >
+        {{ lastOnline }}
+      </span>
     </div>
-    <div class="l-flex__none o-device__next">
+    <div class="l-flex__none l-flex--row c-sibling-item--v o-device__next u-color--info light u-font-size--xs u-text-center">
       <auto-text
         v-if="next"
+        class="l-flex__fill"
         :text="nextInfo"
       />
     </div>
-    <div class="l-flex__none l-flex--row o-device__footer">
-      <i class="l-flex__none o-device__icon el-icon-location-outline" />
+    <div class="l-flex__none l-flex--row c-sibling-item--v near u-color--blue u-font-size--xs u-bold">
+      <i class="l-flex__none c-sibling-item nearer el-icon-location-outline u-font-size" />
       <auto-text
         class="l-flex__auto"
         :text="address"
@@ -306,7 +310,7 @@ export default {
 .o-device {
   display: inline-flex;
   flex-direction: column;
-  padding: 12px $spacing;
+  padding: $padding--md $padding--lg;
   color: $black;
   line-height: 1;
   border-radius: $radius;
@@ -315,8 +319,6 @@ export default {
   &__header {
     justify-self: flex-start;
     height: 24px;
-    font-size: 16px;
-    font-weight: bold;
   }
 
   &__shot {
@@ -329,17 +331,14 @@ export default {
   &__tip {
     display: inline-block;
     position: relative;
-    left: 16px;
-    padding: 4px 8px 4px 10px;
-    margin-left: -4px;
-    font-size: 12px;
-    line-height: 1;
+    left: $padding--lg;
+    padding: $padding--2xs $padding--sm $padding--2xs $padding;
+    margin-left: -$spacing--3xs;
     border-radius: $radius--sm 0 0 $radius--sm;
     background-color: currentColor;
   }
 
   &__preview {
-    margin-top: 12px;
     padding-top: $padding--16_9;
     border-radius: $radius--sm;
 
@@ -354,57 +353,25 @@ export default {
   }
 
   &__info {
-    margin-top: 12px;
-    height: 88px;
-    font-size: 20px;
-  }
-
-  &__current {
-    align-self: stretch;
-    font-weight: bold;
-    text-align: center;
+    height: 64px;
   }
 
   &__line {
     display: inline-block;
-    width: 20px;
-    margin: 0 10px;
+    width: $spacing--xs;
+    margin: 0 $spacing--xs;
     border-bottom: 1px solid currentColor;
   }
 
-  &__hms {
-    position: relative;
-    font-weight: bold;
-  }
-
   &__ymd {
     position: absolute;
     top: 100%;
     left: 50%;
-    color: $info;
-    font-size: 12px;
-    font-weight: normal;
-    transform: translate(-50%, 4px);
+    transform: translate(-50%, $spacing--3xs);
   }
 
   &__next {
-    height: 16px;
-    color: $info;
-    font-size: 12px;
-    line-height: 16px;
-    text-align: center;
-  }
-
-  &__footer {
-    margin-top: 10px;
-    color: $blue;
-    font-size: 12px;
-    font-weight: bold;
-
-    .o-device__icon {
-      margin-right: 6px;
-      font-size: 16px;
-    }
+    height: 12px;
   }
 }
 </style>

+ 8 - 8
src/views/device/detail/components/DeviceInfo.vue

@@ -6,22 +6,22 @@
     <div class="l-flex--row has-bottom-padding u-bold">设备信息</div>
     <div class="l-flex--row c-info__block">
       <div class="l-flex--row l-flex__fill c-info__item">
-        <div class="l-flex__none c-info__title">名称</div>
-        <div class="l-flex__fill c-info__value">{{ device.name }}</div>
+        <div class="l-flex__none c-info__title">序列号</div>
+        <div class="l-flex__fill c-info__value">{{ device.serialNumber }}</div>
       </div>
       <div class="l-flex--row l-flex__fill c-info__item">
-        <div class="l-flex__none c-info__title">配置</div>
-        <div class="l-flex__fill c-info__value">{{ device.productName }}</div>
+        <div class="l-flex__none c-info__title">MAC</div>
+        <div class="l-flex__fill c-info__value">{{ device.mac }}</div>
       </div>
     </div>
     <div class="l-flex--row c-info__block">
       <div class="l-flex--row l-flex__fill c-info__item">
-        <div class="l-flex__none c-info__title">序列号</div>
-        <div class="l-flex__fill c-info__value">{{ device.serialNumber }}</div>
+        <div class="l-flex__none c-info__title">配置</div>
+        <div class="l-flex__fill c-info__value">{{ device.productName }}</div>
       </div>
       <div class="l-flex--row l-flex__fill c-info__item">
-        <div class="l-flex__none c-info__title">MAC</div>
-        <div class="l-flex__fill c-info__value">{{ device.mac }}</div>
+        <div class="l-flex__none c-info__title">运行时间</div>
+        <div class="l-flex__fill c-info__value">{{ device.openTime }} - {{ device.closeTime }}</div>
       </div>
     </div>
     <div class="l-flex--row c-info__block">

+ 40 - 9
src/views/platform/tenant/device/components/Device.vue

@@ -36,18 +36,27 @@
         <span class="c-grid-form__label u-required">MAC</span>
         <el-input
           v-model.trim="currObj.mac"
+          class="u-width--sm"
           placeholder="ff:ff:ff:ff:ff:ff"
           maxlength="17"
           clearable
         />
+        <div class="c-grid-form__label u-required">开关机时间</div>
+        <el-time-picker
+          v-model="currObj.range"
+          class="u-width u-pointer"
+          is-range
+          format="HH:mm"
+          value-format="HH:mm"
+          :clearable="false"
+        />
         <span class="c-grid-form__label u-required">地址</span>
         <el-input
           v-model.trim="currObj.address"
           type="textarea"
           placeholder="最多100个字符"
           maxlength="100"
-          :rows="4"
-          resize="none"
+          :rows="2"
           show-word-limit
         />
         <span class="c-grid-form__label">坐标</span>
@@ -56,18 +65,16 @@
             <span class="c-sibling-item c-grid-form__label">经度</span>
             <el-input
               v-model.trim="currObj.longitude"
-              class="l-flex__fill c-sibling-item"
+              class="c-sibling-item u-width--xs"
               placeholder="-180 ~ +180"
               maxlength="13"
-              clearable
             />
             <span class="c-sibling-item far c-grid-form__label">纬度</span>
             <el-input
               v-model.trim="currObj.latitude"
-              class="l-flex__fill c-sibling-item"
+              class="c-sibling-item far u-width--xs"
               placeholder="-90 ~ +90"
               maxlength="12"
-              clearable
             />
           </div>
           <a
@@ -222,22 +229,32 @@ export default {
         productId: this.$master?.productId,
         serialNumber: '',
         mac: '',
+        range: ['07:00', '22:00'],
+        address: '',
         longitude: '',
         latitude: '',
-        address: '',
         tenant: this.tenant
       }
       this.$refs.editDialog.show()
     },
     onSave (done) {
       if (this.check(this.currObj)) {
+        const { range, ...data } = this.currObj
         if (this.isSub) {
-          addSubDevice(this.$master, this.currObj).then(() => {
+          addSubDevice(this.$master, {
+            openTime: range[0],
+            closeTime: range[1],
+            ...data
+          }).then(() => {
             done()
             this.reloadSubDevices(this.$master)
           })
         } else {
-          addDevice(this.currObj).then(() => {
+          addDevice({
+            openTime: range[0],
+            closeTime: range[1],
+            ...data
+          }).then(() => {
             done()
             this.$refs.table.resetCondition({ name: this.currObj.name, productId: this.currObj.productId })
           })
@@ -281,6 +298,20 @@ export default {
         return false
       }
       item.mac = item.mac.toLowerCase()
+      if (!item.range || !item.range[0] || !item.range[1]) {
+        this.$message({
+          type: 'warning',
+          message: '请选择开关机时间'
+        })
+        return false
+      }
+      if (item.range[0] >= item.range[1]) {
+        this.$message({
+          type: 'warning',
+          message: '开机时间必须小于关机时间'
+        })
+        return false
+      }
       if (!item.address) {
         this.$message({
           type: 'warning',

+ 0 - 38
src/views/platform/tenant/device/settings/components/AdConfigDialog.vue

@@ -13,20 +13,6 @@
           inactive-color="#ff4949"
         />
       </div>
-      <span class="c-grid-form__label u-required">开机时间</span>
-      <el-time-picker
-        v-model="attributes.openTime"
-        value-format="HH:mm"
-        format="HH:mm"
-        :clearable="false"
-      />
-      <span class="c-grid-form__label u-required">关机时间</span>
-      <el-time-picker
-        v-model="attributes.closeTime"
-        value-format="HH:mm"
-        format="HH:mm"
-        :clearable="false"
-      />
       <span class="c-grid-form__label">单次时长(s)</span>
       <el-input-number
         v-model="attributes.minDuration"
@@ -88,8 +74,6 @@ export default {
         this.isAdd = !data
         this.attributes = {
           enable: false,
-          openTime: '07:00', // 开机时间
-          closeTime: '22:00', // 关机时间
           minDuration: 5, // 最小投放广告时长(单位秒)
           minCount: 10, // 最小投放次数
           price: 1000, // 单位分
@@ -102,28 +86,6 @@ export default {
       })
     },
     onSave (done) {
-      const { openTime, closeTime } = this.attributes
-      if (!openTime) {
-        this.$message({
-          type: 'warning',
-          message: '请选择开机时间'
-        })
-        return
-      }
-      if (!closeTime) {
-        this.$message({
-          type: 'warning',
-          message: '请选择关机时间'
-        })
-        return
-      }
-      if (openTime >= closeTime) {
-        this.$message({
-          type: 'warning',
-          message: '开机时间必须小于关机时间'
-        })
-        return
-      }
       updateAdAttributes(this.$deviceId, this.attributes).then(done)
     }
   }

+ 40 - 16
src/views/realm/device/index.vue

@@ -24,6 +24,15 @@
           maxlength="30"
           clearable
         />
+        <div class="c-grid-form__label u-required">开关机时间</div>
+        <el-time-picker
+          v-model="info.range"
+          class="u-width u-pointer"
+          is-range
+          format="HH:mm"
+          value-format="HH:mm"
+          :clearable="false"
+        />
         <span class="c-grid-form__label u-required">地址</span>
         <el-input
           v-model.trim="info.address"
@@ -34,28 +43,27 @@
           resize="none"
           show-word-limit
         />
-        <span class="c-grid-form__label">经度</span>
-        <div class="l-flex--row c-grid-form__option">
+        <span class="c-grid-form__label">坐标</span>
+        <div class="c-grid-form__option">
           <div class="l-flex--row c-sibling-item--v">
+            <span class="c-sibling-item c-grid-form__label">经度</span>
             <el-input
               v-model.trim="info.longitude"
-              class="l-flex__fill c-sibling-item"
+              class="c-sibling-item u-width--xs"
               placeholder="-180 ~ +180"
               maxlength="13"
-              clearable
             />
             <span class="c-sibling-item far c-grid-form__label">纬度</span>
             <el-input
               v-model.trim="info.latitude"
-              class="l-flex__fill c-sibling-item far"
+              class="c-sibling-item far u-width--xs"
               placeholder="-90 ~ +90"
               maxlength="12"
-              clearable
             />
           </div>
           <a
             class="c-sibling-item--v nearer o-link"
-            href="https://lbs.qq.com/getPoint/"
+            href="http://api.map.baidu.com/lbsapi/getpoint/index.html"
             target="_blank"
           />
         </div>
@@ -209,47 +217,63 @@ export default {
       })
     },
     onEditDevice (device) {
-      const { id, name, longitude, latitude, address } = device
+      const { id, name, openTime, closeTime, address, longitude, latitude } = device
       this.$device = device
-      this.info = { id, name, longitude, latitude, address }
+      this.info = { id, name, range: [openTime ?? '07:00', closeTime ?? '22:00'], address, longitude, latitude }
       this.$refs.editDialog.show()
     },
     onSave (done) {
-      if (!this.info.name) {
+      const { id, name, range, longitude, address, latitude } = this.info
+      if (!name) {
         this.$message({
           type: 'warning',
           message: '名称不能为空'
         })
         return
       }
-      if (!this.info.address) {
+      if (!range || !range[0] || !range[1]) {
+        this.$message({
+          type: 'warning',
+          message: '请选择开关机时间'
+        })
+        return
+      }
+      if (range[0] >= range[1]) {
+        this.$message({
+          type: 'warning',
+          message: '开机时间必须小于关机时间'
+        })
+        return
+      }
+      if (!address) {
         this.$message({
           type: 'warning',
           message: '地址不能为空'
         })
         return
       }
-      if (this.info.longitude && !validLongitude(this.info.longitude)) {
+      if (longitude && !validLongitude(longitude)) {
         this.$message({
           type: 'warning',
           message: '经度格式错误,-180 ~ +180'
         })
         return
       }
-      if (this.info.latitude && !validLatitude(this.info.latitude)) {
+      if (latitude && !validLatitude(latitude)) {
         this.$message({
           type: 'warning',
           message: '纬度格式错误,-90 ~ +90'
         })
         return
       }
-      if (Object.keys(this.info).every(key => this.info[key] === this.$device[key])) {
+      const info = { id, name, openTime: range[0], closeTime: range[1], address, longitude, latitude }
+      if (Object.keys(info).every(key => info[key] === this.$device[key])) {
         done()
         return
       }
-      updateDevice(this.info).then(() => {
+      updateDevice(info).then(() => {
         done()
-        Object.assign(this.$device, this.info)
+        Object.assign(this.$device, info)
       })
     },
     onSettingDevice ({ id }) {

+ 1 - 1
src/views/screen/deploy/ratio/index.vue

@@ -104,7 +104,7 @@ export default {
           detail: event
         })
       }
-      return Promise.reject()
+      return Promise.reject('invalid event')
     },
     publish () {
       return this.getPublishTarget().then(