feature/uuid-0609-ch
ch 3 years ago
parent c259a61025
commit 1c5402a7b0

@ -4,19 +4,19 @@
* @Author: ch * @Author: ch
* @Date: 2022-05-03 23:04:45 * @Date: 2022-05-03 23:04:45
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-06-09 18:54:57 * @LastEditTime: 2022-06-09 19:21:46
* @Description: file content * @Description: file content
*/ */
import { creatUuid } from "@/plugins/utils"; import { CreatUuid } from "@/plugins/utils";
let axios = null let axios = null
export default function ({ app, $axios, store, req }) { export default function ({ app, $axios, store, req }) {
let uuid = store.state.uuid; let uuid = store.state.uuid;
if (!uuid) { if (!uuid) {
uuid = creatUuid(16, 2); uuid = CreatUuid(16, 2);
store.commit('setUUID', uuid); store.commit('setUUID', uuid);
} }
$axiosTk.onRequest( config =>{ $axios.onRequest( config =>{
config.headers.uid = uuid; config.headers.uid = uuid;
return config; return config;
}); });

@ -2,22 +2,22 @@
* @Author: ch * @Author: ch
* @Date: 2022-05-04 17:11:07 * @Date: 2022-05-04 17:11:07
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-06-09 18:55:23 * @LastEditTime: 2022-06-09 19:22:06
* @Description: file content * @Description: file content
*/ */
import { creatUuid } from "@/plugins/utils"; import { CreatUuid } from "@/plugins/utils";
let axiosTk = null; let axiosTk = null;
export default function ({$axios, store, route}, inject) { export default function ({$axios, store, route}, inject) {
const $axiosTk = $axios.create(); const $axiosTk = $axios.create();
let uuid = store.state.uuid; let uuid = store.state.uuid;
if (!uuid) { if (!uuid) {
uuid = creatUuid(16, 2); uuid = CreatUuid(16, 2);
store.commit('setUUID', uuid); store.commit('setUUID', uuid);
} }
config.headers.uid = uuid;
$axiosTk.defaults.timeout = 3000; $axiosTk.defaults.timeout = 3000;
$axiosTk.onRequest( config =>{ $axiosTk.onRequest( config =>{
config.headers.uid = uuid;
if(!store.state.token){ if(!store.state.token){
location.href = '/'; location.href = '/';
return Promise.reject({message : '要先登录才能操作哦~'}); return Promise.reject({message : '要先登录才能操作哦~'});

Loading…
Cancel
Save