tool.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. };
  80. // 判断是否完善个人信息
  81. const isFinishInfo = () => {
  82. return new Promise((resolve, reject) => {
  83. wx.request({
  84. url: util.globalData.publicUrl + '/wx/member/' + wx.getStorageSync('openId') + '/info',
  85. method: "get",
  86. success: (res) => {
  87. // console.log(res,'99999999999999999')
  88. if (res.data.code == 0&&res.data.info.name&&res.data.info.height) {
  89. resolve(res.data.info)
  90. } else {
  91. reject(res.data.info)
  92. }
  93. }
  94. })
  95. })
  96. };
  97. // 判断是否完善择偶条件
  98. const isFinishTargetInfo = () => {
  99. return new Promise((resolve, reject) => {
  100. wx.request({
  101. url: util.globalData.publicUrl + '/wx/member/' + wx.getStorageSync('openId') + '/standard',
  102. method: "get",
  103. success: (res) => {
  104. console.log(res)
  105. if (res.data.code == 0) {
  106. resolve(res.data.standard);
  107. } else {
  108. reject(res.data.code)
  109. }
  110. }
  111. })
  112. })
  113. };
  114. module.exports = {
  115. openidStatus,
  116. formDetails,
  117. formatTime,
  118. isLogin,
  119. isFinishInfo,
  120. isFinishTargetInfo
  121. }