From 91e17af463dbba7f79b608e564262f940324bb99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=82=E7=B3=96?= Date: Mon, 28 Jul 2025 11:22:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=B8=8D=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=97=B6=E5=8F=AF=E4=BB=A5=E5=88=B0=E6=B5=8F=E8=A7=88=E5=99=A8?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=AE=89=E8=A3=85=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 272 ++----------------------- api/oa/contact.js | 44 ++++ api/oa/emailAccount.js | 53 +++++ components/oa/oa-file-upload/index.vue | 52 +++++ pages.json | 8 + pages/workbench/index/index.vue | 119 ++++++----- pages/workbench/sales/sales.vue | 37 ++++ static/images/yingxiao.png | Bin 0 -> 5063 bytes util/update.js | 232 +++++++++++++++++++++ version.md | 5 + 10 files changed, 507 insertions(+), 315 deletions(-) create mode 100644 api/oa/contact.js create mode 100644 api/oa/emailAccount.js create mode 100644 components/oa/oa-file-upload/index.vue create mode 100644 pages/workbench/sales/sales.vue create mode 100644 static/images/yingxiao.png create mode 100644 util/update.js create mode 100644 version.md diff --git a/App.vue b/App.vue index f966503..664e51a 100644 --- a/App.vue +++ b/App.vue @@ -8,6 +8,7 @@ import IMSDK, { import config from "./common/config"; import { getDbDir, toastWithCallback } from "@/util/common.js"; import { conversationSort } from "@/util/imCommon"; +import updateManager from "@/util/update.js"; import { PageEvents, UpdateMessageTypes } from "@/constant"; const openSdk = uni.requireNativePlugin('Tuoyun-OpenIMSDK'); const globalEvent = uni.requireNativePlugin('globalEvent'); @@ -15,11 +16,11 @@ const globalEvent = uni.requireNativePlugin('globalEvent'); export default { onLaunch: function () { console.log("App Launch"); - console.log(openSdk); + console.log(openSdk); this.setGlobalIMlistener(); this.tryLogin(); // #ifdef APP-PLUS - checkUpdate(); // 直接调用独立函数,避免this问题 + updateManager.checkUpdate(); // 直接调用独立函数,避免this问题 // #endif // #ifdef H5 console.error( @@ -45,20 +46,20 @@ export default { onShow: function () { console.log("App Show"); IMSDK.asyncApi(IMSDK.IMMethods.SetAppBackgroundStatus, IMSDK.uuid(), false); - //#ifdef APP-PLUS - // var info = plus.push.getClientInfo() - // plus.push.addEventListener("click", function(msg) { - // console.log("click:" + JSON.stringify(msg)); - // console.log(msg.payload); - // console.log(JSON.stringify(msg)); - // }, false); - // // 监听在线消息事件 - // plus.push.addEventListener("receive", function(msg) { - // //业务代码 - // console.log("recevice:" + JSON.stringify(msg)) - // }, false); - //#endif - + //#ifdef APP-PLUS + // var info = plus.push.getClientInfo() + // plus.push.addEventListener("click", function(msg) { + // console.log("click:" + JSON.stringify(msg)); + // console.log(msg.payload); + // console.log(JSON.stringify(msg)); + // }, false); + // // 监听在线消息事件 + // plus.push.addEventListener("receive", function(msg) { + // //业务代码 + // console.log("recevice:" + JSON.stringify(msg)) + // }, false); + //#endif + }, onHide: function () { @@ -498,245 +499,8 @@ export default { }, }; -function checkUpdate(forceCheck = false) { - const localVersion = plus.runtime.version; - const localWgtVersion = uni.getStorageSync('wgtVersion') || localVersion; - uni.request({ - url: 'http://47.117.71.33:11295/fadapp-update/version.json?t=' + Date.now(), - success: (res) => { - const remoteVersion = res.data.version; - const wgtUrl = res.data.wgtUrl; - // 取本地基座和本地wgt的最大版本 - const currentVersion = compareVersion(localWgtVersion, localVersion) > 0 ? localWgtVersion : localVersion; - console.log('本地基座版本:', localVersion, '本地wgt版本:', localWgtVersion, '当前对比版本:', currentVersion, '远程版本:', remoteVersion); - if (compareVersion(remoteVersion, currentVersion) > 0) { - // 检查版本兼容性 - if (!checkVersionCompatibility(remoteVersion, localVersion)) { - console.warn('版本不兼容,跳过更新'); - uni.showModal({ - title: '版本不兼容', - content: `新版本 ${remoteVersion} 与当前基座版本 ${localVersion} 不兼容,请通过应用商店更新完整版本。`, - showCancel: false, - confirmText: '确定' - }); - return; - } - - // 检查是否已忽略当前版本(除非强制检查) - const ignoredVersion = uni.getStorageSync('ignoredVersion'); - if (!forceCheck && ignoredVersion === remoteVersion) { - console.log('用户已选择忽略此版本:', remoteVersion); - return; - } - - uni.showModal({ - title: '发现新版本', - content: `检测到新版本(${remoteVersion}),是否立即下载并更新?`, - confirmText: '立即更新', - cancelText: '暂不更新', - showCancel: true, - success: (modalRes) => { - if (modalRes.confirm) { - // 检查存储空间 - checkStorageSpace().then(() => { - uni.showLoading({title: '正在下载更新包...'}); - console.log('开始下载wgt包:', wgtUrl); - uni.downloadFile({ - url: wgtUrl, - success: (downloadResult) => { - uni.hideLoading(); - console.log('下载结果:', downloadResult); - if (downloadResult.statusCode === 200) { - console.log('开始安装wgt包:', downloadResult.tempFilePath); - // 检查文件是否存在 - plus.io.resolveLocalFileSystemURL(downloadResult.tempFilePath, (entry) => { - console.log('文件存在,开始安装'); - plus.runtime.install(downloadResult.tempFilePath, {force: true}, function() { - console.log('wgt包安装成功'); - // 更新本地wgt版本号 - uni.setStorageSync('wgtVersion', remoteVersion); - uni.showModal({ - title: '更新完成', - content: '应用需要重启才能生效,是否立即重启?', - success: function (res) { - if (res.confirm) { - plus.runtime.restart(); - } - } - }); - }, function(e) { - console.error('wgt包安装失败:', e); - let errorMsg = '安装失败'; - if (e && e.message) { - errorMsg += ': ' + e.message; - } - if (e && e.code) { - errorMsg += ' (错误代码: ' + e.code + ')'; - } - uni.showModal({ - title: '安装失败', - content: errorMsg + '\n\n可能的原因:\n1. 版本不兼容\n2. 文件损坏\n3. 权限不足\n4. 存储空间不足', - showCancel: false, - confirmText: '确定' - }); - }); - }, (error) => { - console.error('文件不存在:', error); - uni.showModal({ - title: '安装失败', - content: '下载的文件不存在或已损坏', - showCancel: false, - confirmText: '确定' - }); - }); - } else { - console.error('下载失败,状态码:', downloadResult.statusCode); - uni.showModal({ - title: '下载失败', - content: `服务器返回错误,状态码: ${downloadResult.statusCode}`, - showCancel: false, - confirmText: '确定' - }); - } - }, - fail: (error) => { - uni.hideLoading(); - console.error('下载失败:', error); - uni.showModal({ - title: '下载失败', - content: '网络连接异常,请检查网络后重试', - showCancel: false, - confirmText: '确定' - }); - } - }); - }).catch((error) => { - console.error('存储空间检查失败:', error); - uni.showModal({ - title: '存储空间不足', - content: '设备存储空间不足,无法下载更新包', - showCancel: false, - confirmText: '确定' - }); - }); - } else { - // 用户选择暂不更新,询问是否忽略此版本 - uni.showModal({ - title: '忽略更新', - content: `是否忽略版本 ${remoteVersion}?忽略后下次启动时将不再提示此版本更新。`, - confirmText: '忽略此版本', - cancelText: '下次提醒', - success: (ignoreRes) => { - if (ignoreRes.confirm) { - uni.setStorageSync('ignoredVersion', remoteVersion); - uni.showToast({title: '已忽略此版本更新'}); - } - } - }); - } - } - }); - } else { - // uni.showToast({title: '当前已是最新版本'}); - console.log('当前已是最新版本'); - } - }, - fail: (error) => { - console.error('检查更新失败:', error); - uni.showToast({title: '网络异常,请稍后重试'}); - } - }); -} -function extractVersionNum(str) { - // 匹配第一个出现的数字版本号 - const match = str.match(/(\d+\.\d+(?:\.\d+)?)/); - return match ? match[1] : '0.0.0'; -} - -function compareVersion(v1, v2) { - v1 = extractVersionNum(v1).split('.').map(Number); - v2 = extractVersionNum(v2).split('.').map(Number); - for (let i = 0; i < Math.max(v1.length, v2.length); i++) { - const n1 = v1[i] || 0; - const n2 = v2[i] || 0; - if (n1 > n2) return 1; - if (n1 < n2) return -1; - } - return 0; -} - -// 更新管理工具函数 -function clearIgnoredVersion() { - uni.removeStorageSync('ignoredVersion'); - console.log('已清除忽略的版本设置'); -} - -function getIgnoredVersion() { - return uni.getStorageSync('ignoredVersion'); -} - -function setIgnoredVersion(version) { - uni.setStorageSync('ignoredVersion', version); - console.log('已设置忽略版本:', version); -} - -// 检查版本兼容性 -function checkVersionCompatibility(wgtVersion, baseVersion) { - console.log('检查版本兼容性:', { wgtVersion, baseVersion }); - - // 提取主版本号进行比较 - const wgtMajor = extractVersionNum(wgtVersion).split('.')[0]; - const baseMajor = extractVersionNum(baseVersion).split('.')[0]; - - // 主版本号必须匹配 - if (wgtMajor !== baseMajor) { - console.warn('主版本号不匹配:', { wgtMajor, baseMajor }); - return false; - } - - // 检查wgt版本是否高于基座版本 - if (compareVersion(wgtVersion, baseVersion) <= 0) { - console.warn('wgt版本不高于基座版本'); - return false; - } - - return true; -} - -// 检查存储空间 -function checkStorageSpace() { - return new Promise((resolve, reject) => { - // #ifdef APP-PLUS - if (typeof plus !== 'undefined' && plus.io) { - plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fs) => { - fs.root.getDirectory('temp', { create: true }, (dir) => { - // 简单检查,实际项目中可能需要更复杂的空间检查 - resolve(true); - }, (error) => { - console.error('检查存储空间失败:', error); - reject(error); - }); - }); - } else { - resolve(true); - } - // #endif - - // #ifndef APP-PLUS - resolve(true); - // #endif - }); -} - // 导出更新管理函数供其他页面使用 -uni.$updateManager = { - checkUpdate: (forceCheck = false) => checkUpdate(forceCheck), - clearIgnoredVersion, - getIgnoredVersion, - setIgnoredVersion, - checkVersionCompatibility, - checkStorageSpace -}; +uni.$updateManager = updateManager; diff --git a/pages.json b/pages.json index 73e6566..eddc4fb 100644 --- a/pages.json +++ b/pages.json @@ -349,6 +349,14 @@ "navigationBarTitleText" : "项目详情", "navigationStyle": "default" } + }, + { + "path" : "pages/workbench/sales/sales", + "style" : + { + "navigationBarTitleText" : "线上营销", + "navigationStyle": "default" + } } ], "tabBar": { diff --git a/pages/workbench/index/index.vue b/pages/workbench/index/index.vue index 0c81569..36eebb1 100644 --- a/pages/workbench/index/index.vue +++ b/pages/workbench/index/index.vue @@ -6,34 +6,15 @@ - - - 每日报工 + + + {{ item.text }} - - - 施工进度 - - - - 任务中心 - - - - 项目排产 - - - - 快递信息 - - - - 项目中心 - - - - 库存盘点 - @@ -53,6 +34,52 @@ export default { // 页面加载时调用getUserProfile this.fetchUserProfile(); }, + data() { + return { + entryList: [ + { + text: '每日报工', + icon: '/static/images/baogong.png', + url: '/pages/workbench/reportWork/reportWork', + }, + { + text: '施工进度', + icon: '/static/images/shigong.png', + url: '/pages/workbench/construction/construction', + }, + { + text: '任务中心', + icon: '/static/images/task.png', + url: '/pages/workbench/task/task', + }, + { + text: '项目排产', + icon: '/static/images/paichan.png', + url: '/pages/workbench/reportSchedule/reportSchedule', + }, + { + text: '快递信息', + icon: '/static/images/express.svg', + url: '/pages/workbench/express/express', + }, + { + text: '项目中心', + icon: '/static/images/project.png', + url: '/pages/workbench/project/project', + }, + { + text: '库存盘点', + icon: '/static/images/stock.png', + url: '/pages/workbench/wms/wms', + }, + { + text: '线上营销', + icon: '/static/images/yingxiao.png', + url: '/pages/workbench/sales/sales', + }, + ], + }; + }, methods: { // 获取用户个人信息 async fetchUserProfile() { @@ -66,41 +93,11 @@ export default { console.error('获取用户个人信息失败:', error); } }, - goReportWork() { - uni.navigateTo({ - url: '/pages/workbench/reportWork/reportWork' - }); + handleEntryClick(item) { + if (item.url) { + uni.navigateTo({ url: item.url }); + } }, - goConstruction() { - uni.navigateTo({ - url: '/pages/workbench/construction/construction' - }); - }, - goTask() { - uni.navigateTo({ - url: '/pages/workbench/task/task' - }) - }, - goSchedule() { - uni.navigateTo({ - url: '/pages/workbench/reportSchedule/reportSchedule' - }) - }, - goExpress() { - uni.navigateTo({ - url: '/pages/workbench/express/express' - }) - }, - goProject() { - uni.navigateTo({ - url: '/pages/workbench/project/project' - }) - }, - goStock() { - uni.navigateTo({ - url: '/pages/workbench/wms/wms' - }) - } }, }; diff --git a/pages/workbench/sales/sales.vue b/pages/workbench/sales/sales.vue new file mode 100644 index 0000000..1a49359 --- /dev/null +++ b/pages/workbench/sales/sales.vue @@ -0,0 +1,37 @@ + + + + + diff --git a/static/images/yingxiao.png b/static/images/yingxiao.png new file mode 100644 index 0000000000000000000000000000000000000000..70b04457aac6c439446511b2ca4cf7dc78129d36 GIT binary patch literal 5063 zcmd^D`8(9z`?tJhtc_jP8M{nGWsS_(*KFB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U-Y#SQ8ogr zX)3ANU$qgO3f)^JX;l%1z>Ng5u zw`vA>i7a9DtQmSg1*PEDoy~i7m)v}A63#iLDuS%8BO9NMV64un@r{u+f65hSKj>@4 z3wpl2(|P{ETJkSM*b3J$CbNU}Wuqr+RIQTwv)Y#4R{4zB#qgCwsx1R%R>y(;lqgLu zu+kJ@ytgxa;C*9qKu@K~p06vShF?xMito zU>!$1<~-|@W3Aykgm-oLH^9hLljGX+SPc@(YiQ^X(iYKUs_w||21$V?!E9Urg58qpmpZxObjgb>roi+{{U=J BS$_Zk literal 0 HcmV?d00001 diff --git a/util/update.js b/util/update.js new file mode 100644 index 0000000..f2201eb --- /dev/null +++ b/util/update.js @@ -0,0 +1,232 @@ + +// 匹配第一个出现的数字版本号 +function extractVersionNum(str) { + const match = str.match(/(\d+\.\d+(?:\.\d+)?)/); + return match ? match[1] : '0.0.0'; +} + +function compareVersion(v1, v2) { + v1 = extractVersionNum(v1).split('.').map(Number); + v2 = extractVersionNum(v2).split('.').map(Number); + for (let i = 0; i < Math.max(v1.length, v2.length); i++) { + const n1 = v1[i] || 0; + const n2 = v2[i] || 0; + if (n1 > n2) return 1; + if (n1 < n2) return -1; + } + return 0; +} + +function clearIgnoredVersion() { + uni.removeStorageSync('ignoredVersion'); + console.log('已清除忽略的版本设置'); +} + +function getIgnoredVersion() { + return uni.getStorageSync('ignoredVersion'); +} + +function setIgnoredVersion(version) { + uni.setStorageSync('ignoredVersion', version); + console.log('已设置忽略版本:', version); +} + +function checkVersionCompatibility(wgtVersion, baseVersion) { + console.log('检查版本兼容性:', { wgtVersion, baseVersion }); + const wgtMajor = extractVersionNum(wgtVersion).split('.')[0]; + const baseMajor = extractVersionNum(baseVersion).split('.')[0]; + if (wgtMajor !== baseMajor) { + console.warn('主版本号不匹配:', { wgtMajor, baseMajor }); + return false; + } + if (compareVersion(wgtVersion, baseVersion) <= 0) { + console.warn('wgt版本不高于基座版本'); + return false; + } + return true; +} + +function checkStorageSpace() { + return new Promise((resolve, reject) => { + // #ifdef APP-PLUS + if (typeof plus !== 'undefined' && plus.io) { + plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fs) => { + fs.root.getDirectory('temp', { create: true }, (dir) => { + resolve(true); + }, (error) => { + console.error('检查存储空间失败:', error); + reject(error); + }); + }); + } else { + resolve(true); + } + // #endif + // #ifndef APP-PLUS + resolve(true); + // #endif + }); +} + +function checkUpdate(forceCheck = false) { + const localVersion = plus.runtime.version; + const localWgtVersion = uni.getStorageSync('wgtVersion') || localVersion; + uni.request({ + url: 'http://47.117.71.33:11295/fadapp-update/version.json?t=' + Date.now(), + success: (res) => { + const remoteVersion = res.data.version; + const wgtUrl = res.data.wgtUrl; + const currentVersion = compareVersion(localWgtVersion, localVersion) > 0 ? localWgtVersion : localVersion; + console.log('本地基座版本:', localVersion, '本地wgt版本:', localWgtVersion, '当前对比版本:', currentVersion, '远程版本:', remoteVersion); + if (compareVersion(remoteVersion, currentVersion) > 0) { + if (!checkVersionCompatibility(remoteVersion, localVersion)) { + console.warn('版本不兼容,跳转到浏览器下载新版安装包'); + uni.showModal({ + title: '版本不兼容', + content: `新版本 ${remoteVersion} 与当前基座版本 ${localVersion} 不兼容,请前往官网下载最新安装包。`, + showCancel: true, + confirmText: '去下载', + cancelText: '取消', + success: (res) => { + if (res.confirm) { + const downloadUrl = `http://47.117.71.33:11295/fadapp-update/fad${remoteVersion}.apk`; + // #ifdef APP-PLUS + plus.runtime.openURL(downloadUrl); + // #endif + // #ifndef APP-PLUS + window.open(downloadUrl, '_blank'); + // #endif + } + } + }); + return; + } + const ignoredVersion = uni.getStorageSync('ignoredVersion'); + if (!forceCheck && ignoredVersion === remoteVersion) { + console.log('用户已选择忽略此版本:', remoteVersion); + return; + } + uni.showModal({ + title: '发现新版本', + content: `检测到新版本(${remoteVersion}),是否立即下载并更新?`, + confirmText: '立即更新', + cancelText: '暂不更新', + showCancel: true, + success: (modalRes) => { + if (modalRes.confirm) { + checkStorageSpace().then(() => { + uni.showLoading({title: '正在下载更新包...'}); + console.log('开始下载wgt包:', wgtUrl); + uni.downloadFile({ + url: wgtUrl, + success: (downloadResult) => { + uni.hideLoading(); + console.log('下载结果:', downloadResult); + if (downloadResult.statusCode === 200) { + console.log('开始安装wgt包:', downloadResult.tempFilePath); + plus.io.resolveLocalFileSystemURL(downloadResult.tempFilePath, (entry) => { + console.log('文件存在,开始安装'); + plus.runtime.install(downloadResult.tempFilePath, {force: true}, function() { + console.log('wgt包安装成功'); + uni.setStorageSync('wgtVersion', remoteVersion); + uni.showModal({ + title: '更新完成', + content: '应用需要重启才能生效,是否立即重启?', + success: function (res) { + if (res.confirm) { + plus.runtime.restart(); + } + } + }); + }, function(e) { + console.error('wgt包安装失败:', e); + let errorMsg = '安装失败'; + if (e && e.message) { + errorMsg += ': ' + e.message; + } + if (e && e.code) { + errorMsg += ' (错误代码: ' + e.code + ')'; + } + uni.showModal({ + title: '安装失败', + content: errorMsg + '\n\n可能的原因:\n1. 版本不兼容\n2. 文件损坏\n3. 权限不足\n4. 存储空间不足', + showCancel: false, + confirmText: '确定' + }); + }); + }, (error) => { + console.error('文件不存在:', error); + uni.showModal({ + title: '安装失败', + content: '下载的文件不存在或已损坏', + showCancel: false, + confirmText: '确定' + }); + }); + } else { + console.error('下载失败,状态码:', downloadResult.statusCode); + uni.showModal({ + title: '下载失败', + content: `服务器返回错误,状态码: ${downloadResult.statusCode}`, + showCancel: false, + confirmText: '确定' + }); + } + }, + fail: (error) => { + uni.hideLoading(); + console.error('下载失败:', error); + uni.showModal({ + title: '下载失败', + content: '网络连接异常,请检查网络后重试', + showCancel: false, + confirmText: '确定' + }); + } + }); + }).catch((error) => { + console.error('存储空间检查失败:', error); + uni.showModal({ + title: '存储空间不足', + content: '设备存储空间不足,无法下载更新包', + showCancel: false, + confirmText: '确定' + }); + }); + } else { + uni.showModal({ + title: '忽略更新', + content: `是否忽略版本 ${remoteVersion}?忽略后下次启动时将不再提示此版本更新。`, + confirmText: '忽略此版本', + cancelText: '下次提醒', + success: (ignoreRes) => { + if (ignoreRes.confirm) { + uni.setStorageSync('ignoredVersion', remoteVersion); + uni.showToast({title: '已忽略此版本更新'}); + } + } + }); + } + } + }); + } else { + console.log('当前已是最新版本'); + } + }, + fail: (error) => { + console.error('检查更新失败:', error); + uni.showToast({title: '网络异常,请稍后重试'}); + } + }); +} + +export default { + checkUpdate, + clearIgnoredVersion, + getIgnoredVersion, + setIgnoredVersion, + checkVersionCompatibility, + checkStorageSpace, + compareVersion, + extractVersionNum +}; diff --git a/version.md b/version.md new file mode 100644 index 0000000..6e997dd --- /dev/null +++ b/version.md @@ -0,0 +1,5 @@ +## 4.5.1 ++ 开始记录版本 ++ 增加版本不兼容时可以从浏览器下载安装包的功能 ++ 优化部分页面功能 ++ 增加线上销售页面 \ No newline at end of file