酷炫小程序

app.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //app.js
  2. var http = require('http/request.js');
  3. var detail = require('http/detail.js');
  4. App({
  5. data: {
  6. hasLogin:false,
  7. userId:'',
  8. channel:"blackWhite",
  9. code:'',
  10. shareMsg: "找我,帮你省钱😝",
  11. failed: false,
  12. winHeight:''
  13. },
  14. onLaunch: function () {
  15. // 展示本地存储能力
  16. this.windowInfo();
  17. },
  18. //页面现实加载,获取群信息
  19. onShow: function (options) {
  20. },
  21. //获取系统消息
  22. windowInfo: function () {
  23. var that = this;
  24. wx.getSystemInfo({
  25. success: function (res) {
  26. that.data.winHeight=res.windowHeight
  27. }
  28. });
  29. },
  30. // 登录
  31. login(cb) {
  32. var that = this;
  33. wx.login({
  34. success: res => {
  35. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  36. if (res.code) {
  37. //发起网络请求
  38. cb?cb(res.code):'';
  39. } else {
  40. console.log("获取用户登录态失败!" + res.errMsg)
  41. that.login();
  42. }
  43. }
  44. })
  45. },
  46. globalData: {
  47. userInfo: null
  48. },
  49. func: {
  50. req: http.req
  51. },
  52. detailFunc: {
  53. detail: detail.detail
  54. },
  55. //跳转详情页
  56. goToDetail: function (e,zuId) {
  57. var goods_id = e.currentTarget.dataset.goods_id;
  58. var name = e.currentTarget.dataset.name;
  59. var category_id = zuId;
  60. wx.navigateTo({
  61. url: '/pages/detail/detail?goods_id=' + goods_id + '&goods_name=' + name + "&category_id=" + category_id,
  62. })
  63. }
  64. })