Skip to content

Commit b968248

Browse files
committed
Chore: release 1.2.12
1 parent f872023 commit b968248

File tree

11 files changed

+1227
-763
lines changed

11 files changed

+1227
-763
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# 更新日志
22

3+
## v 1.2.12
4+
5+
- WebSocket简单包装类
6+
- 完善utils
7+
38
## v 1.2.10
49

510
- banner插件

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-tpl",
3-
"version": "1.2.10",
3+
"version": "1.2.12",
44
"private": false,
55
"description": "vue + vuex + vue router + TypeScript(支持 JavaScript) 模板",
66
"author": "毛瑞 <Maorey@Foxmail.com>",
@@ -15,15 +15,15 @@
1515
"axios": "^0.19.2",
1616
"core-js": "^3.6.5",
1717
"crypto-js": "3.3.0",
18-
"d3": "^5.15.1",
18+
"d3": "^5.16.0",
1919
"echarts": "^4.7.0",
2020
"element-ui": "^2.13.1",
2121
"jsencrypt": "^3.0.0-rc.1",
2222
"luma.gl": "^7.3.2",
2323
"normalize.css": "^8.0.1",
2424
"nprogress": "^0.2.0",
25-
"pixi.js": "^5.2.1",
26-
"pixi.js-legacy": "^5.2.1",
25+
"pixi.js": "^5.2.2",
26+
"pixi.js-legacy": "^5.2.2",
2727
"register-service-worker": "^1.7.1",
2828
"three": "^0.115.0",
2929
"vue": "^2.6.11",
@@ -46,8 +46,8 @@
4646
"@types/d3": "^5.7.2",
4747
"@types/echarts": "^4.4.6",
4848
"@types/jest": "^25.2.1",
49-
"@typescript-eslint/eslint-plugin": "^2.28.0",
50-
"@typescript-eslint/parser": "^2.28.0",
49+
"@typescript-eslint/eslint-plugin": "^2.29.0",
50+
"@typescript-eslint/parser": "^2.29.0",
5151
"@vue/cli-plugin-babel": "~4.3.1",
5252
"@vue/cli-plugin-e2e-cypress": "~4.3.1",
5353
"@vue/cli-plugin-eslint": "~4.3.1",
@@ -70,14 +70,14 @@
7070
"eslint-plugin-vue": "^6.2.2",
7171
"fibers": "^4.0.2",
7272
"hard-source-webpack-plugin": "^0.13.1",
73-
"lint-staged": "^10.1.6",
73+
"lint-staged": "^10.1.7",
7474
"postcss-preset-env": "^6.7.0",
7575
"regenerate": "^1.4.0",
7676
"regjsgen": "^0.5.1",
7777
"regjsparser": "^0.6.4",
7878
"sass": "^1.26.3",
7979
"sass-loader": "^8.0.2",
80-
"stylelint": "^13.3.2",
80+
"stylelint": "^13.3.3",
8181
"stylelint-config-scss-maorey": "^1.1.1",
8282
"stylelint-webpack-plugin": "^1.2.3",
8383
"typescript": "~3.8.3",

