| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- // var kyjplugin = requirePlugin("kyjplugin");
- // let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
- // var uniacid = JSON.stringify(extConfig) != "{}" ? extConfig.uniacid : '1';
- // wx.setStorageSync("store_id", uniacid);
- // console.log('uniacid:' + uniacid);
- var siteinfo = require("siteinfo.js"),
- _api_root = "";
- let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
- var uniacid = JSON.stringify(extConfig) != "{}" ? extConfig.uniacid : '1';
- siteinfo.uniacid = uniacid;
- siteinfo.acid = uniacid;
- wx.setStorageSync("store_id", uniacid);
- console.log('uniacid:' + uniacid);
- if (-1 != siteinfo.acid) {
- var siteroot = siteinfo.siteroot.substr(0, siteinfo.siteroot.indexOf("app/index.php"));
- _api_root = _api_root = siteroot + "core/web/index.php?_acid=" + siteinfo.acid + "&r=api/"
- } else _api_root = siteinfo.apiroot;
- App({
- onLaunch: function (options) {
- // kyjplugin._init(options);
- var that = this
- console.log('App Launch')
- var logs = wx.getStorageSync('logs') || []
- logs.unshift(Date.now())
- wx.setStorageSync('logs', logs)
- wx.login({
- success: res => {
- }
- })
- wx.getSetting({
- success: res => {
- if (res.authSetting['scope.userInfo']) {
- wx.getUserInfo({
- success: res => {
- this.globalData.userInfo = res.userInfo
- if (this.userInfoReadyCallback) {
- this.userInfoReadyCallback(res)
- }
- }
- })
- }
- }
- })
- },
- onShow: function () {
- // kyjplugin._start();
- console.log('App Show')
- },
- onHide: function () {
- console.log('App Hide')
- },
- login: require("utils/login.js"),
- request1: require("utils/request.js"),
- request: function (object) {
- var token = wx.getStorageSync("token");
- var user = wx.getStorageSync("user");
- if (token) {
- if (!object.data) {
- object.data = {};
- }
- };
- wx.request({
- url: object.url,
- header: object.header || {
- // 'content-type': 'application/x-www-form-urlencoded',
- 'Accept': 'application/json',
- 'Authorization': 'Bearer ' + token
- },
- data: object.data || {},
- method: object.method || "GET",
- dataType: object.dataType || "json",
- success: function (res) {
- if (res.data.status_code == 401) {
- getApp().login();
- } else {
- if (object.success)
- object.success(res);
- };
- },
- fail: function (res) {
- if (object.fail)
- object.fail(res);
- },
- complete: function (res) {
- if (object.complete)
- object.complete(res);
- }
- });
- },
- login: function () {
- wx.login({
- success: function (res) {
- if (res.code) {
- var code = res.code;
- wx.getUserInfo({
- success: function (res) {
- console.log(res);
- getApp().request({
- url: server + "/api/auth/login",
- method: "post",
- data: {
- code: code,
- nickname: res.userInfo.nickName,
- avatar: res.userInfo.avatarUrl
- },
- success: function (res) {
- if (res.data.status_code == 0) {
- wx.setStorageSync("token", res.data.data.token);
- wx.setStorageSync("user", {
- nickname: res.data.data.user.nickname,
- avatar: res.data.data.user.headimgurl,
- });
- } else {
- }
- },
- fail: function (res) {
- }
- });
- },
- fail: function (res) {
- wx.showModal({
- title: '用户未授权',
- content: '如需正常使用功能,请按确定并在授权管理中选中“用户信息”,然后点按确定。最后再重新进入小程序即可正常使用。',
- success: function (res) {
- if (res.confirm) {
- wx.openSetting({
- success: function success(res) {
- console.log('openSetting success', res.authSetting);
- }
- });
- }
- }
- })
- }
- });
- } else {
- }
- },
- fail: function (res) {
- }
- });
- },
- siteInfo: require("siteinfo.js"),
- utils: require("utils/utils.js"),
- globalData: {
- hasLogin: false,
- store_id: uniacid,
- userInfo: null
- }
- });
|