Skip to content

Commit

Permalink
init src
Browse files Browse the repository at this point in the history
  • Loading branch information
JChehe committed Nov 16, 2016
1 parent 6f3fbb0 commit f7b2f70
Show file tree
Hide file tree
Showing 64 changed files with 5,579 additions and 38 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["es2015", "stage-0"],
"plugins": ["transform-runtime"]
}
47 changes: 11 additions & 36 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
.DS_Store
app/dist/index.html
app/dist/build.js
builds
builds/*
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
npm-debug.log
npm-debug.log.*
thumbs.db
!.gitkeep
build/
dist/
67 changes: 65 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,65 @@
# xcel
一个基于 Electron 和 Vue 的 Excel 数据过滤工具——凹凸实验室出品 https://aotu.io/notes/2016/11/15/xcel/
# XCel

> An ultimate excel data filter
## Build Setup

``` bash
# install dependencies
npm install

# serve with hot reload at localhost:9080
npm run dev

# build electron app for production
npm run build

# run webpack in production
npm run pack
```

More information can be found [here](https://simulatedgreg.gitbooks.io/electron-vue/content/docs/npm_scripts.html).

---

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).

## Initialize the project may encounter problems
```
ERROR in dlopen(/Users/**/Desktop/XCel/node_modules/node-sass/vendor/darwin-x64-48/binding.node, 1): no suitable image found. Did find:
/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
@ ./~/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
```
What fixed it for me was the following:
```
npm rebuild node-sass
```


## Speed up the installation of electron in China

### 临时方式

```
DEBUG=* ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/" npm install electron
```

加入DEBUG=*是为了查看调试信息,确认下载源是否替换成功。

### 永久方式

给环境变量文件(.zshrc/.bashrc)加入环境变量值(前者对应zsh,后者是bash,自己看情况)

```
export ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/"
```

另外某些情况下会出现安装包下载不完整导致electron安装失败的原因,可以尝试清除electron缓存。

缓存的默认地址在:

```
$HOME/.electron
```
通过添加ELECTRON_CUSTOM_DIR可以自定义缓存目录,方法同上。
101 changes: 101 additions & 0 deletions app/electron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict'

const electron = require('electron')
const path = require('path')
const menuTemplate = require("./menuTemplate")
const ipcMainSets = require("./ipcMainSets")
// const config = require('../config');

const app = electron.app
const BrowserWindow = electron.BrowserWindow
const Menu = electron.Menu
let mainWindow
let backgroundWindow
var windowBounds = {}

let config = {}
if (process.env.NODE_ENV === 'development') {
config = require('../config')
config.mainUrl = `http://localhost:${config.port}`
} else {
config.devtron = false
config.mainUrl = `file://${__dirname}/dist/index.html`
}
config.backUrl = `file://${__dirname}/dist/background/index.html`
config.isDev = process.env.NODE_ENV === 'development'
console.log("主进程pid:", process.pid)

function createMainWindow () {
var win = new BrowserWindow({
height: 850,
width: 1280,
minWidth: 1120,
minHeight: 768,
backgroundColor: "#f5f5f5",
fullscreenable: false,
frame: false,
show: false
})
windowBounds = win.getBounds()
win.loadURL(config.mainUrl)

if (config.isDev) {
BrowserWindow.addDevToolsExtension(path.join(__dirname, '../node_modules/devtron'))

let installExtension = require('electron-devtools-installer')

installExtension.default(installExtension.VUEJS_DEVTOOLS)
.then((name) => win.webContents.openDevTools())
.catch((err) => console.log('An error occurred: ', err))
}

win.on('closed', () => {
console.log("触发 closed")
mainWindow = null
backgroundWindow = null
// 在Mac中完全退出程序,而不会留在dock中
app.quit()
})

win.on('ready-to-show', () => {
win.show()
win.focus()
})
console.log('mainWindow opened')
return win
}

function createBackgroundWindow () {
var win = new BrowserWindow({
show: config.isDev
})
win.loadURL(config.backUrl)
console.log("backgroundWindow opened")
return win
}

app.on('ready', () => {
console.log("ready")
mainWindow = createMainWindow()
backgroundWindow = createBackgroundWindow()
ipcMainSets(mainWindow, backgroundWindow)
const menu = Menu.buildFromTemplate(menuTemplate)
Menu.setApplicationMenu(menu)
})



app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})

