tool.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const util = require('../utils/util.js');
  2. const openidStatus = () => {
  3. return new Promise((resolve, reject) => {
  4. // if (wx.getStorageSync('openId')) {
  5. // resolve([wx.getStorageSync('openId'), wx.getStorageSync('sessionKey')]);
  6. // } else {
  7. wx.login({
  8. success: (res) => {
  9. if (res.code) {
  10. wx.request({
  11. url: util.globalData.publicUrl + '/wx/user/wxbfa171fdd4000e03/login',
  12. method: "GET",
  13. data: {
  14. code: res.code
  15. },
  16. success: res => {
  17. console.log(res)
  18. if (res.statusCode == 200) {
  19. wx.setStorageSync('openId', res.data.openid)
  20. wx.setStorageSync('sessionKey', res.data.sessionKey)
  21. resolve([res.data.openid, res.data.sessionKey]);
  22. }
  23. }
  24. });
  25. } else {
  26. reject(res.errMsg);
  27. }
  28. }
  29. })
  30. })
  31. };
  32. function formatTime(date) {
  33. var year = date.getFullYear()
  34. return year
  35. }
  36. const formDetails = (type) => {
  37. return new Promise((resolve, reject) => {
  38. wx.request({
  39. url: util.globalData.publicUrl + '/wx/member/' + wx.getStorageSync('openId') + '/options',
  40. method: "GET",
  41. data: {
  42. type
  43. },
  44. success: res => {
  45. // console.log(res)
  46. if (res.data.code == 0) {
  47. if (res.data.options) {
  48. let labelArr = res.data.options.map((obj, index) => {
  49. return obj.dictLabel;
  50. })
  51. let valueArr = res.data.options.map((obj, index) => {
  52. return obj.dictValue;
  53. })
  54. resolve([labelArr, valueArr])
  55. }
  56. } else {
  57. reject(res)
  58. }
  59. }
  60. })
  61. })
  62. };
  63. // 判断是否完善个人信息
  64. const isFinishInfo = () => {
  65. return new Promise((resolve, reject) => {
  66. wx.request({
  67. url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/info',
  68. method: "get",
  69. success: (res) => {
  70. console.log(res)
  71. if (res.data.code == 0) {
  72. resolve(res.data.info)
  73. } else {
  74. reject(res.code)
  75. }
  76. }
  77. })
  78. })
  79. };
  80. module.exports = {
  81. openidStatus,
  82. formDetails,
  83. formatTime,
  84. isFinishInfo
  85. }