1. /**
    2. * describe: 手机号中间四位显示*
    3. */
    4. export function starPhone(phoneNum) {
    5. let str = String(phoneNum),
    6. strLen = str.slice(-7, -3);
    7. return str.replace(strLen, "****");
    8. }
    9. /**
    10. * 手机号+* 方法二
    11. * */
    12. export function starPhone2(phoneNum) {
    13. var str = phoneNum
    14. var str2 = str.substr(0, 3) + "****" + str.substr(7);
    15. return str2;
    16. }
    17. /**
    18. * describe: 数字千分位
    19. */
    20. export function ThousandthPercentile(num) {
    21. if (num === null) {
    22. return num = 0;
    23. } else {
    24. if (num != undefined) {
    25. return num = num.replace(/\d{1,3}(?=(\d{3})+(\.|$))/g, '$&,');
    26. }
    27. }
    28. }
    29. //保留n位小数
    30. export function roundFun(val, n) {
    31. return Math.round(val * Math.pow(10, n)) / Math.pow(10, n);
    32. }
    33. // 银行卡号脱敏
    34. export function phoneFormat(val) {
    35. return val.replace(/(\d{3})\d*(\d{4})/, '$1 **** **** $2')
    36. }
    37. //手机号验证
    38. export function MobileVerification(val) {
    39. let reg = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-7|9])|(?:5[0-3|5-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1|8|9]))\d{8}$/;
    40. return reg.test(val);
    41. }
    42. // 银行卡号校验
    43. export function yhkFication(val) {
    44. let reg = /^[1-9]\d{9,29}$/
    45. return reg.test(val)
    46. }
    47. //获取顶部参数
    48. export function getUrlKey(name) {//获取url 参数
    49. return decodeURIComponent(
    50. (new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null;
    51. }
    52. export function handlerDatas(arr) {
    53. let tempArr = [];
    54. let endData = [];
    55. for (let i = 0; i < arr.length; i++) {
    56. if (tempArr.indexOf(arr[i].templateType) === -1) {
    57. endData.push({
    58. templateType: arr[i].templateType,
    59. children: [arr[i]]
    60. });
    61. tempArr.push(arr[i].templateType);
    62. } else {
    63. for (let j = 0; j < endData.length; j++) {
    64. if (endData[j].templateType == arr[i].templateType) {
    65. endData[j].children.push(arr[i]);
    66. break;
    67. }
    68. }
    69. }
    70. }
    71. var newJosn = {};
    72. for (var u in endData) {
    73. newJosn['templateType_' + endData[u].templateType] = endData[u].children
    74. }
    75. console.log(newJosn); // 最终输出
    76. return newJosn;
    77. }
    78. // 判断https/http
    79. export function httpsUrl(name) {
    80. //判断是否符合http://符合返回真不符合返回假
    81. var http = /^http:\/\/.*/i.test(name);
    82. //判断是否符合https://符合返回真不符合返回假
    83. var https = /^https:\/\/.*/i.test(name);
    84. let httpsBooter;
    85. //如果两个都为假
    86. if (!http && !https) {
    87. httpsBooter = false;
    88. } else {
    89. httpsBooter = true;
    90. }
    91. return httpsBooter
    92. }
    93. //获取url
    94. export function httpslianjie(url, urlname) {
    95. var parameter = url.substring(url.indexOf('?') + 1);
    96. parameter = parameter.split('&');
    97. var reg = /urlname=/g;
    98. var menuCode = "";
    99. for (var i = 0; i < parameter.length; i++) {
    100. reg.lastIndex = 0;
    101. if (reg.test(parameter[i])) {
    102. menuCode = parameter[i].replace(urlname + "=", "");
    103. break;
    104. }
    105. }
    106. return menuCode;
    107. }
    108. // 小程序跳转
    109. export function launchWeApp(info) {
    110. if (info.active) {
    111. var btn = document.getElementById(info.eleId);
    112. let script = document.createElement("script");
    113. script.type = "text/wxtag-template";
    114. script.text = info.content
    115. let html =
    116. `<wx-open-launch-weapp style="width:100%;height:100%;display:block;" username="${info.username}" path="${info.url}">${script.outerHTML}</wx-open-launch-weapp>`;
    117. btn.innerHTML = html;
    118. btn.addEventListener("launch", info.launchEvent);
    119. btn.addEventListener("error", info.errorEvent);
    120. } else {
    121. var btn = document.getElementById(info.eleId); //获取元素
    122. let html =
    123. `<view style="width:100%;height:100%;display:block;">${info.content}</view>`;
    124. btn.innerHTML = html;
    125. btn.addEventListener("click", info.noAtiveEvent);
    126. }
    127. }
    128. export function launchApp(info) {
    129. if (info.active) {
    130. var btn = document.getElementById(info.eleId);
    131. let script = document.createElement("script");
    132. script.type = "text/wxtag-template";
    133. script.text = info.content
    134. let html =
    135. `<wx-open-launch-app style="width:100%;height:100%;display:block;" appid="${info.appid}" extinfo="${info.extinfo}">${script.outerHTML}</wx-open-launch-app>`;
    136. btn.innerHTML = html;
    137. btn.addEventListener("launch", info.launchEvent);
    138. btn.addEventListener("error", info.errorEvent);
    139. } else {
    140. var btn = document.getElementById(info.eleId); //获取元素
    141. let html =
    142. `<view style="width:100%;height:100%;display:block;">${info.content}</view>`;
    143. btn.innerHTML = html;
    144. btn.addEventListener("click", info.noAtiveEvent);
    145. }
    146. }
    147. /**
    148. * 数字格式化金额,整数位每三位用逗号隔开,小数点保留n位(默认保留两位)
    149. */
    150. export function filterMoney(s, n) {
    151. if (s !== null && typeof s !== 'undefined') {
    152. n = n > 0 && n <= 20 ? n : 2;
    153. s = `${parseFloat(`${s}`.replace(/[^\d\.-]/g, '')).toFixed(n)}`;
    154. let l = s.split('.')[0].split('').reverse(),
    155. r = s.split('.')[1];
    156. let t = '';
    157. for (let i = 0; i < l.length; i++) {
    158. t += l[i] + ((i + 1) % 3 === 0 && i + 1 !== l.length ? ',' : '');
    159. }
    160. return `${t.split('').reverse().join('')}.${r}`;
    161. }
    162. return null;
    163. }