tool.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. const util = require('../utils/util.js');
  2. const openidStatus = () => {
  3. return new Promise((resolve, reject) => {
  4. wx.login({
  5. success: (res) => {
  6. if (res.code) {
  7. wx.request({
  8. url: util.globalData.publicUrl + '/wx/user/wxbfa171fdd4000e03/login',
  9. method: "GET",
  10. data: {
  11. code: res.code
  12. },
  13. success: res => {
  14. console.log(res.data.openid,'我是wx.login的openid')
  15. console.log(res.data.sessionKey,'我是wx.login的sessionKey')
  16. if (res.statusCode == 200) {
  17. wx.setStorageSync('openId', res.data.openid)
  18. wx.setStorageSync('sessionKey', res.data.sessionKey)
  19. resolve([res.data.openid, res.data.sessionKey]);
  20. }
  21. }
  22. });
  23. } else {
  24. reject(res.errMsg);
  25. }
  26. }
  27. })
  28. })
  29. };
  30. function formatTime(date) {
  31. var year = date.getFullYear()
  32. return year
  33. }
  34. const formDetails = (type) => {
  35. return new Promise((resolve, reject) => {
  36. wx.request({
  37. url: util.globalData.publicUrl + '/wx/member/' + wx.getStorageSync('openId') + '/options',
  38. method: "GET",
  39. data: {
  40. type
  41. },
  42. success: res => {
  43. // console.log(res)
  44. if (res.data.code == 0) {
  45. if (res.data.options) {
  46. let labelArr = res.data.options.map((obj, index) => {
  47. return obj.dictLabel;
  48. })
  49. let valueArr = res.data.options.map((obj, index) => {
  50. return obj.dictValue;
  51. })
  52. resolve([labelArr, valueArr])
  53. }
  54. } else {
  55. reject(res)
  56. }
  57. }
  58. })
  59. })
  60. };
  61. // 判断是否登录
  62. const isLogin = () => {
  63. // return new Promise((resolve, reject) => {
  64. // wx.getSetting({
  65. // success: res => {
  66. // console.log(res)
  67. // if (res.authSetting['scope.userInfo']) {
  68. // wx.getUserInfo({
  69. // success: res => {
  70. // resolve(res)
  71. // }
  72. // })
  73. // } else {
  74. // reject(false)
  75. // }
  76. // }
  77. // })
  78. // })
  79. return new Promise((resolve, reject) => {
  80. wx.request({
  81. url: util.globalData.publicUrl + '/wx/member/' + wx.getStorageSync('openId') + '/info',
  82. method: "get",
  83. success: (res) => {
  84. if (res.data.code == 0&&res.data.info.avatar&&res.data.info.nickName) {
  85. resolve(true)
  86. } else {
  87. reject(false)
  88. }
  89. }
  90. })
  91. })
  92. };
  93. // 判断是否完善个人信息
  94. const isFinishInfo = () => {
  95. return new Promise((resolve, reject) => {
  96. wx.request({
  97. url: util.globalData.publicUrl + '/wx/member/' + wx.getStorageSync('openId') + '/info',
  98. method: "get",
  99. success: (res) => {
  100. // console.log(res,'99999999999999999')
  101. if (res.data.code == 0&&res.data.info.name&&res.data.info.height) {
  102. resolve(res.data.info)
  103. } else {
  104. reject(res.data.info)
  105. }
  106. }
  107. })
  108. })
  109. };
  110. // 判断是否完善择偶条件
  111. const isFinishTargetInfo = () => {
  112. return new Promise((resolve, reject) => {
  113. wx.request({
  114. url: util.globalData.publicUrl + '/wx/member/' + wx.getStorageSync('openId') + '/standard',
  115. method: "get",
  116. success: (res) => {
  117. console.log(res)
  118. if (res.data.code == 0) {
  119. resolve(res.data.standard);
  120. } else {
  121. reject(res.data.code)
  122. }
  123. }
  124. })
  125. })
  126. };
  127. module.exports = {
  128. openidStatus,
  129. formDetails,
  130. formatTime,
  131. isLogin,
  132. isFinishInfo,
  133. isFinishTargetInfo
  134. }