"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); var promise_wx_api_1 = require("./utils/promise-wx-api"); var tools_1 = require("./utils/tools"); var config_1 = require("./config/config"); App({ globalData: { appLaunchTime: "", previewImage: false, landing: false, extAppid: "", token: "", isNoviceEnv: false, isPhoneAccount: false, isLogined: false, customerId: "", gridId: "", agencyId: "", orgInfo: { orgId: "", orgName: "", orgType: "", }, latitude: 0, longitude: 0, userRoleList: [], currentGridName: "", userInfo: { userStreetTrueName: "", userStreetName: "", realName: "", nickname: "", userHeadPhoto: "", }, userPhone: "", pageCustomerData: {}, customOptions: {}, tempData: { subjectTitle: "", subjectSuggest: "", invitationId: "", }, isHintedFillIdNum: false, }, onLaunch: function () { return __awaiter(this, void 0, void 0, function () { var menuButtonObject, extConfig; var _this = this; return __generator(this, function (_a) { setTimeout(function () { }, 100); this.globalData.appLaunchTime = new Date().getTime(); menuButtonObject = wx.getMenuButtonBoundingClientRect(); wx.getSystemInfo({ success: function (res) { var statusBarHeight = res.statusBarHeight, navTop = menuButtonObject.top, navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2; _this.globalData.navHeight = navHeight; _this.globalData.statusHeight = statusBarHeight; _this.globalData.navTop = navTop; _this.globalData.windowHeight = res.windowHeight; }, fail: function (err) { console.log(err); }, }); extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}; console.log("extConfig", extConfig); this.globalData.extAppid = extConfig.extAppid; wx.setStorageSync("extAppid", extConfig.extAppid); this.syncLocalAccountInfo(); return [2]; }); }); }, loadFontFace: function () { wx.loadFontFace({ global: true, family: "Source Han Serif SC", scopes: ["webview", "native"], source: 'url("' + config_1.apiUrl.slice(0, -4) + 'fonts/syst/SourceHanSerifSC-Regular.otf")', success: function (res) { console.log(" 字体加载------------------------------------------res ", res); }, fail: function (err) { console.log(" 字体加载------------------------------------------err ", err); }, }); wx.loadFontFace({ global: true, family: "Source Han Serif SC", scopes: ["webview", "native"], desc: { weight: "bold", }, source: 'url("' + config_1.apiUrl.slice(0, -4) + '/fonts/syst/SourceHanSerifCN-Bold.otf")', success: function (res) { console.log(" 重体---------------------res ", res); }, fail: function (err) { console.log(" 重体---------------------err ", err); }, }); }, doAfterLogin: tools_1.doAfterLogin, syncLocalAccountInfo: function () { this.globalData.isLogined = wx.getStorageSync("isLogined") === false ? false : true; if (this.globalData.isLogined) { this.globalData.isNoviceEnv = wx.getStorageSync("isNoviceEnv") || false; this.globalData.isPhoneAccount = wx.getStorageSync("isPhoneAccount") || false; if (this.globalData.isPhoneAccount) { this.globalData.token = wx.getStorageSync("token") || ""; } } return this.globalData.isLogined; }, setAccountInfo: function (obj) { var _this = this; if (obj === void 0) { obj = {}; } Object.keys(obj).forEach(function (k) { _this.globalData[k] = obj[k]; wx.setStorageSync(k, obj[k]); }); }, logoutRecord: function () { return __awaiter(this, void 0, void 0, function () { var _a, msg, data; return __generator(this, function (_b) { switch (_b.label) { case 0: return [4, promise_wx_api_1.wxRequestPost("auth/thirdlogin/delresitoken", {}, { isQuiet: true, })]; case 1: _a = _b.sent(), msg = _a.msg, data = _a.data.data; if (msg != "success" || data.code !== 0) { console.log("退出失败"); return [2, false]; } else { console.log("退出成功"); return [2, true]; } return [2]; } }); }); }, logout: function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: this.setAccountInfo({ token: "", isNoviceEnv: false, isPhoneAccount: false, isLogined: false, }); this.logoutRecord(); wx.showToast({ title: "退出成功", icon: "none", duration: 2000, }); return [4, tools_1.nextTick(1500)]; case 1: _a.sent(); this.toGuidePage(); return [2]; } }); }); }, toGuidePage: function () { wx.reLaunch({ url: "/pages/guide/guide", }); }, toGuidePageAfterHint: function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: wx.showToast({ title: "登录已失效", icon: "none", duration: 2000, }); return [4, tools_1.nextTick(1500)]; case 1: _a.sent(); this.toGuidePage(); return [2]; } }); }); }, loginbytoken: function () { return __awaiter(this, void 0, void 0, function () { var _a, msg, data; return __generator(this, function (_b) { switch (_b.label) { case 0: return [4, promise_wx_api_1.wxRequestPost("auth/thirdlogin/tonewtoken", {}, { isQuiet: false, })]; case 1: _a = _b.sent(), msg = _a.msg, data = _a.data.data; if (msg != "success" || data.code !== 0 || !data.data || !data.data.token) { console.log("换取token失败", msg); return [2, false]; } else { console.log("换取token成功", data.data.token); this.setAccountInfo({ token: data.data.token }); return [2, true]; } return [2]; } }); }); }, loginbywxcode: function () { return __awaiter(this, void 0, void 0, function () { var retWxLogin, extAppid, url, _a, msg, data; return __generator(this, function (_b) { switch (_b.label) { case 0: return [4, promise_wx_api_1.wxLogin({})]; case 1: retWxLogin = _b.sent(); console.log(retWxLogin); if (retWxLogin.msg != "success") { console.log("获取微信code失败:", retWxLogin); return [2, false]; } extAppid = wx.getStorageSync("extAppid"); url = extAppid ? "auth/thirdlogin/resilogin" : "auth/login/resiwxmp/loginbywxcode"; return [4, promise_wx_api_1.wxRequestPost(url, { wxCode: retWxLogin.data.code, app: "resi", client: "wxmp", encryptedData: "", iv: "", appId: extAppid, }, { hasToken: false, isQuiet: false, })]; case 2: _a = _b.sent(), msg = _a.msg, data = _a.data.data; if (msg != "success" || data.code !== 0) { console.log("登录失败", msg); return [2, false]; } else { console.log("登录成功", data.data.token); this.setAccountInfo({ token: data.data.token }); return [2, true]; } return [2]; } }); }); }, loginGetToken: function () { return __awaiter(this, void 0, void 0, function () { var isPhoneAccount; return __generator(this, function (_a) { switch (_a.label) { case 0: isPhoneAccount = this.globalData.isPhoneAccount; if (!isPhoneAccount) return [3, 2]; return [4, this.loginbytoken()]; case 1: if (!(_a.sent())) { this.toGuidePageAfterHint(); return [2, false]; } else { return [2, true]; } return [3, 4]; case 2: return [4, this.loginbywxcode()]; case 3: return [2, _a.sent()]; case 4: return [2]; } }); }); }, getLatestGridData: function (noSkip) { if (noSkip === void 0) { noSkip = false; } return __awaiter(this, void 0, void 0, function () { var extAppid, url, _a, msg, data; return __generator(this, function (_b) { switch (_b.label) { case 0: extAppid = wx.getStorageSync("extAppid"); url = extAppid ? "resi/mine/mygrid/latestgridinfo" : "resi/mine/mygrid/getlatestgridinfo"; return [4, promise_wx_api_1.wxRequestGet(url, { appId: extAppid }, { isQuiet: false, })]; case 1: _a = _b.sent(), msg = _a.msg, data = _a.data.data; if (msg != "success") { console.log(msg); return [2, false]; } else { if (data.code === 0) { if (data.data && data.data.gridId) { this.globalData.gridId = data.data.gridId; this.globalData.customerId = data.data.customerId; return [2, true]; } else { if (!noSkip) { console.log("找不到最近访问网格"); this.toGuidePage(); } return [2, false]; } } else { return [2, false]; } } return [2]; } }); }); }, enterGridData: function () { return __awaiter(this, void 0, void 0, function () { var _a, customerId, gridId, _b, msg, data; return __generator(this, function (_c) { switch (_c.label) { case 0: _a = this.globalData, customerId = _a.customerId, gridId = _a.gridId; return [4, promise_wx_api_1.wxRequestPost("resi/guide/user/entergrid", { customerId: customerId, gridId: gridId, }, { isQuiet: false, })]; case 1: _b = _c.sent(), msg = _b.msg, data = _b.data.data; if (msg != "success") { console.log(msg); return [2, false]; } else { if (data.code === 0) { wx.setStorageSync("userRoleList", data.data.userRoleList); wx.setStorageSync("gridName", data.data.currentGridName); this.globalData.agencyId = data.data.agencyId; this.globalData.userRoleList = data.data.userRoleList; this.globalData.currentGridName = data.data.currentGridName; this.globalData.orgInfo.orgId = data.data.orgId; this.globalData.orgInfo.orgName = data.data.orgName; this.globalData.orgInfo.orgType = data.data.orgType; this.globalData.userInfo.realName = data.data.realName; this.globalData.userInfo.nickname = data.data.nickname; this.globalData.userInfo.userStreetName = data.data.userStreetName || ""; this.globalData.userInfo.userStreetTrueName = data.data.userStreetTrueName || ""; this.globalData.userInfo.userHeadPhoto = data.data.userHeadPhoto; this.globalData.latitude = parseFloat(data.data.latitude); this.globalData.longitude = parseFloat(data.data.longitude); console.log("加入网格成功。", data.data); return [2, true]; } else { return [2, false]; } } return [2]; } }); }); }, switchGrid: function (customerId, gridId) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: this.globalData.customerId = customerId; this.globalData.gridId = gridId; return [4, this.enterGridData()]; case 1: _a.sent(); return [2]; } }); }); }, login: function () { return __awaiter(this, void 0, void 0, function () { var pages, route, _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: if (this.globalData.landing) return [2, 0]; pages = getCurrentPages(); console.log("当前页面", pages); if (pages.length > 0) { route = pages[pages.length - 1].route; if (route == "pages/guide/guide" || route == "pages/guide/novice/index" || route == "pages/guide/chooseGrid/chooseGrid") return [2, 0]; } this.globalData.landing = true; if (!this.globalData.isLogined) { this.toGuidePage(); return [2, 0]; } return [4, this.loginGetToken()]; case 1: _b = (_c.sent()); if (!_b) return [3, 3]; return [4, this.getLatestGridData()]; case 2: _b = (_c.sent()); _c.label = 3; case 3: _a = _b; if (!_a) return [3, 5]; return [4, this.enterGridData()]; case 4: _a = (_c.sent()); _c.label = 5; case 5: if (_a) { this.globalData.landing = false; return [2, 1]; } else { this.globalData.landing = false; return [2, 0]; } return [2]; } }); }); }, switchTab: function (tab) { var pages = getCurrentPages(); var mainPageIndex = pages.findIndex(function (item) { return item.route == "pages/main/index"; }); if (mainPageIndex !== -1) { var mainPageItem = pages.find(function (item) { return item.route == "pages/main/index"; }); mainPageItem.switchTab(tab); wx.navigateBack({ delta: pages.length - mainPageIndex - 1, }); } else { wx.reLaunch({ url: "/pages/main/index?tab=" + tab }); } }, });