|
| xqd
@@ -53,240 +53,8 @@ App({
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- // dologin: function (raw) {
|
|
|
- // var pages = getCurrentPages();
|
|
|
- // var page = pages[(pages.length - 1)];
|
|
|
- // wx.login({
|
|
|
- // success: function (res) {
|
|
|
- // if (res.code) {
|
|
|
- // var code = res.code;
|
|
|
- // getApp().request({
|
|
|
- // url: api.passport.login,
|
|
|
- // method: "post",
|
|
|
- // data: {
|
|
|
- // code: code,
|
|
|
- // user_info: JSON.stringify(raw.userInfo),
|
|
|
- // encrypted_data: raw.encryptedData,
|
|
|
- // iv: raw.iv,
|
|
|
- // signature: raw.signature
|
|
|
- // },
|
|
|
- // success: function (res) {
|
|
|
- // wx.hideLoading();
|
|
|
- // if (res.code == 0) {
|
|
|
- // wx.setStorageSync("access_token", res.data.access_token);
|
|
|
- // wx.setStorageSync("user_info", res.data);
|
|
|
-
|
|
|
- // var p = getCurrentPages();
|
|
|
- // var parent_id = 0;
|
|
|
- // if (p[0].options.user_id != undefined) {
|
|
|
- // var parent_id = p[0].options.user_id;
|
|
|
- // }
|
|
|
- // else if (p[0].options.scene != undefined) {
|
|
|
- // var parent_id = p[0].options.scene;
|
|
|
- // }
|
|
|
- // getApp().bindParent({
|
|
|
- // parent_id: parent_id || 0
|
|
|
- // });
|
|
|
-
|
|
|
- // if (page == undefined) {
|
|
|
- // return;
|
|
|
-
|
|
|
- // }
|
|
|
- // var loginNoRefreshPage = getApp().loginNoRefreshPage;
|
|
|
- // for (var i in loginNoRefreshPage) {
|
|
|
- // if (loginNoRefreshPage[i] === page.route)
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // wx.redirectTo({
|
|
|
- // url: "/" + page.route + "?" + util.objectToUrlParams(page.options),
|
|
|
- // fail: function () {
|
|
|
- // wx.switchTab({
|
|
|
- // url: "/" + page.route,
|
|
|
- // });
|
|
|
- // },
|
|
|
- // });
|
|
|
-
|
|
|
- // } else {
|
|
|
- // wx.showToast({
|
|
|
- // title: res.msg
|
|
|
- // });
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
- // },
|
|
|
- login: function (e) {
|
|
|
- var pages = getCurrentPages();
|
|
|
- var page = pages[(pages.length - 1)];
|
|
|
- wx.showLoading({
|
|
|
- title: "正在登录",
|
|
|
- mask: true,
|
|
|
- });
|
|
|
- wx.login({
|
|
|
- success: function (res) {
|
|
|
- if (res.code) {
|
|
|
- var code = res.code;
|
|
|
- wx.getSetting({
|
|
|
- success: res => {
|
|
|
- if (res.authSetting['scope.userInfo']) {
|
|
|
- console.log('已经授权' + code)
|
|
|
- // 已经授权,可以直接调用 getUserInfo
|
|
|
- // 获取用户信息
|
|
|
- wx.getSetting({
|
|
|
- success: res => {
|
|
|
- if (res.authSetting['scope.userInfo']) {
|
|
|
- // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
|
|
|
- wx.getUserInfo({
|
|
|
- success: function (res) {
|
|
|
- getApp().request({
|
|
|
- url: api.passport.login,
|
|
|
- method: "post",
|
|
|
- data: {
|
|
|
- code: code,
|
|
|
- user_info: res.rawData,
|
|
|
- encrypted_data: res.encryptedData,
|
|
|
- iv: res.iv,
|
|
|
- signature: res.signature
|
|
|
- },
|
|
|
- success: function (res) {
|
|
|
- wx.hideLoading();
|
|
|
- if (res.code == 0) {
|
|
|
- wx.setStorageSync("access_token", res.data.access_token);
|
|
|
- wx.setStorageSync("user_info", res.data);
|
|
|
- var p = getCurrentPages();
|
|
|
- var parent_id = 0;
|
|
|
- if (p[0].options.user_id != undefined) {
|
|
|
- var parent_id = p[0].options.user_id;
|
|
|
- }
|
|
|
- else if (p[0].options.scene != undefined) {
|
|
|
- var parent_id = p[0].options.scene;
|
|
|
- }
|
|
|
- getApp().bindParent({
|
|
|
- parent_id: parent_id || 0
|
|
|
- });
|
|
|
-
|
|
|
- if (page == undefined) {
|
|
|
- return;
|
|
|
-
|
|
|
- }
|
|
|
- var loginNoRefreshPage = getApp().loginNoRefreshPage;
|
|
|
- for (var i in loginNoRefreshPage) {
|
|
|
- if (loginNoRefreshPage[i] === page.route)
|
|
|
- return;
|
|
|
- }
|
|
|
- wx.redirectTo({
|
|
|
- url: "/" + page.route + "?" + util.objectToUrlParams(page.options),
|
|
|
- fail: function () {
|
|
|
- wx.switchTab({
|
|
|
- url: "/" + page.route,
|
|
|
- });
|
|
|
- },
|
|
|
- });
|
|
|
- } else {
|
|
|
- wx.showToast({
|
|
|
- title: res.msg
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- fail: function (res) {
|
|
|
- wx.hideLoading();
|
|
|
- getApp().getauth({
|
|
|
- content: '需要获取您的用户信息授权,请到小程序设置中打开授权',
|
|
|
- cancel: true,
|
|
|
- success: function (e) {
|
|
|
- if (e) {
|
|
|
- getApp().login();
|
|
|
- }
|
|
|
- },
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- page.setData({
|
|
|
- showModal: true
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- } else {
|
|
|
- //console.log(res);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- request: function (object) {
|
|
|
- if (!object.data)
|
|
|
- object.data = {};
|
|
|
- var access_token = wx.getStorageSync("access_token");
|
|
|
- if (access_token) {
|
|
|
- object.data.access_token = access_token;
|
|
|
- }
|
|
|
- object.data._uniacid = this.siteInfo.uniacid;
|
|
|
- object.data._acid = this.siteInfo.acid;
|
|
|
- wx.request({
|
|
|
- url: object.url,
|
|
|
- header: object.header || {
|
|
|
- 'content-type': 'application/x-www-form-urlencoded'
|
|
|
- },
|
|
|
- data: object.data || {},
|
|
|
- method: object.method || "GET",
|
|
|
- dataType: object.dataType || "json",
|
|
|
- success: function (res) {
|
|
|
- if (res.data.code == -1) {
|
|
|
- getApp().login();
|
|
|
- } else {
|
|
|
- if (object.success)
|
|
|
- object.success(res.data);
|
|
|
- }
|
|
|
- },
|
|
|
- fail: function (res) {
|
|
|
- console.warn('--- request fail >>>');
|
|
|
- console.warn(res);
|
|
|
- console.warn('<<< request fail ---');
|
|
|
- var app = getApp();
|
|
|
- if (app.is_on_launch) {
|
|
|
- app.is_on_launch = false;
|
|
|
- wx.showModal({
|
|
|
- title: "网络请求出错",
|
|
|
- content: res.errMsg,
|
|
|
- showCancel: false,
|
|
|
- success: function (res) {
|
|
|
- if (res.confirm) {
|
|
|
- if (object.fail)
|
|
|
- object.fail(res);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- wx.showToast({
|
|
|
- title: res.errMsg,
|
|
|
- image: "/images/icon-warning.png",
|
|
|
- });
|
|
|
- if (object.fail)
|
|
|
- object.fail(res);
|
|
|
- }
|
|
|
- },
|
|
|
- complete: function (res) {
|
|
|
- if (res.statusCode != 200) {
|
|
|
- console.log('--- request http error >>>');
|
|
|
- console.log(res.statusCode);
|
|
|
- console.log(res.data);
|
|
|
- console.log('<<< request http error ---');
|
|
|
- }
|
|
|
- if (object.complete)
|
|
|
- object.complete(res);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
+ login: require("utils/login.js"),
|
|
|
+ request: require("utils/request.js"),
|
|
|
saveFormId: function (form_id) {
|
|
|
this.request({
|
|
|
url: api.user.save_form_id,
|