/**
 * 视频监控系统：vsT（videoSurveillance.vsNs）、vsCommon
 */
export default {
  methods: {
    vsT(key, values) {
      const ns = this.vsNs
      if (!ns) {
        return key
      }
      return this.$t(`videoSurveillance.${ns}.${key}`, values)
    },
    vsCommon(key) {
      return this.$t(`videoSurveillance.common.${key}`)
    },
    ownerTypeTagType(ownerType) {
      if (ownerType === 1) {
        return "success"
      }
      if (ownerType === 2) {
        return "warning"
      }
      return "info"
    },
    /** 第三方数据同步，带全局 loading */
    runSyncWithLoading(syncFn) {
      if (this.syncing) {
        return Promise.reject(new Error("syncing"))
      }
      let modalLoading = false
      this.syncing = true
      this.$modal.loading(this.vsCommon("syncLoading"))
      modalLoading = true
      return syncFn().finally(() => {
        this.syncing = false
        if (modalLoading) {
          this.$modal.closeLoading()
        }
      })
    }
  }
}
