personal.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. const app = require('../../utils/util.js');
  2. const tool = require('../../utils/tool.js');
  3. Page({
  4. data: {
  5. avatarUrl: '../../images/morenImg.jpg',
  6. tabArr: [{
  7. name: '我的信息',
  8. img: '../../images/icon1.png',
  9. url: '/pages/InfoType/InfoType'
  10. }, {
  11. name: '我的活动',
  12. img: '../../images/icon2.png',
  13. url: '/pages/myActive/myActive'
  14. }, {
  15. name: '心动0次',
  16. img: '../../images/icon3.png',
  17. url: ''
  18. }, {
  19. name: '被心动0次',
  20. img: '../../images/icon4.png',
  21. url: ''
  22. },
  23. // {
  24. // name: '投诉',
  25. // img: '../../images/icon5.png',
  26. // url: '/pages/complaint/complaint'
  27. // }, {
  28. // name: '推荐好友',
  29. // img: '../../images/icon6.png',
  30. // url: '/pages/share/share'
  31. // }
  32. ]
  33. },
  34. goTab(e) {
  35. wx.navigateTo({
  36. url: e.currentTarget.dataset.src
  37. })
  38. },
  39. onShareAppMessage: function (options) {
  40. console.log(options)
  41. var that = this;
  42. // 设置菜单中的转发按钮触发转发事件时的转发内容
  43. var shareObj = {
  44. title: "月合文化", // 默认是小程序的名称(可以写slogan等)
  45. path: '/pages/personal/personal', // 默认是当前页面,必须是以‘/’开头的完整路径
  46. imageUrl: '../../images/photo.jpg', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
  47. success: function (res) {
  48. console.log(res)
  49. // 转发成功之后的回调
  50. if (res.errMsg == 'shareAppMessage:ok') {}
  51. },
  52. fail: function () {
  53. // 转发失败之后的回调
  54. if (res.errMsg == 'shareAppMessage:fail cancel') {
  55. // 用户取消转发
  56. } else if (res.errMsg == 'shareAppMessage:fail') {
  57. // 转发失败,其中 detail message 为详细失败信息
  58. }
  59. }
  60. }
  61. // 来自页面内的按钮的转发
  62. if (options.from == 'button') {
  63. var eData = options.target.dataset;
  64. console.log(eData.name); // shareBtn
  65. // 此处可以修改 shareObj 中的内容
  66. shareObj.path = '/pages/btnname/btnname?btn_name=' + eData.name;
  67. }
  68. // 返回shareObj
  69. return shareObj;
  70. },
  71. /**
  72. * 生命周期函数--监听页面加载
  73. */
  74. bindGetUserInfo: function (e) {
  75. console.log(e.detail.userInfo)
  76. this.setData({
  77. nick: e.detail.userInfo.nickName,
  78. avatarUrl: e.detail.userInfo.avatarUrl
  79. })
  80. this.upload(e.detail.userInfo.nickName, e.detail.userInfo.avatarUrl);
  81. // 直接跳转页面(拒绝了授权)
  82. // wx.reLaunch({
  83. // url: '/pages/menu/homePage/homePage',
  84. // })
  85. },
  86. getNick() {
  87. wx.getSetting({
  88. success: (res) => {
  89. if (res.authSetting['scope.userInfo']) {
  90. wx.getUserInfo({
  91. success: (res) => {
  92. this.setData({
  93. nick: res.userInfo.nickName,
  94. avatarUrl: res.userInfo.avatarUrl
  95. })
  96. }
  97. })
  98. } else {
  99. console.log(res)
  100. }
  101. }
  102. })
  103. },
  104. upload(nickName, avatar) {
  105. wx.request({
  106. url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/info',
  107. method: "POST",
  108. header: {
  109. 'content-type': 'application/x-www-form-urlencoded',
  110. },
  111. data: {
  112. nickName,
  113. avatar
  114. },
  115. success: (res) => {
  116. console.log(res)
  117. if (res.data.code == 0) {
  118. console.log('上传头像昵称成功')
  119. }
  120. }
  121. })
  122. },
  123. getTimes() {
  124. let myHeartTimes = 'tabArr[2].name'
  125. wx.request({
  126. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/0/myHearts',
  127. method: "get",
  128. success: (res) => {
  129. if (res.data.code == 0) {
  130. this.setData({
  131. [myHeartTimes]: '心动' + res.data.heartCount + '次'
  132. })
  133. }
  134. console.log(this.data.tabArr[2].name)
  135. }
  136. })
  137. let myHeartedTimes = 'tabArr[3].name'
  138. wx.request({
  139. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/0/myHearted',
  140. method: "get",
  141. success: (res) => {
  142. if (res.data.code == 0) {
  143. this.setData({
  144. [myHeartedTimes]: '被心动' + res.data.heartedCount + '次'
  145. })
  146. console.log(this.data.tabArr[3].name)
  147. }
  148. }
  149. })
  150. },
  151. getPhoneNumber(e) {
  152. console.log(e)
  153. console.log(e.detail.errMsg == "getPhoneNumber:ok");
  154. if (e.detail.errMsg == "getPhoneNumber:ok") {
  155. wx.request({
  156. url: app.globalData.publicUrl + '/wx/user/wxbfa171fdd4000e03/phone',
  157. // data: {
  158. // encryptedData: e.detail.encryptedData,
  159. // iv: e.detail.iv,
  160. // sessionKey: that.data.session_key,
  161. // uid: "",
  162. // },
  163. data: {
  164. appid: 'wxbfa171fdd4000e03',
  165. sessionKey: this.data.sessionKey,
  166. signature,
  167. rawData,
  168. encryptedData: e.detail.encryptedData,
  169. iv: e.detail.iv
  170. },
  171. method: "get",
  172. success: function (res) {
  173. console.log(res);
  174. }
  175. })
  176. }
  177. // console.log(e.detail.iv)
  178. // console.log(e.detail.encryptedData)
  179. },
  180. async onShow() {
  181. tool.openidStatus().then(result => {
  182. this.setData({
  183. openid: result[0],
  184. sessionkey: result[1]
  185. })
  186. this.getNick();
  187. this.getTimes();
  188. })
  189. },
  190. /**
  191. * 生命周期函数--监听页面初次渲染完成
  192. */
  193. onReady: function () {
  194. },
  195. onHide: function () {
  196. },
  197. /**
  198. * 生命周期函数--监听页面卸载
  199. */
  200. onUnload: function () {
  201. },
  202. /**
  203. * 页面相关事件处理函数--监听用户下拉动作
  204. */
  205. onPullDownRefresh: function () {
  206. },
  207. /**
  208. * 页面上拉触底事件的处理函数
  209. */
  210. onReachBottom: function () {
  211. },
  212. onShareTimeline: function () {
  213. return {
  214. title: '测试',
  215. query: {
  216. id: 0
  217. },
  218. imageUrl: '../../images/icon1.png'
  219. }
  220. },
  221. })