|
|
@ -1,3 +1,4 @@ |
|
|
|
import { v4 as uuidv4 } from 'uuid'; |
|
|
|
const route = useRoute(); |
|
|
|
|
|
|
|
/**需要进行持久化的数据:把需要持久化的数据放在下面这个对象中,才会持久化,不需要持久化的数据就不用放到这里了。 */ |
|
|
@ -91,7 +92,6 @@ export const getPath = () => { |
|
|
|
return route.path; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 跳转页面函数 |
|
|
|
* 携带用于统计用户行为的参数 |
|
|
@ -99,61 +99,59 @@ export const getPath = () => { |
|
|
|
* @param id 128 |
|
|
|
* @param d 项目数据 |
|
|
|
* @param isOpen 是否新窗口打开 |
|
|
|
* @param isToken 是否登录控制台 |
|
|
|
* 拼接规则: {域名}{path}?spm=c.{用户ID}.{租户ID}.{栏目ID}.{商品ID}.{timestamp}&token={token} |
|
|
|
* @return https:///websoft.top/product/detail/128.html?spm=c.5.3057.10005.undefined&token=DDkr1PpE9DouIVMjLEMt9733QsgG7oNV
|
|
|
|
*/ |
|
|
|
export function openSpmUrl(path: string, d?: any, id = 0, isOpen?: boolean): void { |
|
|
|
const domain = route.path; |
|
|
|
export function openSpmUrl(path: string, d?: any, id = 0, isOpen?: boolean, isToken?: boolean): void { |
|
|
|
const config = useWebsite(); |
|
|
|
const spm = ref<string>(''); |
|
|
|
const token = ref<string>(); |
|
|
|
const url = ref<string>(); |
|
|
|
const tid = d?.tenantId || 0; |
|
|
|
const model = ref<string>('c'); |
|
|
|
const tid = config.value.tenantId || 0; |
|
|
|
const mid = config.value.loginUser?.merchantId || 0; |
|
|
|
const pid = d?.parentId || 0; |
|
|
|
const cid = d?.categoryId || 0; |
|
|
|
const uid = localStorage.getItem('UserId') || 0; |
|
|
|
const uid = config.value.loginUser?.userId || 0; |
|
|
|
const timestamp = ref(Date.now() / 1000); |
|
|
|
token.value = `&token=${localStorage.getItem('token')}`; |
|
|
|
let token = uuidv4(); |
|
|
|
|
|
|
|
// TODO 封装租户ID和店铺ID
|
|
|
|
spm.value = `?spm=c.${uid}.${tid}.${pid}.${cid}.${id}.${timestamp.value}${token.value}`; |
|
|
|
// TODO 登录控制台
|
|
|
|
if(isToken){ |
|
|
|
token = `${localStorage.getItem('token')}`; |
|
|
|
} |
|
|
|
|
|
|
|
// TODO 含http直接跳转
|
|
|
|
if (path.slice(0, 4) == 'http') { |
|
|
|
// TODO 判断模型
|
|
|
|
if(d?.articleId){ |
|
|
|
model.value = 'a'; |
|
|
|
} |
|
|
|
if(d?.goodsId){ |
|
|
|
model.value = 'g'; |
|
|
|
} |
|
|
|
if(d?.productId){ |
|
|
|
model.value = 'p'; |
|
|
|
} |
|
|
|
if(d?.appId){ |
|
|
|
model.value = 'app'; |
|
|
|
} |
|
|
|
if(d?.plugId){ |
|
|
|
model.value = 'plug'; |
|
|
|
} |
|
|
|
|
|
|
|
// TODO 封装spm
|
|
|
|
spm.value = `?spm=${model.value}.${tid}.${mid}.${pid}.${cid}.${id}.${uid}.${timestamp.value}&token=${token}`; |
|
|
|
|
|
|
|
// TODO 新窗口打开
|
|
|
|
if(isOpen){ |
|
|
|
window.open(`${path}${spm.value}`); |
|
|
|
return; |
|
|
|
} |
|
|
|
location.href = `${path}${spm.value}`; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 跳转页面
|
|
|
|
url.value = `${path}${spm.value}${token.value}`; |
|
|
|
navigateTo(`${path}${spm.value}`) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 生成spm路径 |
|
|
|
* 携带用于统计用户行为的参数 |
|
|
|
* @param path /product/detail.html |
|
|
|
* @param id 128 |
|
|
|
* @param d 项目数据 |
|
|
|
* 拼接规则: {域名}{path}?spm=c.{用户ID}.{租户ID}.{栏目ID}.{商品ID}.{timestamp}&token={token} |
|
|
|
* @return https:///websoft.top/product/detail/128.html?spm=c.5.3057.10005.undefined&token=DDkr1PpE9DouIVMjLEMt9733QsgG7oNV
|
|
|
|
*/ |
|
|
|
export function getSpmUrl(path: string, d?: any, id = 0): string { |
|
|
|
const domain = route.path; |
|
|
|
const spm = ref<string>(''); |
|
|
|
const token = ref<string>(); |
|
|
|
const url = ref<string>(); |
|
|
|
const tid = d?.tenantId || 0; |
|
|
|
const pid = d?.parentId || 0; |
|
|
|
const cid = d?.categoryId || 0; |
|
|
|
const uid = localStorage.getItem('UserId') || 0; |
|
|
|
const timestamp = ref(Date.now() / 1000); |
|
|
|
token.value = `&token=${localStorage.getItem('token')}`; |
|
|
|
|
|
|
|
// TODO 封装租户ID和店铺ID
|
|
|
|
spm.value = `?spm=c.${uid}.${tid}.${pid}.${cid}.${id}.${timestamp.value}${token.value}`; |
|
|
|
return spm.value; |
|
|
|
// 单点登录控制台
|
|
|
|
export function loginAdminByToken(): void { |
|
|
|
const sysDomain = useSysDomain(); |
|
|
|
openSpmUrl(`https://${sysDomain.value}/token-login`,undefined, 0, true,true) |
|
|
|
} |
|
|
|