1、設(shè)置緩存
// 設(shè)置緩存
? ? Set_Storage(data_id: any, data: any) {
? ? ? ? if (data_id) {
? ? ? ? ? ? if (data >= 0 || data) {
? ? ? ? ? ? ? ? const lsobj: any = window.sessionStorage;
? ? ? ? ? ? ? ? const datajson: any = JSON.stringify(data);
? ? ? ? ? ? ? ? lsobj.setItem(data_id, datajson);
? ? ? ? ? ? }
? ? ? ? }
? ? }
2、獲取緩存
Get_Storage(data_id: any): any {
? ? ? if (data_id) {
? ? ? ? ? ? let data: any = null;
? ? ? ? ? ? const lsdata = window.sessionStorage;
? ? ? ? ? ? let datajson: any = lsdata.getItem(data_id);
? ? ? ? ? ? datajson = JSON.parse(datajson);
? ? ? ? ? ? data = datajson;
? ? ? ? ? ? return data;
? ? ? }
? }
3、// 獲取url中含"?"符后的字串
? GetRequest(name: any): any {
? ? ? const _url = window.location.href;
? ? ? const url = _url.slice(_url.indexOf('?'));
? ? ? const theRequest: any = new Object();
? ? ? if (url.indexOf('?') !== -1) {
? ? ? ? ? let str: any = url.substr(1);
? ? ? ? ? str = str.split('&');
? ? ? ? ? for (let i = 0; i < str.length; i ++) {
? ? ? ? ? ? theRequest[str[i].split('=')[0]] = decodeURI(str[i].split('=')[1]);
? ? ? ? ? }
? ? ? }
? ? ? return theRequest[name];
? ? }
4、 // 獲取當(dāng)前時間,格式Y(jié)YYY-MM-DD
? getNowFormatDate() {
? ? ? const date = new Date();
? ? ? const seperator1 = '-';
? ? ? const year = date.getFullYear();
? ? ? let month: any = date.getMonth() + 1;
? ? ? let strDate: any = date.getDate();
? ? ? if (month >= 1 && month <= 9) {
? ? ? ? ? month = '0' + month;
? ? ? }
? ? ? if (strDate >= 0 && strDate <= 9) {
? ? ? ? ? strDate = '0' + strDate;
? ? ? }
? ? ? const currentdate = year + seperator1 + month + seperator1 + strDate;
? ? ? return currentdate;
? }
5、// 獲取url目錄
? getRealPath() {
? ? ? const obj = window.location;
? ? ? const contextPath = obj.pathname.split('/')[1] ? '/' + obj.pathname.split('/')[1] : '';
? ? ? const basePath = obj.protocol + '//' + obj.host + contextPath;
? ? ? return basePath;
? ? }
6、 /* 校驗各種輸入規(guī)則
? ? 參數(shù)說明:
? ? checkObj:需校驗的數(shù)據(jù)
? ? checkFlag:校驗的規(guī)則類型
? ? */
? ? checkData(checkObj: any , checkFlag: any ) {
? ? ? ? if (checkObj) {
? ? ? ? ? ? let checkData: any = checkObj;
? ? ? ? ? ? checkData = checkData.replace(' ', '');
? ? ? ? ? ? checkData = checkData.replace('¥', '').replace('$', '');
? ? ? ? ? ? let exreg: any;
? ? ? ? ? ? switch (checkFlag) {
? ? ? ? ? ? ? ? case 1 :
? ? ? ? ? ? ? ? exreg = /^[1-9][0-9]*\.{0,1}(\d{1,2})?$/; // 正數(shù)(正數(shù)或浮點數(shù),最多兩位小數(shù))
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 2 :
? ? ? ? ? ? ? ? exreg =? /^[1-9][0-9]*\.{0,1}(\d{1,2})?$/; // 正數(shù)(正數(shù)或浮點數(shù),最多兩位小數(shù))
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? if ( checkFlag === 1) {
? ? ? ? ? ? ? ? if (!exreg.test(checkData)) {
? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? if ( Number(checkData) > 3000) {
? ? ? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? } else if ( checkFlag === 2 ) {
? ? ? ? ? ? ? ? if (!exreg.test(checkData)) {
? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? return true;
? ? ? ? }
? ? }
7、js獲取元素及元素屬性值(兼容ie)
getStyleAttr(obj,attr){
? ? ? if(window.getComputedStyle){
? ? ? ? return window.getComputedStyle(obj)[attr];
? ? ? }else{
? ? ? ? return obj.currentStyle[attr];
? ? ? }
? ? }