Skip to content

Commit f7b2f70

Browse files
committed
init src
1 parent 6f3fbb0 commit f7b2f70

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+5579
-38
lines changed

.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["es2015", "stage-0"],
3+
"plugins": ["transform-runtime"]
4+
}

.gitignore

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,12 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
6-
# Runtime data
7-
pids
8-
*.pid
9-
*.seed
10-
11-
# Directory for instrumented libs generated by jscoverage/JSCover
12-
lib-cov
13-
14-
# Coverage directory used by tools like istanbul
15-
coverage
16-
17-
# nyc test coverage
18-
.nyc_output
19-
20-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21-
.grunt
22-
23-
# node-waf configuration
24-
.lock-wscript
25-
26-
# Compiled binary addons (http://nodejs.org/api/addons.html)
27-
build/Release
28-
29-
# Dependency directories
1+
.DS_Store
2+
app/dist/index.html
3+
app/dist/build.js
4+
builds
5+
builds/*
306
node_modules
31-
jspm_packages
32-
33-
# Optional npm cache directory
34-
.npm
35-
36-
# Optional REPL history
37-
.node_repl_history
7+
npm-debug.log
8+
npm-debug.log.*
9+
thumbs.db
10+
!.gitkeep
11+
build/
12+
dist/

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,65 @@
1-
# xcel
2-
一个基于 Electron 和 Vue 的 Excel 数据过滤工具——凹凸实验室出品 https://aotu.io/notes/2016/11/15/xcel/
1+
# XCel
2+
3+
> An ultimate excel data filter
4+
5+
## Build Setup
6+
7+
``` bash
8+
# install dependencies
9+
npm install
10+
11+
# serve with hot reload at localhost:9080
12+
npm run dev
13+
14+
# build electron app for production
15+
npm run build
16+
17+
# run webpack in production
18+
npm run pack
19+
```
20+
21+
More information can be found [here](https://simulatedgreg.gitbooks.io/electron-vue/content/docs/npm_scripts.html).
22+
23+
---
24+
25+
This project was generated from [electron-vue](https://github.com/SimulatedGREG/electron-vue) using [vue-cli](https://github.com/vuejs/vue-cli). Documentation about this project can be found [here](https://simulatedgreg.gitbooks.io/electron-vue/content/index.html).
26+
27+
## Initialize the project may encounter problems
28+
```
29+
ERROR in dlopen(/Users/**/Desktop/XCel/node_modules/node-sass/vendor/darwin-x64-48/binding.node, 1): no suitable image found. Did find:
30+
/Users/**/Desktop/XCel/node_modules/node-sass/vendor/darwin-x64-48/binding.node: truncated mach-o error: segment __TEXT extends to 1212416 which is past end of file 260668
31+
@ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-rewriter.js!./~/sass-loader!./~/vue-loader/lib/selector.js?type=style&index=0!./app/src/App.vue 4:14-240 13:2-17:4 14:20-246
32+
33+
```
34+
What fixed it for me was the following:
35+
```
36+
npm rebuild node-sass
37+
```
38+
39+
40+
## Speed up the installation of electron in China
41+
42+
### 临时方式
43+
44+
```
45+
DEBUG=* ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/" npm install electron
46+
```
47+
48+
加入DEBUG=*是为了查看调试信息,确认下载源是否替换成功。
49+
50+
### 永久方式
51+
52+
给环境变量文件(.zshrc/.bashrc)加入环境变量值(前者对应zsh,后者是bash,自己看情况)
53+
54+
```
55+
export ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/"
56+
```
57+
58+
另外某些情况下会出现安装包下载不完整导致electron安装失败的原因,可以尝试清除electron缓存。
59+
60+
缓存的默认地址在:
61+
62+
```
63+
$HOME/.electron
64+
```
65+
通过添加ELECTRON_CUSTOM_DIR可以自定义缓存目录,方法同上。

app/electron.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
'use strict'
2+
3+
const electron = require('electron')
4+
const path = require('path')
5+
const menuTemplate = require("./menuTemplate")
6+
const ipcMainSets = require("./ipcMainSets")
7+
// const config = require('../config');
8+
9+
const app = electron.app
10+
const BrowserWindow = electron.BrowserWindow
11+
const Menu = electron.Menu
12+
let mainWindow
13+
let backgroundWindow
14+
var windowBounds = {}
15+
16+
let config = {}
17+
if (process.env.NODE_ENV === 'development') {
18+
config = require('../config')
19+
config.mainUrl = `http://localhost:${config.port}`
20+
} else {
21+
config.devtron = false
22+
config.mainUrl = `file://${__dirname}/dist/index.html`
23+
}
24+
config.backUrl = `file://${__dirname}/dist/background/index.html`
25+
config.isDev = process.env.NODE_ENV === 'development'
26+
console.log("主进程pid:", process.pid)
27+
28+
function createMainWindow () {
29+
var win = new BrowserWindow({
30+
height: 850,
31+
width: 1280,
32+
minWidth: 1120,
33+
minHeight: 768,
34+
backgroundColor: "#f5f5f5",
35+
fullscreenable: false,
36+
frame: false,
37+
show: false
38+
})
39+
windowBounds = win.getBounds()
40+
win.loadURL(config.mainUrl)
41+
42+
if (config.isDev) {
43+
BrowserWindow.addDevToolsExtension(path.join(__dirname, '../node_modules/devtron'))
44+
45+
let installExtension = require('electron-devtools-installer')
46+
47+
installExtension.default(installExtension.VUEJS_DEVTOOLS)
48+
.then((name) => win.webContents.openDevTools())
49+
.catch((err) => console.log('An error occurred: ', err))
50+
}
51+
52+
win.on('closed', () => {
53+
console.log("触发 closed")
54+
mainWindow = null
55+
backgroundWindow = null
56+
// 在Mac中完全退出程序,而不会留在dock中
57+
app.quit()
58+
})
59+
60+
win.on('ready-to-show', () => {
61+
win.show()
62+
win.focus()
63+
})
64+
console.log('mainWindow opened')
65+
return win
66+
}
67+
68+
function createBackgroundWindow () {
69+
var win = new BrowserWindow({
70+
show: config.isDev
71+
})
72+
win.loadURL(config.backUrl)
73+
console.log("backgroundWindow opened")
74+
return win
75+
}
76+
77+
app.on('ready', () => {
78+
console.log("ready")
79+
mainWindow = createMainWindow()
80+
backgroundWindow = createBackgroundWindow()
81+
ipcMainSets(mainWindow, backgroundWindow)
82+
const menu = Menu.buildFromTemplate(menuTemplate)
83+
Menu.setApplicationMenu(menu)
84+
})
85+
86+
87+
88+
app.on('window-all-closed', () => {
89+
if (process.platform !== 'darwin') {
90+
app.quit()
91+
}
92+
})
93+
94+
// 当应用被激活时触发,常用于点击应用的 dock 图标的时候。
95+
// 现在取消保留在Dock中,完全退出
96+
app.on('activate', () => {
97+
if (mainWindow.isDestroyed()) {
98+
mainWindow = createMainWindow()
99+
backgroundWindow = createBackgroundWindow()
100+
}
101+
})

