config.vue
4.18 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
<template>
<CollapseItem name="播放器配置" :expanded="true">
<template v-for="(item, index) in optionData.dataset" :key="index">
<setting-item-box name="源类型" :alone="true">
<setting-item>
<n-radio-group @change="handleChecked($event, item, index)" v-model:value="item.sourceType" name="radiogroup">
<n-space>
<n-radio v-for="(item, index) in sourceTypes" :key="item.value" :value="item.value">
{{ item.label }}
</n-radio>
</n-space>
</n-radio-group>
</setting-item>
</setting-item-box>
<setting-item-box v-if="item.sourceType === sourceTypeEnum.CUSTOM" name="源地址" :alone="true">
<setting-item>
<n-input-group>
<n-input v-model:value="item.url" size="small" placeholder="请输入源地址"></n-input>
</n-input-group>
</setting-item>
</setting-item-box>
<setting-item-box v-if="item.sourceType === sourceTypeEnum.PLATFORM" name="组织" :alone="true">
<setting-item>
<n-tree-select
placement="top-start"
label-field="name"
v-model:value="item.organization"
key-field="id"
children-field="children"
:options="originationOption"
@update:value="handleUpdateTreeValue($event)"
/>
</setting-item>
</setting-item-box>
<setting-item-box v-if="item.sourceType === sourceTypeEnum.PLATFORM" name="视频" :alone="true">
<setting-item>
<n-select
v-model:value="item.url"
@update:value="(value:string,e:any) => handleSelect(value,e, index)"
:options="videoOptions"
/>
</setting-item>
</setting-item-box>
<n-button size="small" @click="optionData.dataset.splice(index, 1)"> - </n-button>
</template>
<n-button
style="margin-left: 10px"
v-if="optionData.dataset.length < 9"
size="small"
@click="optionData.dataset.push({ url: '', sourceType: 'custom', organization: '', byIdUrl: '' })"
>
+
</n-button>
</CollapseItem>
</template>
<script setup lang="ts">
import { PropType, ref, onMounted } from 'vue'
import { option, sourceTypeEnum } from './config'
import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting'
import { getOrganizationList, getVideoList, getVideoUrl } from '@/api/external/common/index'
import { NTreeSelect } from 'naive-ui'
const props = defineProps({
optionData: {
type: Object as PropType<typeof option>,
required: true
}
})
const sourceTypes = [
{
value: 'custom',
label: '自定义'
},
{
value: 'platform',
label: '平台获取'
}
]
const originationOption = ref([])
const videoOptions = ref([])
const getOriginationList = async () => {
const res = await getOrganizationList()
originationOption.value = res
}
const handleUpdateTreeValue = (e: any) => {
getVideoLists(e)
}
const getVideoLists = async (organizationId: string) => {
const res = await getVideoList({ organizationId })
videoOptions.value = res?.data?.map((item: any) => ({
label: item.name,
value: item.accessMode === 1 ? item.id : item.videoUrl,
id: item.id,
accessMode: item.accessMode
}))
}
const handleChecked = ({ target }: any, values: object, index: number) => {
const { value } = target
if (value === sourceTypeEnum.PLATFORM) {
getOriginationList()
}
props.optionData.dataset[index].url = ''
}
const getVideoUrlById = async (e: any, id: string, index: number) => {
const res = await getVideoUrl(id)
if (!res) return
const { url } = res.data
props.optionData.dataset.forEach((item: any, itemIndex: number) => {
if (itemIndex === index) {
item.byIdUrl = url
}
})
}
const handleSelect = (value: string, e: any, index: number) => {
const { accessMode, id } = e
if (accessMode === 1) {
getVideoUrlById(e, id, index)
}
}
onMounted(() => {
props.optionData.dataset.forEach((item: any) => {
if (item.sourceType === sourceTypeEnum.PLATFORM) {
getOriginationList()
if (item.organization) {
getVideoLists(item.organization)
}
}
})
})
</script>