当前位置: 首页 > news >正文

uniapp开发 APP嵌入另一个APP打包的wgt文件,实现点击携带参数跳转到wgtAPP的某一个页面

1. uniapp开发 APP嵌入另一个APP打包的wgt文件,实现点击携带参数跳转到wgtAPP的某一个页面

1.1. 开发背景

  需求描述:原本需求是app中点击跳转到甲方提供的H5页面,但是甲方的功能已经有一个app了不想提供H5页面,甲方提供了app热更新打包的wgt包,希望我们app嵌入wgt实现跳转。

1.2. 实现方案

  uni-app项目中使用uni小程序教程
  uni小程序API

1.3. uni-app项目中使用uni小程序教程

  (1)在HBuilderX中打开宿主App项目的manifest.json文件,切换到源码视图,在 “app-plus” -> “modules” 下添加 "UniMP"字段如下:

  "UniMP": {"description": "uni小程序"}

  (2)将甲方提供的小程序wgt文件拷贝到宿主App项目目录下的"static"目录中(实际上要把wgt放到服务器上下载下来,因为甲方后续可能会更新wgt包),在宿主App中安装小程序wgt,示例代码如下:

installMP(){//通过获取小程序版本API来判断是否已经安装mp.getUniMPVersion('小程序的appid', (ret) => {if(0!=ret.code){//获取失败可以认为没有安装此小程序//安装小程序mp.installUniMP({appid:'小程序的appid',wgtFile:'小程序wgt文件路径'  //放在static目录路径为'/static/{$appid}.wgt',如果小程序wgt在服务器,需要先下载到本地再安装}, (r)=>{if(0==r.code){// openUniMP打开wgt页面,默认跳到首页,可跳过argument配置跳转页面和参数mp.openUniMP({appid: '小程序的appid',path:'/pages/xxx/xxx?queryParams=xxxx'}, (ret)=>{if(0!=ret.code){console.log('启动失败: '+JSON.stringify(ret));}});}else{console.log('安装失败: '+JSON.stringify(r));}});}});
}

  具体的API描述可参考上面的官网地址。

1.4. 完整代码

  (1)pageHelper

