Skip to content

Commit de8124a

Browse files
author
Taois
committed
feat: 一些示例
1 parent 0a599a7 commit de8124a

File tree

7 files changed

+539
-43
lines changed

7 files changed

+539
-43
lines changed

dashboard/src/api/modules/module.js

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,47 @@ export const executeAction = async (module, data) => {
229229
requestData.extend = extend
230230
}
231231

232-
// 如果提供了apiUrl,直接使用站点的API地址(POST请求需要特殊处理)
232+
console.log('executeAction调用参数:', {
233+
module,
234+
data,
235+
requestData,
236+
apiUrl
237+
})
238+
239+
// 如果提供了apiUrl,直接使用站点的API地址
233240
if (apiUrl) {
234-
// 对于POST请求,我们需要使用axios直接调用
235241
const axios = (await import('axios')).default
236-
const response = await axios.post(apiUrl, requestData, {
237-
timeout: 30000,
238-
headers: {
239-
'Accept': 'application/json',
240-
'Content-Type': 'application/json'
241-
}
242-
})
243-
return response.data
242+
console.log('直接调用API:', apiUrl, requestData)
243+
244+
// 如果是测试用的JSON文件,使用GET请求
245+
if (apiUrl.endsWith('.json')) {
246+
const response = await axios.get(apiUrl, {
247+
timeout: 30000,
248+
headers: {
249+
'Accept': 'application/json'
250+
}
251+
})
252+
console.log('API响应 (GET):', response.data)
253+
return response.data
254+
} else {
255+
// 否则使用POST请求
256+
const response = await axios.post(apiUrl, requestData, {
257+
timeout: 30000,
258+
headers: {
259+
'Accept': 'application/json',
260+
'Content-Type': 'application/json'
261+
}
262+
})
263+
console.log('API响应 (POST):', response.data)
264+
return response.data
265+
}
244266
}
245267

246268
// 否则使用原来的代理方式
247-
return post(buildModuleUrl(module), requestData)
269+
console.log('使用代理方式调用:', buildModuleUrl(module), requestData)
270+
const result = await post(buildModuleUrl(module), requestData)
271+
console.log('代理响应:', result)
272+
return result
248273
}
249274

