tools.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const app = getApp();
  2. const request = require('./request.js');
  3. function toLogin() {
  4. wx.showModal({
  5. title: '提示',
  6. content: '您还未登录',
  7. showCancel: false,
  8. success: (res) => {
  9. if (res.confirm) {
  10. wx.navigateTo({
  11. url: '/pages/login/login',
  12. })
  13. }
  14. }
  15. })
  16. };
  17. const isLogin = () => {
  18. return new Promise((resolve, reject) => {
  19. const openId = wx.getStorageSync('openid');
  20. if (openId) {
  21. let options = {
  22. url: 'resource/miniapp/user/isExist',
  23. data: {openId},
  24. method: 'post'
  25. }
  26. let res = request.query(options);
  27. res.then((res2) => {
  28. if (res2.data.code === 200 && res2.data.data.length !== 0) {
  29. app.globalData.type
  30. app.globalData.type = res2.data.data.type;
  31. resolve(true);
  32. } else {
  33. toLogin();
  34. reject(false);
  35. }
  36. }, (error) => {
  37. console.log(error);
  38. })
  39. } else {
  40. toLogin();
  41. reject(false);
  42. }
  43. })
  44. };
  45. module.exports = {
  46. isLogin
  47. }