|
- "use strict";
- import MPServerless from '@alicloud/mpserverless-sdk';
- const mpserverless = new MPServerless(wx, {
- appId: 'wxf9cc799aa0afcd7c',
- spaceId: 'mp-95349d46-9739-4311-b061-756b5e0aa6f5',
- clientSecret: 'YJSzZOpzpRiFLpAtAdt/dQ==',
- endpoint: 'https://api.next.bspapp.com'
- });
- var n = require("@babel/runtime/helpers/typeof");
-
- require("./components/wxPromise.js");
-
- var e = require("./components/http"),
- i = require("./components/storage"),
- t = require("./services/authorize"),
- o = require("./services/diary"),
- s = require("./controllers/authorizeCtrl"),
- r = require("./controllers/diaryCtrl"),
- c = require("./config"),
- u = (require("./models/day"), require("./components/promise")),
- a = (require("./components/async"), require("./utils/ald-stat.js"), require("./controllers/authuserCtrl")),
- h = require("./components/utils"),
- l = require("./services/werun");
-
- require("./services/bi-werun");
-
- App({
- mpserverless: mpserverless,
- onLaunch: function onLaunch(n) {
- mpserverless.init();
- if (this.isAd = 0 === n.path.indexOf("pages/ad/ad"), this.isGroup = 0 === n.path.indexOf("pages/group/group"), this.isAddGroup = 0 === n.path.indexOf("pages/addGroup/addGroup"), this.isPomelo = 0 === n.path.indexOf("pages/pomelo/pomelo"), !(this.isAd || this.isGroup || this.isAddGroup || this.isPomelo)) {
- wx.clearStorageSync(), this.__events = {};
- var u = wx.getStorageSync("version");
- u || (u = c.v, wx.setStorageSync("version", u)), this.Version = u, this.Http = e.instance, this.Config = c, this.isready = !1, this.initializing = !1, this.skipLogin = !1, this.isAuthed = !1, this.denyWeRunData = !1, this.denyUserInfo = !1, this.Diary = r.instance, this.Authorize = s.instance, e.instance.onUnAuthorize(this.onUnAuthorize), s.adapter("network", t), s.adapter("storage", i.instance), r.adapter("network", o), r.adapter("storage", i.instance), s.instance.on("change", function () {
- r.instance.updateSetting({
- duration: s.instance.MeetYouUser.duration_of_menstruation,
- cycle: s.instance.MeetYouUser.menstrual_cycle
- });
- }), this.initialize(), s.instance.scene = n.scene;
- }
-
- this.globalData = {
- userOpenId: '',
- }
- },
- onShow: function onShow() {
- var n = this;
- console.log("App onShow"), this.isAd || this.isGroup || this.isAddGroup || this.isPomelo || (this.isready ? this.initDiary() : this.on("finishLogin", function () {
- n.initDiary();
- }), this.denyUserInfo && this.openAuth());
- },
- onHide: function onHide() {},
- ready: function ready(n) {
- this.isready ? this.fire("ready") : this.on("ready", n);
- },
- on: function on(n, e) {
- var i = this.__events[n] || [],
- t = !1;
- return i.forEach(function (n) {
- n === e && (t = !0);
- }), t || i.push(e), this.__events[n] = i, this;
- },
- fire: function fire(n, e) {
- var i = this.__events[n];
- return i && i.length && i.forEach(function (n) {
- n.call(this);
- }), this;
- },
- off: function off(n, e) {
- var i = this.__events[n] || [],
- t = [];
- return i.forEach(function (n) {
- n !== e && t.push(n);
- }), this.__events[n] = t, this;
- },
- updateSetting: function updateSetting(n) {
- return wx.showToast({
- title: "正在设置",
- icon: "loading",
- duration: 1e4
- }), new u(function (e, i) {
- s.instance.updateSetting(n).then(function (n) {
- wx.showToast({
- title: "设置成功",
- icon: "success"
- });
- }, function (n) {
- wx.showModal({
- showCancel: !1,
- title: "设置失败",
- content: "设置保存失败",
- success: function success(n) {
- n.confirm;
- }
- }), i();
- });
- });
- },
- onUnAuthorize: function onUnAuthorize() {
- wx.showModal({
- title: "提示",
- content: "授权失效!",
- success: function success(n) {}
- });
- },
- initialize: function initialize() {
- var n = this;
- s.checkAuthed().then(function (e) {
- e ? n.onAuthedUser().then(function () {
- console.log("set isready true"), n.isready = !0, n.fire("finishLogin");
- }).catch(function (n) {
- console.log("授权出错了", n);
- }) : (setTimeout(function () {
- wx.redirectTo({
- url: "/pages/authuser/authuser",
- success: function success(n) {
- console.log(n);
- },
- fail: function fail(n) {
- console.log("redirect", n);
- }
- });
- }, 200), a.on("userinfo:authed", function (e) {
- n.onAuthedUser().then(function () {
- console.log("set isready true"), n.isready = !0, n.fire("finishLogin");
- }).catch(function (n) {
- console.log("授权出错了", n);
- });
- }));
- });
- },
- onAuthedUser: function onAuthedUser() {
- var n = this;
- return this.initializing ? new u(function (n, e) {
- n();
- }) : (this.initializing = !0, new u(function (i, t) {
- s.initialize().then(function (o) {
- e.setAuthorization(s.instance.Authorization), s.instance.isLogin || (n.initializing = !1, wx.redirectTo({
- url: "/pages/login/login",
- success: function success(n) {},
- fail: function fail(n) {}
- }), t()), 1 == s.instance.MeetYouUser.mode ? (n.isPregnancy = !0, wx.redirectTo({
- url: "/pages/pregnancy/pregnancy",
- success: function success(n) {},
- fail: function fail(n) {}
- }), t()) : (wx.switchTab({
- url: "/pages/home/home",
- success: function success(n) {},
- fail: function fail(n) {}
- }), i());
- }, function (e) {
- wx.getSetting({
- success: function success(e) {
- e.authSetting["scope.userInfo"] || n.openAuth();
- },
- fail: function fail(e) {
- n.openAuth();
- }
- }), n.initializing = !1, t({
- error: e,
- message: "Authorize.initialize fail"
- });
- });
- }));
- },
- initDiary: function initDiary() {
- var n = this;
- console.log("运行initDiary"), (console.log(!h.isAndroid(), n.denyWeRunData, !s.instance.needWerunAuth), h.isAndroid() && !n.denyWeRunData && s.instance.needWerunAuth ? wx.pro.getSetting().then(function (e) {
- return e.authSetting["scope.werun"] ? n.sendWeRunData() : n.openConfirm(), null;
- }) : u.resolve(null)).then(function () {
- var n = s.instance.MeetYouUser;
- return r.initialize({
- duration: n ? n.duration_of_menstruation : void 0,
- cycle: n ? n.menstrual_cycle : void 0
- });
- }).then(function () {
- n.initializing = !1, n.denyWeRunData = !1;
- }).catch(function (e) {
- console.log("initDiary error", e), wx.showModal({
- title: "小程序初始化失败!",
- content: "请先检查网络连接是否正常,然后重启小程序哦~",
- showCancel: !1
- }), n.initializing = !1;
- });
- },
- openConfirm: function openConfirm() {
- wx.showModal({
- content: "检测到您没打开微信运动的权限,是否去设置打开?",
- confirmText: "确认",
- cancelText: "取消",
- success: function success(n) {
- console.log("model 回调", n), n.confirm ? wx.openSetting({
- success: function success(n) {}
- }) : console.log("用户点击取消");
- }
- });
- },
- openAuth: function openAuth() {
- this.denyUserInfo = !0, wx.redirectTo({
- url: "/pages/auth/auth",
- success: function success(n) {},
- fail: function fail(n) {}
- });
- },
- sendWeRunData: function sendWeRunData() {
- var e = h.isAndroid() || !0,
- i = s.instance.MeetYouUser,
- t = s.instance.WechatUser,
- o = i && void 0 !== n(i.id);
- try {
- e && o && wx.pro.getSetting().then(function (n) {
- if (n.authSetting["scope.werun"]) return l.sendWeRunData(i.id, t.unionid);
- throw new Error("未授权微信运动");
- }).then(function (n) {
- console.log("上报计步数据成功", n);
- }).catch(function (n) {
- console.log("上报计步数据错误", n.message);
- });
- } catch (n) {
- n = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(n);
- console.log("捕获倒错误", n);
- }
- },
- invokeCloudFunc: function invokeCloudFunc(invokeData) {
- var that = this;
- console.log(invokeData);
- return new Promise(function (resolve) {
- if (!invokeData.data.openId) {
- invokeData.data.openId = that.globalData.userOpenId;
- }
- mpserverless.function.invoke(invokeData.name, invokeData.data).then(function (res) {
-
- resolve(res);
- });
- });
- }
- });
|