Commit 8295007d by liwk

commit

1 parent 9a209d06
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
}, },
"dependencies": { "dependencies": {
"autoprefixer": "^8.0.0", "autoprefixer": "^8.0.0",
"axios": "^0.19.2",
"core-js": "^3.6.4", "core-js": "^3.6.4",
"dayjs": "^1.10.5", "dayjs": "^1.10.5",
"glsx-common": "^1.4.8",
"lib-flexible": "^0.3.2", "lib-flexible": "^0.3.2",
"postcss-loader": "^6.2.0", "postcss-loader": "^6.2.0",
"sha1": "^1.1.1", "sha1": "^1.1.1",
......
import axios from '@/plugins/axios'
import sign from './sign'
import util from '@/utils/util'
class Request {
post(params, returnAll = false) {
return this.request('POST', params, returnAll)
}
get(params, returnAll = false) {
return this.request('GET', params, returnAll)
}
request(method, params, returnAll) {
let noSignAttr = []
params.timestamp = new Date().format('yyyy-MM-dd hh:mm:ss')
let sessionId = util.getLocalStorage('dj_scrm_session_id')
if (sessionId) params.sessionId = sessionId
if (params.noSignAttr) {
noSignAttr = params.noSignAttr
delete params.noSignAttr
}
params = {
...window.$sign,
...params
}
let obj = {
method,
returnAll
}
if (method == 'POST') obj.data = sign(params, noSignAttr)
else obj.params = sign(params, noSignAttr)
return axios(obj)
}
}
export default new Request()
\ No newline at end of file \ No newline at end of file
import sha1 from 'sha1'
import qs from 'qs'
const sign = (params, noSignAttr = []) => {
delete params.sign
var objStr = qs.stringify(params, { arrayFormat: 'indices', encode: false, allowDots: true })
var objVal = objStr.split('&')
var realObj = {}
objVal.forEach(item => {
if (item.split('=')[0] == 'scene') {
realObj.scene = params.scene
} else {
realObj[item.split('=')[0]] = item.split('=')[1]
}
})
const keys = Object.keys(realObj).sort()
var str = []
var obj = null
for (const key in realObj) {
obj = realObj[key]
if (obj === null) {
obj = ''
} else if (typeof obj === 'object') {
obj = JSON.stringify(obj)
}
realObj[key] = obj
}
keys.forEach(e => {
!noSignAttr.includes(e) && str.push(e + realObj[e])
})
const secret = window.$secret
realObj.sign = sha1(secret + str.join('') + secret).toUpperCase()
return realObj
}
export default sign
\ No newline at end of file \ No newline at end of file
import api from './request' const url = '/rop-scrm-sso/router'
const returnAll = true
export default { export default {
/**OAuth2授权登陆 */ /**OAuth2授权登陆 */
login(data) { login(data) {
return api.post({ data.method = 'scrm.api.sso.ww.oauth.login'
method: 'scrm.api.sso.ww.oauth.login', return window.$HTTP({
...data, url,
}, true) data,
returnAll
})
}, },
/** 选择登录账号 */ /** 选择登录账号 */
selectAccount(data) { selectAccount(data) {
return api.post({ data.method = 'scrm.api.sso.user.login.select'
method: 'scrm.api.sso.user.login.select', return window.$HTTP({
...data, url,
}, true) data,
returnAll
})
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -16,13 +16,13 @@ import router from './router' ...@@ -16,13 +16,13 @@ import router from './router'
import store from './store' import store from './store'
import api from './api' import api from './api'
import { fetchConfig, cfg } from '@/config' import { fetchConfig, cfg } from '@/config'
import { axsinit } from './plugins/axios'
import '@/assets/css/index.scss' import '@/assets/css/index.scss'
import { bus, tools, store as local } from './utils' import { bus, tools, store as local } from './utils'
import './utils/util' import './utils/util'
import 'components' import 'components'
import { components } from '@/plugins/vant' import { components } from '@/plugins/vant'
components.forEach(component => Vue.use(component)) components.forEach(component => Vue.use(component))
import { Http } from 'glsx-common'
Vue.prototype.api = api Vue.prototype.api = api
Vue.prototype.bus = bus Vue.prototype.bus = bus
Vue.prototype.tools = tools Vue.prototype.tools = tools
...@@ -43,20 +43,22 @@ Vue.config.productionTip = false ...@@ -43,20 +43,22 @@ Vue.config.productionTip = false
// const vConsole = new VConsole() // const vConsole = new VConsole()
const isMock = true const isMock = true
fetchConfig(!isMock).then(({ request, sign, secret, cdn }) => { fetchConfig(!isMock).then(res => {
// 从配置服务器获取动态配置 // 从配置服务器获取动态配置
// 设置 js中可以访问 $cdn // 设置 js中可以访问 $cdn
Vue.prototype.$cdn = cdn
Vue.use(cfg) Vue.use(cfg)
if (isMock) { window.$baseUrl = res.request.baseURL
window.$sign = sign window.$HTTP = new Http({...res, alert: components.Notify })
window.$secret = secret
/**登录过期 重新登录 */
window.reLogin = () => {
console.log(123)
} }
axsinit(request)
window.vm = new Vue({ window.vm = new Vue({
el: '#app', el: '#app',
router, router,
store, store,
render: h => h(App) render: h => h(App)
}) })
store.dispatch('navigation', router)
}) })
\ No newline at end of file \ No newline at end of file
/*
* @Descripttion:
* @version: 1.0.0
* @Author: limin
* @Date: 2021-06-07 17:24:19
* @LastEditors: limin
* @LastEditTime: 2021-06-29 16:08:08
* @FilePath: \gh-hall\src\plugins\axios\index.js
*/
import axios from 'axios'
import store from '@/store'
import Qs from 'qs'
import { Notify, Dialog, Toast } from 'vant'
const service = axios.create({
// baseURL: baseApi, // url = base api url + request url
withCredentials: true, // send cookies when cross-domain requests
// timeout: 5000 // request timeout
transformRequest: [function(data) {
return Qs.stringify(data)
}]
})
// request拦截器 request interceptor
service.interceptors.request.use(
config => {
// 开启loading
if (config.loading) {
Toast.loading({
overlay: true,
duration: 0,
forbidClick: true
})
}
return config
},
error => {
Toast.clear()
// do something with request error
console.log(error) // for debug
return Promise.reject(error)
}
)
// respone拦截器
service.interceptors.response.use(
response => {
Toast.clear()
console.log(response)
// const { config:{params,data} } = response
let { status, data, config: { returnAll } } = response
if (status != 200) {
Notify({ message })
} else {
if (data.code == 20 || data.code == 21) {
Dialog.alert({
title: '温馨提示',
message: '登录过期,请重新登录。',
confirmButtonColor: '#FF7336'
}).then(() => {
store.dispatch('login')
})
} else {
if (returnAll) {
return Promise.resolve(data)
} else {
if (data.code == '0') {
return Promise.resolve(data.data)
} else {
Notify({ message: data.message || '系统异常' })
}
}
}
}
},
error => {
Toast.clear()
Notify({ message: 'err:' + JSON.stringify(error) })
return Promise.reject(error)
}
)
export const axsinit = function(options = {}) {
Object.assign(service.defaults, options)
}
export default service
\ No newline at end of file \ No newline at end of file
...@@ -12,7 +12,6 @@ import util from '@/utils/util' ...@@ -12,7 +12,6 @@ import util from '@/utils/util'
const state = { const state = {
pageMeta: '', pageMeta: '',
keepAlives: [], keepAlives: [],
next: ''
} }
const mutations = { const mutations = {
SET_PAGE_META(state, meta) { SET_PAGE_META(state, meta) {
...@@ -31,9 +30,6 @@ const mutations = { ...@@ -31,9 +30,6 @@ const mutations = {
return arr return arr
}, []) }, [])
}, },
SET_ROUTER_OBJECT(state, next) {
state.next = next
}
} }
const actions = { const actions = {
...@@ -60,7 +56,78 @@ const actions = { ...@@ -60,7 +56,78 @@ const actions = {
}, },
removeKeep({ commit }, names) { removeKeep({ commit }, names) {
commit('REMOVE_KEEP', names) commit('REMOVE_KEEP', names)
},
login() {
let [redirectUrl] = window.location.href.split('?')
const code = getParams('code')
if (code) {
const corpId = util.getLocalStorage('dj_scrm_corpId')
ssoApi.login({
code,
corpId
}).then(({ code, data, message }) => {
let url = `${window.$baseUrl}/dj-scrm-wx-work-main/#/`
let route = state.lastPath == 'home' ? '' : state.lastPath
state.showWindow = true
if (code == '0') {
if (data.loginList.length) {
if (data.loginList.length > 1) {
util.setLocalStorage('dj_scrm_loginToken', data.loginToken)
util.setLocalStorage('dj_scrm_accountList', data.loginList)
let redirect_uri = encodeURI(`${redirectUrl}${route}`)
window.location.replace(`${url}common/accountList?redirect_uri=${redirect_uri}`)
} else {
let [userInfo] = data.loginList
util.setLocalStorage('dj_scrm_userInfo', userInfo)
util.setLocalStorage('dj_scrm_session_id', userInfo.sessionId)
// 只有一个账号 history.back()
console.log(`${redirectUrl}${route}`)
window.location.replace(`${redirectUrl}${route}`)
}
} else {
/**没有账号 */
window.location.replace(`${url}common/nothing`)
}
} else {
/**账号过期 (暂时没有字段判断是否过期) */
window.vm.showToast(message)
window.location.replace(`${url}common/overdue`)
}
})
} else {
util.showLoading()
let corpId = getParams('corpId') //从链接获取
if (!corpId) corpId = 'ww7ee69c648ae1b7e6'
util.setLocalStorage('dj_scrm_corpId', corpId)
// 'ww657a2d4ae89a4424'
const wxUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize'
window.location.replace(`${wxUrl}?appid=${corpId}&redirect_uri=${encodeURIComponent(redirectUrl)}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`)
} }
},
navigation({ dispatch }) {
util.showLoading()
const sessionId = getParams('sessionId')
const storage_sessionId = util.getLocalStorage('dj_scrm_session_id')
if (sessionId || storage_sessionId) {
state.showWindow = true
util.setLocalStorage('dj_scrm_session_id', sessionId || storage_sessionId)
} else {
dispatch('login')
return
}
state.showWindow = true
}
}
const getParams = name => {
let [url, paramsList] = window.location.href.split('?')
if (!paramsList) return name ? null : {}
let param = paramsList.split('&')
let obj = {}
param.map(e => {
let [key, value] = e.split('=')
obj[key] = value
})
return name ? obj[name] : obj
} }
export default { export default {
state, state,
......
<!-- home --> <!-- home -->
<template> <template>
<div class="container"> <div class="container">
<template v-if="showWindow">
<transition name="fade">
<keep-alive v-if="$route.meta.keepAlive"> <keep-alive v-if="$route.meta.keepAlive">
<router-view></router-view> <router-view></router-view>
</keep-alive> </keep-alive>
<router-view v-else></router-view> </transition>
<transition name="fade">
<router-view v-if="!$route.meta.keepAlive"></router-view>
</transition>
<template v-if="$route.meta.isTab">
<tab-bar :data="tabList"></tab-bar>
</template>
</template>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
data () { data () {
return { return {
showWindow: false
} }
}, },
computed: {}, watch: {
watchFlag: {
immediate: true,
handler (newval) {
this.showWindow = newval
this.hideLoading()
}
}
},
computed: {
watchFlag () {
return this.$store.state.app.showWindow
}
},
mounted () { mounted () {
}, },
......
...@@ -49,7 +49,10 @@ const spritesmithFunction = data => { ...@@ -49,7 +49,10 @@ const spritesmithFunction = data => {
return `${shared}\n${perSprite}` return `${shared}\n${perSprite}`
} }
module.exports = { module.exports = {
publicPath: './', // 署应用包时的基本 URL。 vue-router hash 模式使用
publicPath: IS_PROD ? './' : '/dj-scrm-wx-work-main/attachment-customer/', // 署应用包时的基本 URL。 vue-router hash 模式使用
// publicPath: IS_PROD ? './' : '/dj-scrm-wx-work-attachment-customer/', // 署应用包时的基本 URL。 vue-router hash 模式使用
// publicPath: '/dj-scrm-wx-work-attachment-customer/', // 署应用包时的基本 URL。 vue-router history模式使用 // publicPath: '/dj-scrm-wx-work-attachment-customer/', // 署应用包时的基本 URL。 vue-router history模式使用
outputDir: 'dist', // 生产环境构建文件的目录 outputDir: 'dist', // 生产环境构建文件的目录
assetsDir: 'static', // outputDir的静态资源(js、css、img、fonts)目录 assetsDir: 'static', // outputDir的静态资源(js、css、img、fonts)目录
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!