ican-H5Api.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. //#ifdef H5
  2. /** clipboard.js v2.0.4**/
  3. ! function(t, e) {
  4. try {
  5. window.ClipboardJS = e();
  6. } catch (e) {};
  7. "object" == typeof exports && "object" == typeof module ? module.exports = e() : "function" == typeof define &&
  8. define.amd ? define([], e) : "object" == typeof exports ? exports.ClipboardJS = e() : t.ClipboardJS = e()
  9. }(this, function() {
  10. return function(n) {
  11. var o = {};
  12. function r(t) {
  13. if (o[t]) return o[t].exports;
  14. var e = o[t] = {
  15. i: t,
  16. l: !1,
  17. exports: {}
  18. };
  19. return n[t].call(e.exports, e, e.exports, r), e.l = !0, e.exports
  20. }
  21. return r.m = n, r.c = o, r.d = function(t, e, n) {
  22. r.o(t, e) || Object.defineProperty(t, e, {
  23. enumerable: !0,
  24. get: n
  25. })
  26. }, r.r = function(t) {
  27. "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol
  28. .toStringTag, {
  29. value: "Module"
  30. }), Object.defineProperty(t, "__esModule", {
  31. value: !0
  32. })
  33. }, r.t = function(e, t) {
  34. if (1 & t && (e = r(e)), 8 & t) return e;
  35. if (4 & t && "object" == typeof e && e && e.__esModule) return e;
  36. var n = Object.create(null);
  37. if (r.r(n), Object.defineProperty(n, "default", {
  38. enumerable: !0,
  39. value: e
  40. }), 2 & t && "string" != typeof e)
  41. for (var o in e) r.d(n, o, function(t) {
  42. return e[t]
  43. }.bind(null, o));
  44. return n
  45. }, r.n = function(t) {
  46. var e = t && t.__esModule ? function() {
  47. return t.default
  48. } : function() {
  49. return t
  50. };
  51. return r.d(e, "a", e), e
  52. }, r.o = function(t, e) {
  53. return Object.prototype.hasOwnProperty.call(t, e)
  54. }, r.p = "", r(r.s = 0)
  55. }([function(t, e, n) {
  56. "use strict";
  57. var r = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
  58. return typeof t
  59. } : function(t) {
  60. return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol
  61. .prototype ? "symbol" : typeof t
  62. },
  63. i = function() {
  64. function o(t, e) {
  65. for (var n = 0; n < e.length; n++) {
  66. var o = e[n];
  67. o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o
  68. .writable = !0), Object.defineProperty(t, o.key, o)
  69. }
  70. }
  71. return function(t, e, n) {
  72. return e && o(t.prototype, e), n && o(t, n), t
  73. }
  74. }(),
  75. a = o(n(1)),
  76. c = o(n(3)),
  77. u = o(n(4));
  78. function o(t) {
  79. return t && t.__esModule ? t : {
  80. default: t
  81. }
  82. }
  83. var l = function(t) {
  84. function o(t, e) {
  85. ! function(t, e) {
  86. if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function")
  87. }(this, o);
  88. var n = function(t, e) {
  89. if (!t) throw new ReferenceError(
  90. "this hasn't been initialised - super() hasn't been called");
  91. return !e || "object" != typeof e && "function" != typeof e ? t : e
  92. }(this, (o.__proto__ || Object.getPrototypeOf(o)).call(this));
  93. return n.resolveOptions(e), n.listenClick(t), n
  94. }
  95. return function(t, e) {
  96. if ("function" != typeof e && null !== e) throw new TypeError(
  97. "Super expression must either be null or a function, not " +
  98. typeof e);
  99. t.prototype = Object.create(e && e.prototype, {
  100. constructor: {
  101. value: t,
  102. enumerable: !1,
  103. writable: !0,
  104. configurable: !0
  105. }
  106. }), e && (Object.setPrototypeOf ? Object.setPrototypeOf(t, e) : t
  107. .__proto__ = e)
  108. }(o, c.default), i(o, [{
  109. key: "resolveOptions",
  110. value: function() {
  111. var t = 0 < arguments.length && void 0 !== arguments[0] ?
  112. arguments[0] : {};
  113. this.action = "function" == typeof t.action ? t.action : this
  114. .defaultAction, this.target = "function" == typeof t
  115. .target ? t.target : this.defaultTarget, this.text =
  116. "function" == typeof t.text ? t.text : this.defaultText,
  117. this.container = "object" === r(t.container) ? t.container :
  118. document.body
  119. }
  120. }, {
  121. key: "listenClick",
  122. value: function(t) {
  123. var e = this;
  124. this.listener = (0, u.default)(t, "click", function(t) {
  125. return e.onClick(t)
  126. })
  127. }
  128. }, {
  129. key: "onClick",
  130. value: function(t) {
  131. var e = t.delegateTarget || t.currentTarget;
  132. this.clipboardAction && (this.clipboardAction = null), this
  133. .clipboardAction = new a.default({
  134. action: this.action(e),
  135. target: this.target(e),
  136. text: this.text(e),
  137. container: this.container,
  138. trigger: e,
  139. emitter: this
  140. })
  141. }
  142. }, {
  143. key: "defaultAction",
  144. value: function(t) {
  145. return s("action", t) || 'copy'
  146. }
  147. }, {
  148. key: "defaultTarget",
  149. value: function(t) {
  150. var e = s("target", t);
  151. if (e) {
  152. return document.querySelector(e)
  153. }
  154. }
  155. }, {
  156. key: "defaultText",
  157. value: function(t) {
  158. return s("text", t) || this.text
  159. }
  160. }, {
  161. key: "destroy",
  162. value: function() {
  163. this.listener.destroy(), this.clipboardAction && (this
  164. .clipboardAction.destroy(), this.clipboardAction = null)
  165. }
  166. }], [{
  167. key: "isSupported",
  168. value: function() {
  169. var t = 0 < arguments.length && void 0 !== arguments[0] ?
  170. arguments[0] : ["copy", "cut"],
  171. e = "string" == typeof t ? [t] : t,
  172. n = !!document.queryCommandSupported;
  173. return e.forEach(function(t) {
  174. n = n && !!document.queryCommandSupported(t)
  175. }), n
  176. }
  177. }]), o
  178. }();
  179. function s(t, e) {
  180. var n = "data-clipboard-" + t;
  181. let isFun = e && typeof e.hasAttribute === 'function';
  182. if (isFun && e.hasAttribute(n)) {
  183. return e.getAttribute(n)
  184. }
  185. }
  186. t.exports = l
  187. }, function(t, e, n) {
  188. "use strict";
  189. var o, r = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
  190. return typeof t
  191. } : function(t) {
  192. return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol
  193. .prototype ? "symbol" : typeof t
  194. },
  195. i = function() {
  196. function o(t, e) {
  197. for (var n = 0; n < e.length; n++) {
  198. var o = e[n];
  199. o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o
  200. .writable = !0), Object.defineProperty(t, o.key, o)
  201. }
  202. }
  203. return function(t, e, n) {
  204. return e && o(t.prototype, e), n && o(t, n), t
  205. }
  206. }(),
  207. a = n(2),
  208. c = (o = a) && o.__esModule ? o : {
  209. default: o
  210. };
  211. var u = function() {
  212. function e(t) {
  213. ! function(t, e) {
  214. if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function")
  215. }(this, e), this.resolveOptions(t), this.initSelection()
  216. }
  217. return i(e, [{
  218. key: "resolveOptions",
  219. value: function() {
  220. var t = 0 < arguments.length && void 0 !== arguments[0] ?
  221. arguments[0] : {};
  222. this.action = t.action, this.container = t.container, this
  223. .emitter = t.emitter, this.target = t.target, this.text = t
  224. .text, this.trigger = t.trigger, this.selectedText = ""
  225. }
  226. }, {
  227. key: "initSelection",
  228. value: function() {
  229. this.text ? this.selectFake() : this.target && this
  230. .selectTarget()
  231. }
  232. }, {
  233. key: "selectFake",
  234. value: function() {
  235. var t = this,
  236. e = "rtl" == document.documentElement.getAttribute("dir");
  237. this.removeFake(), this.fakeHandlerCallback = function() {
  238. return t.removeFake()
  239. }, this.fakeHandler = this.container.addEventListener(
  240. "click", this.fakeHandlerCallback) || !0, this
  241. .fakeElem = document.createElement("textarea"), this
  242. .fakeElem.style.fontSize = "12pt", this.fakeElem.style
  243. .border = "0", this.fakeElem.style.padding = "0", this
  244. .fakeElem.style.margin = "0", this.fakeElem.style.position =
  245. "absolute", this.fakeElem.style[e ? "right" : "left"] =
  246. "-9999px";
  247. var n = window.pageYOffset || document.documentElement
  248. .scrollTop;
  249. this.fakeElem.style.top = n + "px", this.fakeElem.setAttribute(
  250. "readonly", ""), this.fakeElem.value = this.text, this
  251. .container.appendChild(this.fakeElem), this.selectedText = (
  252. 0, c.default)(this.fakeElem), this.copyText()
  253. }
  254. }, {
  255. key: "removeFake",
  256. value: function() {
  257. this.fakeHandler && (this.container.removeEventListener("click",
  258. this.fakeHandlerCallback), this.fakeHandler = null,
  259. this.fakeHandlerCallback = null), this.fakeElem && (this
  260. .container.removeChild(this.fakeElem), this.fakeElem =
  261. null)
  262. }
  263. }, {
  264. key: "selectTarget",
  265. value: function() {
  266. this.selectedText = (0, c.default)(this.target), this.copyText()
  267. }
  268. }, {
  269. key: "copyText",
  270. value: function() {
  271. var e = void 0;
  272. try {
  273. e = document.execCommand(this.action)
  274. } catch (t) {
  275. e = !1
  276. }
  277. this.handleResult(e)
  278. }
  279. }, {
  280. key: "handleResult",
  281. value: function(t) {
  282. this.emitter.emit(t ? "success" : "error", {
  283. action: this.action,
  284. text: this.selectedText,
  285. trigger: this.trigger,
  286. clearSelection: this.clearSelection.bind(this)
  287. })
  288. }
  289. }, {
  290. key: "clearSelection",
  291. value: function() {
  292. this.trigger && this.trigger.focus(), window.getSelection()
  293. .removeAllRanges()
  294. }
  295. }, {
  296. key: "destroy",
  297. value: function() {
  298. this.removeFake()
  299. }
  300. }, {
  301. key: "action",
  302. set: function() {
  303. var t = 0 < arguments.length && void 0 !== arguments[0] ?
  304. arguments[0] : "copy";
  305. if (this._action = t, "copy" !== this._action && "cut" !== this
  306. ._action) throw new Error(
  307. 'Invalid "action" value, use either "copy" or "cut"'
  308. )
  309. },
  310. get: function() {
  311. return this._action
  312. }
  313. }, {
  314. key: "target",
  315. set: function(t) {
  316. if (void 0 !== t) {
  317. if (!t || "object" !== (void 0 === t ? "undefined" : r(
  318. t)) || 1 !== t.nodeType) throw new Error(
  319. 'Invalid "target" value, use a valid Element');
  320. if ("copy" === this.action && t.hasAttribute("disabled"))
  321. throw new Error(
  322. 'Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'
  323. );
  324. if ("cut" === this.action && (t.hasAttribute("readonly") ||
  325. t.hasAttribute("disabled"))) throw new Error(
  326. 'Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'
  327. );
  328. this._target = t
  329. }
  330. },
  331. get: function() {
  332. return this._target
  333. }
  334. }]), e
  335. }();
  336. t.exports = u
  337. }, function(t, e) {
  338. t.exports = function(t) {
  339. var e;
  340. if ("SELECT" === t.nodeName) t.focus(), e = t.value;
  341. else if ("INPUT" === t.nodeName || "TEXTAREA" === t.nodeName) {
  342. var n = t.hasAttribute("readonly");
  343. n || t.setAttribute("readonly", ""), t.select(), t.setSelectionRange(0, t.value
  344. .length), n || t.removeAttribute("readonly"), e = t.value
  345. } else {
  346. t.hasAttribute("contenteditable") && t.focus();
  347. var o = window.getSelection(),
  348. r = document.createRange();
  349. r.selectNodeContents(t), o.removeAllRanges(), o.addRange(r), e = o.toString()
  350. }
  351. return e
  352. }
  353. }, function(t, e) {
  354. function n() {}
  355. n.prototype = {
  356. on: function(t, e, n) {
  357. var o = this.e || (this.e = {});
  358. return (o[t] || (o[t] = [])).push({
  359. fn: e,
  360. ctx: n
  361. }), this
  362. },
  363. once: function(t, e, n) {
  364. var o = this;
  365. function r() {
  366. o.off(t, r), e.apply(n, arguments)
  367. }
  368. return r._ = e, this.on(t, r, n)
  369. },
  370. emit: function(t) {
  371. for (var e = [].slice.call(arguments, 1), n = ((this.e || (this.e = {}))[t] ||
  372. []).slice(), o = 0, r = n.length; o < r; o++) n[o].fn.apply(n[o].ctx, e);
  373. return this
  374. },
  375. off: function(t, e) {
  376. var n = this.e || (this.e = {}),
  377. o = n[t],
  378. r = [];
  379. if (o && e)
  380. for (var i = 0, a = o.length; i < a; i++) o[i].fn !== e && o[i].fn._ !==
  381. e && r.push(o[i]);
  382. return r.length ? n[t] = r : delete n[t], this
  383. }
  384. }, t.exports = n
  385. }, function(t, e, n) {
  386. var d = n(5),
  387. h = n(6);
  388. t.exports = function(t, e, n) {
  389. if (!t && !e && !n) throw new Error("Missing required arguments");
  390. if (!d.string(e)) throw new TypeError("Second argument must be a String");
  391. if (!d.fn(n)) throw new TypeError("Third argument must be a Function");
  392. if (d.node(t)) return s = e, f = n, (l = t).addEventListener(s, f), {
  393. destroy: function() {
  394. l.removeEventListener(s, f)
  395. }
  396. };
  397. if (d.nodeList(t)) return a = t, c = e, u = n, Array.prototype.forEach.call(a, function(
  398. t) {
  399. t.addEventListener(c, u)
  400. }), {
  401. destroy: function() {
  402. Array.prototype.forEach.call(a, function(t) {
  403. t.removeEventListener(c, u)
  404. })
  405. }
  406. };
  407. if (d.string(t)) return o = t, r = e, i = n, h(document.body, o, r, i);
  408. throw new TypeError(
  409. "First argument must be a String, HTMLElement, HTMLCollection, or NodeList");
  410. var o, r, i, a, c, u, l, s, f
  411. }
  412. }, function(t, n) {
  413. n.node = function(t) {
  414. return void 0 !== t && t instanceof HTMLElement && 1 === t.nodeType
  415. }, n.nodeList = function(t) {
  416. var e = Object.prototype.toString.call(t);
  417. return void 0 !== t && ("[object NodeList]" === e || "[object HTMLCollection]" === e) &&
  418. "length" in t && (0 === t.length || n.node(t[0]))
  419. }, n.string = function(t) {
  420. return "string" == typeof t || t instanceof String
  421. }, n.fn = function(t) {
  422. return "[object Function]" === Object.prototype.toString.call(t)
  423. }
  424. }, function(t, e, n) {
  425. var a = n(7);
  426. function i(t, e, n, o, r) {
  427. var i = function(e, n, t, o) {
  428. return function(t) {
  429. t.delegateTarget = a(t.target, n), t.delegateTarget && o.call(e, t)
  430. }
  431. }.apply(this, arguments);
  432. return t.addEventListener(n, i, r), {
  433. destroy: function() {
  434. t.removeEventListener(n, i, r)
  435. }
  436. }
  437. }
  438. t.exports = function(t, e, n, o, r) {
  439. return "function" == typeof t.addEventListener ? i.apply(null, arguments) :
  440. "function" == typeof n ? i.bind(null, document).apply(null, arguments) : (
  441. "string" == typeof t && (t = document.querySelectorAll(t)), Array.prototype.map
  442. .call(t, function(t) {
  443. return i(t, e, n, o, r)
  444. }))
  445. }
  446. }, function(t, e) {
  447. if ("undefined" != typeof Element && !Element.prototype.matches) {
  448. var n = Element.prototype;
  449. n.matches = n.matchesSelector || n.mozMatchesSelector || n.msMatchesSelector || n
  450. .oMatchesSelector || n.webkitMatchesSelector
  451. }
  452. t.exports = function(t, e) {
  453. for (; t && 9 !== t.nodeType;) {
  454. if ("function" == typeof t.matches && t.matches(e)) return t;
  455. t = t.parentNode
  456. }
  457. }
  458. }])
  459. });
  460. let Types = {
  461. isFunction: function(obj) {
  462. var type = Object.prototype.toString.call(obj)
  463. return type == '[object Function]'
  464. },
  465. isObject: function(obj) {
  466. var type = Object.prototype.toString.call(obj)
  467. return type == '[object Object]'
  468. },
  469. isString: function(obj) {
  470. var type = Object.prototype.toString.call(obj)
  471. return type == '[object String]'
  472. }
  473. }
  474. uni.setClipboardData = function(options) {
  475. let emptyFun = function() {}
  476. let config = {
  477. data: null,
  478. event: null,
  479. success: emptyFun,
  480. fail: emptyFun,
  481. complete: emptyFun
  482. }
  483. if (options && Types.isObject(options)) {
  484. config = Object.assign({}, config, options)
  485. }
  486. if (options && Types.isString(options)) {
  487. config = Object.assign({}, config, {
  488. data: options
  489. })
  490. }
  491. let data = config.data
  492. let success = config.success || emptyFun
  493. let fail = config.fail || emptyFun
  494. let complete = config.complete || emptyFun
  495. let e = config.event || window.event || {}
  496. let cb = new ClipboardJS('.null', {
  497. text: () => data
  498. })
  499. cb.on('success', function(res) {
  500. window.__clipboard__ = data;
  501. success && Types.isFunction(success) && success({
  502. data: res.text
  503. })
  504. complete && Types.isFunction(complete) && complete()
  505. cb.off('error')
  506. cb.off('success')
  507. cb.destroy()
  508. })
  509. cb.on('error', function(err) {
  510. fail && Types.isFunction(fail) && fail(err)
  511. complete && Types.isFunction(complete) && complete()
  512. cb.off('error')
  513. cb.off('success')
  514. cb.destroy()
  515. })
  516. cb.onClick(e)
  517. };
  518. uni.getClipboardData = function(options) {
  519. let emptyFun = function() {}
  520. let config = {
  521. data: null,
  522. event: null,
  523. success: emptyFun,
  524. fail: emptyFun,
  525. complete: emptyFun
  526. }
  527. if (options && Types.isObject(options)) {
  528. config = Object.assign({}, config, options)
  529. }
  530. let success = config.success || emptyFun
  531. let fail = config.fail || emptyFun
  532. let complete = config.complete || emptyFun
  533. if (window.__clipboard__ !== undefined) {
  534. success && Types.isFunction(success) && success({
  535. data: window.__clipboard__
  536. })
  537. } else {
  538. fail && Types.isFunction(fail) && fail({
  539. data: null
  540. })
  541. }
  542. complete && Types.isFunction(complete) && complete()
  543. };
  544. function fileDownLoad(data) {
  545. var linkElement = document.createElement('a')
  546. linkElement.setAttribute('href', data.blob)
  547. linkElement.setAttribute('downLoad', data.name)
  548. linkElement.click()
  549. }
  550. uni.saveImageToPhotosAlbum = uni.saveVideoToPhotosAlbum = function(options) {
  551. let emptyFun = function() {}
  552. let config = {
  553. filePath: null,
  554. success: emptyFun,
  555. fail: emptyFun,
  556. complete: emptyFun
  557. }
  558. if (options && Types.isObject(options)) {
  559. config = Object.assign({}, config, options)
  560. }
  561. if (options && Types.isString(options)) {
  562. config = Object.assign({}, config, {
  563. filePath: options
  564. })
  565. }
  566. let filePath = config.filePath
  567. let success = config.success || emptyFun
  568. let fail = config.fail || emptyFun
  569. let complete = config.complete || emptyFun
  570. if (!filePath) {
  571. fail && Types.isFunction(fail) && fail({
  572. msg: 'no File'
  573. })
  574. complete && Types.isFunction(complete) && complete()
  575. return
  576. }
  577. let names = filePath.split('/')
  578. let name = names[names.length - 1]
  579. uni.downloadFile({
  580. url: filePath,
  581. success: function(res) {
  582. let tempFilePath = res.tempFilePath
  583. fileDownLoad({
  584. name: name,
  585. blob: tempFilePath
  586. })
  587. success && Types.isFunction(success) && success({
  588. filePath: filePath
  589. })
  590. },
  591. fail: function(err) {
  592. fail && Types.isFunction(fail) && fail({
  593. msg: err
  594. })
  595. },
  596. complete: function() {
  597. complete && Types.isFunction(complete) && complete()
  598. }
  599. })
  600. }
  601. //#endif