| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- export function inArray(arr,val){
- for(let i=0;i<arr.length;i++){
- if(arr[i]==val){
- return true;
- }
- }
- return false;
- }
- export function formatDate(date){
- if(typeof date=='string'){
- return date;
- }
- let year = date.getFullYear();
- let month = date.getMonth() + 1;
- if(month<10){
- month='0'+month;
- }
- let day = date.getDate();
- if(day<10){
- day='0'+day;
- }
- return year+'-'+month+'-'+day;
- }
- export function formatDateTime(date){
- if(typeof date=='string'){
- return date;
- }
- let year = date.getFullYear();
- let month = date.getMonth() + 1;
- if(month<10){
- month='0'+month;
- }
- let day = date.getDate();
- if(day<10){
- day='0'+day;
- }
- let hour=date.getHours();
- if(hour<10){
- hour='0'+hour;
- }
- let minis=date.getMinutes();
- if(minis<10){
- minis='0'+minis;
- }
- let seconds=date.getSeconds();
- if(seconds<10){
- seconds='0'+seconds;
- }
- return year+'-'+month+'-'+day+' '+hour+':'+minis+':'+seconds;
- }
- export function formatTime(date){
- let hour=date.getHours();
- if(hour<10){
- hour='0'+hour;
- }
- let minis=date.getMinutes();
- if(minis<10){
- minis='0'+minis;
- }
- let seconds=date.getSeconds();
- if(seconds<10){
- seconds='0'+seconds;
- }
- return hour+':'+minis+':'+seconds;
- }
- export function formatDuration(seconds,showSeconds=true) {
- const days = Math.floor(seconds / (24 * 60 * 60));
- const hours = Math.floor((seconds % (24 * 60 * 60)) / (60 * 60));
- const minutes = Math.floor((seconds % (60 * 60)) / 60);
- const remainingSeconds = seconds % 60;
- let formattedDuration = "";
- if (days > 0) {
- formattedDuration += `${days}天 `;
- }
- if (hours > 0) {
- formattedDuration += `${hours}小时 `;
- }
- if (minutes > 0) {
- formattedDuration += `${minutes}分 `;
- }
- if (remainingSeconds > 0 && showSeconds) {
- formattedDuration += `${remainingSeconds}秒`;
- }
- if(!formattedDuration){
- return remainingSeconds+'秒';
- }
- return formattedDuration.trim();
- }
- export function rand(n,m){
- return Math.floor(Math.random() * (m - n + 1)) + n;
- }
- export function parseNumber(number){
- if(parseInt(number, 10) != number){
- return Number(parseFloat(number).toFixed(2));
- }
- return parseInt(number);
- }
- //用递归的方式深拷贝对象
- export function copyObj(obj){
- let r=JSON.parse(JSON.stringify(obj));
- for(let i in obj){
- if(typeof obj[i]=='function'){
- r[i]=obj[i];
- }
- if(typeof obj[i]=='object'){
- r[i]=copyObj(obj[i]);
- }
- }
- return r;
- }
- export function getUniqid() {
- var currentDate = new Date();
- var timestamp = currentDate.getTime().toString(36); // 使用36进制
- var unique = (currentDate.getUTCMilliseconds() + Math.random()).toString(36).slice(2, 7); // 随机数
- return (timestamp + unique).replace('.','');
- }
- export function getfileImage(filename){
- let $domain=location.origin;
- let start = filename.lastIndexOf('.');
- let $ext= start>-1?filename.slice(start + 1):'';
- if (inArray(['jpg', 'png', 'bmp', 'jpeg', 'gif'],$ext)) {
- return $domain+'/assets/img/fileicon/image.png';
- }else if(inArray(['doc', 'docx'],$ext)) {
- return $domain+'/assets/img/fileicon/doc.png';
- }else if(inArray(['ppt', 'pptx'],$ext)) {
- return $domain+'/assets/img/fileicon/ppt.png';
- }else if(inArray(['xls', 'xlsx'],$ext)) {
- return $domain+'/assets/img/fileicon/xls.png';
- }else if(inArray(['mp3','wav','wma','ogg'],$ext)) {
- return $domain+'/assets/img/fileicon/audio.png';
- }else if(inArray(['mp4', 'avi', 'rmvb','swf', 'flv','rm', 'ram', 'mpeg', 'mpg', 'wmv', 'mov'],$ext)) {
- return $domain+'/assets/img/fileicon/video.png';
- }else if(inArray(['zip', 'rar', '7z', 'gz', 'tar'],$ext)) {
- return $domain+'/assets/img/fileicon/zip.png';
- }else if(inArray(['apk','tiff','exe','html','pdf','psd','visio','svg','txt','xml'],$ext)){
- return $domain+'/assets/img/fileicon/'+$ext+'.png';
- }else{
- return $domain+'/assets/img/fileicon/wz.png';
- }
- }
- export function TreeIdtoString(tree) {
- for (let i = 0; i < tree.length; i++) {
- if (tree[i].childlist && tree[i].childlist.length > 0) {
- tree[i].childlist = TreeIdtoString(tree[i].childlist);
- }
- if (tree[i].id) {
- tree[i].id = tree[i].id.toString();
- }
- }
- return tree;
- }
|