Browse Source

Merge remote-tracking branch 'origin/master'

master
ygs 4 months ago
parent
commit
cb644fc9ba
  1. 10
      src/api/baseinf.js
  2. 118
      src/utils/request.js
  3. 2
      src/views/sanshengjiaohui/index.vue
  4. 157
      vue.config.js

10
src/api/baseinf.js

@ -0,0 +1,10 @@
import request from '@/utils/request'
// 查询【请填写功能名称】列表
export function listBaseinf(query) {
return request({
url: '/system/baseinf/list',
method: 'get',
params: query
})
}

118
src/utils/request.js

@ -0,0 +1,118 @@
import axios from 'axios'
import { Notification, MessageBox, Message, Loading } from 'element-ui'
let downloadLoadingInstance;
axios.defaults.headers['Conntent-Type'] = 'application/json;charset=utf-8'
// 创建axios实例
const service = axios.create({
// axios中请求配置有baseURL选项,表示请求URL公共部分
baseURL: '/',
// 超时
timeout: 300000
// timeout: 10000
})
// request拦截器
service.interceptors.request.use(config => {
// // 是否需要设置 token
// const isToken = (config.headers || {}).isToken === false
// if (getToken() && !isToken) {
// config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
// }
// // get请求映射params参数
// if (config.method === 'get' && config.params) {
// let url = config.url + '?' + tansParams(config.params);
// url = url.slice(0, -1);
// config.params = {};
// config.url = url;
// }
return config
}, error => {
console.log(error)
Promise.reject(error)
})
// 响应拦截器
service.interceptors.response.use(res => {
// 未设置状态码则默认成功状态
const code = res.data.code || 200;
// 获取错误信息
const msg = errorCode[code] || res.data.msg || errorCode['default']
// 二进制数据则直接返回
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
return res.data
}
if (code === 401) {
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
}
).then(() => {
store.dispatch('LogOut').then(() => {
location.href = '/index';
})
}).catch(() => { });
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
} else if (code === 500) {
Message({
message: msg,
type: 'error'
})
return Promise.reject(new Error(msg))
} else if (code !== 200) {
Notification.error({
title: msg
})
return Promise.reject('error')
} else {
return res.data
}
},
error => {
console.log('err' + error)
let { message } = error;
if (message == "Network Error") {
message = "后端接口连接异常";
}
else if (message.includes("timeout")) {
message = "系统接口请求超时";
}
else if (message.includes("Request failed with status code")) {
message = "系统接口" + message.substr(message.length - 3) + "异常";
}
Message({
message: message,
type: 'error',
duration: 5 * 1000
})
return Promise.reject(error)
}
)
// 通用下载方法
export function download(url, params, filename) {
downloadLoadingInstance = Loading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", })
return service.post(url, params, {
transformRequest: [(params) => { return tansParams(params) }],
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
responseType: 'blob'
}).then(async (data) => {
const isLogin = await blobValidate(data);
if (isLogin) {
const blob = new Blob([data])
saveAs(blob, filename)
} else {
Message.error('无效的会话,或者会话已过期,请重新登录。');
}
downloadLoadingInstance.close();
}).catch((r) => {
console.error(r)
Message.error('下载文件出现错误,请联系管理员!')
downloadLoadingInstance.close();
})
}
export default service

2
src/views/sanshengjiaohui/index.vue

@ -155,7 +155,7 @@
</div>
</template>
<script>
import { getEchartInstance } from "./components/bigScreen";
import { getEchartInstance } from "../../api/jczh";
export default {
name:'three',
data(){

157
vue.config.js

@ -1,20 +1,153 @@
'use strict'
const path = require('path')
function resolve(dir) {
return path.join(__dirname, dir)
}
const name = process.env.VUE_APP_TITLE || '' // 网页标题
const port = process.env.port || process.env.npm_config_port || 80 // 端口
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const cesiumSource = 'node_modules/mars3d-cesium/Build/Cesium/'
const otherSource = 'src/'
module.exports = {
configureWebpack: {
resolve: {
alias: {
'@src': require('path').resolve(__dirname, 'src'), // 配置别名 '@src' 指向 'src' 目录
},
},
},
chainWebpack: config => {
config.plugin('provide').use(webpack.ProvidePlugin, [{
$: 'jquery',
jquery: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}])
}
}
// vue.config.js 配置说明
//官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions
// 这里只列一部分,具体配置参考文档
module.exports = {
// 部署生产环境和开发环境下的URL。
// 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
// 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
// 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist)
outputDir: 'dist',
// 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)
assetsDir: 'static',
// 是否开启eslint保存检测,有效值:ture | false | 'error'
lintOnSave: process.env.NODE_ENV === 'development',
// 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
productionSourceMap: process.env.NODE_ENV !== "production",
// webpack-dev-server 相关配置
devServer: {
host: '0.0.0.0',
port: port,
open: true,
proxy: {
'/api': {
target: 'http://localhost:3000', // 后端 API 地址
changeOrigin: true, // 是否允许跨域
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
target: process.env.VUE_APP_TARGET || '101.201.110.29:8080',
changeOrigin: true,
pathRewrite: {
'^/api': '', // 重写路径,将 '/api' 移除
['^' + process.env.VUE_APP_BASE_API]: ''
}
}
},
disableHostCheck: true
},
configureWebpack: {
name: name,
devtool: process.env.NODE_ENV === "production" ? false : 'eval-source-map',
//devtool:'source-map',
resolve: {
alias: {
'@': resolve('src')
}
},
plugins: [
new webpack.DefinePlugin({
CESIUM_BASE_URL: JSON.stringify('static')
}),
new CopyWebpackPlugin({
patterns: [{ from: path.join(cesiumSource, 'Workers'), to: 'static/Workers' }]
}),
new CopyWebpackPlugin({
patterns: [{ from: path.join(cesiumSource, 'Assets'), to: 'static/Assets' }]
}),
new CopyWebpackPlugin({
patterns: [{ from: path.join(cesiumSource, 'ThirdParty'), to: 'static/ThirdParty' }]
}),
new CopyWebpackPlugin({
patterns: [{ from: path.join(cesiumSource, 'Widgets'), to: 'static/Widgets' }]
}),
// new CopyWebpackPlugin({
// patterns: [{from: path.join(otherSource, 'data/3dtiles'), to: 'static/data/3dtiles'}]
// }),
]
},
chainWebpack(config) {
config.plugins.delete('preload') // TODO: need test
config.plugins.delete('prefetch') // TODO: need test
// set svg-sprite-loader
config.module
.rule('svg')
.exclude.add(resolve('src/assets/icons'))
.end()
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('src/assets/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
.end()
config
.when(process.env.NODE_ENV !== 'development',
config => {
config
.plugin('ScriptExtHtmlWebpackPlugin')
.after('html')
.use('script-ext-html-webpack-plugin', [{
// `runtime` must same as runtimeChunk name. default is `runtime`
inline: /runtime\..*\.js$/
}])
.end()
config
.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
libs: {
name: 'chunk-libs',
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: 'initial' // only package third parties that are initially dependent
},
elementUI: {
name: 'chunk-elementUI', // split elementUI into a single package
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
},
};
commons: {
name: 'chunk-commons',
test: resolve('src/components'), // can customize your rules
minChunks: 3, // minimum common number
priority: 5,
reuseExistingChunk: true
}
}
})
config.optimization.runtimeChunk('single'),
{
from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
to: './', //到根目录下
}
}
)
}
}

Loading…
Cancel
Save