baseUtils.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. var netUtil = require('network.js')
  2. var baseUrl = require('wxconstant.js').BaseUrl()
  3. var getUrl = require('wxconstant.js').getUrl
  4. var dateutil = require('DateTime.js')
  5. //公用获取openid方法
  6. function getComOpenid(){
  7. var openid
  8. wx.login({
  9. success: function (res) {
  10. var url = baseUrl + getUrl.getOpenid
  11. if (res.code) {
  12. var data = {
  13. code: res.code
  14. }
  15. netUtil.requestLoading(url, data, '正在请求...', 'GET', function (res) {
  16. if (res.data) {
  17. if (res.data.data.openid) {
  18. openid = res.data.data.openid
  19. wx.setStorageSync('openid', openid)
  20. }
  21. }
  22. }, function (res) {
  23. wx.showToast({
  24. title: '数据获取失败',
  25. icon: 'none',
  26. duration: 2000
  27. })
  28. })
  29. }
  30. }
  31. })
  32. return openid
  33. }
  34. /**
  35. * 公共获取用户信息的方法
  36. */
  37. function getPersonlEmp(){
  38. var data = { openid: wx.getStorageSync('openid') }
  39. var url = baseUrl + getUrl.getEmp
  40. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  41. if(res.data.success && res.data.data){
  42. wx.setStorageSync("myInfoData", res.data.data)
  43. // console.log('myInfoData', wx.getStorageSync('myInfoData'))
  44. }
  45. }, function (res) {
  46. wx.showToast({
  47. title: '加载数据失败',
  48. icon: 'none',
  49. duration: 2000
  50. })
  51. })
  52. }
  53. /**
  54. * 公共获取用户是否关联绑定公司信息
  55. */
  56. function judgeisReg(){
  57. var data = {
  58. openid: wx.getStorageSync('openid'),
  59. }
  60. var url = baseUrl + getUrl.getRank
  61. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  62. if (res.data.success) {
  63. var isregistered = res.data.data.isregistered
  64. wx.setStorageSync('isregistered', isregistered)
  65. if (!isregistered){
  66. wx.showModal({
  67. title: '提示',
  68. content: '您当前尚未与企业关联绑定,是否立即去绑定?',
  69. success: function (res) {
  70. if (res.confirm) {
  71. wx.navigateTo({
  72. url: '../bindphone/bindphone',
  73. })
  74. } else if (res.cancel) {
  75. return
  76. }
  77. }
  78. })
  79. }
  80. }
  81. }, function (res) {
  82. wx.showToast({
  83. title: '加载数据失败',
  84. icon: 'none',
  85. duration: 2000
  86. })
  87. })
  88. }
  89. function getAccessToken(){
  90. var data = { }
  91. var url = baseUrl + getUrl.getAccessToken
  92. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  93. if(res.data.success && res.data.data){
  94. var access_token = JSON.parse(res.data.data).access_token
  95. console.log('access_token=', access_token)
  96. wx.setStorageSync('access_token', access_token)
  97. // console.log('access_token=', wx.getStorageSync('access_token'))
  98. }
  99. }, function (res) {
  100. wx.showToast({
  101. title: '加载数据失败',
  102. icon: 'none',
  103. duration: 2000
  104. })
  105. })
  106. }
  107. module.exports = {
  108. judgeisReg: judgeisReg,
  109. getComOpenid: getComOpenid,
  110. getPersonlEmp: getPersonlEmp,
  111. getAccessToken: getAccessToken
  112. }