|
|
@@ -1,200 +1,4 @@
|
|
|
-import moment from 'moment';
|
|
|
-import React from 'react';
|
|
|
-import { notification, Icon } from 'antd';
|
|
|
-import nzh from 'nzh/cn';
|
|
|
-import { parse, stringify } from 'qs';
|
|
|
-import { SetNotificationRead } from '@/services/user';
|
|
|
-import request from '@/utils/request';
|
|
|
-import { MessageEvent, UnityMessageEvent, PageMessageEvent } from './event';
|
|
|
-
|
|
|
-export function fixedZero(val) {
|
|
|
- return val * 1 < 10 ? `0${val}` : val;
|
|
|
-}
|
|
|
-
|
|
|
-export function getTimeDistance(type) {
|
|
|
- const now = new Date();
|
|
|
- const oneDay = 1000 * 60 * 60 * 24;
|
|
|
-
|
|
|
- if (type === 'today') {
|
|
|
- now.setHours(0);
|
|
|
- now.setMinutes(0);
|
|
|
- now.setSeconds(0);
|
|
|
- return [moment(now), moment(now.getTime() + (oneDay - 1000))];
|
|
|
- }
|
|
|
-
|
|
|
- if (type === 'week') {
|
|
|
- let day = now.getDay();
|
|
|
- now.setHours(0);
|
|
|
- now.setMinutes(0);
|
|
|
- now.setSeconds(0);
|
|
|
-
|
|
|
- if (day === 0) {
|
|
|
- day = 6;
|
|
|
- } else {
|
|
|
- day -= 1;
|
|
|
- }
|
|
|
-
|
|
|
- const beginTime = now.getTime() - day * oneDay;
|
|
|
-
|
|
|
- return [moment(beginTime), moment(beginTime + (7 * oneDay - 1000))];
|
|
|
- }
|
|
|
-
|
|
|
- if (type === 'month') {
|
|
|
- const year = now.getFullYear();
|
|
|
- const month = now.getMonth();
|
|
|
- const nextDate = moment(now).add(1, 'months');
|
|
|
- const nextYear = nextDate.year();
|
|
|
- const nextMonth = nextDate.month();
|
|
|
-
|
|
|
- return [
|
|
|
- moment(`${year}-${fixedZero(month + 1)}-01 00:00:00`),
|
|
|
- moment(moment(`${nextYear}-${fixedZero(nextMonth + 1)}-01 00:00:00`).valueOf() - 1000),
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- const year = now.getFullYear();
|
|
|
- return [moment(`${year}-01-01 00:00:00`), moment(`${year}-12-31 23:59:59`)];
|
|
|
-}
|
|
|
-
|
|
|
-export function getPlainNode(nodeList, parentPath = '') {
|
|
|
- const arr = [];
|
|
|
- nodeList.forEach(node => {
|
|
|
- const item = node;
|
|
|
- item.path = `${parentPath}/${item.path || ''}`.replace(/\/+/g, '/');
|
|
|
- item.exact = true;
|
|
|
- if (item.children && !item.component) {
|
|
|
- arr.push(...getPlainNode(item.children, item.path));
|
|
|
- } else {
|
|
|
- if (item.children && item.component) {
|
|
|
- item.exact = false;
|
|
|
- }
|
|
|
- arr.push(item);
|
|
|
- }
|
|
|
- });
|
|
|
- return arr;
|
|
|
-}
|
|
|
-
|
|
|
-export function digitUppercase(n) {
|
|
|
- return nzh.toMoney(n);
|
|
|
-}
|
|
|
-
|
|
|
-function getRelation(str1, str2) {
|
|
|
- if (str1 === str2) {
|
|
|
- console.warn('Two path are equal!'); // eslint-disable-line
|
|
|
- }
|
|
|
- const arr1 = str1.split('/');
|
|
|
- const arr2 = str2.split('/');
|
|
|
- if (arr2.every((item, index) => item === arr1[index])) {
|
|
|
- return 1;
|
|
|
- }
|
|
|
- if (arr1.every((item, index) => item === arr2[index])) {
|
|
|
- return 2;
|
|
|
- }
|
|
|
- return 3;
|
|
|
-}
|
|
|
-
|
|
|
-function getRenderArr(routes) {
|
|
|
- let renderArr = [];
|
|
|
- renderArr.push(routes[0]);
|
|
|
- for (let i = 1; i < routes.length; i += 1) {
|
|
|
- // 去重
|
|
|
- renderArr = renderArr.filter(item => getRelation(item, routes[i]) !== 1);
|
|
|
- // 是否包含
|
|
|
- const isAdd = renderArr.every(item => getRelation(item, routes[i]) === 3);
|
|
|
- if (isAdd) {
|
|
|
- renderArr.push(routes[i]);
|
|
|
- }
|
|
|
- }
|
|
|
- return renderArr;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Get router routing configuration
|
|
|
- * { path:{name,...param}}=>Array<{name,path ...param}>
|
|
|
- * @param {string} path
|
|
|
- * @param {routerData} routerData
|
|
|
- */
|
|
|
-export function getRoutes(path, routerData) {
|
|
|
- let routes = Object.keys(routerData).filter(
|
|
|
- routePath => routePath.indexOf(path) === 0 && routePath !== path
|
|
|
- );
|
|
|
- // Replace path to '' eg. path='user' /user/name => name
|
|
|
- routes = routes.map(item => item.replace(path, ''));
|
|
|
- // Get the route to be rendered to remove the deep rendering
|
|
|
- const renderArr = getRenderArr(routes);
|
|
|
- // Conversion and stitching parameters
|
|
|
- const renderRoutes = renderArr.map(item => {
|
|
|
- const exact = !routes.some(route => route !== item && getRelation(route, item) === 1);
|
|
|
- return {
|
|
|
- exact,
|
|
|
- ...routerData[`${path}${item}`],
|
|
|
- key: `${path}${item}`,
|
|
|
- path: `${path}${item}`,
|
|
|
- };
|
|
|
- });
|
|
|
- return renderRoutes;
|
|
|
-}
|
|
|
-
|
|
|
-export function getPageQuery() {
|
|
|
- return parse(window.location.href.split('?')[1]);
|
|
|
-}
|
|
|
-
|
|
|
-export function getQueryPath(path = '', query = {}) {
|
|
|
- const search = stringify(query);
|
|
|
- if (search.length) {
|
|
|
- return `${path}?${search}`;
|
|
|
- }
|
|
|
- return path;
|
|
|
-}
|
|
|
-/* eslint no-useless-escape:0 */
|
|
|
-const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
|
|
|
-
|
|
|
-export function isUrl(path) {
|
|
|
- return reg.test(path);
|
|
|
-}
|
|
|
-
|
|
|
-export function formatWan(val) {
|
|
|
- const v = val * 1;
|
|
|
- if (!v || Number.isNaN(v)) return '';
|
|
|
-
|
|
|
- let result = val;
|
|
|
- if (val > 10000) {
|
|
|
- result = Math.floor(val / 10000);
|
|
|
- result = (
|
|
|
- <span>
|
|
|
- {result}
|
|
|
- <span
|
|
|
- style={{
|
|
|
- position: 'relative',
|
|
|
- top: -2,
|
|
|
- fontSize: 14,
|
|
|
- fontStyle: 'normal',
|
|
|
- marginLeft: 2,
|
|
|
- }}
|
|
|
- >
|
|
|
- 万
|
|
|
- </span>
|
|
|
- </span>
|
|
|
- );
|
|
|
- }
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-// 给官方演示站点用,用于关闭真实开发环境不需要使用的特性
|
|
|
-export function isAntdPro() {
|
|
|
- return window.location.hostname === 'preview.pro.ant.design';
|
|
|
-}
|
|
|
-
|
|
|
-export const importCDN = (url, name) =>
|
|
|
- new Promise(resolve => {
|
|
|
- const dom = document.createElement('script');
|
|
|
- dom.src = url;
|
|
|
- dom.type = 'text/javascript';
|
|
|
- dom.onload = () => {
|
|
|
- resolve(window[name]);
|
|
|
- };
|
|
|
- document.head.appendChild(dom);
|
|
|
- });
|
|
|
+import { MessageEvent, PageMessageEvent } from './event';
|
|
|
|
|
|
export const clearToken = () => {
|
|
|
localStorage.setItem('JWT-TOKEN', '');
|
|
|
@@ -216,9 +20,7 @@ export const getToken = () => {
|
|
|
* <a href="url" download/>
|
|
|
*/
|
|
|
export const downloadFile = (url, fileName, encode = true) => {
|
|
|
- // if (window.InvokeUnityFileOpener) {
|
|
|
- // window.InvokeUnityFileOpener(url);
|
|
|
- // } else {
|
|
|
+
|
|
|
const downloadLink = document.createElement('a');
|
|
|
const body = document.documentElement || document.body;
|
|
|
body.appendChild(downloadLink);
|
|
|
@@ -235,40 +37,6 @@ export const downloadFile = (url, fileName, encode = true) => {
|
|
|
body.removeChild(downloadLink);
|
|
|
// }
|
|
|
};
|
|
|
-window.downloadFile = downloadFile;
|
|
|
-
|
|
|
-/**
|
|
|
- *
|
|
|
- * @param date1
|
|
|
- * @param date2
|
|
|
- * @returns {number}
|
|
|
- * @constructor 日期相减
|
|
|
- */
|
|
|
-export function DateMinus(date1, date2) {
|
|
|
- const sdate = new Date(date1);
|
|
|
- const now = new Date(date2);
|
|
|
- const days = now.getTime() - sdate.getTime();
|
|
|
- const day = parseInt(days / (1000 * 60 * 60 * 24), 10);
|
|
|
- return day;
|
|
|
-}
|
|
|
-
|
|
|
-export function SendMsgToWebGL(type, data) {
|
|
|
- if (window.MsgSender) {
|
|
|
- window.MsgSender(type, data);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-export function ShowUnreadNotification(notice) {
|
|
|
- notification.open({
|
|
|
- message: '通知',
|
|
|
- description: notice.MsgBody,
|
|
|
- icon: <Icon type="warning" style={{ color: '#108ee9' }} />,
|
|
|
- placement: 'bottomRight',
|
|
|
- onClose: () => {
|
|
|
- return SetNotificationRead({ ID: notice.ID });
|
|
|
- },
|
|
|
- });
|
|
|
-}
|
|
|
|
|
|
export function IsImageFile(fileName) {
|
|
|
return (
|
|
|
@@ -321,16 +89,6 @@ export function GetFileType(url) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export function getAuthoriter(projectId) {
|
|
|
- return request(`/user/res/${projectId}`).then(res => {
|
|
|
- if (res && res.data) {
|
|
|
- sessionStorage['authority'] = JSON.stringify(res.data);
|
|
|
- localStorage['authority'] = JSON.stringify(res.data);
|
|
|
- }
|
|
|
- return res;
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
export function getUser(params) {
|
|
|
let arr = [];
|
|
|
if (!params) {
|
|
|
@@ -343,6 +101,7 @@ export function getUser(params) {
|
|
|
.join(','));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
export const UnityAction = {
|
|
|
event: {},
|
|
|
on(type, callback) {
|
|
|
@@ -385,100 +144,26 @@ export const UnityAction = {
|
|
|
}
|
|
|
},
|
|
|
};
|
|
|
-if (window.vuplex) {
|
|
|
- window.vuplex.addEventListener('message', e => {
|
|
|
- console.log('============================getMessageForUnity============================');
|
|
|
- const data = JSON.parse(e.data);
|
|
|
- console.log(data);
|
|
|
- UnityAction.emit(data.type, data.message);
|
|
|
-
|
|
|
- // 将消息广播给子页面
|
|
|
- // let iframeDom = document.getElementsByClassName('iframe');
|
|
|
- // for (let i = 0; i < iframeDom.length; i++) {
|
|
|
- // const item = iframeDom[i];
|
|
|
- // item.contentWindow.postMessage(data.type, data.message);
|
|
|
- // }
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-var longClick = false,
|
|
|
- timer = null,
|
|
|
- touches = null;
|
|
|
-export const LongPress = {
|
|
|
- on(ele, callback) {
|
|
|
- ele.addEventListener('touchstart', function(e) {
|
|
|
- longClick = false;
|
|
|
- touches = {
|
|
|
- clientX: e.touches[0].clientX,
|
|
|
- clientY: e.touches[0].clientY,
|
|
|
- screenX: e.touches[0].screenX,
|
|
|
- screenY: e.touches[0].screenY,
|
|
|
- };
|
|
|
|
|
|
- console.log(e);
|
|
|
- ele.dispatchEvent(
|
|
|
- new MouseEvent('mousedown', {
|
|
|
- view: window,
|
|
|
- bubbles: true,
|
|
|
- cancelable: true,
|
|
|
- })
|
|
|
- );
|
|
|
- timer = setTimeout(function() {
|
|
|
- longClick = true;
|
|
|
- e.preventDefault();
|
|
|
- }, 1000);
|
|
|
- });
|
|
|
- ele.addEventListener('touchmove', function(e) {
|
|
|
- clearTimeout(timer);
|
|
|
- longClick = false;
|
|
|
- });
|
|
|
- ele.addEventListener('touchend', function(e) {
|
|
|
- clearTimeout(timer);
|
|
|
- if (longClick) {
|
|
|
- callback && callback(e, touches);
|
|
|
- }
|
|
|
- return false;
|
|
|
- });
|
|
|
- },
|
|
|
- off(ele) {
|
|
|
- var getEventListeners = window.getEventListeners;
|
|
|
- if (getEventListeners) {
|
|
|
- getEventListeners(ele).touchstart.forEach(fn => el.removeEventListener(fn));
|
|
|
- getEventListeners(ele).touchmove.forEach(fn => el.removeEventListener(fn));
|
|
|
- getEventListeners(ele).touchend.forEach(fn => el.removeEventListener(fn));
|
|
|
- }
|
|
|
- },
|
|
|
-};
|
|
|
-// export const EventBus = {
|
|
|
-// event: {},
|
|
|
-// on(type, callback) {
|
|
|
-// if (!EventBus.event[type]) {
|
|
|
-// EventBus.event[type] = [];
|
|
|
-// }
|
|
|
-// EventBus.event[type].push(callback);
|
|
|
-// },
|
|
|
-// off(type, callback) {
|
|
|
-// if (callback) {
|
|
|
-// let index = EventBus.event[type].indexOf(callback);
|
|
|
-// if (index == -1) return;
|
|
|
-// EventBus.event[type].splice(index, 1);
|
|
|
-// } else {
|
|
|
-// EventBus.event[type] = [];
|
|
|
-// }
|
|
|
-// window[type] = null;
|
|
|
-// },
|
|
|
-// emit(type, e) {
|
|
|
-// if (!EventBus.event[type]) return;
|
|
|
-// console.log('emit====== type:', type, '====== event:', e);
|
|
|
-// EventBus.event[type].forEach(item => {
|
|
|
-// item && item(e);
|
|
|
-// });
|
|
|
-// },
|
|
|
-// };
|
|
|
-
|
|
|
-export const EventBus = new MessageEvent();
|
|
|
+// if (window.vuplex) {
|
|
|
+// window.vuplex.addEventListener('message', e => {
|
|
|
+// console.log('============================getMessageForUnity============================');
|
|
|
+// const data = JSON.parse(e.data);
|
|
|
+// console.log(data);
|
|
|
+// UnityAction.emit(data.type, data.message);
|
|
|
+
|
|
|
+// // 将消息广播给子页面
|
|
|
+// // let iframeDom = document.getElementsByClassName('iframe');
|
|
|
+// // for (let i = 0; i < iframeDom.length; i++) {
|
|
|
+// // const item = iframeDom[i];
|
|
|
+// // item.contentWindow.postMessage(data.type, data.message);
|
|
|
+// // }
|
|
|
+// });
|
|
|
+// }
|
|
|
+
|
|
|
+// export const EventBus = new MessageEvent();
|
|
|
// export const UnityAction = new UnityMessageEvent();
|
|
|
-export const PageAction = new PageMessageEvent();
|
|
|
+// export const PageAction = new PageMessageEvent();
|
|
|
|
|
|
export function getGlobalData(key) {
|
|
|
let data;
|
|
|
@@ -490,6 +175,7 @@ export function getGlobalData(key) {
|
|
|
|
|
|
return key ? data[key] : data;
|
|
|
}
|
|
|
+
|
|
|
export function setGlobalData(key, value) {
|
|
|
let data;
|
|
|
if (!key) return;
|
|
|
@@ -501,6 +187,7 @@ export function setGlobalData(key, value) {
|
|
|
data[key] = value;
|
|
|
localStorage.GLOBAL_DATA = JSON.stringify(data);
|
|
|
}
|
|
|
+
|
|
|
// 根据token缓存数据
|
|
|
export function saveData(key, data) {
|
|
|
let token = GetTokenFromUrl() || getToken();
|