src/api/user.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Author: 毛瑞
44
* @LastEditTime: 2019-07-24 11:01:36
55
*/
6-
import { HEAD, get, post } from '@/utils/ajax'
6+
import { setHEAD, get, post } from '@/utils/ajax'
77
import { local } from '@/utils/storage'
88
import CONFIG from '@/config'
99
import API from '@/config/api/user'
@@ -53,7 +53,8 @@ function login(formData: ILogin) {
5353
account,
5454
password,
5555
}).then(res => {
56-
HEAD[CONFIG.token] = res.data.token
56+
setHEAD(CONFIG.token, res.data.token, true)
57+
// 加密存token + 进入页面最先检查/设置token
5758
local.set(CONFIG.token, res.data, CONFIG.tokenAlive)
5859
return res
5960
})
@@ -65,7 +66,7 @@ function login(formData: ILogin) {
6566
*/
6667
function logout() {
6768
return get(API.logout).then(res => {
68-
delete HEAD[CONFIG.token]
69+
setHEAD(CONFIG.token, '', true)
6970
local.remove(CONFIG.token)
7071
return res
7172
})

src/components/RouterViewTransparent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default {
3434
this.d = 0
3535
},
3636
beforeRouteLeave(this: any, to, from, next) {
37-
this.d = to.matched.length // for 刷新
37+
this.d = to.matched.length && 1 // for 刷新
3838
setTimeout(next)
3939
},
4040
deactivated(this: any) {

src/utils/ajax.ts renamed to src/utils/ajax/index.ts

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import sort from '@/utils/sort'
1111
import clone from '@/utils/clone'
1212
import { Memory } from '@/utils/storage'
1313

14-
// import { success, failed } from './interceptor' // [请求拦截]
15-
// import { emit } from '../eventBus' // 通知取消请求 以便自定义取消策略使用
14+
import { success, failed } from './interceptor'
15+
import WS from './websocket'
16+
// import { emit } from '@/utils/eventBus' // 通知取消请求 以便自定义取消策略使用
1617

1718
// 默认请求配置 https://github.com/axios/axios#config-defaults
1819
clone(AXIOS.defaults, {
@@ -54,6 +55,30 @@ const CancelToken = AXIOS.CancelToken
5455
/** 是否被取消 */
5556
const isCancel = AXIOS.isCancel
5657

58+
/** 全局请求头配置【只用于携带token等】 */
59+
let HEAD = AXIOS.defaults.headers || (AXIOS.defaults.headers = {})
60+
HEAD = HEAD.common || (HEAD.common = {})
61+
62+
/** 设置【全局】请求头
63+
* @param headOrKey
64+
* @param value
65+
* @param isToken
66+
*/
67+
function setHEAD(head: IObject): void
68+
function setHEAD(name: string, value: string, isToken?: boolean): void
69+
function setHEAD(
70+
headOrKey: IObject | string,
71+
value?: string,
72+
isToken?: boolean
73+
) {
74+
if (value) {
75+
HEAD[headOrKey as string] = value
76+
isToken && (WS.defaults.protocols = [value]) // websocket 授权
77+
} else {
78+
Object.assign(HEAD, headOrKey as IObject)
79+
}
80+
}
81+
5782
/** 【debug】带上特定查询字段 */
5883
let SEARCH: IObject | undefined
5984
location.search
@@ -66,10 +91,6 @@ location.search
6691
}
6792
)
6893

69-
/** 全局请求头配置【只用于携带token等】 */
70-
let HEAD = AXIOS.defaults.headers || (AXIOS.defaults.headers = {})
71-
HEAD = HEAD.common || (HEAD.common = {})
72-
7394
/** 获取url (直接使用url的情况, 比如验证码、下载、上传等, 添加BaseUrl、调试参数等)
7495
* @param {string} url
7596
* @param {IObject} params 查询参数
@@ -102,6 +123,7 @@ function searchToObj(search: string) {
102123
}
103124
return Obj
104125
}
126+
105127
/** 获取请求标识
106128
* @param url 请求地址
107129
* @param params 查询参数
@@ -184,25 +206,20 @@ function request(
184206
requestQueue.remove(config.key) // 移除请求队列
185207
shouldCache && dataStore.set(config.key, res, config.alive) // 设置缓存
186208

187-
return res // success(res) // [请求拦截]
209+
return success(res)
188210
})
189211
.catch((res: any) => {
190212
res.meta = config // 请求配置加到元数据
191213
requestQueue.remove(config.key) // 移除请求队列
192-
// if (isCancel(res)) {
193-
// throw res
194-
// } else if (config.$_) {
195-
// res = config.$_ // 自定义取消标记
196-
// config.$_ = 0 // 只取消一次
197-
// throw res
198-
// } else {
199-
// failed(res) // [请求拦截]
200-
// }
201-
if (config.$_) {
214+
if (isCancel(res)) {
215+
throw res
216+
} else if (config.$_) {
202217
res = config.$_ // 自定义取消标记
203218
config.$_ = 0 // 只取消一次
219+
throw res
220+
} else {
221+
failed(res)
204222
}
205-
throw res
206223
})
207224

208225
// data && (cache.cancel = data) // [不划算]
@@ -309,6 +326,7 @@ export {
309326
CancelToken,
310327
isCancel,
311328
HEAD,
329+
setHEAD,
312330
getUri,
313331
getKey,
314332
get,
@@ -317,4 +335,5 @@ export {
317335
post,
318336
patch,
319337
cancel,
338+
WS,
320339
}

src/utils/ajax/interceptor.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** 响应拦截器 */
2+
// import Message from 'element-ui/lib/message'
3+
// import MessageBox from 'element-ui/lib/message-box'
4+
// ↑因scss注入问题,应在合适的地方引入组件对应的scss,比如页面入口
5+
6+
function success(res: any) {
7+
return res
8+
}
9+
10+
function failed(res: any) {
11+
throw res
12+
}
13+
14+
export { success, failed }

0 commit comments

Comments
 (0)