250275
/**

dashboard/src/components/SearchResults.vue

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,20 @@
9999
v-if="showActionRenderer"
100100
ref="actionRendererRef"
101101
:action-data="currentActionData"
102+
:module="props.module"
103+
:extend="props.extend"
104+
:api-url="props.apiUrl"
102105
@close="handleActionClose"
103106
@submit="handleActionSubmit"
107+
@special-action="handleSpecialAction"
104108
/>
105109
</div>
106110
</template>
107111

108112
<script setup>
109113
import { ref, nextTick, onMounted, onBeforeUnmount, watch } from 'vue'
110114
import { useRouter } from 'vue-router'
115+
import { Message } from '@arco-design/web-vue'
111116
import { usePaginationStore } from '@/stores/paginationStore'
112117
import { usePageStateStore } from '@/stores/pageStateStore'
113118
import { useVisitedStore } from '@/stores/visitedStore'
@@ -157,11 +162,26 @@ const props = defineProps({
157162
scrollPosition: {
158163
type: Number,
159164
default: 0
165+
},
166+
// 模块名称,用于T4接口调用
167+
module: {
168+
type: String,
169+
default: ''
170+
},
171+
// 扩展参数,用于T4接口调用
172+
extend: {
173+
type: String,
174+
default: ''
175+
},
176+
// API URL,用于直接调用站点API
177+
apiUrl: {
178+
type: String,
179+
default: ''
160180
}
161181
})
162182
163183
// Emits
164-
const emit = defineEmits(['video-click', 'exit-search', 'load-more'])
184+
const emit = defineEmits(['video-click', 'exit-search', 'load-more', 'refresh-list'])
165185
166186
const containerRef = ref(null)
167187
const scrollbarRef = ref(null)
@@ -307,7 +327,7 @@ const handleVideoClick = (video) => {
307327
// 检查是否为action类型
308328
if (video.vod_tag === 'action') {
309329
try {
310-
// 解析vod_id中的JSON字符串获取action配置
330+
// 尝试解析vod_id中的JSON字符串获取action配置
311331
const actionConfig = JSON.parse(video.vod_id);
312332
console.log('SearchResults解析action配置:', actionConfig);
313333
@@ -316,9 +336,14 @@ const handleVideoClick = (video) => {
316336
showActionRenderer.value = true;
317337
return;
318338
} catch (error) {
319-
console.error('SearchResults解析action配置失败:', error, 'vod_id:', video.vod_id);
320-
// 如果解析失败,显示错误信息
321-
alert(`Action配置解析失败: ${error.message}`);
339+
console.log('SearchResults vod_id不是JSON格式,作为普通文本处理:', video.vod_id);
340+
341+
// 如果解析失败,说明vod_id是普通文本,显示Toast提示
342+
Message.info({
343+
content: video.vod_id,
344+
duration: 3000,
345+
closable: true
346+
});
322347
return;
323348
}
324349
}
@@ -431,6 +456,34 @@ const handleActionSubmit = (result) => {
431456
currentActionData.value = null;
432457
// 可以在这里处理action的提交结果
433458
}
459+
460+
const handleSpecialAction = (actionType, actionData) => {
461+
console.log('处理专项动作:', actionType, actionData);
462+
463+
switch (actionType) {
464+
case 'self-search':
465+
// 处理源内搜索
466+
console.log('执行源内搜索:', actionData);
467+
break;
468+
case 'detail':
469+
// 处理详情页跳转
470+
console.log('跳转到详情页:', actionData);
471+
break;
472+
case 'ktv-player':
473+
// 处理KTV播放
474+
console.log('启动KTV播放:', actionData);
475+
break;
476+
case 'refresh-list':
477+
// 处理刷新列表
478+
console.log('刷新列表:', actionData);
479+
// 可以触发父组件的刷新事件
480+
emit('refresh-list');
481+
break;
482+
default:
483+
console.log('未知的专项动作:', actionType, actionData);
484+
break;
485+
}
486+
}
434487
</script>
435488
436489
<style scoped>

dashboard/src/components/VideoGrid.vue

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,20 @@
5555
v-if="showActionRenderer"
5656
ref="actionRendererRef"
5757
:action-data="currentActionData"
58+
:module="props.module"
59+
:extend="props.extend"
60+
:api-url="props.apiUrl"
5861
@close="handleActionClose"
5962
@submit="handleActionSubmit"
63+
@special-action="handleSpecialAction"
6064
/>
6165
</div>
6266
</template>
6367

6468
<script setup>
6569
import { onMounted, nextTick, ref, onBeforeUnmount, watch } from 'vue';
6670
import { useRouter } from 'vue-router';
71+
import { Message } from '@arco-design/web-vue';
6772
import { useVisitedStore } from '@/stores/visitedStore';
6873
import ActionRenderer from '@/components/actions/ActionRenderer.vue';
6974
@@ -92,10 +97,23 @@ const props = defineProps({
9297
sourceRoute: {
9398
type: Object,
9499
default: () => ({})
100+
},
101+
// T4接口调用相关参数
102+
module: {
103+
type: String,
104+
default: ''
105+
},
106+
extend: {
107+
type: Object,
108+
default: () => ({})
109+
},
110+
apiUrl: {
111+
type: String,
112+
default: ''
95113
}
96114
});
97115
98-
const emit = defineEmits(['load-more', 'scroll-bottom']);
116+
const emit = defineEmits(['load-more', 'scroll-bottom', 'refresh-list']);
99117
100118
const router = useRouter();
101119
const visitedStore = useVisitedStore();
@@ -115,7 +133,7 @@ const handleVideoClick = (video) => {
115133
// 检查是否为action类型
116134
if (video.vod_tag === 'action') {
117135
try {
118-
// 解析vod_id中的JSON字符串获取action配置
136+
// 尝试解析vod_id中的JSON字符串获取action配置
119137
const actionConfig = JSON.parse(video.vod_id);
120138
console.log('VideoGrid解析action配置:', actionConfig);
121139
@@ -124,9 +142,14 @@ const handleVideoClick = (video) => {
124142
showActionRenderer.value = true;
125143
return;
126144
} catch (error) {
127-
console.error('VideoGrid解析action配置失败:', error, 'vod_id:', video.vod_id);
128-
// 如果解析失败,显示错误信息
129-
alert(`Action配置解析失败: ${error.message}`);
145+
console.log('VideoGrid vod_id不是JSON格式,作为普通文本处理:', video.vod_id);
146+
147+
// 如果解析失败,说明vod_id是普通文本,显示Toast提示
148+
Message.info({
149+
content: video.vod_id,
150+
duration: 3000,
151+
closable: true
152+
});
130153
return;
131154
}
132155
}
@@ -352,6 +375,34 @@ const handleActionSubmit = (result) => {
352375
// 比如刷新列表、显示消息等
353376
};
354377
378+
const handleSpecialAction = (actionType, actionData) => {
379+
console.log('VideoGrid处理专项动作:', actionType, actionData);
380+
381+
switch (actionType) {
382+
case 'self-search':
383+
// 处理源内搜索
384+
console.log('执行源内搜索:', actionData);
385+
break;
386+
case 'detail':
387+
// 处理详情页跳转
388+
console.log('跳转到详情页:', actionData);
389+
break;
390+
case 'ktv-player':
391+
// 处理KTV播放
392+
console.log('启动KTV播放:', actionData);
393+
break;
394+
case 'refresh-list':
395+
// 处理刷新列表
396+
console.log('刷新列表:', actionData);
397+
// 可以触发父组件的刷新事件
398+
emit('refresh-list');
399+
break;
400+
default:
401+
console.log('未知的专项动作:', actionType, actionData);
402+
break;
403+
}
404+
};
405+
355406
// 暴露方法给父组件
356407
defineExpose({
357408
checkTextOverflow,

dashboard/src/components/VideoList.vue

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
:hasMore="false"
2525
:statsText="`推荐视频:共 ${listData[activeKey]?.length || 0} 条`"
2626
:sourceRoute="props.sourceRoute"
27+
:module="props.module"
28+
:extend="props.extend"
29+
:api-url="props.apiUrl"
30+
@refresh-list="handleRefreshList"
2731
/>
2832
</div>
2933

@@ -36,8 +40,12 @@
3640
:loading="loadingMore[activeKey] || false"
3741
:hasMore="pageData[activeKey]?.hasNext || false"
3842
:sourceRoute="props.sourceRoute"
43+
:module="props.module"
44+
:extend="props.extend"
45+
:api-url="props.apiUrl"
3946
@load-more="loadMoreData(activeKey)"
4047
@scroll-bottom="loadMoreData(activeKey)"
48+
@refresh-list="handleRefreshList"
4149
/>
4250
</div>
4351
</div>
@@ -82,6 +90,19 @@ const props = defineProps({
8290
returnToActiveKey: {
8391
type: String,
8492
default: ""
93+
},
94+
// T4接口调用相关参数
95+
module: {
96+
type: String,
97+
default: ''
98+
},
99+
extend: {
100+
type: Object,
101+
default: () => ({})
102+
},
103+
apiUrl: {
104+
type: String,
105+
default: ''
85106
}
86107
});
87108
@@ -439,8 +460,33 @@ defineExpose({
439460
}, 200);
440461
}
441462
}
463+
},
464+
refreshCurrentCategory: () => {
465+
if (activeKey.value) {
466+
console.log('刷新当前分类:', activeKey.value);
467+
// 重置当前分类的数据
468+
listData[activeKey.value] = [];
469+
pageData[activeKey.value] = { page: 1, hasNext: true };
470+
loadingMore[activeKey.value] = false;
471+
// 重新加载数据
472+
getListData(activeKey.value);
473+
}
442474
}
443475
});
476+
477+
// 处理刷新列表事件
478+
const handleRefreshList = () => {
479+
console.log('VideoList收到刷新列表请求');
480+
if (activeKey.value) {
481+
console.log('刷新当前分类:', activeKey.value);
482+
// 重置当前分类的数据
483+
listData[activeKey.value] = [];
484+
pageData[activeKey.value] = { page: 1, hasNext: true };
485+
loadingMore[activeKey.value] = false;
486+
// 重新加载数据
487+
getListData(activeKey.value);
488+
}
489+
};
444490
</script>
445491
446492
<style scoped>

0 commit comments

Comments
 (0)