张恒

删除已经过时的api调用方法,修改封装ipc错误

1 +import { ipcMain, dialog } from 'electron'
1 export default { 2 export default {
2 - Mainfunc (ipc, mainWindow, IsUseSysTitle) { 3 + Mainfunc (mainWindow, IsUseSysTitle) {
3 - ipc.on('IsUseSysTitle', (event) => { 4 + ipcMain.on('IsUseSysTitle', (event) => {
4 const data = IsUseSysTitle 5 const data = IsUseSysTitle
5 event.reply('CisUseSysTitle', data) 6 event.reply('CisUseSysTitle', data)
6 }) 7 })
7 - ipc.on('windows-mini', () => { 8 + ipcMain.on('windows-mini', () => {
8 mainWindow.minimize() 9 mainWindow.minimize()
9 }) 10 })
10 - ipc.on('window-max', (event) => { 11 + ipcMain.on('window-max', (event) => {
11 if (mainWindow.isMaximized()) { 12 if (mainWindow.isMaximized()) {
12 event.reply('window-confirm', false) 13 event.reply('window-confirm', false)
13 mainWindow.restore() 14 mainWindow.restore()
...@@ -16,8 +17,25 @@ export default { ...@@ -16,8 +17,25 @@ export default {
16 mainWindow.maximize() 17 mainWindow.maximize()
17 } 18 }
18 }) 19 })
19 - ipc.on('window-close', () => { 20 + ipcMain.on('window-close', () => {
20 mainWindow.close() 21 mainWindow.close()
21 }) 22 })
23 + ipcMain.on('open-messagebox', (event, arg) => {
24 + dialog.showMessageBox(mainWindow, {
25 + type: arg.type || 'info',
26 + title: arg.title || '',
27 + buttons: arg.buttons || [],
28 + message: arg.message || '',
29 + noLink: arg.noLink || true
30 + }).then(res => {
31 + event.reply('confirm-message', res)
32 + })
33 + })
34 + ipcMain.on('open-errorbox', (event, arg) => {
35 + dialog.showErrorBox(
36 + arg.title,
37 + arg.message
38 + )
39 + })
22 } 40 }
23 } 41 }
......
1 -import { BrowserWindow, Menu, ipcMain } from 'electron' 1 +import { BrowserWindow, Menu } from 'electron'
2 import menuconfig from '../config/menu' 2 import menuconfig from '../config/menu'
3 import config from '@config' 3 import config from '@config'
4 import setIpc from './ipcMain' 4 import setIpc from './ipcMain'
...@@ -58,7 +58,7 @@ function createMainWindow () { ...@@ -58,7 +58,7 @@ function createMainWindow () {
58 Menu.setApplicationMenu(menu) 58 Menu.setApplicationMenu(menu)
59 mainWindow.loadURL(winURL) 59 mainWindow.loadURL(winURL)
60 60
61 - setIpc.Mainfunc(ipcMain, mainWindow, config.IsUseSysTitle) 61 + setIpc.Mainfunc(mainWindow, config.IsUseSysTitle)
62 upload.Update(mainWindow) 62 upload.Update(mainWindow)
63 DownloadUpdate.download(mainWindow) 63 DownloadUpdate.download(mainWindow)
64 64
......
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
51 51
52 <script> 52 <script>
53 import SystemInformation from "./LandingPage/SystemInformation"; 53 import SystemInformation from "./LandingPage/SystemInformation";
54 -import api from "../tools/dialog";
55 import ipcApi from "../utils/ipcRenderer"; 54 import ipcApi from "../utils/ipcRenderer";
56 export default { 55 export default {
57 name: "landing-page", 56 name: "landing-page",
...@@ -62,7 +61,7 @@ export default { ...@@ -62,7 +61,7 @@ export default {
62 name: "yyy", 61 name: "yyy",
63 age: "12" 62 age: "12"
64 }, 63 },
65 - logo:require('@/assets/logo.png').default, 64 + logo: require("@/assets/logo.png").default,
66 textarray: [], 65 textarray: [],
67 percentage: 0, 66 percentage: 0,
68 colors: [ 67 colors: [
...@@ -91,7 +90,6 @@ export default { ...@@ -91,7 +90,6 @@ export default {
91 }, 90 },
92 // 获取数据库的数据 91 // 获取数据库的数据
93 getdata() { 92 getdata() {
94 - console.log(ne)
95 this.$db 93 this.$db
96 .finddata() 94 .finddata()
97 .then(res => { 95 .then(res => {
...@@ -104,22 +102,35 @@ export default { ...@@ -104,22 +102,35 @@ export default {
104 // 清空数据库的数据 102 // 清空数据库的数据
105 deledata() { 103 deledata() {
106 // dialog为electron实例,data则是显示需要的参数,fun是需要执行的函数,此选项不是为必选的 104 // dialog为electron实例,data则是显示需要的参数,fun是需要执行的函数,此选项不是为必选的
107 - const dialog = this.$electron.remote.dialog;
108 const data = { 105 const data = {
109 title: "清除数据", 106 title: "清除数据",
110 buttons: ["确定了!", "才不要,我手滑了"], 107 buttons: ["确定了!", "才不要,我手滑了"],
111 noLink: true, 108 noLink: true,
112 message: "此操作会清空本地数据库中的所有数据,是否继续?" 109 message: "此操作会清空本地数据库中的所有数据,是否继续?"
113 }; 110 };
114 - const fun = this.$db.deleall({ name: "yyy" }); 111 + ipcApi.send("open-messagebox", data);
115 - api.MessageBox(dialog, data, fun).then(res => { 112 + ipcApi.on("confirm-message", (event, arg) => {
113 + console.log(arg);
114 + if (arg.response === 0) {
115 + this.$db.deleall({ name: "yyy" }).then(res => {
116 + console.log(res);
117 + if (res !== 0) {
116 this.getdata(); 118 this.getdata();
117 this.$message({ 119 this.$message({
118 - showClose: true,
119 message: "成功删除" + res + "条", 120 message: "成功删除" + res + "条",
120 type: "success" 121 type: "success"
121 }); 122 });
123 + } else {
124 + let errormsg = {
125 + title: "错误",
126 + message: "已经没有数据可以被删除!"
127 + };
128 + ipcApi.send("open-errorbox", errormsg);
129 + }
122 }); 130 });
131 + }
132 + });
133 + // api.MessageBox(dialog, data, fun).then(res => {});
123 // const data = { 134 // const data = {
124 // title:'发生致命错误', 135 // title:'发生致命错误',
125 // message:'?' 136 // message:'?'
...@@ -196,7 +207,7 @@ export default { ...@@ -196,7 +207,7 @@ export default {
196 this.$alert("下载由于未知原因被中断!", "提示", { 207 this.$alert("下载由于未知原因被中断!", "提示", {
197 confirmButtonText: "重试", 208 confirmButtonText: "重试",
198 callback: action => { 209 callback: action => {
199 - ipcApi.send('download-restart') 210 + ipcApi.send("download-restart");
200 } 211 }
201 }); 212 });
202 } 213 }
...@@ -220,6 +231,14 @@ export default { ...@@ -220,6 +231,14 @@ export default {
220 handleClose() { 231 handleClose() {
221 this.dialogVisible = false; 232 this.dialogVisible = false;
222 } 233 }
234 + },
235 + destroyed() {
236 + ipcApi.remove("confirm-message");
237 + ipcApi.remove("download-done");
238 + ipcApi.remove("download-paused");
239 + ipcApi.remove("confirm-download");
240 + ipcApi.remove("download-progress");
241 + ipcApi.remove("download-error");
223 } 242 }
224 }; 243 };
225 </script> 244 </script>
...@@ -277,7 +296,7 @@ main > div { ...@@ -277,7 +296,7 @@ main > div {
277 font-size: 18px; 296 font-size: 18px;
278 margin-bottom: 10px; 297 margin-bottom: 10px;
279 } 298 }
280 -.doc{ 299 +.doc {
281 margin-bottom: 20px; 300 margin-bottom: 20px;
282 } 301 }
283 .doc p { 302 .doc p {
......
1 -export default {
2 - /**
3 - * @export
4 - * @param {Array} data
5 - * @param {Object} dialog
6 - * @param {function} fun
7 - * @returns
8 - * @feature 消息弹窗通用函数
9 - */
10 - MessageBox (dialog, data, fun) {
11 - return new Promise((resolve, reject) => {
12 - dialog.showMessageBox({
13 - type: 'info',
14 - title: data.title,
15 - buttons: data.buttons,
16 - message: data.message,
17 - noLink: data.noLink || false
18 - }, index => {
19 - if (index === 0) {
20 - // eslint-disable-next-line prefer-const
21 - let tempfun = async () => {
22 - try {
23 - resolve(await fun)
24 - } catch (error) {
25 - reject(error)
26 - }
27 - }
28 - tempfun()
29 - }
30 - })
31 - })
32 - },
33 - /**
34 - * @export
35 - * @param {Array} data
36 - * @param {Object} dialog
37 - * @returns
38 - * @feature 错误消息弹窗
39 - */
40 - ErrorMessageBox (dialog, data) {
41 - return dialog.showErrorBox(
42 - data.title,
43 - data.message
44 - )
45 - }
46 -}
1 import $electron from 'electron' 1 import $electron from 'electron'
2 2
3 export default { 3 export default {
4 - send (data, cb) { 4 + send (data, arg, cb) {
5 - $electron.ipcRenderer.send(data, (event, arg) => cb(event, arg)) 5 + $electron.ipcRenderer.send(data, arg, (event, arg) => cb(event, arg))
6 }, 6 },
7 - on (data, cb) { 7 + on (data, arg, cb) {
8 - $electron.ipcRenderer.on(data, (event, arg) => cb(event, arg)) 8 + $electron.ipcRenderer.on(data, arg, (event, arg) => cb(event, arg))
9 + },
10 + remove (data) {
11 + $electron.ipcRenderer.removeAllListeners(data)
9 } 12 }
10 } 13 }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
16 background-size: 163px; 16 background-size: 163px;
17 font: 14px/21px Monaco, sans-serif; 17 font: 14px/21px Monaco, sans-serif;
18 color: #999; 18 color: #999;
19 - font-smoothing: antialiased; 19 + -webkit-font-smoothing: antialiased;
20 -webkit-text-size-adjust: 100%; 20 -webkit-text-size-adjust: 100%;
21 -moz-text-size-adjust: 100%; 21 -moz-text-size-adjust: 100%;
22 -ms-text-size-adjust: 100%; 22 -ms-text-size-adjust: 100%;
......