抖音c端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.4 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. try {
  28. var res = tt.getSystemInfoSync();
  29. that.statusBarHeight = res.statusBarHeight
  30. console.log(`手机型号为`,that.statusBarHeight);
  31. this.globalData.platform = res.platform
  32. } catch (error) {
  33. console.log(`获取系统信息失败`);
  34. }
  35. that.logn();
  36. tt.getSystemInfo({
  37. success(res) {
  38. console.log(res,"**");
  39. that.globalData.systemInfo = res
  40. },
  41. fail(res) {
  42. console.log(`getSystemInfo 调用失败`);
  43. },
  44. });
  45. },
  46. statusBarHeight: 0,
  47. getTemplateId(that) {
  48. // console.log("隐藏")
  49. // tt.hideTabBar()
  50. Http.get({
  51. url: config.api.templateId,
  52. data: {
  53. pageNum: 1,
  54. pageSize: 100
  55. }
  56. }).then(res => {
  57. const {
  58. code,
  59. data
  60. } = res
  61. if (code == 200) {
  62. // this.setData({
  63. // templateId: data.list
  64. // })
  65. that.globalData.templateId = data.list
  66. } else {
  67. return
  68. }
  69. })
  70. },
  71. logn(){
  72. let that = this;
  73. tt.login({
  74. success:(res=>{
  75. let {code} = res
  76. console.log(code,"code");
  77. Http.post({
  78. url:config.api.login,
  79. data:{
  80. code:code,
  81. appId:that.globalData.appId,
  82. systemInfo:JSON.stringify(this.globalData.systemInfo)
  83. }
  84. }).then(res=>{
  85. tt.setStorageSync("openId", res.data.openId);
  86. if (res.data.mall){
  87. that.globalData.marketName = res.data.mall.name ? res.data.mall.name : ""
  88. }
  89. that.globalData.mouldType = res.data.mouldType ? res.data.mouldType:0;
  90. if (res.data.subMalls) {
  91. const squareList = JSON.parse(res.data.subMalls)
  92. tt.setStorageSync("squareList", squareList)
  93. if (res.data.mall){
  94. tt.setStorageSync("selectedMall", res.data.mall.tenantId)
  95. }
  96. }
  97. Http.setToken(res.data.token);
  98. that.globalData.token = res.data.token
  99. that.getTemplateId(that);//获取订阅消息模板id
  100. if (that.tokenCallback) {
  101. that.tokenCallback(res.data.token);
  102. }
  103. }).catch(err=>{
  104. console.log(err);
  105. tt.showModal({
  106. title: '提示',
  107. showCancel: false,
  108. content: '登录失败,请重新尝试',
  109. success: (res) => {
  110. if (res.cancel) {
  111. //点击取消,默认隐藏弹框
  112. } else {
  113. //点击确定
  114. tt.reLaunch({
  115. url: '/pages/index/index',
  116. })
  117. }
  118. }
  119. });
  120. })
  121. }),
  122. });
  123. }
  124. })