如何使用 JavaScript UI 控件(WijmoJS)构建 Electron 应用程序

2019-02-15 10:58:53 +08:00
 powertoolsteam
如何使用 JavaScript UI 控件( WijmoJS )构建 Electron 应用程序
( WijmoJS 试用地址: https://www.grapecity.com.cn/developer/wijmojs

What is Electron?
Electron 是一个使用 JavaScript、HTML 和 CSS 构建跨平台桌面应用程序的框架。 您可以将 Electron 与纯 JavaScript 或您选择的 JavaScript 框架一起使用:

- React
- Angular
- Vue

构建一个简单的 Electron 应用程序

要创建基本的 Electron 应用程序,请按照下列步骤操作:

git clone https://github.com/electron/electron-quick-start
cd electron-quick-start
npm install
npm start


将 JavaScript UI 控件( WijmoJS )添加到应用程序

要将 WijmoJS 添加到应用程序,请先安装它。在命令提示符下,进入 app 文件夹( electron-quick-start )并键入:

npm install Wijmo

接下来,使用 VS Code 或您喜好的编辑器打开 index.html 文件,并添加以下内容:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>

<!-- add Bootstrap and Wijmo css -->
<link href=https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css
rel="stylesheet"/>
<link href=https://cdn.grapecity.com/wijmo/5.latest/styles/wijmo.min.css
rel="stylesheet"/>

<!-- define the app styles -->
<style>
.app-panel {
margin: 0 48pt;
}
.app-panel .wj-control {
display: inline-block;
vertical-align: top;
width: 400px;
height: 300px;
}
</style>
</head>
<body>
<div class="container">
<h1>Hello World!</h1>
<p>
<!-- Node.js APIs are available in this renderer process. -->
We are using Node.js
<script>document.write(process.versions.node)</script>,
Chromium <script>document.write(process.versions.chrome)</script>,
and Electron
<script>document.write(process.versions.electron)</script>.
</p>

<!--add Wijmo controls to the page -->
<div class="app-panel">
<div id="theGrid"></div>
<div id="theChart"></div>
</div>
</div>
<script>
// You can also require other files to run in this process
require('./renderer.js')
</script>
</body>
</html>

在这一步中,我们为两个 WijmoJS 控件添加了一些样式和主题元素。接下来,打开“ renderer.js ”文件并按如下所示进行编辑:

// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.

// import Wijmo
var wjCore = require('./node_modules/wijmo/wijmo.js');
var wjGrid = require('./node_modules/wijmo/wijmo.grid.js');
var wjChart = require('./node_modules/wijmo/wijmo.chart.js');

// set the Wijmo license key
var key = 'GrapeCity-Internal-Use-Only,…';
wjCore.setLicenseKey(key);

// create the controls
var theGrid = new wjGrid.FlexGrid('#theGrid', {
itemsSource: getData()
});
var theChart = new wjChart.FlexChart('#theChart', {
itemsSource: theGrid.itemsSource,
bindingX: 'country',
series: [
{ name: 'Sales', binding: 'sales' },
{ name: 'Expenses', binding: 'expenses' },
{ name: 'Downloads', binding: 'downloads' },
]
});

// get some random data
function getData() {
var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
data = [];
for (var i = 0; i < countries.length; i++) {
data.push({
country: countries[i],
sales: Math.random() * 10000,
expenses: Math.random() * 5000,
downloads: Math.round(Math.random() * 20000),
});
}
return new wjCore.CollectionView(data);
}

实现这段代码首先需要三个 WijmoJS 模块:WijmoJS Core,Grid 和 Chart。 (它设置了 WijmoJS 许可证密钥,因此应用程序在运行时不会显示水印。如果您没有许可证密钥,请跳过此步骤,应用程序仍将运行,但会显示水印元素)

如果您在此之前已经安装了许可证密钥,则不需要特定域。WijmoJS 电子应用程序会从文件或本地主机协议运行,因此任何有效的 WijmoJS 密钥都将起作用,无论用于生成它的域是什么。

最后一步是创建 WijmoJS 控件并将它们绑定到数据源。 在此示例中,网格和图表绑定到同一数据源。

运行 Electron 应用程序

像以前一样运行应用程序!

npm start


由于表格和图表绑定到相同的数据,因此您对网格所做的任何更改(如编辑单元格或排序列)都将自动应用于图表。

现在,请下载 WijmoJS ( https://www.grapecity.com.cn/download/?pid=54 ),享用 WijmoJS JavaScript 控件的 Electron 应用程序吧。
1020 次点击
所在节点    推广
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/535203

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX