codecamp

如何通过插件或模块的方式对后台首页进行模块注入

Notadd 后台管理的首页(Dashboard),是可以通过插件或扩展,进行添加自定义模块的。

支持的自定义模块类型

  • html(自定义原生 HTML 代码)
  • text(字符串文本)
  • button(普通按钮或带链接的按钮)
  • chart(自定义图标,基于百度图标)

数据结构

button

{
    content: '这是 Button 文本内容',
    link: 'http://www.hao123.com',
    span: 12,
    theme: 'primary',
    title: '这是 Button 标题',
    type: 'button',
}

chart

{
    content: {
        title: {
            text: 'Notadd 图标测试',
        },
        tooltip: {},
        xAxis: {
            data: ['Shirt', 'Sweater', 'Chiffon Shirt', 'Pants', 'High Heels', 'Socks'],
        },
        yAxis: {},
        series: [
            {
                name: 'Sales',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20],
            },
        ],
    },
    span: 12,
    style: 'height: 300px;',
    title: '这是 Chart 标题',
    type: 'chart',
}

html

{
    content: '这是 Html 文本内容',
    span: 12,
    title: '这是 Html 标题',
    type: 'html',
}

text

{
    content: '这是 Text 文本内容',
    span: 12,
    title: '这是 Text 标题',
    type: 'text',
}

注入方法

基于 Notadd 后台前端框架,实现该页面的注入,仅需要前端模块注入的install方式中使用useBoard函数进行注入即可。

参考代码如下:

export default function (injection) {
    injection.useBoard({
        content: {
            title: {
                text: 'Notadd Content 模块图标测试',
            },
            tooltip: {},
            xAxis: {
                data: ['资讯', '科技', '文化', '讲座', '娱乐', '软件'],
            },
            yAxis: {},
            series: [
                {
                    name: 'Sales',
                    type: 'bar',
                    data: [5, 20, 36, 10, 10, 20],
                },
            ],
        },
        span: 12,
        style: 'height: 300px;',
        title: '这是 Chart 标题',
        type: 'chart',
    });
}
如何开发一个 Notadd Administration 模块的前端扩展
如何用Vue2写出web单页应用
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

技术规范

API 结构

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }