抖音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.

174 lines
4.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. 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. /**
  73. * desc: 主题色配置
  74. * borderRadius:按钮圆角大小,默认 8rpx
  75. * backgroundColor:按钮背景色 + 退款原因选中背景色,默认 #FE2C55
  76. * fontColor:按钮字体颜色,默认 #ffffff
  77. */
  78. getThemeConfig() {
  79. return {
  80. borderRadius: '8rpx', // string
  81. backgroundColor: '#FE2C55', // string
  82. fontColor: '#ffffff', // string
  83. }
  84. },
  85. /**
  86. * desc: 获取手机号
  87. * params:加密数据
  88. * success:成功回调
  89. * fail: 失败回调
  90. */
  91. getPhoneNumber({
  92. params,
  93. success,
  94. fail
  95. }) {
  96. const {
  97. iv,
  98. encryptedData
  99. } = params;
  100. // ...
  101. // 开发者服务端解密 encryptedData,得到手机号
  102. // ...
  103. const result = {
  104. phoneNumber: '13580006666',
  105. }
  106. // 回调前端模板
  107. success(result)
  108. },
  109. login() {
  110. console.log('login!');
  111. let that = this;
  112. tt.login({
  113. success: (res => {
  114. let {
  115. code
  116. } = res
  117. console.log(code, "code");
  118. Http.post({
  119. url: config.api.login,
  120. data: {
  121. code: code,
  122. appId: that.globalData.appId,
  123. systemInfo: JSON.stringify(this.globalData.systemInfo)
  124. }
  125. }).then(res => {
  126. tt.setStorageSync("openId", res.data.openId);
  127. if (res.data.mall) {
  128. that.globalData.marketName = res.data.mall.name ? res.data.mall.name : ""
  129. }
  130. // that.globalData.mouldType = res.data.mouldType ? res.data.mouldType : 0;
  131. that.globalData.mouldType = 1;
  132. if (res.data.subMalls) {
  133. const squareList = JSON.parse(res.data.subMalls)
  134. tt.setStorageSync("squareList", squareList)
  135. if (res.data.mall) {
  136. tt.setStorageSync("selectedMall", res.data.mall.tenantId)
  137. }
  138. }
  139. Http.setToken(res.data.token);
  140. that.globalData.token = res.data.token
  141. // that.getTemplateId(that); //获取订阅消息模板id
  142. if (that.tokenCallback) {
  143. that.tokenCallback(res.data.token);
  144. }
  145. }).catch(err => {
  146. console.log(err, 'getUserInfo');
  147. tt.showModal({
  148. title: '提示',
  149. showCancel: false,
  150. content: '登录失败,请重新尝试',
  151. success: (res) => {
  152. if (res.cancel) {
  153. //点击取消,默认隐藏弹框
  154. } else {
  155. //点击确定
  156. tt.reLaunch({
  157. url: '/pages/index/index',
  158. })
  159. }
  160. }
  161. });
  162. })
  163. }),
  164. });
  165. }
  166. })