perf[utils]: optimizate variable name

This commit is contained in:
Pan 2019-02-19 10:24:22 +08:00
parent 070a3343f2
commit fe950801c9
5 changed files with 23 additions and 25 deletions

View File

@ -1,8 +0,0 @@
/**
* Created by jiachenpan on 17/3/8.
*/
export default function createUniqueString() {
const timestamp = +new Date() + ''
const randomNum = parseInt((1 + Math.random()) * 65536) + ''
return (+(randomNum + timestamp)).toString(32)
}

View File

@ -290,3 +290,9 @@ export function deepClone(source) {
export function uniqueArr(arr) { export function uniqueArr(arr) {
return Array.from(new Set(arr)) return Array.from(new Set(arr))
} }
export function createUniqueString() {
const timestamp = +new Date() + ''
const randomNum = parseInt((1 + Math.random()) * 65536) + ''
return (+(randomNum + timestamp)).toString(32)
}

View File

@ -2,35 +2,35 @@
* Created by jiachenpan on 16/11/18. * Created by jiachenpan on 16/11/18.
*/ */
export function isvalidUsername(str) {
const valid_map = ['admin', 'editor']
return valid_map.indexOf(str.trim()) >= 0
}
export function isExternal(path) { export function isExternal(path) {
return /^(https?:|mailto:|tel:)/.test(path) return /^(https?:|mailto:|tel:)/.test(path)
} }
export function validUsername(str) {
const valid_map = ['admin', 'editor']
return valid_map.indexOf(str.trim()) >= 0
}
/* 合法uri*/ /* 合法uri*/
export function validateURL(textval) { export function validURL(url) {
const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/ const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
return urlregex.test(textval) return reg.test(url)
} }
/* 小写字母*/ /* 小写字母*/
export function validateLowerCase(str) { export function validLowerCase(str) {
const reg = /^[a-z]+$/ const reg = /^[a-z]+$/
return reg.test(str) return reg.test(str)
} }
/* 大写字母*/ /* 大写字母*/
export function validateUpperCase(str) { export function validUpperCase(str) {
const reg = /^[A-Z]+$/ const reg = /^[A-Z]+$/
return reg.test(str) return reg.test(str)
} }
/* 大小写字母*/ /* 大小写字母*/
export function validateAlphabets(str) { export function validAlphabets(str) {
const reg = /^[A-Za-z]+$/ const reg = /^[A-Za-z]+$/
return reg.test(str) return reg.test(str)
} }
@ -40,7 +40,7 @@ export function validateAlphabets(str) {
* @param email * @param email
* @returns {boolean} * @returns {boolean}
*/ */
export function validateEmail(email) { export function validEmail(email) {
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return re.test(email) return re.test(email)
} }

View File

@ -78,7 +78,7 @@ import Tinymce from '@/components/Tinymce'
import Upload from '@/components/Upload/singleImage3' import Upload from '@/components/Upload/singleImage3'
import MDinput from '@/components/MDinput' import MDinput from '@/components/MDinput'
import Sticky from '@/components/Sticky' // header import Sticky from '@/components/Sticky' // header
import { validateURL } from '@/utils/validate' import { validURL } from '@/utils/validate'
import { fetchArticle } from '@/api/article' import { fetchArticle } from '@/api/article'
import { userSearch } from '@/api/remoteSearch' import { userSearch } from '@/api/remoteSearch'
import Warning from './Warning' import Warning from './Warning'
@ -121,7 +121,7 @@ export default {
} }
const validateSourceUri = (rule, value, callback) => { const validateSourceUri = (rule, value, callback) => {
if (value) { if (value) {
if (validateURL(value)) { if (validURL(value)) {
callback() callback()
} else { } else {
this.$message({ this.$message({

View File

@ -71,7 +71,7 @@
</template> </template>
<script> <script>
import { isvalidUsername } from '@/utils/validate' import { validUsername } from '@/utils/validate'
import LangSelect from '@/components/LangSelect' import LangSelect from '@/components/LangSelect'
import SocialSign from './socialsignin' import SocialSign from './socialsignin'
@ -80,7 +80,7 @@ export default {
components: { LangSelect, SocialSign }, components: { LangSelect, SocialSign },
data() { data() {
const validateUsername = (rule, value, callback) => { const validateUsername = (rule, value, callback) => {
if (!isvalidUsername(value)) { if (!validUsername(value)) {
callback(new Error('Please enter the correct user name')) callback(new Error('Please enter the correct user name'))
} else { } else {
callback() callback()