This commit is contained in:
weipengfei 2023-11-22 11:47:40 +08:00
parent b8d52b9602
commit 19c30008ca
9 changed files with 402 additions and 282 deletions

View File

@ -1,3 +1,3 @@
{ {
"prompt": "template" "prompt" : "template"
} }

12
api/menu.js Normal file
View File

@ -0,0 +1,12 @@
import request from "@/utils/request.js";
/**
* 小程序列表
* @param object
*/
export function indexMiniapp(data) {
return request.get(`index/miniapp`, data, {noAuth: true});
}

View File

@ -22,6 +22,7 @@ Vue.prototype.$Cache = Cache;
Vue.prototype.$eventHub = new Vue(); Vue.prototype.$eventHub = new Vue();
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.prototype.$bus = new Vue(); Vue.prototype.$bus = new Vue();
// #ifdef H5 // #ifdef H5
import { import {
parseQuery parseQuery

View File

@ -1,6 +1,7 @@
{ {
"name" : "里海中台", "name" : "里海中台",
"appid" : "__UNI__3A527D1", "appid" : "__UNI__BBF059D",
// "appid" : "__UNI__3A527D1",
"description" : "", "description" : "",
"versionName" : "0.0.1", "versionName" : "0.0.1",
"versionCode" : 1, "versionCode" : 1,
@ -12,6 +13,9 @@
"nvueCompiler" : "uni-app", "nvueCompiler" : "uni-app",
"nvueStyleCompiler" : "uni-app", "nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3, "compilerVersion" : 3,
"compatible" : {
"ignoreVersion" : true //trueHBuilderX1.9.0
},
"splashscreen" : { "splashscreen" : {
"alwaysShowBeforeRender" : true, "alwaysShowBeforeRender" : true,
"waiting" : true, "waiting" : true,
@ -70,7 +74,7 @@
"<uses-permission android:name=\"android.permission.BLUETOOTH\"/>", "<uses-permission android:name=\"android.permission.BLUETOOTH\"/>",
"<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\"/>" "<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\"/>"
], ],
"abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ], "abiFilters" : [ "armeabi-v7a", "arm64-v8a" ],
"permissionExternalStorage" : { "permissionExternalStorage" : {
"request" : "none", "request" : "none",
"prompt" : "应用保存运行状态等信息,需要获取读写手机存储(系统提示为访问设备上的照片、媒体内容和文件)权限,请允许。" "prompt" : "应用保存运行状态等信息,需要获取读写手机存储(系统提示为访问设备上的照片、媒体内容和文件)权限,请允许。"
@ -157,7 +161,8 @@
} }
}, },
"splashscreen" : { "splashscreen" : {
"useOriginalMsgbox" : true "useOriginalMsgbox" : true,
"androidStyle" : "common"
} }
}, },
"nativePlugins" : { "nativePlugins" : {

View File

@ -12,7 +12,7 @@
<block v-if="nowMenuList.length > 0"> <block v-if="nowMenuList.length > 0">
<u-transition v-for="(item, index) in nowMenuList" :key="item.name" show> <u-transition v-for="(item, index) in nowMenuList" :key="item.name" show>
<view class="examine" @click=" <view class="examine" @click="
editFlag ? removeMenu(item) : clickMenu(item.type, item.data) editFlag ? removeMenu(item) : clickMenu(item.type||0, item.data, item)
"> ">
<image class="icon_img" :src="item.icon" mode="aspectFit"> <image class="icon_img" :src="item.icon" mode="aspectFit">
</image> </image>
@ -53,11 +53,15 @@
getStoreList, getStoreList,
getUserInfo getUserInfo
} from '@/api/user.js' } from '@/api/user.js'
import{
indexMiniapp
} from "@/api/menu.js"
import { import {
Toast Toast
} from '@/libs/uniApi'; } from '@/libs/uniApi';
// #ifdef APP-PLUS // #ifdef APP-PLUS
import uniMP from '@/utils/uniMP.js'; import uniMP from '@/utils/uniMP.js';
import parse from '../../uni_modules/uview-ui/libs/config/props/parse';
// #endif // #endif
export default { export default {
@ -198,7 +202,6 @@
this.emptyText = '请登录' this.emptyText = '请登录'
this.jurisdiction = true this.jurisdiction = true
} }
console.log(this.jurisdiction);
}, },
onPullDownRefresh() { onPullDownRefresh() {
uni.stopPullDownRefresh() uni.stopPullDownRefresh()
@ -291,18 +294,28 @@
}, },
// //
initMenu() { initMenu() {
let now = uni.getStorageSync('gatherNowMenuList'); indexMiniapp().then((res)=>{
try { this.$set(this, 'AllMenuList', res.data)
this.nowMenuList = JSON.parse(now); // console.log({...this.AllMenuList[0]});
this.AllMenuList = this.AllMenuList.filter((item) => { try {
return this.nowMenuList.find(t => t.name == item.name)?.name != item.name; let now = uni.getStorageSync('gatherNowMenuList');
}) now = JSON.parse(now);
} catch (e) { this.AllMenuList.forEach(item=>{
this.nowMenuList = []; 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) { clickMenu(e, data, item) {
this.getUniMp(e, data); this.getUniMp(e, data, item);
}, },
// //
pushMenu(data) { pushMenu(data) {
@ -323,14 +336,17 @@
this.editFlag = false; this.editFlag = false;
uni.setStorageSync('gatherNowMenuList', JSON.stringify(this.nowMenuList)); uni.setStorageSync('gatherNowMenuList', JSON.stringify(this.nowMenuList));
}, },
getUniMp(type, data) { getUniMp(type, data, item) {
let that = this; let that = this;
// #ifdef APP-PLUS // #ifdef APP-PLUS
switch (type) { switch (type) {
case 0:
uniMP.loadMPcenter(item);
break;
case 1: case 1:
uniMP.loadMP(data); uniMP.loadMP(data);
break; break;
case 2: uniMP.loadMPx(data); break; case 2: uniMP.loadMPx(data); break;
// case 2: // case 2:
// // this.navigator(data); // // this.navigator(data);
// // uniMP.loadMPx(data); // // uniMP.loadMPx(data);

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,12 +1,13 @@
import { import {
getGXconfig, getGXconfig,
miniapp miniapp
} from "@/api/uniMP.js"; } from "@/api/uniMP.js";
import { import {
HTTP_REQUEST_URL HTTP_REQUEST_URL
} from '@/config/app'; } from '@/config/app';
const mp = uni.requireNativePlugin('uniMP'); const mp = uni.requireNativePlugin('uniMP');
import store from "@/store/modules/app.js" import store from "@/store/modules/app.js"
import { Toast } from "../libs/uniApi";
let appid = ''; // 应用id let appid = ''; // 应用id
let wgtFile = ''; // 应用文件地址 let wgtFile = ''; // 应用文件地址
@ -14,234 +15,317 @@ let timer = null; // 加载计时器
// 比较版本号大小 // 比较版本号大小
function compareVersions(version1, version2) { function compareVersions(version1, version2) {
const arr1 = version1.split('.').map(Number); const arr1 = version1.split('.').map(Number);
const arr2 = version2.split('.').map(Number); const arr2 = version2.split('.').map(Number);
for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) {
const num1 = i < arr1.length ? arr1[i] : 0; const num1 = i < arr1.length ? arr1[i] : 0;
const num2 = i < arr2.length ? arr2[i] : 0; const num2 = i < arr2.length ? arr2[i] : 0;
if (num1 > num2) { if (num1 > num2) {
return 1; return 1;
} else if (num1 < num2) { } else if (num1 < num2) {
return -1; return -1;
} }
} }
return 0; 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) => { const loadMP = async (id) => {
appid = id; appid = id;
let info = await getGXconfig(); let info = await getGXconfig();
console.log('最新版本', info.data); console.log('最新版本', info.data);
console.log(mp, uni); console.log(mp, uni);
// return ; // return ;
uni.showLoading({ uni.showLoading({
title: '初始化中...', title: '初始化中...',
mask: true mask: true
}) })
mp.getUniMPVersion(id, (ret) => { mp.getUniMPVersion(id, (ret) => {
console.log('当前版本', ret); console.log('当前版本', ret);
let flag; let flag;
if (HTTP_REQUEST_URL == 'https://shop.lihaink.cn') { if (HTTP_REQUEST_URL == 'https://shop.lihaink.cn') {
flag = false flag = false
} else { } else {
flag = true flag = true
} }
if (0 != ret.code || compareVersions(info.data.version, ret.versionInfo.name) == 1 || flag == if (0 != ret.code || compareVersions(info.data.version, ret.versionInfo.name) == 1 || flag ==
true) { true) {
let count = 0; let count = 0;
timer = setInterval(() => { timer = setInterval(() => {
if (count < 100) uni.showLoading({ if (count < 100) uni.showLoading({
title: `初始化中... ${count}%`, title: `初始化中... ${count}%`,
mask: true mask: true
}) })
else uni.showLoading({ else uni.showLoading({
title: '初始化中...100%', title: '初始化中...99%',
mask: true mask: true
}) })
}, 600) }, 600)
let downloadTask = uni.downloadFile({ let downloadTask = uni.downloadFile({
url: info.data.version_info?.dow_url, url: info.data.version_info?.dow_url,
success(res) { success(res) {
wgtFile = res.tempFilePath; wgtFile = res.tempFilePath;
console.log('初始化完成', wgtFile); console.log('初始化完成', wgtFile);
installMP(); setTimeout(() => {
}, installMP();
fail(res) { clearInterval(timer);
clearInterval(timer); timer = null;
timer = null; }, 700)
uni.hideLoading(); },
} fail(res) {
}); clearInterval(timer);
downloadTask.onProgressUpdate((res) => { timer = null;
// console.log('初始化进度' + res.progress); uni.hideLoading();
if (res.progress > count) count += 10; }
if (count >= 90) { });
clearInterval(timer); downloadTask.onProgressUpdate((res) => {
timer = null; // console.log('初始化进度' + res.progress);
} if (res.progress > count) count += 10;
}); if (count >= 90) {
} else { clearInterval(timer);
open() timer = null;
} }
}); });
} else {
open()
}
});
}; };
//加载商城小程序 //加载商城小程序
const loadMPx = async (id) => { 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({ appid = id;
url: info.data.appInfo.dow_url, let info = await miniapp();
success(res) { console.log('最新版本', info.data);
wgtFile = res.tempFilePath; console.log(mp, uni);
console.log('初始化完成', wgtFile); // return ;
installMP(); uni.showLoading({
}, title: '初始化中...',
fail(res) { mask: true
clearInterval(timer); })
timer = null; mp.getUniMPVersion(id, (ret) => {
uni.hideLoading(); console.log('当前版本', ret);
} let flag;
}); if (HTTP_REQUEST_URL == 'https://shop.lihaink.cn') {
downloadTask.onProgressUpdate((res) => { flag = false
// console.log('初始化进度' + res.progress); } else {
if (res.progress > count) count += 10; flag = true
if (count >= 90) { }
clearInterval(timer); if (0 != ret.code || compareVersions(info.data.appInfo.version, ret.versionInfo.name) == 1 ||
timer = null; flag ==
} true) {
}); let count = 0;
} else { timer = setInterval(() => {
open() 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) => { const loadMPurl = async (e) => {
appid = e.id; appid = e.id;
let FURL = e.url; let FURL = e.url;
uni.showLoading({ uni.showLoading({
title: '初始化中...', title: '初始化中...',
mask: true mask: true
}) })
uni.request({ uni.request({
url: FURL, url: FURL,
method: 'GET', method: 'GET',
success: (fileInfo) => { success: (fileInfo) => {
mp.getUniMPVersion(appid, (ret) => { mp.getUniMPVersion(appid, (ret) => {
console.log('当前版本', ret); console.log('当前版本', ret);
let flag; let flag;
if (HTTP_REQUEST_URL == 'https://shop.lihaink.cn') { if (HTTP_REQUEST_URL == 'https://shop.lihaink.cn') {
flag = false flag = false
} else { } else {
flag = true flag = true
} }
if (0 != ret.code || compareVersions(fileInfo.data?.data?.version, ret.versionInfo.name) == 1 || flag == if (0 != ret.code || compareVersions(fileInfo.data?.data?.version, ret.versionInfo.name) == 1 ||
true) { flag ==
let count = 0; true) {
timer = setInterval(() => { let count = 0;
if (count < 100) uni.showLoading({ timer = setInterval(() => {
title: `初始化中... ${count}%`, if (count < 100) uni.showLoading({
mask: true title: `初始化中... ${count}%`,
}) mask: true
else uni.showLoading({ })
title: '初始化中...100%', else uni.showLoading({
mask: true title: '初始化中...99%',
}) mask: true
}, 600) })
let downloadTask = uni.downloadFile({ }, 600)
url: fileInfo.data?.data?.down_url, let downloadTask = uni.downloadFile({
success(res) { url: fileInfo.data?.data?.down_url,
wgtFile = res.tempFilePath; success(res) {
console.log('初始化完成', wgtFile); wgtFile = res.tempFilePath;
installMP(); console.log('初始化完成', wgtFile);
}, setTimeout(() => {
fail(res) { installMP();
clearInterval(timer); clearInterval(timer);
timer = null; timer = null;
uni.hideLoading(); }, 700)
} },
}); fail(res) {
downloadTask.onProgressUpdate((res) => { clearInterval(timer);
// console.log('初始化进度' + res.progress); timer = null;
if (res.progress > count) count += 10; uni.hideLoading();
if (count >= 90) { }
clearInterval(timer); });
timer = null; downloadTask.onProgressUpdate((res) => {
} // console.log('初始化进度' + res.progress);
}); if (res.progress > count) count += 10;
} else { if (count >= 90) {
open() clearInterval(timer);
} timer = null;
}
});
} else {
open()
}
}); });
}, },
fail:(err)=> { fail: (err) => {
console.log('错误:', err); console.log('错误:', err);
} }
}) })
}; };
// 按远程文件地址加载小程序 // 按远程文件地址加载小程序
const loadMPdns = async (e) => { const loadMPdns = async (e) => {
appid = e.id; appid = e.id;
let FURL = e.url; let FURL = e.url;
uni.showLoading({ uni.showLoading({
title: '初始化中...', title: '初始化中...',
mask: true mask: true
}) })
let count = 0; let count = 0;
timer = setInterval(() => { timer = setInterval(() => {
if (count < 100) uni.showLoading({ if (count < 100) uni.showLoading({
title: `初始化中... ${count}%`, title: `初始化中... ${count}%`,
mask: true mask: true
}) })
else uni.showLoading({ else uni.showLoading({
title: '初始化中...100%', title: '初始化中...99%',
mask: true mask: true
}) })
}, 600) }, 600)
let downloadTask = uni.downloadFile({ let downloadTask = uni.downloadFile({
url: FURL, url: FURL,
success(res) { success(res) {
wgtFile = res.tempFilePath; wgtFile = res.tempFilePath;
console.log('初始化完成', wgtFile); console.log('初始化完成', wgtFile);
installMP(); setTimeout(() => {
}, installMP();
clearInterval(timer);
timer = null;
}, 700)
},
fail(res) { fail(res) {
clearInterval(timer); clearInterval(timer);
timer = null; timer = null;
@ -249,87 +333,89 @@ const loadMPdns = async (e) => {
} }
}); });
downloadTask.onProgressUpdate((res) => { downloadTask.onProgressUpdate((res) => {
// console.log('初始化进度' + res.progress); // console.log('初始化进度' + res.progress);
if (res.progress > count) count += 10; if (res.progress > count) count += 10;
if (count >= 90) { if (count >= 90) {
clearInterval(timer); clearInterval(timer);
timer = null; timer = null;
} }
}); });
}; };
// 小程序版本信息 // 小程序版本信息
const getVersion = (id) => { const getVersion = (id) => {
appid = id; appid = id;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
mp.getUniMPVersion(appid, (ret) => { mp.getUniMPVersion(appid, (ret) => {
console.log('供销', ret); console.log('供销', ret);
}); });
}) })
} }
// 初始化小程序 // 初始化小程序
const installMP = () => { const installMP = () => {
mp.getUniMPVersion(appid, (ret) => { mp.getUniMPVersion(appid, (ret) => {
doInstallMP(); doInstallMP();
console.log('getUniMPVersion: ' + JSON.stringify(ret)); console.log('getUniMPVersion: ' + JSON.stringify(ret));
}); });
}; };
const doInstallMP = () => { const doInstallMP = () => {
mp.installUniMP({ mp.installUniMP({
appid: appid, appid: appid,
wgtFile: wgtFile wgtFile: wgtFile
}, (r) => { }, (r) => {
if (0 == r.code) { if (0 == r.code) {
open(); open();
} else { } else {
uni.hideLoading(); uni.hideLoading();
clearInterval(timer); clearInterval(timer);
timer = null; timer = null;
uni.showModal({ uni.showModal({
title: '初始化失败', title: '初始化失败',
content: JSON.stringify(r), content: JSON.stringify(r),
showCancel: false showCancel: false
}); });
} }
console.log('初始化: ' + JSON.stringify(r)); console.log('初始化: ' + JSON.stringify(r));
}); });
}; };
const open = (id = null) => { const open = (id = null) => {
let token = uni.getStorageSync('LOGIN_STATUS_TOKEN'); let token = uni.getStorageSync('LOGIN_STATUS_TOKEN');
if (!token) return uni.showToast({ console.log(token);
icon: 'none', if (!token) return uni.showToast({
title: '请先登录' icon: 'none',
}) title: '请先登录'
let avatar = store?.state?.userInfo?.avatar; })
mp.openUniMP({ let avatar = store?.state?.userInfo?.avatar;
appid: id || appid, mp.openUniMP({
extraData: { appid: id || appid,
uniMP: true, extraData: {
token: token, uniMP: true,
avatar: avatar, token: token,
} avatar: avatar,
}, (ret) => { }
uni.hideLoading(); }, (ret) => {
if (0 != ret.code) { uni.hideLoading();
uni.showModal({ if (0 != ret.code) {
title: '启动失败', uni.showModal({
content: JSON.stringify(ret), title: '启动失败',
showCancel: false content: JSON.stringify(ret),
}); showCancel: false
} });
console.log('openUniMP: ' + JSON.stringify(ret)); }
}); console.log('openUniMP: ' + JSON.stringify(ret));
});
} }
export default { export default {
loadMP, loadMPcenter,
loadMPurl, loadMP,
loadMPx, loadMPurl,
loadMPx,
loadMPdns, loadMPdns,
installMP, installMP,
doInstallMP, doInstallMP,
getVersion, getVersion,
open open
} }