app/icons/icon.icns

119 KB
Binary file not shown.

app/icons/icon.ico

361 KB
Binary file not shown.

app/icons/icon.png

49.5 KB
Loading

app/ipcMainSets.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
const shortid = require('shortid')
2+
const xlsx = require('xlsx')
3+
const path = require('path')
4+
const electron = require('electron')
5+
const app = electron.app
6+
const BrowserWindow = electron.BrowserWindow
7+
const dialog = electron.dialog
8+
const ipcMain = electron.ipcMain
9+
let savePath = ''
10+
11+
shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$@')
12+
13+
module.exports = function(mainWindow, backgroundWindow) {
14+
15+
ipcMain.on("readFile-response", (event, arg) => {
16+
console.log("触发readFile-response")
17+
mainWindow.webContents.send("readFile-response", arg)
18+
})
19+
ipcMain.on("readFile-start", (event, arg) => {
20+
console.log("读取文件emit")
21+
savePath = getSavePath(arg.data.path)
22+
console.log(savePath)
23+
backgroundWindow.webContents.send("readFile-start", arg)
24+
})
25+
26+
ipcMain.on("generate-htmlstring-response", (event, arg) => {
27+
mainWindow.webContents.send("generate-htmlstring-response", arg)
28+
})
29+
30+
ipcMain.on("filter-response", (event, arg) => {
31+
mainWindow.webContents.send("filter-response", arg)
32+
})
33+
ipcMain.on("filter-start", (event, arg) => {
34+
backgroundWindow.webContents.send("filter-start", arg)
35+
})
36+
37+
ipcMain.on("changeTab-start", (event, arg) => {
38+
backgroundWindow.webContents.send("changeTab-start", arg)
39+
})
40+
41+
ipcMain.on("exportFile-response", (event, arg) => {
42+
mainWindow.webContents.send("exportFile-response", arg)
43+
})
44+
ipcMain.on("exportFile-start", (event, arg) => {
45+
backgroundWindow.webContents.send("exportFile-start", arg)
46+
})
47+
48+
ipcMain.on("delAllFilterTag-start", (event, arg) => {
49+
backgroundWindow.webContents.send("delAllFilterTag-start", arg)
50+
})
51+
52+
ipcMain.on("sync-openFile-dialog", (event, arg) => {
53+
dialog.showOpenDialog({
54+
title: "请选择Excel文件",
55+
filters: [{name: 'Excel File', extensions: ['xls', "xlsx"]}],
56+
properties: ["openFile"]
57+
}, function(arr) {
58+
if(arr !== undefined) {
59+
// arr 是一个文件路径 数组
60+
// console.log("event", event)
61+
// 正常触发
62+
if(event) {
63+
event.sender.send("open-file-response", arr[0])
64+
}
65+
// 通过 emit 触发(如快捷键)
66+
else {
67+
var mainWindow = BrowserWindow.fromId(1)
68+
if(mainWindow) {
69+
mainWindow.webContents.send("open-file-response", arr[0])
70+
}
71+
}
72+
}
73+
})
74+
})
75+
76+
ipcMain.on("sync-saveFile-dialog", (event, arg) => {
77+
console.log("sync-saveFile-dialog")
78+
dialog.showSaveDialog({
79+
title: "请选择保存路径",
80+
defaultPath: savePath,
81+
filters: [{
82+
name: "Excel",
83+
extensions: ["xlsx"]
84+
}]
85+
}, function(p) {
86+
if(p !== undefined) {
87+
xlsx.writeFile(arg.data, p)
88+
}
89+
// p 是用户输入的路径名
90+
console.log("p" , p);
91+
})
92+
})
93+
94+
95+
ipcMain.on("sync-alert-dialog", (event, arg) => {
96+
dialog.showMessageBox({
97+
type: "warning",
98+
buttons: ["确定"],
99+
defaultId: 0, // dialog 打开是默认选中哪个按钮
100+
title: arg.title || "xcel",
101+
message: arg.content || "",
102+
detail: arg.detail || ""
103+
})
104+
})
105+
106+
// 接受窗口的最小化、最大化、关闭 事件
107+
ipcMain.on("sync-close", (event, arg) => {
108+
mainWindow.close()
109+
})
110+
ipcMain.on("sync-maximize", (event, arg) => {
111+
if(mainWindow.isMaximized()){
112+
mainWindow.setBounds(windowBounds)
113+
}else{
114+
windowBounds = mainWindow.getBounds()
115+
mainWindow.maximize()
116+
}
117+
event.sender.send("send-isMax", mainWindow.isMaximized())
118+
})
119+
ipcMain.on("sync-minimize", (event, arg) => {
120+
if(!mainWindow.isMinimized()){
121+
mainWindow.minimize()
122+
console.log("可以最小化")
123+
}else{
124+
console.log("不可最小化,因为已经最小化了")
125+
}
126+
})
127+
}
128+
129+
function getSavePath(uPath) {
130+
var file = path.parse(uPath)
131+
return path.join(file.dir, file.name + '-' + shortid.generate() + file.ext)
132+
}

app/main.ejs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no">
6+
<title><%= htmlWebpackPlugin.options.title %></title>
7+
</head>
8+
<body style="display:block;">
9+
<div id="app"></div>
10+
<!-- webpack builds are automatically injected -->
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)