This commit is contained in:
fengchenchen
2023-08-14 17:10:11 +08:00
commit 37f6ec895d
1145 changed files with 437754 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
import Vue from 'vue'
/**
* 省市区
*/
export default class Area {
/**
* 构造器
* @param pcaa
*/
constructor (pcaa) {
if (!pcaa) {
pcaa = Vue.prototype.$Jpcaa
}
const arr = []
const province = pcaa['86']
Object.keys(province).map(key => {
arr.push({ id: key, text: province[key], pid: '86', index: 1 })
const city = pcaa[key]
Object.keys(city).map(key2 => {
arr.push({ id: key2, text: city[key2], pid: key, index: 2 })
const qu = pcaa[key2]
if (qu) {
Object.keys(qu).map(key3 => {
arr.push({ id: key3, text: qu[key3], pid: key2, index: 3 })
})
}
})
})
this.all = arr
}
get pca () {
return this.all
}
getCode (text) {
if (!text || text.length === 0) {
return ''
}
for (const item of this.all) {
if (item.text === text) {
return item.id
}
}
}
getText (code) {
if (!code || code.length === 0) {
return ''
}
const arr = []
this.getAreaBycode(code, arr, 3)
return arr.join('/')
}
getRealCode (code) {
const arr = []
this.getPcode(code, arr, 3)
return arr
}
getPcode (id, arr, index) {
for (const item of this.all) {
if (item.id === id && item.index === index) {
arr.unshift(id)
if (item.pid !== '86') {
this.getPcode(item.pid, arr, --index)
}
}
}
}
getAreaBycode (code, arr, index) {
for (const item of this.all) {
if (item.id === code && item.index === index) {
arr.unshift(item.text)
if (item.pid !== '86') {
this.getAreaBycode(item.pid, arr, --index)
}
}
}
}
}
+46
View File
@@ -0,0 +1,46 @@
/**
* 获取字符串的长度ascii长度为1 中文长度为2
* @param str
* @returns {number}
*/
export const getStrFullLength = (str = '') =>
str.split('').reduce((pre, cur) => {
const charCode = cur.charCodeAt(0)
if (charCode >= 0 && charCode <= 128) {
return pre + 1
}
return pre + 2
}, 0)
/**
* 给定一个字符串和一个长度,将此字符串按指定长度截取
* @param str
* @param maxLength
* @returns {string}
*/
export const cutStrByFullLength = (str = '', maxLength) => {
let showLength = 0
return str.split('').reduce((pre, cur) => {
const charCode = cur.charCodeAt(0)
if (charCode >= 0 && charCode <= 128) {
showLength += 1
} else {
showLength += 2
}
if (showLength <= maxLength) {
return pre + cur
}
return pre
}, '')
}
// 下划线转换驼峰
export function underLinetoHump (name) {
return name.replace(/_(\w)/g, function (all, letter) {
return letter.toUpperCase()
})
}
// 驼峰转换下划线
export function humptoUnderLine (name) {
return name.replace(/([A-Z])/g, '_$1').toLowerCase()
}
+12
View File
@@ -0,0 +1,12 @@
/**
* components util
*/
/**
* 清理空值,对象
* @param children
* @returns {*[]}
*/
export function filterEmpty (children = []) {
return children.filter(c => c.tag || (c.text && c.text.trim() !== ''))
}