|
@@ -1,347 +0,0 @@
|
|
|
-import { login, logout } from '@/api/user'
|
|
|
-import { getToken, setToken, removeToken, setSessionStorage, removeSessionStorage } from '@/utils/auth'
|
|
|
-import { imageByName } from '@/api/ftp'
|
|
|
-import { getCommonCode, editDictionary } from '@/api/base'
|
|
|
-import { resetRouter } from '@/router'
|
|
|
-import { encrypt, decrypt } from '@/utils/rsa'
|
|
|
-import { AjaxRequest } from '@/utils/request'
|
|
|
-
|
|
|
-const sha1Hex = require('sha1-hex')
|
|
|
-
|
|
|
-const getDefaultState = () => {
|
|
|
- return {
|
|
|
- token: sessionStorage.getItem('token') || '',
|
|
|
- name: '',
|
|
|
- avatar: '',
|
|
|
- username: '',
|
|
|
- realName: '',
|
|
|
- userId: '',
|
|
|
- departmentId: '',
|
|
|
- applied: false,
|
|
|
- arcgistoken: sessionStorage.getItem('arcgistoken') || ''
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-const state = getDefaultState()
|
|
|
-
|
|
|
-const mutations = {
|
|
|
- RESET_STATE: (state) => {
|
|
|
- Object.assign(state, getDefaultState())
|
|
|
- },
|
|
|
- SET_TOKEN: (state, token) => {
|
|
|
- state.token = token
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- SET_USERNAME: (state, username) => {
|
|
|
- state.username = username
|
|
|
- },
|
|
|
- SET_AVATAR: (state, avatar) => {
|
|
|
- state.avatar = avatar
|
|
|
- },
|
|
|
- SET_REALNAME: (state, realName) => {
|
|
|
- state.realName = realName
|
|
|
- },
|
|
|
- SET_USERID: (state, userId) => {
|
|
|
- state.userId = userId
|
|
|
- },
|
|
|
- SET_DEPTS: (state, departmentId) => {
|
|
|
- state.departmentId = departmentId
|
|
|
- console.log('部门:' + state.departmentId)
|
|
|
- },
|
|
|
- COMPLETE_APPLY: (state, payload) => {
|
|
|
- state.applied = payload
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- SET_ARCGISTOKEN: (state, arcgistoken) => {
|
|
|
- state.arcgistoken = arcgistoken
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-const actions = {
|
|
|
-
|
|
|
- login({ commit, dispatch }, userInfo) {
|
|
|
- const { username, password } = userInfo
|
|
|
-
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- login({ 'username': username, 'password': encrypt(password) }).then(response => {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- const { accessToken, username, avatar, realName, id, departmentId } = response.result
|
|
|
-
|
|
|
-
|
|
|
- console.log('部门编码:' + departmentId)
|
|
|
- commit('SET_TOKEN', accessToken)
|
|
|
- commit('SET_USERNAME', username)
|
|
|
- commit('SET_REALNAME', realName)
|
|
|
- commit('SET_USERID', id)
|
|
|
- commit('SET_DEPTS', departmentId)
|
|
|
- setSessionStorage('token', accessToken)
|
|
|
- setSessionStorage('username', username)
|
|
|
- setSessionStorage('realName', realName)
|
|
|
- setSessionStorage('userId', id)
|
|
|
- setSessionStorage('departmentId', departmentId)
|
|
|
- if (avatar) {
|
|
|
- imageByName(avatar).then(res => {
|
|
|
- if (res.status === 200) {
|
|
|
- commit('SET_AVATAR', res.config.url)
|
|
|
- setSessionStorage('avatar', res.config.url)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- getCommonCode({ pCid: 66560 }).then(data => {
|
|
|
- if (data.code !== -1) {
|
|
|
- const tempAry = data.result[0].codeList
|
|
|
- const arcgisToken = tempAry.filter(item => {
|
|
|
- return item.ccode == 'token'
|
|
|
- })[0].cname
|
|
|
- const arcgisExpires = tempAry.filter(item => {
|
|
|
- return item.ccode == 'expires'
|
|
|
- })[0].cname
|
|
|
-
|
|
|
- let arcgisTokenObject = {}
|
|
|
-
|
|
|
- if (arcgisExpires < Date.now() || true) {
|
|
|
- getCommonCode({ pCid: 66542 }).then(res => {
|
|
|
- if (res.code !== -1) {
|
|
|
- const parmasary = res.result[0].codeList
|
|
|
- debugger
|
|
|
- console.warn('process.envprocess.envprocess.env', process.env)
|
|
|
- let tokenObj = {}
|
|
|
- if (process.env.NODE_ENV != 'production') {
|
|
|
- tokenObj = {
|
|
|
- 'password': '307cc1a58ac82c710c81628660c5b9820cb871a85757bab7f58a016811fddfa03dd9956b5fc83aaaa12c19382a6976623c4754e8874e6172267642ebfaa4f6ee',
|
|
|
- 'f': 'json',
|
|
|
- 'username': '3289197cde837d86981484f7b1aea274f558dd38b345d8d0059b6e22e6b3461ab29c3c9038ec76b665aa82c60a9b8a6e2a068413bdc0ed303201cda521cd88e2',
|
|
|
- 'client': '1025c788afee7e33b4ec72a4ce71802dec7eb35fb625a5822b0432e20b3e304b45c2e3f18ee93939aa2620635e374a118add33dd3bb1e3d5a250c8279c236715',
|
|
|
- 'referer': '',
|
|
|
- 'ip': '',
|
|
|
- 'expiration': 'abacd3ddfe55390e63d6237ebf5bf33faf81491e7174f613dd5c06da4c61756781920e0807c876a046d4f0aef8d334454ac623abcef67b1511afb83041153b5a',
|
|
|
- 'encrypted': 'true'
|
|
|
- }
|
|
|
- } else {
|
|
|
- tokenObj = {
|
|
|
- 'password': parmasary.filter(item => { return item.ccode == 'password' })[0].cname,
|
|
|
- 'f': 'pjson',
|
|
|
- 'username': parmasary.filter(item => { return item.ccode == 'username' })[0].cname,
|
|
|
- 'client': parmasary.filter(item => { return item.ccode == 'client' })[0].cname,
|
|
|
- 'referer': parmasary.filter(item => { return item.ccode == 'referer' })[0].cname,
|
|
|
- 'ip': parmasary.filter(item => { return item.ccode == 'ip' })[0].cname,
|
|
|
- 'expiration': parmasary.filter(item => { return item.ccode == 'expiration' })[0].cname,
|
|
|
- 'encrypted': parmasary.filter(item => { return item.ccode == 'encrypted' })[0].cname
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- AjaxRequest({
|
|
|
- url: 'http://36.138.232.112:6080/arcgis/tokens/generateToken',
|
|
|
- isAsync: false,
|
|
|
- dataType: 'json',
|
|
|
- method: 'POST',
|
|
|
- data: tokenObj
|
|
|
- }, function(result) {
|
|
|
- const ajaxdata = result
|
|
|
- arcgisTokenObject = ajaxdata
|
|
|
- console.log('arcgistoken', ajaxdata)
|
|
|
- if (ajaxdata.token) {
|
|
|
- commit('SET_ARCGISTOKEN', ajaxdata.token)
|
|
|
- setSessionStorage('arcgistoken', ajaxdata.token)
|
|
|
- }
|
|
|
- }).catch(error => {
|
|
|
- throw error
|
|
|
- })
|
|
|
-
|
|
|
- return tempAry
|
|
|
- }
|
|
|
- }).then(data => {
|
|
|
- console.log('参数:', data, arcgisTokenObject, response)
|
|
|
-
|
|
|
- const token = tempAry.filter(item => {
|
|
|
- return item.ccode == 'token'
|
|
|
- })[0]
|
|
|
- token.cname = arcgisTokenObject.token
|
|
|
- const expires = tempAry.filter(item => {
|
|
|
- return item.ccode == 'expires'
|
|
|
- })[0]
|
|
|
- expires.cname = arcgisTokenObject.expires
|
|
|
-
|
|
|
- editDictionary(token).then((res) => {
|
|
|
- return editDictionary(expires)
|
|
|
- }).then((res) => {
|
|
|
- console.log('expires', res)
|
|
|
- resolve(response)
|
|
|
- }).catch(error => {
|
|
|
- reject(error)
|
|
|
- throw error
|
|
|
- })
|
|
|
-
|
|
|
- })
|
|
|
- } else {
|
|
|
- commit('SET_ARCGISTOKEN', arcgisToken)
|
|
|
- setSessionStorage('arcgistoken', arcgisToken)
|
|
|
- resolve(response)
|
|
|
- }
|
|
|
- }
|
|
|
- }).catch(error => {
|
|
|
- throw error
|
|
|
- })
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }).catch(error => {
|
|
|
- reject(error)
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- logout({ commit, state, dispatch }) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- const data = {
|
|
|
- token: state.token
|
|
|
- }
|
|
|
- logout(data).then(() => {
|
|
|
-
|
|
|
- removeSessionStorage('token')
|
|
|
- removeSessionStorage('username')
|
|
|
- removeSessionStorage('avatar')
|
|
|
- removeSessionStorage('realName')
|
|
|
- removeSessionStorage('userId')
|
|
|
- removeSessionStorage('departmentId')
|
|
|
- removeSessionStorage('last-route')
|
|
|
- resetRouter()
|
|
|
- commit('RESET_STATE')
|
|
|
- dispatch('tagsView/loginOutdel', {}, { root: true })
|
|
|
- dispatch('routeSetting/loginOutdel', {}, { root: true })
|
|
|
- resolve()
|
|
|
- }).catch(error => {
|
|
|
- reject(error)
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- resetToken({ commit }) {
|
|
|
- return new Promise(resolve => {
|
|
|
-
|
|
|
- removeSessionStorage('token')
|
|
|
- removeSessionStorage('avatar')
|
|
|
- removeSessionStorage('username')
|
|
|
- removeSessionStorage('realName')
|
|
|
- removeSessionStorage('userId')
|
|
|
- removeSessionStorage('departmentId')
|
|
|
- removeSessionStorage('last-route')
|
|
|
- commit('RESET_STATE')
|
|
|
- resolve()
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- finnishApply({ commit }, status) {
|
|
|
- commit('COMPLETE_APPLY', status)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-export default {
|
|
|
- namespaced: true,
|
|
|
- state,
|
|
|
- mutations,
|
|
|
- actions
|
|
|
-}
|
|
|
-
|