// 当应用被激活时触发,常用于点击应用的 dock 图标的时候。
// 现在取消保留在Dock中,完全退出
app.on('activate', () => {
if (mainWindow.isDestroyed()) {
mainWindow = createMainWindow()
backgroundWindow = createBackgroundWindow()
}
})
Binary file added app/icons/icon.icns
Binary file not shown.
Binary file added app/icons/icon.ico
Binary file not shown.
Binary file added app/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
132 changes: 132 additions & 0 deletions app/ipcMainSets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
const shortid = require('shortid')
const xlsx = require('xlsx')
const path = require('path')
const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow
const dialog = electron.dialog
const ipcMain = electron.ipcMain
let savePath = ''

shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$@')

module.exports = function(mainWindow, backgroundWindow) {

ipcMain.on("readFile-response", (event, arg) => {
console.log("触发readFile-response")
mainWindow.webContents.send("readFile-response", arg)
})
ipcMain.on("readFile-start", (event, arg) => {
console.log("读取文件emit")
savePath = getSavePath(arg.data.path)
console.log(savePath)
backgroundWindow.webContents.send("readFile-start", arg)
})

ipcMain.on("generate-htmlstring-response", (event, arg) => {
mainWindow.webContents.send("generate-htmlstring-response", arg)
})

ipcMain.on("filter-response", (event, arg) => {
mainWindow.webContents.send("filter-response", arg)
})
ipcMain.on("filter-start", (event, arg) => {
backgroundWindow.webContents.send("filter-start", arg)
})

ipcMain.on("changeTab-start", (event, arg) => {
backgroundWindow.webContents.send("changeTab-start", arg)
})

ipcMain.on("exportFile-response", (event, arg) => {
mainWindow.webContents.send("exportFile-response", arg)
})
ipcMain.on("exportFile-start", (event, arg) => {
backgroundWindow.webContents.send("exportFile-start", arg)
})

ipcMain.on("delAllFilterTag-start", (event, arg) => {
backgroundWindow.webContents.send("delAllFilterTag-start", arg)
})

ipcMain.on("sync-openFile-dialog", (event, arg) => {
dialog.showOpenDialog({
title: "请选择Excel文件",
filters: [{name: 'Excel File', extensions: ['xls', "xlsx"]}],
properties: ["openFile"]
}, function(arr) {
if(arr !== undefined) {
// arr 是一个文件路径 数组
// console.log("event", event)
// 正常触发
if(event) {
event.sender.send("open-file-response", arr[0])
}
// 通过 emit 触发(如快捷键)
else {
var mainWindow = BrowserWindow.fromId(1)
if(mainWindow) {
mainWindow.webContents.send("open-file-response", arr[0])
}
}
}
})
})

ipcMain.on("sync-saveFile-dialog", (event, arg) => {
console.log("sync-saveFile-dialog")
dialog.showSaveDialog({
title: "请选择保存路径",
defaultPath: savePath,
filters: [{
name: "Excel",
extensions: ["xlsx"]
}]
}, function(p) {
if(p !== undefined) {
xlsx.writeFile(arg.data, p)
}
// p 是用户输入的路径名
console.log("p" , p);
})
})


ipcMain.on("sync-alert-dialog", (event, arg) => {
dialog.showMessageBox({
type: "warning",
buttons: ["确定"],
defaultId: 0, // dialog 打开是默认选中哪个按钮
title: arg.title || "xcel",
message: arg.content || "",
detail: arg.detail || ""
})
})

// 接受窗口的最小化、最大化、关闭 事件
ipcMain.on("sync-close", (event, arg) => {
mainWindow.close()
})
ipcMain.on("sync-maximize", (event, arg) => {
if(mainWindow.isMaximized()){
mainWindow.setBounds(windowBounds)
}else{
windowBounds = mainWindow.getBounds()
mainWindow.maximize()
}
event.sender.send("send-isMax", mainWindow.isMaximized())
})
ipcMain.on("sync-minimize", (event, arg) => {
if(!mainWindow.isMinimized()){
mainWindow.minimize()
console.log("可以最小化")
}else{
console.log("不可最小化,因为已经最小化了")
}
})
}

function getSavePath(uPath) {
var file = path.parse(uPath)
return path.join(file.dir, file.name + '-' + shortid.generate() + file.ext)
}
12 changes: 12 additions & 0 deletions app/main.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body style="display:block;">
<div id="app"></div>
<!-- webpack builds are automatically injected -->
</body>
</html>
Loading

0 comments on commit f7b2f70

Please sign in to comment.