Skip to content

Commit 36ba7a7

Browse files
committed
完成markdown文档, 自动登录数据库, 提示文件已存在
1 parent cf0a9b6 commit 36ba7a7

14 files changed

Lines changed: 447 additions & 58 deletions

File tree

favicon.ico

264 KB
Binary file not shown.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "easycode-javascript",
3-
"version": "0.1.0",
3+
"version": "1.0.0",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",
@@ -17,7 +17,9 @@
1717
"ejs": "^3.1.5",
1818
"electron-localstorage": "^1.0.5",
1919
"element-ui": "^2.13.2",
20+
"github-markdown-css": "^4.0.0",
2021
"lodash": "^4.17.20",
22+
"marked": "^1.2.2",
2123
"mysql2": "^2.2.5",
2224
"uuid": "^8.3.1",
2325
"vue": "^2.6.11",

src/api.js

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ejs from 'ejs'
55
import { v4 as uuidv4 } from 'uuid'
66
import { exec } from 'child_process'
77
import localstorage from 'electron-localstorage'
8+
import path from 'path'
89

910
function queryAllTables (connection, db) {
1011
return new Promise((resolve, reject) => {
@@ -76,12 +77,35 @@ export default function (win, renderer) {
7677
})
7778
})
7879

80+
ipcMain.on('localTemplateFile', () => {
81+
const folder = path.join(__dirname, '../static/ejs/')
82+
fs.access(folder, err => {
83+
if (!err) {
84+
fs.readdir(folder, (err, fileList) => {
85+
if (!err) {
86+
renderer.send('localTemplateFile', fileList.map(v => ({
87+
title: v,
88+
value: folder + v
89+
})))
90+
}
91+
})
92+
}
93+
})
94+
})
95+
7996
ipcMain.on('connectToTheDatabase', (e, data) => {
8097
try {
98+
delete data.tryConnection
8199
connection = mysql.createConnection(data)
82-
win.webContents.send('connection.success')
100+
connection.ping((err) => {
101+
if (err) {
102+
win.webContents.send('connection.failed', { msg: '请启动mysql服务!' + err.message })
103+
} else {
104+
win.webContents.send('connection.success')
105+
}
106+
})
83107
} catch (err) {
84-
win.webContents.send('connection.failed', err)
108+
win.webContents.send('connection.failed', { msg: err.message })
85109
}
86110
})
87111

