tabbar.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // pages/Components/tabbar/tabbar.js
  2. const app = getApp();
  3. const util = require('../../../utils/util.js')
  4. let url = null
  5. Component({
  6. lifetimes: {
  7. attached() {
  8. this.isApple()
  9. if (!wx.getStorageSync('isShow')) {
  10. this.data.titleList.splice(2, 1)
  11. this.setData({
  12. titleList: this.data.titleList
  13. })
  14. }
  15. }
  16. },
  17. /**
  18. * 组件的属性列表
  19. */
  20. properties: {
  21. curIndex: {
  22. type: Number,
  23. value: 0
  24. },
  25. curHtml: {
  26. type: String,
  27. value: ''
  28. },
  29. phone:{
  30. type: String,
  31. value: ''
  32. }
  33. },
  34. /**
  35. * 组件的初始数据
  36. */
  37. data: {
  38. titleList: [{
  39. title: '首页',
  40. icon: '/images/index.png',
  41. curIcon: '/images/cur-index.png',
  42. val: '首页',
  43. path: '/pages/index/index'
  44. },
  45. {
  46. title: '练琴',
  47. icon: '/images/piano.png',
  48. curIcon: '/images/cur-piano.png',
  49. val: '练琴',
  50. path: '/pages/piano/piano'
  51. },
  52. {
  53. title: '活动',
  54. icon: '/images/active.png',
  55. curIcon: '/images/active-red.png',
  56. val: '活动',
  57. path: '/pages/tabBar/active/active'
  58. },
  59. {
  60. title: '我的',
  61. icon: '/images/my.png',
  62. curIcon: '/images/cur-my.png',
  63. val: '我的',
  64. path: '/pages/myself/myself'
  65. },
  66. ],
  67. phoneList: [
  68. 'iPhone X',
  69. 'iPhone XR',
  70. 'iPhone XS Max',
  71. 'iPhone 11',
  72. 'iPhone 11 Pro',
  73. 'iPhone 11 Pro Max',
  74. 'iPhone 12',
  75. 'iPhone 12 Mini',
  76. 'iPhone 12 Pro',
  77. 'iPhone 12 Pro Max'
  78. ],
  79. },
  80. /**
  81. * 组件的方法列表
  82. */
  83. methods: {
  84. isApple: function () {
  85. wx.getSystemInfo({ //当小程序初始化完成时 获取用户的手机机型 并写出适配ipnone手机安全区域的的适配方案
  86. success: (res) => {
  87. const phone = res.model.split(" ")
  88. this.data.phoneList.forEach(item => {
  89. if (item == phone[0] + ' ' + phone[1]) {
  90. this.setData({
  91. bottomStyle: true
  92. })
  93. return false;
  94. }
  95. });
  96. }
  97. })
  98. },
  99. changeTitle: function (e) {
  100. const name = e.currentTarget.dataset.value
  101. if(name == '活动'){
  102. wx.navigateToMiniProgram({
  103. appId: 'wx4efd688fa52ba3f7',
  104. path: 'pages/welcome/welcome?isPage=active',
  105. // extraData: {
  106. // foo: 'bar'
  107. // },
  108. envVersion: 'release',
  109. success(res) {
  110. // 打开成功
  111. wx.redirectTo({
  112. url: '/pages/index/index',
  113. })
  114. }
  115. })
  116. return
  117. }
  118. const phone = wx.getStorageSync('phone')
  119. if (e.currentTarget.dataset.index == this.data.curIndex) {
  120. return
  121. }
  122. const index = e.currentTarget.dataset.index
  123. wx.redirectTo({
  124. url: this.data.titleList[index].path
  125. })
  126. },
  127. //授权手机号
  128. getPhoneNumber: function (e) {
  129. url = e.currentTarget.dataset.url
  130. let that = this;
  131. if (e.detail.errMsg == "getPhoneNumber:ok") {
  132. util.doPost(
  133. 'getPhoneNumber', {
  134. encryptedData: e.detail.encryptedData,
  135. iv: e.detail.iv,
  136. openId: app.globalData.openId,
  137. }
  138. ).then(rs => {
  139. if (rs.success > 0) {
  140. wx.setStorageSync('phone', rs.data.phoneNumber)
  141. this.setData({
  142. phone: rs.data.phoneNumber
  143. })
  144. wx.redirectTo({
  145. url: e.currentTarget.dataset.url,
  146. })
  147. }
  148. })
  149. }
  150. that.setData({
  151. model: false,
  152. localtion: true
  153. })
  154. },
  155. }
  156. })