Skip to content

Commit 73f5beb

Browse files
author
Taois
committed
feat:修正全局动作界面警告
1 parent b548ee5 commit 73f5beb

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

dashboard/src/components/Breadcrumb.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,19 @@ const handleActionExecuted = (event) => {
184184
// 向父组件发送动作执行事件
185185
emit('actionExecuted', event);
186186
187+
// 添加安全检查,防止null引用错误
188+
if (!event || typeof event !== 'object') {
189+
console.warn('Invalid event object received in handleActionExecuted');
190+
return;
191+
}
192+
193+
const actionName = event.action?.name || '未知动作';
194+
187195
if (event.success) {
188-
Message.success(`动作 "${event.action.name}" 执行成功`);
196+
Message.success(`动作 "${actionName}" 执行成功`);
189197
} else {
190198
if (event.error !== 'cancel') {
191-
Message.error(`动作 "${event.action.name}" 执行失败: ${event.error}`);
199+
Message.error(`动作 "${actionName}" 执行失败: ${event.error || '未知错误'}`);
192200
}
193201
}
194202
};

dashboard/src/components/GlobalActionDialog.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ const handleActionClick = async (action) => {
228228
try {
229229
console.log('执行全局动作:', action)
230230
231+
// 添加安全检查,防止null引用错误
232+
if (!action || typeof action !== 'object') {
233+
throw new Error('无效的动作对象')
234+
}
235+
231236
// 解析动作配置
232237
let actionConfig
233238
if (typeof action.action === 'string') {
@@ -239,11 +244,11 @@ const handleActionClick = async (action) => {
239244
actionConfig = {
240245
actionId: action.action,
241246
type: 'msgbox',
242-
title: action.name,
247+
title: action.name || '未知动作',
243248
msg: `执行动作: ${action.action}`
244249
}
245250
}
246-
} else if (typeof action.action === 'object') {
251+
} else if (typeof action.action === 'object' && action.action !== null) {
247252
actionConfig = action.action
248253
} else {
249254
throw new Error('无效的动作配置')

dashboard/src/views/Video.vue

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,23 @@ const checkNowSite = () => {
247247
} else if (form.sites.length > 0) {
248248
// 如果没有当前源,设置第一个可用源
249249
const firstSite = form.sites.find(site => site.type === 4) || form.sites[0];
250-
form.now_site = firstSite;
251-
form.now_site_title = firstSite.name;
252-
siteService.setCurrentSite(firstSite.key);
250+
if (firstSite) {
251+
form.now_site = firstSite;
252+
form.now_site_title = firstSite.name;
253+
siteService.setCurrentSite(firstSite.key);
254+
}
253255
}
254256
} else {
255257
// 检查当前源是否在站点列表中
256258
const siteExists = form.sites.some(site => site.key === form.now_site.key);
257259
if (!siteExists && form.sites.length > 0) {
258260
// 如果当前源不在列表中,设置第一个可用源
259261
const firstSite = form.sites.find(site => site.type === 4) || form.sites[0];
260-
form.now_site = firstSite;
261-
form.now_site_title = firstSite.name;
262-
siteService.setCurrentSite(firstSite.key);
262+
if (firstSite) {
263+
form.now_site = firstSite;
264+
form.now_site_title = firstSite.name;
265+
siteService.setCurrentSite(firstSite.key);
266+
}
263267
}
264268
}
265269
@@ -877,9 +881,17 @@ const handlePush = async (vodId) => {
877881
const handleActionExecuted = (event) => {
878882
console.log('全局动作执行完成:', event);
879883
884+
// 添加安全检查,防止null引用错误
885+
if (!event || typeof event !== 'object') {
886+
console.warn('Invalid event object received in handleActionExecuted');
887+
return;
888+
}
889+
890+
const actionName = event.action?.name || '未知动作';
891+
880892
if (event.success) {
881893
// 动作执行成功,可以根据需要进行后续处理
882-
console.log('动作执行成功:', event.action.name, event.result);
894+
console.log('动作执行成功:', actionName, event.result);
883895
884896
// 如果动作返回了特殊结果,可以在这里处理
885897
if (event.result && event.result.refresh) {
@@ -893,7 +905,7 @@ const handleActionExecuted = (event) => {
893905
}
894906
} else {
895907
// 动作执行失败
896-
console.error('动作执行失败:', event.action.name, event.error);
908+
console.error('动作执行失败:', actionName, event.error);
897909
}
898910
};
899911

0 commit comments

Comments
 (0)