123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- function isLocalEnv() {
- let domain = window.location.origin
- if (['http://127.0.0.1:5501', 'file://'].includes(domain)) {
- return true
- } else {
- return false
- }
- }
- window.apiType = "uat"
- window.fetchUrl = ""
- window.user = "18335173447"
- if (window.apiType == "dev") {
- window.fetchUrl = "http://192.168.1.12:8080"
- } else if (window.apiType == "sit") {
- window.fetchUrl = "http://172.21.9.236:8081"
- } else if (window.apiType == "uat") {
- window.fetchUrl = "http://172.21.12.247:8081"
- } else if(window.apiType == "prod"){
- window.fetchUrl = "http://172.21.12.244:8081"
- }
- function getApiUrl() {
-
- if (!isLocalEnv()) {
- return window.location.origin
- } else {
-
-
-
-
-
-
-
-
-
- return 'http:192.168.1.60:8081'
- }
- }
- function getWsUrl() {
- let prefix = location.protocol === 'https:' ? 'wss://' : 'ws://'
-
- if (!isLocalEnv()) {
- return prefix + window.location.host
- } else {
- return prefix + 'sxtc.com:10002'
-
- }
- }
- function getMinioUrl() {
- let isProduction = location.origin.indexOf('1.71.170.214') != -1
- if (isProduction) {
- return 'http://1.71.170.214:19000/constr-documents/'
- } else {
- return 'http://10.8.8.191:9000/constr-documents-test/'
- }
- }
- const httpRequest = axios.create({
- baseURL: 'http:192.168.1.60:8081',
- timeout: 3 * 60 * 1000,
- withCredentials: true
- })
- httpRequest.interceptors.request.use(
- function (config) {
- if (!isLocalEnv()) {
- if (getQueryVariable('token')) {
- config.headers['access_token'] = getQueryVariable('token')
- }
- } else {
- config.headers['access_token'] = localStorage.getItem('token')
-
- }
-
- if (config.url == '/apiSys/oss/upload') {
- config.headers['Content-Type'] = 'multipart/form-data'
- } else {
- config.headers['Content-Type'] = 'application/json'
- }
- return config
- },
- function (error) {
- return Promise.reject(error)
- }
- )
- httpRequest.interceptors.response.use(
- function (response) {
- const res = response.data
-
-
-
-
-
-
-
-
-
- return response
- },
- function (error) {
- this.ELEMENT.Message.error(error.message)
- return Promise.reject(error)
- }
- )
- function get(url, params) {
- return new Promise((resolve, reject) => {
- httpRequest
- .get(url, { params: params })
- .then(res => {
- resolve(res.data)
- })
- .catch(err => {
- reject(err.data)
- })
- })
- }
- function post(url, data, config) {
- return new Promise((resolve, reject) => {
- httpRequest
- .post(url, data, config)
- .then(res => {
- resolve(res.data)
- })
- .catch(err => {
- reject(err)
- })
- })
- }
- function postFile(url, blob) {
- return new Promise((resolve, reject) => {
- let formdata = new FormData()
- formdata.append('multipartFile', blob)
- httpRequest
- .post(url, formdata)
- .then(res => {
- resolve(res.data)
- })
- .catch(err => {
- reject(err)
- })
- })
- }
- function localEnvLogin() {
- post(
- '/ierp/api/getAppToken.do',
- {
- username: 'admin',
- password: '1q2w3e4r5t'
- },
- {
- transformRequest: [
- function (data, headers) {
-
- headers['Content-Type'] = 'application/x-www-form-urlencoded'
- return stringify(data)
- }
- ]
- }
- ).then(res => {
- localStorage.setItem('token', res.data.token || getQueryVariable('token'))
- })
- }
- function localEnvAppToken() {
- return new Promise((resole, reject) => {
- let data
- if (window.apiType == "dev") {
- data = {
- appId: "jsc",
- appSecuret: "G|s26?hAW1TzX5rY",
- tenantid: "jmdev",
- accountId: "1541173495969351680",
- }
- } else if (window.apiType == "sit") {
- data = {
- appId: "jsc",
- appSecuret: "OA9#'Jn'4p|f`nBG",
- tenantid: "dev",
- accountId: "1493393884158362624",
- }
- } else if (window.apiType == "uat") {
- data = {
- appId: "jsc",
- appSecuret: "Cs?9HeKqacN%gnu3",
- tenantid: "jmuatierp",
- accountId: "1507348433172694016",
- }
- } else if(window.apiType == "prod") {
- data = {
- appId: "jsc",
- appSecuret: '{Li$d73F13x"+ASb',
- tenantid: "jmierp",
- accountId: "1507155316804943872",
- }
- }else {
- console.log("未知类型");
- return
- }
- fetch(fetchUrl + "/ierp/api/getAppToken.do", {
- method: "post",
- body: JSON.stringify(data),
- timeout: 5000,
- mode: 'cors'
- }).then(res => {
- return res.json()
- })
- .catch(error => {
- reject(error)
- })
- .then(response => {
- if (response != undefined) {
- resole(response.data)
- } else {
- reject({ requestType: false })
- }
- });
- })
- };
- function getLocalEnvAccessToken() {
- return new Promise((resole, reject) => {
- let data
- if (window.apiType == "dev") {
- data = {
- user: "17649834944",
- apptoken: localStorage.getItem("app_token"),
- tenantid: "jmdev",
- accountId: "1541173495969351680",
- usertype: "Mobile",
- }
- } else if (window.apiType == "sit") {
- data = {
- user: window.user,
-
- apptoken: localStorage.getItem("app_token"),
- tenantid: "dev",
- accountId: "1493393884158362624",
- usertype: "Mobile",
- }
- } else if (window.apiType == "uat") {
- data = {
-
- apptoken: localStorage.getItem("app_token"),
-
- tenantid: "jmuatierp",
-
- user: window.user,
- usertype: "Mobile",
- accountId: "1507348433172694016",
- }
- } else if(window.apiType == "prod") {
- data = {
-
- user: window.user,
- usertype: "Mobile",
- apptoken: localStorage.getItem("app_token"),
-
- tenantid: "jmierp",
- accountId: "1507155316804943872",
- }
- } else {
- console.log("未知类型");
- return
- }
- fetch(fetchUrl + "/ierp/api/login.do", {
- method: "post",
- body: JSON.stringify(data),
- mode: 'cors'
- }).then(res => res.json())
- .catch(error => {
- reject(error)
- })
- .then(response => {
- resole(response.data)
- });
- })
- }
- function fetchPostMethods(url, params) {
- return new Promise((resole, reject) => {
- fetch(fetchUrl + url, {
- method: "post",
- body: JSON.stringify(params),
- headers: new Headers({
- "Content-Type": "application/json",
- "accesstoken": localStorage.getItem("access_token"),
- }),
- mode: 'cors'
- }).then(res => {
- return res.json()
- })
- .catch(error => {
- reject(error)
- })
- .then(response => {
- if (response != undefined) {
- resole(response.data)
- }
- });
- })
- }
- function stringify(data) {
- let ret = ''
- for (const it in data) {
- ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
- }
- ret = ret.substring(0, ret.lastIndexOf('&'))
- return ret
- }
- function formatDate(time) {
- let date = time ? new Date(Number(time)) : new Date();
- let Y = date.getFullYear() + '-';
- let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
- let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
- let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
- let m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
- let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
- return Y + M + D + h + m + s;
- }
|