Newer
Older
smartwell_front / src / views / home / ledger / sync / index.vue
liyaguang on 27 Apr 5 KB 视频轮询逻辑修改
<!--
  Description: 台账管理-闸井/场站列表-同步日志
  Author: 李亚光
  Date: 2024-07-22
 -->
<script lang="ts" setup name="SyncRecordList">
import { ElMessage, ElMessageBox } from 'element-plus'
import { getDictByCode } from '@/api/system/dict'
import { getSyncListPage, removeSync } from '@/api/home/ledger/log'
import { shortcuts } from '@/utils/common'
import detail from './detailDialog.vue'
const $router = useRouter()
// 表格数据
const list = ref([])
const total = ref(0)
// 初始展示列
const columns = ref<any>([
  { text: '开始时间', value: 'startTime', align: 'center', isRequired: true, width: '190' },
  { text: '结束时间', value: 'endTime', align: 'center', isRequired: true, width: '190' },
  { text: '操作人', value: 'createUser', align: 'center', isRequired: true },
  { text: '同步类型', value: 'syncTypeName', align: 'center' },
  { text: '同步结果', value: 'syncResult', align: 'center' },
  { text: '更新数据', value: 'updateCount', align: 'center', isRequired: true },
  { text: '删除数据', value: 'deleteCount', align: 'center', isRequired: true },
  { text: '新增数据', value: 'addCount', align: 'center', isRequired: true },
  // { text: '位置状态', value: 'isUsedName', align: 'center', isRequired: true },
])
// 最终展示列
const columnsConfig = ref([])
// 修改列
const editColumns = (data: any) => {
  columnsConfig.value = data
}
const loadingTable = ref(true)
//  查询条件
const listQuery = ref({
  limit: 20,
  offset: 1,
  operatorName: '',
  startTime: '',
  endTime: ''
})
// 开始结束时间
const datetimerange = ref()
watch(() => datetimerange.value, (newVal) => {
  listQuery.value.startTime = ''
  listQuery.value.endTime = ''
  if (Array.isArray(newVal)) {
    if (newVal.length) {
      listQuery.value.startTime = `${newVal[0]} 00:00:00`
      listQuery.value.endTime = `${newVal[1]} 23:59:59`
    }
  }
})
// 查询数据
const fetchData = () => {
  getSyncListPage(listQuery.value).then((res) => {
    // console.log(res.data, '数据列表')
    list.value = res.data.rows.map((item: any) => ({
      ...item,
      syncTypeName: item.syncType === '1' ? '全量同步' : item.syncType === '2' ? '增量同步' : ''
    }))
    total.value = res.data.total
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 重置查询条件f
const reset = () => {
  datetimerange.value = []
  listQuery.value = {
    limit: 20,
    offset: 1,
    operatorName: '',
    startTime: '',
    endTime: ''
  }
  fetchData()
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size: number; page: number }) => {
  if (val && val.size) {
    listQuery.value.limit = val.size
  }
  if (val && val.page) {
    listQuery.value.offset = val.page
  }
  fetchData()
}
// 删除
const removeRow = (row: any) => {
  ElMessageBox.confirm(
    '确定要删除该数据吗?',
    '确认操作',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    removeSync({ ids: [row.id] }).then((response) => {
      if (response.code === 200) {
        ElMessage({
          message: '删除成功',
          type: 'success',
        })
        fetchData()
      }
    })
  })
}
const goBak = () => {
  $router.go(-1)
}
// 查看
const detailRef = ref()
const detailRow = (row: any) => {
  detailRef.value.initDialog(row)
}
onMounted(async () => {
  fetchData()
})
const { proxy } = getCurrentInstance() as any
const $route = useRoute()
</script>

<template>
  <!-- 布局 -->
  <app-container>
    <detail ref="detailRef" />
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="fetchData" @clear="reset">
      <search-item>
        <el-input v-model="listQuery.operatorName" placeholder="操作人员" clearable style="width: 162px;" />
      </search-item>
      <search-item>
        <el-date-picker v-model="datetimerange" type="datetimerange" format="YYYY-MM-DD HH:mm:ss" :shortcuts="shortcuts"
          value-format="YYYY-MM-DD HH:mm:ss" range-separator="至" start-placeholder="同步开始时间" end-placeholder="同步结束时间"
          clearable />
      </search-item>
    </search-area>
    <!-- 表头标题 -->
    <table-container :is-config="true" config-title="sync-record" :columns="columns" :config-columns="columnsConfig"
      :edit="editColumns">
      <template #btns-right>
        <!-- 操作 -->
        <div>
          <el-button v-if="$route.type" type="primary" @click="goBak">
            返回
          </el-button>
        </div>
      </template>
      <!-- 查询结果Table显示 -->
      <normal-table :data="list" :total="total" :columns="columnsConfig" :query="listQuery" :list-loading="loadingTable"
        @change="changePage">
        <template #preColumns>
          <el-table-column label="序号" width="80" align="center">
            <template #default="scope">
              {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
        <template #columns>
          <el-table-column label="操作" align="center" width="100">
            <template #default="scope">
              <el-button type="primary" link size="small"
                @click="detailRow(scope.row)">
                查看
              </el-button>
              <el-button v-if="proxy.hasPerm('/ledger/sync/delete')" type="danger" link size="small"
                @click="removeRow(scope.row)">
                删除
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>

<style lang="scss" scoped>
.circle {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  margin: 0 auto;
}

.online {
  background-color: #95f204;
}

.offline {
  background-color: #7f7f7f;
}
</style>