ican-H5Api.js 21 KB

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