123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- // index.js
- // 获取应用实例
- const app = getApp()
- //正式环境
- let API_BASE_URL = 'wss://uspace.4dage.com/'
- let PAGE_URL = 'https://uspace.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: '',
- phone: ''
- },
- 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),
- })
- }
- if (wx.getStorageSync('phone')) {
- this.setData({
- phone: wx.getStorageSync('phone')
- })
- }
- 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',
- })
- },
- saveNumber(num) {
- let userinfo = wx.getStorageSync('userInfo')
- wx.request({
- // url: 'http://192.168.20.55:8040/' + `api/wx/save/wxUser`,
- url: PAGE_URL + `api/wx/save/wxUser`,
- method: 'post',
- data: {
- ...userinfo,
- phone: num
- },
- dataType: 'json',
- success: res => {
- },
- fail: err => {
- console.log(err)
- },
- complete: complete => {
- }
- })
- },
- getPhoneNumber(e) {
- console.log(e.detail.code)
- if (e.detail.code) {
- wx.request({
- // url: 'http://192.168.20.55:8040/' + `api/wx/getPhone/${e.detail.code}`,
- url: PAGE_URL + `api/wx/getPhone/${e.detail.code}`,
- method: 'get',
- dataType: 'json',
- success: res => {
- console.log(res)
- if (res.data.code > -1) {
- wx.setStorageSync('phone', res.data.data.phoneNumber)
- this.saveNumber(res.data.data.phoneNumber)
- }
- },
- fail: err => {
- console.log(err)
- },
- complete: complete => {
- }
- })
- }
- },
- getUserProfile(e) {
- if (wx.getStorageSync('avatarUrl') && wx.getStorageSync('nickName')) {
- wx.setStorageSync('nickName', this.data.inputNickName)
- this.setData({
- avatarUrl: wx.getStorageSync('avatarUrl'),
- nickName: wx.getStorageSync('nickName')
- })
- this.enterUrl()
- } else {
- // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
- wx.getUserProfile({
- desc: '使用您的昵称,作为数字人的昵称', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
- success: (res) => {
- wx.setStorageSync('userInfo', res.userInfo)
- 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()
- }
- })
- }
- }
- })
|