// index.js // 获取应用实例 const app = getApp() //正式环境 let API_BASE_URL = 'wss://xspace.4dage.com/' let PAGE_URL = 'https://xspace.4dage.com/' //测试环境,上传发布版本要注释以下代码 // API_BASE_URL = 'ws://test-xspace.4dage.com/' // PAGE_URL = 'https://test-xspace.4dage.com/' Page({ data: { motto: 'Hello World', userInfo: {}, url: '', hasUserInfo: false, PageOrientation: 'portrait', canIUse: wx.canIUse('button.open-type.getUserInfo'), sIdAndrIdQuery: '', loadCompele: false, inputNickName:'' }, onShareAppMessage() { // const promise = new Promise(resolve => { // setTimeout(() => { // resolve({ // title: '四维元宇宙' // }) // }, 1000) // }) return { title: '四维元宇宙', //path: '/page/user?id=123', //promise } }, onShareTimeline() { }, bindKeyInput(e) { this.setData({ inputNickName: e.detail.value }) }, onLoad(options) { // 1、获取二维码传参 if (options.scene) { this.setData({ sIdAndrIdQuery: decodeURIComponent(options.scene), }) } console.log(decodeURIComponent(options.scene)) if (wx.getStorageSync('nickName')) { console.log(wx.getStorageSync('nickName')) this.setData({ inputNickName: wx.getStorageSync('nickName') }) } }, loadcompele() { this.setData({ loadCompele: true }) }, enterUrl() { this.setData({ url: `${PAGE_URL}?avatarUrl=${encodeURIComponent(this.data.avatarUrl)}&nickName=${encodeURIComponent(this.data.nickName)}${this.data.sIdAndrIdQuery?('&'+this.data.sIdAndrIdQuery):''}`, }) wx.setPageOrientation({ orientation: 'landscape', }) }, getUserProfile(e) { if (wx.getStorageSync('avatarUrl') && wx.getStorageSync('nickName')) { this.setData({ avatarUrl: wx.getStorageSync('avatarUrl'), nickName: wx.getStorageSync('nickName') }) this.enterUrl() } else { // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 wx.getUserProfile({ desc: '使用您的昵称,作为数字人的昵称', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { let { nickName, avatarUrl } = res.userInfo this.setData({ avatarUrl: avatarUrl, nickName: this.data.inputNickName.trim() || nickName }) wx.setStorageSync('avatarUrl', this.data.avatarUrl) wx.setStorageSync('nickName', this.data.nickName) this.enterUrl() }, fail: (error) => { console.log(error); //如果用户拒绝,使用默认昵称 this.setData({ avatarUrl: null, nickName: this.data.inputNickName.trim() || '微信用户' }) this.enterUrl() } }) } } })