| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import Cookies from 'js-cookie'
- const TokenKey = 'dy_admin_token'
- // const CrossTokenKey = 'Admin-Token'
- const CrossTokenKey = 'Admin-Token'
- function getCookieDomain() {
- let host = location.hostname
- const ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
- if (ip.test(host) === true || host === 'localhost') return host
- const regex = /([^]*).*/
- const match = host.match(regex)
- if (typeof match !== 'undefined' && match !== null) host = match[1]
- if (typeof host !== 'undefined' && host !== null) {
- const strAry = host.split('.')
- if (strAry.length > 1) {
- host = strAry[strAry.length - 2] + '.' + strAry[strAry.length - 1]
- }
- }
- return '.' + host
- }
- export function getToken () {
- return Cookies.get(TokenKey)
- }
- export function setToken (token) {
- return Cookies.set(TokenKey, token)
- }
- export function removeToken () {
- return Cookies.remove(TokenKey)
- }
- export function setCrossToken (token) {
- return Cookies.set(CrossTokenKey, token, { domain: getCookieDomain() })
- }
- export function removeCrossToken () {
- return Cookies.remove(CrossTokenKey, { domain: getCookieDomain() })
- }
|