//pageHelper
/*** 设置标题*/
const setTitleBar = (title) => {//设置标题uni.setNavigationBarTitle({title: title})//设置标题背景uni.setNavigationBarColor({frontColor: '#ffffff',backgroundColor: '#007AFF'})
};/*** 跳转到web页面*/
const openWeb = (itemParams) => {uni.navigateTo({url: `/pages/myWeb/myWeb?itemObj=${JSON.stringify(itemParams)}`,});
};/*** 跳转到微信小程序*/
const openWxProgram = (wxAppId) => {plus.share.getServices(res => {let sweixin = null;for (let i in res) {if (res[i].id == 'weixin') {sweixin = res[i];}}//唤醒微信小程序if (sweixin) {uni.hideLoading()sweixin.launchMiniProgram({id: wxAppId, //需要跳转到的小程序的原始id,这是特别要注意的,type: 0,// path:'https://jingyan.baidu.com/article/XXXX.html' //跳转指定小程序的页面});}})
};/*** 跳转到微信小程序(wgt文件)*/
const openUniMP = (itemObj) => {// 文件下载uni.downloadFile({url: itemObj.detailUrl,//下载资源的 urlsuccess: res => {console.log(res);if (res.statusCode === 200) {console.log('下载成功');}console.log(res.tempFilePath);//文件保存到本地uni.saveFile({tempFilePath: res.tempFilePath, //临时路径success: function(res) {console.log(res);// uni.showToast({//     icon: 'none',//     mask: true,//     title: '文件已保存:' + res.savedFilePath, //保存路径//     duration: 3000// });const mp = uni.requireNativePlugin('uniMP');//通过获取小程序版本API来判断是否已经安装mp.getUniMPVersion( itemObj.appId, //'小程序的appid'(ret) => {console.log("qwrwer",ret.code);// if(0!=ret.code){//获取失败可以认为没有安装此小程序//安装小程序mp.installUniMP({appid: itemObj.appId,//'小程序的appid'wgtFile:res.savedFilePath  //放在static目录路径为'/static/{$appid}.wgt',如果小程序wgt在服务器,需要先下载到本地再安装}, (r)=>{if(0==r.code){// openUniMP打开wgt页面,默认跳到首页,可跳过argument配置跳转页面和参数mp.openUniMP({appid: itemObj.appId,//'小程序的appid'path:'/pages/xxx/xxx?queryParams=xxxx'}, (ret)=>{if(0!=ret.code){console.log('启动失败: '+JSON.stringify(ret));}});}else{console.log('安装失败: '+JSON.stringify(r));}});// }});setTimeout(() => {//打开文档查看// uni.openDocument({//     filePath: res.savedFilePath,//     success: function(res) {//         console.log('打开文档成功');//     },//     fail: function() {//         console.log('打开失败');//     }// });}, 3000);},fail: function() {console.log('保存失败');}});},fail: function() {console.log('下载失败');uni.showToast({icon: 'none',mask: true,title: '失败请重新下载'});}});// const mp = uni.requireNativePlugin('uniMP');// //通过获取小程序版本API来判断是否已经安装// mp.getUniMPVersion( itemObj.appId, //'小程序的appid'//     (ret) => {//         console.log("qwrwer",ret.code);//         // if(0!=ret.code){//获取失败可以认为没有安装此小程序//         //安装小程序//         mp.installUniMP({//             appid: itemObj.appId,//'小程序的appid'//             wgtFile:'/static/wgt/7947484196810655488.wgt'  //放在static目录路径为'/static/{$appid}.wgt',如果小程序wgt在服务器,需要先下载到本地再安装//         }, (r)=>{//             if(0==r.code){//                 // openUniMP打开wgt页面,默认跳到首页,可跳过argument配置跳转页面和参数//                 mp.openUniMP({//                     appid: itemObj.appId,//'小程序的appid'//                     path:'/pages/xxx/xxx?queryParams=xxxx'//                 }, (ret)=>{//                     if(0!=ret.code){//                         console.log('启动失败: '+JSON.stringify(ret));//                     }//                 });//             }else{//                 console.log('安装失败: '+JSON.stringify(r));//             }//         });//         // }//     });
};export default {setTitleBar: setTitleBar,openWeb: openWeb,openWxProgram: openWxProgram,openUniMP: openUniMP,}

  (2)wgt.bue

<template><view class="base-btn-layout"><view class="base-btn-txt"@click="wgtClick()">wgtClick</view></view>
</template>
<script>
import pageHelper from "../../../helper/pageHelper";export default {data() {return {name1: "",name2: "",}},onLoad: function (option) {var that = this;pageHelper.setTitleBar("wgt");},methods: {wgtClick: function () {let itemObj =  {"detailUrl": "https://os/upload/cServ/csrv/7947410655488.wgt","appId": "__UNI__AE923235D9","bindCode": "xshrtrty",}pageHelper.openUniMP(itemObj)}},
}
</script><style></style>
http://www.dtcms.com/a/466685.html

相关文章:

  • VS2010做网站登录页面步骤可以免费浏览的网站
  • DeepSeek Sparse Attention(DSA)快速洞察(DeepSeek-V3.2)
  • 山西建设银行官方网站wordpress 文章投票插件
  • C++ 模拟 力扣1576. 替换所有的问号 题解 每日一题
  • 安全联盟网站认证网络营销的认识
  • 基于SpringBoot+Vue的少儿编程培训机构管理系(WebSocket及时通讯、协同过滤算法、Echarts图形化分析)
  • 时序数据库promQL
  • 网站安全检测可以监测哪些内容风险信息宜春网站开发
  • 网站建设中企动力强成都那家网站建设好
  • RK3588 linux在uboot关机模式下待熄屏休眠后拔插适配器无反应屏幕也不会亮
  • 建设厅网站关于建筑资质合并wordpress速度很慢
  • 做网站的叫什么软件上海阿里巴巴做网站
  • Redis的Hash解析
  • 旅游业网站开发建设毕设做微课资源网站设计可以吗
  • 设计公司网站什么重要杭州工业设计
  • 【北京迅为】iTOP-4412精英版使用手册-第三十五章 WEB控制LED
  • 重庆seo整站优化报价福建建筑人才网官网
  • 教学信息化大赛网站建设作品永久免费国外ip代理
  • [嵌入式系统-93]: NVIDIA 正在从‘数据中心霸主’向‘端-边-云一体化AI平台’战略扩张。
  • 网站管理助手4.0域名备案查询管理系统
  • Oracle EBS ERP之报表开发—条件筛选按钮和组件开发
  • 济南网站建设与优化注册城乡规划师考试时间2023
  • 南通网站建设公司做品牌推广用什么网站
  • linux模拟压测CPU彪高到100%
  • 【2025全新】CDToolX专业圆二色谱数据处理软件下载安装教程(含最新版安装包)
  • 做网站做小程序推广中搜seo
  • Qiankun 微前端框架 start() 方法详解
  • 网站开发服务器多少钱个体户45万以下免个税
  • Autoware Universe 定位模块详解 | 第二节 深入研究定位模块数据流
  • 网站底部横条导航代码免费软件app下载大全