index.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // index.ts
  2. // 获取应用实例
  3. const app = getApp<IAppOption>()
  4. var mixins = require('../../utils/mixins')
  5. Page({
  6. mixins: [mixins],
  7. data: {
  8. isShowHelp: false,
  9. isShowAuth: true,
  10. userInfo: {},
  11. hasUserInfo: false,
  12. },
  13. // 事件处理函数
  14. toPerson() {
  15. this.getUserProfile(() => {
  16. wx.navigateTo({
  17. url: '../person/index',
  18. })
  19. })
  20. },
  21. tapclose() {
  22. this.setData({
  23. isShowHelp: false
  24. })
  25. },
  26. tapAuthclose(){
  27. this.setData({
  28. isShowAuth: false
  29. })
  30. },
  31. tapHelp() {
  32. this.setData({
  33. isShowHelp: true
  34. })
  35. },
  36. toActivity() {
  37. this.getUserProfile(() => {
  38. wx.navigateTo({
  39. url: '../activity_mode/index',
  40. })
  41. })
  42. },
  43. toGame() {
  44. this.getUserProfile(() => {
  45. wx.navigateTo({
  46. url: `../game/index`,
  47. })
  48. })
  49. },
  50. getUserProfile(cb = () => { }) {
  51. if (this.data.hasUserInfo) {
  52. cb()
  53. }
  54. else {
  55. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  56. wx.getUserProfile({
  57. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  58. success: res => {
  59. console.log(res);
  60. let { userInfo } = res
  61. // @ts-ignore
  62. this.data.fetchutil.post(`/sys/wxUser/save`, {
  63. "avatarUrl": userInfo.avatarUrl,
  64. "gender": userInfo.gender,
  65. "nickName": userInfo.nickName,
  66. // @ts-ignore
  67. id: app.globalData.userInfo.id
  68. }, {}).then((response: any) => {
  69. console.log(response);
  70. this.setData({
  71. hasUserInfo: true
  72. })
  73. cb()
  74. })
  75. }
  76. })
  77. }
  78. },
  79. onLoad(options) {
  80. let {noTips} = options
  81. if (!noTips) {
  82. this.setData({
  83. isShowHelp:true
  84. })
  85. }
  86. },
  87. onShow(){
  88. // @ts-ignore
  89. app.watch('hasAvatar', (v: any) => {
  90. if (v) {
  91. this.setData({
  92. hasUserInfo: true
  93. })
  94. }
  95. })
  96. }
  97. })