index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. //正式环境
  5. let API_BASE_URL = 'wss://xspace.4dage.com/'
  6. let PAGE_URL = 'https://xspace.4dage.com/'
  7. //测试环境,上传发布版本要注释以下代码
  8. // API_BASE_URL = 'ws://test-xspace.4dage.com/'
  9. // PAGE_URL = 'https://test-xspace.4dage.com/'
  10. Page({
  11. data: {
  12. motto: 'Hello World',
  13. userInfo: {},
  14. url: '',
  15. hasUserInfo: false,
  16. PageOrientation: 'portrait',
  17. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  18. sIdAndrIdQuery: '',
  19. loadCompele: false,
  20. inputNickName:''
  21. },
  22. onShareAppMessage() {
  23. // const promise = new Promise(resolve => {
  24. // setTimeout(() => {
  25. // resolve({
  26. // title: '四维元宇宙'
  27. // })
  28. // }, 1000)
  29. // })
  30. return {
  31. title: '四维元宇宙',
  32. //path: '/page/user?id=123',
  33. //promise
  34. }
  35. },
  36. onShareTimeline() {
  37. },
  38. bindKeyInput(e) {
  39. this.setData({
  40. inputNickName: e.detail.value
  41. })
  42. },
  43. onLoad(options) {
  44. // 1、获取二维码传参
  45. if (options.scene) {
  46. this.setData({
  47. sIdAndrIdQuery: decodeURIComponent(options.scene),
  48. })
  49. }
  50. console.log(decodeURIComponent(options.scene))
  51. if (wx.getStorageSync('nickName')) {
  52. console.log(wx.getStorageSync('nickName'))
  53. this.setData({
  54. inputNickName: wx.getStorageSync('nickName')
  55. })
  56. }
  57. },
  58. loadcompele() {
  59. this.setData({
  60. loadCompele: true
  61. })
  62. },
  63. enterUrl() {
  64. this.setData({
  65. url: `${PAGE_URL}?avatarUrl=${encodeURIComponent(this.data.avatarUrl)}&nickName=${encodeURIComponent(this.data.nickName)}${this.data.sIdAndrIdQuery?('&'+this.data.sIdAndrIdQuery):''}`,
  66. })
  67. wx.setPageOrientation({
  68. orientation: 'landscape',
  69. })
  70. },
  71. getUserProfile(e) {
  72. if (wx.getStorageSync('avatarUrl') && wx.getStorageSync('nickName')) {
  73. this.setData({
  74. avatarUrl: wx.getStorageSync('avatarUrl'),
  75. nickName: wx.getStorageSync('nickName')
  76. })
  77. this.enterUrl()
  78. } else {
  79. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  80. wx.getUserProfile({
  81. desc: '使用您的昵称,作为数字人的昵称', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  82. success: (res) => {
  83. let {
  84. nickName,
  85. avatarUrl
  86. } = res.userInfo
  87. this.setData({
  88. avatarUrl: avatarUrl,
  89. nickName: this.data.inputNickName.trim() || nickName
  90. })
  91. wx.setStorageSync('avatarUrl', this.data.avatarUrl)
  92. wx.setStorageSync('nickName', this.data.nickName)
  93. this.enterUrl()
  94. },
  95. fail: (error) => {
  96. console.log(error);
  97. //如果用户拒绝,使用默认昵称
  98. this.setData({
  99. avatarUrl: null,
  100. nickName: this.data.inputNickName.trim() || '微信用户'
  101. })
  102. this.enterUrl()
  103. }
  104. })
  105. }
  106. }
  107. })