croods-1.3.3.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587
  1. (this.nativeLog || function(s) {console.log(s)})('WELCOME START CROODS JS FRAMEWORK 1.3.3, Build 2017-05-16 09:52.');
  2. ;(this.getJSFMVersion = function(){return '1.3.3'});
  3. (function (global, factory) {
  4. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  5. typeof define === 'function' && define.amd ? define(factory) :
  6. (global.croods = factory());
  7. }(this, (function () { 'use strict';
  8. var KEY_TYPE_ARR = ['volumedownbutton', 'volumeupbutton', 'searchbutton', 'menubutton', 'backbutton', 'homebutton'];
  9. var API_NAMES = {
  10. copy: 'BasePlugin.copy',
  11. loadUrl: 'BasePlugin.loadUrl',
  12. close: 'BasePlugin.close',
  13. goBack: 'BasePlugin.goBack',
  14. exit: 'BasePlugin.exit',
  15. request: 'RoutePlugin.request',
  16. networkType: 'BasePlugin.getNetworkType',
  17. bindButton: 'BasePlugin.bindButton',
  18. unbindButton: 'BasePlugin.unbindButton',
  19. appInfo: 'BasePlugin.getAppInfo',
  20. deviceInfo: 'BasePlugin.getDeviceInfo',
  21. getContact: 'ContactsPlugin.get'
  22. };
  23. /**
  24. * 请求统一路由
  25. * @param {Object} opt
  26. * opt{
  27. * method:'', 请求方法
  28. * params:{}, 请求参数
  29. * success: function(res){}, 成功回调
  30. * fail: function(res){} 失败回调
  31. * }
  32. */
  33. var ajax = function (opt) {
  34. var obj = checkParam(opt);
  35. var args = {};
  36. if (!obj.method) {
  37. throw new Error('The arguments "method" is required and cannot be null!')
  38. }
  39. checkParamsType({ name: 'method', value: obj.method, type: GLOBAL_STR.STRING });
  40. checkParamsType({ name: 'timeout', value: obj.timeout, type: GLOBAL_STR.NUMBER });
  41. args.t = obj.timeout || 8000;
  42. args.m = obj.method;
  43. if (obj.params && isNotObject(obj.params)) {
  44. throw new Error('The arguments "params" type must be object!')
  45. }
  46. if (!isEmptyObject(obj.params)) {
  47. args.p = obj.params;
  48. }
  49. obj.params = args;
  50. return exec(API_NAMES.request, obj)
  51. };
  52. /**
  53. * 调用自定义插件方法
  54. * @param {Object} opt
  55. * opt {
  56. * action: xxx.xx 自定义插件名称
  57. * params: {}可选 自定义插件参数
  58. * success: function(){} 可选 自定义插件成功回调
  59. * }
  60. */
  61. var customPlugin = function (opt) {
  62. var obj = checkParam(opt);
  63. if (!obj.action) {
  64. throw new Error('The arguments "action" is required!')
  65. }
  66. if (typeof obj.action !== GLOBAL_STR.STRING || obj.action.indexOf('.') === -1) {
  67. throw new Error('The arguments "action" type must be string, like:"PluginName.ActionName"!')
  68. }
  69. if (obj.params && isNotObject(obj.params)) {
  70. throw new Error('The arguments "params" type must be object!')
  71. }
  72. return exec(obj.action, obj)
  73. };
  74. /**
  75. * 复制
  76. * @param {Object} opt
  77. * opt{
  78. * content:'', 复制内容
  79. * }
  80. */
  81. var copy = function (opt) {
  82. var obj = checkParam(opt);
  83. if (!obj.content) {
  84. throw new Error('The arguments "content" is required!')
  85. }
  86. checkParamsType({ name: 'content', value: obj.content, type: GLOBAL_STR.STRING });
  87. obj.params = {
  88. content: obj.content
  89. };
  90. return exec(API_NAMES.copy, obj)
  91. };
  92. /**
  93. * 页面跳转
  94. * @param url 跳转地址
  95. * @param isClose 是否关闭当前页,默认false
  96. */
  97. var loadUrl = function (opt) {
  98. var obj = checkParam(opt);
  99. checkParamsType({ name: 'url', value: obj.url, type: GLOBAL_STR.STRING });
  100. obj.params = {
  101. url: obj.url,
  102. close: obj.close || false
  103. };
  104. return exec(API_NAMES.loadUrl, obj)
  105. };
  106. /**
  107. * 页面关闭(建议使用closePage,此方法名称过时)
  108. */
  109. var pageClose = function (opt) {
  110. var obj = checkParam(opt);
  111. obj.params = {};
  112. checkParamsType({ name: 'callback', value: obj.callback, type: GLOBAL_STR.STRING });
  113. obj.params.callback = obj.callback || GLOBAL_STR.NULL_STR;
  114. return exec(API_NAMES.close, obj)
  115. };
  116. var closePage = function (opt) {
  117. return pageClose(opt)
  118. };
  119. /**
  120. * 页面退出
  121. */
  122. var exit = function () {
  123. return exec(API_NAMES.exit, {})
  124. };
  125. /**
  126. * 页面返回
  127. */
  128. var goBack = function () {
  129. return exec(API_NAMES.goBack, {})
  130. };
  131. /**
  132. * 检查API是否存在
  133. * @param {Object} opt
  134. */
  135. var checkJsApi = function (opt) {
  136. var obj = checkParam(opt);
  137. var apis = obj.jsApiList;
  138. var result = {};
  139. if (!(apis instanceof Array)) {
  140. throw new Error('The arguments "jsApiList" type must be array!')
  141. }
  142. result = inArrayMap(apis, croods);
  143. typeof obj.success === GLOBAL_STR.FUNCTION && obj.success(result);
  144. };
  145. /**
  146. * 获取网络类型
  147. */
  148. var getNetworkType = function (opt) {
  149. return exec(API_NAMES.networkType, checkParam(opt))
  150. };
  151. /**
  152. * 获取应用信息
  153. */
  154. var getAppInfo = function (opt) {
  155. return exec(API_NAMES.appInfo, checkParam(opt))
  156. };
  157. /**
  158. * 获取设备信息
  159. */
  160. var getDeviceInfo = function (opt) {
  161. return exec(API_NAMES.deviceInfo, checkParam(opt))
  162. };
  163. /**
  164. * 绑定android物理按键
  165. * opt:{
  166. * keycode: ['volumedownbutton', 'volumeupbutton',
  167. * 'searchbutton', 'menubutton',
  168. * 'backbutton', 'homebutton'],
  169. * success: function(res){
  170. * res.action: 指定某个按钮
  171. * }
  172. * }
  173. */
  174. var bindButton = function (opt) {
  175. return buttonEventTrigger(API_NAMES.bindButton, opt)
  176. };
  177. /**
  178. * 解绑物理按键
  179. * opt:{
  180. * keycode: ['volumedownbutton', 'volumeupbutton',
  181. * 'searchbutton', 'menubutton',
  182. * 'backbutton', 'homebutton'],
  183. * success: function(res){
  184. * res.action: 指定某个按钮
  185. * }
  186. * }
  187. */
  188. var unbindButton = function (opt) {
  189. return buttonEventTrigger(API_NAMES.unbindButton, opt)
  190. };
  191. /**
  192. * 物理按键事件触发
  193. */
  194. var buttonEventTrigger = function (eventName, opt) {
  195. var obj = checkParam(opt);
  196. obj.params = {};
  197. if (!obj.keycode) {
  198. throw new Error('The arguments "keycode" is required and cannot be null!')
  199. }
  200. if (obj.keycode instanceof Array) {
  201. if (obj.keycode.length === 0) {
  202. throw new Error('The arguments "keycode" cannot be null!')
  203. }
  204. obj.keycode = obj.keycode.unique();
  205. for (var i = 0, len = obj.keycode.length; i < len; i++) {
  206. if (!inArray(obj.keycode[i], KEY_TYPE_ARR)) {
  207. throw new Error(("The arguments \"keycode\" value " + (obj.keycode[i]) + " invalid!"))
  208. }
  209. }
  210. }
  211. else {
  212. throw new Error('The arguments "keycode" type must be array !')
  213. }
  214. obj.params.keycode = obj.keycode;
  215. return exec(eventName, obj)
  216. };
  217. /**
  218. * 获取联系人信息
  219. * @param {Object} opt
  220. * success: function(res){
  221. * res.name : xx 返回联系人姓名
  222. * res.phoneNum: xx 返回联系人号码
  223. * }
  224. */
  225. var getContact = function (opt) {
  226. return exec(API_NAMES.getContact, checkParam(opt))
  227. };
  228. var CONFIG_INFO = {};
  229. /**
  230. * 配置
  231. * @param {Object} opt
  232. */
  233. var config = function (opt) {
  234. CONFIG_INFO = checkParam(opt);
  235. };
  236. /**
  237. * croods 工具包
  238. * @author jingli12
  239. */
  240. var GLOBAL_STR = {
  241. ANDROID: 'android',
  242. IOS: 'ios',
  243. IPHONE: 'iPhone',
  244. IPAD: 'iPad',
  245. OBJECT: 'object',
  246. STRING: 'string',
  247. BOOLEAN: 'boolean',
  248. NUMBER: 'number',
  249. FUNCTION: 'function',
  250. TIMEOUT: 'TIMEOUT',
  251. NULL_STR: ''
  252. };
  253. /**
  254. * check e is in arr
  255. * @param {Object} e
  256. * @param {Object} arr
  257. */
  258. var inArray = function (e, arr) {
  259. if (arr && arr instanceof Array) {
  260. for (var i = 0; i < arr.length; i++) {
  261. if (e === arr[i]) {
  262. return true
  263. }
  264. }
  265. return false
  266. }
  267. return false
  268. };
  269. var inArrayMap = function (arr, croods) {
  270. var result = {};
  271. var api = null;
  272. if (arr && arr instanceof Array) {
  273. for (var i = 0; i < arr.length; i++) {
  274. api = arr[i].split('.');
  275. result[arr[i]] = false;
  276. for (var o in croods) {
  277. if (o === api[0]) {
  278. // 判断是否子方法
  279. if (typeof croods[o] === GLOBAL_STR.OBJECT && api[1]) {
  280. for (var c in croods[o]) {
  281. if (c === api[1]) {
  282. result[arr[i]] = true;
  283. }
  284. }
  285. }
  286. else {
  287. result[arr[i]] = true;
  288. }
  289. }
  290. }
  291. }
  292. }
  293. return result
  294. };
  295. /**
  296. * check array unique
  297. */
  298. Array.prototype.unique = function () {
  299. var this$1 = this;
  300. var arr = [];
  301. var obj = {};
  302. for (var i = 0; i < this.length; i++) {
  303. if (!obj[this$1[i]]) {
  304. arr.push(this$1[i]);
  305. obj[this$1[i]] = 1;
  306. }
  307. }
  308. return arr
  309. };
  310. /**
  311. * check object is empty
  312. * @param {Object} o
  313. */
  314. var isEmptyObject = function (o) {
  315. for (var t in o) { return false }
  316. return true
  317. };
  318. /**
  319. * check isNotObject
  320. * @param {Object} o
  321. */
  322. var isNotObject = function (o) {
  323. if (typeof o !== GLOBAL_STR.OBJECT || o instanceof Array) {
  324. return true
  325. }
  326. return false
  327. };
  328. /**
  329. * check request param
  330. * @param {Object} opt
  331. */
  332. var checkParam = function (opt) {
  333. var obj = opt || {};
  334. if (isNotObject(obj)) {
  335. throw new Error('The arguments type must be object!')
  336. }
  337. return obj
  338. };
  339. /**
  340. * checkParamsType
  341. * @param value
  342. * @param type
  343. */
  344. var checkParamsType = function (obj) {
  345. if (obj.value && obj.type && typeof obj.value !== obj.type) {
  346. throw new Error('The arguments "' + obj.name + '" type must be ' + obj.type + '!')
  347. }
  348. };
  349. /**
  350. * check userAgent
  351. */
  352. var userAgent = function () {
  353. var agent = navigator.userAgent;
  354. var os = GLOBAL_STR.ANDROID;
  355. if (agent.indexOf(GLOBAL_STR.IPHONE) !== -1 ||
  356. agent.indexOf(GLOBAL_STR.IPAD) !== -1) {
  357. os = GLOBAL_STR.IOS;
  358. }
  359. return os
  360. };
  361. /**
  362. * setAndroidJsToNativeMode
  363. * @param obj
  364. */
  365. var setAndroidJsToNativeMode = function (obj) {
  366. var agent = navigator.userAgent;
  367. var index = agent.indexOf(GLOBAL_STR.ANDROID);
  368. var version = 4.4;
  369. if (index !== -1) {
  370. version = parseFloat(agent.slice(index + 8, index + 13));
  371. }
  372. if (version < 4.4) {
  373. setAndroidJsToNativeMode = function (obj) {
  374. window.prompt('iflytek:' + JSON.stringify(obj));
  375. };
  376. }
  377. else {
  378. setAndroidJsToNativeMode = function (obj) {
  379. croodsBridge.exec('iflytek:' + JSON.stringify(obj));
  380. };
  381. }
  382. setAndroidJsToNativeMode(obj);
  383. };
  384. /**
  385. * create iframe for ios invoke
  386. */
  387. var createExecIframe = function () {
  388. var iframe = document.createElement('iframe');
  389. iframe.style.display = 'none';
  390. iframe.src = '';
  391. document.body.appendChild(iframe);
  392. return iframe
  393. };
  394. /**
  395. * 调试输出
  396. */
  397. var debug = {
  398. log: function (msg) {
  399. if (CONFIG_INFO.debug) {
  400. console.log(msg);
  401. }
  402. },
  403. alert: function (msg) {
  404. if (CONFIG_INFO.debug) {
  405. window.alert(msg);
  406. }
  407. }
  408. };
  409. var ExecIframe;
  410. var callbackObj = {
  411. // Generate callbackId for call api callback function name
  412. callbackId: Math.floor(Math.random() * 10000000000),
  413. // Queue for ios request
  414. commandQueue: [],
  415. // Object for call api callbacks.
  416. callbacks: {},
  417. // promise style call.
  418. $deferred: function () {
  419. var obj = {};
  420. obj.success = function (callback) {
  421. if (typeof callback === GLOBAL_STR.FUNCTION) {
  422. this._success = callback;
  423. }
  424. return this
  425. };
  426. obj.fail = function (callback) {
  427. if (typeof callback === GLOBAL_STR.FUNCTION) {
  428. this._fail = callback;
  429. }
  430. return this
  431. };
  432. obj.complete = function (callback) {
  433. if (typeof callback === GLOBAL_STR.FUNCTION) {
  434. this._complete = callback;
  435. }
  436. return this
  437. };
  438. obj.cancel = function (callback) {
  439. if (typeof callback === GLOBAL_STR.FUNCTION) {
  440. this._cancel = callback;
  441. }
  442. return this
  443. };
  444. return obj
  445. },
  446. // callback status code
  447. callbackStatus: {
  448. OK: 10000, // plugin success code
  449. CANCEL: 10007, // plugin cancel code
  450. TIMEOUT: 10012, // plugin request timeout
  451. TIMEOUT_ROUTER: 40001, // plugin request timeout for router
  452. OK_ROUTER: 1, // router request success
  453. FAIL_ROUTER: 0 // router request fail
  454. },
  455. // create callback for invoke
  456. create: function (callbackId, $deferred) {
  457. window[callbackId] = function (result) {
  458. var c = callbackObj.callbacks[callbackId];
  459. callbackHandler(c, result, $deferred);
  460. };
  461. }
  462. };
  463. /**
  464. * 回调处理函数
  465. */
  466. var callbackHandler = function (c, result, $deferred) {
  467. var s = callbackObj.callbackStatus;
  468. var e = result.code;
  469. var m = result.message;
  470. switch (e) {
  471. case s.OK:
  472. var o = m ? JSON.parse(m) : {};
  473. if (o.status == undefined) {
  474. c.success && c.success(o);
  475. setTimeout(function () {
  476. $deferred && $deferred._success && $deferred._success(o);
  477. }, 0);
  478. break
  479. }
  480. // 打开统一路由请求调试
  481. debug.alert(JSON.stringify(result));
  482. if (o.status == s.OK_ROUTER) {
  483. c.success && c.success(o.result);
  484. setTimeout(function () {
  485. $deferred && $deferred._success && $deferred._success(o.result);
  486. }, 0);
  487. break
  488. }
  489. if (o.status == s.FAIL_ROUTER) {
  490. c.fail && c.fail(o.errorCode + ': ' + o.errorMessage);
  491. setTimeout(function () {
  492. $deferred && $deferred._fail && $deferred._fail(o.errorCode + ': ' + o.errorMessage);
  493. }, 0);
  494. }
  495. break
  496. case s.CANCEL:
  497. c.cancel && c.cancel(result);
  498. setTimeout(function () {
  499. $deferred && $deferred._cancel && $deferred._cancel(result);
  500. }, 0);
  501. break
  502. case s.TIMEOUT_ROUTER:
  503. result.status = GLOBAL_STR.TIMEOUT;
  504. break
  505. default:
  506. c.fail && c.fail(e + ': ' + m);
  507. setTimeout(function () {
  508. $deferred && $deferred._fail && $deferred._fail(e + ': ' + m);
  509. }, 0);
  510. }
  511. c.complete && c.complete(result);
  512. setTimeout(function () {
  513. $deferred && $deferred._complete && $deferred._complete(result);
  514. }, 0);
  515. };
  516. /**
  517. * croods ExecObj obj
  518. */
  519. var ExecObj = {
  520. /**
  521. * Format params for call api.
  522. * @param {Object} action
  523. * @param {Object} obj
  524. */
  525. args: function (_action, obj) {
  526. var action = _action.split('.');
  527. var callbackId = action[0] + callbackObj.callbackId++;
  528. var callback = {};
  529. var param = {
  530. service: action[0],
  531. action: action[1]
  532. };
  533. if (typeof obj.success === GLOBAL_STR.FUNCTION) {
  534. callback.success = obj.success;
  535. }
  536. if (typeof obj.fail === GLOBAL_STR.FUNCTION) {
  537. callback.fail = obj.fail;
  538. }
  539. if (typeof obj.complete === GLOBAL_STR.FUNCTION) {
  540. callback.complete = obj.complete;
  541. }
  542. if (typeof obj.cancel === GLOBAL_STR.FUNCTION) {
  543. callback.cancel = obj.cancel;
  544. }
  545. callbackObj.callbacks[callbackId] = callback;
  546. param.callback = callbackId;
  547. param.params = obj.params || {};
  548. return param
  549. },
  550. /**
  551. * Android invoke
  552. * @param {Object} obj
  553. */
  554. android: function (obj) {
  555. debug.log(JSON.stringify(obj));
  556. // window.prompt('iflytek:' + JSON.stringify(obj))
  557. setAndroidJsToNativeMode(obj);
  558. },
  559. /**
  560. * IOS invoke
  561. * @param {Object} obj
  562. */
  563. ios: function (obj) {
  564. callbackObj.commandQueue.push(obj);
  565. ExecIframe = ExecIframe || createExecIframe();
  566. ExecIframe.src = 'iflytek://ready';
  567. }
  568. };
  569. /**
  570. * invoke api .
  571. * @param {Object} action
  572. * @param {Object} obj
  573. */
  574. var exec = function (action, obj) {
  575. var params = ExecObj.args(action, obj);
  576. var callbackId = params.callback;
  577. var callback = callbackObj.callbacks[callbackId];
  578. var $deferred = isEmptyObject(callback) ? new callbackObj.$deferred() : null;
  579. callbackObj.create(callbackId, $deferred);
  580. ExecObj[userAgent()](params);
  581. return $deferred
  582. };
  583. /**
  584. * 获取队列中请求信息
  585. */
  586. var nativeFetchQueue = function () {
  587. var commandStr = JSON.stringify(callbackObj.commandQueue);
  588. callbackObj.commandQueue = [];
  589. debug.log(commandStr);
  590. return commandStr
  591. };
  592. /**
  593. * 销毁回调
  594. * @param {Object} callbackId
  595. */
  596. var callbackDestroy = function (callbackId) {
  597. delete window[callbackId];
  598. delete callbackObj.callbacks[callbackId];
  599. debug.log('Destroy Function: ' + callbackId);
  600. };
  601. var API_NAMES$1 = {
  602. open: 'GeoPlugin.open',
  603. close: 'GeoPlugin.close',
  604. get: 'GeoPlugin.getLocation'
  605. };
  606. /**
  607. * 打开定位
  608. * @param {Object} opt
  609. * opt {
  610. * interval: 代表每隔n秒进行一次定位,默认5000
  611. * success: function(res){
  612. * res.acc: 精度,
  613. * res.lng: 经度,
  614. * res.lat: 纬度,
  615. * res.alt: 海拔,
  616. * }
  617. * }
  618. */
  619. var openLocation = function (opt) {
  620. var obj = checkParam(opt);
  621. obj.params = {};
  622. checkParamsType({ name: 'interval', value: obj.interval, type: GLOBAL_STR.NUMBER });
  623. obj.params.interval = obj.interval || 5000;
  624. return exec(API_NAMES$1.open, obj)
  625. };
  626. /**
  627. * 关闭定位
  628. */
  629. var closeLocation = function (opt) {
  630. return exec(API_NAMES$1.close, checkParam(opt))
  631. };
  632. /**
  633. * 获取地理位置信息
  634. * @param {Object} opt
  635. * opt {
  636. * lng: 经度
  637. * lat: 纬度
  638. * success: function(res){
  639. * res:{
  640. * nation: xxx,
  641. * province: xxxx,
  642. * city: xxxxx,
  643. * district: xxxxx,
  644. * street: xxxxx,
  645. * streetNum: xxxxx
  646. * }
  647. * }
  648. */
  649. var getLocation = function (opt) {
  650. var obj = checkParam(opt);
  651. if (!obj.lng) {
  652. throw new Error('The arguments "lng" is required!')
  653. }
  654. checkParamsType({ name: 'lng', value: obj.lng, type: GLOBAL_STR.NUMBER });
  655. if (!obj.lat) {
  656. throw new Error('The arguments "lat" is required!')
  657. }
  658. checkParamsType({ name: 'lat', value: obj.lat, type: GLOBAL_STR.NUMBER });
  659. obj.params = {
  660. lng: obj.lng,
  661. lat: obj.lat
  662. };
  663. return exec(API_NAMES$1.get, obj)
  664. };
  665. var API_NAMES$2 = {
  666. shareContent: 'SharePlugin.shareContent',
  667. setPlatformConfig: 'SharePlugin.setPlatformConfig',
  668. thirdpartyLogin: 'SharePlugin.thirdpartyLogin'
  669. };
  670. /**
  671. * 分享平台类型
  672. * @type {object}
  673. */
  674. var sharePlatform = {
  675. QQ: 1,
  676. QZone: 2,
  677. SinaWeibo: 3,
  678. WeChatSession: 4,
  679. WeChatTimeline: 5,
  680. WeChatFav: 6
  681. };
  682. /**
  683. * 第三方登录平台类型
  684. * @type {object}
  685. */
  686. var loginPlatform = {
  687. QQ: 0,
  688. WeChat: 1,
  689. SinaWeibo: 2
  690. };
  691. /**
  692. * 内容分享类型
  693. * @type {object}
  694. */
  695. var shareType = {
  696. Text: 0,
  697. Image: 1,
  698. WebPage: 2,
  699. Music: 3,
  700. Video: 4,
  701. Apps: 5,
  702. File: 6
  703. };
  704. /**
  705. * 分享内容
  706. * @param {Object} opt
  707. * {
  708. * platform: croods.sharePlatform.SinaWeibo,
  709. shareParams: {
  710. type: croods.shareType.Text,
  711. text: '测试一下分享',
  712. url: 'http://www.baidu.com',
  713. title: '测试',
  714. titleUrl: '',
  715. site: ''
  716. siteUrl:''
  717. imageUrl: ''
  718. },
  719. success: function(res){
  720. }
  721. }
  722. */
  723. var shareContent = function (opt) {
  724. var obj = checkParam(opt);
  725. if (!obj.platform) {
  726. throw new Error('The arguments "platform" is required !')
  727. }
  728. checkParamsType({ name: 'platform', value: obj.platform, type: GLOBAL_STR.NUMBER });
  729. if (!obj.shareParams) {
  730. throw new Error('The arguments "shareParams" is required!')
  731. }
  732. if (isNotObject(obj.shareParams)) {
  733. throw new Error('The arguments "shareParams" type must be object!')
  734. }
  735. if (typeof obj.shareParams.type !== GLOBAL_STR.NUMBER) {
  736. throw new Error('The arguments "shareParams.type" is required and type must be number!')
  737. }
  738. if (!obj.shareParams.text) {
  739. throw new Error('The arguments "shareParams.text" is required!')
  740. }
  741. checkParamsType({ name: 'shareParams.text', value: obj.shareParams.text, type: GLOBAL_STR.STRING });
  742. obj.params = {
  743. platform: obj.platform,
  744. shareParams: obj.shareParams
  745. };
  746. return exec(API_NAMES$2.shareContent, obj)
  747. };
  748. /**
  749. * 第三方登录
  750. * @param {Object} opt
  751. * {
  752. * platform: croods.loginPlatform.SinaWeibo,
  753. success: function(res){
  754. platformType: '2' // 平台类型
  755. uid: '' // 用户在平台的uid
  756. nickname: '' // 用户昵称
  757. imageUrl: '' // 头像url地址
  758. gender: 0 // 性别
  759. homePage: '' // 用户主页
  760. about: '' // 用户简介
  761. birthday: '' // 生日,毫秒数
  762. followerCount: '' // 粉丝数
  763. friendCount: '' // 好友数
  764. shareCount: '' //分享数
  765. }
  766. }
  767. */
  768. var thirdpartyLogin = function (opt) {
  769. var obj = checkParam(opt);
  770. if (typeof obj.platform !== GLOBAL_STR.NUMBER) {
  771. throw new Error('The arguments "platform" is required and type must be number!')
  772. }
  773. obj.params = {
  774. platform: obj.platform
  775. };
  776. return exec(API_NAMES$2.thirdpartyLogin, obj)
  777. };
  778. /**
  779. * 设置平台配置
  780. * @param {Object} opt
  781. */
  782. var setPlatformConfig = function (opt) {
  783. var obj = checkParam(opt);
  784. if (typeof obj.platform !== GLOBAL_STR.NUMBER) {
  785. throw new Error('The arguments "platform" is required and type must be number!')
  786. }
  787. if (!obj.config) {
  788. throw new Error('The arguments "config" is required!')
  789. }
  790. if (isNotObject(obj.config)) {
  791. throw new Error('The arguments "config" type must be object!')
  792. }
  793. obj.params = {
  794. platform: obj.platform,
  795. config: obj.config
  796. };
  797. return exec(API_NAMES$2.setPlatformConfig, obj)
  798. };
  799. var API_NAMES$3 = {
  800. start: 'DownloadPlugin.start',
  801. listener: 'DownloadPlugin.listener',
  802. download: 'DownloadPlugin.download',
  803. cancel: 'DownloadPlugin.cancel',
  804. open: 'FilePlugin.open',
  805. choose: 'FilePlugin.choose',
  806. upload: 'UploadPlugin.upload',
  807. unzip: 'FilePlugin.unzip'
  808. };
  809. /**
  810. * 开始下载文件 *注 1.3.2后弃用
  811. * @param {Object} opt
  812. * opt {
  813. * url: "xx",
  814. * success: function(e){
  815. * }
  816. * }
  817. */
  818. var startDownload = function (opt) {
  819. var obj = checkParam(opt);
  820. obj.params = {};
  821. if (!obj.url) {
  822. throw new Error('The arguments "url" is required and cannot be null!')
  823. }
  824. checkParamsType({ name: 'url', value: obj.url, type: GLOBAL_STR.STRING });
  825. obj.params.url = obj.url;
  826. return exec(API_NAMES$3.start, obj)
  827. };
  828. /**
  829. * 下载文件监听 *注 1.3.2后弃用
  830. * @param {Object} opt
  831. * opt {
  832. * success: function(msg){
  833. * msg.process: "xx",//进度
  834. * msg.speed: "xx", //速度
  835. * msg.size: "", //文件大小
  836. * msg.hasDownSize: "", //已经下载大小
  837. * msg.path: "xx"//文件位置
  838. * },
  839. * fail: function(msg){
  840. * }
  841. * }
  842. */
  843. var downloadListener = function (opt) {
  844. return exec(API_NAMES$3.listener, checkParam(opt))
  845. };
  846. /**
  847. * 下载文件
  848. * @param {Object} opt
  849. * opt {
  850. * url: "xx",
  851. * success: function(e){
  852. * }
  853. * }
  854. */
  855. var download = function (opt) {
  856. var obj = checkParam(opt);
  857. obj.params = {};
  858. if (!obj.url) {
  859. throw new Error('The arguments "url" is required and cannot be null!')
  860. }
  861. checkParamsType({ name: 'url', value: obj.url, type: GLOBAL_STR.STRING });
  862. obj.params.url = obj.url;
  863. return exec(API_NAMES$3.download, obj)
  864. };
  865. /**
  866. * 取消下载
  867. * @param {Object} opt
  868. */
  869. var cancelDownload = function (opt) {
  870. return exec(API_NAMES$3.cancel, checkParam(opt))
  871. };
  872. /**
  873. * 打开文件
  874. * @param {Object} opt
  875. * opt {
  876. * filePath:文件路径
  877. * }
  878. */
  879. var openFile = function (opt) {
  880. var obj = checkParam(opt);
  881. obj.params = {};
  882. if (!obj.filePath) {
  883. throw new Error('The arguments "filePath" is required and cannot be null!')
  884. }
  885. checkParamsType({ name: 'filePath', value: obj.filePath, type: GLOBAL_STR.STRING });
  886. obj.params.filePath = obj.filePath;
  887. return exec(API_NAMES$3.open, obj)
  888. };
  889. /**
  890. * 选择文件
  891. * @param {Object} opt
  892. * opt {
  893. * path:'/sdcard', 指定查找目录
  894. * reg: '/.jpg$/', 指定查找规则,正则表示
  895. * recursive: true/false 是否递归查找
  896. * success: function(res){
  897. * res: 文件对象信息,包含文件大小、路径、类型等
  898. * }
  899. * }
  900. */
  901. var chooseFile = function (opt) {
  902. var obj = checkParam(opt);
  903. obj.params = {};
  904. checkParamsType({ name: 'path', value: obj.path, type: GLOBAL_STR.STRING });
  905. checkParamsType({ name: 'reg', value: obj.reg, type: GLOBAL_STR.STRING });
  906. checkParamsType({ name: 'recursive', value: obj.recursive, type: GLOBAL_STR.BOOLEAN });
  907. obj.params.recursive = typeof obj.recursive === GLOBAL_STR.BOOLEAN ? obj.recursive : false;
  908. obj.params.path = obj.path ? obj.path : undefined;
  909. obj.params.reg = obj.reg ? obj.reg : undefined;
  910. return exec(API_NAMES$3.choose, obj)
  911. };
  912. /**
  913. * 文件上传
  914. */
  915. var upload = function (opt) {
  916. var obj = checkParam(opt);
  917. obj.params = {};
  918. if (!obj.method) {
  919. throw new Error('The arguments "method" is required and cannot be null!')
  920. }
  921. checkParamsType({ name: 'method', value: obj.method, type: GLOBAL_STR.STRING });
  922. checkParamsType({ name: 'fileSizeLimit', value: obj.fileSizeLimit, type: GLOBAL_STR.NUMBER });
  923. obj.params.method = obj.method;
  924. if (obj.fileSizeLimit) {
  925. obj.params.fileSizeLimit = obj.fileSizeLimit;
  926. }
  927. if (obj.files && isNotObject(obj.files)) {
  928. throw new Error('The arguments "files" type must be object!')
  929. }
  930. if (isEmptyObject(obj.files)) {
  931. throw new Error('The arguments "files" is required and cannot be null!!')
  932. }
  933. obj.params.files = obj.files;
  934. if (obj.formData && isNotObject(obj.formData)) {
  935. throw new Error('The arguments "formData" type must be object!')
  936. }
  937. if (!isEmptyObject(obj.formData)) {
  938. obj.params.formData = obj.formData;
  939. }
  940. return exec(API_NAMES$3.upload, obj)
  941. };
  942. /**
  943. * 解压文件
  944. * @param {Object} opt
  945. * opt {
  946. * filePath:文件路径
  947. * }
  948. */
  949. var unzip = function (opt) {
  950. var obj = checkParam(opt);
  951. obj.params = {};
  952. if (!obj.filePath) {
  953. throw new Error('The arguments "filePath" is required and cannot be null!')
  954. }
  955. checkParamsType({ name: 'filePath', value: obj.filePath, type: GLOBAL_STR.STRING });
  956. obj.params.filePath = obj.filePath;
  957. return exec(API_NAMES$3.unzip, obj)
  958. };
  959. var API_NAMES$4 = {
  960. add: 'StoragePlugin.add',
  961. get: 'StoragePlugin.get',
  962. getAll: 'StoragePlugin.getAll',
  963. remove: 'StoragePlugin.remove',
  964. removeAll: 'StoragePlugin.removeAll'
  965. };
  966. var storage = {
  967. /**
  968. * add data
  969. * @param {Object} opt
  970. */
  971. add: function (opt) {
  972. var obj = checkParam(opt);
  973. if (!obj.params || isEmptyObject(obj.params)) {
  974. throw new Error('The arguments "params" is required!')
  975. }
  976. if (isNotObject(obj.params)) {
  977. throw new Error('The arguments "params" type must be object!')
  978. }
  979. return exec(API_NAMES$4.add, obj)
  980. },
  981. /**
  982. * get data
  983. * @param {Object} opt
  984. */
  985. get: function (opt) {
  986. var obj = checkParam(opt);
  987. obj.params = {};
  988. if (!obj.key) {
  989. throw new Error('The arguments "key" is required!')
  990. }
  991. checkParamsType({ name: 'key', value: obj.key, type: GLOBAL_STR.STRING });
  992. obj.params.key = obj.key;
  993. return exec(API_NAMES$4.get, obj)
  994. },
  995. /**
  996. * get all
  997. * @param {Object} opt
  998. */
  999. getAll: function (opt) {
  1000. return exec(API_NAMES$4.getAll, checkParam(opt))
  1001. },
  1002. /**
  1003. * remove data
  1004. * @param {Object} opt
  1005. */
  1006. remove: function (opt) {
  1007. var obj = checkParam(opt);
  1008. obj.params = {};
  1009. if (!obj.key) {
  1010. throw new Error('The arguments "key" is required!')
  1011. }
  1012. checkParamsType({ name: 'key', value: obj.key, type: GLOBAL_STR.STRING });
  1013. obj.params.key = obj.key;
  1014. return exec(API_NAMES$4.remove, obj)
  1015. },
  1016. /**
  1017. * remove all
  1018. * @param {Object} opt
  1019. */
  1020. removeAll: function (opt) {
  1021. return exec(API_NAMES$4.removeAll, checkParam(opt))
  1022. }
  1023. };
  1024. var LD_ACTIONS = ['blink', 'mouth', 'yaw', 'nod'];
  1025. var IAT_DOMAINS = ['iat', 'search', 'video', 'poi', 'music', 'asr'];
  1026. var IAT_LANGUAGES = ['zh_cn', 'en_us'];
  1027. var IAT_ACCENTS = ['mandarin', 'cantonese', 'henanese'];
  1028. var API_NAMES$5 = {
  1029. take: 'ImagePlugin.takePhoto',
  1030. choose: 'ImagePlugin.choose',
  1031. previewImage: 'ImagePlugin.preview',
  1032. start: 'AudioPlugin.startRecord',
  1033. listener: 'AudioPlugin.recordListener',
  1034. stop: 'AudioPlugin.stopRecord',
  1035. play: 'AudioPlugin.startPlay',
  1036. playListener: 'AudioPlugin.playListener',
  1037. stopVoice: 'AudioPlugin.stopPlay',
  1038. livenessDetect: 'LivenessPlugin.detect',
  1039. scanning: 'QRCodePlugin.scanCode',
  1040. generate: 'QRCodePlugin.generate',
  1041. startIat: 'SpeechPlugin.startIat',
  1042. stopIat: 'SpeechPlugin.stopIat',
  1043. playVideo: 'VideoPlugin.play'
  1044. };
  1045. /**
  1046. * 调用摄像头
  1047. * @param {Object} opt
  1048. * opt {
  1049. * success: function(res){
  1050. * res.filePath: 照片路径
  1051. * }
  1052. * }
  1053. */
  1054. var takePhoto = function (opt) {
  1055. return exec(API_NAMES$5.take, checkParam(opt))
  1056. };
  1057. /**
  1058. * 选择图片
  1059. * @param {Object} opt
  1060. * opt {
  1061. * count: 选择图片数量,默认为1
  1062. * success: function(res){
  1063. * res: [{...}] //图片数组,包含图片url等信息
  1064. * }
  1065. * }
  1066. */
  1067. var chooseImage = function (opt) {
  1068. var obj = checkParam(opt);
  1069. checkParamsType({ name: 'count', value: obj.count, type: GLOBAL_STR.NUMBER });
  1070. obj.params = {
  1071. count: obj.count || 1
  1072. };
  1073. return exec(API_NAMES$5.choose, obj)
  1074. };
  1075. /**
  1076. * 查看图片
  1077. * @param {Object} opt
  1078. * opt {
  1079. * paths:[] 页面中所有图片路径,array,首次调用必填
  1080. * index:当前点击图片的索引,number,必填
  1081. * success: function(res){
  1082. * res: [{...}] //
  1083. * }
  1084. * }
  1085. */
  1086. var previewImage = function (opt) {
  1087. var obj = checkParam(opt);
  1088. if (obj.paths && !(obj.paths instanceof Array)) {
  1089. throw new Error('The arguments "paths" type must be array!')
  1090. }
  1091. if (obj.index === '' || obj.index === undefined || obj.index === null) {
  1092. throw new Error('The arguments "index" is required!')
  1093. }
  1094. checkParamsType({ name: 'index', value: obj.index, type: GLOBAL_STR.NUMBER });
  1095. obj.params = {
  1096. paths: obj.paths,
  1097. index: obj.index
  1098. };
  1099. return exec(API_NAMES$5.previewImage, obj)
  1100. };
  1101. /**
  1102. * 活体检测
  1103. * @param {Object} opt
  1104. * success: function(res){
  1105. * res.photo : xx返回图片地址
  1106. * }
  1107. */
  1108. var livenessDetect = function (opt) {
  1109. var obj = checkParam(opt);
  1110. if (obj.actions) {
  1111. if (obj.actions instanceof Array) {
  1112. obj.actions = obj.actions.unique();
  1113. if (!inArray(LD_ACTIONS[0], obj.actions)) {
  1114. throw new Error(("The arguments 'actions' value must has " + (obj.actions[0]) + " !"))
  1115. }
  1116. for (var i = 0, len = obj.actions.length; i < len; i++) {
  1117. if (!inArray(obj.actions[i], LD_ACTIONS)) {
  1118. throw new Error(("The arguments 'actions' value " + (obj.actions[i]) + " invalid!"))
  1119. }
  1120. }
  1121. }
  1122. else {
  1123. throw new Error('The arguments "actions" type must be array!')
  1124. }
  1125. }
  1126. checkParamsType({ name: 'soundNotice', value: obj.soundNotice, type: GLOBAL_STR.BOOLEAN });
  1127. obj.params = {
  1128. actions: obj.actions || LD_ACTIONS,
  1129. soundNotice: typeof obj.soundNotice === GLOBAL_STR.BOOLEAN ? obj.soundNotice : true
  1130. };
  1131. return exec(API_NAMES$5.livenessDetect, obj)
  1132. };
  1133. /**
  1134. * 二维码扫描
  1135. * @param {Object} opt
  1136. * success: function(res){
  1137. * res : xx返回扫描内容
  1138. * }
  1139. */
  1140. var scanQRCode = function (opt) {
  1141. return exec(API_NAMES$5.scanning, checkParam(opt))
  1142. };
  1143. /**
  1144. * 二维码生成
  1145. * @param {Object} opt
  1146. * opt{
  1147. * content: 需要生成二维码的内容
  1148. * size:二维码的大小,默认为200
  1149. * success: function(res){
  1150. * res.: xx
  1151. * }
  1152. * }
  1153. */
  1154. var createQRCode = function (opt) {
  1155. var obj = checkParam(opt);
  1156. checkParamsType({ name: 'content', value: obj.content, type: GLOBAL_STR.STRING });
  1157. checkParamsType({ name: 'size', value: obj.size, type: GLOBAL_STR.NUMBER });
  1158. obj.params = {
  1159. content: obj.content || '',
  1160. size: obj.size || 200
  1161. };
  1162. return exec(API_NAMES$5.generate, obj)
  1163. };
  1164. /**
  1165. * 开始录音
  1166. * @param {Object} opt
  1167. */
  1168. var startRecord = function (opt) {
  1169. return exec(API_NAMES$5.start, checkParam(opt))
  1170. };
  1171. /**
  1172. * 录音监听
  1173. * @param {Object} opt
  1174. * opt {
  1175. * success: function(res){
  1176. * res.volume: 音量大小
  1177. * res.voiceLen: 录音长度s
  1178. * },
  1179. * error: function(res){
  1180. *
  1181. * }
  1182. * }
  1183. */
  1184. var recordListener = function (opt) {
  1185. return exec(API_NAMES$5.listener, checkParam(opt))
  1186. };
  1187. /**
  1188. * 停止录音
  1189. * @param {Object} opt
  1190. * success: function(res){
  1191. * res.filePath: 录音位置
  1192. * },
  1193. * error: function(res){
  1194. *
  1195. * }
  1196. * }
  1197. *
  1198. */
  1199. var stopRecord = function (opt) {
  1200. return exec(API_NAMES$5.stop, checkParam(opt))
  1201. };
  1202. /**
  1203. * 播放录音
  1204. * @param {Object} opt
  1205. * opt {
  1206. * filePath:录音文件路径
  1207. * }
  1208. */
  1209. var playVoice = function (opt) {
  1210. var obj = checkParam(opt);
  1211. obj.params = {};
  1212. if (!obj.filePath) {
  1213. throw new Error('The arguments "filePath" is required!')
  1214. }
  1215. checkParamsType({ name: 'filePath', value: obj.filePath, type: GLOBAL_STR.STRING });
  1216. obj.params.filePath = obj.filePath;
  1217. return exec(API_NAMES$5.play, obj)
  1218. };
  1219. /**
  1220. * 播放监听
  1221. * @param {Object} opt
  1222. * success: function(res){
  1223. * res.currentPosition //当前播放时间点,单位为毫秒
  1224. * }
  1225. */
  1226. var playListener = function (opt) {
  1227. return exec(API_NAMES$5.playListener, checkParam(opt))
  1228. };
  1229. /**
  1230. * 停止播放
  1231. */
  1232. var stopVoice = function (opt) {
  1233. return exec(API_NAMES$5.stopVoice, checkParam(opt))
  1234. };
  1235. /**
  1236. * 播放视频
  1237. * @param {Object} opt
  1238. * opt {
  1239. * url:'xxx' 视频文件路径 string 必填
  1240. * isFullScreen:false 是否全屏 boolean 默认为false 可选
  1241. * title:''视频名称 string 可选
  1242. * }
  1243. */
  1244. var playVideo = function (opt) {
  1245. var obj = checkParam(opt);
  1246. obj.params = {};
  1247. if (!obj.url) {
  1248. throw new Error('The arguments "url" is required!')
  1249. }
  1250. checkParamsType({ name: 'url', value: obj.url, type: GLOBAL_STR.STRING });
  1251. checkParamsType({ name: 'isFullScreen', value: obj.isFullScreen, type: GLOBAL_STR.BOOLEAN });
  1252. checkParamsType({ name: 'title', value: obj.title, type: GLOBAL_STR.STRING });
  1253. obj.params.url = obj.url;
  1254. obj.params.isFullScreen = obj.isFullScreen || false;
  1255. if (obj.title) {
  1256. obj.params.title = obj.title;
  1257. }
  1258. return exec(API_NAMES$5.playVideo, obj)
  1259. };
  1260. /**
  1261. * 语音合成
  1262. * @params opt
  1263. * opt {
  1264. * //应用领域 'iat'(普通文本听写)、'search'(热词搜索)、'video'(视频搜索)、'poi'、'music'、'asr'(关键词识别) string 选填
  1265. * domain: 'iat',
  1266. * //返回结果的语言 'zh_cn'(中文)、'en_us'(英文) string 选填
  1267. * language: 'zh_cn',
  1268. * //语言区域 'mandarin'(中文)、'cantonese'(粤语)、'henanese'(河南话) string 选填 language为英文时,忽略此参数
  1269. * accent: 'mandarin',
  1270. * //前端点超时时间(用户多长时间不说话) 0-10000 ms number 选填
  1271. * vadBos: 5000,
  1272. * //后断点超时时间(用户停止说话多长时间) 1000-10000 ms number 选填
  1273. * vadEos: 3000,
  1274. * //是否保存录音 true or false, boolean 选填
  1275. * isSave: true,
  1276. * //是否需要标点符号 true or false, boolean 选填
  1277. * isDot: true,
  1278. * //回调结果
  1279. * success: function(res) {
  1280. * res.audioPath: 录音路径,
  1281. * res.result: 转化文字,
  1282. * res.volum: 音量大小
  1283. * }
  1284. * }
  1285. */
  1286. var iflyIat = function (opt) {
  1287. var obj = checkParam(opt);
  1288. checkParamsType({ name: 'domain', value: obj.domain, type: GLOBAL_STR.STRING });
  1289. if (obj.domain && !inArray(obj.domain, IAT_DOMAINS)) {
  1290. throw new Error('The arguments "domain" value invalid!')
  1291. }
  1292. checkParamsType({ name: 'language', value: obj.language, type: GLOBAL_STR.STRING });
  1293. if (obj.language && !inArray(obj.language, IAT_LANGUAGES)) {
  1294. throw new Error('The arguments "language" value invalid!')
  1295. }
  1296. checkParamsType({ name: 'accent', value: obj.accent, type: GLOBAL_STR.STRING });
  1297. if (obj.accent && !inArray(obj.accent, IAT_ACCENTS)) {
  1298. throw new Error('The arguments "accent" value invalid!')
  1299. }
  1300. checkParamsType({ name: 'vadBos', value: obj.vadBos, type: GLOBAL_STR.NUMBER });
  1301. if (obj.vadBos && (obj.vadBos < 1000 || obj.vadBos > 10000)) {
  1302. throw new Error('The arguments "vadBos" value between 1000 and 10000!')
  1303. }
  1304. checkParamsType({ name: 'vadEos', value: obj.vadEos, type: GLOBAL_STR.NUMBER });
  1305. if (obj.vadEos && (obj.vadEos < 0 || obj.vadEos > 10000)) {
  1306. throw new Error('The arguments "vadEos" value between 0 and 10000!')
  1307. }
  1308. checkParamsType({ name: 'isSave', value: obj.isSave, type: GLOBAL_STR.BOOLEAN });
  1309. checkParamsType({ name: 'hasDot', value: obj.hasDot, type: GLOBAL_STR.BOOLEAN });
  1310. obj.params = {
  1311. domain: obj.domain ? obj.domain : undefined,
  1312. language: obj.language ? obj.language : undefined,
  1313. accent: obj.accent ? obj.accent : undefined,
  1314. vadBos: obj.vadBos && String(obj.vadBos),
  1315. vadEos: obj.vadEos && String(obj.vadEos),
  1316. isSave: obj.isSave,
  1317. hasDot: obj.hasDot
  1318. };
  1319. return exec(API_NAMES$5.startIat, obj)
  1320. };
  1321. // core api
  1322. var Cross = Object.freeze({
  1323. nativeFetchQueue: nativeFetchQueue,
  1324. callbackDestroy: callbackDestroy,
  1325. openLocation: openLocation,
  1326. closeLocation: closeLocation,
  1327. getLocation: getLocation,
  1328. sharePlatform: sharePlatform,
  1329. shareType: shareType,
  1330. shareContent: shareContent,
  1331. setPlatformConfig: setPlatformConfig,
  1332. loginPlatform: loginPlatform,
  1333. thirdpartyLogin: thirdpartyLogin,
  1334. upload: upload,
  1335. startDownload: startDownload,
  1336. downloadListener: downloadListener,
  1337. cancelDownload: cancelDownload,
  1338. download: download,
  1339. openFile: openFile,
  1340. chooseFile: chooseFile,
  1341. unzip: unzip,
  1342. storage: storage,
  1343. config: config,
  1344. ajax: ajax,
  1345. customPlugin: customPlugin,
  1346. copy: copy,
  1347. loadUrl: loadUrl,
  1348. pageClose: pageClose,
  1349. closePage: closePage,
  1350. goBack: goBack,
  1351. exit: exit,
  1352. checkJsApi: checkJsApi,
  1353. getNetworkType: getNetworkType,
  1354. getAppInfo: getAppInfo,
  1355. getDeviceInfo: getDeviceInfo,
  1356. bindButton: bindButton,
  1357. unbindButton: unbindButton,
  1358. getContact: getContact,
  1359. takePhoto: takePhoto,
  1360. chooseImage: chooseImage,
  1361. previewImage: previewImage,
  1362. livenessDetect: livenessDetect,
  1363. scanQRCode: scanQRCode,
  1364. createQRCode: createQRCode,
  1365. startRecord: startRecord,
  1366. recordListener: recordListener,
  1367. stopRecord: stopRecord,
  1368. playVoice: playVoice,
  1369. playListener: playListener,
  1370. stopVoice: stopVoice,
  1371. playVideo: playVideo,
  1372. iflyIat: iflyIat
  1373. });
  1374. // import { isWXAgent } from './cross/utils'
  1375. // import * as WX from './wx/index'
  1376. var FrameWork = Cross;
  1377. return FrameWork;
  1378. })));