能效诊断
This commit is contained in:
@@ -0,0 +1,246 @@
|
||||
import axios from 'axios'
|
||||
// import { getToken } from './auth';
|
||||
import Vue from 'vue'
|
||||
import store from '@/store'
|
||||
// import { Encrypt, Decrypt} from '@/utils/secret.js'
|
||||
import { encryptStr } from 'pwd-restclient'
|
||||
|
||||
const service = axios.create({
|
||||
baseURL: process.env.NODE_ENV === 'development' ? process.env.VUE_APP_BASE_API : '',
|
||||
timeout: 50000 // request timeout
|
||||
})
|
||||
// service.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
||||
// service.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
||||
// request拦截器
|
||||
service.interceptors.request.use(config => {
|
||||
return config
|
||||
}, error => {
|
||||
console.log(error)
|
||||
Promise.reject(error)
|
||||
})
|
||||
service.interceptors.response.use(
|
||||
response => {
|
||||
const res = response.data
|
||||
if (res.code == '-1') {
|
||||
const toast = Toast.$create({
|
||||
txt: res.message,
|
||||
type: 'error'
|
||||
})
|
||||
toast.show()
|
||||
setTimeout(() => {
|
||||
toast.hide()
|
||||
}, 3000)
|
||||
}
|
||||
return res
|
||||
},
|
||||
error => {
|
||||
const toast = Toast.$create({
|
||||
txt: error.message || '系统接口请求异常',
|
||||
type: 'error'
|
||||
})
|
||||
toast.show()
|
||||
setTimeout(() => {
|
||||
toast.hide()
|
||||
}, 3000)
|
||||
// alert(result.message)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
const keyValue = (params) => {
|
||||
var str = ''
|
||||
for (const key in params) {
|
||||
if (Object.hasOwnProperty.call(params, key)) {
|
||||
if (typeof params[key] === 'string') {
|
||||
str += `"${key}":"${params[key]}",`
|
||||
} else if (typeof params[key] === 'number') {
|
||||
str += `"${key}":${params[key]},`
|
||||
} else if (typeof params[key] === 'object') {
|
||||
str += `"${key}":${JSON.stringify(params[key])},`
|
||||
}
|
||||
}
|
||||
}
|
||||
return str.substring(0, str.length - 1)
|
||||
}
|
||||
export function callApi(funName, params) {
|
||||
// debugger
|
||||
let userInfo = store.state.user.userInfo || {}
|
||||
|
||||
if(params){
|
||||
params['partyActType']=store.state.user.partyActType || ''
|
||||
params['erpId']=userInfo.sapUserId || null
|
||||
}else{
|
||||
params={
|
||||
partyActType:store.state.user.partyActType || '',
|
||||
erpId:userInfo.sapUserId || ''
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// if (sessionStorage.getItem('USER_INFO')) {
|
||||
// userInfo = JSON.parse(sessionStorage.getItem('USER_INFO'))
|
||||
// } else {
|
||||
// userInfo = store.getters['d2admin/user/userInfo']
|
||||
// }
|
||||
// console.log('==>请求:', userInfo)
|
||||
const requsetParams = {
|
||||
...params || params,
|
||||
fun_code: funName
|
||||
// userId:userInfo.id
|
||||
// habitId: userInfo.appuserid || '',
|
||||
// habitName: userInfo.username || ''
|
||||
}
|
||||
|
||||
const requsetParams1 = {
|
||||
...requsetParams
|
||||
}
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
// to do
|
||||
// test cordova ready
|
||||
// if (process.env.VUE_APP_TEST === '1') {
|
||||
// return service({
|
||||
// url: 'https://mam1.ft-power.com.cn:10030/xtkb-web/djAction.do',
|
||||
// method: 'post',
|
||||
// data: requsetParams1
|
||||
// })
|
||||
// }
|
||||
return new Promise((resolve, reject) => {
|
||||
function success(result) {
|
||||
if(typeof result !== 'string' && result.code){
|
||||
resolve(result)
|
||||
}
|
||||
else{
|
||||
reject(result)
|
||||
}
|
||||
}
|
||||
let appCode = 'JSINTXTKB',
|
||||
params;
|
||||
if(process.env.VUE_APP_ENV === '0'){ //走测试, 电科院加密
|
||||
params = {"data":encryptStr(JSON.stringify(requsetParams1))}
|
||||
console.log('加密前参数:', requsetParams1)
|
||||
}else{
|
||||
params = {"data":Encrypt(JSON.stringify(requsetParams1))}
|
||||
}
|
||||
// mam.navigator.ajax.post(appCode, params, '/xtkb-web/djAction.do', success)
|
||||
try{
|
||||
mam.navigator.ajax.postJSON(appCode, params, '/xtkb-web/djAction.do', success)
|
||||
}catch (e){
|
||||
reject(e)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
keyValue(requsetParams1)
|
||||
// Encrypt()
|
||||
const str = '{' + keyValue(requsetParams1) + '}'
|
||||
// const str = 'data='+Encrypt(str)
|
||||
// 加密
|
||||
// const a = process.env.VUE_APP_ISENCRYPTION === 'yes' ? Encrypt(str) : str
|
||||
//let a = "data="+Encrypt(str)
|
||||
// 不加密
|
||||
// let a = "data="+str
|
||||
return service({
|
||||
url: 'xtkb-web/djAction.do',
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
data: 'data=' + str
|
||||
// data: Encrypt(str)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function fileDown (downLoadUrl, fileName, id,data) {
|
||||
// 测试app
|
||||
|
||||
// let url = `https://mam.zeus2.top:10030/xtkb-web/file/fileDownload?id=${downLoadUrl}`
|
||||
// const url = `https://mamjs.sgcc.com.cn:10443/xtkb-web/file/fileDownload?id=${downLoadUrl}`
|
||||
//正式app
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
let url = `/xtkb-web/file/fileDownload?id=${downLoadUrl}`
|
||||
mam.navigator.appfilemanage.openFile(url, fileName);
|
||||
}else{
|
||||
|
||||
}
|
||||
// // let url = `https://mamjs.sgcc.com.cn:10443/xtkb-web/file/fileDownload?id=${downLoadUrl}`
|
||||
// function success (result) {
|
||||
// let type = result.data.event
|
||||
// switch (type) {
|
||||
// case 'fail':
|
||||
// Toast.$create({
|
||||
// txt: '下载失败',
|
||||
// type: 'error'
|
||||
// }).show();
|
||||
// break;
|
||||
// case 'progress':
|
||||
// Toast.$create({
|
||||
// txt: '正在下载',
|
||||
// type: 'warn'
|
||||
// }).show();
|
||||
// break;
|
||||
// case 'success':
|
||||
// Toast.$create({
|
||||
// txt: '下载成功',
|
||||
// type: 'success'
|
||||
// }).show();
|
||||
// // let urlData = result.fileUrl.split('/serverfile')
|
||||
// // let newUrl
|
||||
// // if (urlData.length === 2) {
|
||||
// // newUrl = urlData[0] + '/serverfile/' + fileName
|
||||
// // } else {
|
||||
// // newUrl = result.fileUrl
|
||||
// // }
|
||||
// // let dataUrl = data.split('data:')
|
||||
// mam.navigator.appfilemanage.openFile(url,fileName);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// // JSINTXTKB
|
||||
// Dialog.$create({
|
||||
// type: 'confirm',
|
||||
// icon: 'cubeic-alert',
|
||||
// title: '文件',
|
||||
// content: '是否下载文件',
|
||||
// confirmBtn: {
|
||||
// text: '确定下载',
|
||||
// active: true,
|
||||
// disabled: false,
|
||||
// href: 'javascript:;'
|
||||
// },
|
||||
// cancelBtn: {
|
||||
// text: '取消下载',
|
||||
// active: false,
|
||||
// disabled: false,
|
||||
// href: 'javascript:;'
|
||||
// },
|
||||
// onConfirm: () => {
|
||||
// // JSINTXTWZS
|
||||
// mam.navigator.appfilemanage.fileDownload2(success, 'JSINTXTWZS', '', url, '/serverfile', fileName, id, { id: id })
|
||||
// },
|
||||
// onCancel: () => {
|
||||
// }
|
||||
// }).show()
|
||||
}
|
||||
// function diyDownload()
|
||||
// {
|
||||
|
||||
// var filename = 'xtkb.doc';
|
||||
// var fileCode = '1_diyFile';
|
||||
|
||||
// var param={fileName:filename};
|
||||
|
||||
// var downLoadUrl = 'https://mam.zeus2.top:10030/xtkb-web/file/fileDownload?path=/domain/upload/xtkb.doc'
|
||||
|
||||
|
||||
// var saveUrl = '/diy';
|
||||
// var fileName='local_'+filename;
|
||||
|
||||
// navigator.appfilemanage.fileDownload2(fileDownloadCallback,'JSINTXTKB','',downLoadUrl,saveUrl,fileName,fileCode,param);
|
||||
|
||||
// }
|
||||
// function fileDownloadCallback(obj) {
|
||||
// console.log("fileDownloadCallback 下载文件 回调 " + JSON.stringify(obj));
|
||||
// }
|
||||
|
||||
export default service
|
||||
Reference in New Issue
Block a user