// import { getToken } from '@/utils/authority'; import pathRegexp from 'path-to-regexp'; import { parse } from 'querystring'; import { uploadFile } from './service' /* eslint no-useless-escape:0 import/prefer-default-export:0 */ const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/; export const isUrl = (path) => reg.test(path); export const isAntDesignPro = () => { if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') { return true; } return window.location.hostname === 'preview.pro.ant.design'; }; // 给官方演示站点用,用于关闭真实开发环境不需要使用的特性 export const customRequest = (params) => { const { file, onSuccess, onError } = params; const formData = new FormData(); formData.append('file', file); uploadFile(formData) .then((ret) => { onSuccess(ret.data); }) .catch((ret) => { onError(); }); }; export const isAntDesignProOrDev = () => { const { NODE_ENV } = process.env; if (NODE_ENV === 'development') { return true; } return isAntDesignPro(); }; export const getPageQuery = () => parse(window.location.href.split('?')[1]); /** * props.route.routes * @param router [{}] * @param pathname string */ /** * 导出 * @param {*} params * @param {*} name * @param {*} url * @returns */ export const exportExcell = (name, params, url) => { fetch(BASE_URL + url, { method: 'post', body: JSON.stringify({ ...params, }), headers: { Authorization: getToken(), 'ConTent-Type': 'application/json;charset=UTF-8', }, responseType: 'blob', }) .then((res) => res.blob()) .then((res) => { const link = document.createElement('a'); link.style.display = 'none'; link.href = URL.createObjectURL(res); link.download = name; document.body.appendChild(link); link.click(); // 释放的 URL 对象以及移除 a 标签 URL.revokeObjectURL(link.href); document.body.removeChild(link); }); }; //下载导入末班 export const downLoad = (url, name) => { fetch(BASE_URL + url, { method: 'get', responseType: 'blob', headers: { Authorization: getToken(), 'ConTent-Type': 'application/json;charset=UTF-8', }, }) .then((res) => res.blob()) .then((res) => { const link = document.createElement('a'); link.style.display = 'none'; link.href = URL.createObjectURL(res); link.download = name; document.body.appendChild(link); link.click(); // 释放的 URL 对象以及移除 a 标签 URL.revokeObjectURL(link.href); document.body.removeChild(link); }); }; export const getAuthorityFromRouter = (router = [], pathname) => { const authority = router.find( ({ routes, path = '/' }) => (path && pathRegexp(path).exec(pathname)) || (routes && getAuthorityFromRouter(routes, pathname)), ); if (authority) return authority; return undefined; }; export const getRouteAuthority = (path, routeData) => { let authorities; routeData.forEach((route) => { // match prefix if (pathRegexp(`${route.path}/(.*)`).test(`${path}/`)) { if (route.authority) { authorities = route.authority; } // exact match if (route.path === path) { authorities = route.authority || authorities; } // get children authority recursively if (route.routes) { authorities = getRouteAuthority(path, route.routes) || authorities; } } }); return authorities; }; // export const upload2oss = (file) => { // let OSS = require('ali-oss'); // let client = new OSS({ // region: 'oss-cn-shanghai', // //云账号AccessKey有所有API访问权限,建议遵循阿里云安全最佳实践,创建并使用STS方式来进行API访问 // accessKeyId: 'tycz5P0YNUdHAF8M', // accessKeySecret: 'Xde4xijVNbVhDDatyyoVrUVhe7nIdv', // // stsToken: '', // bucket: 'shuju-jtzx', // }); // return new Promise((resolve, reject) => { // const date = new Date(); // const year = date.getFullYear(); // const month = date.getMonth() + 1; // const day = date.getDate(); // let filename = ''; // if (file.name.split('.').pop() === 'apk') { // filename = 'apk/' + uuidv4() + '.apk'; // } else { // filename = // 'images/' + // year + // '/' + // month + // '/' + // day + // '/' + // uuidv4() + // '.' + // file.name.split('.').pop(); // } // client // .put(filename, file) // .then((res) => { // // resolve(res); // }) // .catch((e) => { // reject(e); // }); // }); // }; export const roleMenuIds = () => { return [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, ]; }; // export const upload2ossVideo = (file) => { // let OSS = require('ali-oss'); // let client = new OSS({ // region: 'oss-cn-shanghai', // //云账号AccessKey有所有API访问权限,建议遵循阿里云安全最佳实践,创建并使用STS方式来进行API访问 // accessKeyId: 'tycz5P0YNUdHAF8M', // accessKeySecret: 'Xde4xijVNbVhDDatyyoVrUVhe7nIdv', // // stsToken: '', // bucket: 'shuju-jtzx', // }); // return new Promise((resolve, reject) => { // const date = new Date(); // const year = date.getFullYear(); // const month = date.getMonth() + 1; // const day = date.getDate(); // let filename = ''; // if (file.name.split('.').pop() === 'apk') { // filename = 'apk/' + uuidv4() + '.apk'; // } else { // filename = // 'images/' + // year + // '/' + // month + // '/' + // day + // '/' + // uuidv4() + // '.' + // file.name.split('.').pop(); // } // client // .multipartUpload( // filename, // file, // { // progress: function (p, checkpoint) { // // 断点记录点。浏览器重启后无法直接继续上传,您需要手动触发上传操作。 // // tempCheckpoint = checkpoint; // ); // getDvaApp()._store.dispatch({ // type: 'courseSection/SetVideoProgress', // payload: { value: Math.floor(p * 100) }, // }); // }, // }, // { // callback: (e) => { // // }, // }, // ) // .then((res) => { // res.name = 'http://shuju-jtzx.oss-cn-shanghai.aliyuncs.com/' + res.name; // // resolve(res); // }) // .catch((e) => { // reject(e); // }); // }); // };