翻譯|使用教程|編輯:龔雪|2023-07-03 10:12:15.923|閱讀 118 次
概述:本文將為大家介紹如何用DHTMLX構建一個交互式的JavaScript UI儀表板,歡迎下載相關組件體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
DHTMLX Suite包含了超過20個UI小部件,可以幫助開發功能齊全的Web應用程序。例如,開發者可以創建一個全面的儀表板來可視化和監控票務系統的性能。
在本文這個JavaScript儀表板教程中,我們將介紹如何在DHTMLX Suite UI小部件和Optimus微框架的幫助下構建和配置交互式儀表板。
通過DHTMLX創建的UI儀表板允許用戶創建新的票證,將其分配給不同的公司部門,并監視其性能。該Demo是使用以下小部件創建的:
首先,您必須并在設備上運行它,構建UI儀表板的DHTMLX小部件被劃分為多個視圖,可以分別初始化或配置每個小部件,也可以刪除它們。
讓我們來概述一下基于Optimus框架的UI儀表板demo。
從index.html文件開始,在文件的頭部,可以找到suite.js和suite.css,包括DHTMLX套件及其所有組件。同樣可以看到app.js和app.css來配置webpack:
<!DOCTYPE html> <html lang="en"> <head> ... <title>DHTMLX - UI Dashboard</title> ... <!-- Suite --> <script type="text/javascript" src="./lib/suite/suite.js"></script> <link rel="stylesheet" href="./lib/suite/suite.css"/> <!-- App --> <script type="text/javascript" src="./app.js"></script> <link rel="stylesheet" href="./app.css"/> </head>
所有這些文件都包含在demo包中,在body部分,我們可以看到一個容器來渲染demo:
<body> <section class="demo--container" id="top_layout"></section> </body>
應用程序的初始化是通過render()方法完成的:
<script> const app = new uidashboard.UIDashboardApp(); app.render("#top_layout"); </script>
demo的下一個主文件是index.js,它包含呈現應用程序的UIDashboardApp類,在index.html中被用來初始化我們上面描述的演示:
export class UIDashboardApp extends App { init() { this.tickets = getTickets(); this.store = new Store(initialState); this.params.store = this.store; this.state = this.store.getState(); this.subscribe(); dhx.scrollViewConfig.enable = true; this.show("", TopLayout, { tickets: this.tickets, schedulerData, ganttData }); // TopLayout view this.use(HistoryManager); } subscribe() { this.on("modeChanged", id => { this.state.mode = id || "dashboard"; }); this.on("addTicketClicked", obj => { this.tickets.add( { title: obj.title, text: obj.comment, type: obj.type, icon: "Avatar_01", name: `${obj.name} ${obj.lastName}`, comments: "0", time: new Date().getTime(), }, 0 ); }); } }
UIDashboardApp類繼承自index.js文件中包含的所有類,TopLayout類是UI儀表板演示的下一個重要部分:
import "./assets/styles/main.scss"; import { App } from "dhx-optimus"; import Store from "dhx-optimus-store"; import { getLocationParams } from "./helpers/url"; import TopLayout from "./views/TopLayout"; // TopLayout view import HistoryManager from "./components/HistoryManager"; import { getTickets } from "./services/dataService";
總而言之,index.html和index.js文件是UI儀表板演示的基礎。
儀表板演示的下一個組件是Views文件塊,可以在view文件夾中找到它們,每個視圖都是一個ViewName.js文件。讓我們從“unites”演示的TopLayout.js視圖開始。
在這里,您可以看到如何構建和初始化TopLayout類,它包括布局和標簽欄:
export default class TopLayout extends View { init() { this.ui = new dhx.Layout(null, layoutConfig); this.navigationBar = new dhx.Tabbar(this.ui.getCell("tabbar"), { mode: "top", tabAlign: "center", tabWidth: 200, noContent: true, views: [ { id: "dashboard", tab: "Dashboard" }, ], }); this.navigationBar.events.on("change", id => { this.fire("modeChanged", [id]); }); this.show(this.ui.getCell("top"), TopBar); return this.ui; } ready() { this.observe( state => state.mode, mode => { const cell = this.navigationBar.getCell(this.app.state.mode); if (cell) { cell.show(); } this.changeView(mode); } ); } changeView(id) { switch (id) { case "dashboard": this.show(this.ui.getCell("center"), Dashboard, { tickets: this.params.tickets }); break; default: this.show(this.ui.getCell("center"), NotReady); break; } } }
然后,可以通過將其劃分為三個單元格來配置布局:
const layoutConfig = { rows: [ { id: "top", height: "content", }, { id: "tabbar", height: "content", }, { css: "cell_center", id: "center", }, ], };
在這里你可以看到一個輸出:
TopLayout類繼承自以下類:
import { View } from "dhx-optimus"; import TopBar from "./TopBar"; import Dashboard from "./Dashboard"; // Dashboard demo
現在我們準備概述Dashboard視圖,它初始化UI儀表板demo,打開Dashboard.js文件。
在這里可以看到Dashboard的初始化以及Layout的配置:
export default class Dashboard extends View { init() { this.ui = new dhx.Layout(null, { type: "space", cols: [ { type: "wide", rows: [ { height: "50%", cols: [ { id: "left-top", }, { id: "left-bottom", }, ], }, { id: "center", }, ], }, { id: "right", width: "30%", minWidth: 440, maxWidth: 440, }, ], }); this.show(this.ui.getCell("right"), Notifications); this.show(this.ui.getCell("center"), Tickets, { tickets: this.params.tickets }); this.show(this.ui.getCell("left-top"), SalesChart); this.show(this.ui.getCell("left-bottom"), NotificationsChart); return this.ui; } }
因此,我們將Layout的中心單元格劃分為4個部分:
Dashboard類繼承自以下類:
import { View } from "dhx-optimus"; import Notifications from "./Notifications"; import Tickets from "./Tickets"; import SalesChart from "./SalesChart"; import NotificationsChart from "./NotificationsChart";
這就是創建DHTMLX UI儀表板演示的方法,您會發現視圖的結構是完全相同的。每個視圖都將構建儀表板演示的一部分,并在必要時從底層類繼承。您可以打開每個視圖的文件,探索它們的結構,并根據需求對它們進行配置。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網