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

添加vuex和配置axios

parent 113570f6
......@@ -10,9 +10,9 @@
font-size: 1.6vh;
}
</style>
<!-- <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='https://api.map.baidu.com/api?v=2.0&ak=MvCb6BWu4jHR9TD0svHfO4bWlx9pA9HG'></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='https://api.map.baidu.com/api?v=2.0&ak=MvCb6BWu4jHR9TD0svHfO4bWlx9pA9HG'></script> -->
</head>
<body>
<div id="app"></div>
......
......@@ -13382,6 +13382,11 @@
"integrity": "sha1-HuO8mhbsv1EYvjNLsV+cRvgvWCU=",
"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": {
"version": "1.6.0",
"resolved": "https://registry.npm.taobao.org/watchpack/download/watchpack-1.6.0.tgz",
......
......@@ -27,7 +27,8 @@
"vue-countup-v2": "^4.0.0",
"vue-odometer": "^1.0.2",
"vue-router": "^3.0.1",
"vue-seamless-scroll": "^1.1.17"
"vue-seamless-scroll": "^1.1.17",
"vuex": "^3.1.2"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
......
<template>
<div id="app">
<!-- <transition name="custom-classes-transition" enter-active-class="animated fadeIn" leave-active-class="animated fadeOut"> -->
<router-view :key="$route.fullPath"/>
<!-- </transition> -->
</div>
</template>
<script>
export default {
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>
......
......@@ -4,8 +4,9 @@ import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
// 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 ajax from '@/server/ajax'
import api from '@/server/api'
......@@ -40,21 +41,11 @@ Vue.use(MonitorForm)
Vue.use(MonitorTable)
Vue.component('Row', Row)
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 */
new Vue({
el: '#app',
router,
store,
components: { App },
template: '<App/>'
})
import axios from 'axios'
import qs from 'qs'
import api from './api'
import Store from '@/store'
const Axios = axios.create({
baseURL: api.BASE_URL,
timeout: 50000,
timeout: 15000,
})
Axios.interceptors.request.use(config => {
// 启动loading,添加token
// 添加token
// config.headers.Authorization = token
return config
}, error => {
......@@ -16,32 +17,62 @@ Axios.interceptors.request.use(config => {
Axios.interceptors.response.use(response => {
// TODO 返回的数据status判断错误操作等……
Store.commit('SET_LOADING', false)
return response.data
}, error => {
Store.commit('SET_LOADING', false)
return Promise.resolve(error.response)
})
export default {
post(url, data) {
return Axios({
method: 'POST',
url,
data: qs.stringify(data),
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
/**
* 请求
* @param {String} method [请求方法]
* @param {String} url [请求地址]
* @param {Object} params [请求参数]
* @param {String} contentType [请求头,默认为'application/json;charset=UTF-8']
* @param {Boolean} showLoading [是否显示请求时的loading图,默认为true]
*/
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)
},
get(url, params) {
return Axios({
method: 'GET',
let config = {
method,
url,
params, // get 请求时带的参数
headers: {
'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 {
BASE_URL: 'http://sunmonster.vicp.cc:41318/pudong/',
IMG_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 @@
</template>
<script>
// const {ShsmiGis} = window
import BaiduMap from './components/baidu'
const {ShsmiGis} = window
// import BaiduMap from './components/baidu'
import ThemeTitle from './components/title'
import DayCheckSituation from './components/day-check-situation'
import ThemeList from './components/theme-list'
......@@ -62,7 +62,7 @@ import MapOperate from './components/map-operate'
export default {
name: 'Main',
components: {
BaiduMap,
// BaiduMap,
ThemeTitle,
DayCheckSituation,
ThemeList,
......@@ -241,7 +241,7 @@ export default {
}
},
mounted() {
// this.$nextTick(this.initMap)
this.$nextTick(this.initMap)
},
methods: {
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