Newer
Older
laserPTZFrontV2.0 / src / views / line / listLine.vue
wangxitong on 22 May 2023 8 KB first commit
<script lang="ts" setup name="LineList">
import type { Ref } from 'vue'
import { getCurrentInstance, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import type { LineListInfo, MonitorListInfo, SerialListInfo } from './line-interface'
import EditLine from './editLine.vue'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { HCCruiseRoute, HCPreset, getLineList, getSerialListPage } from '@/api/ptz/line'
import { getDevList } from '@/api/ptz/dev'

const editDialog = ref() // 组件

const proxy = getCurrentInstance() as any
// 默认查询条件
const defaultQuery = {
  monitorId: '',
  lineNum: '',
  offset: 1,
  limit: 20,
  sort: '',
  order: '',
}
const listQuery = reactive({ ...defaultQuery })
const lineName = ref('')
const showAdd = ref(false)
const total = ref(0)

// 表格表头
const columns: Ref<TableColumn[]> = ref([])
columns.value = [
  { text: '预置点名', value: 'serialName', align: 'center' },
  { text: '水平角', value: 'direction', align: 'center' },
  { text: '仰俯角', value: 'pitch', align: 'center' },
  { text: '巡航速度', value: 'speed', align: 'center' },
  { text: '停留时间', value: 'stopTime', align: 'center' },
  { text: '报警阈值', value: 'alarmValue', align: 'center' },
  { text: '修改时间', value: 'updateTime', align: 'center' },
  { text: '创建时间', value: 'createTime', align: 'center' },
]
// 数据列表
const list: Ref<SerialListInfo[]> = ref([])
const loading = ref(false)

const monitorList: Ref<MonitorListInfo[]> = ref([])
const lineList: Ref<LineListInfo[]> = ref([])

function fetchDev() {
  getDevList('').then((res) => {
    monitorList.value = res.data
  })
  // getLineList('', '').then((res) => {
  //   lineList.value = res.data
  // })
}

function changeMonitor() {
  listQuery.lineNum = ''
  getLineList('', listQuery.monitorId).then((res) => {
    lineList.value = res.data
  })
}

// 搜索按钮
function search() {
  fetchData()
}

// 搜索重置
function clear() {
  Object.assign(listQuery, defaultQuery)
  showAdd.value = false
  lineName.value = ''
  fetchData()
}

// 查询数据
function fetchData() {
  loading.value = true
  getSerialListPage(listQuery).then((res: { data: { rows: []; total: number } }) => {
    list.value = res.data.rows
    total.value = res.data.total
    loading.value = false
  })
  // list.value =
  //   [{
  //     id: '111',
  //     lineNum: '111',
  //     serialName: '111',
  //     lineName: '111',
  //     direction: '111',
  //     pitch: '111',
  //     speed: '111',
  //     stopTime: '111',
  //     alarmValue: '111',
  //     createTime: '111',
  //     updateTime: '111',
  //     ip: '111',
  // }]
  // total.value = 1
}

// 添加
function add() {
  if (listQuery.monitorId === '') {
    ElMessage.warning('请选择设备')
    return
  }
  editDialog.value.initDialog('create', monitorList.value.filter(item => item.id === listQuery.monitorId)[0])
}
// 编辑
function edit(row: SerialListInfo) {
  editDialog.value.initDialog('update', row)
}

// 插入
function insert(row: SerialListInfo) {
  editDialog.value.initDialog('insert', row)
}

// 详情
function detail(row: SerialListInfo) {
  editDialog.value.initDialog('detail', row)
}

// 删除
function del(row: SerialListInfo) {
  ElMessageBox.confirm(
    `确定要删除${row.monitorName}吗?`,
    '确认删除',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    const param = {
      deviceIp: row.ip,
      command: 'presetDel',
      presetIndex: row.id,
      cruiseRoute: row.lineNum,
      presetName: row.serialName,
      cruiseName: row.lineName,
    }
    HCPreset(row.id).then(() => {
      ElMessage.success('删除成功')
      fetchData()
    })
  })
}

