抖音小程序C端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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