123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import useMemberStores from '@/stores/member'
- import { ElMessage } from 'element-plus'
- export function getToken(): null | string {
- return useMemberStores().token
- }
- export function debounce(fn: (args?: any) => any, delay: number = 300) {
- let timer: null | number = null
- return function (...args: any) {
- if (timer != null) {
- clearTimeout(timer)
- timer = null
- }
- timer = setTimeout(() => {
- fn.call(this, ...args)
- }, delay);
- }
- }
- export function isUrl(str: string): boolean {
- return str.indexOf('http://') != -1 || str.indexOf('https://') != -1
- }
- export function img(path: string): string {
- const runtimeConfig = useRuntimeConfig()
- return isUrl(path) ? path : `${runtimeConfig.public.VITE_IMG_DOMAIN || location.origin}/${path}`
- }
- export function moneyFormat(money: string): string {
- return isNaN(parseFloat(money)) ? money : parseFloat(money).toFixed(2)
- }
- export function deepClone(obj: object) {
-
- if ([null, undefined, NaN, false].includes(obj)) return obj
- if (typeof obj !== 'object' && typeof obj !== 'function') {
-
- return obj
- }
- const o = isArray(obj) ? [] : {}
- for (const i in obj) {
- if (obj.hasOwnProperty(i)) {
- o[i] = typeof obj[i] === 'object' ? deepClone(obj[i]) : obj[i]
- }
- }
- return o
- }
- const isArray = (value: any) => {
- if (typeof Array.isArray === 'function') {
- return Array.isArray(value)
- }
- return Object.prototype.toString.call(value) === '[object Array]'
- }
- export function copy(value, callback) {
- var oInput = document.createElement('input');
- oInput.value = value;
- oInput.setAttribute("readonly", "readonly");
- document.body.appendChild(oInput);
- oInput.select();
- document.execCommand("Copy");
- oInput.className = 'oInput';
- oInput.style.display = 'none';
- document.body.removeChild(oInput);
- ElMessage({
- message: '复制成功',
- type: 'success',
- })
- typeof callback == 'function' && callback();
- }
- export function filterSpecial(event:any){
- event.target.value = event.target.value.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g, '')
- event.target.value = event.target.value.replace(/[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘’,。、]/g,'')
- }
|