├── .babelrc ├── .electron-vue ├── build.js ├── dev-client.js ├── dev-runner.js ├── webpack.main.config.js ├── webpack.renderer.config.js └── webpack.web.config.js ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .travis.yml ├── README.md ├── appveyor.yml ├── build └── icons │ └── icon.png ├── package-lock.json ├── package.json ├── src ├── index.ejs ├── main │ ├── index.dev.js │ └── index.js └── renderer │ ├── App.vue │ ├── assets │ └── less │ │ ├── common.less │ │ └── global.less │ ├── components │ ├── Aside.vue │ └── Header.vue │ ├── main.js │ ├── menu.js │ ├── pages │ ├── Home.vue │ └── menu │ │ ├── DetailList.vue │ │ └── Goods.vue │ ├── route.js │ ├── store │ ├── index.js │ └── modules │ │ └── index.js │ └── utils │ ├── axios.js │ ├── db.js │ ├── download.js │ ├── logger.js │ ├── settings.js │ ├── upgrade.js │ └── util.js ├── static └── .gitkeep └── verify_commit_msg.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "comments": false, 3 | "env": { 4 | "main": { 5 | "presets": [ 6 | ["env", { 7 | "targets": { "node": 7 } 8 | }], 9 | "stage-0" 10 | ] 11 | }, 12 | "renderer": { 13 | "presets": [ 14 | ["env", { 15 | "modules": false 16 | }], 17 | "stage-0" 18 | ] 19 | }, 20 | "web": { 21 | "presets": [ 22 | ["env", { 23 | "modules": false 24 | }], 25 | "stage-0" 26 | ] 27 | } 28 | }, 29 | "plugins": ["transform-runtime"] 30 | } 31 | -------------------------------------------------------------------------------- /.electron-vue/build.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | process.env.NODE_ENV = 'production' 4 | 5 | const { say } = require('cfonts') 6 | const chalk = require('chalk') 7 | const del = require('del') 8 | const { spawn } = require('child_process') 9 | const webpack = require('webpack') 10 | const Multispinner = require('multispinner') 11 | 12 | 13 | const mainConfig = require('./webpack.main.config') 14 | const rendererConfig = require('./webpack.renderer.config') 15 | const webConfig = require('./webpack.web.config') 16 | 17 | const doneLog = chalk.bgGreen.white(' DONE ') + ' ' 18 | const errorLog = chalk.bgRed.white(' ERROR ') + ' ' 19 | const okayLog = chalk.bgBlue.white(' OKAY ') + ' ' 20 | const isCI = process.env.CI || false 21 | 22 | if (process.env.BUILD_TARGET === 'clean') clean() 23 | else if (process.env.BUILD_TARGET === 'web') web() 24 | else build() 25 | 26 | function clean () { 27 | del.sync(['build/*', '!build/icons', '!build/icons/icon.*']) 28 | console.log(`\n${doneLog}\n`) 29 | process.exit() 30 | } 31 | 32 | function build () { 33 | greeting() 34 | 35 | del.sync(['dist/electron/*', '!.gitkeep']) 36 | 37 | const tasks = ['main', 'renderer'] 38 | const m = new Multispinner(tasks, { 39 | preText: 'building', 40 | postText: 'process' 41 | }) 42 | 43 | let results = '' 44 | 45 | m.on('success', () => { 46 | process.stdout.write('\x1B[2J\x1B[0f') 47 | console.log(`\n\n${results}`) 48 | console.log(`${okayLog}take it away ${chalk.yellow('`electron-builder`')}\n`) 49 | process.exit() 50 | }) 51 | 52 | pack(mainConfig).then(result => { 53 | results += result + '\n\n' 54 | m.success('main') 55 | }).catch(err => { 56 | m.error('main') 57 | console.log(`\n ${errorLog}failed to build main process`) 58 | console.error(`\n${err}\n`) 59 | process.exit(1) 60 | }) 61 | 62 | pack(rendererConfig).then(result => { 63 | results += result + '\n\n' 64 | m.success('renderer') 65 | }).catch(err => { 66 | m.error('renderer') 67 | console.log(`\n ${errorLog}failed to build renderer process`) 68 | console.error(`\n${err}\n`) 69 | process.exit(1) 70 | }) 71 | } 72 | 73 | function pack (config) { 74 | return new Promise((resolve, reject) => { 75 | webpack(config, (err, stats) => { 76 | if (err) reject(err.stack || err) 77 | else if (stats.hasErrors()) { 78 | let err = '' 79 | 80 | stats.toString({ 81 | chunks: false, 82 | colors: true 83 | }) 84 | .split(/\r?\n/) 85 | .forEach(line => { 86 | err += ` ${line}\n` 87 | }) 88 | 89 | reject(err) 90 | } else { 91 | resolve(stats.toString({ 92 | chunks: false, 93 | colors: true 94 | })) 95 | } 96 | }) 97 | }) 98 | } 99 | 100 | function web () { 101 | del.sync(['dist/web/*', '!.gitkeep']) 102 | webpack(webConfig, (err, stats) => { 103 | if (err || stats.hasErrors()) console.log(err) 104 | 105 | console.log(stats.toString({ 106 | chunks: false, 107 | colors: true 108 | })) 109 | 110 | process.exit() 111 | }) 112 | } 113 | 114 | function greeting () { 115 | const cols = process.stdout.columns 116 | let text = '' 117 | 118 | if (cols > 85) text = 'lets-build' 119 | else if (cols > 60) text = 'lets-|build' 120 | else text = false 121 | 122 | if (text && !isCI) { 123 | say(text, { 124 | colors: ['yellow'], 125 | font: 'simple3d', 126 | space: false 127 | }) 128 | } else console.log(chalk.yellow.bold('\n lets-build')) 129 | console.log() 130 | } 131 | -------------------------------------------------------------------------------- /.electron-vue/dev-client.js: -------------------------------------------------------------------------------- 1 | const hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') 2 | 3 | hotClient.subscribe(event => { 4 | /** 5 | * Reload browser when HTMLWebpackPlugin emits a new index.html 6 | * 7 | * Currently disabled until jantimon/html-webpack-plugin#680 is resolved. 8 | * https://github.com/SimulatedGREG/electron-vue/issues/437 9 | * https://github.com/jantimon/html-webpack-plugin/issues/680 10 | */ 11 | // if (event.action === 'reload') { 12 | // window.location.reload() 13 | // } 14 | 15 | /** 16 | * Notify `mainWindow` when `main` process is compiling, 17 | * giving notice for an expected reload of the `electron` process 18 | */ 19 | if (event.action === 'compiling') { 20 | document.body.innerHTML += ` 21 | 34 | 35 |
36 | Compiling Main Process... 37 |
38 | ` 39 | } 40 | }) 41 | -------------------------------------------------------------------------------- /.electron-vue/dev-runner.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const chalk = require('chalk') 4 | const electron = require('electron') 5 | const path = require('path') 6 | const { say } = require('cfonts') 7 | const { spawn } = require('child_process') 8 | const webpack = require('webpack') 9 | const WebpackDevServer = require('webpack-dev-server') 10 | const webpackHotMiddleware = require('webpack-hot-middleware') 11 | 12 | const mainConfig = require('./webpack.main.config') 13 | const rendererConfig = require('./webpack.renderer.config') 14 | 15 | let electronProcess = null 16 | let manualRestart = false 17 | let hotMiddleware 18 | 19 | function logStats (proc, data) { 20 | let log = '' 21 | 22 | log += chalk.yellow.bold(`┏ ${proc} Process ${new Array((19 - proc.length) + 1).join('-')}`) 23 | log += '\n\n' 24 | 25 | if (typeof data === 'object') { 26 | data.toString({ 27 | colors: true, 28 | chunks: false 29 | }).split(/\r?\n/).forEach(line => { 30 | log += ' ' + line + '\n' 31 | }) 32 | } else { 33 | log += ` ${data}\n` 34 | } 35 | 36 | log += '\n' + chalk.yellow.bold(`┗ ${new Array(28 + 1).join('-')}`) + '\n' 37 | 38 | console.log(log) 39 | } 40 | 41 | function startRenderer () { 42 | return new Promise((resolve, reject) => { 43 | rendererConfig.entry.renderer = [path.join(__dirname, 'dev-client')].concat(rendererConfig.entry.renderer) 44 | 45 | const compiler = webpack(rendererConfig) 46 | hotMiddleware = webpackHotMiddleware(compiler, { 47 | log: false, 48 | heartbeat: 2500 49 | }) 50 | 51 | compiler.plugin('compilation', compilation => { 52 | compilation.plugin('html-webpack-plugin-after-emit', (data, cb) => { 53 | hotMiddleware.publish({ action: 'reload' }) 54 | cb() 55 | }) 56 | }) 57 | 58 | compiler.plugin('done', stats => { 59 | logStats('Renderer', stats) 60 | }) 61 | 62 | const server = new WebpackDevServer( 63 | compiler, 64 | { 65 | contentBase: path.join(__dirname, '../'), 66 | quiet: true, 67 | before (app, ctx) { 68 | app.use(hotMiddleware) 69 | ctx.middleware.waitUntilValid(() => { 70 | resolve() 71 | }) 72 | } 73 | } 74 | ) 75 | 76 | server.listen(9080) 77 | }) 78 | } 79 | 80 | function startMain () { 81 | return new Promise((resolve, reject) => { 82 | mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main) 83 | 84 | const compiler = webpack(mainConfig) 85 | 86 | compiler.plugin('watch-run', (compilation, done) => { 87 | logStats('Main', chalk.white.bold('compiling...')) 88 | hotMiddleware.publish({ action: 'compiling' }) 89 | done() 90 | }) 91 | 92 | compiler.watch({}, (err, stats) => { 93 | if (err) { 94 | console.log(err) 95 | return 96 | } 97 | 98 | logStats('Main', stats) 99 | 100 | if (electronProcess && electronProcess.kill) { 101 | manualRestart = true 102 | process.kill(electronProcess.pid) 103 | electronProcess = null 104 | startElectron() 105 | 106 | setTimeout(() => { 107 | manualRestart = false 108 | }, 5000) 109 | } 110 | 111 | resolve() 112 | }) 113 | }) 114 | } 115 | 116 | function startElectron () { 117 | electronProcess = spawn(electron, ['--inspect=5858', '.']) 118 | 119 | electronProcess.stdout.on('data', data => { 120 | electronLog(data, 'blue') 121 | }) 122 | electronProcess.stderr.on('data', data => { 123 | electronLog(data, 'red') 124 | }) 125 | 126 | electronProcess.on('close', () => { 127 | if (!manualRestart) process.exit() 128 | }) 129 | } 130 | 131 | function electronLog (data, color) { 132 | let log = '' 133 | data = data.toString().split(/\r?\n/) 134 | data.forEach(line => { 135 | log += ` ${line}\n` 136 | }) 137 | if (/[0-9A-z]+/.test(log)) { 138 | console.log( 139 | chalk[color].bold('┏ Electron -------------------') + 140 | '\n\n' + 141 | log + 142 | chalk[color].bold('┗ ----------------------------') + 143 | '\n' 144 | ) 145 | } 146 | } 147 | 148 | function greeting () { 149 | const cols = process.stdout.columns 150 | let text = '' 151 | 152 | if (cols > 104) text = 'electron-vue' 153 | else if (cols > 76) text = 'electron-|vue' 154 | else text = false 155 | 156 | if (text) { 157 | say(text, { 158 | colors: ['yellow'], 159 | font: 'simple3d', 160 | space: false 161 | }) 162 | } else console.log(chalk.yellow.bold('\n electron-vue')) 163 | console.log(chalk.blue(' getting ready...') + '\n') 164 | } 165 | 166 | function init () { 167 | greeting() 168 | 169 | Promise.all([startRenderer(), startMain()]) 170 | .then(() => { 171 | startElectron() 172 | }) 173 | .catch(err => { 174 | console.error(err) 175 | }) 176 | } 177 | 178 | init() 179 | -------------------------------------------------------------------------------- /.electron-vue/webpack.main.config.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | process.env.BABEL_ENV = 'main' 4 | 5 | const path = require('path') 6 | const { dependencies } = require('../package.json') 7 | const webpack = require('webpack') 8 | 9 | const BabiliWebpackPlugin = require('babili-webpack-plugin') 10 | 11 | let mainConfig = { 12 | entry: { 13 | main: path.join(__dirname, '../src/main/index.js') 14 | }, 15 | externals: [ 16 | ...Object.keys(dependencies || {}) 17 | ], 18 | module: { 19 | rules: [ 20 | { 21 | test: /\.(js)$/, 22 | enforce: 'pre', 23 | exclude: /node_modules/, 24 | use: { 25 | loader: 'eslint-loader', 26 | options: { 27 | formatter: require('eslint-friendly-formatter') 28 | } 29 | } 30 | }, 31 | { 32 | test: /\.js$/, 33 | use: 'babel-loader', 34 | exclude: /node_modules/ 35 | }, 36 | { 37 | test: /\.node$/, 38 | use: 'node-loader' 39 | } 40 | ] 41 | }, 42 | node: { 43 | __dirname: process.env.NODE_ENV !== 'production', 44 | __filename: process.env.NODE_ENV !== 'production' 45 | }, 46 | output: { 47 | filename: '[name].js', 48 | libraryTarget: 'commonjs2', 49 | path: path.join(__dirname, '../dist/electron') 50 | }, 51 | plugins: [ 52 | new webpack.NoEmitOnErrorsPlugin() 53 | ], 54 | resolve: { 55 | extensions: ['.js', '.json', '.node'] 56 | }, 57 | target: 'electron-main' 58 | } 59 | 60 | /** 61 | * Adjust mainConfig for development settings 62 | */ 63 | if (process.env.NODE_ENV !== 'production') { 64 | mainConfig.plugins.push( 65 | new webpack.DefinePlugin({ 66 | '__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"` 67 | }) 68 | ) 69 | } 70 | 71 | /** 72 | * Adjust mainConfig for production settings 73 | */ 74 | if (process.env.NODE_ENV === 'production') { 75 | mainConfig.plugins.push( 76 | new BabiliWebpackPlugin(), 77 | new webpack.DefinePlugin({ 78 | 'process.env.NODE_ENV': '"production"' 79 | }) 80 | ) 81 | } 82 | 83 | module.exports = mainConfig 84 | -------------------------------------------------------------------------------- /.electron-vue/webpack.renderer.config.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | process.env.BABEL_ENV = 'renderer' 4 | 5 | const path = require('path') 6 | const { dependencies } = require('../package.json') 7 | const webpack = require('webpack') 8 | 9 | const BabiliWebpackPlugin = require('babili-webpack-plugin') 10 | const CopyWebpackPlugin = require('copy-webpack-plugin') 11 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 12 | const HtmlWebpackPlugin = require('html-webpack-plugin') 13 | 14 | /** 15 | * List of node_modules to include in webpack bundle 16 | * 17 | * Required for specific packages like Vue UI libraries 18 | * that provide pure *.vue files that need compiling 19 | * https://simulatedgreg.gitbooks.io/electron-vue/content/en/webpack-configurations.html#white-listing-externals 20 | */ 21 | let whiteListedModules = ['vue'] 22 | 23 | let rendererConfig = { 24 | devtool: '#cheap-module-eval-source-map', 25 | entry: { 26 | renderer: path.join(__dirname, '../src/renderer/main.js') 27 | }, 28 | externals: [ 29 | ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d)) 30 | ], 31 | module: { 32 | rules: [ 33 | { 34 | test: /\.(js|vue)$/, 35 | enforce: 'pre', 36 | exclude: /node_modules/, 37 | use: { 38 | loader: 'eslint-loader', 39 | options: { 40 | formatter: require('eslint-friendly-formatter') 41 | } 42 | } 43 | }, 44 | { 45 | test: /\.css$/, 46 | use: ExtractTextPlugin.extract({ 47 | fallback: 'style-loader', 48 | use: 'css-loader' 49 | }) 50 | }, 51 | { 52 | test: /\.less/, 53 | use: ExtractTextPlugin.extract({ 54 | fallback: 'style-loader', 55 | use: 'css-loader!less-loader' 56 | }) 57 | }, 58 | { 59 | test: /\.html$/, 60 | use: 'vue-html-loader' 61 | }, 62 | { 63 | test: /\.js$/, 64 | use: 'babel-loader', 65 | exclude: /node_modules/ 66 | }, 67 | { 68 | test: /\.node$/, 69 | use: 'node-loader' 70 | }, 71 | { 72 | test: /\.vue$/, 73 | use: { 74 | loader: 'vue-loader', 75 | options: { 76 | extractCSS: process.env.NODE_ENV === 'production', 77 | loaders: { 78 | sass: 'vue-style-loader!css-loader!less-loader?indentedSyntax=1', 79 | scss: 'vue-style-loader!css-loader!less-loader' 80 | } 81 | } 82 | } 83 | }, 84 | { 85 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 86 | use: { 87 | loader: 'url-loader', 88 | query: { 89 | limit: 10000, 90 | name: 'imgs/[name]--[folder].[ext]' 91 | } 92 | } 93 | }, 94 | { 95 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, 96 | loader: 'url-loader', 97 | options: { 98 | limit: 10000, 99 | name: 'media/[name]--[folder].[ext]' 100 | } 101 | }, 102 | { 103 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 104 | use: { 105 | loader: 'url-loader', 106 | query: { 107 | limit: 10000, 108 | name: 'fonts/[name]--[folder].[ext]' 109 | } 110 | } 111 | } 112 | ] 113 | }, 114 | node: { 115 | __dirname: process.env.NODE_ENV !== 'production', 116 | __filename: process.env.NODE_ENV !== 'production' 117 | }, 118 | plugins: [ 119 | new ExtractTextPlugin('styles.css'), 120 | new HtmlWebpackPlugin({ 121 | filename: 'index.html', 122 | template: path.resolve(__dirname, '../src/index.ejs'), 123 | minify: { 124 | collapseWhitespace: true, 125 | removeAttributeQuotes: true, 126 | removeComments: true 127 | }, 128 | nodeModules: process.env.NODE_ENV !== 'production' 129 | ? path.resolve(__dirname, '../node_modules') 130 | : false 131 | }), 132 | new webpack.HotModuleReplacementPlugin(), 133 | new webpack.NoEmitOnErrorsPlugin() 134 | ], 135 | output: { 136 | filename: '[name].js', 137 | libraryTarget: 'commonjs2', 138 | path: path.join(__dirname, '../dist/electron') 139 | }, 140 | resolve: { 141 | alias: { 142 | '@': path.join(__dirname, '../src/renderer'), 143 | 'vue$': 'vue/dist/vue.esm.js' 144 | }, 145 | extensions: ['.js', '.vue', '.json', '.css', '.node'] 146 | }, 147 | target: 'electron-renderer' 148 | } 149 | 150 | /** 151 | * Adjust rendererConfig for development settings 152 | */ 153 | if (process.env.NODE_ENV !== 'production') { 154 | rendererConfig.plugins.push( 155 | new webpack.DefinePlugin({ 156 | '__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"` 157 | }) 158 | ) 159 | } 160 | 161 | /** 162 | * Adjust rendererConfig for production settings 163 | */ 164 | if (process.env.NODE_ENV === 'production') { 165 | rendererConfig.devtool = '' 166 | 167 | rendererConfig.plugins.push( 168 | new BabiliWebpackPlugin(), 169 | new CopyWebpackPlugin([ 170 | { 171 | from: path.join(__dirname, '../static'), 172 | to: path.join(__dirname, '../dist/electron/static'), 173 | ignore: ['.*'] 174 | } 175 | ]), 176 | new webpack.DefinePlugin({ 177 | 'process.env.NODE_ENV': '"production"' 178 | }), 179 | new webpack.LoaderOptionsPlugin({ 180 | minimize: true 181 | }) 182 | ) 183 | } 184 | 185 | module.exports = rendererConfig 186 | -------------------------------------------------------------------------------- /.electron-vue/webpack.web.config.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | process.env.BABEL_ENV = 'web' 4 | 5 | const path = require('path') 6 | const webpack = require('webpack') 7 | 8 | const BabiliWebpackPlugin = require('babili-webpack-plugin') 9 | const CopyWebpackPlugin = require('copy-webpack-plugin') 10 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 11 | const HtmlWebpackPlugin = require('html-webpack-plugin') 12 | 13 | let webConfig = { 14 | devtool: '#cheap-module-eval-source-map', 15 | entry: { 16 | web: path.join(__dirname, '../src/renderer/main.js') 17 | }, 18 | module: { 19 | rules: [ 20 | { 21 | test: /\.(js|vue)$/, 22 | enforce: 'pre', 23 | exclude: /node_modules/, 24 | use: { 25 | loader: 'eslint-loader', 26 | options: { 27 | formatter: require('eslint-friendly-formatter') 28 | } 29 | } 30 | }, 31 | { 32 | test: /\.css$/, 33 | use: ExtractTextPlugin.extract({ 34 | fallback: 'style-loader', 35 | use: 'css-loader' 36 | }) 37 | }, 38 | { 39 | test: /\.less/, 40 | use: ExtractTextPlugin.extract({ 41 | fallback: 'style-loader', 42 | use: 'css-loader!less-loader' 43 | }) 44 | }, 45 | { 46 | test: /\.html$/, 47 | use: 'vue-html-loader' 48 | }, 49 | { 50 | test: /\.js$/, 51 | use: 'babel-loader', 52 | include: [ path.resolve(__dirname, '../src/renderer') ], 53 | exclude: /node_modules/ 54 | }, 55 | { 56 | test: /\.vue$/, 57 | use: { 58 | loader: 'vue-loader', 59 | options: { 60 | extractCSS: true, 61 | loaders: { 62 | sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1', 63 | scss: 'vue-style-loader!css-loader!sass-loader' 64 | } 65 | } 66 | } 67 | }, 68 | { 69 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 70 | use: { 71 | loader: 'url-loader', 72 | query: { 73 | limit: 10000, 74 | name: 'imgs/[name].[ext]' 75 | } 76 | } 77 | }, 78 | { 79 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 80 | use: { 81 | loader: 'url-loader', 82 | query: { 83 | limit: 10000, 84 | name: 'fonts/[name].[ext]' 85 | } 86 | } 87 | } 88 | ] 89 | }, 90 | plugins: [ 91 | new ExtractTextPlugin('styles.css'), 92 | new HtmlWebpackPlugin({ 93 | filename: 'index.html', 94 | template: path.resolve(__dirname, '../src/index.ejs'), 95 | minify: { 96 | collapseWhitespace: true, 97 | removeAttributeQuotes: true, 98 | removeComments: true 99 | }, 100 | nodeModules: false 101 | }), 102 | new webpack.DefinePlugin({ 103 | 'process.env.IS_WEB': 'true' 104 | }), 105 | new webpack.HotModuleReplacementPlugin(), 106 | new webpack.NoEmitOnErrorsPlugin() 107 | ], 108 | output: { 109 | filename: '[name].js', 110 | path: path.join(__dirname, '../dist/web') 111 | }, 112 | resolve: { 113 | alias: { 114 | '@': path.join(__dirname, '../src/renderer'), 115 | 'vue$': 'vue/dist/vue.esm.js' 116 | }, 117 | extensions: ['.js', '.vue', '.json', '.css'] 118 | }, 119 | target: 'web' 120 | } 121 | 122 | /** 123 | * Adjust webConfig for production settings 124 | */ 125 | if (process.env.NODE_ENV === 'production') { 126 | webConfig.devtool = '' 127 | 128 | webConfig.plugins.push( 129 | new BabiliWebpackPlugin(), 130 | new CopyWebpackPlugin([ 131 | { 132 | from: path.join(__dirname, '../static'), 133 | to: path.join(__dirname, '../dist/web/static'), 134 | ignore: ['.*'] 135 | } 136 | ]), 137 | new webpack.DefinePlugin({ 138 | 'process.env.NODE_ENV': '"production"' 139 | }), 140 | new webpack.LoaderOptionsPlugin({ 141 | minimize: true 142 | }) 143 | ) 144 | } 145 | 146 | module.exports = webConfig 147 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist/* 2 | build/* 3 | static/* 4 | node_modules/* -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parserOptions: { 4 | parser: 'babel-eslint', 5 | ecmaVersion: 6, 6 | sourceType: 'module', 7 | ecmaFeatures: { 'experimentalObjectRestSpread': true, 'modules': true } 8 | }, 9 | env: { 10 | browser: true, 11 | node: true, 12 | }, 13 | extends: [ 'plugin:vue/essential', 'eslint-config-egg' ], 14 | plugins: [ 15 | 'vue' 16 | ], 17 | rules: { 18 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', 19 | "vue/no-parsing-error": [ 2, { "x-invalid-end-tag": false } ], 20 | "linebreak-style": "off", 21 | }, 22 | }; 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | dist/electron/* 3 | dist/web/* 4 | build/* 5 | !build/icons 6 | node_modules/ 7 | npm-debug.log 8 | npm-debug.log.* 9 | thumbs.db 10 | !.gitkeep 11 | .idea/* 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | osx_image: xcode8.3 2 | sudo: required 3 | dist: trusty 4 | language: c 5 | matrix: 6 | include: 7 | - os: osx 8 | - os: linux 9 | env: CC=clang CXX=clang++ npm_config_clang=1 10 | compiler: clang 11 | cache: 12 | directories: 13 | - node_modules 14 | - "$HOME/.electron" 15 | - "$HOME/.cache" 16 | addons: 17 | apt: 18 | packages: 19 | - libgnome-keyring-dev 20 | - icnsutils 21 | before_install: 22 | - mkdir -p /tmp/git-lfs && curl -L https://github.com/github/git-lfs/releases/download/v1.2.1/git-lfs-$([ 23 | "$TRAVIS_OS_NAME" == "linux" ] && echo "linux" || echo "darwin")-amd64-1.2.1.tar.gz 24 | | tar -xz -C /tmp/git-lfs --strip-components 1 && /tmp/git-lfs/git-lfs pull 25 | - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils; fi 26 | install: 27 | - nvm install 7 28 | - curl -o- -L https://yarnpkg.com/install.sh | bash 29 | - source ~/.bashrc 30 | - npm install -g xvfb-maybe 31 | - yarn 32 | script: 33 | - yarn run build 34 | branches: 35 | only: 36 | - master 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # easy-invoices 2 | 3 | > An electron-vue sqlite3 project 4 | 5 | #### Build Setup 6 | 7 | ``` bash 8 | # 安装依赖 9 | npm install 10 | 11 | # 本地开发 12 | npm run dev 13 | 14 | # 本地打包(安装程序) 15 | npm run build 16 | 17 | # 本地打包(直接目录) 18 | npm run build:dir 19 | 20 | ``` 21 | 22 | --- 23 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 0.0.{build} 2 | 3 | branches: 4 | only: 5 | - master 6 | 7 | image: Visual Studio 2017 8 | platform: 9 | - x64 10 | 11 | cache: 12 | - node_modules 13 | - '%APPDATA%\npm-cache' 14 | - '%USERPROFILE%\.electron' 15 | - '%USERPROFILE%\AppData\Local\Yarn\cache' 16 | 17 | init: 18 | - git config --global core.autocrlf input 19 | 20 | install: 21 | - ps: Install-Product node 8 x64 22 | - yarn 23 | 24 | build_script: 25 | - yarn build:ci 26 | 27 | test: off 28 | -------------------------------------------------------------------------------- /build/icons/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CaanDoll/easy-invoices/8e7f686935ed4639ea015a00b9a0814ab0965984/build/icons/icon.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "easy-invoices", 3 | "version": "1.0.1", 4 | "author": "caandoll ", 5 | "description": "Easy invoicing system stand-alone desktop version,An electron-vue sqlite3 project", 6 | "license": "MIT", 7 | "main": "./dist/electron/main.js", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/CaanDoll/easy-invoices.git" 11 | }, 12 | "keywords": [ 13 | "electron", 14 | "electron-vue", 15 | "sqlite3" 16 | ], 17 | "scripts": { 18 | "build": "node .electron-vue/build.js && electron-builder", 19 | "build:ci": "node .electron-vue/build.js && electron-builder --publish always", 20 | "build:dir": "node .electron-vue/build.js && electron-builder --dir", 21 | "build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js", 22 | "build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js", 23 | "dev": "node .electron-vue/dev-runner.js", 24 | "lint": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter src", 25 | "lint:fix": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter --fix src", 26 | "pack": "npm run pack:main && npm run pack:renderer", 27 | "pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js", 28 | "pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js", 29 | "postinstall": "install-app-deps", 30 | "packageVersion": "echo $npm_package_version" 31 | }, 32 | "build": { 33 | "productName": "easy-invoices", 34 | "copyright": "caandoll", 35 | "appId": "org.caandoll.easy-invoices", 36 | "directories": { 37 | "output": "build" 38 | }, 39 | "files": [ 40 | "dist/electron/**/*" 41 | ], 42 | "dmg": { 43 | "contents": [ 44 | { 45 | "x": 410, 46 | "y": 150, 47 | "type": "link", 48 | "path": "/Applications" 49 | }, 50 | { 51 | "x": 130, 52 | "y": 150, 53 | "type": "file" 54 | } 55 | ] 56 | }, 57 | "mac": { 58 | "icon": "build/icons/icon.png" 59 | }, 60 | "win": { 61 | "icon": "build/icons/icon.png" 62 | }, 63 | "linux": { 64 | "icon": "build/icons/icon.png" 65 | }, 66 | "nsis": { 67 | "oneClick": false, 68 | "allowToChangeInstallationDirectory": true 69 | } 70 | }, 71 | "gitHooks": { 72 | "commit-msg": "node verify_commit_msg.js" 73 | }, 74 | "lint-staged": { 75 | "*.js": [ 76 | "eslint --fix", 77 | "git add" 78 | ] 79 | }, 80 | "dependencies": { 81 | "sqlite3": "^4.0.1" 82 | }, 83 | "devDependencies": { 84 | "axios": "^0.16.1", 85 | "babel-core": "^6.25.0", 86 | "babel-eslint": "^7.2.3", 87 | "babel-loader": "^7.1.5", 88 | "babel-plugin-transform-runtime": "^6.23.0", 89 | "babel-preset-env": "^1.6.0", 90 | "babel-preset-stage-0": "^6.24.1", 91 | "babel-register": "^6.24.1", 92 | "babili-webpack-plugin": "^0.1.2", 93 | "cfonts": "^1.1.3", 94 | "chalk": "^2.4.1", 95 | "copy-webpack-plugin": "^4.5.2", 96 | "cross-env": "^5.2.0", 97 | "css-loader": "^0.28.4", 98 | "dayjs": "^1.7.4", 99 | "del": "^3.0.0", 100 | "devtron": "^1.4.0", 101 | "electron": "^2.0.4", 102 | "electron-builder": "^20.20.4", 103 | "electron-debug": "^1.4.0", 104 | "electron-devtools-installer": "^2.2.0", 105 | "electron-settings": "^3.2.0", 106 | "electron-updater": "^2.23.3", 107 | "eslint": "^4.4.1", 108 | "eslint-config-egg": "^7.0.0", 109 | "eslint-friendly-formatter": "^3.0.0", 110 | "eslint-loader": "^1.9.0", 111 | "eslint-plugin-html": "^3.1.1", 112 | "eslint-plugin-vue": "^4.5.0", 113 | "extract-text-webpack-plugin": "^3.0.0", 114 | "file-loader": "^0.11.2", 115 | "fs-extra": "^6.0.1", 116 | "html-webpack-plugin": "^2.30.1", 117 | "iview": "^2.14.3", 118 | "less": "^3.7.1", 119 | "less-loader": "^4.1.0", 120 | "lint-staged": "^7.2.0", 121 | "multispinner": "^0.2.1", 122 | "node-loader": "^0.6.0", 123 | "node-xlsx": "^0.12.1", 124 | "style-loader": "^0.18.2", 125 | "url-loader": "^0.5.9", 126 | "vue": "^2.3.3", 127 | "vue-electron": "^1.0.6", 128 | "vue-html-loader": "^1.2.4", 129 | "vue-loader": "^13.0.5", 130 | "vue-router": "^2.5.3", 131 | "vue-style-loader": "^3.0.1", 132 | "vue-template-compiler": "^2.4.2", 133 | "vuex": "^2.3.1", 134 | "webpack": "^3.5.2", 135 | "webpack-dev-server": "^2.7.1", 136 | "webpack-hot-middleware": "^2.18.2", 137 | "yorkie": "^1.0.3" 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/index.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | easy-invoices 6 | <% if (htmlWebpackPlugin.options.nodeModules) { %> 7 | 8 | 11 | <% } %> 12 | 13 | 14 |
15 | 16 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/index.dev.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is used specifically and only for development. It installs 3 | * `electron-debug` & `vue-devtools`. There shouldn't be any need to 4 | * modify this file, but it can be used to extend your development 5 | * environment. 6 | */ 7 | 8 | /* eslint-disable */ 9 | 10 | // Set environment for development 11 | process.env.NODE_ENV = 'development' 12 | 13 | // Install `electron-debug` with `devtron` 14 | require('electron-debug')({ showDevTools: true }) 15 | 16 | // Install `vue-devtools` 17 | require('electron').app.on('ready', () => { 18 | let installExtension = require('electron-devtools-installer') 19 | installExtension.default(installExtension.VUEJS_DEVTOOLS) 20 | .then(() => {}) 21 | .catch(err => { 22 | console.log('Unable to install `vue-devtools`: \n', err) 23 | }) 24 | }) 25 | 26 | // Require `main` process to boot app 27 | require('./index') 28 | -------------------------------------------------------------------------------- /src/main/index.js: -------------------------------------------------------------------------------- 1 | import { app, BrowserWindow, ipcMain } from 'electron'; 2 | import { autoUpdater } from 'electron-updater'; 3 | 4 | /** 5 | * Set `__static` path to static files in production 6 | * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html 7 | */ 8 | if (process.env.NODE_ENV !== 'development') { 9 | global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\'); 10 | } 11 | 12 | let mainWindow; 13 | const winURL = process.env.NODE_ENV === 'development' 14 | ? 'http://localhost:9080' 15 | : `file://${__dirname}/index.html`; 16 | 17 | function createWindow() { 18 | /** 19 | * Initial window options 20 | */ 21 | mainWindow = new BrowserWindow({ 22 | frame: false, 23 | useContentSize: true, 24 | width: 1366, 25 | height: 768, 26 | minWidth: 800, 27 | minHeight: 600, 28 | show: false, 29 | }); 30 | 31 | mainWindow.loadURL(winURL); 32 | 33 | mainWindow.on('closed', () => { 34 | mainWindow = null; 35 | }); 36 | 37 | // 加载好html再呈现window,避免白屏 38 | mainWindow.on('ready-to-show', () => { 39 | mainWindow.show(); 40 | mainWindow.focus(); 41 | }); 42 | 43 | // mainWindow.webContents.openDevTools({ detach: true }); 44 | } 45 | 46 | app.on('ready', () => { 47 | if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdatesAndNotify(); 48 | // autoUpdater.checkForUpdatesAndNotify(); 49 | createWindow(); 50 | }); 51 | 52 | app.on('window-all-closed', () => { 53 | if (process.platform !== 'darwin') { 54 | app.quit(); 55 | } 56 | }); 57 | 58 | app.on('activate', () => { 59 | if (mainWindow === null) { 60 | createWindow(); 61 | } 62 | }); 63 | 64 | /** 65 | * 边框 66 | */ 67 | // 窗口最小化 68 | ipcMain.on('min-window', () => { 69 | mainWindow.minimize(); 70 | }); 71 | // 窗口最大化 72 | ipcMain.on('max-window', () => { 73 | if (mainWindow.isMaximized()) { 74 | mainWindow.restore(); 75 | } else { 76 | mainWindow.maximize(); 77 | } 78 | }); 79 | // 关闭 80 | ipcMain.on('close-window', () => { 81 | mainWindow.close(); 82 | }); 83 | 84 | /** 85 | * 导出下载 86 | */ 87 | ipcMain.on('download', (event, downloadPath) => { 88 | mainWindow.webContents.downloadURL(downloadPath); 89 | mainWindow.webContents.session.once('will-download', (event, item) => { 90 | item.once('done', (event, state) => { 91 | // 成功的话 state为completed 取消的话 state为cancelled 92 | mainWindow.webContents.send('downstate', state); 93 | }); 94 | }); 95 | }); 96 | 97 | 98 | /** 99 | * 自动更新 100 | */ 101 | 102 | function sendUpdateMessage(message, data) { 103 | mainWindow.webContents.send('update-message', { message, data }); 104 | } 105 | 106 | // 阻止程序关闭自动安装升级 107 | autoUpdater.autoInstallOnAppQuit = false; 108 | 109 | autoUpdater.on('error', data => { 110 | sendUpdateMessage('error', data); 111 | }); 112 | 113 | /* // 检查更新 114 | autoUpdater.on('checking-for-update', data => { 115 | sendUpdateMessage('checking-for-update', data); 116 | });*/ 117 | 118 | // 有可用更新 119 | autoUpdater.on('update-available', data => { 120 | sendUpdateMessage('update-available', data); 121 | }); 122 | 123 | // 已经最新 124 | autoUpdater.on('update-not-available', data => { 125 | sendUpdateMessage('update-not-available', data); 126 | }); 127 | 128 | // 更新下载进度事件 129 | autoUpdater.on('download-progress', data => { 130 | sendUpdateMessage('download-progress', data); 131 | }); 132 | // 更新下载完成事件(event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) 133 | autoUpdater.on('update-downloaded', () => { 134 | sendUpdateMessage('update-downloaded', {}); 135 | ipcMain.once('update-now', () => { 136 | autoUpdater.quitAndInstall(); 137 | }); 138 | }); 139 | -------------------------------------------------------------------------------- /src/renderer/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 10 | 11 | 82 | -------------------------------------------------------------------------------- /src/renderer/assets/less/common.less: -------------------------------------------------------------------------------- 1 | .clearfix { 2 | &::after { 3 | display: block; 4 | height: 0; 5 | content: ''; 6 | clear: both; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/renderer/assets/less/global.less: -------------------------------------------------------------------------------- 1 | @view-left: 50px; 2 | @view-top: 30px; 3 | @view-padding: 10px; 4 | 5 | @bg-color:#ddd; 6 | @header-color:#e9eaec; 7 | @aside-color:#495060; -------------------------------------------------------------------------------- /src/renderer/components/Aside.vue: -------------------------------------------------------------------------------- 1 | 41 | 42 | 91 | 92 | 146 | -------------------------------------------------------------------------------- /src/renderer/components/Header.vue: -------------------------------------------------------------------------------- 1 | 33 | 34 | 86 | 179 | -------------------------------------------------------------------------------- /src/renderer/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import VueRouter from 'vue-router'; 3 | import iView from 'iview'; 4 | import routes from './route'; 5 | import store from './store'; 6 | import filters from './utils/util'; 7 | import db from './utils/db'; 8 | import logger from './utils/logger'; 9 | import 'iview/dist/styles/iview.css'; 10 | import './assets/less/common.less'; 11 | import App from './App.vue'; 12 | // 升级脚本 13 | import './utils/upgrade'; 14 | 15 | Vue.use(VueRouter); 16 | 17 | Vue.use(iView); 18 | 19 | Object.keys(filters).forEach(k => Vue.filter(k, filters[ k ])); 20 | 21 | const router = new VueRouter({ 22 | routes, 23 | }); 24 | 25 | Vue.prototype.$db = db; 26 | 27 | Vue.prototype.$logger = logger; 28 | 29 | if (!process.env.IS_WEB) Vue.use(require('vue-electron')); 30 | Vue.config.productionTip = false; 31 | 32 | /* eslint-disable no-new */ 33 | new Vue({ 34 | el: '#app', 35 | router, 36 | store, 37 | render: h => h(App), 38 | }); 39 | -------------------------------------------------------------------------------- /src/renderer/menu.js: -------------------------------------------------------------------------------- 1 | import Goods from './pages/menu/Goods.vue'; 2 | import DetailList from './pages/menu/DetailList.vue'; 3 | 4 | const menu = [ 5 | { 6 | icon: 'cube', 7 | title: '物品管理', 8 | path: '/goods', 9 | component: Goods, 10 | }, 11 | { 12 | icon: 'clipboard', 13 | title: '进出明细', 14 | path: '/detailList', 15 | component: DetailList, 16 | }, 17 | ]; 18 | export default menu; 19 | -------------------------------------------------------------------------------- /src/renderer/pages/Home.vue: -------------------------------------------------------------------------------- 1 | 10 | 24 | 56 | -------------------------------------------------------------------------------- /src/renderer/pages/menu/DetailList.vue: -------------------------------------------------------------------------------- 1 | 93 | 659 | 661 | -------------------------------------------------------------------------------- /src/renderer/pages/menu/Goods.vue: -------------------------------------------------------------------------------- 1 | 88 | 620 | 622 | -------------------------------------------------------------------------------- /src/renderer/route.js: -------------------------------------------------------------------------------- 1 | import Home from './pages/Home'; 2 | import menus from './menu'; 3 | 4 | const childrenRoutes = []; 5 | 6 | for (const menu of menus) { 7 | childrenRoutes.push(menu); 8 | } 9 | 10 | childrenRoutes.push({ 11 | path: '*', 12 | redirect: menus[ 0 ].path, 13 | }); 14 | 15 | const routes = [ 16 | { 17 | path: '/', 18 | component: Home, 19 | children: childrenRoutes, 20 | }, 21 | ]; 22 | 23 | export default routes; 24 | -------------------------------------------------------------------------------- /src/renderer/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Vuex from 'vuex'; 3 | 4 | import modules from './modules'; 5 | 6 | Vue.use(Vuex); 7 | 8 | export default new Vuex.Store({ 9 | modules, 10 | strict: process.env.NODE_ENV !== 'production', 11 | }); 12 | -------------------------------------------------------------------------------- /src/renderer/store/modules/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The file enables `@/store/index.js` to import all vuex modules 3 | * in a one-shot manner. There should not be any reason to edit this file. 4 | */ 5 | 6 | const files = require.context('.', false, /\.js$/); 7 | const modules = {}; 8 | 9 | files.keys().forEach(key => { 10 | if (key === './index.js') return; 11 | modules[key.replace(/(\.\/|\.js)/g, '')] = files(key).default; 12 | }); 13 | 14 | export default modules; 15 | -------------------------------------------------------------------------------- /src/renderer/utils/axios.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | import iview from 'iview'; 3 | 4 | export const _back_public = axios.create({ 5 | baseURL: '/back-public', 6 | }); 7 | 8 | export const _back_api = axios.create({ 9 | baseURL: '/back-api', 10 | }); 11 | 12 | export const _api = axios.create({}); 13 | 14 | _back_public.interceptors.request.use(reqSuccess, reqError); 15 | _back_public.interceptors.response.use(resSuccess, resError); 16 | 17 | _back_api.interceptors.request.use(reqSuccess, reqError); 18 | _back_api.interceptors.response.use(resSuccess, resError); 19 | 20 | function reqSuccess(config) { 21 | config.headers.token = localStorage.getItem('token') || ''; 22 | return config; 23 | } 24 | 25 | function reqError(error) { 26 | return Promise.reject(error); 27 | } 28 | 29 | function resSuccess(response) { 30 | const token = response.headers.token; 31 | if (token) { 32 | localStorage.token = token; 33 | } 34 | return response; 35 | } 36 | 37 | function resError(error) { 38 | if (error.response.status === 401) { 39 | window.location.hash = '/login?reason=expired'; 40 | } else if (String(error.response.status)[0] === '5') { 41 | iview.Message.error('服务器内部错误'); 42 | } 43 | return Promise.reject(error); 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/renderer/utils/db.js: -------------------------------------------------------------------------------- 1 | import fse from 'fs-extra'; 2 | import path from 'path'; 3 | import sq3 from 'sqlite3'; 4 | import logger from './logger'; 5 | import { docDir } from './settings'; 6 | // 将数据存至系统用户目录,防止用户误删程序 7 | export const dbPath = path.join(docDir, 'data.sqlite3'); 8 | fse.ensureFileSync(dbPath); 9 | 10 | const sqlite3 = sq3.verbose(); 11 | const db = new sqlite3.Database(dbPath); 12 | db.serialize(() => { 13 | /** 14 | * 物品表 GOODS 15 | * name 品名 16 | * standard_buy_unit_price 标准进价 17 | * standard_sell_unit_price 标准售价 18 | * total_amount 总金额 19 | * total_count 总数量 20 | * remark 备注 21 | * create_time 创建时间 22 | * update_time 修改时间 23 | */ 24 | db.run(`CREATE TABLE GOODS( 25 | id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 26 | name VARCHAR(255) NOT NULL, 27 | standard_buy_unit_price DECIMAL(15,2) NOT NULL, 28 | standard_sell_unit_price DECIMAL(15,2) NOT NULL, 29 | total_amount DECIMAL(15,2) NOT NULL, 30 | total_count DECIMAL(15,3) NOT NULL, 31 | remark VARCHAR(255) NOT NULL, 32 | create_time INTEGER NOT NULL, 33 | update_time INTEGER NOT NULL 34 | )`, err => { 35 | logger(err); 36 | }); 37 | 38 | /** 39 | * 进出明细表 GOODS_DETAIL_LIST 40 | * goods_id 物品id 41 | * count 计数(+加 -减) 42 | * actual_buy_unit_price 实际进价 43 | * actual_sell_unit_price 实际售价 44 | * amount 实际金额 45 | * remark 备注 46 | * latest 是否某物品最新一条记录(不是最新操作无法删除)(1是 0不是) 47 | * create_time 创建时间 48 | * update_time 修改时间 49 | */ 50 | db.run(`CREATE TABLE GOODS_DETAIL_LIST( 51 | id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 52 | goods_id INTEGER NOT NULL, 53 | count DECIMAL(15,3) NOT NULL, 54 | actual_sell_unit_price DECIMAL(15,2) NOT NULL, 55 | actual_buy_unit_price DECIMAL(15,2) NOT NULL, 56 | amount DECIMAL(15,2) NOT NULL, 57 | remark VARCHAR(255) NOT NULL, 58 | latest INTEGER NOT NULL, 59 | create_time INTEGER NOT NULL, 60 | update_time INTEGER NOT NULL, 61 | FOREIGN KEY (goods_id) REFERENCES GOODS(id) 62 | )`, err => { 63 | logger(err); 64 | }); 65 | }); 66 | 67 | export default db; 68 | -------------------------------------------------------------------------------- /src/renderer/utils/download.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import fse from 'fs-extra'; 3 | import xlsx from 'node-xlsx'; 4 | import path from 'path'; 5 | import os from 'os'; 6 | import day from 'dayjs'; 7 | import { ipcRenderer } from 'electron'; 8 | import logger from './logger'; 9 | 10 | const tmpPath = path.join(os.tmpdir(), 'easy-invoices'); 11 | fse.ensureDirSync(tmpPath); 12 | /** 13 | * 导出excel 14 | * @param {String} filename 文件名 15 | * @param {Object} excelOption 表格配置([{name:,data:}]) 16 | * @return {Promise} 导出回调 17 | */ 18 | const excel = (filename, excelOption) => { 19 | return new Promise((resolve, reject) => { 20 | const buffer = xlsx.build(excelOption); 21 | const fileName = `${day().format('YYYY-MM-DD_HH-mm-ss')}_${filename}.xlsx`; 22 | const filePath = path.join(tmpPath, fileName); 23 | logger('tmp:' + filePath); 24 | fs.writeFileSync(filePath, buffer); 25 | ipcRenderer.send('download', filePath); 26 | ipcRenderer.once('downstate', (event, arg) => { 27 | if (arg === 'completed' || arg === 'cancelled') { 28 | resolve(arg); 29 | } else { 30 | reject(arg); 31 | } 32 | fse.remove(filePath); 33 | }); 34 | }); 35 | }; 36 | 37 | export default { 38 | excel, 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /src/renderer/utils/logger.js: -------------------------------------------------------------------------------- 1 | const log = msg => { 2 | if (process.env.NODE_ENV === 'development') { 3 | console.log(msg); 4 | } 5 | }; 6 | 7 | export default log; 8 | -------------------------------------------------------------------------------- /src/renderer/utils/settings.js: -------------------------------------------------------------------------------- 1 | import settings from 'electron-settings'; 2 | import fse from 'fs-extra'; 3 | import path from 'path'; 4 | import os from 'os'; 5 | 6 | export const docDir = path.join(os.homedir(), 'easy-invoices'); 7 | const settingsPath = path.join(docDir, 'settings.json'); 8 | fse.ensureFileSync(settingsPath); 9 | 10 | settings.setPath(settingsPath); 11 | 12 | export default settings; 13 | -------------------------------------------------------------------------------- /src/renderer/utils/upgrade.js: -------------------------------------------------------------------------------- 1 | import settings from './settings'; 2 | import packageJson from '../../../package.json'; 3 | // 程序当前版本 4 | const appCurrentVersion = packageJson.version; 5 | 6 | /* 7 | import db from './db'; 8 | 9 | // 罗列增量升级脚本 10 | const incrementalUpgrade = { 11 | '1.0.1':()=>{ 12 | db.run(); 13 | }, 14 | '1.0.2':()=>{ 15 | db.run(); 16 | }, 17 | } 18 | 19 | // 升级前版本 20 | const beforeUpgradeVersion = settings.get('version'); 21 | // 寻找执行的脚本 增量执行 22 | */ 23 | 24 | // 升级完成 25 | settings.set('version', appCurrentVersion); 26 | -------------------------------------------------------------------------------- /src/renderer/utils/util.js: -------------------------------------------------------------------------------- 1 | exports.dateFilter = value => { 2 | if (value) { 3 | const d = new Date(parseInt(value)); 4 | const date = { 5 | Y: d.getFullYear(), 6 | M: d.getMonth() > 8 ? (d.getMonth() + 1) : '0' + (d.getMonth() + 1), 7 | D: d.getDate() > 9 ? d.getDate() : '0' + d.getDate(), 8 | h: d.getHours() > 9 ? d.getHours() : '0' + d.getHours(), 9 | m: d.getMinutes() > 9 ? d.getMinutes() : '0' + d.getMinutes(), 10 | s: d.getSeconds() > 9 ? d.getSeconds() : '0' + d.getSeconds(), 11 | }; 12 | const t = date.Y + '-' + date.M + '-' + date.D + ' ' + date.h + ':' + date.m + ':' + date.s; 13 | return t; 14 | } 15 | return ''; 16 | }; 17 | 18 | exports.getRegexp = type => { 19 | switch (type) { 20 | case 'money': 21 | return /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/; 22 | default: 23 | return null; 24 | } 25 | }; 26 | 27 | exports.getDatePickerOpt = () => { 28 | return { 29 | disabledDate: date => { 30 | return date.valueOf() > Date.now(); 31 | }, 32 | }; 33 | }; 34 | -------------------------------------------------------------------------------- /static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CaanDoll/easy-invoices/8e7f686935ed4639ea015a00b9a0814ab0965984/static/.gitkeep -------------------------------------------------------------------------------- /verify_commit_msg.js: -------------------------------------------------------------------------------- 1 | 2 | const chalk = require('chalk'); 3 | const msgPath = process.env.GIT_PARAMS; 4 | const msg = require('fs').readFileSync(msgPath, 'utf-8').trim(); 5 | 6 | const commitRE = /^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|ci|chore|types)(\(.+\))?: .{1,50}/; 7 | 8 | if (!commitRE.test(msg)) { 9 | console.log(); 10 | console.error( 11 | ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red('invalid commit message format.')}\n\n` + 12 | chalk.red(' Proper commit message format is required for automated changelog generation. Examples:\n\n') + 13 | ` ${chalk.green('feat(compiler): add \'comments\' option')}\n` + 14 | ` ${chalk.green('fix(v-model): handle events on blur (close #28)')}\n\n` + 15 | chalk.red(' See .README.md for more details.\n') + 16 | chalk.red(` You can also use ${chalk.cyan('npm run commit')} to interactively generate a commit message.\n`) 17 | ); 18 | process.exit(1); 19 | } 20 | --------------------------------------------------------------------------------