index.vue
4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<script lang="ts" setup>
import { Description, useDescription } from '/@/components/Description';
import { descSchema } from './config';
import type { PropType } from 'vue';
import { unref } from 'vue';
import edgeDevicePng from '/@/assets/images/edgeDevice.png';
import { Image, Popconfirm } from 'ant-design-vue';
import { EdgeDeviceItemType } from '/@/api/edgeManage/model/edgeInstance';
import { getDeviceToken } from '/@/api/device/deviceManager';
import { useClipboard } from '@vueuse/core';
import { useMessage } from '/@/hooks/web/useMessage';
import ManageDeviceTokenModal from '/@/views/device/list/cpns/modal/ManageDeviceTokenModal.vue';
import { useModal } from '/@/components/Modal';
import { edgeDeviceDeleteDistribution } from '/@/api/edgeManage/edgeInstance';
import { useGo } from '/@/hooks/web/usePage';
import { useI18n } from '/@/hooks/web/useI18n';
const emits = defineEmits(['success']);
const props = defineProps({
recordData: {
type: Object as PropType<EdgeDeviceItemType>,
default: () => {},
},
edgeId: {
type: String,
default: '',
},
});
const CS = {
'word-break': 'break-all',
overflow: 'hidden',
display: '-webkit-box',
'-webkit-line-clamp': 2,
'-webkit-box-orient': 'vertical',
};
const [register] = useDescription({
layout: 'vertical',
schema: descSchema(),
column: 5,
});
const { t } = useI18n();
const { createMessage } = useMessage();
const go = useGo();
const { copied, copy } = useClipboard({ legacy: true });
const handleEventIsCopyDeviceToken = async () => {
if (!props?.recordData?.id?.id) return;
const token = await getDeviceToken(props?.recordData?.id?.id);
if (token.credentialsType === 'ACCESS_TOKEN') {
await copy(token.credentialsId);
} else {
await copy(token.credentialsValue);
}
if (unref(copied)) {
createMessage.success(t('common.copyOk'));
}
};
const [registerModal, { openModal }] = useModal();
const handleEventIsManageDeviceToken = async () => {
if (!props?.recordData?.id?.id) return;
const token = await getDeviceToken(props?.recordData?.id?.id);
openModal(true, token);
};
const handleEventIsCancelDistribution = async () => {
await edgeDeviceDeleteDistribution(props.edgeId, props.recordData.id?.id);
createMessage.success(t('edge.instance.message.cancelAssignSuccess'));
emits('success');
goBack();
};
function goBack() {
go('/edge/edge_detail/' + props.edgeId);
}
</script>
<template>
<a-row :gutter="{ xs: 8, sm: 16, md: 24, lg: 32 }">
<a-col class="gutter-row" :span="3">
<div class="!flex flex-col justify-between items-center">
<div><Image :src="recordData?.deviceInfo?.avatar || edgeDevicePng" :width="180" /></div>
<div class="!flex flex-col mt-3">
<span style="color: #1d2129" class="font-bold">{{
recordData?.alias ? recordData?.alias : recordData?.name
}}</span>
<span style="color: #3d3d3d">
{{ t('edge.instance.text.edgeDeviceDetail') }}
</span>
</div>
</div>
</a-col>
<a-col class="gutter-row" :span="21">
<div class="!flex flex-col justify-between">
<Description v-if="recordData" @register="register" :data="recordData" :contentStyle="CS" />
<div class="!flex mt-3">
<a-button type="primary" @click="handleEventIsCopyDeviceToken">
{{ t('edge.instance.action.copyAccessToken') }}
</a-button>
<a-button class="ml-4" type="primary" @click="handleEventIsManageDeviceToken">
{{ t('edge.instance.action.manageAccessToken') }}
</a-button>
<Popconfirm
:title="t('edge.instance.confirm.cancelAssign')"
@confirm="handleEventIsCancelDistribution"
>
<a-button class="ml-4" type="primary">
{{ t('edge.instance.action.cancelAssign') }}
</a-button>
</Popconfirm>
</div>
</div>
</a-col>
</a-row>
<ManageDeviceTokenModal @register="registerModal" />
</template>
<style lang="less" scoped>
:deep(.ant-image-img) {
height: 157px;
}
</style>