原創|使用教程|編輯:何躍|2021-12-07 16:40:27.883|閱讀 395 次
概述:在前后端分離的情況下,很多企業的各類業務系統開始從只關注業務升級到同時關心交互與效率的層面,那么一套可以滿足一線人員操作又能滿足管理人員根據圖表做決策的系統的開發需求就來了,DHTMLX可以一試!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
DHTMLX Suite包括20多個UI部件,有助于開發全功能的網絡應用程序。其中包含了一線辦事人員會用到的美觀的下拉框、輸入框、表格、按鈕,也包含了管理人員需要的各類圖表,例如餅圖、折線圖等。具體舉例,作為售票大廳工作的你甚至可以創建一個全面的儀表盤來可視化和監控票務系統的性能。
本篇將為身為技術的你還原這類系統是如何打造的,。
在這個JavaScript儀表盤教程中,我們將描述如何在Suite UI部件和Optimus微框架的幫助下建立和配置一個互動儀表盤。
DHTMLX的UI儀表盤允許用戶創建一個新的票據,將其分配給不同的公司部門,并監控其表現。這個演示是用以下DHTMLX工具創建的:
首先,咱們并在你的設備上運行它。你可能會注意到,構建UI儀表盤的DHTMLX部件被劃分為視圖。你可以分別初始化或配置每個小部件,也可以將其刪除。
讓我們對基于Optimus框架的UI儀表板演示做一個概述。
我們將從index.html文件開始。在文件的頭部部分,你可以找到 suite.js 和 suite.css。我們包括DHTMLX Suite及其所有的組件。此外,你可以看到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> <body> <section class="demo--container" id="top_layout">這是一個空的界面應用標簽,記得ID要寫呀</section> </body> <script> //應用程序的初始化是通過render()方法進行的。 const app = new uidashboard.UIDashboardApp(); app.render("#top_layout"); </script>
該演示的下一個主要文件是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"; // 頂部菜單 import HistoryManager from "./components/HistoryManager"; import { getTickets } from "./services/dataService";總而言之,index.html和index.js文件是UI儀表板演示的基礎。你可以在文檔中了解更多關于使用這些文件以及如何使用Optimus構建應用程序的信息。
儀表盤演示的下一個組成部分是一個視圖文件塊。你可以在view文件夾中找到所有這些文件。每個視圖都是一個ViewName.js文件。讓我們從TopLayout.js視圖開始,它 "聯合 "了整個演示。
在這里你可以看到TopLayout類是如何建立和啟動的。它包括Layout和Tabbar:
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; } } }然后,你可以通過將其劃分為三個單元來配置Layout。
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儀表板演示。讓我們打開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個部分。
// 儀表盤繼承與以下類 import { View } from "dhx-optimus"; import Notifications from "./Notifications"; import Tickets from "./Tickets"; import SalesChart from "./SalesChart"; import NotificationsChart from "./NotificationsChart";這就是DHTMLX UI儀表盤演示的創建方式。你會發現,視圖的結構是非常相同的。每個視圖都會建立儀表盤演示的部分,并在必要時繼承底部的類。你可以打開每個視圖的文件,探索它們的結構,并根據你的要求來配置它們。
紙上覺來終覺錢,要知此事請看DEMO代碼,結合上述對區域劃分的方法,找到使用DHTMLX快捷開發業務系統的方法!
以上您也可以直接下載DHTMLX SUITE從0開始體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn