新增在线更新功能
This commit is contained in:
parent
86c8ca6472
commit
d57cecd91d
15844
dist-electron/main.js
15844
dist-electron/main.js
File diff suppressed because it is too large
Load Diff
|
|
@ -1,6 +1,10 @@
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { app, BrowserWindow, ipcMain } from "electron";
|
import { app, BrowserWindow, ipcMain } from "electron";
|
||||||
|
|
||||||
|
import axios from "axios";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
|
import fs from "fs";
|
||||||
|
import { exec } from "child_process";
|
||||||
|
|
||||||
let win;
|
let win;
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
|
|
@ -28,6 +32,56 @@ app.whenReady().then(() => {
|
||||||
win.loadFile(path.resolve(__dirname, "../dist/index.html")); // 打包后使用文件路径访问应用
|
win.loadFile(path.resolve(__dirname, "../dist/index.html")); // 打包后使用文件路径访问应用
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const installExe = async (exePath) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
exec(`start ${exePath}`, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
resolve(stdout);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
ipcMain.on("downloadFile", async (event, arg) => {
|
||||||
|
let _parmas = JSON.parse(arg);
|
||||||
|
axios({
|
||||||
|
url: _parmas.url,
|
||||||
|
method: "get",
|
||||||
|
responseType: "arraybuffer",
|
||||||
|
onDownloadProgress: (propessEvent) => {
|
||||||
|
// 更新进度条
|
||||||
|
const propress = Math.round(
|
||||||
|
(propessEvent.loaded / propessEvent.total) * 100
|
||||||
|
);
|
||||||
|
win.webContents.send("updateProgress", propress);
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(async (response) => {
|
||||||
|
try {
|
||||||
|
const tempFilePath = path.join(
|
||||||
|
app.getPath("temp"),
|
||||||
|
"temp-exe-file.exe"
|
||||||
|
);
|
||||||
|
fs.writeFileSync(tempFilePath, response.data);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
win = null;
|
||||||
|
app.exit();
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
const installResult = await installExe(tempFilePath);
|
||||||
|
console.log(`安装结果:${installResult}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error", error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log("下载失败", JSON.stringify(err));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
app.on("activate", () => {
|
app.on("activate", () => {
|
||||||
// 在 macOS 系统内, 如果没有已开启的应用窗口
|
// 在 macOS 系统内, 如果没有已开启的应用窗口
|
||||||
// 点击托盘图标时通常会重新创建一个新窗口
|
// 点击托盘图标时通常会重新创建一个新窗口
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@
|
||||||
<div class="t2">
|
<div class="t2">
|
||||||
<span>原价:¥{{ formatDecimal(props.amount) }}</span>
|
<span>原价:¥{{ formatDecimal(props.amount) }}</span>
|
||||||
<span style="margin-left: 20px;">优惠:¥{{ formatDecimal(props.amount - money) }}</span>
|
<span style="margin-left: 20px;">优惠:¥{{ formatDecimal(props.amount - money) }}</span>
|
||||||
<span style="margin-left: 20px;" v-if="props.discount" @click="cancelDiscount">折扣:{{ formatDecimal(props.discount * 10, 1, true) }}折
|
<span style="margin-left: 20px;" v-if="props.discount" @click="cancelDiscount">折扣:{{
|
||||||
|
formatDecimal(props.discount * 10, 1, true) }}折
|
||||||
<el-icon style="margin-left: 6px;">
|
<el-icon style="margin-left: 6px;">
|
||||||
<CircleClose />
|
<CircleClose />
|
||||||
</el-icon>
|
</el-icon>
|
||||||
|
|
@ -295,7 +296,8 @@ async function getMemberList() {
|
||||||
shopId: store.userInfo.shopId,
|
shopId: store.userInfo.shopId,
|
||||||
phone: tableData.phone,
|
phone: tableData.phone,
|
||||||
page: tableData.page,
|
page: tableData.page,
|
||||||
pageSize: tableData.size
|
pageSize: tableData.size,
|
||||||
|
isFlag: 1
|
||||||
})
|
})
|
||||||
tableData.loading = false
|
tableData.loading = false
|
||||||
tableData.list = res.list
|
tableData.list = res.list
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
<template>
|
||||||
|
<el-dialog v-model="showDialog" title="发现新版本" width="500" :close-on-click-modal="false"
|
||||||
|
:close-on-press-escape="false" :show-close="false">
|
||||||
|
<div class="message">
|
||||||
|
{{ updataInfo.message }}
|
||||||
|
</div>
|
||||||
|
<div class="progress_wrap" style="padding-top: 20px;">
|
||||||
|
<el-progress :percentage="uploadPro" :stroke-width="15" striped :striped-flow="uploadPro < 100" />
|
||||||
|
</div>
|
||||||
|
<template #footer>
|
||||||
|
<div class="footer" style="padding: 0 20px 20px;">
|
||||||
|
<el-button v-if="!updataInfo.isUp && !isUpload" @click="showDialog = false">下次更新</el-button>
|
||||||
|
<el-button type="primary" :loading="isUpload" @click="uplaodHandle">
|
||||||
|
<template v-if="!uploadSucess">
|
||||||
|
<template v-if="!isUpload">
|
||||||
|
立即更新
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
下载中...
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
立即安装
|
||||||
|
</template>
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
import { findVersion } from '@/api/user.js'
|
||||||
|
import packageData from "../../package.json";
|
||||||
|
import { ipcRenderer } from 'electron'
|
||||||
|
|
||||||
|
import { useUser } from "@/store/user.js";
|
||||||
|
|
||||||
|
const store = useUser()
|
||||||
|
|
||||||
|
const showDialog = ref(false)
|
||||||
|
const updataInfo = ref({})
|
||||||
|
const isUpload = ref(false)
|
||||||
|
const uploadPro = ref(0)
|
||||||
|
const uploadSucess = ref(false)
|
||||||
|
const uploadResponse = ref({})
|
||||||
|
const tempFilePath = ref('')
|
||||||
|
|
||||||
|
// 检查版本更新
|
||||||
|
async function findVersionAjax() {
|
||||||
|
try {
|
||||||
|
const res = await findVersion()
|
||||||
|
let reg = /\./g;
|
||||||
|
if (res.version.replace(reg, '') > packageData.version.replace(reg, '') && res.url) {
|
||||||
|
showDialog.value = true
|
||||||
|
updataInfo.value = res
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下载新版本
|
||||||
|
async function uplaodHandle() {
|
||||||
|
try {
|
||||||
|
if (!uploadSucess.value) {
|
||||||
|
isUpload.value = true
|
||||||
|
ipcRenderer.send('downloadFile', JSON.stringify({ url: updataInfo.value.url }))
|
||||||
|
// await downloadFile(updataInfo.value.url)
|
||||||
|
// isUpload.value = false
|
||||||
|
// uploadSucess.value = true
|
||||||
|
} else {
|
||||||
|
// 安装文件
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (store.userInfo) {
|
||||||
|
findVersionAjax()
|
||||||
|
}
|
||||||
|
ipcRenderer.on('updateProgress', (event, res) => {
|
||||||
|
uploadPro.value = res
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
@ -135,6 +135,8 @@
|
||||||
<fastCashier ref="fastCashierRef" type="0" />
|
<fastCashier ref="fastCashierRef" type="0" />
|
||||||
<!-- 挂起订单 -->
|
<!-- 挂起订单 -->
|
||||||
<pendingCartModal ref="pendingCartModalRef" @select="pendingCartHandle" />
|
<pendingCartModal ref="pendingCartModalRef" @select="pendingCartHandle" />
|
||||||
|
<!-- 检查版本升级 -->
|
||||||
|
<updateDialog />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
@ -147,6 +149,8 @@ import { onMounted, ref } from "vue";
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { useUser } from "@/store/user.js";
|
import { useUser } from "@/store/user.js";
|
||||||
import { useGlobal } from '@/store/global.js'
|
import { useGlobal } from '@/store/global.js'
|
||||||
|
|
||||||
|
import updateDialog from '@/components/updateDialog.vue'
|
||||||
import remarkModal from "@/components/remarkModal.vue";
|
import remarkModal from "@/components/remarkModal.vue";
|
||||||
import takeFoodCode from "@/components/takeFoodCode.vue";
|
import takeFoodCode from "@/components/takeFoodCode.vue";
|
||||||
import cartOperation from "@/views/home/components/cartOperation.vue";
|
import cartOperation from "@/views/home/components/cartOperation.vue";
|
||||||
|
|
@ -409,6 +413,7 @@ async function createCodeAjax(type = "0") {
|
||||||
const res = await createCode({
|
const res = await createCode({
|
||||||
shopId: store.userInfo.shopId,
|
shopId: store.userInfo.shopId,
|
||||||
type: type,
|
type: type,
|
||||||
|
tableId: global.tableInfo.qrcode || '',
|
||||||
});
|
});
|
||||||
masterId.value = res.code;
|
masterId.value = res.code;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,72 @@
|
||||||
<template>
|
<template>
|
||||||
<el-button>button</el-button>
|
<el-dialog v-model="showDialog" title="发现新版本" width="500" :close-on-click-modal="false"
|
||||||
|
:close-on-press-escape="false" :show-close="false">
|
||||||
|
<div class="message">
|
||||||
|
{{ updataInfo.message }}
|
||||||
|
</div>
|
||||||
|
<div class="progress_wrap" style="padding-top: 20px;">
|
||||||
|
<el-progress :percentage="uploadPro" :stroke-width="15" striped :striped-flow="uploadPro < 100" />
|
||||||
|
</div>
|
||||||
|
<template #footer>
|
||||||
|
<div class="footer" style="padding: 0 20px 20px;">
|
||||||
|
<el-button v-if="!updataInfo.isUp">下次更新</el-button>
|
||||||
|
<el-button type="primary" :loading="isUpload" @click="uplaodHandle">
|
||||||
|
<template v-if="!uploadSucess">
|
||||||
|
<template v-if="!isUpload">
|
||||||
|
立即更新
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
下载中...
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
立即安装
|
||||||
|
</template>
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import { findVersion } from '@/api/user.js'
|
import { findVersion } from '@/api/user.js'
|
||||||
import packageData from "../../../package.json";
|
import packageData from "../../../package.json";
|
||||||
|
import { ipcRenderer } from 'electron'
|
||||||
|
|
||||||
|
const showDialog = ref(false)
|
||||||
|
const updataInfo = ref({})
|
||||||
|
const isUpload = ref(false)
|
||||||
|
const uploadPro = ref(0)
|
||||||
|
const uploadSucess = ref(false)
|
||||||
|
const uploadResponse = ref({})
|
||||||
|
const tempFilePath = ref('')
|
||||||
|
|
||||||
|
// 检查版本更新
|
||||||
async function findVersionAjax() {
|
async function findVersionAjax() {
|
||||||
try {
|
try {
|
||||||
const res = await findVersion()
|
const res = await findVersion()
|
||||||
let reg = /\./g;
|
let reg = /\./g;
|
||||||
// console.log('res.version', res.version.replace(reg, ''));
|
|
||||||
// console.log('packageData.version', packageData.version.replace(reg, ''));
|
|
||||||
if (res.version.replace(reg, '') > packageData.version.replace(reg, '') && res.url) {
|
if (res.version.replace(reg, '') > packageData.version.replace(reg, '') && res.url) {
|
||||||
console.log('有版本更新');
|
showDialog.value = true
|
||||||
|
updataInfo.value = res
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下载新版本
|
||||||
|
async function uplaodHandle() {
|
||||||
|
try {
|
||||||
|
if (!uploadSucess.value) {
|
||||||
|
isUpload.value = true
|
||||||
|
ipcRenderer.send('downloadFile', JSON.stringify({ url: updataInfo.value.url }))
|
||||||
|
// await downloadFile(updataInfo.value.url)
|
||||||
|
// isUpload.value = false
|
||||||
|
// uploadSucess.value = true
|
||||||
|
} else {
|
||||||
|
// 安装文件
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
@ -23,5 +75,9 @@ async function findVersionAjax() {
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
findVersionAjax()
|
findVersionAjax()
|
||||||
|
ipcRenderer.on('updateProgress', (event, res) => {
|
||||||
|
// console.log('updateProgress===', event, res);
|
||||||
|
uploadPro.value = res
|
||||||
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -308,7 +308,8 @@ const asyncqueryMembermember = async () => {//会员列表数据
|
||||||
shopId: store.userInfo.shopId,
|
shopId: store.userInfo.shopId,
|
||||||
page: tableData.page,
|
page: tableData.page,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
phone: tableData.phone
|
phone: tableData.phone,
|
||||||
|
isFlag: 0
|
||||||
})
|
})
|
||||||
if (res) {
|
if (res) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue