pipeline-app/wwwroot/todo_badge.js

54 lines
2.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 待办角标1 分钟定时刷新 + 点击打开待办列表
// 由 HTML shell 自动加载configuredServer.get_js_files 收集 wwwroot 下 .js在 bricks.js 之后引入)
// 列表与详情的界面全部由后端 dspy 返回 bricks widget 描述渲染:
// /pipeline-sdlc/api/my_todos_popup.dspy → 待办列表弹窗
// /pipeline-sdlc/api/todo_detail.dspy → 待办详情(正文 MdWidget + VScrollPanel 滚动 + 操作按钮)
(function(){
if (typeof bricks === 'undefined') return;
window.refreshTodo = function(){
fetch('/pipeline-sdlc/api/project_human_count.dspy')
.then(function(r){ return r.json(); })
.then(function(d){
var n = (d && d.count) || 0;
var b = bricks.getWidgetById && bricks.getWidgetById('todo_badge', bricks.app);
if (b && b.text_w) {
var _t = function(s, o){ return (bricks.app && bricks.app.i18n) ? bricks.app.i18n._(s, o) : s; };
b.text_w.set_text(n > 0 ? _t('🔔 待办 ${n}', {n: n}) : _t('🔔 待办'));
}
});
};
window.openMyTodos = function(){
// 已打开则先关掉,避免叠加多个列表弹窗
var old = bricks.getWidgetById && bricks.getWidgetById('my_todos_pw', bricks.app);
if (old && old.destroy) { old.destroy(); }
return fetch('/pipeline-sdlc/api/my_todos_popup.dspy')
.then(function(r){ return r.json(); })
.then(function(desc){
if (!desc) { return; }
if (desc.error || desc.success === false) {
var m = new bricks.Message({title:'打开失败', message: desc.error || '无法加载待办'});
m.open();
return;
}
return bricks.widgetBuild(desc, bricks.app);
})
.catch(function(e){
var m2 = new bricks.Message({title:'打开失败', message:'网络错误:' + e});
m2.open();
});
};
// 等 app 初始化完成后启动定时刷新(.js 在 app.run 之前加载,故轮询等 app 就绪)
function _start(){
if (bricks.app && bricks.getWidgetById){
setInterval(function(){ window.refreshTodo(); }, 60000);
setTimeout(function(){ window.refreshTodo(); }, 800);
} else {
setTimeout(_start, 300);
}
}
setTimeout(_start, 300);
})();