123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- import Cookie from 'js-cookie';
- import { build } from 'eth-url-parser';
- import axios from 'axios';
- //application/vnd.chromium.remoting-viewer 可能为360特有 通过_mine判断是否是360
- export function isBrowser() {
- var agent = navigator.userAgent.toLowerCase();
- console.log(agent);
- const System = function () {
- if (agent.indexOf('qqbrowser') > 0) {
- //判断是qq浏览器还是其它浏览器
- return 'qq浏览器';
- }
- if (agent.indexOf('se 2.x') > 0) {
- return '搜狗浏览器';
- }
- var is360 = _mime('type', 'application/vnd.chromium.remoting-viewer');
- if (is360) {
- return '360浏览器';
- }
- //检测是否是谷歌内核(可排除360及谷歌以外的浏览器)
- //测试mime
- function _mime(option, value) {
- var mimeTypes = navigator.mimeTypes;
- console.log(mimeTypes);
- for (var mt in mimeTypes) {
- if (mimeTypes[mt][option] == value) {
- return true;
- }
- }
- return false;
- }
- };
- let s = System();
- if (s) {
- return s;
- }
- if (agent.indexOf('firefox') > 0) {
- return 'firefox浏览器';
- }
- if (agent.indexOf('trident') > 0) {
- return 'IE浏览器';
- }
- if (agent.indexOf('edg') > 0) {
- return 'IE浏览器';
- }
- if (agent.indexOf('safari') > 0 && agent.indexOf('chrome') < 0) {
- return 'Safari';
- }
- if (agent.indexOf('chrome') > 0) {
- return 'chrome';
- }
- }
- // 获取host
- export const getEnvConfig = () => {
- let host, logHost;
- console.log('NODE_ENV=', process.env.NUXT_ENV.MODE);
- // @ts-ignore
- switch (process.env.NUXT_ENV.MODE) {
- case `prod`:
- host = `https://api.denetme.net`;
- logHost = 'https://log.denetme.net';
- break;
- case `pre`:
- host = `https://preapi.denetme.net`;
- logHost = 'https:/prelog.denetme.net';
- break;
- default:
- host = `https://testapi.denetme.net`;
- logHost = 'https://testlog.denetme.net';
- break;
- }
- return {
- host,
- logHost,
- };
- };
- export function getBrowser() {
- let browser;
- let UserAgent = navigator.userAgent.toLowerCase();
- if (UserAgent.indexOf('chrome') > -1 && UserAgent.indexOf('safari') > -1) {
- browser = `Chrome`;
- } else if (UserAgent.indexOf('firefox') > -1) {
- browser = `Firefox`;
- } else if (UserAgent.indexOf('opera') > -1) {
- browser = `Opera`;
- } else if (UserAgent.indexOf('safari') > -1 && UserAgent.indexOf('chrome') == -1) {
- browser = `Safari`;
- } else if (UserAgent.indexOf('edge') > -1) {
- browser = `Edge`;
- } else {
- browser = `Other`;
- }
- return browser;
- }
- export function formatSecondsAsTime(secs) {
- var hr = Math.floor(secs / 3600);
- var min = Math.floor((secs - hr * 3600) / 60);
- var sec = Math.floor(secs - hr * 3600 - min * 60);
- var text;
- if (hr < 10) {
- hr = '0' + hr;
- }
- if (min < 10) {
- min = '0' + min;
- }
- if (sec < 10) {
- sec = '0' + sec;
- }
- text = hr + ':' + min + ':' + sec;
- return text;
- }
- // 抽奖红包 left
- export function formatSecondsAsDaysOrTime(secs) {
- if (secs <= 0) {
- return '00:00:00';
- }
- let text = '';
- var hr = Math.floor(secs / 3600);
- if (hr >= 24) {
- let day = parseInt(hr / 24);
- text = `${day} days left`;
- } else {
- text = formatSecondsAsTime(secs);
- }
- return text;
- }
- export const appVersionCode = 17;
- export const appType = 1;
- export function getBrowserType() {
- let device = ''; // ios 安卓 chrome no-chrome
- if (/android/i.test(navigator.userAgent)) {
- device = '安卓';
- } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
- device = 'ios';
- } else if (isBrowser() == 'chrome') {
- device = 'chrome';
- } else {
- device = 'no-chrome';
- }
- return device;
- }
- const api = {
- prod: 'https://api.denetme.net',
- pre: 'https://preapi.denetme.net',
- test: 'https://testapi.denetme.net',
- };
- const page = {
- prod: 'https://h5.denetme.net',
- pre: 'https://preh5.denetme.net',
- test: 'https://testh5.denetme.net',
- };
- export const jumpUrl = page[process.env.NUXT_ENV.MODE] + '/';
- export const baseURL = api[process.env.NUXT_ENV.MODE];
- export const getStorage = (key) => {
- return JSON.parse(localStorage.getItem(key));
- };
- export const setStorage = (key, data) => {
- localStorage.setItem(key, JSON.stringify(data));
- };
- export const removeStorage = (key) => {
- localStorage.removeItem(key);
- };
- // storageKey
- export const storageKey = {
- verifier: 'verifierKey',
- userInfo: 'userInfo',
- achPayInfo: 'achPayInfo',
- paymentUrl: 'paymentUrl',
- backFromTwitterLogin: 'denet-mobile-landpage-back-from-twitter-login',
- };
- // 推特授权url
- export const getOauthUrl = (token) => {
- return `https://api.twitter.com/oauth/authenticate?oauth_token=${token}`;
- };
- // 创建窗口
- export const createWindow = (url, w = 400, h = 600) => {
- var left = Math.round((window.screen.availWidth - w) / 2);
- var top = Math.round((window.screen.availHeight - 100 - h) / 2);
- 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`);
- return win;
- };
- // 帮助函数
- const guid = () => {
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
- var r = (Math.random() * 16) | 0,
- v = c == 'x' ? r : (r & 0x3) | 0x8;
- return v.toString(16);
- });
- };
- // 获取mid
- export const getMid = () => {
- let _mid;
- let _cookie_mid_arr = Cookie.get('mid') || [];
- if (_cookie_mid_arr.length > 0) {
- _mid = JSON.parse(_cookie_mid_arr)[0].mid;
- } else {
- _mid = guid();
- Cookie.set('mid', JSON.stringify([{ mid: _mid }]), { expires: 1000 });
- }
- return _mid;
- };
- export const getUserInfo = () => {
- let userInfo = getStorage(storageKey.userInfo) || null;
- if (userInfo) {
- return userInfo;
- } else {
- return null;
- }
- };
- export function getQueryString(name) {
- let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
- let r = window.location.search.substr(1).match(reg);
- if (r != null) {
- return decodeURIComponent(r[2]);
- }
- return null;
- }
- export const denetExtensionId = 'inlfbeejfdgkknpiodhemfcokbdgofja';
- export function detectExtension(extensionId, callback) {
- var img;
- img = new Image();
- img.src = 'chrome-extension://' + extensionId + '/img/icon-denet-logo.svg';
- img.onload = function () {
- callback(true);
- };
- img.onerror = function () {
- callback(false);
- };
- }
- export const maskUrl = (params, isMain = true) => {
- let url = build({
- function_name: isMain ? null : `transfer`,
- ...params,
- });
- // url
- return url.replace(`ethereum:`, `https://metamask.app.link/send/`);
- };
- export const OSDetect = () => {
- let u = navigator.userAgent;
- // 安卓
- if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
- return 'android';
- }
- // iOS
- if (u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
- return 'ios';
- }
- };
- export async function getDetailSSR({ context = {}, params = {}, url = '' }) {
- let { req } = context;
- const headers = req && req.headers ? Object.assign({}, req.headers) : {};
- let { data } = await axios.post(
- url,
- {
- baseInfo: {
- appVersionCode: appVersionCode,
- mid: '00000000-0000-0000-0000-000000000000',
- },
- params,
- },
- {
- headers: {
- referer: headers['referer'] || '',
- 'x-forwarded-for': headers['x-forwarded-for'] || '',
- },
- }
- );
- return data;
- }
|