diff --git a/androidPrivacy.json b/androidPrivacy.json index 12df862..0d726ca 100644 --- a/androidPrivacy.json +++ b/androidPrivacy.json @@ -1,3 +1,3 @@ { - "prompt": "template" + "prompt" : "template" } diff --git a/api/menu.js b/api/menu.js new file mode 100644 index 0000000..e3e3900 --- /dev/null +++ b/api/menu.js @@ -0,0 +1,12 @@ + +import request from "@/utils/request.js"; + +/** + * 小程序列表 + * @param object + */ +export function indexMiniapp(data) { + return request.get(`index/miniapp`, data, {noAuth: true}); +} + + diff --git a/main.js b/main.js index 7483fe5..cc2c3b7 100644 --- a/main.js +++ b/main.js @@ -22,6 +22,7 @@ Vue.prototype.$Cache = Cache; Vue.prototype.$eventHub = new Vue(); Vue.config.productionTip = false Vue.prototype.$bus = new Vue(); + // #ifdef H5 import { parseQuery diff --git a/manifest.json b/manifest.json index a8848d6..ded9127 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,7 @@ { "name" : "里海中台", - "appid" : "__UNI__3A527D1", + "appid" : "__UNI__BBF059D", + // "appid" : "__UNI__3A527D1", "description" : "", "versionName" : "0.0.1", "versionCode" : 1, @@ -12,6 +13,9 @@ "nvueCompiler" : "uni-app", "nvueStyleCompiler" : "uni-app", "compilerVersion" : 3, + "compatible" : { + "ignoreVersion" : true //true表示忽略版本检查提示框,HBuilderX1.9.0及以上版本支持 + }, "splashscreen" : { "alwaysShowBeforeRender" : true, "waiting" : true, @@ -70,7 +74,7 @@ "", "" ], - "abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ], + "abiFilters" : [ "armeabi-v7a", "arm64-v8a" ], "permissionExternalStorage" : { "request" : "none", "prompt" : "应用保存运行状态等信息,需要获取读写手机存储(系统提示为访问设备上的照片、媒体内容和文件)权限,请允许。" @@ -157,7 +161,8 @@ } }, "splashscreen" : { - "useOriginalMsgbox" : true + "useOriginalMsgbox" : true, + "androidStyle" : "common" } }, "nativePlugins" : { diff --git a/pages/center/center.vue b/pages/center/center.vue index 794d25a..6b16100 100644 --- a/pages/center/center.vue +++ b/pages/center/center.vue @@ -12,7 +12,7 @@ @@ -53,11 +53,15 @@ getStoreList, getUserInfo } from '@/api/user.js' + import{ + indexMiniapp + } from "@/api/menu.js" import { Toast } from '@/libs/uniApi'; // #ifdef APP-PLUS import uniMP from '@/utils/uniMP.js'; +import parse from '../../uni_modules/uview-ui/libs/config/props/parse'; // #endif export default { @@ -198,7 +202,6 @@ this.emptyText = '请登录' this.jurisdiction = true } - console.log(this.jurisdiction); }, onPullDownRefresh() { uni.stopPullDownRefresh() @@ -291,18 +294,28 @@ }, // 初始化菜单 initMenu() { - let now = uni.getStorageSync('gatherNowMenuList'); - try { - this.nowMenuList = JSON.parse(now); - this.AllMenuList = this.AllMenuList.filter((item) => { - return this.nowMenuList.find(t => t.name == item.name)?.name != item.name; - }) - } catch (e) { - this.nowMenuList = []; - } + indexMiniapp().then((res)=>{ + this.$set(this, 'AllMenuList', res.data) + // console.log({...this.AllMenuList[0]}); + try { + let now = uni.getStorageSync('gatherNowMenuList'); + now = JSON.parse(now); + this.AllMenuList.forEach(item=>{ + if(now.find(e=>e.name==item.name)){ + this.nowMenuList.push(item); + } + }) + this.AllMenuList = this.AllMenuList.filter((item) => { + return this.nowMenuList.find(t => t.name == item.name)?.name != item.name; + }) + } catch (e) { + this.nowMenuList = []; + } + }) + }, - clickMenu(e, data) { - this.getUniMp(e, data); + clickMenu(e, data, item) { + this.getUniMp(e, data, item); }, // 添加菜单 pushMenu(data) { @@ -323,14 +336,17 @@ this.editFlag = false; uni.setStorageSync('gatherNowMenuList', JSON.stringify(this.nowMenuList)); }, - getUniMp(type, data) { + getUniMp(type, data, item) { let that = this; // #ifdef APP-PLUS switch (type) { + case 0: + uniMP.loadMPcenter(item); + break; case 1: uniMP.loadMP(data); break; - case 2: uniMP.loadMPx(data); break; + case 2: uniMP.loadMPx(data); break; // case 2: // // this.navigator(data); // // uniMP.loadMPx(data); diff --git a/static/wgt/__UNI__1EE148C.wgt b/static/wgt/__UNI__1EE148C.wgt deleted file mode 100644 index 976e349..0000000 Binary files a/static/wgt/__UNI__1EE148C.wgt and /dev/null differ diff --git a/static/wgt/__UNI__3A527D1.wgt b/static/wgt/__UNI__3A527D1.wgt deleted file mode 100644 index 2b85600..0000000 Binary files a/static/wgt/__UNI__3A527D1.wgt and /dev/null differ diff --git a/static/wgt/__UNI__9EDFE40.wgt b/static/wgt/__UNI__9EDFE40.wgt deleted file mode 100644 index 20bc707..0000000 Binary files a/static/wgt/__UNI__9EDFE40.wgt and /dev/null differ diff --git a/utils/uniMP.js b/utils/uniMP.js index 4c9900d..9ef7427 100644 --- a/utils/uniMP.js +++ b/utils/uniMP.js @@ -1,12 +1,13 @@ import { - getGXconfig, - miniapp + getGXconfig, + miniapp } from "@/api/uniMP.js"; import { - HTTP_REQUEST_URL + HTTP_REQUEST_URL } from '@/config/app'; const mp = uni.requireNativePlugin('uniMP'); import store from "@/store/modules/app.js" +import { Toast } from "../libs/uniApi"; let appid = ''; // 应用id let wgtFile = ''; // 应用文件地址 @@ -14,234 +15,317 @@ let timer = null; // 加载计时器 // 比较版本号大小 function compareVersions(version1, version2) { - const arr1 = version1.split('.').map(Number); - const arr2 = version2.split('.').map(Number); - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = i < arr1.length ? arr1[i] : 0; - const num2 = i < arr2.length ? arr2[i] : 0; - if (num1 > num2) { - return 1; - } else if (num1 < num2) { - return -1; - } - } - return 0; + const arr1 = version1.split('.').map(Number); + const arr2 = version2.split('.').map(Number); + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = i < arr1.length ? arr1[i] : 0; + const num2 = i < arr2.length ? arr2[i] : 0; + if (num1 > num2) { + return 1; + } else if (num1 < num2) { + return -1; + } + } + return 0; } +// 加载中台小程序 +const loadMPcenter = async (info) => { + console.log(info); + if(info.app_id[0]!='_'){ + console.log(`app_id:${info.app_id}不合法`); + return Toast('APPID不合法'); + } + appid = info.app_id; + try{ + uni.showLoading({ + title: '初始化中...', + mask: true + }) + mp.getUniMPVersion(appid, (ret) => { + console.log('当前版本', ret); + let flag; + if (HTTP_REQUEST_URL == 'https://middle.lihaink.cn') { + flag = false + } else { + flag = true + } + if (0 != ret.code || compareVersions(info.app_version, ret.versionInfo.name) == 1 || + flag == + true) { + let count = 0; + timer = setInterval(() => { + if (count < 100) uni.showLoading({ + title: `初始化中... ${count}%`, + mask: true + }) + else uni.showLoading({ + title: '初始化中...100%', + mask: true + }) + }, 600) + + let downloadTask = uni.downloadFile({ + url: info.down_url, + success(res) { + wgtFile = res.tempFilePath; + console.log('初始化完成', wgtFile); + installMP(); + }, + fail(res) { + clearInterval(timer); + timer = null; + uni.hideLoading(); + } + }); + downloadTask.onProgressUpdate((res) => { + // console.log('初始化进度' + res.progress); + if (res.progress > count) count += 10; + if (count >= 90) { + clearInterval(timer); + timer = null; + } + }); + } else { + open() + } + }); + }catch(e){ + uni.hideLoading() + } +}; + // 加载供销小程序 const loadMP = async (id) => { - appid = id; - let info = await getGXconfig(); - console.log('最新版本', info.data); - console.log(mp, uni); - // return ; - uni.showLoading({ - title: '初始化中...', - mask: true - }) - mp.getUniMPVersion(id, (ret) => { - console.log('当前版本', ret); - let flag; - if (HTTP_REQUEST_URL == 'https://shop.lihaink.cn') { - flag = false - } else { - flag = true - } - if (0 != ret.code || compareVersions(info.data.version, ret.versionInfo.name) == 1 || flag == - true) { - let count = 0; - timer = setInterval(() => { - if (count < 100) uni.showLoading({ - title: `初始化中... ${count}%`, - mask: true - }) - else uni.showLoading({ - title: '初始化中...100%', - mask: true - }) - }, 600) - let downloadTask = uni.downloadFile({ - url: info.data.version_info?.dow_url, - success(res) { - wgtFile = res.tempFilePath; - console.log('初始化完成', wgtFile); - installMP(); - }, - fail(res) { - clearInterval(timer); - timer = null; - uni.hideLoading(); - } - }); - downloadTask.onProgressUpdate((res) => { - // console.log('初始化进度' + res.progress); - if (res.progress > count) count += 10; - if (count >= 90) { - clearInterval(timer); - timer = null; - } - }); - } else { - open() - } - }); + appid = id; + let info = await getGXconfig(); + console.log('最新版本', info.data); + console.log(mp, uni); + // return ; + uni.showLoading({ + title: '初始化中...', + mask: true + }) + mp.getUniMPVersion(id, (ret) => { + console.log('当前版本', ret); + let flag; + if (HTTP_REQUEST_URL == 'https://shop.lihaink.cn') { + flag = false + } else { + flag = true + } + if (0 != ret.code || compareVersions(info.data.version, ret.versionInfo.name) == 1 || flag == + true) { + let count = 0; + timer = setInterval(() => { + if (count < 100) uni.showLoading({ + title: `初始化中... ${count}%`, + mask: true + }) + else uni.showLoading({ + title: '初始化中...99%', + mask: true + }) + }, 600) + let downloadTask = uni.downloadFile({ + url: info.data.version_info?.dow_url, + success(res) { + wgtFile = res.tempFilePath; + console.log('初始化完成', wgtFile); + setTimeout(() => { + installMP(); + clearInterval(timer); + timer = null; + }, 700) + }, + fail(res) { + clearInterval(timer); + timer = null; + uni.hideLoading(); + } + }); + downloadTask.onProgressUpdate((res) => { + // console.log('初始化进度' + res.progress); + if (res.progress > count) count += 10; + if (count >= 90) { + clearInterval(timer); + timer = null; + } + }); + } else { + open() + } + }); }; //加载商城小程序 const loadMPx = async (id) => { - - appid = id; - let info = await miniapp(); - console.log('最新版本', info.data); - console.log(mp, uni); - // return ; - uni.showLoading({ - title: '初始化中...', - mask: true - }) - mp.getUniMPVersion(id, (ret) => { - console.log('当前版本', ret); - let flag; - if (HTTP_REQUEST_URL == 'https://shop.lihaink.cn') { - flag = false - } else { - flag = true - } - if (0 != ret.code || compareVersions(info.data.appInfo.version, ret.versionInfo.name) == 1 || - flag == - true) { - let count = 0; - timer = setInterval(() => { - if (count < 100) uni.showLoading({ - title: `初始化中... ${count}%`, - mask: true - }) - else uni.showLoading({ - title: '初始化中...100%', - mask: true - }) - }, 600) - let downloadTask = uni.downloadFile({ - url: info.data.appInfo.dow_url, - success(res) { - wgtFile = res.tempFilePath; - console.log('初始化完成', wgtFile); - installMP(); - }, - fail(res) { - clearInterval(timer); - timer = null; - uni.hideLoading(); - } - }); - downloadTask.onProgressUpdate((res) => { - // console.log('初始化进度' + res.progress); - if (res.progress > count) count += 10; - if (count >= 90) { - clearInterval(timer); - timer = null; - } - }); - } else { - open() - } - }); + appid = id; + let info = await miniapp(); + console.log('最新版本', info.data); + console.log(mp, uni); + // return ; + uni.showLoading({ + title: '初始化中...', + mask: true + }) + mp.getUniMPVersion(id, (ret) => { + console.log('当前版本', ret); + let flag; + if (HTTP_REQUEST_URL == 'https://shop.lihaink.cn') { + flag = false + } else { + flag = true + } + if (0 != ret.code || compareVersions(info.data.appInfo.version, ret.versionInfo.name) == 1 || + flag == + true) { + let count = 0; + timer = setInterval(() => { + if (count < 100) uni.showLoading({ + title: `初始化中... ${count}%`, + mask: true + }) + else uni.showLoading({ + title: '初始化中...99%', + mask: true + }) + }, 600) + + let downloadTask = uni.downloadFile({ + url: info.data.appInfo.dow_url, + success(res) { + wgtFile = res.tempFilePath; + console.log('初始化完成', wgtFile); + setTimeout(() => { + installMP(); + clearInterval(timer); + timer = null; + }, 700) + }, + fail(res) { + clearInterval(timer); + timer = null; + uni.hideLoading(); + } + }); + downloadTask.onProgressUpdate((res) => { + // console.log('初始化进度' + res.progress); + if (res.progress > count) count += 10; + if (count >= 90) { + clearInterval(timer); + timer = null; + } + }); + } else { + open() + } + }); }; // 按信息接口加载小程序 const loadMPurl = async (e) => { - appid = e.id; + appid = e.id; let FURL = e.url; - uni.showLoading({ - title: '初始化中...', - mask: true - }) + uni.showLoading({ + title: '初始化中...', + mask: true + }) uni.request({ url: FURL, method: 'GET', success: (fileInfo) => { mp.getUniMPVersion(appid, (ret) => { - console.log('当前版本', ret); - let flag; - if (HTTP_REQUEST_URL == 'https://shop.lihaink.cn') { - flag = false - } else { - flag = true - } - if (0 != ret.code || compareVersions(fileInfo.data?.data?.version, ret.versionInfo.name) == 1 || flag == - true) { - let count = 0; - timer = setInterval(() => { - if (count < 100) uni.showLoading({ - title: `初始化中... ${count}%`, - mask: true - }) - else uni.showLoading({ - title: '初始化中...100%', - mask: true - }) - }, 600) - let downloadTask = uni.downloadFile({ - url: fileInfo.data?.data?.down_url, - success(res) { - wgtFile = res.tempFilePath; - console.log('初始化完成', wgtFile); - installMP(); - }, - fail(res) { - clearInterval(timer); - timer = null; - uni.hideLoading(); - } - }); - downloadTask.onProgressUpdate((res) => { - // console.log('初始化进度' + res.progress); - if (res.progress > count) count += 10; - if (count >= 90) { - clearInterval(timer); - timer = null; - } - }); - } else { - open() - } + console.log('当前版本', ret); + let flag; + if (HTTP_REQUEST_URL == 'https://shop.lihaink.cn') { + flag = false + } else { + flag = true + } + if (0 != ret.code || compareVersions(fileInfo.data?.data?.version, ret.versionInfo.name) == 1 || + flag == + true) { + let count = 0; + timer = setInterval(() => { + if (count < 100) uni.showLoading({ + title: `初始化中... ${count}%`, + mask: true + }) + else uni.showLoading({ + title: '初始化中...99%', + mask: true + }) + }, 600) + let downloadTask = uni.downloadFile({ + url: fileInfo.data?.data?.down_url, + success(res) { + wgtFile = res.tempFilePath; + console.log('初始化完成', wgtFile); + setTimeout(() => { + installMP(); + clearInterval(timer); + timer = null; + }, 700) + }, + fail(res) { + clearInterval(timer); + timer = null; + uni.hideLoading(); + } + }); + downloadTask.onProgressUpdate((res) => { + // console.log('初始化进度' + res.progress); + if (res.progress > count) count += 10; + if (count >= 90) { + clearInterval(timer); + timer = null; + } + }); + } else { + open() + } }); - + }, - fail:(err)=> { + fail: (err) => { console.log('错误:', err); } }) - + }; // 按远程文件地址加载小程序 const loadMPdns = async (e) => { - appid = e.id; + appid = e.id; let FURL = e.url; - uni.showLoading({ - title: '初始化中...', - mask: true - }) + uni.showLoading({ + title: '初始化中...', + mask: true + }) let count = 0; timer = setInterval(() => { if (count < 100) uni.showLoading({ - title: `初始化中... ${count}%`, - mask: true - }) - else uni.showLoading({ - title: '初始化中...100%', - mask: true - }) + title: `初始化中... ${count}%`, + mask: true + }) + else uni.showLoading({ + title: '初始化中...99%', + mask: true + }) }, 600) let downloadTask = uni.downloadFile({ - url: FURL, - success(res) { - wgtFile = res.tempFilePath; - console.log('初始化完成', wgtFile); - installMP(); - }, + url: FURL, + success(res) { + wgtFile = res.tempFilePath; + console.log('初始化完成', wgtFile); + setTimeout(() => { + installMP(); + clearInterval(timer); + timer = null; + }, 700) + }, fail(res) { clearInterval(timer); timer = null; @@ -249,87 +333,89 @@ const loadMPdns = async (e) => { } }); downloadTask.onProgressUpdate((res) => { - // console.log('初始化进度' + res.progress); - if (res.progress > count) count += 10; - if (count >= 90) { - clearInterval(timer); - timer = null; - } + // console.log('初始化进度' + res.progress); + if (res.progress > count) count += 10; + if (count >= 90) { + clearInterval(timer); + timer = null; + } }); - + }; // 小程序版本信息 const getVersion = (id) => { - appid = id; - return new Promise((resolve, reject) => { - mp.getUniMPVersion(appid, (ret) => { - console.log('供销', ret); - }); - }) + appid = id; + return new Promise((resolve, reject) => { + mp.getUniMPVersion(appid, (ret) => { + console.log('供销', ret); + }); + }) } // 初始化小程序 const installMP = () => { - mp.getUniMPVersion(appid, (ret) => { - doInstallMP(); - console.log('getUniMPVersion: ' + JSON.stringify(ret)); - }); + mp.getUniMPVersion(appid, (ret) => { + doInstallMP(); + console.log('getUniMPVersion: ' + JSON.stringify(ret)); + }); }; const doInstallMP = () => { - mp.installUniMP({ - appid: appid, - wgtFile: wgtFile - }, (r) => { - if (0 == r.code) { - open(); - } else { - uni.hideLoading(); - clearInterval(timer); - timer = null; - uni.showModal({ - title: '初始化失败', - content: JSON.stringify(r), - showCancel: false - }); - } - console.log('初始化: ' + JSON.stringify(r)); - }); + mp.installUniMP({ + appid: appid, + wgtFile: wgtFile + }, (r) => { + if (0 == r.code) { + open(); + } else { + uni.hideLoading(); + clearInterval(timer); + timer = null; + uni.showModal({ + title: '初始化失败', + content: JSON.stringify(r), + showCancel: false + }); + } + console.log('初始化: ' + JSON.stringify(r)); + }); }; const open = (id = null) => { - let token = uni.getStorageSync('LOGIN_STATUS_TOKEN'); - if (!token) return uni.showToast({ - icon: 'none', - title: '请先登录' - }) - let avatar = store?.state?.userInfo?.avatar; - mp.openUniMP({ - appid: id || appid, - extraData: { - uniMP: true, - token: token, - avatar: avatar, - } - }, (ret) => { - uni.hideLoading(); - if (0 != ret.code) { - uni.showModal({ - title: '启动失败', - content: JSON.stringify(ret), - showCancel: false - }); - } - console.log('openUniMP: ' + JSON.stringify(ret)); - }); + let token = uni.getStorageSync('LOGIN_STATUS_TOKEN'); + console.log(token); + if (!token) return uni.showToast({ + icon: 'none', + title: '请先登录' + }) + let avatar = store?.state?.userInfo?.avatar; + mp.openUniMP({ + appid: id || appid, + extraData: { + uniMP: true, + token: token, + avatar: avatar, + } + }, (ret) => { + uni.hideLoading(); + if (0 != ret.code) { + uni.showModal({ + title: '启动失败', + content: JSON.stringify(ret), + showCancel: false + }); + } + console.log('openUniMP: ' + JSON.stringify(ret)); + }); } export default { - loadMP, - loadMPurl, - loadMPx, + loadMPcenter, + loadMP, + loadMPurl, + loadMPx, loadMPdns, - installMP, - doInstallMP, - getVersion, - open + installMP, + doInstallMP, + getVersion, + open } \ No newline at end of file