xctc-utils 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/weixin/index.js +14 -12
- package/package.json +1 -1
    
        package/dist/weixin/index.js
    CHANGED
    
    | @@ -5,6 +5,7 @@ exports.weixinPay = exports.weixinShareInit = exports.weixinShareConfig = export | |
| 5 5 | 
             
            var weixin = require("weixin-js-sdk");
         | 
| 6 6 | 
             
            var utils_1 = require("../utils");
         | 
| 7 7 | 
             
            var crypto_1 = require("../crypto");
         | 
| 8 | 
            +
            var index_1 = require("../storage/index");
         | 
| 8 9 | 
             
            var w = window;
         | 
| 9 10 | 
             
            var loc = w.location;
         | 
| 10 11 | 
             
            var defaultKey = "5uMz4R8rop26DkC8";
         | 
| @@ -18,7 +19,7 @@ function weixinUrlCode(config) { | |
| 18 19 | 
             
                var codeKey = weixinConfig['codeKey'];
         | 
| 19 20 | 
             
                var localCode = "";
         | 
| 20 21 | 
             
                if (codeKey)
         | 
| 21 | 
            -
                    localCode =  | 
| 22 | 
            +
                    localCode = (0, index_1.getSessionStorage)(codeKey);
         | 
| 22 23 | 
             
                if (!localCode && search && search.indexOf("code=") != -1) {
         | 
| 23 24 | 
             
                    // localCode 不存在, 微信链接中存在 code 用户初次登录系统,
         | 
| 24 25 | 
             
                    var urlArr = formatSearch(search, "code=");
         | 
| @@ -28,7 +29,7 @@ function weixinUrlCode(config) { | |
| 28 29 | 
             
                        if (item.indexOf("code=") != -1) {
         | 
| 29 30 | 
             
                            code = item.substr(5);
         | 
| 30 31 | 
             
                            if (codeKey)
         | 
| 31 | 
            -
                                 | 
| 32 | 
            +
                                (0, index_1.useSessionStorage)(codeKey, code);
         | 
| 32 33 | 
             
                        }
         | 
| 33 34 | 
             
                    }
         | 
| 34 35 | 
             
                    weixinLogin(code);
         | 
| @@ -46,11 +47,11 @@ function weixinUrlCode(config) { | |
| 46 47 | 
             
                            if (item.indexOf("state=") != -1) {
         | 
| 47 48 | 
             
                                hrefState = item.substr(6);
         | 
| 48 49 | 
             
                                var stateKey = weixinConfig['stateKey'] || "weixinState";
         | 
| 49 | 
            -
                                 | 
| 50 | 
            +
                                (0, index_1.useSessionStorage)(stateKey, hrefState);
         | 
| 50 51 | 
             
                                var stateObj = (0, crypto_1.decrypt)(hrefState, cryptoConfig(cryptokey).key, cryptoConfig(cryptoiv).iv);
         | 
| 51 52 | 
             
                                if (stateObj instanceof Object)
         | 
| 52 53 | 
             
                                    stateObj = JSON.stringify(stateObj);
         | 
| 53 | 
            -
                                 | 
| 54 | 
            +
                                (0, index_1.useSessionStorage)("".concat(stateKey, "Obj"), stateObj);
         | 
| 54 55 | 
             
                            }
         | 
| 55 56 | 
             
                        }
         | 
| 56 57 | 
             
                    }
         | 
| @@ -71,13 +72,14 @@ function cryptoConfig(key, iv) { | |
| 71 72 | 
             
            }
         | 
| 72 73 | 
             
            // 执行微信登录
         | 
| 73 74 | 
             
            function weixinLogin(code) {
         | 
| 74 | 
            -
                 | 
| 75 | 
            +
                var cryptoiv = weixinConfig.cryptoiv, cryptokey = weixinConfig.cryptokey, appId = weixinConfig.appId, http = weixinConfig.http, stateKey = weixinConfig.stateKey;
         | 
| 76 | 
            +
                if (!appId)
         | 
| 75 77 | 
             
                    return;
         | 
| 76 78 | 
             
                var obj = {
         | 
| 77 | 
            -
                    "app_id":  | 
| 79 | 
            +
                    "app_id": appId,
         | 
| 78 80 | 
             
                    "js_code": code
         | 
| 79 81 | 
             
                };
         | 
| 80 | 
            -
                if (! | 
| 82 | 
            +
                if (!http)
         | 
| 81 83 | 
             
                    return;
         | 
| 82 84 | 
             
                weixinConfig.http(obj).then(function (res) {
         | 
| 83 85 | 
             
                    if (res.code == 40163) {
         | 
| @@ -90,13 +92,13 @@ function weixinLogin(code) { | |
| 90 92 | 
             
                        if (item instanceof Object) {
         | 
| 91 93 | 
             
                            item = JSON.stringify(item);
         | 
| 92 94 | 
             
                        }
         | 
| 93 | 
            -
                         | 
| 95 | 
            +
                        (0, index_1.useSessionStorage)(key, item);
         | 
| 94 96 | 
             
                    }
         | 
| 95 97 | 
             
                    var url = loc.origin;
         | 
| 96 | 
            -
                    var state =  | 
| 98 | 
            +
                    var state = (0, index_1.getSessionStorage)(stateKey);
         | 
| 97 99 | 
             
                    var str = "";
         | 
| 98 100 | 
             
                    if (state) {
         | 
| 99 | 
            -
                        var stateObj = (0,  | 
| 101 | 
            +
                        var stateObj = (0, index_1.getSessionStorage)("".concat(stateKey, "Obj"));
         | 
| 100 102 | 
             
                        for (var key in stateObj) {
         | 
| 101 103 | 
             
                            if (key == "path") {
         | 
| 102 104 | 
             
                                if (stateObj[key][0] == "/") {
         | 
| @@ -213,7 +215,7 @@ function weixinShareInit(options) { | |
| 213 215 | 
             
                var desc = "微信分享描述";
         | 
| 214 216 | 
             
                if (options === null || options === void 0 ? void 0 : options.desc)
         | 
| 215 217 | 
             
                    desc = options.desc;
         | 
| 216 | 
            -
                var link = loc. | 
| 218 | 
            +
                var link = loc.origin;
         | 
| 217 219 | 
             
                if (options === null || options === void 0 ? void 0 : options.link)
         | 
| 218 220 | 
             
                    link = options.link;
         | 
| 219 221 | 
             
                var imgUrl = "";
         | 
| @@ -229,7 +231,7 @@ function weixinShareInit(options) { | |
| 229 231 | 
             
                }
         | 
| 230 232 | 
             
                var wx = weixinInit();
         | 
| 231 233 | 
             
                // console.log("shareUrl===",link)
         | 
| 232 | 
            -
                 | 
| 234 | 
            +
                (0, index_1.useSessionStorage)("shareUrl", link);
         | 
| 233 235 | 
             
                wx.ready(function () {
         | 
| 234 236 | 
             
                    //需在用户可能点击分享按钮前就先调用
         | 
| 235 237 | 
             
                    wx.updateAppMessageShareData({
         | 
    
        package/package.json
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            {
         | 
| 2 2 | 
             
              "name": "xctc-utils",
         | 
| 3 | 
            -
              "version": "1.1. | 
| 3 | 
            +
              "version": "1.1.5",
         | 
| 4 4 | 
             
              "description": "localStorage存储\r ```\r sessionStorage存储\r ```\r crypto-js加密、解密\r ```\r 微信授权登录、微信分享\r ```\r 设备环境获取\r ```\r 是否是微信浏览器\r ```\r 时间戳转时间,字符串转时间戳",
         | 
| 5 5 | 
             
              "main": "./dist/index.js",
         | 
| 6 6 | 
             
              "types": "./dist/index.d.ts",
         |