feature/uuid-0609-ch
ch 2 years ago
parent 8b18ca4f73
commit c259a61025

@ -1,9 +1,17 @@
/*
* @Author: ch
* @Date: 2022-05-17 18:17:00
* @LastEditors: ch
* @LastEditTime: 2022-06-09 18:50:01
* @Description: file content
*/
/** /**
* 全局常量请避免使用魔法数字 * 全局常量请避免使用魔法数字
*/ */
// 用户凭证名 // 用户凭证名
const TOKEN_KEY = "msbPcToken"; const TOKEN_KEY = "msbPcToken";
const UUID_KEY = "msbPcUuid";
// 订单状态 // 订单状态
const ORDER_STATUS = { const ORDER_STATUS = {
@ -31,4 +39,4 @@ const SECKILL_STATUS = {
GOING: 2, // 进行中 GOING: 2, // 进行中
}; };
export { TOKEN_KEY, ORDER_STATUS, SEX_TYPE, CATEGROY_LEVEL, SECKILL_STATUS }; export { TOKEN_KEY, UUID_KEY, ORDER_STATUS, SEX_TYPE, CATEGROY_LEVEL, SECKILL_STATUS };

@ -1,24 +1,25 @@
/* /*
* @Author: ch * @Author: ch
* @Date: 2022-05-03 23:04:45 * @Date: 2022-05-03 23:04:45
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-25 17:48:31 * @LastEditTime: 2022-06-09 18:54:57
* @Description: file content * @Description: file content
*/ */
import { creatUuid } from "@/plugins/utils";
let axios = null let axios = null
export default function({app, $axios, req}) { export default function ({ app, $axios, store, req }) {
// if(req){ let uuid = store.state.uuid;
// let str = 'Safari' if (!uuid) {
// if(req.headers['user-agent'].includes('Chrome')){ uuid = creatUuid(16, 2);
// str = 'Chrome' store.commit('setUUID', uuid);
// } }
// console.log(str, req.headers['cookie'].split('token')[1]);
// }
// export default function ({app, $axios}) {
// $axios.onRequest(()=>{
// }) $axiosTk.onRequest( config =>{
config.headers.uid = uuid;
return config;
});
$axios.onResponse(response => { $axios.onResponse(response => {
const result = response.data; const result = response.data;

@ -2,12 +2,19 @@
* @Author: ch * @Author: ch
* @Date: 2022-05-04 17:11:07 * @Date: 2022-05-04 17:11:07
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-25 17:48:35 * @LastEditTime: 2022-06-09 18:55:23
* @Description: file content * @Description: file content
*/ */
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;
if (!uuid) {
uuid = creatUuid(16, 2);
store.commit('setUUID', uuid);
}
config.headers.uid = uuid;
$axiosTk.defaults.timeout = 3000; $axiosTk.defaults.timeout = 3000;
$axiosTk.onRequest( config =>{ $axiosTk.onRequest( config =>{

@ -2,10 +2,10 @@
* @Author: ch * @Author: ch
* @Date: 2022-05-04 20:35:20 * @Date: 2022-05-04 20:35:20
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-07 22:33:28 * @LastEditTime: 2022-06-09 18:50:16
* @Description: file content * @Description: file content
*/ */
import { TOKEN_KEY } from "@/constants"; import { TOKEN_KEY,UUID_KEY } from "@/constants";
import { ApiGetCurrentUser, ApiPostLogout } from "@/plugins/api/account"; import { ApiGetCurrentUser, ApiPostLogout } from "@/plugins/api/account";
import { ApiGetCartList } from "@/plugins/api/cart"; import { ApiGetCartList } from "@/plugins/api/cart";
import { ApiGetCategoryOneList } from "@/plugins/api/goods"; import { ApiGetCategoryOneList } from "@/plugins/api/goods";
@ -13,6 +13,7 @@ const ONE_DAY = 86400000; // 一天的毫秒数 24 * 60 * 60 * 1000;
const state = () => ({ const state = () => ({
token: "", token: "",
uuid : '',
userInfo: {}, userInfo: {},
loginVisible: false, // 是否展示登录弹窗 loginVisible: false, // 是否展示登录弹窗
seckillTabVisible: false, // 公共头是否展示秒杀tab seckillTabVisible: false, // 公共头是否展示秒杀tab
@ -25,6 +26,14 @@ const mutations = {
setUserInfo(state, info) { setUserInfo(state, info) {
state.userInfo = info; state.userInfo = info;
}, },
setUUID(state, uuid) {
state.uuid = uuid;
this.$cookies.set(UUID_KEY, uuid, {
path: "/",
maxAge: ONE_DAY,
});
},
setToken(state, token) { setToken(state, token) {
state.token = token; state.token = token;
this.$cookies.set(TOKEN_KEY, token, { this.$cookies.set(TOKEN_KEY, token, {

Loading…
Cancel
Save