|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- const Http = require("./utils/HttpBasics.js")
- const config = require("./config/config.js");
- App({
- data:{},
- globalData:{
- token: null,
- imgHttps: 'https://formall.oss-accelerate.aliyuncs.com/douyin/drawable-xhdpi/',
- platform:null,//手机型号
- systemInfo:"",
- curHtml:"",
- marketName:"",
- mouldType:1,
- appId:config.weapp.AppId,
- selected:0,
- goHomeUrl:"/index/index",
- type:"",//存放跳转标记
- previewFlag: false, //解决图片预览调用noshow
- skipUrl:"",//存放授权跳转地址
- skip:"",
- avatarUrl:"",//用户头像
- nickName:"",//用户姓名
- templateId:[],//订阅消息模板id
- ifshowtab:false,
- },
- onLaunch: function () {
- let that = this
-
- try {
- var res = tt.getSystemInfoSync();
- that.statusBarHeight = res.statusBarHeight
- console.log(`手机型号为`,that.statusBarHeight);
- this.globalData.platform = res.platform
- } catch (error) {
- console.log(`获取系统信息失败`);
- }
- that.logn();
- tt.getSystemInfo({
- success(res) {
- console.log(res,"**");
- that.globalData.systemInfo = res
-
- },
- fail(res) {
- console.log(`getSystemInfo 调用失败`);
- },
- });
-
- },
-
- statusBarHeight: 0,
- getTemplateId(that) {
- // console.log("隐藏")
- // tt.hideTabBar()
- Http.get({
- url: config.api.templateId,
- data: {
- pageNum: 1,
- pageSize: 100
- }
- }).then(res => {
- const {
- code,
- data
- } = res
- if (code == 200) {
- // this.setData({
- // templateId: data.list
- // })
- that.globalData.templateId = data.list
- } else {
- return
- }
- })
- },
- logn(){
- let that = this;
- tt.login({
- success:(res=>{
- let {code} = res
- console.log(code,"code");
- Http.post({
- url:config.api.login,
- data:{
- code:code,
- appId:that.globalData.appId,
- systemInfo:JSON.stringify(this.globalData.systemInfo)
- }
- }).then(res=>{
- tt.setStorageSync("openId", res.data.openId);
- if (res.data.mall){
- that.globalData.marketName = res.data.mall.name ? res.data.mall.name : ""
- }
- that.globalData.mouldType = res.data.mouldType ? res.data.mouldType:0;
- if (res.data.subMalls) {
- const squareList = JSON.parse(res.data.subMalls)
- tt.setStorageSync("squareList", squareList)
- if (res.data.mall){
- tt.setStorageSync("selectedMall", res.data.mall.tenantId)
- }
-
- }
- Http.setToken(res.data.token);
- that.globalData.token = res.data.token
- that.getTemplateId(that);//获取订阅消息模板id
- if (that.tokenCallback) {
- that.tokenCallback(res.data.token);
- }
-
- }).catch(err=>{
- console.log(err);
- tt.showModal({
- title: '提示',
- showCancel: false,
- content: '登录失败,请重新尝试',
- success: (res) => {
- if (res.cancel) {
- //点击取消,默认隐藏弹框
- } else {
- //点击确定
- tt.reLaunch({
- url: '/pages/index/index',
- })
- }
- }
- });
- })
-
- }),
-
- });
- }
- })
|