public.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. import Vue from "vue";
  2. // import {checkGoogleCode, baseUrl} from "../api/public.js";
  3. import transCodeImg from "./codeImg";
  4. // import ElementUI from "element-ui";
  5. import md5 from "js-md5";
  6. // import i18n from "@/locale/index.js"; //引入语言包
  7. // import CryptoJS from "crypto-js";
  8. import {store} from "../store";
  9. const keyStr = "bi_ecology_qwert"; //加密的秘钥
  10. // Vue.use(ElementUI);
  11. // Vue.use(ElementUI, {
  12. // i18n: (key, value) => i18n.t(key, value) //重点!!在注册Element时设置i18n的处理方法(这里有个小坑)
  13. // });
  14. // let vue = new Vue({
  15. // i18n: i18n
  16. // });
  17. let Public = new Object();
  18. Public.imgUpload = "/api/authentication/shangchuan"; //图片上传地址
  19. Public.img_host = "https://jyh.hashtron.top/";
  20. Public.kf = 'https://1539049.s2.udesk.cn/im_client/?web_plugin_id=28350';
  21. Public.captchaId = "7057166a15d74781a0d8620b925436c9"; // 网易滑块
  22. // 加法
  23. Public.UserInfo = {};
  24. Public.getLocalTime = function (nS) {
  25. var h, m, s;
  26. var date = new Date(nS * 1000);
  27. h = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
  28. m =
  29. (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
  30. ":";
  31. s = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  32. return h + m + s;
  33. };
  34. Public.Addition = function (a, b) {
  35. var c, d, e;
  36. try {
  37. c = a.toString().split(".")[1].length;
  38. } catch (f) {
  39. c = 0;
  40. }
  41. try {
  42. d = b.toString().split(".")[1].length;
  43. } catch (f) {
  44. d = 0;
  45. }
  46. return (e = Math.pow(10, Math.max(c, d))), (mul(a, e) + mul(b, e)) / e;
  47. };
  48. // 减法
  49. Public.Subtraction = function (a, b) {
  50. var c, d, e;
  51. try {
  52. c = a.toString().split(".")[1].length;
  53. } catch (f) {
  54. c = 0;
  55. }
  56. try {
  57. d = b.toString().split(".")[1].length;
  58. } catch (f) {
  59. d = 0;
  60. }
  61. return (e = Math.pow(10, Math.max(c, d))), (mul(a, e) - mul(b, e)) / e;
  62. };
  63. // 参数val为内容,num为需要保留的位数 bl为true则去除无效零
  64. Public.toIntercept = function (_val, num, bl, debug) {
  65. var val = String(_val)
  66. if (val == undefined) return 0; //
  67. // var _num = Number(val).toFixed(num + 1); // 补零
  68. var de = val.indexOf('.')
  69. var arr = val.split('.')
  70. if (de > -1) { // 小数
  71. var rs = arr[1]
  72. if (rs.length >= num) { // 小数位多余需保留位数
  73. rs = rs.substring(0, num)
  74. arr[1] = rs
  75. } else {
  76. // 补零
  77. for (var i = 0; i < num; i++) {
  78. rs[i] === undefined ? rs = rs + '0' : ''
  79. }
  80. arr[1] = rs
  81. }
  82. return bl ? parseFloat(Number(arr.join('.'))) : arr.join('.')
  83. } else {// 整数
  84. return bl ? val : Number(val).toFixed(num)
  85. }
  86. };
  87. // 数组去重 根据数组中的对象
  88. Public.repeat = function (arr, key) {
  89. console.log(arr)
  90. const res = new Map();
  91. return arr.filter((a) => !res.has(a[key]) && res.set(a[key], 1))
  92. },
  93. // 乘法
  94. Public.Multiplication = function (arg1, arg2) {
  95. var arg1 = isNaN(Number(arg1)) ? 0 : Number(arg1);
  96. var arg2 = isNaN(Number(arg2)) ? 0 : Number(arg2);
  97. var r1, r2, m, n, q;
  98. if (parseInt(arg1) == arg1) {
  99. r1 = 0;
  100. } else {
  101. r1 = arg1.toString().split(".")[1].length;
  102. }
  103. if (parseInt(arg2) == arg2) {
  104. r2 = 0;
  105. } else {
  106. r2 = arg2.toString().split(".")[1].length;
  107. }
  108. m = Math.pow(10, r1);
  109. n = Math.pow(10, r2);
  110. q = m * n;
  111. var sum = (arg1 * m * (arg2 * n)) / q;
  112. return sum;
  113. };
  114. Public.toPercent = function (val) {
  115. return Number(val) * 100 + "%";
  116. };
  117. // 除法
  118. Public.Division = function (a, b) {
  119. var a = a == "" || isNaN(Number(a)) ? 0 : Number(a);
  120. var b = b == "" || isNaN(Number(b)) ? 0 : Number(b);
  121. var c,
  122. d,
  123. e = 0,
  124. f = 0;
  125. try {
  126. e = a.toString().split(".")[1].length;
  127. } catch (g) {
  128. }
  129. try {
  130. f = b.toString().split(".")[1].length;
  131. } catch (g) {
  132. }
  133. return (
  134. (c = Number(a.toString().replace(".", ""))),
  135. (d = Number(b.toString().replace(".", ""))),
  136. mul(c / d, Math.pow(10, f - e))
  137. );
  138. };
  139. Public.toLowFixed1 = function (num, n) {
  140. var c, e;
  141. try {
  142. c = num.toString().split(".")[1].length;
  143. } catch (f) {
  144. c = 0;
  145. }
  146. e = Math.pow(10, Math.max(0, n));
  147. let str = mul(num, e) / e;
  148. str = str + "";
  149. if (str.indexOf(".") == -1) {
  150. str = str + ".0000000000";
  151. } else {
  152. str = str + "00000000";
  153. }
  154. return str.substring(0, str.indexOf(".") + n + 1);
  155. };
  156. Public.formatSeconds = function (value) {
  157. var theTime = parseInt(value);// 需要转换的时间秒
  158. var theTime1 = 0;// 分
  159. var theTime2 = 0;// 小时
  160. var theTime3 = 0;// 天
  161. if (theTime > 60) {
  162. theTime1 = parseInt(theTime / 60);
  163. theTime = parseInt(theTime % 60);
  164. if (theTime1 > 60) {
  165. theTime2 = parseInt(theTime1 / 60);
  166. theTime1 = parseInt(theTime1 % 60);
  167. if (theTime2 > 24) {
  168. //大于24小时
  169. theTime3 = parseInt(theTime2 / 24);
  170. theTime2 = parseInt(theTime2 % 24);
  171. }
  172. }
  173. }
  174. var result = '';
  175. if (theTime > 0) {
  176. result = "" + parseInt(theTime) + "秒";
  177. }
  178. if (theTime1 > 0) {
  179. result = "" + parseInt(theTime1) + "分" + result;
  180. }
  181. if (theTime2 > 0) {
  182. result = "" + parseInt(theTime2) + "小时" + result;
  183. }
  184. if (theTime3 > 0) {
  185. result = "" + parseInt(theTime3) + "天" + result;
  186. }
  187. return result;
  188. }
  189. // 保留小数位 btc btc_usdt btc/usdt 字母不区分大小写
  190. Public.cutDot = function (num, type) {
  191. if (type.indexOf("_") != -1) {
  192. type = type.split("_")[0];
  193. }
  194. if (type.indexOf("/") != -1) {
  195. type = type.split("/")[0];
  196. }
  197. type = type.toUpperCase();
  198. if (type == "BTC") {
  199. return this.toLowFixed1(parseFloat(num), 6);
  200. } else if (type == "XRP") {
  201. return this.toLowFixed1(parseFloat(num), 4);
  202. } else if (type == "ETH") {
  203. return this.toLowFixed1(parseFloat(num), 6);
  204. } else if (type == "LTC") {
  205. return this.toLowFixed1(parseFloat(num), 2);
  206. } else if (type == "EOS") {
  207. return this.toLowFixed1(parseFloat(num), 4);
  208. } else if (type == "BCH") {
  209. return this.toLowFixed1(parseFloat(num), 2);
  210. } else if (type == "ETC") {
  211. return this.toLowFixed1(parseFloat(num), 4);
  212. } else if (type == "TRX") {
  213. return this.toLowFixed1(parseFloat(num), 6);
  214. } else if (type == "ZEC") {
  215. return this.toLowFixed1(parseFloat(num), 2);
  216. } else if (type == "DASH") {
  217. return this.toLowFixed1(parseFloat(num), 2);
  218. } else if (type == "USDT") {
  219. return this.toLowFixed1(parseFloat(num), 4);
  220. } else if (type == "CNY") {
  221. return this.toLowFixed1(parseFloat(num), 2);
  222. } else if (type == "NUM") {
  223. return this.toLowFixed1(parseFloat(num), 6);
  224. } else if (type == "UDR") {
  225. // 涨跌幅
  226. return this.toLowFixed1(parseFloat(num), 2);
  227. } else {
  228. return this.toLowFixed1(parseFloat(num), 8);
  229. }
  230. };
  231. // 百分数转小数
  232. Public.toPoint = function (percent) {
  233. if (percent == 0) {
  234. return 0;
  235. }
  236. var str = percent.replace("%", "");
  237. str = str / 100;
  238. return str;
  239. };
  240. // 验证正整数
  241. Public.integer = function (value) {
  242. var reg = /^\+?[1-9][0-9]*$/;
  243. if (!reg.test(value)) {
  244. return false;
  245. } else {
  246. return true;
  247. }
  248. };
  249. // 验证小数最多8位
  250. Public.integerDecimal = function (value) {
  251. var reg = /^\d{1}$|^\d{1}(\.?\d{1,8})$/;
  252. if (!reg.test(value)) {
  253. return false;
  254. } else {
  255. return true;
  256. }
  257. };
  258. // 时间戳转化
  259. Public.timestampToTime = function (timestamp, mat) {
  260. var date = new Date(timestamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  261. var Y, M, D, h, m, s;
  262. var format = '-'
  263. if (mat) format = mat
  264. Y = date.getFullYear() + format;
  265. M =
  266. (date.getMonth() < 9 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) +
  267. format;
  268. D = (date.getDate() < 9 ? "0" + date.getDate() : date.getDate()) + " ";
  269. h = (date.getHours() < 9 ? "0" + date.getHours() : date.getHours()) + ":";
  270. m =
  271. (date.getMinutes() < 9 ? "0" + date.getMinutes() : date.getMinutes()) + ":";
  272. s = date.getSeconds() < 9 ? "0" + date.getSeconds() : date.getSeconds();
  273. return Y + M + D + h + m + s;
  274. };
  275. // 时间戳转化
  276. Public.timestampToTimeshian = function (timestamp) {
  277. var date = new Date(timestamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  278. var Y, M, D, h, m, s;
  279. Y = date.getFullYear() + "-";
  280. M =
  281. (date.getMonth() < 9 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) +
  282. "-";
  283. D = (date.getDate() < 9 ? "0" + date.getDate() : date.getDate()) + " ";
  284. h = (date.getHours() < 9 ? "0" + date.getHours() : date.getHours()) + ":";
  285. m =
  286. (date.getMinutes() < 9 ? "0" + date.getMinutes() : date.getMinutes()) + ":";
  287. s = date.getSeconds() < 9 ? "0" + date.getSeconds() : date.getSeconds();
  288. return Y + M + D;
  289. };
  290. Public.timestampToTimeshian1 = function (timestamp) {
  291. var date = new Date(timestamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  292. var Y, M, D, h, m, s;
  293. Y = date.getFullYear() + "-";
  294. M =
  295. (date.getMonth() < 9 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) +
  296. "-";
  297. D = (date.getDate() < 9 ? "0" + date.getDate() : date.getDate()) + " ";
  298. h = (date.getHours() < 9 ? "0" + date.getHours() : date.getHours()) + ":";
  299. m =
  300. (date.getMinutes() < 9 ? "0" + date.getMinutes() : date.getMinutes()) + ":";
  301. s = date.getSeconds() < 9 ? "0" + date.getSeconds() : date.getSeconds();
  302. return h + m + s;
  303. };
  304. // 函数节流
  305. // throttle(fn, 1000) 函数foo每次执行间隔最小为1000ms
  306. // 第一个参数也可以为数组:throttle([fn, arg1, arg2...], 1000)
  307. // 同一页面多个节流时需要传mark(String类型) 区分全局变量防止冲突
  308. Public.throttle = function (obj, t, mark) {
  309. var windowVar = (function () {
  310. if (mark == undefined) return "$$THROTTLE_CTRL";
  311. if (mark.constructor === String || mark.constructor === Number)
  312. return "$$THROTTLE_CTRL" + "_" + mark;
  313. else return "$$THROTTLE_CTRL";
  314. })();
  315. if (!window[windowVar]) {
  316. window[windowVar] = true;
  317. if (obj.constructor === Function) obj();
  318. if (obj.constructor !== Function && obj.constructor !== Array)
  319. throw new TypeError(
  320. "throttle(option , time) 'option' Musb be a Function or Array"
  321. );
  322. if (obj.constructor === Array) {
  323. var fn = obj[0];
  324. if (fn.constructor !== Function)
  325. throw new TypeError("throttle(arr , time) 'arr[0]' Musb be a Function");
  326. obj.splice(0, 1);
  327. fn.apply(null, obj);
  328. }
  329. window.setTimeout(function () {
  330. window[windowVar] = null;
  331. }, t);
  332. }
  333. };
  334. //密码格式
  335. Public.pwd = function (val) {
  336. var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$/;
  337. return reg.test(val);
  338. };
  339. //邮箱验证
  340. Public.email = function (em) {
  341. // var ema = /^[A-Za-z0-9\u4e00-\u9fa5_]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
  342. // if (!ema.test(em)) {
  343. // return false;
  344. // } else {
  345. // return true;
  346. // }
  347. var exist = em.indexOf('@') > -1;
  348. if (exist) {
  349. return true;
  350. } else {
  351. return false;
  352. }
  353. };
  354. // 手机正则
  355. Public.checkMobile = function (sMobile) {
  356. var phone = sMobile.trim();
  357. // var reg = /^1\d{10}$/;
  358. // return reg.test(phone);
  359. if (isNaN(Number(phone))) {
  360. return false
  361. }
  362. return true
  363. };
  364. //身份证号验证
  365. Public.isCardID = function (sId) {
  366. if (!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(sId)) {
  367. return false;
  368. } else {
  369. return true;
  370. }
  371. };
  372. //银行卡号验证
  373. Public.bank_car = function (val) {
  374. if (!isNaN(val) && val.length > 10 && val.length < 20) {
  375. return true;
  376. } else {
  377. return false;
  378. }
  379. };
  380. Public.Eliminate = function (str) {
  381. var rs = "";
  382. for (var i = 0; i < str.length; i++) {
  383. rs = rs + str.substr(i, 1).replace(/^\s+/, "");
  384. }
  385. return rs;
  386. };
  387. //验证码格式验证
  388. Public.code = function (val) {
  389. var reg = /^\d{6}$/;
  390. return reg.test(val);
  391. };
  392. Public.name = function (val) {
  393. var reg1 = /^([\u4e00-\u9fa5]){2,7}$/; //只能是中文,长度为2-7位
  394. var reg2 = /^[a-zA-Z\/ ]{2,20}$/; //英文
  395. if (reg1.test(val) || reg2.test(val)) {
  396. return true;
  397. } else {
  398. return false;
  399. }
  400. //return reg2.test(val);
  401. };
  402. //验证是否为大于0的非空纯数字
  403. Public.Ints = function (val) {
  404. if (!val) {
  405. return false;
  406. } else if (val <= 0) {
  407. return false;
  408. } else {
  409. return true;
  410. }
  411. };
  412. // 正数
  413. // Public.validateNums = function (num) {
  414. // var reg = /^\d+$|^\d+\.\d+$/g
  415. // if(reg.test(num)) return true;
  416. // return false ;
  417. // }
  418. Public.isInteger = function (obj) {
  419. var obj = Number(obj);
  420. return Math.floor(obj) === obj;
  421. };
  422. //倒计时执行函数封装
  423. Public.setTime = function (_this) {
  424. _this.btnCode = {
  425. time: 59,
  426. disabled: true
  427. };
  428. _this.$message({
  429. // message: _this.$t('header.tips[1]'),
  430. message: "验证码发送成功",
  431. type: "success"
  432. });
  433. var path = _this.$route.path;
  434. var set = setInterval(function () {
  435. if (_this.$route.path != path) clearInterval(set);
  436. _this.btnCode.time--;
  437. if (_this.btnCode.time <= 0) {
  438. _this.btnCode = {
  439. time: "重获验证码",
  440. disabled: false
  441. };
  442. clearInterval(set);
  443. }
  444. }, 1000);
  445. };
  446. //密码加密
  447. Public.transPwd = function (msg, type, _this) {
  448. };
  449. //提示信息封装
  450. Public.msg = function (msg, type, _this) {
  451. // _this.$message({
  452. // showClose: true,
  453. // message: msg,
  454. // type: type,
  455. // time: 2100000
  456. // });
  457. const h = _this.$createElement;
  458. _this.$notify[type]({
  459. message: msg,
  460. });
  461. };
  462. //传一个手机号 返回手机号的前3位和后四位 其他的显示* (手机号加密)
  463. Public.telStart = function (num, type) {
  464. let _num = String(num)
  465. //获得手机号的前3位
  466. if (!_num) {
  467. return false;
  468. }
  469. var a = _num.slice(0, 3);
  470. var b = _num.slice(7);
  471. var ok = a + "****" + b;
  472. if (type === 'bank') {
  473. var reg = /^(\d{4})\d+(\d{4})$/;
  474. _num = _num.replace(reg, "$1 **** **** $2");
  475. return _num
  476. }
  477. return ok;
  478. };
  479. Public.Trim = function (str) {
  480. return str.replace(/(^\s*)|(\s*$)/g, "");
  481. };
  482. Public.codeImg = function (id) {
  483. // 生成验证码
  484. function yanzhenma(window, document) {
  485. var size = 4; //设置验证码长度
  486. function GVerify(options) {
  487. //创建一个图形验证码对象,接收options对象为参数
  488. this.options = {
  489. //默认options参数值
  490. id: "", //容器Id
  491. canvasId: "verifyCanvas", //canvas的ID
  492. width: "200", //默认canvas宽度
  493. height: "44", //默认canvas高度
  494. type: "blend", //图形验证码默认类型blend:数字字母混合类型、number:纯数字、letter:纯字母
  495. code: ""
  496. };
  497. if (Object.prototype.toString.call(options) == "[object Object]") {
  498. //判断传入参数类型
  499. for (var i in options) {
  500. //根据传入的参数,修改默认参数值
  501. this.options[i] = options[i];
  502. }
  503. } else {
  504. this.options.id = options;
  505. }
  506. this.options.numArr = "0,1,2,3,4,5,6,7,8,9".split(",");
  507. this.options.letterArr = getAllLetter();
  508. this._init();
  509. this.refresh();
  510. }
  511. GVerify.prototype = {
  512. /**版本号**/
  513. version: "1.0.0",
  514. /**初始化方法**/
  515. _init: function () {
  516. var con = document.getElementById(this.options.id);
  517. var canvas = document.createElement("canvas");
  518. this.options.width = con.offsetWidth > 0 ? con.offsetWidth : "200";
  519. this.options.height = con.offsetHeight > 0 ? con.offsetHeight : "44";
  520. canvas.id = this.options.canvasId;
  521. canvas.width = this.options.width;
  522. canvas.height = this.options.height;
  523. canvas.style.cursor = "pointer";
  524. canvas.innerHTML = "您的浏览器版本不支持canvas";
  525. con.appendChild(canvas);
  526. var parent = this;
  527. canvas.onclick = function () {
  528. parent.refresh();
  529. };
  530. },
  531. /**生成验证码**/
  532. refresh: function () {
  533. this.options.code = "";
  534. var canvas = document.getElementById(this.options.canvasId);
  535. if (canvas.getContext) {
  536. var ctx = canvas.getContext("2d");
  537. } else {
  538. return;
  539. }
  540. ctx.textBaseline = "middle";
  541. ctx.fillStyle = randomColor(180, 240);
  542. ctx.fillRect(0, 0, this.options.width, this.options.height);
  543. if (this.options.type == "blend") {
  544. //判断验证码类型
  545. var txtArr = this.options.numArr.concat(this.options.letterArr);
  546. } else if (this.options.type == "number") {
  547. var txtArr = this.options.numArr;
  548. } else {
  549. var txtArr = this.options.letterArr;
  550. }
  551. for (var i = 1; i <= size; i++) {
  552. var txt = txtArr[randomNum(0, txtArr.length)];
  553. this.options.code += txt;
  554. ctx.font =
  555. randomNum(this.options.height, this.options.height) + "px SimHei"; //随机生成字体大小
  556. ctx.fillStyle = randomColor(50, 160); //随机生成字体颜色
  557. ctx.shadowOffsetX = randomNum(-3, 3);
  558. ctx.shadowOffsetY = randomNum(-3, 3);
  559. ctx.shadowBlur = randomNum(-3, 3);
  560. ctx.shadowColor = "rgba(0, 0, 0, 0.3)";
  561. var x = (this.options.width / (size + 1)) * i;
  562. var y = this.options.height / 2;
  563. var deg = randomNum(-30, 30);
  564. /**设置旋转角度和坐标原点**/
  565. ctx.translate(x, y);
  566. ctx.rotate((deg * Math.PI) / 180);
  567. ctx.fillText(txt, 0, 0);
  568. /**恢复旋转角度和坐标原点**/
  569. ctx.rotate((-deg * Math.PI) / 180);
  570. ctx.translate(-x, -y);
  571. }
  572. /**绘制干扰线**/
  573. for (var i = 0; i < 4; i++) {
  574. ctx.strokeStyle = randomColor(40, 180);
  575. ctx.beginPath();
  576. ctx.moveTo(
  577. randomNum(0, this.options.width),
  578. randomNum(0, this.options.height)
  579. );
  580. ctx.lineTo(
  581. randomNum(0, this.options.width),
  582. randomNum(0, this.options.height)
  583. );
  584. ctx.stroke();
  585. }
  586. /**绘制干扰点**/
  587. for (var i = 0; i < this.options.width / 4; i++) {
  588. ctx.fillStyle = randomColor(0, 255);
  589. ctx.beginPath();
  590. ctx.arc(
  591. randomNum(0, this.options.width),
  592. randomNum(0, this.options.height),
  593. 1,
  594. 0,
  595. 2 * Math.PI
  596. );
  597. ctx.fill();
  598. }
  599. },
  600. /**验证验证码**/
  601. validate: function (code) {
  602. var code = code.toLowerCase();
  603. var v_code = this.options.code.toLowerCase();
  604. if (code == v_code) {
  605. return true;
  606. } else {
  607. this.refresh();
  608. return false;
  609. }
  610. }
  611. };
  612. /**生成字母数组**/
  613. function getAllLetter() {
  614. var letterStr =
  615. "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
  616. return letterStr.split(",");
  617. }
  618. /**生成一个随机数**/
  619. function randomNum(min, max) {
  620. return Math.floor(Math.random() * (max - min) + min);
  621. }
  622. /**生成一个随机色**/
  623. function randomColor(min, max) {
  624. var r = randomNum(min, max);
  625. var g = randomNum(min, max);
  626. var b = randomNum(min, max);
  627. return "rgb(" + r + "," + g + "," + b + ")";
  628. }
  629. window.GVerify = GVerify;
  630. }
  631. yanzhenma(window, document);
  632. new GVerify(id);
  633. };
  634. //页面路由跳转封装
  635. Public.go = function (url, time, _this) {
  636. _this.$router.push({
  637. path: url
  638. });
  639. };
  640. Public.scrollTop = function () {
  641. document.body.scrollTop = document.documentElement.scrollTop = 0;
  642. };
  643. function mul(a, b) {
  644. var c = 0,
  645. d = a.toString(),
  646. e = b.toString();
  647. try {
  648. c += d.split(".")[1].length;
  649. } catch (f) {
  650. }
  651. try {
  652. c += e.split(".")[1].length;
  653. } catch (f) {
  654. }
  655. return (
  656. (Number(d.replace(".", "")) * Number(e.replace(".", ""))) / Math.pow(10, c)
  657. );
  658. }
  659. //判断是否登录执行函数
  660. Public.isLogin = function (_this) {
  661. if (!sessionStorage.account || !sessionStorage.token) {
  662. _this.$public.msg(_this.$t("confirm[4]"), "warning", _this);
  663. _this.$public.go("login", 1000, _this);
  664. }
  665. };
  666. //提示信息封装
  667. Public.confirm = function (msg, what, _this) {
  668. _this
  669. .$confirm(msg, _this.$t("confirm[0]"), {
  670. confirmButtonText: _this.$t("confirm[1]"),
  671. cancelButtonText: _this.$t("confirm[2]"),
  672. type: "warning"
  673. })
  674. .then(() => {
  675. _this.$public.go(what, 800, _this);
  676. })
  677. .catch(() => {
  678. _this.$message({
  679. type: "info",
  680. message: _this.$t("confirm[3]")
  681. });
  682. });
  683. return false;
  684. };
  685. //提示没有设置资金密码
  686. Public.confirm_fund_pwd = function (msg, what, _this) {
  687. _this
  688. .$confirm(msg, _this.$t("confirm[0]"), {
  689. confirmButtonText: _this.$t("confirm[1]"),
  690. cancelButtonText: _this.$t("confirm[2]"),
  691. type: "warning"
  692. })
  693. .then(() => {
  694. _this.$public.go(what, 800, _this);
  695. })
  696. .catch(() => {
  697. _this.$message({
  698. type: "info",
  699. message: _this.$t("confirm[3]")
  700. });
  701. });
  702. return false;
  703. };
  704. // 币种图标
  705. Public.transCodeImg = function (code) {
  706. return transCodeImg(code);
  707. };
  708. //清除对象值
  709. Public.clearObj = function (obj, save) {
  710. for (var i in obj) {
  711. if (i !== save) {
  712. obj[i] = undefined;
  713. }
  714. }
  715. };
  716. //谷歌验证
  717. Public.googleVerify = function (isLogin) {
  718. //直接调用 不用额外判断用户谷歌开关状态 内部统一处理
  719. return new Promise((resolve, reject) => {
  720. if (isLogin || store.getters.googleState == 1) {
  721. //谷歌验证已开启的用户
  722. // '请输入谷歌验证码', '谷歌验证'
  723. vue
  724. .$prompt(
  725. vue.$t("googleDialog.tips[0]"),
  726. vue.$t("googleDialog.tips[1]"),
  727. {
  728. confirmButtonText: vue.$t("center.baseInfo[33]"),
  729. cancelButtonText: vue.$t("center.baseInfo[34]"),
  730. customClass: "prompt_googleVerify",
  731. inputType: "password",
  732. inputPattern: /^\d{6}$/,
  733. inputErrorMessage: vue.$t("googleDialog.tips[2]")
  734. }
  735. )
  736. .then(data => {
  737. // 请求谷歌验证码接口,成功返回true 失败false
  738. let _data = {
  739. code: data.value,
  740. stockUserId: store.getters.Id
  741. };
  742. checkGoogleCode(_data).then(res => {
  743. if (res.data.code == 200) {
  744. resolve(true);
  745. } else {
  746. resolve(false);
  747. }
  748. });
  749. })
  750. .catch(() => {
  751. reject("取消输入");
  752. });
  753. } else {
  754. //谷歌验证关闭的用户
  755. resolve(true);
  756. }
  757. });
  758. };
  759. // 保留位数
  760. Public.savePoint = function (code) {
  761. if (!code) {
  762. return 2;
  763. }
  764. var _code = code;
  765. if (_code.indexOf("/") > -1) {
  766. _code = _code.replace("/", "_");
  767. }
  768. _code = _code.toLowerCase();
  769. var obj = {
  770. btc_usdt: 2,
  771. eth_usdt: 2,
  772. bch_usdt: 2,
  773. etc_usdt: 4,
  774. xrp_usdt: 5,
  775. ltc_usdt: 2,
  776. eos_usdt: 4,
  777. dash_usdt: 2,
  778. ht_usdt: 4,
  779. atom_usdt: 4,
  780. trx_usdt: 6,
  781. imc_usdt: 4,
  782. link_usdt: 4,
  783. bsv_usdt: 4,
  784. trx_usdt: 6,
  785. ada_usdt: 6,
  786. xlm_usdt: 6,
  787. xmr_usdt: 2,
  788. neo_usdt: 2,
  789. xem_usdt: 4,
  790. iota_usdt: 4,
  791. zec_usdt: 2,
  792. omg_usdt: 4,
  793. ont_usdt: 4,
  794. defalut: 2
  795. };
  796. var num = obj[_code] ? obj[_code] : obj.defalut;
  797. return num;
  798. };
  799. Public.cpTime = function (endTime) {
  800. let start = new Date().getTime()
  801. let end = new Date(endTime).getTime()
  802. let time = end - start;
  803. if (time >= 0) {
  804. let day = Math.floor(time / 86400000);
  805. time = time - day * 86400000;
  806. let hours = Math.floor(time / 3600000);
  807. time = time - hours * 3600000;
  808. let min = Math.floor(time / 60000);
  809. time = time - min * 60000;
  810. let second = Math.floor(time / 1000);
  811. let obj = {
  812. day,
  813. hours,
  814. min,
  815. second
  816. };
  817. // let obj = {
  818. // day:day<10?'0'+day:day,
  819. // hours:hours<10?'0'+hours:hours,
  820. // min:min<10?'0'+min:min,
  821. // second:second<10?'0'+second:second
  822. // };
  823. obj.hours = obj.day * 24 + obj.hours * 1
  824. obj.hours < 10 ? obj.hours = '0' + obj.hours : ''
  825. obj.min < 10 ? obj.min = '0' + obj.min : ''
  826. obj.second < 10 ? obj.second = '0' + obj.second : ''
  827. return `${obj.hours}:${obj.min}:${obj.second}`
  828. } else {
  829. return false
  830. }
  831. },
  832. // 保留位数 下单数量
  833. Public.savePoint_order = function (code) {
  834. if (!code) {
  835. return 6;
  836. }
  837. var _code = code;
  838. if (_code.indexOf("/") > -1) {
  839. _code = _code.replace("/", "_");
  840. }
  841. _code = _code.toLowerCase();
  842. var obj = {
  843. btc_usdt: 6,
  844. eth_usdt: 4,
  845. bch_usdt: 4,
  846. etc_usdt: 4,
  847. xrp_usdt: 2,
  848. ltc_usdt: 4,
  849. eos_usdt: 4,
  850. dash_usdt: 4,
  851. atom_usdt: 4,
  852. ht_usdt: 4,
  853. imc_usdt: 4,
  854. link_usdt: 4,
  855. bsv_usdt: 4,
  856. trx_usdt: 4,
  857. ada_usdt: 4,
  858. xlm_usdt: 4,
  859. xmr_usdt: 4,
  860. neo_usdt: 4,
  861. xem_usdt: 4,
  862. iota_usdt: 4,
  863. zec_usdt: 4,
  864. omg_usdt: 4,
  865. ont_usdt: 4,
  866. defalut: 2
  867. };
  868. var num = obj[_code] ? obj[_code] : obj.defalut;
  869. return num;
  870. };
  871. Public.transPrice_order = function (val, code, bl) {
  872. //按需将价格位数保留
  873. if (val == undefined) return 0; //
  874. var num = this.savePoint_order(code);
  875. var _num = Number(val).toFixed(num + 1);
  876. if (bl) {
  877. return parseFloat(Number(_num.substr(0, _num.length - 1)));
  878. }
  879. return _num.substr(0, _num.length - 1);
  880. };
  881. Public.CryptographicLand = function (argument) {
  882. //登录密码加密
  883. return md5(argument);
  884. };
  885. Public.ungzip = function (msg, call) {
  886. let reader = new FileReader();
  887. reader.onload = () => {
  888. let result = JSON.parse(
  889. this.$pako.inflate(reader.result, {to: "string"})
  890. );
  891. };
  892. let blob = msg.data;
  893. try {
  894. reader.readAsBinaryString(blob);
  895. } catch (err) {
  896. console.log(err);
  897. }
  898. };
  899. Public.Cryptographiccapital = function (argument) {
  900. //资金密码加密
  901. return md5(argument);
  902. };
  903. Public.transPrice = function (val, code, bl) {
  904. //按需将价格位数保留
  905. if (val == undefined) return 0; //
  906. var num = this.savePoint(code);
  907. var _num = Number(val).toFixed(num + 1);
  908. if (bl) {
  909. return parseFloat(_num.substr(0, _num.length - 1));
  910. }
  911. return _num.substr(0, _num.length - 1);
  912. };
  913. Public.CryptographicLand = function (argument) {
  914. //登录密码加密
  915. return md5(argument);
  916. };
  917. Public.Cryptographiccapital = function (argument) {
  918. //资金密码加密
  919. return md5(argument);
  920. };
  921. // 加密
  922. Public.encrypt = function (word) {
  923. return word
  924. // return vue.$jse.encrypt(String(word))
  925. var key = CryptoJS.enc.Utf8.parse(keyStr);
  926. var srcs = CryptoJS.enc.Utf8.parse(word);
  927. var encrypted = CryptoJS.AES.encrypt(srcs, key, {
  928. mode: CryptoJS.mode.ECB,
  929. // padding: CryptoJS.pad.Pkcs7
  930. padding: CryptoJS.pad.ZeroPadding
  931. }); // 加密模式为ECB,补码方式为PKCS5Padding(也就是PKCS7)
  932. return encrypted.toString();
  933. };
  934. // 解密
  935. Public.decrypt = function (word) {
  936. var key = CryptoJS.enc.Utf8.parse(keyStr);
  937. var decrypt = CryptoJS.AES.decrypt(word, key, {
  938. mode: CryptoJS.mode.ECB,
  939. // padding: CryptoJS.pad.Pkcs7
  940. padding: CryptoJS.pad.ZeroPadding
  941. });
  942. return CryptoJS.enc.Utf8.stringify(decrypt).toString();
  943. };
  944. // 獲取 cookie
  945. Public.getCookie = function (name) {
  946. var arr,
  947. reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  948. if ((arr = document.cookie.match(reg))) return unescape(arr[2]);
  949. else return null;
  950. };
  951. //获取浏览器查询字符串
  952. Public.GetQueryString = function (name) {
  953. //截取url
  954. var reg = new RegExp("(^|&|)" + name + "=([^&?]*)(&|$|)", "i");
  955. var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
  956. var context = "";
  957. if (r != null) context = r[2];
  958. reg = null;
  959. r = null;
  960. return context == null || context == "" || context == "undefined"
  961. ? ""
  962. : context;
  963. };
  964. Public.webSocket = function (url) {
  965. let _webSocket;
  966. if ("WebSocket" in window) {
  967. _webSocket = new WebSocket(url);
  968. } else if ("MozWebSocket" in window) {
  969. _webSocket = new MozWebSocket(url);
  970. } else {
  971. _webSocket = new SockJS(url);
  972. }
  973. return _webSocket;
  974. };
  975. export default Public;