抖音c端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 regels
3.5 KiB

  1. const Http = require("./utils/HttpBasics.js")
  2. const config = require("./config/config.js");
  3. App({
  4. data: {},
  5. globalData: {
  6. token: null,
  7. imgHttps: 'https://formall.oss-accelerate.aliyuncs.com/douyin/drawable-xhdpi/',
  8. platform: null, //手机型号
  9. systemInfo: "",
  10. curHtml: "",
  11. marketName: "",
  12. mouldType: 1,
  13. appId: config.weapp.AppId,
  14. selected: 0,
  15. goHomeUrl: "/index/index",
  16. type: "", //存放跳转标记
  17. previewFlag: false, //解决图片预览调用noshow
  18. skipUrl: "", //存放授权跳转地址
  19. skip: "",
  20. avatarUrl: "", //用户头像
  21. nickName: "", //用户姓名
  22. templateId: [], //订阅消息模板id
  23. ifshowtab: false,
  24. },
  25. onLaunch: function () {
  26. let that = this
  27. tt.setStorageSync('locationFlag', true);
  28. try {
  29. var res = tt.getSystemInfoSync();
  30. that.statusBarHeight = res.statusBarHeight
  31. console.log(`手机型号为`, that.statusBarHeight);
  32. this.globalData.platform = res.platform
  33. } catch (error) {
  34. console.log(`获取系统信息失败`);
  35. }
  36. that.login();
  37. tt.getSystemInfo({
  38. success(res) {
  39. console.log(res, "**");
  40. that.globalData.systemInfo = res
  41. },
  42. fail(res) {
  43. console.log(`getSystemInfo 调用失败`);
  44. },
  45. });
  46. },
  47. statusBarHeight: 0,
  48. getTemplateId(that) {
  49. // console.log("隐藏")
  50. // tt.hideTabBar()
  51. Http.get({
  52. url: config.api.templateId,
  53. data: {
  54. pageNum: 1,
  55. pageSize: 100
  56. }
  57. }).then(res => {
  58. const {
  59. code,
  60. data
  61. } = res
  62. if (code == 200) {
  63. // this.setData({
  64. // templateId: data.list
  65. // })
  66. that.globalData.templateId = data.list
  67. } else {
  68. return
  69. }
  70. })
  71. },
  72. login() {
  73. console.log('login!');
  74. let that = this;
  75. tt.login({
  76. success: (res => {
  77. let {
  78. code
  79. } = res
  80. console.log(code, "code");
  81. Http.post({
  82. url: config.api.login,
  83. data: {
  84. code: code,
  85. appId: that.globalData.appId,
  86. systemInfo: JSON.stringify(this.globalData.systemInfo)
  87. }
  88. }).then(res => {
  89. tt.setStorageSync("openId", res.data.openId);
  90. if (res.data.mall) {
  91. that.globalData.marketName = res.data.mall.name ? res.data.mall.name : ""
  92. }
  93. that.globalData.mouldType = res.data.mouldType ? res.data.mouldType : 0;
  94. if (res.data.subMalls) {
  95. const squareList = JSON.parse(res.data.subMalls)
  96. tt.setStorageSync("squareList", squareList)
  97. if (res.data.mall) {
  98. tt.setStorageSync("selectedMall", res.data.mall.tenantId)
  99. }
  100. }
  101. Http.setToken(res.data.token);
  102. that.globalData.token = res.data.token
  103. // that.getTemplateId(that); //获取订阅消息模板id
  104. if (that.tokenCallback) {
  105. that.tokenCallback(res.data.token);
  106. }
  107. }).catch(err => {
  108. console.log(err, 'getUserInfo');
  109. tt.showModal({
  110. title: '提示',
  111. showCancel: false,
  112. content: '登录失败,请重新尝试',
  113. success: (res) => {
  114. if (res.cancel) {
  115. //点击取消,默认隐藏弹框
  116. } else {
  117. //点击确定
  118. tt.reLaunch({
  119. url: '/pages/index/index',
  120. })
  121. }
  122. }
  123. });
  124. })
  125. }),
  126. });
  127. }
  128. })