Skip to content

Commit 872e15e

Browse files
eviIItlevy9527
authored andcommitted
feat: 添加 @nuxtjs/pwa 模块
1 parent 4e70cf6 commit 872e15e

File tree

12 files changed

+1810
-30
lines changed

12 files changed

+1810
-30
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Create a Deepexi Nuxt App in seconds.
3434
- [x] [dotenv](https://github.com/motdotla/dotenv) Loads environment variables from .env for nodejs projects
3535
- [x] [element-ui](https://element.eleme.io/) A Vue.js 2.0 UI Toolkit for Web
3636
- [x] [vant](https://youzan.github.io/vant) Lightweight Mobile UI Components built on Vue
37+
- [x] [PWA](https://pwa.nuxtjs.org) Nuxt Progressive Web Apps solution
3738

3839
[⬆ Back to Top](#table-of-contents)
3940

template.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const common = {
2626
release: 'release-log',
2727
styles: 'styles',
2828
'icon-font': 'icon-font',
29-
test: 'jest'
29+
test: 'jest',
30+
utils: 'utils'
3031
}
3132

3233
const desktop = {

template/_package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<%_ } _%>
4646
"@nuxtjs/axios": "^5.0.1",
4747
"@nuxtjs/dotenv": "^1.3.0",
48+
"@nuxtjs/pwa": "^3.0.0-beta.16",
4849
"dayjs": "^1.7.4",
4950
"dotenv": "^6.0.0",
5051
"js-cookie": "^2.2.0",

template/frameworks/axios/plugins/axios.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818

1919
import Vue from 'vue'
2020

21+
const skipUrls = ['easy-mock']
22+
2123
export default function({$axios, store, app, redirect}) {
2224
$axios.onRequest(config => {
2325
let url = config.url
26+
27+
if (skipUrls.some(skipUrl => url.indexOf(skipUrl) > -1)) return
28+
2429
// jwt 验证
2530
if (store.state.token) {
2631
config.headers.common['Authorization'] = `Bearer ${store.state.token}`
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const {getRouterBase} = require('../src/utils')
2+
3+
describe('测试 utils.getRouterBase 函数', () => {
4+
test('传入非法的参数,返回根路径', () => {
5+
expect(getRouterBase()).toBe('/')
6+
expect(getRouterBase(false)).toBe('/')
7+
expect(getRouterBase(12345)).toBe('/')
8+
expect(getRouterBase('abcde')).toBe('/')
9+
expect(getRouterBase(null)).toBe('/')
10+
expect(getRouterBase({})).toBe('/')
11+
expect(getRouterBase(undefined)).toBe('/')
12+
})
13+
14+
test('只传入域名,返回根路径', () => {
15+
expect(getRouterBase('https://bing.com')).toBe('/')
16+
expect(getRouterBase('https://static.deepexi.top#/hash')).toBe('/')
17+
})
18+
19+
test('传入带有路由的域名,返回路由', () => {
20+
expect(getRouterBase('https://bing.com/aaa')).toBe('/aaa/')
21+
expect(getRouterBase('https://serverless.deepexi.top/bbb#/hash')).toBe(
22+
'/bbb/'
23+
)
24+
expect(getRouterBase('https://static.deepexi.top/aaa/bbb')).toBe('/aaa/bbb/')
25+
expect(
26+
getRouterBase('https://static.deepexi.top/serverless-console/aaa/bbb')
27+
).toBe('/serverless-console/aaa/bbb/')
28+
})
29+
30+
test('传入带有文件名的域名,只返回路由', () => {
31+
expect(
32+
getRouterBase(
33+
'https://serverless.deepexi.top/serverless-console/index.html#/app-list'
34+
)
35+
).toBe('/serverless-console/')
36+
37+
expect(
38+
getRouterBase(
39+
'https://serverless.deepexi.top/serverless-console/aaa/bbb/ccc/index.html#/app-list'
40+
)
41+
).toBe('/serverless-console/aaa/bbb/ccc/')
42+
})
43+
})

0 commit comments

Comments
 (0)