//--------------------------------app.vue------------------------------------------------
<template lang="">
<div class="wealth-manage">
weixin:
<div>
{{this.$route.path}}
{{this.$route.params}}
{{this.$route.query}}
</div>
<button @click="fixPosition">获取位置</button>
<button @click="sendParamByH5">发送数据到宿主</button>
</div>
</template>
<script>
var jweixin = require('jweixin-module');
export default {
name: 'wealthManage',
components: {
},
data() {
return {
list: [],
tapInfo: {},
visible: false,
delData: {},
loading: false
};
},
methods: {
fixPosition() {
//保存当前地址,以便从小程序中返回时使用
let jumpUrl = window.location;
//传递多个参数时用&连接
let path = `/pages/address/address?address=${this.warehouse}&jumpUrl=${jumpUrl}`
//使用navigateTo跳转到小程序路径中
try {
jweixin.miniProgram.navigateTo({
url: path
});
} catch(ex) {
console.log(ex);
alert(ex);
}
},
sendParamByH5() {
// jweixin.miniProgram.navigateBack({delta: 1})
jweixin.miniProgram.postMessage({
data: {
testParam1: "1",
testParam2: "2",
testParam3: "3"
}
})
}
},
mounted() {
}
};
</script>
<style scoped lang="scss">
.wealth-manage {
.operation {
text-align: right;
}
.table {
margin-top: 16px;
}
.videoImg {
width: 100px;
::v-deep img {
width: 100%;
height: 100%;
}
}
}
</style>
//------------------------------------index.wxml--------------------------------------------
<!--index.wxml-->
<view class="container">
<view class="userinfo">
<block wx:if="{{canIUseOpenData}}">
<view class="userinfo-avatar" bindtap="bindViewTap">
<open-data type="userAvatarUrl"></open-data>
</view>
<open-data type="userNickName"></open-data>
</block>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block>
</view>
<view class="usermotto">
<web-view bindmessage="getMessageFromH5" src="https://apg-kkgkkmh-mixalpha-admin.fe.editor.h5no1.com/apg-kkgkkmh-mixAlpha-admin-test/#/weixinLocation?name=yanglihao">hi</web-view>
</view>
</view>
//------------------------------------index.js--------------------------------------------
// index.js
// 获取应用实例
const app = getApp()
Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
canIUseGetUserProfile: false,
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
},
// 事件处理函数
bindViewTap() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad() {
console.log('yanglihao2006')
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
wx.scanCode({
success: (res) => {
console.log(res)
}
})
},
getMessageFromH5(e){
if (e && e.detail && e.detail.data) {
console.log(e.detail)
}
},
getUserProfile(e) {
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log('yanglihao')
console.log(res)
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
},
getUserInfo(e) {
// 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
console.log('yanglihao getUserInfo')
console.log(e)
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
})
//------------------------------------address.wxml--------------------------------------------
<!--index.wxml-->
<view class="container">
<view class="userinfo">
hi
</view>
<view class="usermotto">
<text class="user-motto">{{motto}}</text>
{{url}}
<web-view src='{{url}}'>hi</web-view>
</view>
</view>
//-------------------------------------------------address.js---------------------------------
// 获取应用实例
const app = getApp()
Page({
data: {
url: 'https://apg-kkgkkmh-mixalpha-admin.fe.editor.h5no1.com/apg-kkgkkmh-mixAlpha-admin-test/#/organization',
latitude: 0,
longitude: 0,
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
canIUseGetUserProfile: false,
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
},
// 事件处理函数
bindViewTap() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad() {
console.log('yanglihao2006')
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
wx.getLocation({
type: 'wgs84',
success: (res) => {
this.latitude = res.latitude // 纬度
this.longitude = res.longitude // 经度
this.setData({
url: `https://apg-kkgkkmh-mixalpha-admin.fe.editor.h5no1.com/apg-kkgkkmh-mixAlpha-admin-test/#/weixinLocation?name=${this.latitude}`
})
// this.url = `https://apg-kkgkkmh-mixalpha-admin.fe.editor.h5no1.com/apg-kkgkkmh-mixAlpha-admin-test/#/weixinLocation?name=${this.latitude}`
console.log('getLocation', res)
}
})
wx.scanCode({
success: (res) => {
console.log(res)
}
})
},
getUserProfile(e) {
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log('yanglihao')
console.log(res)
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
},
getUserInfo(e) {
// 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
console.log('yanglihao getUserInfo')
console.log(e)
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
})