@scgczm/bridge 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/README.md CHANGED
@@ -44,6 +44,7 @@ window.scgcBridge.scgcLogin();
44
44
  - scgcLogin - 调用app登录
45
45
  - scgcOpenexplorer - 使用系统浏览器打开指定的url
46
46
  - scgcOpenwechat - 打开微信小程序
47
+ - scgcSaveFile - 保存文件(音频/视频)
47
48
  - scgcSaveimage - 保存图片
48
49
  - scgcScan - 调用app扫码
49
50
  - scgcSetVolume - 设置app音量
@@ -54,6 +54,17 @@ export interface ISaveimageData {
54
54
  * @param {string} data.data base64数据
55
55
  */
56
56
  export declare const scgcSaveimage: (data: ISaveimageData) => void;
57
+ export interface ISaveFileData {
58
+ fileType: 'audio' | 'video';
59
+ path: string;
60
+ }
61
+ /**
62
+ * @description 保存文件(音频/视频)
63
+ * @param {ISaveFileData} data
64
+ * @param {'audio' | 'video'} data.fileType 文件类型
65
+ * @param {string} data.path 文件路径
66
+ */
67
+ export declare const scgcSaveFile: (data: ISaveFileData) => void;
57
68
  export interface IShareData {
58
69
  shareUrl?: string;
59
70
  shareImg?: string;
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.scgcCopyText = exports.scgcToTopicPublish = exports.scgcToTopicCollection = exports.scgctoDocumentshow = exports.scgctoVarietyshow = exports.scgcGetCaptchaVerifyParam = exports.scgcGetPhoneNumber = exports.scgcGetNickName = exports.scgcGetAvatar = exports.scgcGetUserId = exports.scgcChangeStateBarColor = exports.scgcToAppHome = exports.scgcToKuaipai = exports.scgcToMall = exports.scgcFocusWeb = exports.scgcToMallDetail = exports.scgcToSubSpecial = exports.scgcSetVolume = exports.scgcToTopic = exports.scgcToLive = exports.scgcToSpecial = exports.scgcToDetail = exports.scgcToH5 = exports.scgcShare = exports.scgcSaveimage = exports.scgcOpenwechat = exports.scgcOpenexplorer = exports.scgcClose = exports.scgcScan = exports.scgcLogin = exports.scgcGetSlideData = exports.isScgcApp = exports.setDevMode = void 0;
3
+ exports.scgcCopyText = exports.scgcToTopicPublish = exports.scgcToTopicCollection = exports.scgctoDocumentshow = exports.scgctoVarietyshow = exports.scgcGetCaptchaVerifyParam = exports.scgcGetPhoneNumber = exports.scgcGetNickName = exports.scgcGetAvatar = exports.scgcGetUserId = exports.scgcChangeStateBarColor = exports.scgcToAppHome = exports.scgcToKuaipai = exports.scgcToMall = exports.scgcFocusWeb = exports.scgcToMallDetail = exports.scgcToSubSpecial = exports.scgcSetVolume = exports.scgcToTopic = exports.scgcToLive = exports.scgcToSpecial = exports.scgcToDetail = exports.scgcToH5 = exports.scgcShare = exports.scgcSaveFile = exports.scgcSaveimage = exports.scgcOpenwechat = exports.scgcOpenexplorer = exports.scgcClose = exports.scgcScan = exports.scgcLogin = exports.scgcGetSlideData = exports.isScgcApp = exports.setDevMode = void 0;
4
4
  /*#__PURE__*/
5
5
  var utils_1 = require("./utils");
6
6
  (0, utils_1.initAsyncCallbackPool)();
@@ -67,6 +67,16 @@ var scgcSaveimage = function (data) {
67
67
  commonBridge('saveimage', data);
68
68
  };
69
69
  exports.scgcSaveimage = scgcSaveimage;
70
+ /**
71
+ * @description 保存文件(音频/视频)
72
+ * @param {ISaveFileData} data
73
+ * @param {'audio' | 'video'} data.fileType 文件类型
74
+ * @param {string} data.path 文件路径
75
+ */
76
+ var scgcSaveFile = function (data) {
77
+ commonBridge('saveFile', data);
78
+ };
79
+ exports.scgcSaveFile = scgcSaveFile;
70
80
  /**
71
81
  * @description 配置app分享
72
82
  * @param {IShareData} data
@@ -2,7 +2,7 @@ export interface ICommonResult<T> {
2
2
  success: boolean;
3
3
  data: T;
4
4
  }
5
- type TSyncFuns = 'getSlideData' | 'login' | 'scan' | 'close' | 'openexplorer' | 'openwechat' | 'saveimage' | 'share' | 'toH5' | 'toDetail' | 'toLive' | 'toTopic' | 'setVolume' | 'toSubSpecial' | 'detailJson' | 'focusWeb' | 'mall' | 'mainPage' | 'changeStatebarColor' | 'release' | 'toSpecial' | 'getCaptchaVerifyParam' | 'toVarietyshow' | 'toDocumentary' | 'toTopicCollection' | 'toTopicPublish' | 'copyText';
5
+ type TSyncFuns = 'getSlideData' | 'login' | 'scan' | 'close' | 'openexplorer' | 'openwechat' | 'saveimage' | 'share' | 'toH5' | 'toDetail' | 'toLive' | 'toTopic' | 'setVolume' | 'toSubSpecial' | 'detailJson' | 'focusWeb' | 'mall' | 'mainPage' | 'changeStatebarColor' | 'release' | 'toSpecial' | 'getCaptchaVerifyParam' | 'toVarietyshow' | 'toDocumentary' | 'toTopicCollection' | 'toTopicPublish' | 'copyText' | 'saveFile';
6
6
  type TAsyncFuns = 'getToken' | 'getUserId' | 'getNickName' | 'getAvatar' | 'getPhoneNumber' | 'getPromise';
7
7
  export declare const setDevMode: () => void;
8
8
  export declare const initAsyncCallbackPool: () => void;
@@ -54,6 +54,17 @@ export interface ISaveimageData {
54
54
  * @param {string} data.data base64数据
55
55
  */
56
56
  export declare const scgcSaveimage: (data: ISaveimageData) => void;
57
+ export interface ISaveFileData {
58
+ fileType: 'audio' | 'video';
59
+ path: string;
60
+ }
61
+ /**
62
+ * @description 保存文件(音频/视频)
63
+ * @param {ISaveFileData} data
64
+ * @param {'audio' | 'video'} data.fileType 文件类型
65
+ * @param {string} data.path 文件路径
66
+ */
67
+ export declare const scgcSaveFile: (data: ISaveFileData) => void;
57
68
  export interface IShareData {
58
69
  shareUrl?: string;
59
70
  shareImg?: string;
package/dist/esm/index.js CHANGED
@@ -55,6 +55,15 @@ export var scgcOpenwechat = function (data) {
55
55
  export var scgcSaveimage = function (data) {
56
56
  commonBridge('saveimage', data);
57
57
  };
58
+ /**
59
+ * @description 保存文件(音频/视频)
60
+ * @param {ISaveFileData} data
61
+ * @param {'audio' | 'video'} data.fileType 文件类型
62
+ * @param {string} data.path 文件路径
63
+ */
64
+ export var scgcSaveFile = function (data) {
65
+ commonBridge('saveFile', data);
66
+ };
58
67
  /**
59
68
  * @description 配置app分享
60
69
  * @param {IShareData} data
@@ -2,7 +2,7 @@ export interface ICommonResult<T> {
2
2
  success: boolean;
3
3
  data: T;
4
4
  }
5
- type TSyncFuns = 'getSlideData' | 'login' | 'scan' | 'close' | 'openexplorer' | 'openwechat' | 'saveimage' | 'share' | 'toH5' | 'toDetail' | 'toLive' | 'toTopic' | 'setVolume' | 'toSubSpecial' | 'detailJson' | 'focusWeb' | 'mall' | 'mainPage' | 'changeStatebarColor' | 'release' | 'toSpecial' | 'getCaptchaVerifyParam' | 'toVarietyshow' | 'toDocumentary' | 'toTopicCollection' | 'toTopicPublish' | 'copyText';
5
+ type TSyncFuns = 'getSlideData' | 'login' | 'scan' | 'close' | 'openexplorer' | 'openwechat' | 'saveimage' | 'share' | 'toH5' | 'toDetail' | 'toLive' | 'toTopic' | 'setVolume' | 'toSubSpecial' | 'detailJson' | 'focusWeb' | 'mall' | 'mainPage' | 'changeStatebarColor' | 'release' | 'toSpecial' | 'getCaptchaVerifyParam' | 'toVarietyshow' | 'toDocumentary' | 'toTopicCollection' | 'toTopicPublish' | 'copyText' | 'saveFile';
6
6
  type TAsyncFuns = 'getToken' | 'getUserId' | 'getNickName' | 'getAvatar' | 'getPhoneNumber' | 'getPromise';
7
7
  export declare const setDevMode: () => void;
8
8
  export declare const initAsyncCallbackPool: () => void;
@@ -1 +1 @@
1
- !function(n,a){"object"==typeof exports&&"object"==typeof module?module.exports=a():"function"==typeof define&&define.amd?define([],a):"object"==typeof exports?exports.scgcBridge=a():n.scgcBridge=a()}(self,()=>(()=>{"use strict";var __webpack_modules__={"./src/index.ts"(__unused_webpack_module,__webpack_exports__,__webpack_require__){eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ isScgcApp: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_0__.isScgcApp),\n/* harmony export */ scgcChangeStateBarColor: () => (/* binding */ scgcChangeStateBarColor),\n/* harmony export */ scgcClose: () => (/* binding */ scgcClose),\n/* harmony export */ scgcCopyText: () => (/* binding */ scgcCopyText),\n/* harmony export */ scgcFocusWeb: () => (/* binding */ scgcFocusWeb),\n/* harmony export */ scgcGetAvatar: () => (/* binding */ scgcGetAvatar),\n/* harmony export */ scgcGetCaptchaVerifyParam: () => (/* binding */ scgcGetCaptchaVerifyParam),\n/* harmony export */ scgcGetNickName: () => (/* binding */ scgcGetNickName),\n/* harmony export */ scgcGetPhoneNumber: () => (/* binding */ scgcGetPhoneNumber),\n/* harmony export */ scgcGetSlideData: () => (/* binding */ scgcGetSlideData),\n/* harmony export */ scgcGetUserId: () => (/* binding */ scgcGetUserId),\n/* harmony export */ scgcLogin: () => (/* binding */ scgcLogin),\n/* harmony export */ scgcOpenexplorer: () => (/* binding */ scgcOpenexplorer),\n/* harmony export */ scgcOpenwechat: () => (/* binding */ scgcOpenwechat),\n/* harmony export */ scgcSaveimage: () => (/* binding */ scgcSaveimage),\n/* harmony export */ scgcScan: () => (/* binding */ scgcScan),\n/* harmony export */ scgcSetVolume: () => (/* binding */ scgcSetVolume),\n/* harmony export */ scgcShare: () => (/* binding */ scgcShare),\n/* harmony export */ scgcToAppHome: () => (/* binding */ scgcToAppHome),\n/* harmony export */ scgcToDetail: () => (/* binding */ scgcToDetail),\n/* harmony export */ scgcToH5: () => (/* binding */ scgcToH5),\n/* harmony export */ scgcToKuaipai: () => (/* binding */ scgcToKuaipai),\n/* harmony export */ scgcToLive: () => (/* binding */ scgcToLive),\n/* harmony export */ scgcToMall: () => (/* binding */ scgcToMall),\n/* harmony export */ scgcToMallDetail: () => (/* binding */ scgcToMallDetail),\n/* harmony export */ scgcToSpecial: () => (/* binding */ scgcToSpecial),\n/* harmony export */ scgcToSubSpecial: () => (/* binding */ scgcToSubSpecial),\n/* harmony export */ scgcToTopic: () => (/* binding */ scgcToTopic),\n/* harmony export */ scgcToTopicCollection: () => (/* binding */ scgcToTopicCollection),\n/* harmony export */ scgcToTopicPublish: () => (/* binding */ scgcToTopicPublish),\n/* harmony export */ scgctoDocumentshow: () => (/* binding */ scgctoDocumentshow),\n/* harmony export */ scgctoVarietyshow: () => (/* binding */ scgctoVarietyshow),\n/* harmony export */ setDevMode: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_0__.setDevMode)\n/* harmony export */ });\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils */ \"./src/utils.ts\");\n/*#__PURE__*/\n\n(0,_utils__WEBPACK_IMPORTED_MODULE_0__.initAsyncCallbackPool)();\nvar commonBridge = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.commonBridgeFun)();\n\n/**\n * @deprecated 因阿里验证码1.0升级至2.0,原有scgcGetSlideData方法已使用scgcGetCaptchaVerifyParam替换,自 v1.1.0 起弃用,将在 v2.0.0 中移除\n *\n * @description 阿里滑动验证(使用的旧版api,目前官方文档已散佚,可参考其他项目)\n * @param {IGetSlideDataData} data\n */\nvar scgcGetSlideData = function (data) {\n commonBridge('getSlideData', data);\n};\n/**\n * @description 调用app登录\n */\nvar scgcLogin = function () {\n commonBridge('login');\n};\n/**\n * @description 调用app扫码\n */\nvar scgcScan = function () {\n commonBridge('scan');\n};\n/**\n * @description 关闭当前webview\n */\nvar scgcClose = function () {\n commonBridge('close');\n};\n/**\n * @description 使用系统浏览器打开指定的url\n * @param {IOpenexplorerData} data\n * @param {string} data.path 需要打开的url\n */\nvar scgcOpenexplorer = function (data) {\n commonBridge('openexplorer', data);\n};\n/**\n * @description 打开微信小程序\n * @param {IOpenwechatData} data\n * @param {string} data.appid 小程序appid,格式为gh开头\n * @param {string} data.path 小程序路径\n */\nvar scgcOpenwechat = function (data) {\n commonBridge('openwechat', data);\n};\n/**\n * @description 保存图片\n * @param {ISaveimageData} data\n * @param {string} data.data base64数据\n */\nvar scgcSaveimage = function (data) {\n commonBridge('saveimage', data);\n};\n/**\n * @description 配置app分享\n * @param {IShareData} data\n * @param {string} data.shareUrl 需要分享的地址\n * @param {string} data.shareImg 分享的封面\n * @param {string} data.shareTitle 分享的标题\n * @param {string} data.shareDesc 分享的说明\n * @param {boolean} data.doShare 是否在调用bridge时立即触发app的分享,默认为仅修改配置\n */\nvar scgcShare = function (data) {\n commonBridge('share', data);\n};\n/**\n * @description 打开一个webview\n * @param {ItoH5Data} data\n * @param {string} data.path 需要打开的url\n */\nvar scgcToH5 = function (data) {\n commonBridge('toH5', data);\n};\n/**\n * @description 打开app原生新闻页\n * @param {IToDetailData} data\n * @param {string} data.path 新闻json地址 --相对地址,没有域名前缀的形式\n * @param {number} data.newsType 新闻类型 --1.图文 2.音频 3.视频 4.纯视频新闻 6 外链\n */\nvar scgcToDetail = function (data) {\n commonBridge('toDetail', data);\n};\n/**\n * @description 打开app原生专题详情页\n * @param {IToSpecialData} data\n * @param {string} data.id 专题id\n */\nvar scgcToSpecial = function (data) {\n commonBridge('toSpecial', data);\n};\n/**\n * @description 打开app原生直播页\n * @param {IToLiveData} data\n * @param {string} data.id 直播id\n * @param {string} data.type 直播样式 1 横版 2 竖版\n */\nvar scgcToLive = function (data) {\n commonBridge('toLive', data);\n};\n/**\n * @description 打开app话题页\n * @param {IToTopicData} data\n * @param {string} data.name 话题名称\n * @param {string} data.cover 话题封面图(完整的图片地址)\n * @param {string} data.id 话题id\n */\nvar scgcToTopic = function (data) {\n commonBridge('toTopic', data);\n};\n/**\n * @description 设置app音量\n * @param {ISetVolumeData} data\n * @param {number} data.type 0 调小 1 调大\n */\nvar scgcSetVolume = function (data) {\n commonBridge('setVolume', data);\n};\n/**\n * @description 打开app原生专题新闻列表页\n * @param {IToSubSpecialData} data\n * @param {string} data.title 专题标题\n * @param {string} data.id 专题id\n */\nvar scgcToSubSpecial = function (data) {\n commonBridge('toSubSpecial', data);\n};\n/**\n * @description 打开积分商城商品详情\n * @param {IMallDetailData} data\n * @param {string} data.json 商品详情json地址\n * @param {string} data.url 商品详情网页地址\n * @param {string} data.ptype todo 未知\n * @param {number} data.isDark 0 普通模式 1 黑暗模式\n */\nvar scgcToMallDetail = function (data) {\n commonBridge('detailJson', data);\n};\n/**\n * @description 是否禁用app左右滑动(主要用户嵌入在app首页的swiper,避免滑动swiper的情况下,会滑动app首页的tab页)\n * @param {IMallDetailData} data\n * @param {boolean} data.focus 是否禁止app滑动\n *\n */\nvar scgcFocusWeb = function (data) {\n commonBridge('focusWeb', data);\n};\n/**\n * @description 跳转至积分商城\n */\nvar scgcToMall = function () {\n commonBridge('mall');\n};\n/**\n * @description 跳转至快拍\n */\nvar scgcToKuaipai = function () {\n commonBridge('release');\n};\n/**\n * @description 跳转至app首页\n */\nvar scgcToAppHome = function () {\n commonBridge('mainPage');\n};\n/**\n * @description 设置app顶部时间栏颜色\n * @param {IChangeStateBarColorData} data\n * @param {number} data.type 1 黑色 2 白色\n *\n */\nvar scgcChangeStateBarColor = function (data) {\n commonBridge('changeStatebarColor', data);\n};\n/**\n * @description 获取app 用户id\n * @return {Promise((success:boolean,data:string))} 返回promise\n *\n */\nvar scgcGetUserId = function () {\n return commonBridge('getUserId');\n};\n/**\n * @description 获取app 用户头像\n * @return {Promise((success:boolean,data:string))} 返回promise\n *\n */\nvar scgcGetAvatar = function () {\n return commonBridge('getAvatar');\n};\n/**\n * @description 获取app 用户昵称\n * @return {Promise((success:boolean,data:string))} 返回promise\n *\n */\nvar scgcGetNickName = function () {\n return commonBridge('getNickName');\n};\n// /**\n// * @description 获取app 用户手机号\n// * @return {Promise((success:boolean,data:string))} 返回promise\n// *\n// */\nvar scgcGetPhoneNumber = function () {\n return commonBridge('getPhoneNumber');\n};\n/**\n * @description 传递验证码参数到app(阿里验证码2.0使用)\n * @param {IGetCaptchaVerifyParamData} data\n * @param {string} data.captchaVerifyParam 验证码参数\n */\nvar scgcGetCaptchaVerifyParam = function (data) {\n return commonBridge('getCaptchaVerifyParam', data);\n};\n/**\n * @description 打开原生综艺页面\n * @param {IProgramData} data\n * @param {string} data.programId 节目Id\n * @param {string} data.groupId 合集Id\n * @param {string} data.episodeId 单集Id\n */\nvar scgctoVarietyshow = function (data) {\n return commonBridge('toVarietyshow', data);\n};\n/**\n * @description 打开原生纪录片页面\n * @param {IProgramData} data\n * @param {string} data.programId 节目Id\n * @param {string} data.groupId 合集Id\n * @param {string} data.episodeId 单集Id\n */\nvar scgctoDocumentshow = function (data) {\n return commonBridge('toDocumentary', data);\n};\n/**\n * @description 打开话题合集页\n * @param {ITopicCollectionData} data\n * @param {string} data.type 话题合集类型\n */\nvar scgcToTopicCollection = function (data) {\n return commonBridge('toTopicCollection', data);\n};\n/**\n * @description 打开话题发布页\n * @param {ITopicPublishData} data\n * @param {string} data.id 话题Id(可选)\n * @param {string} data.name 话题名称(可选)\n */\nvar scgcToTopicPublish = function (data) {\n if (data === void 0) { data = {}; }\n return commonBridge('toTopicPublish', data);\n};\n/**\n * @description 复制文本到剪贴板\n * @param {ICopyTextData} data\n * @param {string} data.text 要复制的文本\n */\nvar scgcCopyText = function (data) {\n return commonBridge('copyText', data);\n};\n\n\n//# sourceURL=webpack://scgcBridge/./src/index.ts?\n}")},"./src/utils.ts"(__unused_webpack_module,__webpack_exports__,__webpack_require__){eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ commonBridgeFun: () => (/* binding */ commonBridgeFun),\n/* harmony export */ initAsyncCallbackPool: () => (/* binding */ initAsyncCallbackPool),\n/* harmony export */ isScgcApp: () => (/* binding */ isScgcApp),\n/* harmony export */ setDevMode: () => (/* binding */ setDevMode)\n/* harmony export */ });\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === \"function\" ? Iterator : Object).prototype);\n return g.next = verb(0), g[\"throw\"] = verb(1), g[\"return\"] = verb(2), typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n 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;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nvar distinctionPlatform = function () {\n var ua = navigator.userAgent;\n if (/(iPhone|iPad|iPod)/i.test(ua)) {\n return 'ios';\n }\n else if (/Android/i.test(ua)) {\n return 'android';\n }\n else if (/openharmony/i.test(ua)) {\n return 'harmony';\n }\n else {\n return 'unknow';\n }\n};\nvar asyncFunsArr = [\n 'getToken',\n 'getUserId',\n 'getAvatar',\n 'getNickName',\n 'getPhoneNumber',\n 'getPromise', //测试用\n];\nvar androidAsyncFunsArr = ['getPromise'];\nvar devMode = false;\nvar setDevMode = function () {\n devMode = true;\n};\nvar initAsyncCallbackPool = function () {\n window.bridgeCallbacks = {};\n};\nvar devFn = function (platform, fnName, data) {\n //动态判断是否为devMode,避免初始化commonBridgeFun比调用setDevMode的早的情况下,devMode参数已固定(损失的性能可以接受)\n if (devMode) {\n var devInfo = {\n platform: platform,\n fnName: fnName,\n data: data,\n };\n console.log(devInfo);\n }\n};\nfunction makeRandomId(fnName) {\n return \"\".concat(fnName || 'anonymous', \"_\").concat(Date.now());\n}\nfunction registerCallback(fnName, cb) {\n if (!cb) {\n return null;\n }\n var callbackId = makeRandomId(fnName);\n if (!window.hasOwnProperty('bridgeCallbacks')) {\n window.bridgeCallbacks = {};\n }\n window.bridgeCallbacks[callbackId] = function (data) {\n var result;\n if (typeof data === 'object') {\n result = data;\n }\n else if (typeof data === 'string') {\n try {\n result = JSON.parse(data);\n }\n catch (e) {\n result = data;\n }\n }\n cb(result);\n };\n return \"bridgeCallbacks.\".concat(callbackId);\n}\nfunction androidBridgeFn(fnName, data) {\n var _this = this;\n var _a, _b;\n var androidParams = {\n Method: fnName,\n Data: data,\n };\n devFn('android', fnName, data);\n if (fnName == 'getSlideData') {\n (_a = window === null || window === void 0 ? void 0 : window.testInterface) === null || _a === void 0 ? void 0 : _a.getSlideData(JSON.stringify(androidParams));\n }\n else if (asyncFunsArr.includes(fnName)) {\n var promiseRes = new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {\n var res, result;\n var _a, _b;\n return __generator(this, function (_c) {\n try {\n //安卓使用了异步返回\n if (androidAsyncFunsArr.includes(fnName)) {\n (_a = window === null || window === void 0 ? void 0 : window.newBridge) === null || _a === void 0 ? void 0 : _a[fnName](JSON.stringify({\n callback: registerCallback(fnName, resolve),\n }));\n }\n else {\n res = (_b = window === null || window === void 0 ? void 0 : window.newBridge) === null || _b === void 0 ? void 0 : _b[fnName]();\n result = void 0;\n if (typeof res === 'object') {\n result = res;\n }\n else if (typeof res === 'string') {\n try {\n result = JSON.parse(res);\n }\n catch (e) {\n result = { success: false, data: res };\n }\n }\n if ((result === null || result === void 0 ? void 0 : result.success) == true) {\n resolve(result);\n }\n else {\n reject(result);\n }\n }\n }\n catch (error) {\n reject(error);\n }\n return [2 /*return*/];\n });\n }); });\n return promiseRes;\n }\n else {\n (_b = window === null || window === void 0 ? void 0 : window.bridge) === null || _b === void 0 ? void 0 : _b.callRouter(JSON.stringify(androidParams), function () { });\n }\n}\nfunction iosBridgeFn(fnName, data) {\n var _this = this;\n var _a, _b, _c;\n devFn('ios', fnName, data);\n if (asyncFunsArr.includes(fnName)) {\n var promiseRes = new Promise(function (resolve, reject) {\n var _a, _b, _c;\n try {\n var _cb = function (res) { return __awaiter(_this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n try {\n if ((res === null || res === void 0 ? void 0 : res.success) == 'true') {\n resolve({\n success: true,\n data: res === null || res === void 0 ? void 0 : res.data,\n });\n }\n else {\n reject({\n success: false,\n data: res === null || res === void 0 ? void 0 : res.data,\n });\n }\n }\n catch (error) {\n reject({\n success: false,\n data: error,\n });\n }\n return [2 /*return*/];\n });\n }); };\n (_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b[fnName]) === null || _c === void 0 ? void 0 : _c.postMessage({\n data: {},\n callback: registerCallback(fnName, _cb),\n });\n }\n catch (error) {\n reject({\n success: false,\n data: error,\n });\n }\n });\n return promiseRes;\n }\n else {\n (_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b[fnName]) === null || _c === void 0 ? void 0 : _c.postMessage(data);\n }\n}\nfunction harmonyBridgeFn(fnName, data) {\n var _a, _b;\n devFn('harmony', fnName, data);\n if (asyncFunsArr.includes(fnName)) {\n var promiseRes = new Promise(function (resolve, reject) {\n var _a;\n try {\n (_a = window === null || window === void 0 ? void 0 : window.harmonyBridge) === null || _a === void 0 ? void 0 : _a[fnName]({\n data: data,\n callback: registerCallback(fnName, resolve),\n });\n }\n catch (error) {\n reject(error);\n }\n });\n return promiseRes;\n }\n else {\n (_b = (_a = window === null || window === void 0 ? void 0 : window.harmonyBridge) === null || _a === void 0 ? void 0 : _a[fnName]) === null || _b === void 0 ? void 0 : _b.call(_a, data);\n }\n}\nfunction defaultBridgeFn(fnName, data) {\n console.log('请使用scgc app打开');\n if (asyncFunsArr.includes(fnName)) {\n var promiseRes = new Promise(function (resolve, reject) {\n try {\n resolve('请使用scgc app打开');\n }\n catch (error) {\n reject(error);\n }\n });\n return promiseRes;\n }\n}\nvar commonBridgeFun = function () {\n var platform = distinctionPlatform();\n if (platform == 'android') {\n return androidBridgeFn;\n }\n else if (platform == 'ios') {\n return iosBridgeFn;\n }\n else if (platform == 'harmony') {\n return harmonyBridgeFn;\n }\n else {\n return defaultBridgeFn;\n }\n};\n/**\n * @description 是否为app环境\n * @return {boolean} true 是 false 否\n */\nvar isScgcApp = function () {\n return navigator.userAgent.indexOf('SCGC_UA') > -1;\n};\n\n\n//# sourceURL=webpack://scgcBridge/./src/utils.ts?\n}")}},__webpack_module_cache__={};function __webpack_require__(n){var a=__webpack_module_cache__[n];if(void 0!==a)return a.exports;var e=__webpack_module_cache__[n]={exports:{}};if(!(n in __webpack_modules__)){delete __webpack_module_cache__[n];var r=new Error("Cannot find module '"+n+"'");throw r.code="MODULE_NOT_FOUND",r}return __webpack_modules__[n](e,e.exports,__webpack_require__),e.exports}__webpack_require__.d=(n,a)=>{for(var e in a)__webpack_require__.o(a,e)&&!__webpack_require__.o(n,e)&&Object.defineProperty(n,e,{enumerable:!0,get:a[e]})},__webpack_require__.o=(n,a)=>Object.prototype.hasOwnProperty.call(n,a),__webpack_require__.r=n=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})};var __webpack_exports__=__webpack_require__("./src/index.ts");return __webpack_exports__})());
1
+ !function(n,a){"object"==typeof exports&&"object"==typeof module?module.exports=a():"function"==typeof define&&define.amd?define([],a):"object"==typeof exports?exports.scgcBridge=a():n.scgcBridge=a()}(self,()=>(()=>{"use strict";var __webpack_modules__={"./src/index.ts"(__unused_webpack_module,__webpack_exports__,__webpack_require__){eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ isScgcApp: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_0__.isScgcApp),\n/* harmony export */ scgcChangeStateBarColor: () => (/* binding */ scgcChangeStateBarColor),\n/* harmony export */ scgcClose: () => (/* binding */ scgcClose),\n/* harmony export */ scgcCopyText: () => (/* binding */ scgcCopyText),\n/* harmony export */ scgcFocusWeb: () => (/* binding */ scgcFocusWeb),\n/* harmony export */ scgcGetAvatar: () => (/* binding */ scgcGetAvatar),\n/* harmony export */ scgcGetCaptchaVerifyParam: () => (/* binding */ scgcGetCaptchaVerifyParam),\n/* harmony export */ scgcGetNickName: () => (/* binding */ scgcGetNickName),\n/* harmony export */ scgcGetPhoneNumber: () => (/* binding */ scgcGetPhoneNumber),\n/* harmony export */ scgcGetSlideData: () => (/* binding */ scgcGetSlideData),\n/* harmony export */ scgcGetUserId: () => (/* binding */ scgcGetUserId),\n/* harmony export */ scgcLogin: () => (/* binding */ scgcLogin),\n/* harmony export */ scgcOpenexplorer: () => (/* binding */ scgcOpenexplorer),\n/* harmony export */ scgcOpenwechat: () => (/* binding */ scgcOpenwechat),\n/* harmony export */ scgcSaveFile: () => (/* binding */ scgcSaveFile),\n/* harmony export */ scgcSaveimage: () => (/* binding */ scgcSaveimage),\n/* harmony export */ scgcScan: () => (/* binding */ scgcScan),\n/* harmony export */ scgcSetVolume: () => (/* binding */ scgcSetVolume),\n/* harmony export */ scgcShare: () => (/* binding */ scgcShare),\n/* harmony export */ scgcToAppHome: () => (/* binding */ scgcToAppHome),\n/* harmony export */ scgcToDetail: () => (/* binding */ scgcToDetail),\n/* harmony export */ scgcToH5: () => (/* binding */ scgcToH5),\n/* harmony export */ scgcToKuaipai: () => (/* binding */ scgcToKuaipai),\n/* harmony export */ scgcToLive: () => (/* binding */ scgcToLive),\n/* harmony export */ scgcToMall: () => (/* binding */ scgcToMall),\n/* harmony export */ scgcToMallDetail: () => (/* binding */ scgcToMallDetail),\n/* harmony export */ scgcToSpecial: () => (/* binding */ scgcToSpecial),\n/* harmony export */ scgcToSubSpecial: () => (/* binding */ scgcToSubSpecial),\n/* harmony export */ scgcToTopic: () => (/* binding */ scgcToTopic),\n/* harmony export */ scgcToTopicCollection: () => (/* binding */ scgcToTopicCollection),\n/* harmony export */ scgcToTopicPublish: () => (/* binding */ scgcToTopicPublish),\n/* harmony export */ scgctoDocumentshow: () => (/* binding */ scgctoDocumentshow),\n/* harmony export */ scgctoVarietyshow: () => (/* binding */ scgctoVarietyshow),\n/* harmony export */ setDevMode: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_0__.setDevMode)\n/* harmony export */ });\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils */ \"./src/utils.ts\");\n/*#__PURE__*/\n\n(0,_utils__WEBPACK_IMPORTED_MODULE_0__.initAsyncCallbackPool)();\nvar commonBridge = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.commonBridgeFun)();\n\n/**\n * @deprecated 因阿里验证码1.0升级至2.0,原有scgcGetSlideData方法已使用scgcGetCaptchaVerifyParam替换,自 v1.1.0 起弃用,将在 v2.0.0 中移除\n *\n * @description 阿里滑动验证(使用的旧版api,目前官方文档已散佚,可参考其他项目)\n * @param {IGetSlideDataData} data\n */\nvar scgcGetSlideData = function (data) {\n commonBridge('getSlideData', data);\n};\n/**\n * @description 调用app登录\n */\nvar scgcLogin = function () {\n commonBridge('login');\n};\n/**\n * @description 调用app扫码\n */\nvar scgcScan = function () {\n commonBridge('scan');\n};\n/**\n * @description 关闭当前webview\n */\nvar scgcClose = function () {\n commonBridge('close');\n};\n/**\n * @description 使用系统浏览器打开指定的url\n * @param {IOpenexplorerData} data\n * @param {string} data.path 需要打开的url\n */\nvar scgcOpenexplorer = function (data) {\n commonBridge('openexplorer', data);\n};\n/**\n * @description 打开微信小程序\n * @param {IOpenwechatData} data\n * @param {string} data.appid 小程序appid,格式为gh开头\n * @param {string} data.path 小程序路径\n */\nvar scgcOpenwechat = function (data) {\n commonBridge('openwechat', data);\n};\n/**\n * @description 保存图片\n * @param {ISaveimageData} data\n * @param {string} data.data base64数据\n */\nvar scgcSaveimage = function (data) {\n commonBridge('saveimage', data);\n};\n/**\n * @description 保存文件(音频/视频)\n * @param {ISaveFileData} data\n * @param {'audio' | 'video'} data.fileType 文件类型\n * @param {string} data.path 文件路径\n */\nvar scgcSaveFile = function (data) {\n commonBridge('saveFile', data);\n};\n/**\n * @description 配置app分享\n * @param {IShareData} data\n * @param {string} data.shareUrl 需要分享的地址\n * @param {string} data.shareImg 分享的封面\n * @param {string} data.shareTitle 分享的标题\n * @param {string} data.shareDesc 分享的说明\n * @param {boolean} data.doShare 是否在调用bridge时立即触发app的分享,默认为仅修改配置\n */\nvar scgcShare = function (data) {\n commonBridge('share', data);\n};\n/**\n * @description 打开一个webview\n * @param {ItoH5Data} data\n * @param {string} data.path 需要打开的url\n */\nvar scgcToH5 = function (data) {\n commonBridge('toH5', data);\n};\n/**\n * @description 打开app原生新闻页\n * @param {IToDetailData} data\n * @param {string} data.path 新闻json地址 --相对地址,没有域名前缀的形式\n * @param {number} data.newsType 新闻类型 --1.图文 2.音频 3.视频 4.纯视频新闻 6 外链\n */\nvar scgcToDetail = function (data) {\n commonBridge('toDetail', data);\n};\n/**\n * @description 打开app原生专题详情页\n * @param {IToSpecialData} data\n * @param {string} data.id 专题id\n */\nvar scgcToSpecial = function (data) {\n commonBridge('toSpecial', data);\n};\n/**\n * @description 打开app原生直播页\n * @param {IToLiveData} data\n * @param {string} data.id 直播id\n * @param {string} data.type 直播样式 1 横版 2 竖版\n */\nvar scgcToLive = function (data) {\n commonBridge('toLive', data);\n};\n/**\n * @description 打开app话题页\n * @param {IToTopicData} data\n * @param {string} data.name 话题名称\n * @param {string} data.cover 话题封面图(完整的图片地址)\n * @param {string} data.id 话题id\n */\nvar scgcToTopic = function (data) {\n commonBridge('toTopic', data);\n};\n/**\n * @description 设置app音量\n * @param {ISetVolumeData} data\n * @param {number} data.type 0 调小 1 调大\n */\nvar scgcSetVolume = function (data) {\n commonBridge('setVolume', data);\n};\n/**\n * @description 打开app原生专题新闻列表页\n * @param {IToSubSpecialData} data\n * @param {string} data.title 专题标题\n * @param {string} data.id 专题id\n */\nvar scgcToSubSpecial = function (data) {\n commonBridge('toSubSpecial', data);\n};\n/**\n * @description 打开积分商城商品详情\n * @param {IMallDetailData} data\n * @param {string} data.json 商品详情json地址\n * @param {string} data.url 商品详情网页地址\n * @param {string} data.ptype todo 未知\n * @param {number} data.isDark 0 普通模式 1 黑暗模式\n */\nvar scgcToMallDetail = function (data) {\n commonBridge('detailJson', data);\n};\n/**\n * @description 是否禁用app左右滑动(主要用户嵌入在app首页的swiper,避免滑动swiper的情况下,会滑动app首页的tab页)\n * @param {IMallDetailData} data\n * @param {boolean} data.focus 是否禁止app滑动\n *\n */\nvar scgcFocusWeb = function (data) {\n commonBridge('focusWeb', data);\n};\n/**\n * @description 跳转至积分商城\n */\nvar scgcToMall = function () {\n commonBridge('mall');\n};\n/**\n * @description 跳转至快拍\n */\nvar scgcToKuaipai = function () {\n commonBridge('release');\n};\n/**\n * @description 跳转至app首页\n */\nvar scgcToAppHome = function () {\n commonBridge('mainPage');\n};\n/**\n * @description 设置app顶部时间栏颜色\n * @param {IChangeStateBarColorData} data\n * @param {number} data.type 1 黑色 2 白色\n *\n */\nvar scgcChangeStateBarColor = function (data) {\n commonBridge('changeStatebarColor', data);\n};\n/**\n * @description 获取app 用户id\n * @return {Promise((success:boolean,data:string))} 返回promise\n *\n */\nvar scgcGetUserId = function () {\n return commonBridge('getUserId');\n};\n/**\n * @description 获取app 用户头像\n * @return {Promise((success:boolean,data:string))} 返回promise\n *\n */\nvar scgcGetAvatar = function () {\n return commonBridge('getAvatar');\n};\n/**\n * @description 获取app 用户昵称\n * @return {Promise((success:boolean,data:string))} 返回promise\n *\n */\nvar scgcGetNickName = function () {\n return commonBridge('getNickName');\n};\n// /**\n// * @description 获取app 用户手机号\n// * @return {Promise((success:boolean,data:string))} 返回promise\n// *\n// */\nvar scgcGetPhoneNumber = function () {\n return commonBridge('getPhoneNumber');\n};\n/**\n * @description 传递验证码参数到app(阿里验证码2.0使用)\n * @param {IGetCaptchaVerifyParamData} data\n * @param {string} data.captchaVerifyParam 验证码参数\n */\nvar scgcGetCaptchaVerifyParam = function (data) {\n return commonBridge('getCaptchaVerifyParam', data);\n};\n/**\n * @description 打开原生综艺页面\n * @param {IProgramData} data\n * @param {string} data.programId 节目Id\n * @param {string} data.groupId 合集Id\n * @param {string} data.episodeId 单集Id\n */\nvar scgctoVarietyshow = function (data) {\n return commonBridge('toVarietyshow', data);\n};\n/**\n * @description 打开原生纪录片页面\n * @param {IProgramData} data\n * @param {string} data.programId 节目Id\n * @param {string} data.groupId 合集Id\n * @param {string} data.episodeId 单集Id\n */\nvar scgctoDocumentshow = function (data) {\n return commonBridge('toDocumentary', data);\n};\n/**\n * @description 打开话题合集页\n * @param {ITopicCollectionData} data\n * @param {string} data.type 话题合集类型\n */\nvar scgcToTopicCollection = function (data) {\n return commonBridge('toTopicCollection', data);\n};\n/**\n * @description 打开话题发布页\n * @param {ITopicPublishData} data\n * @param {string} data.id 话题Id(可选)\n * @param {string} data.name 话题名称(可选)\n */\nvar scgcToTopicPublish = function (data) {\n if (data === void 0) { data = {}; }\n return commonBridge('toTopicPublish', data);\n};\n/**\n * @description 复制文本到剪贴板\n * @param {ICopyTextData} data\n * @param {string} data.text 要复制的文本\n */\nvar scgcCopyText = function (data) {\n return commonBridge('copyText', data);\n};\n\n\n//# sourceURL=webpack://scgcBridge/./src/index.ts?\n}")},"./src/utils.ts"(__unused_webpack_module,__webpack_exports__,__webpack_require__){eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ commonBridgeFun: () => (/* binding */ commonBridgeFun),\n/* harmony export */ initAsyncCallbackPool: () => (/* binding */ initAsyncCallbackPool),\n/* harmony export */ isScgcApp: () => (/* binding */ isScgcApp),\n/* harmony export */ setDevMode: () => (/* binding */ setDevMode)\n/* harmony export */ });\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === \"function\" ? Iterator : Object).prototype);\n return g.next = verb(0), g[\"throw\"] = verb(1), g[\"return\"] = verb(2), typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n 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;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nvar distinctionPlatform = function () {\n var ua = navigator.userAgent;\n if (/(iPhone|iPad|iPod)/i.test(ua)) {\n return 'ios';\n }\n else if (/Android/i.test(ua)) {\n return 'android';\n }\n else if (/openharmony/i.test(ua)) {\n return 'harmony';\n }\n else {\n return 'unknow';\n }\n};\nvar asyncFunsArr = [\n 'getToken',\n 'getUserId',\n 'getAvatar',\n 'getNickName',\n 'getPhoneNumber',\n 'getPromise', //测试用\n];\nvar androidAsyncFunsArr = ['getPromise'];\nvar devMode = false;\nvar setDevMode = function () {\n devMode = true;\n};\nvar initAsyncCallbackPool = function () {\n window.bridgeCallbacks = {};\n};\nvar devFn = function (platform, fnName, data) {\n //动态判断是否为devMode,避免初始化commonBridgeFun比调用setDevMode的早的情况下,devMode参数已固定(损失的性能可以接受)\n if (devMode) {\n var devInfo = {\n platform: platform,\n fnName: fnName,\n data: data,\n };\n console.log(devInfo);\n }\n};\nfunction makeRandomId(fnName) {\n return \"\".concat(fnName || 'anonymous', \"_\").concat(Date.now());\n}\nfunction registerCallback(fnName, cb) {\n if (!cb) {\n return null;\n }\n var callbackId = makeRandomId(fnName);\n if (!window.hasOwnProperty('bridgeCallbacks')) {\n window.bridgeCallbacks = {};\n }\n window.bridgeCallbacks[callbackId] = function (data) {\n var result;\n if (typeof data === 'object') {\n result = data;\n }\n else if (typeof data === 'string') {\n try {\n result = JSON.parse(data);\n }\n catch (e) {\n result = data;\n }\n }\n cb(result);\n };\n return \"bridgeCallbacks.\".concat(callbackId);\n}\nfunction androidBridgeFn(fnName, data) {\n var _this = this;\n var _a, _b;\n var androidParams = {\n Method: fnName,\n Data: data,\n };\n devFn('android', fnName, data);\n if (fnName == 'getSlideData') {\n (_a = window === null || window === void 0 ? void 0 : window.testInterface) === null || _a === void 0 ? void 0 : _a.getSlideData(JSON.stringify(androidParams));\n }\n else if (asyncFunsArr.includes(fnName)) {\n var promiseRes = new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {\n var res, result;\n var _a, _b;\n return __generator(this, function (_c) {\n try {\n //安卓使用了异步返回\n if (androidAsyncFunsArr.includes(fnName)) {\n (_a = window === null || window === void 0 ? void 0 : window.newBridge) === null || _a === void 0 ? void 0 : _a[fnName](JSON.stringify({\n callback: registerCallback(fnName, resolve),\n }));\n }\n else {\n res = (_b = window === null || window === void 0 ? void 0 : window.newBridge) === null || _b === void 0 ? void 0 : _b[fnName]();\n result = void 0;\n if (typeof res === 'object') {\n result = res;\n }\n else if (typeof res === 'string') {\n try {\n result = JSON.parse(res);\n }\n catch (e) {\n result = { success: false, data: res };\n }\n }\n if ((result === null || result === void 0 ? void 0 : result.success) == true) {\n resolve(result);\n }\n else {\n reject(result);\n }\n }\n }\n catch (error) {\n reject(error);\n }\n return [2 /*return*/];\n });\n }); });\n return promiseRes;\n }\n else {\n (_b = window === null || window === void 0 ? void 0 : window.bridge) === null || _b === void 0 ? void 0 : _b.callRouter(JSON.stringify(androidParams), function () { });\n }\n}\nfunction iosBridgeFn(fnName, data) {\n var _this = this;\n var _a, _b, _c;\n devFn('ios', fnName, data);\n if (asyncFunsArr.includes(fnName)) {\n var promiseRes = new Promise(function (resolve, reject) {\n var _a, _b, _c;\n try {\n var _cb = function (res) { return __awaiter(_this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n try {\n if ((res === null || res === void 0 ? void 0 : res.success) == 'true') {\n resolve({\n success: true,\n data: res === null || res === void 0 ? void 0 : res.data,\n });\n }\n else {\n reject({\n success: false,\n data: res === null || res === void 0 ? void 0 : res.data,\n });\n }\n }\n catch (error) {\n reject({\n success: false,\n data: error,\n });\n }\n return [2 /*return*/];\n });\n }); };\n (_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b[fnName]) === null || _c === void 0 ? void 0 : _c.postMessage({\n data: {},\n callback: registerCallback(fnName, _cb),\n });\n }\n catch (error) {\n reject({\n success: false,\n data: error,\n });\n }\n });\n return promiseRes;\n }\n else {\n (_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b[fnName]) === null || _c === void 0 ? void 0 : _c.postMessage(data);\n }\n}\nfunction harmonyBridgeFn(fnName, data) {\n var _a, _b;\n devFn('harmony', fnName, data);\n if (asyncFunsArr.includes(fnName)) {\n var promiseRes = new Promise(function (resolve, reject) {\n var _a;\n try {\n (_a = window === null || window === void 0 ? void 0 : window.harmonyBridge) === null || _a === void 0 ? void 0 : _a[fnName]({\n data: data,\n callback: registerCallback(fnName, resolve),\n });\n }\n catch (error) {\n reject(error);\n }\n });\n return promiseRes;\n }\n else {\n (_b = (_a = window === null || window === void 0 ? void 0 : window.harmonyBridge) === null || _a === void 0 ? void 0 : _a[fnName]) === null || _b === void 0 ? void 0 : _b.call(_a, data);\n }\n}\nfunction defaultBridgeFn(fnName, data) {\n console.log('请使用scgc app打开');\n if (asyncFunsArr.includes(fnName)) {\n var promiseRes = new Promise(function (resolve, reject) {\n try {\n resolve('请使用scgc app打开');\n }\n catch (error) {\n reject(error);\n }\n });\n return promiseRes;\n }\n}\nvar commonBridgeFun = function () {\n var platform = distinctionPlatform();\n if (platform == 'android') {\n return androidBridgeFn;\n }\n else if (platform == 'ios') {\n return iosBridgeFn;\n }\n else if (platform == 'harmony') {\n return harmonyBridgeFn;\n }\n else {\n return defaultBridgeFn;\n }\n};\n/**\n * @description 是否为app环境\n * @return {boolean} true 是 false 否\n */\nvar isScgcApp = function () {\n return navigator.userAgent.indexOf('SCGC_UA') > -1;\n};\n\n\n//# sourceURL=webpack://scgcBridge/./src/utils.ts?\n}")}},__webpack_module_cache__={};function __webpack_require__(n){var a=__webpack_module_cache__[n];if(void 0!==a)return a.exports;var e=__webpack_module_cache__[n]={exports:{}};if(!(n in __webpack_modules__)){delete __webpack_module_cache__[n];var r=new Error("Cannot find module '"+n+"'");throw r.code="MODULE_NOT_FOUND",r}return __webpack_modules__[n](e,e.exports,__webpack_require__),e.exports}__webpack_require__.d=(n,a)=>{for(var e in a)__webpack_require__.o(a,e)&&!__webpack_require__.o(n,e)&&Object.defineProperty(n,e,{enumerable:!0,get:a[e]})},__webpack_require__.o=(n,a)=>Object.prototype.hasOwnProperty.call(n,a),__webpack_require__.r=n=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})};var __webpack_exports__=__webpack_require__("./src/index.ts");return __webpack_exports__})());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scgczm/bridge",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "scgczm app jsbridge",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
package/readme.dev.md CHANGED
@@ -3,3 +3,12 @@
3
3
  # umd 打包好之后放至 oss
4
4
 
5
5
  ## oss://scgc-sctv-bucket/sctv/dependencies/bridge/
6
+
7
+ ## 临时设置npm令牌
8
+ ```js
9
+ # 一次性使用(仅本次终端会话有效)
10
+ npm config set //registry.npmjs.org/:_authToken=你的令牌字符串
11
+
12
+ # 或永久保存到项目(推荐)
13
+ echo "//registry.npmjs.org/:_authToken=你的令牌字符串" >> .npmrc
14
+ ```