Commit 759fdf41 authored by webwanghao's avatar webwanghao

init

parents
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
{
"name": "jeq-shared",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "jeq-shared",
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"blueimp-md5": "^2.18.0",
"js-cookie": "^2.2.1"
},
"devDependencies": {
"@types/blueimp-md5": "^2.7.0",
"@types/js-cookie": "^2.2.6",
"typescript": "^4.1.2"
},
"peerDependencies": {
"axios": "^0.21.0"
}
},
"node_modules/@types/blueimp-md5": {
"version": "2.7.0",
"resolved": "https://registry.npm.taobao.org/@types/blueimp-md5/download/@types/blueimp-md5-2.7.0.tgz",
"integrity": "sha1-QEIigGgAR4yieC6K1GWQq6fxRic=",
"dev": true
},
"node_modules/@types/js-cookie": {
"version": "2.2.6",
"resolved": "https://registry.npm.taobao.org/@types/js-cookie/download/@types/js-cookie-2.2.6.tgz",
"integrity": "sha1-8aHLNa/0e8XPsFywxEHKkekUwm8=",
"dev": true
},
"node_modules/axios": {
"version": "0.21.0",
"resolved": "https://registry.npm.taobao.org/axios/download/axios-0.21.0.tgz?cache=0&sync_timestamp=1603468716105&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Faxios%2Fdownload%2Faxios-0.21.0.tgz",
"integrity": "sha1-Jt8IiAOiNQ3/LCf5b++Z/klEKso=",
"peer": true,
"dependencies": {
"follow-redirects": "^1.10.0"
}
},
"node_modules/blueimp-md5": {
"version": "2.18.0",
"resolved": "https://registry.npm.taobao.org/blueimp-md5/download/blueimp-md5-2.18.0.tgz?cache=0&sync_timestamp=1599370039411&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fblueimp-md5%2Fdownload%2Fblueimp-md5-2.18.0.tgz",
"integrity": "sha1-EVK+EzXwxrORHtnjbbVPPmrFKTU="
},
"node_modules/follow-redirects": {
"version": "1.13.0",
"resolved": "https://registry.npm.taobao.org/follow-redirects/download/follow-redirects-1.13.0.tgz",
"integrity": "sha1-tC6Nk6Kn7qXtiGM2dtZZe8jjhNs=",
"peer": true,
"engines": {
"node": ">=4.0"
}
},
"node_modules/js-cookie": {
"version": "2.2.1",
"resolved": "https://registry.npm.taobao.org/js-cookie/download/js-cookie-2.2.1.tgz?cache=0&sync_timestamp=1599570846666&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjs-cookie%2Fdownload%2Fjs-cookie-2.2.1.tgz",
"integrity": "sha1-aeEG3F1YBolFYpAqpbrsN0Tpsrg="
},
"node_modules/typescript": {
"version": "4.1.2",
"resolved": "https://registry.npm.taobao.org/typescript/download/typescript-4.1.2.tgz?cache=0&sync_timestamp=1606891808783&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ftypescript%2Fdownload%2Ftypescript-4.1.2.tgz",
"integrity": "sha1-Y2nvIlFv5eEDBKrlpcSGLbVTgOk=",
"dev": true,
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=4.2.0"
}
}
},
"dependencies": {
"@types/blueimp-md5": {
"version": "2.7.0",
"resolved": "https://registry.npm.taobao.org/@types/blueimp-md5/download/@types/blueimp-md5-2.7.0.tgz",
"integrity": "sha1-QEIigGgAR4yieC6K1GWQq6fxRic=",
"dev": true
},
"@types/js-cookie": {
"version": "2.2.6",
"resolved": "https://registry.npm.taobao.org/@types/js-cookie/download/@types/js-cookie-2.2.6.tgz",
"integrity": "sha1-8aHLNa/0e8XPsFywxEHKkekUwm8=",
"dev": true
},
"axios": {
"version": "0.21.0",
"resolved": "https://registry.npm.taobao.org/axios/download/axios-0.21.0.tgz?cache=0&sync_timestamp=1603468716105&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Faxios%2Fdownload%2Faxios-0.21.0.tgz",
"integrity": "sha1-Jt8IiAOiNQ3/LCf5b++Z/klEKso=",
"peer": true,
"requires": {
"follow-redirects": "^1.10.0"
}
},
"blueimp-md5": {
"version": "2.18.0",
"resolved": "https://registry.npm.taobao.org/blueimp-md5/download/blueimp-md5-2.18.0.tgz?cache=0&sync_timestamp=1599370039411&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fblueimp-md5%2Fdownload%2Fblueimp-md5-2.18.0.tgz",
"integrity": "sha1-EVK+EzXwxrORHtnjbbVPPmrFKTU="
},
"follow-redirects": {
"version": "1.13.0",
"resolved": "https://registry.npm.taobao.org/follow-redirects/download/follow-redirects-1.13.0.tgz",
"integrity": "sha1-tC6Nk6Kn7qXtiGM2dtZZe8jjhNs=",
"peer": true
},
"js-cookie": {
"version": "2.2.1",
"resolved": "https://registry.npm.taobao.org/js-cookie/download/js-cookie-2.2.1.tgz?cache=0&sync_timestamp=1599570846666&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjs-cookie%2Fdownload%2Fjs-cookie-2.2.1.tgz",
"integrity": "sha1-aeEG3F1YBolFYpAqpbrsN0Tpsrg="
},
"typescript": {
"version": "4.1.2",
"resolved": "https://registry.npm.taobao.org/typescript/download/typescript-4.1.2.tgz?cache=0&sync_timestamp=1606891808783&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ftypescript%2Fdownload%2Ftypescript-4.1.2.tgz",
"integrity": "sha1-Y2nvIlFv5eEDBKrlpcSGLbVTgOk=",
"dev": true
}
}
}
{
"name": "jeq-shared",
"version": "1.0.0",
"main": "index.js",
"author": "jeq-fe",
"license": "MIT",
"private": true,
"scripts": {
"clean": "rm -rf dist",
"build": "yarn clean && tsc"
},
"peerDependencies": {
"axios": "^0.21.0"
},
"devDependencies": {
"@types/blueimp-md5": "^2.7.0",
"@types/js-cookie": "^2.2.6",
"typescript": "^4.1.2"
},
"dependencies": {
"blueimp-md5": "^2.18.0",
"js-cookie": "^2.2.1"
}
}
import instance from './request'
export default function () {
return function () {
return instance
}
}
function Parse () {
const escapee = { '"': '"', '\\': '\\', '/': '/', b: '\b', f: '\f', n: '\n', r: '\r', t: '\t' }
let at
let ch
let text
const error = function (m) {
throw { name: 'SyntaxError', message: m, at: at, text: text }
}
const next = function (c) {
if (c && c !== ch) {
error('Expected \'' + c + '\' instead of \'' + ch + '\'')
}
ch = text.charAt(at)
at += 1
return ch
}
const number = function () {
let number, string = ''
if (ch === '-') {
string = '-'
next('-')
}
while (ch >= '0' && ch <= '9') {
string += ch
next()
}
if (ch === '.') {
string += '.'
while (next() && ch >= '0' && ch <= '9') {
string += ch
}
}
if (ch === 'e' || ch === 'E') {
string += ch
next()
if (ch === '-' || ch === '+') {
string += ch
next()
}
while (ch >= '0' && ch <= '9') {
string += ch
next()
}
}
number = +string
if (!isFinite(number)) {
error('Bad number')
} else {
if (string.length > 15) return string
return number
}
}
const string = function () {
let hex, i, string = '', uffff
if (ch === '"') {
while (next()) {
if (ch === '"') {
next()
return string
}
if (ch === '\\') {
next()
if (ch === 'u') {
uffff = 0
for (i = 0; i < 4; i += 1) {
hex = parseInt(next(), 16)
if (!isFinite(hex)) {
break
}
uffff = uffff * 16 + hex
}
string += String.fromCharCode(uffff)
} else if (typeof escapee[ch] === 'string') {
string += escapee[ch]
} else {
break
}
} else {
string += ch
}
}
}
error('Bad string')
}
const white = function () {
while (ch && ch <= ' ') {
next()
}
}
const word = function () {
switch (ch) {
case 't':
next('t')
next('r')
next('u')
next('e')
return true
case 'f':
next('f')
next('a')
next('l')
next('s')
next('e')
return false
case 'n':
next('n')
next('u')
next('l')
next('l')
return null
}
error('Unexpected \'' + ch + '\'')
}
let value
const array = function () {
const array = []
if (ch === '[') {
next('[')
white()
if (ch === ']') {
next(']')
return array // empty array
}
while (ch) {
array.push(value())
white()
if (ch === ']') {
next(']')
return array
}
next(',')
white()
}
}
error('Bad array')
}
const object = function () {
let key, object = {}
if (ch === '{') {
next('{')
white()
if (ch === '}') {
next('}')
return object // empty object
}
while (ch) {
key = string()
white()
next(':')
if (key)
object[key] = value()
white()
if (ch === '}') {
next('}')
return object
}
next(',')
white()
}
}
error('Bad object')
}
value = function () {
white()
switch (ch) {
case '{':
return object()
case '[':
return array()
case '"':
return string()
case '-':
return number()
default:
return ch >= '0' && ch <= '9' ? number() : word()
}
}
return function (source) {
let result
text = source + ''
at = 0
ch = ' '
result = value()
white()
if (ch) {
error('Syntax error')
}
return result
}
}
export default Parse()
import axios from 'axios'
import parse from './parse'
import { getToken, removeToken } from '../token'
axios.defaults.transformResponse = [res => {
if (/\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g.test(res)) {
res = res.replace(/\\/g, '%')
res = unescape(res)
}
return parse(res)
}]
interface RequestGlobalConfig {
baseURL: string
headers: Record<string, string | number>
onAuthError?: (err: any) => void
}
export default function initRequest ({ baseURL, headers, onAuthError }: RequestGlobalConfig) {
const instance = axios.create({ baseURL, headers })
instance.interceptors.request.use(config => {
if (config.method?.toLowerCase() === 'post') {
config.data = filterParams(config.data, true)
} else {
config.params = filterParams(config.params)
}
config.headers.Authorization = getToken() || ''
return config
}, Promise.reject)
instance.interceptors.response.use(res => {
if (res?.status === 200) {
return Promise.resolve(res.data)
}
return Promise.reject(res.data)
}, err => {
if (err.response?.status) {
if ([401, 403].includes(err.response.data.status)) {
removeToken()
onAuthError?.(err)
}
return Promise.reject(err.response.data)
}
})
}
function filterParams (params?: any, post?: boolean) {
const entityType = ['number', 'boolean']
if (post) entityType.push('string')
if (entityType.includes(typeof params) || Array.isArray(params)) {
return params
}
if (typeof params === 'object' && params) {
const result: Record<string, any> = {}
Object.keys(params).forEach(key => {
const value = params[key]
if (entityType.includes(typeof value)) {
result[key] = value
} else if (value) {
result[key] = value
}
})
return result
}
}
function generateHeaders () {
const screen = window.screen
return {
devicesid: window.deviceId || 'none',
network: window.networkType,
r: `${screen.width * devicePixelRatio}x${screen.height * devicePixelRatio}`,
region: store.getters.region,
lon: store.state.location[0],
lat: store.state.location[1],
loc_region: store.state.positionCode,
device_brand: '',
device_mobel: '',
os_version: getOSVersion(),
}
}
function getOSVersion () {
const wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d.]+)/i)
return wechatInfo ? wechatInfo[1] : ''
}
export * from './api'
export * from './token'
import Cookies from 'js-cookie'
const TokenKey = 'jeq_wap_token'
export function getToken (key: string = TokenKey) {
return Cookies.get(key)
}
export function setToken (token: string, key: string = TokenKey) {
if (key === TokenKey) {
return Cookies.set(key, `Bearer ${token}`)
} else {
return Cookies.set(key, token)
}
}
export function removeToken (key: string = TokenKey) {
return Cookies.remove(key)
}
{
"compilerOptions": {
"target": "es2015",
"outDir": "dist",
"module": "CommonJS",
"strict": true,
"declaration": true,
"skipLibCheck": true,
"esModuleInterop": true,
"moduleResolution": "Node",
"allowJs": true,
"lib": [
"ESNext",
"dom"
]
},
"include": ["src/**/*"]
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/blueimp-md5@^2.7.0":
"integrity" "sha1-QEIigGgAR4yieC6K1GWQq6fxRic="
"resolved" "https://registry.npm.taobao.org/@types/blueimp-md5/download/@types/blueimp-md5-2.7.0.tgz"
"version" "2.7.0"
"@types/js-cookie@^2.2.6":
"integrity" "sha1-8aHLNa/0e8XPsFywxEHKkekUwm8="
"resolved" "https://registry.npm.taobao.org/@types/js-cookie/download/@types/js-cookie-2.2.6.tgz"
"version" "2.2.6"
"axios@^0.21.0":
"integrity" "sha1-Jt8IiAOiNQ3/LCf5b++Z/klEKso="
"resolved" "https://registry.npm.taobao.org/axios/download/axios-0.21.0.tgz?cache=0&sync_timestamp=1603468716105&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Faxios%2Fdownload%2Faxios-0.21.0.tgz"
"version" "0.21.0"
dependencies:
"follow-redirects" "^1.10.0"
"blueimp-md5@^2.18.0":
"integrity" "sha1-EVK+EzXwxrORHtnjbbVPPmrFKTU="
"resolved" "https://registry.npm.taobao.org/blueimp-md5/download/blueimp-md5-2.18.0.tgz?cache=0&sync_timestamp=1599370039411&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fblueimp-md5%2Fdownload%2Fblueimp-md5-2.18.0.tgz"
"version" "2.18.0"
"follow-redirects@^1.10.0":
"integrity" "sha1-tC6Nk6Kn7qXtiGM2dtZZe8jjhNs="
"resolved" "https://registry.npm.taobao.org/follow-redirects/download/follow-redirects-1.13.0.tgz"
"version" "1.13.0"
"js-cookie@^2.2.1":
"integrity" "sha1-aeEG3F1YBolFYpAqpbrsN0Tpsrg="
"resolved" "https://registry.npm.taobao.org/js-cookie/download/js-cookie-2.2.1.tgz?cache=0&sync_timestamp=1599570846666&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjs-cookie%2Fdownload%2Fjs-cookie-2.2.1.tgz"
"version" "2.2.1"
"typescript@^4.1.2":
"integrity" "sha1-Y2nvIlFv5eEDBKrlpcSGLbVTgOk="
"resolved" "https://registry.npm.taobao.org/typescript/download/typescript-4.1.2.tgz?cache=0&sync_timestamp=1606891808783&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ftypescript%2Fdownload%2Ftypescript-4.1.2.tgz"
"version" "4.1.2"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment