123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- // 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()
- }
- })
- }
- }
- })
|