help.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import Cookie from 'js-cookie';
  2. //application/vnd.chromium.remoting-viewer 可能为360特有 通过_mine判断是否是360
  3. export function isBrowser() {
  4. var agent = navigator.userAgent.toLowerCase();
  5. console.log(agent);
  6. const System = function () {
  7. if (agent.indexOf('qqbrowser') > 0) {
  8. //判断是qq浏览器还是其它浏览器
  9. return 'qq浏览器';
  10. }
  11. if (agent.indexOf('se 2.x') > 0) {
  12. return '搜狗浏览器';
  13. }
  14. var is360 = _mime('type', 'application/vnd.chromium.remoting-viewer');
  15. if (is360) {
  16. return '360浏览器';
  17. }
  18. //检测是否是谷歌内核(可排除360及谷歌以外的浏览器)
  19. //测试mime
  20. function _mime(option, value) {
  21. var mimeTypes = navigator.mimeTypes;
  22. console.log(mimeTypes);
  23. for (var mt in mimeTypes) {
  24. if (mimeTypes[mt][option] == value) {
  25. return true;
  26. }
  27. }
  28. return false;
  29. }
  30. };
  31. let s = System();
  32. if (s) {
  33. return s;
  34. }
  35. if (agent.indexOf('firefox') > 0) {
  36. return 'firefox浏览器';
  37. }
  38. if (agent.indexOf('trident') > 0) {
  39. return 'IE浏览器';
  40. }
  41. if (agent.indexOf('edg') > 0) {
  42. return 'IE浏览器';
  43. }
  44. if (agent.indexOf('safari') > 0 && agent.indexOf('chrome') < 0) {
  45. return 'Safari';
  46. }
  47. if (agent.indexOf('chrome') > 0) {
  48. return 'chrome';
  49. }
  50. }
  51. // 获取host
  52. export const getEnvConfig = () => {
  53. let host, logHost;
  54. // @ts-ignore
  55. switch (process.env.NODE_ENV) {
  56. case `production`:
  57. host = `https://api.denetme.net`;
  58. logHost = `https://log.weiqumeta.com`;
  59. break;
  60. case `pre`:
  61. host = `https://preapi.denetme.net`;
  62. logHost = `https://prelog.weiqumeta.com`;
  63. break;
  64. default:
  65. host = `https://testapi.denetme.net`;
  66. logHost = `https://testlog.weiqumeta.com`;
  67. break;
  68. }
  69. return {
  70. host,
  71. logHost,
  72. };
  73. };
  74. export function getBrowser() {
  75. let browser;
  76. let UserAgent = navigator.userAgent.toLowerCase();
  77. if (UserAgent.indexOf('chrome') > -1 || UserAgent.indexOf('crios') > -1) {
  78. browser = `Chrome`;
  79. } else if (UserAgent.indexOf('firefox') > -1) {
  80. browser = `Firefox`;
  81. } else if (UserAgent.indexOf('opera') > -1) {
  82. browser = `Opera`;
  83. } else if (UserAgent.indexOf('safari') > -1 && UserAgent.indexOf('chrome') == -1) {
  84. browser = `Safari`;
  85. } else if (UserAgent.indexOf('edge') > -1) {
  86. browser = `Edge`;
  87. } else {
  88. browser = `Other`;
  89. }
  90. return browser;
  91. }
  92. export function formatSecondsAsTime(secs) {
  93. var hr = Math.floor(secs / 3600);
  94. var min = Math.floor((secs - hr * 3600) / 60);
  95. var sec = Math.floor(secs - hr * 3600 - min * 60);
  96. var text;
  97. if (hr < 10) {
  98. hr = '0' + hr;
  99. }
  100. if (min < 10) {
  101. min = '0' + min;
  102. }
  103. if (sec < 10) {
  104. sec = '0' + sec;
  105. }
  106. text = hr + ':' + min + ':' + sec;
  107. return text;
  108. }
  109. // 抽奖红包 left
  110. export function formatSecondsAsDaysOrTime(secs) {
  111. if (secs <= 0) {
  112. return '00:00:00';
  113. }
  114. let text = '';
  115. var hr = Math.floor(secs / 3600);
  116. if (hr >= 24) {
  117. let day = parseInt(hr / 24);
  118. text = `${day} days left`;
  119. } else {
  120. text = formatSecondsAsTime(secs);
  121. }
  122. return text;
  123. }
  124. export const appVersionCode = 17;
  125. export const appType = 1;
  126. export function getBrowserType() {
  127. let device = ''; // ios 安卓 chrome no-chrome
  128. if (/android/i.test(navigator.userAgent)) {
  129. device = '安卓';
  130. } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
  131. device = 'ios';
  132. } else if (isBrowser() == 'chrome') {
  133. device = 'chrome';
  134. } else {
  135. device = 'no-chrome';
  136. }
  137. return device;
  138. }
  139. const api = {
  140. prod: 'https://api.denetme.net',
  141. pre: 'https://preapi.denetme.net',
  142. test: 'https://testapi.denetme.net',
  143. };
  144. const page = {
  145. prod: 'https://h5.denetme.net',
  146. pre: 'https://preh5.denetme.net',
  147. test: 'https://testh5.denetme.net',
  148. };
  149. export const jumpUrl = page[process.env.NUXT_ENV.MODE] + '/';
  150. export const baseURL = api[process.env.NUXT_ENV.MODE];
  151. export const getStorage = (key) => {
  152. return JSON.parse(localStorage.getItem(key));
  153. };
  154. export const setStorage = (key, data) => {
  155. localStorage.setItem(key, JSON.stringify(data));
  156. };
  157. export const removeStorage = (key) => {
  158. localStorage.removeItem(key);
  159. };
  160. // storageKey
  161. export const storageKey = {
  162. verifier: 'verifierKey',
  163. userInfo: 'userInfo',
  164. backFromTwitterLogin: 'denet-mobile-landpage-back-from-twitter-login',
  165. };
  166. // 推特授权url
  167. export const getOauthUrl = (token) => {
  168. return `https://api.twitter.com/oauth/authenticate?oauth_token=${token}`;
  169. };
  170. // 创建窗口
  171. export const createWindow = (url, w = 400, h = 600) => {
  172. var left = Math.round((window.screen.availWidth - w) / 2);
  173. var top = Math.round((window.screen.availHeight - 100 - h) / 2);
  174. var win = window.open(url, `newWin`, `width=${w}, height=${h}, top=${top}, left=${left}, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no`);
  175. return win;
  176. };
  177. // 帮助函数
  178. const guid = () => {
  179. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  180. var r = (Math.random() * 16) | 0,
  181. v = c == 'x' ? r : (r & 0x3) | 0x8;
  182. return v.toString(16);
  183. });
  184. };
  185. // 获取mid
  186. export const getMid = () => {
  187. let _mid;
  188. let _cookie_mid_arr = Cookie.get('mid') || [];
  189. if (_cookie_mid_arr.length > 0) {
  190. _mid = JSON.parse(_cookie_mid_arr)[0].mid;
  191. } else {
  192. _mid = guid();
  193. Cookie.set('mid', JSON.stringify([{ mid: _mid }]), { expires: 1000 });
  194. }
  195. return _mid;
  196. };
  197. export const getUserInfo = () => {
  198. let userInfo = getStorage(storageKey.userInfo) || null;
  199. if (userInfo) {
  200. return userInfo;
  201. } else {
  202. return null;
  203. }
  204. };
  205. export function getQueryString(name) {
  206. let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  207. let r = window.location.search.substr(1).match(reg);
  208. if (r != null) {
  209. return decodeURIComponent(r[2]);
  210. }
  211. return null;
  212. }