Skip to content

Commit 070a334

Browse files
committed
perf[utils]: optimize code
1 parent 48e47e8 commit 070a334

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

src/utils/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,3 @@ export function deepClone(source) {
290290
export function uniqueArr(arr) {
291291
return Array.from(new Set(arr))
292292
}
293-
294-
export function isExternal(path) {
295-
return /^(https?:|mailto:|tel:)/.test(path)
296-
}

src/utils/validate.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export function isvalidUsername(str) {
77
return valid_map.indexOf(str.trim()) >= 0
88
}
99

10+
export function isExternal(path) {
11+
return /^(https?:|mailto:|tel:)/.test(path)
12+
}
13+
1014
/* 合法uri*/
1115
export function validateURL(textval) {
1216
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.,?'\\+&%$#=~_-]+))*$/

src/views/layout/components/Sidebar/Link.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</template>
88

99
<script>
10-
import { isExternal } from '@/utils'
10+
import { isExternal } from '@/utils/validate'
1111
1212
export default {
1313
props: {

src/views/layout/components/Sidebar/SidebarItem.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<script>
4040
import path from 'path'
4141
import { generateTitle } from '@/utils/i18n'
42-
import { isExternal } from '@/utils'
42+
import { isExternal } from '@/utils/validate'
4343
import Item from './Item'
4444
import AppLink from './Link'
4545
import FixiOSBug from './FixiOSBug'
@@ -94,14 +94,12 @@ export default {
9494
return false
9595
},
9696
resolvePath(routePath) {
97-
if (this.isExternalLink(routePath)) {
97+
if (isExternal(routePath)) {
9898
return routePath
9999
}
100100
return path.resolve(this.basePath, routePath)
101101
},
102-
isExternalLink(routePath) {
103-
return isExternal(routePath)
104-
},
102+
105103
generateTitle
106104
}
107105
}

0 commit comments

Comments
 (0)