personal.js 7.1 KB

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