Commit 40b73871 authored by 郭铭瑶's avatar 郭铭瑶 🤘

添加vuex和配置axios

parent 113570f6
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
font-size: 1.6vh; font-size: 1.6vh;
} }
</style> </style>
<!-- <script src="./static/jquery.min.js"></script> <script src="./static/jquery.min.js"></script>
<script type='text/javascript' src='http://168.168.112.76:8181/smimap/ShsmiGis.Bridge.js'></script> --> <script type='text/javascript' src='http://168.168.112.76:8181/smimap/ShsmiGis.Bridge.js'></script>
<script type='text/javascript' src='https://api.map.baidu.com/api?v=2.0&ak=MvCb6BWu4jHR9TD0svHfO4bWlx9pA9HG'></script> <!-- <script type='text/javascript' src='https://api.map.baidu.com/api?v=2.0&ak=MvCb6BWu4jHR9TD0svHfO4bWlx9pA9HG'></script> -->
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
......
...@@ -13382,6 +13382,11 @@ ...@@ -13382,6 +13382,11 @@
"integrity": "sha1-HuO8mhbsv1EYvjNLsV+cRvgvWCU=", "integrity": "sha1-HuO8mhbsv1EYvjNLsV+cRvgvWCU=",
"dev": true "dev": true
}, },
"vuex": {
"version": "3.1.2",
"resolved": "https://registry.npm.taobao.org/vuex/download/vuex-3.1.2.tgz",
"integrity": "sha1-ooY/QAWqc/JYflXD+t8/AfacfU0="
},
"watchpack": { "watchpack": {
"version": "1.6.0", "version": "1.6.0",
"resolved": "https://registry.npm.taobao.org/watchpack/download/watchpack-1.6.0.tgz", "resolved": "https://registry.npm.taobao.org/watchpack/download/watchpack-1.6.0.tgz",
......
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
"vue-countup-v2": "^4.0.0", "vue-countup-v2": "^4.0.0",
"vue-odometer": "^1.0.2", "vue-odometer": "^1.0.2",
"vue-router": "^3.0.1", "vue-router": "^3.0.1",
"vue-seamless-scroll": "^1.1.17" "vue-seamless-scroll": "^1.1.17",
"vuex": "^3.1.2"
}, },
"devDependencies": { "devDependencies": {
"autoprefixer": "^7.1.2", "autoprefixer": "^7.1.2",
......
<template> <template>
<div id="app"> <div id="app">
<!-- <transition name="custom-classes-transition" enter-active-class="animated fadeIn" leave-active-class="animated fadeOut"> -->
<router-view :key="$route.fullPath"/> <router-view :key="$route.fullPath"/>
<!-- </transition> -->
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name: 'App', name: 'App',
// data() {
// return {
// routes: ['farming', 'fishing'],
// cur: 0,
// timer: null,
// timeOuter: null,
// seconds: 1000 * 10
// }
// },
// mounted() {
// // this.$router.push({
// // name: this.routes[this.cur]
// // })
// this.$router.replace({
// name: this.routes[this.cur]
// })
// this.setTimer()
// document.body.addEventListener('mousemove', this.removeTimer)
// },
// beforeDestroy() {
// clearInterval(this.timer)
// document.body.removeEventListener('mousemove')
// },
// methods: {
// setTimer() {
// this.timer = setInterval(() => {
// this.cur += 1
// if (this.cur >= this.routes.length) {
// this.cur = 0
// }
// this.$router.push({
// name: this.routes[this.cur]
// })
// }, this.seconds)
// },
// removeTimer() {
// clearTimeout(this.timeOuter)
// clearInterval(this.timer)
// this.timer = null
// this.timeOuter = setTimeout(this.setTimer, this.seconds / 10)
// },
// },
} }
</script> </script>
......
...@@ -4,8 +4,9 @@ import 'babel-polyfill' ...@@ -4,8 +4,9 @@ import 'babel-polyfill'
import Vue from 'vue' import Vue from 'vue'
import App from './App' import App from './App'
import router from './router' import router from './router'
import store from './store'
// import echarts from 'echarts' // import echarts from 'echarts'
import {Row, Col, Button, Divider, Progress, Select, Option, Circle, Icon, Dropdown, DropdownMenu, DropdownItem} from 'view-design' import {Row, Col} from 'view-design'
import animate from 'animate.css' import animate from 'animate.css'
import ajax from '@/server/ajax' import ajax from '@/server/ajax'
import api from '@/server/api' import api from '@/server/api'
...@@ -40,21 +41,11 @@ Vue.use(MonitorForm) ...@@ -40,21 +41,11 @@ Vue.use(MonitorForm)
Vue.use(MonitorTable) Vue.use(MonitorTable)
Vue.component('Row', Row) Vue.component('Row', Row)
Vue.component('i-col', Col) Vue.component('i-col', Col)
Vue.component('Button', Button)
Vue.component('Divider', Divider)
Vue.component('Progress', Progress)
Vue.component('Select', Select)
Vue.component('Option', Option)
Vue.component('i-circle', Circle)
Vue.component('Icon', Icon)
Vue.component('Dropdown', Dropdown)
Vue.component('DropdownMenu', DropdownMenu)
Vue.component('DropdownItem', DropdownItem)
/* eslint-disable no-new */ /* eslint-disable no-new */
new Vue({ new Vue({
el: '#app', el: '#app',
router, router,
store,
components: { App }, components: { App },
template: '<App/>' template: '<App/>'
}) })
import axios from 'axios' import axios from 'axios'
import qs from 'qs' import qs from 'qs'
import api from './api' import api from './api'
import Store from '@/store'
const Axios = axios.create({ const Axios = axios.create({
baseURL: api.BASE_URL, baseURL: api.BASE_URL,
timeout: 50000, timeout: 15000,
}) })
Axios.interceptors.request.use(config => { Axios.interceptors.request.use(config => {
// 启动loading,添加token // 添加token
// config.headers.Authorization = token // config.headers.Authorization = token
return config return config
}, error => { }, error => {
...@@ -16,32 +17,62 @@ Axios.interceptors.request.use(config => { ...@@ -16,32 +17,62 @@ Axios.interceptors.request.use(config => {
Axios.interceptors.response.use(response => { Axios.interceptors.response.use(response => {
// TODO 返回的数据status判断错误操作等…… // TODO 返回的数据status判断错误操作等……
Store.commit('SET_LOADING', false)
return response.data return response.data
}, error => { }, error => {
Store.commit('SET_LOADING', false)
return Promise.resolve(error.response) return Promise.resolve(error.response)
}) })
export default { /**
post(url, data) { * 请求
return Axios({ * @param {String} method [请求方法]
method: 'POST', * @param {String} url [请求地址]
url, * @param {Object} params [请求参数]
data: qs.stringify(data), * @param {String} contentType [请求头,默认为'application/json;charset=UTF-8']
headers: { * @param {Boolean} showLoading [是否显示请求时的loading图,默认为true]
'X-Requested-With': 'XMLHttpRequest', */
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', const request = ({ method, url, params = {}, contentType = 'application/json;charset=UTF-8', showLoading = true }) => {
if (!url || typeof(url) != 'string') {
throw new Error('接口URL不正确')
} }
}).then(res => res) let config = {
}, method,
get(url, params) {
return Axios({
method: 'GET',
url, url,
params, // get 请求时带的参数
headers: { headers: {
'X-Requested-With': 'XMLHttpRequest', 'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json;charset=UTF-8', 'Content-Type': contentType,
},
}
if (method === 'GET') {
config = Object.assign(config, { params })
} else {
if (contentType.toLowerCase().indexOf('x-www-form-urlencoded') >= 0) {
config = Object.assign(config, { data: qs.stringify(params) })
} else {
config = Object.assign(config, { data: params })
}
} }
}).then(res => res) if (showLoading) {
Store.commit('SET_LOADING', true)
} }
return Axios(config)
}
export default {
get(args) {
return request({ method: 'GET', ...args })
},
post(args) {
return request({ method: 'POST', ...args })
},
put(args) {
return request({ method: 'PUT', ...args })
},
delete(args) {
return request({ method: 'DELETE', ...args })
},
all(...ajaxs) {
return Promise.all(ajaxs)
},
} }
...@@ -13,12 +13,4 @@ export default { ...@@ -13,12 +13,4 @@ export default {
BASE_URL: 'http://sunmonster.vicp.cc:41318/pudong/', BASE_URL: 'http://sunmonster.vicp.cc:41318/pudong/',
IMG_URL, IMG_URL,
FILE_URL, FILE_URL,
GET_SMART_INFO: '/api/discoverInfo',
GET_SMART_DETAIL: '/api/discoverDetail',
GET_TS_LIST: '/api/findUnCaseTsList',
GET_BX_LIST: '/api/findUnCaseBxList',
GET_COMPANY_CYCLE: '/api/findCycle',
GET_CREDIT_HIGH: '/api/findCreditHigh',
GET_CREDIT_MIDDLE: '/api/findCreditMiddle',
GET_CREDIT_LOW: '/api/findCreditLow',
} }
export default {
}
import Vue from 'vue'
import Vuex from 'vuex'
import state from './state'
import actions from './actions'
import mutations from './mutations'
Vue.use(Vuex)
const isDev = process.env.NODE_ENV === 'development'
export default new Vuex.Store({
strict: isDev,
state,
actions,
mutations,
})
export default {
SET_LOADING(state, val) {
state.showLoading = val
},
}
export default {
showLoading: false,
}
...@@ -50,8 +50,8 @@ ...@@ -50,8 +50,8 @@
</template> </template>
<script> <script>
// const {ShsmiGis} = window const {ShsmiGis} = window
import BaiduMap from './components/baidu' // import BaiduMap from './components/baidu'
import ThemeTitle from './components/title' import ThemeTitle from './components/title'
import DayCheckSituation from './components/day-check-situation' import DayCheckSituation from './components/day-check-situation'
import ThemeList from './components/theme-list' import ThemeList from './components/theme-list'
...@@ -62,7 +62,7 @@ import MapOperate from './components/map-operate' ...@@ -62,7 +62,7 @@ import MapOperate from './components/map-operate'
export default { export default {
name: 'Main', name: 'Main',
components: { components: {
BaiduMap, // BaiduMap,
ThemeTitle, ThemeTitle,
DayCheckSituation, DayCheckSituation,
ThemeList, ThemeList,
...@@ -241,7 +241,7 @@ export default { ...@@ -241,7 +241,7 @@ export default {
} }
}, },
mounted() { mounted() {
// this.$nextTick(this.initMap) this.$nextTick(this.initMap)
}, },
methods: { methods: {
initMap() { initMap() {
......
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