-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathindex.vue
More file actions
469 lines (431 loc) · 15.1 KB
/
index.vue
File metadata and controls
469 lines (431 loc) · 15.1 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<template>
<div class="p-16-24">
<h2 class="mb-16">{{ $t('views.applicationOverview.title') }}</h2>
<el-scrollbar>
<div class="main-calc-height">
<el-card style="--el-card-padding: 24px">
<h4 class="title-decoration-1 mb-16">
{{ $t('views.applicationOverview.appInfo.header') }}
</h4>
<el-card shadow="never" class="overview-card" v-loading="loading">
<div class="title flex align-center">
<div class="edit-avatar mr-12">
<el-avatar shape="square" :size="32" style="background: none">
<img :src="resetUrl(detail?.icon, resetUrl('./favicon.ico'))" alt="" />
</el-avatar>
</div>
<h4>{{ detail?.name || '-' }}</h4>
</div>
<el-row :gutter="12">
<el-col :span="12" class="mt-16">
<div class="flex">
<el-text type="info"
>{{ $t('views.applicationOverview.appInfo.publicAccessLink') }}
</el-text>
<el-switch
v-model="accessToken.is_active"
class="ml-8"
size="small"
inline-prompt
:active-text="$t('views.applicationOverview.appInfo.openText')"
:inactive-text="$t('views.applicationOverview.appInfo.closeText')"
:before-change="() => changeState(accessToken.is_active)"
/>
</div>
<div class="mt-4 mb-16 url-height flex align-center" style="margin-bottom: 37px">
<span class="vertical-middle lighter break-all ellipsis-1">
{{ shareUrl }}
</span>
<el-tooltip effect="dark" :content="$t('common.copy')" placement="top">
<el-button type="primary" text @click="copyClick(shareUrl)">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</el-tooltip>
<el-tooltip effect="dark" :content="$t('common.refresh')" placement="top">
<el-button
@click="refreshAccessToken"
type="primary"
text
style="margin-left: 1px"
>
<el-icon>
<RefreshRight />
</el-icon>
</el-button>
</el-tooltip>
</div>
<div>
<el-button
v-if="accessToken?.is_active"
:disabled="!accessToken?.is_active"
tag="a"
:href="shareUrl"
target="_blank"
>
<AppIcon iconName="app-create-chat" class="mr-4"></AppIcon>
{{ $t('views.application.operation.toChat') }}
</el-button>
<el-button v-else :disabled="!accessToken?.is_active">
<AppIcon iconName="app-create-chat" class="mr-4"></AppIcon>
{{ $t('views.application.operation.toChat') }}
</el-button>
<el-button
:disabled="!accessToken?.is_active"
@click="openDialog"
v-if="permissionPrecise.overview_embed(id)"
>
<AppIcon iconName="app-export" class="mr-4"></AppIcon>
{{ $t('views.applicationOverview.appInfo.embedInWebsite') }}
</el-button>
<!-- 访问限制 -->
<el-button @click="openLimitDialog" v-if="permissionPrecise.overview_access(id)">
<AppIcon iconName="app-lock" class="mr-4"></AppIcon>
{{ $t('views.applicationOverview.appInfo.accessControl') }}
</el-button>
<!-- 显示设置 -->
<el-button
@click="openDisplaySettingDialog"
v-if="permissionPrecise.overview_display(id)"
>
<AppIcon iconName="app-setting" class="mr-4"></AppIcon>
{{ $t('views.applicationOverview.appInfo.displaySetting') }}
</el-button>
</div>
</el-col>
<el-col :span="12" class="mt-16">
<div class="flex">
<el-text type="info"
>{{ $t('views.applicationOverview.appInfo.apiAccessCredentials') }}
</el-text>
</div>
<div class="mt-4 mb-16 url-height">
<div>
<el-text>API {{ $t('common.fileUpload.document') }}: </el-text>
<el-button
type="primary"
link
@click="toUrl(apiUrl)"
class="vertical-middle lighter break-all"
>
{{ apiUrl }}
</el-button>
</div>
<div class="flex align-center">
<span class="flex">
<el-text style="width: 80px">Base URL:</el-text>
</span>
<span class="vertical-middle lighter break-all ellipsis-1">{{
baseUrl + id
}}</span>
<el-tooltip effect="dark" :content="$t('common.copy')" placement="top">
<el-button type="primary" text @click="copyClick(baseUrl + id)">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</el-tooltip>
</div>
</div>
<div>
<el-button
@click="openAPIKeyDialog"
v-if="permissionPrecise.overview_api_key(id)"
>
<el-icon class="mr-4">
<Key />
</el-icon>
{{ $t('views.applicationOverview.appInfo.apiKey') }}
</el-button>
</div>
</el-col>
</el-row>
</el-card>
</el-card>
<el-card style="--el-card-padding: 24px" class="mt-16">
<h4 class="title-decoration-1 mb-16">
{{ $t('views.applicationOverview.monitor.monitoringStatistics') }}
</h4>
<div class="mb-16">
<el-select
v-model="history_day"
class="mr-12"
@change="changeDayHandle"
style="width: 180px"
>
<el-option
v-for="item in dayOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
<el-date-picker
v-if="history_day === 'other'"
v-model="daterangeValue"
type="daterange"
:start-placeholder="$t('views.applicationOverview.monitor.startDatePlaceholder')"
:end-placeholder="$t('views.applicationOverview.monitor.endDatePlaceholder')"
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
@change="changeDayRangeHandle"
/>
</div>
<div v-loading="statisticsLoading">
<StatisticsCharts :data="statisticsData" />
</div>
</el-card>
</div>
</el-scrollbar>
<EmbedDialog
ref="EmbedDialogRef"
:data="detail"
:api-input-params="mapToUrlParams(apiInputParams)"
/>
<APIKeyDialog ref="APIKeyDialogRef" />
<!-- 社区版访问限制 -->
<component :is="currentLimitDialog" ref="LimitDialogRef" @refresh="refresh" />
<!-- 显示设置 -->
<component :is="currentDisplaySettingDialog" ref="DisplaySettingDialogRef" @refresh="refresh" />
</div>
</template>
<script setup lang="ts">
import { ref, computed, onMounted, shallowRef, nextTick } from 'vue'
import { useRoute } from 'vue-router'
import EmbedDialog from './component/EmbedDialog.vue'
import APIKeyDialog from './component/APIKeyDialog.vue'
import LimitDialog from './component/LimitDialog.vue'
import XPackLimitDrawer from './xpack-component/XPackLimitDrawer.vue'
import DisplaySettingDialog from './component/DisplaySettingDialog.vue'
import XPackDisplaySettingDialog from './xpack-component/XPackDisplaySettingDialog.vue'
import StatisticsCharts from './component/StatisticsCharts.vue'
import { nowDate, beforeDay } from '@/utils/time'
import { MsgSuccess, MsgConfirm } from '@/utils/message'
import { copyClick } from '@/utils/clipboard'
import { resetUrl } from '@/utils/common'
import { mapToUrlParams } from '@/utils/application'
import useStore from '@/stores'
import { t } from '@/locales'
import { EditionConst } from '@/utils/permission/data'
import { hasPermission } from '@/utils/permission/index'
import permissionMap from '@/permission'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
const route = useRoute()
const {
params: { id },
} = route as any
const apiType = computed(() => {
if (route.path.includes('resource-management')) {
return 'systemManage'
} else {
return 'workspace'
}
})
const permissionPrecise = computed(() => {
return permissionMap['application'][apiType.value]
})
const apiUrl = window.location.origin + '/doc_chat/'
const baseUrl = window.location.origin + `${window.MaxKB.chatPrefix}/api/`
const APIKeyDialogRef = ref()
const EmbedDialogRef = ref()
const accessToken = ref<any>({})
const detail = ref<any>(null)
const loading = ref(false)
const urlParams = computed(() =>
mapToUrlParams(apiInputParams.value) ? '?' + mapToUrlParams(apiInputParams.value) : '',
)
const shareUrl = computed(
() =>
`${window.location.origin}${window.MaxKB.chatPrefix}/` +
accessToken.value?.access_token +
urlParams.value,
)
const dayOptions = [
{
value: 7,
label: t('views.applicationOverview.monitor.pastDayOptions.past7Days'),
},
{
value: 30,
label: t('views.applicationOverview.monitor.pastDayOptions.past30Days'),
},
{
value: 90,
label: t('views.applicationOverview.monitor.pastDayOptions.past90Days'),
},
{
value: 183,
label: t('views.applicationOverview.monitor.pastDayOptions.past183Days'),
},
{
value: 'other',
label: t('common.custom'),
},
]
const history_day = ref<number | string>(7)
// 日期组件时间
const daterangeValue = ref('')
// 提交日期时间
const daterange = ref({
start_time: '',
end_time: '',
})
const statisticsLoading = ref(false)
const statisticsData = ref([])
const apiInputParams = ref([])
function toUrl(url: string) {
window.open(url, '_blank')
}
// 显示设置
const DisplaySettingDialogRef = ref()
const currentDisplaySettingDialog = shallowRef<any>(null)
function openDisplaySettingDialog() {
// 企业版和专业版
if (hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR')) {
currentDisplaySettingDialog.value = XPackDisplaySettingDialog
} else {
// 社区版
currentDisplaySettingDialog.value = DisplaySettingDialog
}
nextTick(() => {
if (currentDisplaySettingDialog.value == XPackDisplaySettingDialog) {
loadSharedApi({ type: 'application', systemType: apiType.value })
.getApplicationSetting(id)
.then((ok: any) => {
DisplaySettingDialogRef.value?.open(ok.data, detail.value)
})
} else {
DisplaySettingDialogRef.value?.open(accessToken.value, detail.value)
}
})
}
// 访问限制
const LimitDialogRef = ref()
const currentLimitDialog = shallowRef<any>(null)
function openLimitDialog() {
// 企业版和专业版
if (hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR')) {
currentLimitDialog.value = XPackLimitDrawer
} else {
// 社区版
currentLimitDialog.value = LimitDialog
}
nextTick(() => {
LimitDialogRef.value.open(accessToken.value)
})
}
function changeDayHandle(val: number | string) {
if (val !== 'other') {
daterange.value.start_time = beforeDay(val)
daterange.value.end_time = nowDate
getAppStatistics()
}
}
function changeDayRangeHandle(val: string) {
daterange.value.start_time = val[0]
daterange.value.end_time = val[1]
getAppStatistics()
}
function getAppStatistics() {
loadSharedApi({ type: 'application', systemType: apiType.value })
.getStatistics(id, daterange.value, statisticsLoading)
.then((res: any) => {
statisticsData.value = res.data
})
}
function refreshAccessToken() {
MsgConfirm(
t('views.applicationOverview.appInfo.refreshToken.msgConfirm1'),
t('views.applicationOverview.appInfo.refreshToken.msgConfirm2'),
{
confirmButtonText: t('common.confirm'),
cancelButtonText: t('common.cancel'),
},
)
.then(() => {
const obj = {
access_token_reset: true,
}
const str = t('views.applicationOverview.appInfo.refreshToken.refreshSuccess')
updateAccessToken(obj, str)
})
.catch(() => {})
}
async function changeState(bool: boolean) {
const obj = {
is_active: !bool,
}
const str = obj.is_active ? t('common.status.enableSuccess') : t('common.status.disableSuccess')
await updateAccessToken(obj, str)
.then(() => {
return true
})
.catch(() => {
return false
})
}
async function updateAccessToken(obj: any, str: string) {
loadSharedApi({ type: 'application', systemType: apiType.value })
.putAccessToken(id as string, obj, loading)
.then((res: any) => {
accessToken.value = res?.data
MsgSuccess(str)
})
}
function openAPIKeyDialog() {
APIKeyDialogRef.value.open()
}
function openDialog() {
EmbedDialogRef.value.open(accessToken.value?.access_token)
}
function getAccessToken() {
loadSharedApi({ type: 'application', systemType: apiType.value })
.getAccessToken(id, loading)
.then((res: any) => {
accessToken.value = res?.data
})
}
function getDetail() {
loadSharedApi({ type: 'application', systemType: apiType.value })
.getApplicationDetail(id, loading)
.then((res: any) => {
detail.value = res.data
detail.value.work_flow?.nodes
?.filter((v: any) => v.id === 'base-node')
.map((v: any) => {
apiInputParams.value = v.properties.api_input_field_list
? v.properties.api_input_field_list.map((v: any) => {
return {
name: v.variable,
value: v.default_value,
}
})
: v.properties.input_field_list
? v.properties.input_field_list
.filter((v: any) => v.assignment_method === 'api_input')
.map((v: any) => {
return {
name: v.variable,
value: v.default_value,
}
})
: []
})
})
}
function refresh() {
getAccessToken()
}
onMounted(() => {
getDetail()
getAccessToken()
changeDayHandle(history_day.value)
})
</script>
<style lang="scss" scoped>
.overview-card {
position: relative;
.active-button {
position: absolute;
right: 16px;
top: 21px;
}
}
</style>