| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- <template>
- <wrapper
- fill
- margin
- padding
- background
- >
- <div class="l-flex--row">
- <button
- class="o-button c-sibling-item"
- @click="onTransferSchedule"
- >
- 迁移设备排期
- </button>
- <button
- class="o-button c-sibling-item"
- @click="onTransferHistory"
- >
- 迁移发布历史
- </button>
- </div>
- <el-dialog
- title="迁移设备排期"
- :visible.sync="scheduleTransfering"
- custom-class="c-dialog"
- >
- <c-table
- v-if="scheduleTransfering"
- :options="deviceOptions"
- @pagination="getDevices"
- >
- <template #header>
- <button
- v-if="deviceOptions.totalCount"
- class="o-button c-sibling-item"
- @click="transferPageDevices"
- >
- 迁移当前页
- </button>
- <button
- v-if="deviceOptions.totalCount > deviceOptions.params.pageSize"
- class="o-button c-sibling-item"
- @click="transferAllDevices"
- >
- 迁移所有
- </button>
- </template>
- <el-table-column
- prop="id"
- label="ID"
- align="center"
- />
- <el-table-column
- prop="name"
- label="设备名称"
- align="center"
- />
- <el-table-column
- label="操作"
- align="center"
- >
- <template v-slot="scope">
- <div
- class="c-table__btn u-pointer"
- @click="transformOneDevice(scope.row)"
- >
- 迁移至事件模式
- </div>
- <div
- class="c-table__btn u-pointer"
- @click="clearDevice(scope.row)"
- >
- 清除
- </div>
- </template>
- </el-table-column>
- </c-table>
- </el-dialog>
- <el-dialog
- title="迁移发布历史"
- :visible.sync="historyTransfering"
- custom-class="c-dialog"
- >
- <c-table
- v-if="historyTransfering"
- :options="historyOptions"
- @pagination="getHistoriesByOptions"
- >
- <template #header>
- <button
- v-if="historyOptions.totalCount"
- class="o-button c-sibling-item"
- @click="transferPageHistories"
- >
- 迁移当前页
- </button>
- <button
- v-if="historyOptions.totalCount > historyOptions.params.pageSize"
- class="o-button c-sibling-item"
- @click="transferAllHistories"
- >
- 迁移所有
- </button>
- </template>
- <el-table-column
- prop="id"
- label="ID"
- align="center"
- />
- <el-table-column
- prop="programCalendarName"
- label="名称"
- align="center"
- />
- <el-table-column
- prop="createTime"
- label="审核时间"
- align="center"
- />
- <el-table-column
- label="操作"
- align="center"
- >
- <template v-slot="scope">
- <div
- class="c-table__btn u-pointer"
- @click="transferOneHistory(scope.row)"
- >
- 迁移
- </div>
- </template>
- </el-table-column>
- </c-table>
- </el-dialog>
- </wrapper>
- </template>
- <script>
- import { getDevices } from '@/api/device'
- import request from '@/utils/request'
- import { toEvent } from '@/utils/event'
- import { createListOptions } from '@/utils'
- import {
- State,
- PublishType
- } from '@/constant'
- export default {
- name: 'Transfer',
- data () {
- return {
- scheduleTransfering: false,
- deviceOptions: null,
- historyTransfering: false,
- historyOptions: null
- }
- },
- methods: {
- onTransferSchedule () {
- this.deviceOptions = createListOptions()
- this.getDevices()
- this.scheduleTransfering = true
- },
- getDevices () {
- const options = this.deviceOptions
- options.error = false
- options.loading = true
- getDevices(options.params).then(
- ({ data, totalCount }) => {
- options.list = data.map(({ id, name }) => {
- return { id, name }
- })
- options.totalCount = totalCount
- },
- () => {
- options.error = true
- options.list = []
- }
- ).finally(() => {
- options.loading = false
- })
- },
- setDeviceCalendar (id, events) {
- return request({
- url: `/content/deviceCalender/${id}`,
- method: 'POST',
- data: events,
- custom: true
- })
- },
- clearDevice (device) {
- const loading = this.$showLoading()
- this.setDeviceCalendar(device.id, []).then(
- () => {
- this.$message({
- type: 'success',
- message: '数据已清除'
- })
- },
- () => {
- this.$message({
- type: 'warning',
- message: '数据清除失败'
- })
- }
- ).finally(() => {
- this.$closeLoading(loading)
- })
- },
- async transferDevice ({ id }) {
- const { data } = await request({
- url: `/content/deviceCalender/${id}`,
- method: 'GET',
- custom: true
- })
- const schedules = JSON.parse(data.eventDetail) || []
- if (schedules.length && !schedules[0].freq) {
- const events = []
- for (let i = 0; i < schedules.length; i++) {
- const event = toEvent(schedules[i])
- await event.invoke()
- events.push(event)
- }
- await this.setDeviceCalendar(id, events)
- return true
- }
- return false
- },
- async transferDevices (devices) {
- const length = devices.length
- for (let i = 0; i < length; i++) {
- const device = devices[i]
- try {
- await this.transferDevice(device)
- } catch (e) {
- console.warn(e)
- this.$message({
- type: 'warning',
- message: `${device.name}迁移失败`
- })
- return
- }
- }
- this.$message({
- type: 'success',
- message: '数据迁移成功'
- })
- },
- async transformOneDevice (device) {
- const loading = this.$showLoading()
- try {
- const has = await this.transferDevice(device)
- if (has) {
- this.$message({
- type: 'success',
- message: '数据迁移成功'
- })
- } else {
- this.$message({
- type: 'warning',
- message: '数据不需迁移或已迁移'
- })
- }
- } catch (e) {
- console.warn(e)
- this.$message({
- type: 'warning',
- message: '数据迁移失败'
- })
- }
- this.$closeLoading(loading)
- },
- async transferPageDevices () {
- const loading = this.$showLoading()
- await this.transferDevices(this.deviceOptions.list)
- this.$closeLoading(loading)
- },
- async transferAllDevices () {
- if (this.deviceOptions.totalCount <= this.deviceOptions.params.pageSize) {
- this.transferPageDevices()
- } else {
- const loading = this.$showLoading()
- try {
- const { data } = await getDevices({
- pageNum: 1,
- pageSize: this.deviceOptions.totalCount
- })
- await this.transferDevices(data)
- } catch (e) {
- console.warn(e)
- this.$message({
- type: 'warning',
- message: '获取迁移数据失败'
- })
- }
- this.$closeLoading(loading)
- }
- },
- onTransferHistory () {
- this.historyOptions = createListOptions()
- this.getHistoriesByOptions()
- this.historyTransfering = true
- },
- getHistories ({ pageNum: pageIndex, pageSize }) {
- return request({
- url: '/orchestration/calendarRelease/page',
- method: 'GET',
- params: {
- pageIndex,
- pageSize,
- status: State.RESOLVED
- }
- })
- },
- getHistoriesByOptions () {
- const options = this.historyOptions
- options.error = false
- options.loading = true
- this.getHistories(options.params).then(
- ({ data, totalCount }) => {
- options.list = data
- options.totalCount = totalCount
- },
- () => {
- options.error = true
- options.list = []
- }
- ).finally(() => {
- options.loading = false
- })
- },
- transferHistory ({ id, programCalendarId }) {
- return request({
- url: `/orchestration/calendarRelease/${id}/save`,
- method: 'POST',
- data: {
- type: PublishType.CALENDAR,
- detail: programCalendarId
- },
- custom: true
- })
- },
- async transferHistories (histories) {
- const length = histories.length
- for (let i = 0; i < length; i++) {
- const history = histories[i]
- try {
- await this.transferHistory(history)
- } catch (e) {
- console.warn(e)
- this.$message({
- type: 'warning',
- message: `${history.programCalendarName}迁移失败`
- })
- return
- }
- }
- this.$message({
- type: 'success',
- message: '数据迁移成功'
- })
- const options = this.historyOptions
- if (options.params.pageNum > 1 && options.list.length <= length) {
- if (options.params.pageSize >= length) {
- options.params.pageNum -= 1
- } else {
- options.params.pageNum = 1
- }
- }
- this.getHistoriesByOptions()
- },
- async transferOneHistory (history) {
- const loading = this.$showLoading()
- await this.transferHistories([history])
- this.$closeLoading(loading)
- },
- async transferPageHistories () {
- const loading = this.$showLoading()
- await this.transferHistories(this.historyOptions.list)
- this.$closeLoading(loading)
- },
- async transferAllHistories () {
- if (this.historyOptions.totalCount <= this.historyOptions.params.pageSize) {
- this.transferPageHistories()
- } else {
- const loading = this.$showLoading()
- try {
- const { data } = await this.getHistories({
- pageNum: 1,
- pageSize: this.historyOptions.totalCount
- })
- await this.transferHistories(data)
- } catch (e) {
- console.warn(e)
- this.$message({
- type: 'warning',
- message: '获取迁移数据失败'
- })
- }
- this.$closeLoading(loading)
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- </style>
|