// 删除巡航线
function delLine() {
  if (listQuery.monitorId === '' || listQuery.lineNum === '') {
    ElMessage.warning('请选择巡航路径进行删除')
  }
  else {
    ElMessageBox.confirm(
      '确定要删除所选巡航路径吗?',
      '确认删除',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      },
    ).then(() => {
      const param = {
        deviceIp: monitorList.value.filter(item => item.id === listQuery.monitorId)[0].ip,
        command: 'cruiseDelete',
        cruiseValue: listQuery.lineNum,
        cruiseName: monitorList.value.filter(item => item.id === listQuery.monitorId)[0].lineName,
      }
      HCCruiseRoute(param).then(() => {
        ElMessage.success('删除成功')
        changeMonitor() // 刷新巡航线列表
      })
    })
  }
}

// 添加巡航线(展示)
function addShow() {
  lineName.value = ''
  showAdd.value = true
  const addLineBtn = document.getElementById('addLineBtn')
  const addLineDiv = document.getElementById('addLineDiv')
  const width = Number(getComputedStyle(document.documentElement).getPropertyValue('--g-sub-sidebar-width').replace('px', ''))
  addLineDiv.style.left = `${addLineBtn.getBoundingClientRect().left - width + 40}px`
}

// 添加巡航线(提交)
function addLine() {
  if (listQuery.monitorId === '') {
    ElMessage.warning('请选择设备')
  }
  else if (lineName.value === '') {
    ElMessage.warning('请填写巡航路径名称')
  }
  else {
    const param = {
      deviceIp: monitorList.value.filter(item => item.id === listQuery.monitorId)[0].ip,
      command: 'cruiseAdd',
      cruiseName: lineName.value,
      cruiseValue: '',
    }
    HCCruiseRoute(param).then(() => {
      ElMessage.success('巡航路径添加成功')
      showAdd.value = false
      lineName.value = ''
      changeMonitor() // 刷新巡航线列表
    })
  }
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
function changePage(val: { size: number; page: number }) {
  if (val && val.size) {
    listQuery.limit = val.size
  }
  if (val && val.page) {
    listQuery.offset = val.page
  }
  fetchData()
}

onMounted(() => {
  fetchDev()
  fetchData()
})
</script>

<template>
  <app-container>
    <search-area :need-clear="true" @search="search" @clear="clear">
      <search-item>
        <el-select v-model="listQuery.monitorId" placeholder="选择设备" @change="changeMonitor">
          <el-option
            v-for="item in monitorList"
            :key="item.id"
            :label="item.monitorName"
            :value="item.id"
          />
        </el-select>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.lineNum" :disabled="listQuery.monitorId === ''" :placeholder="listQuery.monitorId === '' ? '请先选择设备' : '选择巡航路径'" clearable>
          <el-option
            v-for="item in lineList"
            :key="item.id"
            :label="item.lineName"
            :value="item.id"
          />
        </el-select>
      </search-item>
      <icon-button icon="icon-delete" title="删除" style="margin-left: 5px;" @click="delLine" />
      <icon-button id="addLineBtn" icon="icon-add" title="新增" @click="addShow" @mouseover="addShow" />
    </search-area>
    <div v-show="showAdd" id="addLineDiv" class="add-line">
      <el-input v-model="lineName" placeholder="巡航路径名称" />
      <icon-button icon="search-up" title="提交" style="margin-left: 5px;" @click="addLine" />
      <div style="margin-left: 5px;color: #4788fe;cursor: pointer;margin-top: -10px;font-weight: 800;" @click="showAdd = false">
        ×
      </div>
    </div>
    <table-container>
      <template #btns-right>
        <icon-button icon="icon-add" title="新增" @click="add" />
      </template>
      <normal-table :query="listQuery" :list-loading="loading" :columns="columns" :data="list" :total="total" :border="false" @change="changePage">
        <template #preColumns>
          <el-table-column label="序号" width="55" align="center">
            <template #default="scope">
              {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
        <template #columns>
          <el-table-column label="操作" width="200" align="center">
            <template #default="scope">
              <icon-button icon="icon-file" title="详情" @click="detail(scope.row)" />
              <icon-button icon="icon-edit" title="编辑" @click="edit(scope.row)" />
              <icon-button icon="icon-add" title="插入" @click="insert(scope.row)" />
              <icon-button icon="icon-delete" title="删除" @click="del(scope.row)" />
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
    <edit-line ref="editDialog" @close-refresh="search" />
  </app-container>
</template>

<style lang="scss" scoped>
.add-line {
  position: absolute;
  width: 250px;
  display: flex;
  top: 12px;
  background: #f2f6ff;
  padding: 10px;
  border-radius: 10px;
}
</style>