首先在ui-utils目錄下建立三個js檔案:
foundation.js 放一些常用的基礎方法
regexp.js 放正則驗證
index.js 匯入匯出檔案
/**
* 將unix時間戳轉換為指定格式
* @param unix 時間戳【秒】
* @param format 轉換格式
* @returns
*/export function unixtodate(unix, format)
if (/(y+)/.test(_format)) _format = _format.replace(regexp.$1, (d.getfullyear() + '').substr(4 - regexp.$1.length))
for (const k in o) if (new regexp('(' + k + ')').test(_format)) _format = _format.replace(regexp.$1, (regexp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
return _format
}/**
* 將時間轉unix時間戳
* @param date
* @returns 【秒】
*/export function datetounix(date)
/** * 對乙個物件進行深拷貝
* @param object
* @returns
*/export function deepclone(object)
if (typeof object !== 'object') else if (window.json) else
}} return newobj
}/**
* 貨幣格式化
* @param price
* @returns
*/export function formatprice(price) )+(?!\d))/g, ',')
}/**
* 手機號隱私保護
* 隱藏中間四位數字
* @param mobile
* @returns
*/export function secrecymobile(mobile) /.test(mobile))
return mobile.replace(/(\d)(\d)(\d)/, '$1****$3')
}/**
* 隨機生成指定長度的字串
* @param length
* @returns
*/export function randomstring(length = 32)
return _string
}/**
* 計算當前時間到第二天0點的倒計時[秒]
* @returns
*/export function thenextdaytime()
/** * 計算傳秒數的倒計時【天、時、分、秒】
* @param seconds
* @returns }
*/export function counttimedown(seconds)
return
}
// 手機號
export const mobile = /^0?(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])[0-9]$/
// 電子郵箱
export const email = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
// 密碼【6-20位 包括特殊字元】
export const password = /^[a-za-z0-9!#$%^&*.~,]$/
// 正整數【不包含0】
export const integer = /^[1-9]\d*$/
// 正整數【包含0】
export const positiveinteger = /^[0-9]\d*$/
// 金錢
export const money = /(^[1-9]([0-9]+)?(\.[0-9])?$)|(^(0)$)|(^[0-9]\.[0-9]([0-9])?$)/
// 納稅識別號
export const tinumber = /(^[a-za-z0-9]$)|(^[a-za-z0-9]$)|(^[a-za-z0-9]$)/
// 身份證
export const idcard = /^[1-9]\d((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d$|^[1-9]\d[1-9]\d((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d([0-9]|x)$/
// 賬戶名稱【漢字、字母、數字、「-」、「_」的組合】以其開頭並且匹配乙個或任意多個
// 固話
export const tel = /0\d-\d/
匯入foundation與regexp封裝方法
import * as foundation from './foundation'
import * as regexp from './regexp'
匯出
export
引入
import from '@/ui-utils'
在專案中使用 foundation
/** 開始倒計時 */
startcountdown() = this;
if (time <= 0) );
return false
}time -= 1;
const timetext = foundation.counttimedown(time);
this.$set(this, 'times', foundation.counttimedown(time));
this.$set(this, 'time', time)
}, 1000)
},
引入
import from '@/ui-utils'
在專案中使用regexp
if (!regexp.integer.test(_value))
if (!regexp.mobile.test(value)) else
Vue電商專案學習總結Day2
token 將登入成功之後的token 儲存到客戶端的sessionstorage中 專案中除了登入之外的其他api介面,必須在登入之後才能訪問 token只應在 開啟期間生效,所以儲存在sessionstorage中 路由導航守衛router.beforeeach to,from,next git...
電商推薦系統專案工作總結
1 資料集中是否存在缺失值,處理缺失值。處理資料集中缺失值的策略大概分為刪除,補齊和忽略三類。組刪除 將含有缺失值的屬性特徵刪除 電商推薦中一般不採取此方法,具體看業務場景 忽略 補齊處理只是將未知值補以我們的主觀估計值,不一定完全符合客觀事實,在對不完備資訊進行補齊處理的同時,我們或多或少地改變了...
開課吧Vue電商專案實戰 一 登入認證
安裝cube ui vue add cube ui配置router 需要驗證時新增meta標籤,確認哪個路由需要受保護 import vue from vue import router from vue router import home from views home.vue import l...