tool.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const util = require('../utils/util.js');
  2. const openidStatus = () => {
  3. if (wx.getStorageSync('openId')) {
  4. return [wx.getStorageSync('openId'), wx.getStorageSync('sessionKey')]
  5. } else {
  6. return new Promise((resolve, reject) => {
  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. return [res.data.openid, res.data.sessionKey];
  22. }
  23. }
  24. });
  25. } else {
  26. console.log('获取用户登录态失败!' + res.errMsg);
  27. }
  28. }
  29. })
  30. })
  31. }
  32. };
  33. function formatTime(date) {
  34. var year = date.getFullYear()
  35. return year
  36. }
  37. const formDetails = (type) => {
  38. return new Promise((resolve, reject) => {
  39. wx.request({
  40. url: util.globalData.publicUrl + '/wx/member/'+ wx.getStorageSync('openId') +'/options',
  41. method: "GET",
  42. data: {
  43. type
  44. },
  45. success: res => {
  46. console.log(res)
  47. if (res.data.code == 0) {
  48. if(res.data.options){
  49. let labelArr = res.data.options.map((obj, index) => {
  50. return obj.dictLabel;
  51. })
  52. let valueArr = res.data.options.map((obj, index) => {
  53. return obj.dictValue;
  54. })
  55. resolve([labelArr,valueArr])
  56. }
  57. }else{
  58. reject(res)
  59. }
  60. }
  61. })
  62. })
  63. };
  64. module.exports = {
  65. openidStatus,
  66. formDetails,
  67. formatTime
  68. }