分解tool.js

This commit is contained in:
sakuya 2021-06-28 19:15:57 +08:00
parent fa056e547c
commit 48880c2f67
1 changed files with 90 additions and 79 deletions

View File

@ -1,6 +1,14 @@
const tool = {
/*
* @Descripttion: 工具集
* @version: 1.0
* @LastEditors: sakuya
* @LastEditTime: 2021年6月28日19:13:13
*/
const tool = {}
/* localStorage */
data: {
tool.data = {
set(table, settings) {
var _set = JSON.stringify(settings)
return localStorage.setItem(table, _set);
@ -20,9 +28,10 @@ const tool = {
clear() {
return localStorage.clear();
}
},
}
/* Fullscreen */
screen(element){
tool.screen = function (element) {
var isFull = !!(document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement || document.fullscreenElement);
if(isFull){
if(document.exitFullscreen) {
@ -45,13 +54,15 @@ const tool = {
element.webkitRequestFullscreen();
}
}
},
}
/* 复制对象 */
objCopy(obj){
tool.objCopy = function (obj) {
return JSON.parse(JSON.stringify(obj));
},
}
/* 日期格式化 */
dateFormat(date, fmt='yyyy-MM-dd'){
tool.dateFormat = function (date, fmt='yyyy-MM-dd') {
date = new Date(date)
var o = {
"M+" : date.getMonth()+1, //月份
@ -71,9 +82,10 @@ const tool = {
}
}
return fmt;
},
}
/* 千分符 */
groupSeparator(num){
tool.groupSeparator = function (num) {
num = num + '';
if(!num.includes('.')){
num += '.'
@ -82,6 +94,5 @@ const tool = {
return $1 + ',';
}).replace(/\.$/, '');
}
}
export default tool