@@ -166,11 +190,12 @@ export default function (win, renderer) {
166190
ipcMain.on('generateCustomFiles', (e, data) => {
167191
// 使用固定文件位置
168192
const setting = localstorage.getItem('setting')
193+
const name = data.name || uuidv4()
169194
let filepath
170195
if (setting && setting.fileGenerationDirectory) {
171-
filepath = setting.fileGenerationDirectory + '\\' + uuidv4() + '.' + data.suffix
196+
filepath = setting.fileGenerationDirectory + '\\' + name + '.' + data.suffix
172197
} else {
173-
filepath = app.getPath('userData') + '\\files\\' + uuidv4() + '.' + data.suffix
198+
filepath = app.getPath('userData') + '\\' + name + '.' + data.suffix
174199
}
175200
ejs.renderFile(data.templateName, data, (err, str) => {
176201
if (err) {
@@ -179,11 +204,11 @@ export default function (win, renderer) {
179204
msg: 'err: ' + err.message
180205
})
181206
} else {
182-
fs.writeFile(filepath, str, { flag: 'a' }, (err, datas) => {
207+
// flag: a 不存在该文件则会创建该文件
208+
fs.writeFile(filepath, str, { flag: 'ax' }, (err, datas) => {
183209
if (err) {
184210
renderer.send('generateCustomFiles', {
185-
code: -1,
186-
msg: 'err: ' + err.message
211+
code: err.code
187212
})
188213
} else {
189214
renderer.send('generateCustomFiles', {
@@ -257,4 +282,28 @@ export default function (win, renderer) {
257282
ipcMain.on('getSetting', () => {
258283
renderer.send('getSetting', localstorage.getItem('setting'))
259284
})
285+
286+
// 保存数据源
287+
ipcMain.on('saveDataSource', (e, json) => {
288+
localstorage.setItem('dataSource', json)
289+
})
290+
291+
// 取出数据源
292+
ipcMain.on('getDataSource', () => {
293+
renderer.send('getDataSource', localstorage.getItem('dataSource'))
294+
})
295+
296+
// 查询文档
297+
ipcMain.on('consultYourDocumentation', (e, id) => {
298+
const file = path.join(__dirname, '../static/document', id)
299+
fs.access(file, err => {
300+
if (!err) {
301+
fs.readFile(file, 'utf8', (err, data) => {
302+
if (!err) {
303+
renderer.send('consultYourDocumentation', data)
304+
}
305+
})
306+
}
307+
})
308+
})
260309
}

src/background.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
import { app, protocol, BrowserWindow, Menu } from 'electron'
3+
import { app, protocol, BrowserWindow, Menu, shell } from 'electron'
44
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
55
import api from './api'
66
// import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
@@ -85,7 +85,7 @@ app.on('ready', async () => {
8585
}
8686
const template = [
8787
{
88-
label: '&connection',
88+
label: '&Connection',
8989
submenu: [
9090
{
9191
label: '连接数据库',
@@ -102,6 +102,22 @@ app.on('ready', async () => {
102102
}
103103
}
104104
]
105+
},
106+
{
107+
label: '&About',
108+
submenu: [
109+
{
110+
label: '前端CRUD',
111+
submenu: [
112+
{
113+
label: '使用手册',
114+
click () {
115+
win.webContents.send('about', { id: 'frontCRUD.md', title: '前端CRUD手册' })
116+
}
117+
}
118+
]
119+
}
120+
]
105121
}
106122
]
107123

src/router/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const routes = [
1919
}
2020
]
2121
},
22+
{
23+
path: '/DocumentText',
24+
component: () => import('@/views/DocumentText')
25+
},
2226
{
2327
path: '/about',
2428
name: 'About',

src/store/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ Vue.use(Vuex)
55

66
export default new Vuex.Store({
77
state: {
8+
// 是否连接数据库
9+
connection: false
810
},
911
mutations: {
12+
setConnection (state, bool) {
13+
state.connection = bool
14+
}
1015
},
11-
actions: {
16+
getters: {
17+
connection: state => state.connection
1218
},
13-
modules: {
14-
}
19+
actions: {},
20+
modules: {}
1521
})

src/style/reset.css

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,48 @@ table {
6161
color: #409EFF;
6262
cursor: pointer;
6363
}
64+
65+
::-webkit-scrollbar-track {
66+
border-radius: 10px;
67+
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0);
68+
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0);
69+
}
70+
71+
::-webkit-scrollbar-thumb {
72+
background-color: rgba(0, 0, 0, 0.05);
73+
border-radius: 10px;
74+
box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.1);
75+
-webkit-box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.1);
76+
}
77+
78+
::-webkit-scrollbar-thumb {
79+
background-color: rgba(0, 0, 0, 0.2);
80+
border-radius: 10px;
81+
box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.1);
82+
-webkit-box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.1);
83+
}
84+
85+
::-webkit-scrollbar {
86+
width: 16px;
87+
height: 16px;
88+
}
89+
90+
::-webkit-scrollbar-track,
91+
::-webkit-scrollbar-thumb {
92+
border-radius: 999px;
93+
border: 5px solid transparent;
94+
}
95+
96+
::-webkit-scrollbar-track {
97+
box-shadow: 1px 1px 5px rgba(144, 146, 152, 0.3) inset;
98+
}
99+
100+
::-webkit-scrollbar-thumb {
101+
min-height: 20px;
102+
background-clip: content-box;
103+
box-shadow: 0 0 0 5px rgba(144, 146, 152, 0.3) inset;
104+
}
105+
106+
::-webkit-scrollbar-corner {
107+
background: transparent;
108+
}

0 commit comments

Comments
 (0)