personal.js 6.0 KB

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